On Wed, 2007-01-31 at 00:53 +0100, peter sikking wrote:

> So I had a look, one delay, but they also gave me an idea how
> we can make everybody here happy, without the cost of two delays:
> In 'snap window' mode the shot shall be taken:
> a) on the first mouse-down after the timer (can be zero) has expired;
> b) immediately, when a non-zero timer expires AND a mouse-button
>     (left, right [pop-up menu], even middle?) is being held down.
> The latter captures menus being open or pushbuttons being down
> exactly when the timer expires.

Very nice! I gave a quick shot at an implementation and came up with the
following patch:

Index: plug-ins/common/screenshot.c
--- plug-ins/common/screenshot.c        (revision 21819)
+++ plug-ins/common/screenshot.c        (working copy)
@@ -398,10 +398,16 @@

   if (status != GrabSuccess)
-      g_message (_("Error grabbing the pointer"));
+      gint   x, y;
+      guint  xmask;

-      XFreeCursor (x_dpy, x_cursor);
-      return 0;
+      XQueryPointer (x_dpy, x_root, &x_root, &x_win, &x, &y, &x, &y,
+      // FIXME: check window type and walk up the window hierarchy
+      //        we hit a toplevel window
+      if (x_win == None)
+        g_message (_("Error selecting the window"));

   if (shootvals.shoot_type == SHOOT_REGION)
@@ -574,9 +580,11 @@
       g_free (keys);

-  XUngrabPointer (x_dpy, CurrentTime);
+  if (status == GrabSuccess)
+    XUngrabPointer (x_dpy, CurrentTime);

   XFreeCursor (x_dpy, x_cursor);
   if (x_gc != None)
     XFreeGC (x_dpy, x_gc);

If you actually try this you will understand why I added a FIXME. If you
open a popup menu and keep the mouse button pressed until the timer
expires, this code takes a screenshot of the popup menu, not of the
window that the popup is created from. This behaviour is correct from a
technical point of view (after all popup menus are separate windows).
But it's not what the user expects. We will somehow have to special-case
this. I posted the patch here in case that someone experienced with XLib
programming wants to give this a try.


Gimp-developer mailing list

Reply via email to