gnome-utils r7879 - in trunk: . gnome-screenshot



Author: matthiasc
Date: Mon Apr  7 15:40:19 2008
New Revision: 7879
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=7879&view=rev

Log:
2008-04-07  Matthias Clasen  <mclasen redhat com>

        Bug 171151 â showing the cursor in the screenshot

        * screenshot-utils.h:
        * screenshot-utils.c (screenshot_get_pixbuf): Optionally
        include the cursor in the image.
        (screenshot_grab_lock): Don't grab the pointer while taking
        the screenshot.

        * gnome-screenshot.schemas.in:
        * gnome-screenshot.c: Add an 'include pointer' option.



Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/gnome-screenshot/ChangeLog
   trunk/gnome-screenshot/Makefile.am
   trunk/gnome-screenshot/gnome-screenshot.c
   trunk/gnome-screenshot/gnome-screenshot.schemas.in
   trunk/gnome-screenshot/screenshot-utils.c
   trunk/gnome-screenshot/screenshot-utils.h

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Mon Apr  7 15:40:19 2008
@@ -138,7 +138,10 @@
 dnl screenshot modules
 dnl *****************************************
 AC_CHECK_HEADERS(X11/extensions/shape.h, XSHAPE_LIBS="-lXext")
+AC_CHECK_HEADERS(X11/extensions/Xfixes.h, XFIXES_LIBS="-lXfixes", , [#include <X11/Xlib.h>])
 AC_SUBST(XSHAPE_LIBS)
+AC_SUBST(XFIXES_LIBS)
+
 
 PKG_CHECK_MODULES(SCREENSHOT, gtk+-2.0 >= $GTK_REQUIRED dnl
                               libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED dnl

Modified: trunk/gnome-screenshot/Makefile.am
==============================================================================
--- trunk/gnome-screenshot/Makefile.am	(original)
+++ trunk/gnome-screenshot/Makefile.am	Mon Apr  7 15:40:19 2008
@@ -42,6 +42,7 @@
 
 gnome_screenshot_LDADD =		\
 	$(XSHAPE_LIBS)			\
+	$(XFIXES_LIBS)			\
 	$(SCREENSHOT_LIBS)		\
 	$(NULL)
 

Modified: trunk/gnome-screenshot/gnome-screenshot.c
==============================================================================
--- trunk/gnome-screenshot/gnome-screenshot.c	(original)
+++ trunk/gnome-screenshot/gnome-screenshot.c	Mon Apr  7 15:40:19 2008
@@ -52,6 +52,7 @@
 
 #define GNOME_SCREENSHOT_GCONF  "/apps/gnome-screenshot"
 #define INCLUDE_BORDER_KEY      GNOME_SCREENSHOT_GCONF "/include_border"
+#define INCLUDE_POINTER_KEY     GNOME_SCREENSHOT_GCONF "/include_pointer"
 #define LAST_SAVE_DIRECTORY_KEY GNOME_SCREENSHOT_GCONF "/last_save_directory"
 #define BORDER_EFFECT_KEY       GNOME_SCREENSHOT_GCONF "/border_effect"
 
@@ -81,6 +82,7 @@
 /* Options */
 static gboolean take_window_shot = FALSE;
 static gboolean include_border = FALSE;
+static gboolean include_pointer = TRUE;
 static char *border_effect = NULL;
 static guint delay = 0;
 
@@ -157,6 +159,13 @@
 }
 
 static void
+include_pointer_toggled_cb (GtkToggleButton *button,
+                            gpointer         data)
+{
+  include_pointer = gtk_toggle_button_get_active (button);
+}
+
+static void
 effect_combo_changed_cb (GtkComboBox *combo,
                          gpointer     user_data)
 {
@@ -300,6 +309,15 @@
   gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
   gtk_widget_show (vbox);
 
+  /** Include pointer **/
+  check = gtk_check_button_new_with_mnemonic (_("Include _pointer"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), include_pointer);
+  g_signal_connect (check, "toggled",
+                    G_CALLBACK (include_pointer_toggled_cb),
+                    NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
+  gtk_widget_show (check);
+
   /** Include window border **/
   check = gtk_check_button_new_with_mnemonic (_("Include the window _border"));
   gtk_widget_set_sensitive (check, take_window_shot);
@@ -693,7 +711,7 @@
       win = GDK_ROOT_WINDOW ();
     }
 
-  screenshot = screenshot_get_pixbuf (win);
+  screenshot = screenshot_get_pixbuf (win, include_pointer);
 
   if (take_window_shot) {
     switch (border_effect[0])
@@ -813,6 +831,10 @@
                                           INCLUDE_BORDER_KEY,
                                           NULL);
 
+  include_pointer = gconf_client_get_bool (gconf_client,
+                                          INCLUDE_POINTER_KEY,
+                                          NULL);
+
   border_effect = gconf_client_get_string (gconf_client,
                                            BORDER_EFFECT_KEY,
                                            NULL);

Modified: trunk/gnome-screenshot/gnome-screenshot.schemas.in
==============================================================================
--- trunk/gnome-screenshot/gnome-screenshot.schemas.in	(original)
+++ trunk/gnome-screenshot/gnome-screenshot.schemas.in	Mon Apr  7 15:40:19 2008
@@ -28,6 +28,18 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/gnome-screenshot/include_pointer</key>
+      <applyto>/apps/gnome-screenshot/include_pointer</applyto>
+      <owner>gnome-screenshot</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+        <short>Include Pointer</short>
+        <long>Include the pointer in the screenshot</long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/gnome-screenshot/border_effect</key>
       <applyto>/apps/gnome-screenshot/border_effect</applyto>
       <owner>gnome-screenshot</owner>

Modified: trunk/gnome-screenshot/screenshot-utils.c
==============================================================================
--- trunk/gnome-screenshot/screenshot-utils.c	(original)
+++ trunk/gnome-screenshot/screenshot-utils.c	Mon Apr  7 15:40:19 2008
@@ -29,6 +29,8 @@
 #include <X11/extensions/shape.h>
 #endif
 
+#include <X11/extensions/Xfixes.h>
+
 static GtkWidget *selection_window;
 
 #define SELECTION_NAME "_GNOME_PANEL_SCREENSHOT"
@@ -265,11 +267,6 @@
       goto out;
     }
 
-  cursor = gdk_cursor_new (GDK_WATCH);
-  gdk_pointer_grab (selection_window->window, FALSE, 0, NULL,
-		    cursor, GDK_CURRENT_TIME);
-  gdk_cursor_unref (cursor);
-
   result = TRUE;
 
  out:
@@ -476,7 +473,7 @@
 }
 
 GdkPixbuf *
-screenshot_get_pixbuf (Window w)
+screenshot_get_pixbuf (Window w, gboolean include_pointer)
 {
   GdkWindow *window, *root;
   GdkPixbuf *screenshot;
@@ -602,6 +599,85 @@
 					     width, height);
 #endif /* HAVE_X11_EXTENSIONS_SHAPE_H */
 
+  if (include_pointer) 
+    {
+      XFixesCursorImage *cursor_image;
+
+      cursor_image = XFixesGetCursorImage (GDK_DISPLAY ());
+      
+      if (cursor_image != NULL) 
+        {
+          GdkRectangle r1, r2;
+          int cx, cy, i, j, k;
+          int r, g, b, a;
+          guchar *pixels, *p;
+          int rowstride;
+          unsigned long pixel;
+
+          cx = cursor_image->x - cursor_image->xhot;
+          cy = cursor_image->y - cursor_image->yhot;
+
+          r1.x = x_real_orig;
+          r1.y = y_real_orig;
+          r1.width = real_width;
+          r1.height = real_height;
+          r2.x = cx;
+          r2.y = cy;
+          r2.width = cursor_image->width;
+          r2.height = cursor_image->height;
+          if (gdk_rectangle_intersect (&r1, &r2, &r2)) 
+            {
+              GdkPixbuf *cursor_pixbuf;
+
+              cursor_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+                                              TRUE, 8, 
+                                              cursor_image->width,
+                                               cursor_image->height);
+              pixels = gdk_pixbuf_get_pixels (cursor_pixbuf);
+              rowstride = gdk_pixbuf_get_rowstride (cursor_pixbuf);
+              for (i = 0, k = 0; i < cursor_image->height; i++) 
+                {
+                  p = pixels + i * rowstride;
+                  for (j = 0; j < cursor_image->width; j++, k++)
+                    {
+                      pixel = cursor_image->pixels[k];
+                    
+                      b = pixel & 0xff;
+                      g = (pixel >> 8) & 0xff;
+                      r = (pixel >> 16) & 0xff;
+                      a = (pixel >> 24) & 0xff;
+
+                      if (a != 0) 
+                        {
+                          p[0] = r * 255 / a;
+                          p[1] = g * 255 / a;
+                          p[2] = b * 255 / a;
+                          p[3] = a;
+                        }
+                      else 
+                        {
+                          p[0] = p[1] = p[2] = p[3] = 0;
+                        }
+
+                      p += 4;
+                    }
+               }
+ 
+              gdk_pixbuf_composite (cursor_pixbuf, screenshot,
+                                    r2.x - x_real_orig, r2.y - y_real_orig, 
+                                    r2.width, r2.height,
+                                    cx - x_real_orig, cy - y_real_orig, 
+                                    1.0, 1.0, 
+                                    GDK_INTERP_BILINEAR,
+                                    255);
+
+              g_object_unref (cursor_pixbuf);
+            }
+
+          XFree (cursor_image);
+        }
+    }
+
   return screenshot;
 }
 

Modified: trunk/gnome-screenshot/screenshot-utils.h
==============================================================================
--- trunk/gnome-screenshot/screenshot-utils.h	(original)
+++ trunk/gnome-screenshot/screenshot-utils.h	Mon Apr  7 15:40:19 2008
@@ -29,7 +29,8 @@
 void       screenshot_release_lock        (void);
 gchar     *screenshot_get_window_title    (Window   w);
 Window     screenshot_find_current_window (gboolean include_decoration);
-GdkPixbuf *screenshot_get_pixbuf          (Window   w);
+GdkPixbuf *screenshot_get_pixbuf          (Window   w,
+                                           gboolean include_pointer);
 
 void       screenshot_show_error_dialog   (GtkWindow   *parent,
                                            const gchar *message,



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