]> git.sur5r.net Git - i3/i3/commitdiff
Implement resizing floating clients with Mod1 + right mouse button
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 22 Aug 2009 05:49:28 +0000 (07:49 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 22 Aug 2009 05:49:28 +0000 (07:49 +0200)
include/floating.h
src/floating.c
src/handlers.c
src/manage.c

index 6169d7b4057b0c2e5405f50f64b2b160a2d85169..5cf3deddc12980b849923aa15189f5b5316cac81 100644 (file)
@@ -55,6 +55,15 @@ int floating_border_click(xcb_connection_t *conn, Client *client,
 void floating_drag_window(xcb_connection_t *conn, Client *client,
                           xcb_button_press_event_t *event);
 
+/**
+ * Called when the user right-clicked on the titlebar of a floating window to
+ * resize it.
+ * Calls the drag_pointer function with the resize_window callback
+ *
+ */
+void floating_resize_window(xcb_connection_t *conn, Client *client,
+                            xcb_button_press_event_t *event);
+
 /**
  * Changes focus in the given direction for floating clients.
  *
index 04d99f6c5a08d3f258bdc703a6e8481c7549fa57..394145457111cf7a7d167fcfd3385b57ae9ea5a9 100644 (file)
@@ -255,10 +255,37 @@ void floating_drag_window(xcb_connection_t *conn, Client *client, xcb_button_pre
                 /* fake_absolute_configure_notify flushes */
         }
 
-
         drag_pointer(conn, client, event, XCB_NONE, BORDER_TOP /* irrelevant */, drag_window_callback);
 }
 
+/*
+ * Called when the user right-clicked on the titlebar of a floating window to
+ * resize it.
+ * Calls the drag_pointer function with the resize_window callback
+ *
+ */
+void floating_resize_window(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) {
+        LOG("floating_resize_window\n");
+
+        void resize_window_callback(Rect *old_rect, uint32_t new_x, uint32_t new_y) {
+                int32_t new_width = old_rect->width + (new_x - event->root_x);
+                int32_t new_height = old_rect->height + (new_y - event->root_y);
+                /* Obey minimum window size */
+                if (new_width < 75 || new_height < 50)
+                        return;
+
+                /* Reposition the client correctly while moving */
+                client->rect.width = new_width;
+                client->rect.height = new_height;
+
+                /* resize_client flushes */
+                resize_client(conn, client);
+        }
+
+        drag_pointer(conn, client, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback);
+}
+
+
 /*
  * This function grabs your pointer and lets you drag stuff around (borders).
  * Every time you move your mouse, an XCB_MOTION_NOTIFY event will be received
index 2f98f019a673f8bc834e0385c6cbae5a1faf4f36..5ffd54f943f4cb98bbaf6a248694184bdce1f7ad 100644 (file)
@@ -380,7 +380,14 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_
                         return 1;
                 }
                 if (client_is_floating(client)) {
-                        floating_drag_window(conn, client, event);
+                        LOG("button %d pressed\n", event->detail);
+                        if (event->detail == 1) {
+                                LOG("left mouse button, dragging\n");
+                                floating_drag_window(conn, client, event);
+                        } else if (event->detail == 3) {
+                                LOG("right mouse button\n");
+                                floating_resize_window(conn, client, event);
+                        }
                         return 1;
                 }
         }
index eb9112ecb6caefc2e8d5b34edf497bb8d8611116..8c05b607ca504d1083576c85dd6bcf17dbfe9441 100644 (file)
@@ -233,6 +233,11 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
                         XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, root, XCB_NONE,
                         1 /* left mouse button */, XCB_MOD_MASK_1);
 
+        xcb_grab_button(conn, false, child, XCB_EVENT_MASK_BUTTON_PRESS,
+                        XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, root, XCB_NONE,
+                        3 /* right mouse button */, XCB_MOD_MASK_1);
+
+
         /* Get _NET_WM_WINDOW_TYPE (to see if it’s a dock) */
         xcb_atom_t *atom;
         xcb_get_property_reply_t *preply = xcb_get_property_reply(conn, wm_type_cookie, NULL);