From c7ba95e79dfbb2e3a186b76ecb2754f6e9339d8c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 22 Aug 2009 07:49:28 +0200 Subject: [PATCH] Implement resizing floating clients with Mod1 + right mouse button --- include/floating.h | 9 +++++++++ src/floating.c | 29 ++++++++++++++++++++++++++++- src/handlers.c | 9 ++++++++- src/manage.c | 5 +++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/floating.h b/include/floating.h index 6169d7b4..5cf3dedd 100644 --- a/include/floating.h +++ b/include/floating.h @@ -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. * diff --git a/src/floating.c b/src/floating.c index 04d99f6c..39414545 100644 --- a/src/floating.c +++ b/src/floating.c @@ -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 diff --git a/src/handlers.c b/src/handlers.c index 2f98f019..5ffd54f9 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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; } } diff --git a/src/manage.c b/src/manage.c index eb9112ec..8c05b607 100644 --- a/src/manage.c +++ b/src/manage.c @@ -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); -- 2.39.5