Clean up the FillToEdge action implementation
[dana/openbox.git] / openbox / moveresize.c
index 2f68395..d12a64d 100644 (file)
@@ -21,6 +21,7 @@
 #include "framerender.h"
 #include "screen.h"
 #include "client.h"
+#include "focus.h"
 #include "frame.h"
 #include "openbox.h"
 #include "resist.h"
@@ -63,8 +64,8 @@ static ObDirection edge_warp_dir = -1;
 static gboolean edge_warp_odd = FALSE;
 static guint edge_warp_timer = 0;
 static ObDirection key_resize_edge = -1;
-#ifdef SYNC
 static guint waiting_for_sync;
+#ifdef SYNC
 static guint sync_timer = 0;
 #endif
 
@@ -82,6 +83,8 @@ static void client_dest(ObClient *client, gpointer data)
 {
     if (moveresize_client == client)
         moveresize_end(TRUE);
+    if (popup && client == popup->client)
+        popup->client = NULL;
 }
 
 void moveresize_startup(gboolean reconfig)
@@ -166,6 +169,7 @@ static void popup_coords(ObClient *c, const gchar *format, gint a, gint b)
 
         popup_position(popup, gravity, x, y);
     }
+    popup->client = c;
     popup_show(popup, text);
     g_free(text);
 }
@@ -262,6 +266,7 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr)
     cur_h = start_ch;
 
     moveresize_in_progress = TRUE;
+    waiting_for_sync = 0;
 
 #ifdef SYNC
     if (config_resize_redraw && !moving && obt_display_extension_sync &&
@@ -300,8 +305,6 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr)
                                             XSyncCADelta |
                                             XSyncCAEvents,
                                             &aa);
-
-        waiting_for_sync = 0;
     }
 #endif
 }
@@ -312,6 +315,7 @@ void moveresize_end(gboolean cancel)
     ungrab_pointer();
 
     popup_hide(popup);
+    popup->client = NULL;
 
     if (!moving) {
 #ifdef SYNC
@@ -582,19 +586,19 @@ static void edge_warp_move_ptr(void)
     a = screen_physical_area_all_monitors();
 
     switch (edge_warp_dir) {
-       case OB_DIRECTION_NORTH:
-           y = a->height - 1;
-           break;
-       case OB_DIRECTION_EAST:
-           x = a->x;
-           break;
-       case OB_DIRECTION_SOUTH:
-           y = a->y;
-           break;
-       case OB_DIRECTION_WEST:
-           x = a->width - 1;
-           break;
-       default:
+    case OB_DIRECTION_NORTH:
+        y = a->height - 1;
+        break;
+    case OB_DIRECTION_EAST:
+        x = a->x;
+        break;
+    case OB_DIRECTION_SOUTH:
+        y = a->y;
+        break;
+    case OB_DIRECTION_WEST:
+        x = a->width - 1;
+        break;
+    default:
         g_assert_not_reached();
     }
 
@@ -630,6 +634,10 @@ static void do_edge_warp(gint x, gint y)
 
     for (i = 0; i < screen_num_monitors; ++i) {
         const Rect *a = screen_physical_area_monitor(i);
+
+        if (!RECT_CONTAINS(*a, x, y))
+            continue;
+
         if (x == RECT_LEFT(*a)) dir = OB_DIRECTION_WEST;
         if (x == RECT_RIGHT(*a)) dir = OB_DIRECTION_EAST;
         if (y == RECT_TOP(*a)) dir = OB_DIRECTION_NORTH;
@@ -787,8 +795,13 @@ static void resize_with_keys(KeySym sym, guint state)
         else /* if (sym == XK_Up)) */
             dir = OB_DIRECTION_NORTH;
 
-        client_find_resize_directional(moveresize_client, key_resize_edge,
-                                       key_resize_edge == dir,
+        ObClientDirectionalResizeType resize_type =
+            key_resize_edge == dir ? CLIENT_RESIZE_GROW
+                                   : CLIENT_RESIZE_SHRINK;
+
+        client_find_resize_directional(moveresize_client,
+                                       key_resize_edge,
+                                       resize_type,
                                        &x, &y, &w, &h);
         dw = w - moveresize_client->area.width;
         dh = h - moveresize_client->area.height;
@@ -1084,5 +1097,9 @@ gboolean moveresize_event(XEvent *e)
         used = TRUE;
     }
 #endif
+
+    if (used && moveresize_client == focus_client)
+        event_update_user_time();
+
     return used;
 }