[Xfce4-commits] <libxfce4ui:master> Simplify the xfce_gdk_screen_get_active fucntion.

Nick Schermer noreply at xfce.org
Sat Dec 31 13:54:01 CET 2011


Updating branch refs/heads/master
         to c3c47bf16faa2618a57525090f00d07b6932a82c (commit)
       from 04461012e8be40bb916d9cc2bfad6c6cf02c58ff (commit)

commit c3c47bf16faa2618a57525090f00d07b6932a82c
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Dec 31 13:50:33 2011 +0100

    Simplify the xfce_gdk_screen_get_active fucntion.
    
    The XQueryPointer also segfaults in some cases, so use
    gdk for all of this.

 libxfce4ui/xfce-gdk-extensions.c |   58 ++++++++++---------------------------
 1 files changed, 16 insertions(+), 42 deletions(-)

diff --git a/libxfce4ui/xfce-gdk-extensions.c b/libxfce4ui/xfce-gdk-extensions.c
index 4773853..402da5b 100644
--- a/libxfce4ui/xfce-gdk-extensions.c
+++ b/libxfce4ui/xfce-gdk-extensions.c
@@ -49,53 +49,27 @@
 GdkScreen *
 xfce_gdk_screen_get_active (gint *monitor_return)
 {
-#ifdef GDK_WINDOWING_X11
-  GdkScreen *screen;
-  Window     child;
-  Window     root;
-  GSList    *displays;
-  GSList    *lp;
-  guint      xmask;
-  gint       rootx, rooty;
-  gint       winx, winy;
-  gint       n;
+  GdkDisplay *display;
+  gint        rootx, rooty;
+  GdkScreen  *screen;
 
-  /* determine the list of active displays */
-  displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
-  for (lp = displays; lp != NULL; lp = lp->next)
-    {
-      /* check all screens on this display */
-      for (n = 0; n < gdk_display_get_n_screens (lp->data); ++n)
-        {
-          /* check if this screen contains the pointer */
-          screen = gdk_display_get_screen (lp->data, n);
-          if (XQueryPointer (GDK_SCREEN_XDISPLAY (screen),
-                             GDK_DRAWABLE_XID (gdk_screen_get_root_window (screen)),
-                             &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
-            {
-              /* return the monitor number */
-              if (monitor_return != NULL)
-                *monitor_return = gdk_screen_get_monitor_at_point (screen, rootx, rooty);
+  display = gdk_display_get_default ();
+  gdk_display_get_pointer (display, &screen, &rootx, &rooty, NULL);
 
-              /* yap, this screen contains the pointer, hence it's the active screen */
-              goto out;
-            }
-        }
+  if (G_UNLIKELY (screen == NULL))
+    {
+      screen = gdk_screen_get_default ();
+      if (monitor_return != NULL)
+        *monitor_return = 0;
+    }
+  else
+    {
+      /* return the monitor number */
+      if (monitor_return != NULL)
+        *monitor_return = gdk_screen_get_monitor_at_point (screen, rootx, rooty);
     }
-
-  /* nothing found, fallback to default screen */
-  screen = gdk_screen_get_default ();
-  if (monitor_return != NULL)
-    *monitor_return = 0;
-
-out:
-  g_slist_free (displays);
 
   return screen;
-#else
-  /* dunno what to do on non-X11 window systems */
-  return gdk_screen_get_default ();
-#endif
 }
 
 


More information about the Xfce4-commits mailing list