[gnome-flashback] screenshot: handle csd window screenshots differently



commit f8841277d14aaf943f58e5eb581af3e7c37baf37
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Jan 27 10:39:01 2016 +0200

    screenshot: handle csd window screenshots differently
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755673

 gnome-flashback/libscreenshot/gf-screenshot.c |   89 +++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/gnome-flashback/libscreenshot/gf-screenshot.c b/gnome-flashback/libscreenshot/gf-screenshot.c
index d215a45..c9da2b5 100644
--- a/gnome-flashback/libscreenshot/gf-screenshot.c
+++ b/gnome-flashback/libscreenshot/gf-screenshot.c
@@ -24,6 +24,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <X11/extensions/shape.h>
+#include <X11/Xatom.h>
 
 #include "gf-dbus-screenshot.h"
 #include "gf-flashspot.h"
@@ -322,6 +323,55 @@ find_wm_window (GdkDisplay *display,
     }
 }
 
+static gboolean
+get_gtk_frame_extents (GdkWindow *window,
+                       GtkBorder *extents)
+{
+  GdkDisplay *display;
+  Display *xdisplay;
+  Window xwindow;
+  Atom gtk_frame_extents;
+  Atom type;
+  gint format;
+  gulong n_items;
+  gulong bytes_after;
+  guchar *data;
+  gint result;
+  gulong *borders;
+
+  display = gdk_display_get_default ();
+  xdisplay = gdk_x11_display_get_xdisplay (display);
+  xwindow = gdk_x11_window_get_xid (window);
+  gtk_frame_extents = XInternAtom (xdisplay, "_GTK_FRAME_EXTENTS", False);
+
+  gdk_error_trap_push ();
+  result = XGetWindowProperty (xdisplay, xwindow, gtk_frame_extents,
+                               0, G_MAXLONG, False, XA_CARDINAL,
+                               &type, &format, &n_items, &bytes_after, &data);
+  gdk_error_trap_pop_ignored ();
+
+  if (data == NULL)
+    return FALSE;
+
+  if (result != Success || type != XA_CARDINAL || format != 32 || n_items != 4)
+    {
+      XFree (data);
+
+      return FALSE;
+    }
+
+  borders = (gulong *) data;
+
+  extents->left = borders[0];
+  extents->right = borders[1];
+  extents->top = borders[2];
+  extents->bottom = borders[3];
+
+  XFree (data);
+
+  return TRUE;
+}
+
 static void
 get_window_rect_coords (GdkWindow    *window,
                         gboolean      include_frame,
@@ -477,6 +527,7 @@ take_screenshot_real (GfScreenshot    *screenshot,
 {
   GdkDisplay *display;
   GdkWindow *window;
+  GtkBorder extents;
   GdkRectangle real;
   GdkRectangle s;
   Window wm;
@@ -491,6 +542,44 @@ take_screenshot_real (GfScreenshot    *screenshot,
   if (window == NULL)
     return FALSE;
 
+  if (type == SCREENSHOT_WINDOW && get_gtk_frame_extents (window, &extents))
+    {
+      gdk_window_get_frame_extents (window, &real);
+
+      if (include_frame)
+        {
+          real.x = 0;
+          real.y = 0;
+        }
+      else
+        {
+          real.x = extents.left;
+          real.y = extents.top;
+          real.width -= extents.left + extents.right;
+          real.height -= extents.top + extents.bottom;
+        }
+
+      pixbuf = gdk_pixbuf_get_from_window (window, real.x, real.y,
+                                           real.width, real.height);
+
+      gdk_window_get_frame_extents (window, &real);
+
+      *x = real.x;
+      *y = real.y;
+      *width = real.width;
+      *height = real.height;
+
+      if (!include_frame)
+        {
+          *x += extents.left;
+          *y += extents.top;
+          *width -= extents.left + extents.right;
+          *height -= extents.top + extents.bottom;
+        }
+
+      return save_screenshot (pixbuf, filename_in, filename_out);
+    }
+
   get_window_rect_coords (window, include_frame, &real, &s);
 
   wm = find_wm_window (display, window);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]