[Goodies-commits] r5260 - in xfce4-screenshooter-plugin/trunk: . src

Jerome Guelfucci jeromeg at xfce.org
Sun Aug 17 00:00:53 CEST 2008


Author: jeromeg
Date: 2008-08-16 22:00:52 +0000 (Sat, 16 Aug 2008)
New Revision: 5260

Modified:
   xfce4-screenshooter-plugin/trunk/ChangeLog
   xfce4-screenshooter-plugin/trunk/NEWS
   xfce4-screenshooter-plugin/trunk/configure.ac.in
   xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c
   xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h
Log:
* src/screenshooter-utils.c:
  - ported to use mostly gdk functions.
  - BUGFIX: when the active window is the desktop, instead of returning a
    corrupted snapshot of the background image, return the whole desktop view.
  - drop get_window_property and screenshot_find_active_window which are now 
    useless.
  - improve indentation of code.
* src/screenshooter-utils.h:
  - remove some useless #includes.
* configure.ac.in: add svn tag that I had forgotten.
* NEWS: updated.


Modified: xfce4-screenshooter-plugin/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter-plugin/trunk/ChangeLog	2008-08-16 18:30:30 UTC (rev 5259)
+++ xfce4-screenshooter-plugin/trunk/ChangeLog	2008-08-16 22:00:52 UTC (rev 5260)
@@ -1,3 +1,17 @@
+2008-08-16 jeromeg
+
+  * src/screenshooter-utils.c:
+    - ported to use mostly gdk functions.
+    - BUGFIX: when the active window is the desktop, instead of returning a
+      corrupted snapshot of the background image, return the whole desktop view.
+    - drop get_window_property and screenshot_find_active_window which are now 
+      useless.
+    - improve indentation of code.
+  * src/screenshooter-utils.h:
+    - remove some useless #includes.
+  * configure.ac.in: add svn tag that I had forgotten.
+  * NEWS: updated.
+
 2008-08-15 jeromeg
 
   * src/screenshooter-plugin.c:

Modified: xfce4-screenshooter-plugin/trunk/NEWS
===================================================================
--- xfce4-screenshooter-plugin/trunk/NEWS	2008-08-16 18:30:30 UTC (rev 5259)
+++ xfce4-screenshooter-plugin/trunk/NEWS	2008-08-16 22:00:52 UTC (rev 5260)
@@ -1,5 +1,8 @@
 === Version 1.3.2 ===
   * BUGFIX: plug some stupid leaks.
+  * BUGFIX: when the active window is the desktop, instead of returning a
+    corrupted snapshot of the background image, return the whole desktop view.
+  * Code cleanup using libgdk functions.
   * Use tooltips for panel plugin when compiled with gtk >= 2.12.
 
 === Version 1.3.1 ===

Modified: xfce4-screenshooter-plugin/trunk/configure.ac.in
===================================================================
--- xfce4-screenshooter-plugin/trunk/configure.ac.in	2008-08-16 18:30:30 UTC (rev 5259)
+++ xfce4-screenshooter-plugin/trunk/configure.ac.in	2008-08-16 22:00:52 UTC (rev 5260)
@@ -8,7 +8,7 @@
 m4_define([xfce4_screenshooter_plugin_version_micro], [1])
 m4_define([xfce4_screenshooter_plugin_version_nano],  []) dnl leave this empty to have no nano version
 m4_define([xfce4_screenshooter_plugin_version_build], [r at REVISION@])
-m4_define([xfce4_screenshooter_plugin_version_tag],   [])
+m4_define([xfce4_screenshooter_plugin_version_tag],   [svn])
 m4_define([xfce4_screenshooter_plugin_version], [xfce4_screenshooter_plugin_version_major().xfce4_screenshooter_plugin_version_minor().xfce4_screenshooter_plugin_version_micro()ifelse(xfce4_screenshooter_plugin_version_nano(), [], [], [.xfce4_screenshooter_plugin_version_nano()])ifelse(xfce4_screenshooter_plugin_version_tag(), [svn], [xfce4_screenshooter_plugin_version_tag()-xfce4_screenshooter_plugin_version_build()], [xfce4_screenshooter_plugin_version_tag()])])
 
 AC_INIT([xfce4-screenshooter-plugin], [xfce4_screenshooter_plugin_version], [http://bugzilla.xfce.org/], [xfce4-screenshooter-plugin])

Modified: xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c	2008-08-16 18:30:30 UTC (rev 5259)
+++ xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.c	2008-08-16 22:00:52 UTC (rev 5260)
@@ -20,74 +20,11 @@
 #include <screenshooter-utils.h>
 
 /* Prototypes */
-
-static Window get_window_property (Window xwindow, Atom atom);
-static Window find_toplevel_window (Window xid);
-static Window screenshot_find_active_window (void);
 static gchar *generate_filename_for_uri(char *uri);
+static Window find_toplevel_window (Window xid);
 
-/* Internals */
-
-/* Borrowed from libwnck */
-static Window
-get_window_property (Window  xwindow,
-		     Atom    atom)
-{
-  Atom type;
-  int format;
-  gulong nitems;
-  gulong bytes_after;
-  Window *w;
-  int err, result;
-  Window retval;
-
-  gdk_error_trap_push ();
-
-  type = None;
-  result = XGetWindowProperty (gdk_display,
-			       xwindow,
-			       atom,
-			       0, G_MAXLONG,
-			       False, XA_WINDOW, &type, &format, &nitems,
-			       &bytes_after, (unsigned char **) &w);  
-  err = gdk_error_trap_pop ();
-
-  if (err != Success ||
-      result != Success)
-    return None;
-  
-  if (type != XA_WINDOW)
-    {
-      XFree (w);
-      return None;
-    }
-
-  retval = *w;
-  XFree (w);
-  
-  return retval;
-}
-
 /* Borrowed from gnome-screenshot */
 static Window
-screenshot_find_active_window (void)
-{
-  Window retval = None;
-  Window root_window;
-
-  root_window = GDK_ROOT_WINDOW ();
-
-  if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
-    {
-      retval = get_window_property (root_window,
-				    gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW"));
-    }
-
-  return retval;  
-}
-
-/* Borrowed from gnome-screenshot */
-static Window
 find_toplevel_window (Window xid)
 {
   Window root, parent, *children;
@@ -97,43 +34,44 @@
     {
       if (XQueryTree (GDK_DISPLAY (), xid, &root,
 		      &parent, &children, &nchildren) == 0)
-	{
-	  g_warning ( _("Couldn't find window manager window") );
-	  return None;
-	}
+	      {
+	        g_warning ( _("Couldn't find window manager window") );
+	        return None;
+	      }
 
       if (root == parent)
-	return xid;
+	      return xid;
 
       xid = parent;
     }
   while (TRUE);
 }
 
+
 static gchar *generate_filename_for_uri(char *uri)
 {
   gchar *file_name;
   unsigned int i = 0;
     
   if ( uri == NULL )
-  {
-  	return NULL;
-  }      
+    {
+  	  return NULL;
+    }      
   
   file_name = g_strdup ( _("Screenshot.png") );
     
-  if( g_access ( g_build_filename (uri, file_name, NULL), F_OK ) != 0 ) 
-  {
-    return file_name;
-  }
+  if( g_access (g_build_filename (uri, file_name, NULL), F_OK ) != 0 ) 
+    {
+      return file_name;
+    }
     
   do
-  {
-    i++;
-    g_free (file_name);
-    file_name = g_strdup_printf ( _("Screenshot-%d.png"), i);
-  }
-  while( g_access ( g_build_filename (uri, file_name, NULL), F_OK ) == 0 );
+    {
+      i++;
+      g_free (file_name);
+      file_name = g_strdup_printf ( _("Screenshot-%d.png"), i);
+    }
+  while( g_access (g_build_filename (uri, file_name, NULL), F_OK ) == 0 );
     
   return file_name;
 }
@@ -142,19 +80,36 @@
 
 GdkPixbuf *take_screenshot (ScreenshotData * sd)
 {
-  GdkPixbuf * screenshot;
-  GdkWindow * window;
+  GdkPixbuf *screenshot;
+  GdkWindow *window;
+  GdkScreen *screen;
+  
   gint width;
   gint height;
+  gboolean needs_unref = TRUE;
   
+  screen = gdk_screen_get_default ();
+    
   if (sd->whole_screen)
-  {
-    window = gdk_get_default_root_window();
-  } 
+    {
+      window = gdk_get_default_root_window();
+      needs_unref = FALSE;
+    } 
   else 
-  {
-    window = gdk_window_foreign_new (find_toplevel_window (screenshot_find_active_window ()));
-  }
+    {
+      window = gdk_screen_get_active_window (screen);
+    
+      if (gdk_window_get_type_hint (window) == GDK_WINDOW_TYPE_HINT_DESKTOP)
+        {
+          window = gdk_get_default_root_window();
+          needs_unref = FALSE;
+        }
+      else
+        {
+          window = 
+            gdk_window_foreign_new (find_toplevel_window (GDK_WINDOW_XID(window)));
+        }
+    }
   
   sleep(sd->screenshot_delay);
   
@@ -164,7 +119,10 @@
 					     window,
 					     NULL, 0, 0, 0, 0,
 					     width, height);
-	
+					     
+	if (needs_unref)
+	  g_object_unref (window);
+		
 	return screenshot;
 }
 
@@ -178,47 +136,53 @@
 
   filename = generate_filename_for_uri ( sd->screenshot_dir );
     
-  if ( sd->show_save_dialog )
-	{
-	  /* If the user wants a save dialog, we run it, and grab the filename the user
-	  has chosen. */
+  if (sd->show_save_dialog)
+	  {
+	    /* If the user wants a save dialog, we run it, and grab the filename 
+	    the user has chosen. */
 	  
-    chooser = gtk_file_chooser_dialog_new ( _("Save screenshot as ..."),
-                                          NULL,
-                                          GTK_FILE_CHOOSER_ACTION_SAVE,
-                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                          GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-                                          NULL);
-    gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER ( chooser ), TRUE);
-    gtk_dialog_set_default_response (GTK_DIALOG ( chooser ), GTK_RESPONSE_ACCEPT);
-    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER ( chooser ), sd->screenshot_dir);
+      chooser = 
+        gtk_file_chooser_dialog_new (_("Save screenshot as ..."),
+                                     NULL,
+                                     GTK_FILE_CHOOSER_ACTION_SAVE,
+                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                     GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+                                     NULL);
+      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (chooser), 
+                                                      TRUE);
+      gtk_dialog_set_default_response (GTK_DIALOG (chooser), 
+                                     GTK_RESPONSE_ACCEPT);
+      gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (chooser), 
+                                        sd->screenshot_dir);
 
-    preview = gtk_image_new ();
+      preview = gtk_image_new ();
   
-    gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER ( chooser ), filename);
-    gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER ( chooser ), preview);
+      gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser), filename);
+      gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser), preview);
   
-    thumbnail = gdk_pixbuf_scale_simple (screenshot, gdk_pixbuf_get_width(screenshot)/5, 
-                                         gdk_pixbuf_get_height(screenshot)/5, 
-                                         GDK_INTERP_BILINEAR);
-    gtk_image_set_from_pixbuf (GTK_IMAGE (preview), thumbnail);
-    g_object_unref ( thumbnail );
+      thumbnail = 
+        gdk_pixbuf_scale_simple (screenshot, gdk_pixbuf_get_width(screenshot)/5, 
+                                 gdk_pixbuf_get_height(screenshot)/5, 
+                                 GDK_INTERP_BILINEAR);
+      gtk_image_set_from_pixbuf (GTK_IMAGE (preview), thumbnail);
+      g_object_unref (thumbnail);
     
-    dialog_response = gtk_dialog_run ( GTK_DIALOG ( chooser ) );
+      dialog_response = gtk_dialog_run (GTK_DIALOG (chooser));
 	  
-	  if ( dialog_response == GTK_RESPONSE_ACCEPT )
-	  {
-	    filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( chooser ) );
-      gdk_pixbuf_save (screenshot, filename, "png", NULL, NULL);
-	  }
+	    if (dialog_response == GTK_RESPONSE_ACCEPT)
+	      {
+	        filename = 
+	          gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser) );
+          gdk_pixbuf_save (screenshot, filename, "png", NULL, NULL);
+	      }
 	  
-	  gtk_widget_destroy ( GTK_WIDGET ( chooser ) );
-	}  
+	    gtk_widget_destroy ( GTK_WIDGET ( chooser ) );
+	  }  
 	else
-	{    
+	  {    
 	    /* Else, we just save the file in the default folder */
       filename = g_build_filename (sd->screenshot_dir, filename, NULL);
 	    gdk_pixbuf_save (screenshot, filename, "png", NULL, NULL);
-	}
-  g_free( filename );
+	  }
+  g_free (filename);
 }

Modified: xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h
===================================================================
--- xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h	2008-08-16 18:30:30 UTC (rev 5259)
+++ xfce4-screenshooter-plugin/trunk/src/screenshooter-utils.h	2008-08-16 22:00:52 UTC (rev 5260)
@@ -27,8 +27,6 @@
 
 #include <libxfce4util/libxfce4util.h>
 
-#include <fcntl.h>
-#include <X11/Xatom.h>
 #include <unistd.h>
 
 typedef struct




More information about the Goodies-commits mailing list