[Xfce4-commits] r29274 - in xfwm4/trunk: . src

Olivier Fourdan olivier at xfce.org
Sun Jan 18 22:42:47 CET 2009


Author: olivier
Date: 2009-01-18 21:42:47 +0000 (Sun, 18 Jan 2009)
New Revision: 29274

Modified:
   xfwm4/trunk/ChangeLog
   xfwm4/trunk/src/client.c
   xfwm4/trunk/src/events.c
   xfwm4/trunk/src/moveresize.c
   xfwm4/trunk/src/netwm.c
   xfwm4/trunk/src/placement.c
   xfwm4/trunk/src/screen.c
   xfwm4/trunk/src/screen.h
   xfwm4/trunk/src/tabwin.c
Log:
	* src/client.c, src/events.c, src/moveresize.c, src/netwm.c,
	  src/placement.c, src/screen.c, src/screen.h, src/tabwin.c: Cache
	  the monitor geometry instead of just the monitor number, it's more
	  efficient.

Modified: xfwm4/trunk/ChangeLog
===================================================================
--- xfwm4/trunk/ChangeLog	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/ChangeLog	2009-01-18 21:42:47 UTC (rev 29274)
@@ -1,3 +1,10 @@
+2009-01-18	olivier
+
+	* src/client.c, src/events.c, src/moveresize.c, src/netwm.c,
+	  src/placement.c, src/screen.c, src/screen.h, src/tabwin.c: Cache
+	  the monitor geometry instead of just the monitor number, it's more
+	  efficient.
+
 2009-01-17	olivier
 
 	* settings-dialogs/xfwm4-settings.c, 

Modified: xfwm4/trunk/src/client.c
===================================================================
--- xfwm4/trunk/src/client.c	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/client.c	2009-01-18 21:42:47 UTC (rev 29274)
@@ -2983,14 +2983,12 @@
     if (!FLAG_TEST (c->flags, CLIENT_FLAG_FULLSCREEN) && (c->size->flags & PMaxSize))
     {
         GdkRectangle rect;
-        gint monitor_nbr;
         int cx, cy;
 
         cx = frameX (c) + (frameWidth (c) / 2);
         cy = frameY (c) + (frameHeight (c) / 2);
 
-        monitor_nbr = myScreenFindMonitorAtPoint (c->screen_info, cx, cy);
-        gdk_screen_get_monitor_geometry (c->screen_info->gscr, monitor_nbr, &rect);
+        myScreenFindMonitorAtPoint (c->screen_info, cx, cy, &rect);
 
         if ((c->size->max_width < rect.width) || (c->size->max_height < rect.height))
         {
@@ -3117,7 +3115,6 @@
     GdkRectangle rect;
     int cx, cy, full_x, full_y, full_w, full_h;
     int tmp_x, tmp_y, tmp_w, tmp_h;
-    gint monitor_nbr;
 
     tmp_x = frameX (c);
     tmp_y = frameY (c);
@@ -3129,8 +3126,7 @@
 
     screen_info = c->screen_info;
 
-    monitor_nbr = myScreenFindMonitorAtPoint (screen_info, cx, cy);
-    gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
+    myScreenFindMonitorAtPoint (screen_info, cx, cy, &rect);
 
     full_x = MAX (screen_info->params->xfwm_margins[STRUTS_LEFT], rect.x);
     full_y = MAX (screen_info->params->xfwm_margins[STRUTS_TOP], rect.y);

Modified: xfwm4/trunk/src/events.c
===================================================================
--- xfwm4/trunk/src/events.c	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/events.c	2009-01-18 21:42:47 UTC (rev 29274)
@@ -50,6 +50,7 @@
 #include "client.h"
 #include "moveresize.h"
 #include "cycle.h"
+#include "placement.h"
 #include "stacking.h"
 #include "transients.h"
 #include "focus.h"
@@ -2748,7 +2749,10 @@
      * is not valid anymore and potentially refers to a monitor that
      * was just removed, so invalidate it.
      */
-    screen_info->cache_monitor = -1;
+    screen_info->cache_monitor.x = -1;
+    screen_info->cache_monitor.y = -1;
+    screen_info->cache_monitor.width = 0;
+    screen_info->cache_monitor.height = 0;
 
     /*
      * From the window manager point of view,

Modified: xfwm4/trunk/src/moveresize.c
===================================================================
--- xfwm4/trunk/src/moveresize.c	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/moveresize.c	2009-01-18 21:42:47 UTC (rev 29274)
@@ -378,7 +378,6 @@
     int best_delta_x, best_delta_y;
     int c_frame_x1, c_frame_x2, c_frame_y1, c_frame_y2;
     GdkRectangle rect;
-    gint monitor_nbr;
 
     g_return_if_fail (c != NULL);
     TRACE ("entering clientSnapPosition");
@@ -405,8 +404,7 @@
     best_frame_x = frame_x;
     best_frame_y = frame_y;
 
-    monitor_nbr = myScreenFindMonitorAtPoint (screen_info, cx, cy);
-    gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
+    myScreenFindMonitorAtPoint (screen_info, cx, cy, &rect);
 
     disp_x = rect.x;
     disp_y = rect.y;
@@ -1106,7 +1104,6 @@
     int frame_top, frame_left, frame_right, frame_bottom;
     int move_top, move_bottom, move_left, move_right;
     int temp;
-    gint monitor_nbr;
     gint min_visible;
     gboolean resizing;
 
@@ -1149,8 +1146,7 @@
             || (passdata->handle == CORNER_COUNT + SIDE_LEFT)) ?
         1 : 0;
 
-    monitor_nbr = myScreenFindMonitorAtPoint (screen_info, cx, cy);
-    gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
+    myScreenFindMonitorAtPoint (screen_info, cx, cy, &rect);
 
     disp_x = rect.x;
     disp_y = rect.y;

Modified: xfwm4/trunk/src/netwm.c
===================================================================
--- xfwm4/trunk/src/netwm.c	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/netwm.c	2009-01-18 21:42:47 UTC (rev 29274)
@@ -741,14 +741,12 @@
     if (FLAG_TEST (c->flags, CLIENT_FLAG_FULLSCREEN))
     {
         GdkRectangle rect;
-        gint monitor_nbr;
         int cx, cy;
 
         cx = frameX (c) + (frameWidth (c) / 2);
         cy = frameY (c) + (frameHeight (c) / 2);
 
-        monitor_nbr = myScreenFindMonitorAtPoint (screen_info, cx, cy);
-        gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
+        myScreenFindMonitorAtPoint (screen_info, cx, cy, &rect);
 
         c->fullscreen_old_x = c->x;
         c->fullscreen_old_y = c->y;

Modified: xfwm4/trunk/src/placement.c
===================================================================
--- xfwm4/trunk/src/placement.c	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/placement.c	2009-01-18 21:42:47 UTC (rev 29274)
@@ -202,7 +202,6 @@
     int screen_width, screen_height;
     unsigned int ret;
     GdkRectangle rect;
-    gint monitor_nbr;
     gint min_visible;
 
     g_return_val_if_fail (c != NULL, 0);
@@ -225,8 +224,7 @@
     cy = frame_y + (frame_height / 2);
 
     screen_info = c->screen_info;
-    monitor_nbr = myScreenFindMonitorAtPoint (screen_info, cx, cy);
-    gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
+    myScreenFindMonitorAtPoint (screen_info, cx, cy, &rect);
 
     screen_width = screen_info->width;
     screen_height = screen_info->height;
@@ -650,7 +648,6 @@
     Client *c2;
     GdkRectangle rect;
     int full_x, full_y, full_w, full_h, msx, msy;
-    gint monitor_nbr;
     gint n_monitors;
     gboolean place;
     gboolean position;
@@ -664,14 +661,15 @@
     position = (c->size->flags & (PPosition | USPosition));
 
     n_monitors = gdk_screen_get_n_monitors (c->screen_info->gscr);
-    monitor_nbr = 0;
     if ((n_monitors > 1) || (screen_info->params->placement_mode == PLACE_MOUSE))
     {
         getMouseXY (screen_info, screen_info->xroot, &msx, &msy);
-        monitor_nbr = myScreenFindMonitorAtPoint (screen_info, msx, msy);
+        myScreenFindMonitorAtPoint (screen_info, msx, msy, &rect);
     }
-    gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
-
+    else
+    {
+        gdk_screen_get_monitor_geometry (screen_info->gscr, 0, &rect);
+    }
     if (position || (c->type & (WINDOW_TYPE_DONT_PLACE | WINDOW_TYPE_DIALOG)) || clientIsTransient (c))
     {
         if (!position && clientIsTransient (c) && (c2 = clientGetTransient (c)))
@@ -684,8 +682,7 @@
             {
                 msx = frameX (c) + (frameWidth (c) / 2);
                 msy = frameY (c) + (frameHeight (c) / 2);
-                monitor_nbr = myScreenFindMonitorAtPoint (screen_info, msx, msy);
-                gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
+                myScreenFindMonitorAtPoint (screen_info, msx, msy, &rect);
             }
         }
         if (CONSTRAINED_WINDOW (c))
@@ -761,7 +758,6 @@
     unsigned short mask;
     int i, cx, cy, full_x, full_y, full_w, full_h;
     int tmp_x, tmp_y, tmp_w, tmp_h;
-    gint monitor_nbr;
 
     g_return_if_fail (c != NULL);
 
@@ -888,8 +884,7 @@
     cx = tmp_x + (tmp_w / 2);
     cy = tmp_y + (tmp_h / 2);
 
-    monitor_nbr = myScreenFindMonitorAtPoint (screen_info, cx, cy);
-    gdk_screen_get_monitor_geometry (screen_info->gscr, monitor_nbr, &rect);
+    myScreenFindMonitorAtPoint (screen_info, cx, cy, &rect);
 
     full_x = MAX (screen_info->params->xfwm_margins[STRUTS_LEFT], rect.x);
     full_y = MAX (screen_info->params->xfwm_margins[STRUTS_TOP], rect.y);

Modified: xfwm4/trunk/src/screen.c
===================================================================
--- xfwm4/trunk/src/screen.c	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/screen.c	2009-01-18 21:42:47 UTC (rev 29274)
@@ -221,10 +221,6 @@
     screen_info->key_grabs = 0;
     screen_info->pointer_grabs = 0;
 
-    screen_info->cache_monitor = -1;
-    screen_info->cache_x = 0;
-    screen_info->cache_y =0;
-
     getHint (display_info, screen_info->xroot, NET_SHOWING_DESKTOP, &desktop_visible);
     screen_info->show_desktop = (desktop_visible != 0);
 
@@ -314,6 +310,8 @@
         xfwmPixmapInit (screen_info, &screen_info->top[i][INACTIVE]);
     }
 
+    myScreenInvalidateMonitorCache (screen_info);
+
     return (screen_info);
 }
 
@@ -566,46 +564,53 @@
     return NULL;
 }
 
+void
+myScreenInvalidateMonitorCache (ScreenInfo *screen_info)
+{
+    g_return_if_fail (screen_info != NULL);
+
+    screen_info->cache_monitor.x = -1;
+    screen_info->cache_monitor.y = -1;
+    screen_info->cache_monitor.width = -1;
+    screen_info->cache_monitor.height = -1;
+}
+
 /*
    gdk_screen_get_monitor_at_point () doesn't give accurate results
    when the point is off screen, use my own implementation from xfce 3
  */
-gint
-myScreenFindMonitorAtPoint (ScreenInfo *screen_info, gint x, gint y)
+void
+myScreenFindMonitorAtPoint (ScreenInfo *screen_info, gint x, gint y, GdkRectangle *rect)
 {
-    gint dx, dy, center_x, center_y;
+    gint dx, dy, center_x, center_y, num_monitors, i;
     guint32 distsquare, min_distsquare;
-    gint num_monitors, nearest_monitor, i;
-    GdkRectangle monitor;
+    GdkRectangle monitor, nearest_monitor = { 0, 0, 0, 0 };
 
-    g_return_val_if_fail (screen_info != NULL, 0);
-    g_return_val_if_fail (GDK_IS_SCREEN (screen_info->gscr), 0);
+    g_return_if_fail (screen_info != NULL);
+    g_return_if_fail (rect != NULL);
+    g_return_if_fail (GDK_IS_SCREEN (screen_info->gscr));
 
     /* Cache system */
-    if ((screen_info->cache_monitor >= 0) &&
-        (x == screen_info->cache_x) && (y == screen_info->cache_y))
+    if ((x >= screen_info->cache_monitor.x) && (x < screen_info->cache_monitor.x + screen_info->cache_monitor.width) &&
+        (y >= screen_info->cache_monitor.y) && (y < screen_info->cache_monitor.y + screen_info->cache_monitor.height))
     {
-        return (screen_info->cache_monitor);
+        *rect = screen_info->cache_monitor;
+        return;
     }
 
-    screen_info->cache_x = x;
-    screen_info->cache_y = y;
+    min_distsquare = G_MAXUINT32;
+    num_monitors = gdk_screen_get_n_monitors (screen_info->gscr);
 
-    /* No monitor has been eligible, use the closest one */
-
-    min_distsquare = ((guint32) 0xffffffff);
-    nearest_monitor = 0;
-
-    num_monitors = gdk_screen_get_n_monitors (screen_info->gscr);
     for (i = 0; i < num_monitors; i++)
     {
         gdk_screen_get_monitor_geometry (screen_info->gscr, i, &monitor);
 
-        if ((x >= monitor.x) && (x < monitor.x + monitor.width) &&
+        if ((x >= monitor.x) && (x < (monitor.x + monitor.width)) &&
             (y >= monitor.y) && (y < (monitor.y + monitor.height)))
         {
-            screen_info->cache_monitor = i;
-            return i;
+            screen_info->cache_monitor = monitor;
+            *rect = screen_info->cache_monitor;
+            return;
         }
 
         center_x = monitor.x + (monitor.width / 2);
@@ -619,10 +624,10 @@
         if (distsquare < min_distsquare)
         {
             min_distsquare = distsquare;
-            nearest_monitor = i;
+            nearest_monitor = monitor;
         }
     }
 
     screen_info->cache_monitor = nearest_monitor;
-    return (nearest_monitor);
+    *rect = screen_info->cache_monitor;
 }

Modified: xfwm4/trunk/src/screen.h
===================================================================
--- xfwm4/trunk/src/screen.h	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/screen.h	2009-01-18 21:42:47 UTC (rev 29274)
@@ -116,9 +116,7 @@
     int previous_ws;
 
     /* Monitor search caching */
-    gint cache_monitor;
-    gint cache_x;
-    gint cache_y;
+    GdkRectangle cache_monitor;
 
     /* Workspace definitions */
     int workspace_count;
@@ -215,8 +213,10 @@
 Client                  *myScreenGetClientFromWindow            (ScreenInfo *,
                                                                  Window,
                                                                  unsigned short);
-gint                    myScreenFindMonitorAtPoint              (ScreenInfo *,
+void                     myScreenInvalidateMonitorCache         (ScreenInfo *);
+void                     myScreenFindMonitorAtPoint             (ScreenInfo *,
                                                                  gint,
-                                                                 gint);
+                                                                 gint,
+                                                                 GdkRectangle *);
 
 #endif /* INC_SCREEN_H */

Modified: xfwm4/trunk/src/tabwin.c
===================================================================
--- xfwm4/trunk/src/tabwin.c	2009-01-18 18:07:18 UTC (rev 29273)
+++ xfwm4/trunk/src/tabwin.c	2009-01-18 21:42:47 UTC (rev 29274)
@@ -201,7 +201,6 @@
     unsigned int grid_rows;
     int i, packpos;
     int msx, msy;
-    gint monitor;
 
     g_return_val_if_fail (current != NULL, NULL);
 
@@ -217,8 +216,7 @@
     g_return_val_if_fail (n_clients > 0, NULL);
 
     getMouseXY (screen_info, screen_info->xroot, &msx, &msy);
-    monitor = myScreenFindMonitorAtPoint (screen_info, msx, msy);
-    gdk_screen_get_monitor_geometry (scr, monitor, &monitor_sz);
+    myScreenFindMonitorAtPoint (screen_info, msx, msy, &monitor_sz);
 
     /* add the width of the border on each side */
     grid_cols = (monitor_sz.width / (WIN_ICON_SIZE + 2 * WIN_ICON_BORDER)) * 0.75;




More information about the Xfce4-commits mailing list