[gtk+] x11: Simplify code for single-screen case



commit f8b017faa8ced24d71e4472fc8b2bfa939a7738f
Author: Benjamin Otte <otte redhat com>
Date:   Thu Apr 4 16:22:12 2013 +0200

    x11: Simplify code for single-screen case

 gdk/x11/gdkdevice-core-x11.c |   75 +++++++++++++++++--------------------
 gdk/x11/gdkdevice-xi2.c      |   84 ++++++++++++++++++++----------------------
 gdk/x11/gdkdisplay-x11.c     |   32 ++++++---------
 3 files changed, 87 insertions(+), 104 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-core-x11.c b/gdk/x11/gdkdevice-core-x11.c
index 57a1975..0c6ed7f 100644
--- a/gdk/x11/gdkdevice-core-x11.c
+++ b/gdk/x11/gdkdevice-core-x11.c
@@ -450,7 +450,7 @@ gdk_x11_device_core_window_at_position (GdkDevice       *device,
     }
   else
     {
-      gint i, screens, width, height;
+      gint width, height;
       GList *toplevels, *list;
       Window pointer_window, root, child;
       int rootx = -1, rooty = -1;
@@ -459,59 +459,52 @@ gdk_x11_device_core_window_at_position (GdkDevice       *device,
 
       /* FIXME: untrusted clients case not multidevice-safe */
       pointer_window = None;
-      screens = gdk_display_get_n_screens (display);
-
-      for (i = 0; i < screens; ++i)
+      screen = gdk_display_get_screen (display, 0);
+      toplevels = gdk_screen_get_toplevel_windows (screen);
+      for (list = toplevels; list != NULL; list = g_list_next (list))
         {
-          screen = gdk_display_get_screen (display, i);
-          toplevels = gdk_screen_get_toplevel_windows (screen);
-          for (list = toplevels; list != NULL; list = g_list_next (list))
+          window = GDK_WINDOW (list->data);
+          xwindow = GDK_WINDOW_XID (window);
+          gdk_x11_display_error_trap_push (display);
+          XQueryPointer (xdisplay, xwindow,
+                         &root, &child,
+                         &rootx, &rooty,
+                         &winx, &winy,
+                         &xmask);
+          if (gdk_x11_display_error_trap_pop (display))
+            continue;
+          if (child != None)
+            {
+              pointer_window = child;
+              break;
+            }
+          gdk_window_get_geometry (window, NULL, NULL, &width, &height);
+          if (winx >= 0 && winy >= 0 && winx < width && winy < height)
             {
-              window = GDK_WINDOW (list->data);
-              xwindow = GDK_WINDOW_XID (window);
-              gdk_x11_display_error_trap_push (display);
+              /* A childless toplevel, or below another window? */
+              XSetWindowAttributes attributes;
+              Window w;
+
+              w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
+                                 CopyFromParent, InputOnly, CopyFromParent,
+                                 0, &attributes);
+              XMapWindow (xdisplay, w);
               XQueryPointer (xdisplay, xwindow,
                              &root, &child,
                              &rootx, &rooty,
                              &winx, &winy,
                              &xmask);
-              if (gdk_x11_display_error_trap_pop (display))
-                continue;
-              if (child != None)
+              XDestroyWindow (xdisplay, w);
+              if (child == w)
                 {
-                  pointer_window = child;
+                  pointer_window = xwindow;
                   break;
                 }
-              gdk_window_get_geometry (window, NULL, NULL, &width, &height);
-              if (winx >= 0 && winy >= 0 && winx < width && winy < height)
-                {
-                  /* A childless toplevel, or below another window? */
-                  XSetWindowAttributes attributes;
-                  Window w;
-
-                  w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
-                                     CopyFromParent, InputOnly, CopyFromParent,
-                                     0, &attributes);
-                  XMapWindow (xdisplay, w);
-                  XQueryPointer (xdisplay, xwindow,
-                                 &root, &child,
-                                 &rootx, &rooty,
-                                 &winx, &winy,
-                                 &xmask);
-                  XDestroyWindow (xdisplay, w);
-                  if (child == w)
-                    {
-                      pointer_window = xwindow;
-                      break;
-                    }
-                }
             }
-
-          g_list_free (toplevels);
-          if (pointer_window != None)
-            break;
         }
 
+      g_list_free (toplevels);
+
       xwindow = pointer_window;
     }
 
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
index ef7e166..9803273 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -512,27 +512,53 @@ gdk_x11_device_xi2_window_at_position (GdkDevice       *device,
     }
   else
     {
-      gint i, screens, width, height;
+      gint width, height;
       GList *toplevels, *list;
       Window pointer_window, root, child;
 
       /* FIXME: untrusted clients case not multidevice-safe */
       pointer_window = None;
-      screens = gdk_display_get_n_screens (display);
 
-      for (i = 0; i < screens; ++i)
+      screen = gdk_display_get_screen (display, 0);
+      toplevels = gdk_screen_get_toplevel_windows (screen);
+      for (list = toplevels; list != NULL; list = g_list_next (list))
         {
-          screen = gdk_display_get_screen (display, i);
-          toplevels = gdk_screen_get_toplevel_windows (screen);
-          for (list = toplevels; list != NULL; list = g_list_next (list))
+          window = GDK_WINDOW (list->data);
+          xwindow = GDK_WINDOW_XID (window);
+
+          /* Free previous button mask, if any */
+          g_free (button_state.mask);
+
+          gdk_x11_display_error_trap_push (display);
+          XIQueryPointer (xdisplay,
+                          device_xi2->device_id,
+                          xwindow,
+                          &root, &child,
+                          &xroot_x, &xroot_y,
+                          &xwin_x, &xwin_y,
+                          &button_state,
+                          &mod_state,
+                          &group_state);
+          if (gdk_x11_display_error_trap_pop (display))
+            continue;
+          if (child != None)
+            {
+              pointer_window = child;
+              break;
+            }
+          gdk_window_get_geometry (window, NULL, NULL, &width, &height);
+          if (xwin_x >= 0 && xwin_y >= 0 && xwin_x < width && xwin_y < height)
             {
-              window = GDK_WINDOW (list->data);
-              xwindow = GDK_WINDOW_XID (window);
+              /* A childless toplevel, or below another window? */
+              XSetWindowAttributes attributes;
+              Window w;
 
-              /* Free previous button mask, if any */
-              g_free (button_state.mask);
+              free (button_state.mask);
 
-              gdk_x11_display_error_trap_push (display);
+              w = XCreateWindow (xdisplay, xwindow, (int)xwin_x, (int)xwin_y, 1, 1, 0,
+                                 CopyFromParent, InputOnly, CopyFromParent,
+                                 0, &attributes);
+              XMapWindow (xdisplay, w);
               XIQueryPointer (xdisplay,
                               device_xi2->device_id,
                               xwindow,
@@ -542,42 +568,12 @@ gdk_x11_device_xi2_window_at_position (GdkDevice       *device,
                               &button_state,
                               &mod_state,
                               &group_state);
-              if (gdk_x11_display_error_trap_pop (display))
-                continue;
-              if (child != None)
+              XDestroyWindow (xdisplay, w);
+              if (child == w)
                 {
-                  pointer_window = child;
+                  pointer_window = xwindow;
                   break;
                 }
-              gdk_window_get_geometry (window, NULL, NULL, &width, &height);
-              if (xwin_x >= 0 && xwin_y >= 0 && xwin_x < width && xwin_y < height)
-                {
-                  /* A childless toplevel, or below another window? */
-                  XSetWindowAttributes attributes;
-                  Window w;
-
-                  free (button_state.mask);
-
-                  w = XCreateWindow (xdisplay, xwindow, (int)xwin_x, (int)xwin_y, 1, 1, 0,
-                                     CopyFromParent, InputOnly, CopyFromParent,
-                                     0, &attributes);
-                  XMapWindow (xdisplay, w);
-                  XIQueryPointer (xdisplay,
-                                  device_xi2->device_id,
-                                  xwindow,
-                                  &root, &child,
-                                  &xroot_x, &xroot_y,
-                                  &xwin_x, &xwin_y,
-                                  &button_state,
-                                  &mod_state,
-                                  &group_state);
-                  XDestroyWindow (xdisplay, w);
-                  if (child == w)
-                    {
-                      pointer_window = xwindow;
-                      break;
-                    }
-                }
             }
 
           g_list_free (toplevels);
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 4bd2f2e..9463f34 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -478,27 +478,21 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
 
   if (xevent->type == DestroyNotify && !is_substructure)
     {
-      int i, n;
+      screen = GDK_X11_DISPLAY (display)->screen;
+      x11_screen = GDK_X11_SCREEN (screen);
 
-      n = gdk_display_get_n_screens (display);
-      for (i = 0; i < n; i++)
+      if (x11_screen->wmspec_check_window == xevent->xdestroywindow.window)
         {
-          screen = gdk_display_get_screen (display, i);
-          x11_screen = GDK_X11_SCREEN (screen);
-
-          if (x11_screen->wmspec_check_window == xevent->xdestroywindow.window)
-            {
-              x11_screen->wmspec_check_window = None;
-              x11_screen->last_wmspec_check_time = 0;
-              g_free (x11_screen->window_manager_name);
-              x11_screen->window_manager_name = g_strdup ("unknown");
+          x11_screen->wmspec_check_window = None;
+          x11_screen->last_wmspec_check_time = 0;
+          g_free (x11_screen->window_manager_name);
+          x11_screen->window_manager_name = g_strdup ("unknown");
 
-              /* careful, reentrancy */
-              _gdk_x11_screen_window_manager_changed (screen);
+          /* careful, reentrancy */
+          _gdk_x11_screen_window_manager_changed (screen);
 
-              return_val = FALSE;
-              goto done;
-            }
+          return_val = FALSE;
+          goto done;
         }
     }
 


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