From 37db4e04780b265cdd11eea2053a9ea70b7f9b06 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 11 Mar 2020 13:02:34 -0400 Subject: [PATCH] added logic to resize existing windows --- anvil.c | 34 +++++++++++++++++++++++++++------- anvil.h | 2 ++ client.c | 12 ++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/anvil.c b/anvil.c index b32b1a0..e74254b 100644 --- a/anvil.c +++ b/anvil.c @@ -19,13 +19,17 @@ static void xbtnpress(XEvent* e) { if (ev->button == Button1) { client_raise(c); - if (ev->y < (TITLE_HEIGHT + BORDER_WIDTH)) { - X.start_x = ev->x_root; - X.start_y = ev->y_root; - } - else + X.start_x = ev->x_root; + X.start_y = ev->y_root; + if (ev->y > (TITLE_HEIGHT + BORDER_WIDTH)) { - /* TODO: warp the pointer and resize the window*/ + X.reshaping = 1; + XWarpPointer(X.disp, None, ev->window, 0, 0, 0, 0, + c->w + 2*BORDER_WIDTH, + c->h + 2*BORDER_WIDTH + TITLE_HEIGHT + ); + X.start_x = c->x + c->w + 2*BORDER_WIDTH; + X.start_y = c->y + c->h + 2*BORDER_WIDTH + TITLE_HEIGHT; } } else if (ev->button == Button2) { client_close(c); @@ -38,6 +42,12 @@ static void xbtnpress(XEvent* e) static void xbtnrelease(XEvent* e) { (void)e; + X.reshaping = 0; +} + +static inline int PRESSED(int mods, int btn) +{ + return ((mods & (1 << (btn + 7))) == (1 << (btn + 7))); } static void xbtnmotion(XEvent* e) @@ -47,7 +57,17 @@ static void xbtnmotion(XEvent* e) if (c && (ev->window == c->frame)) { /* TODO: only move window if Button1 held */ - client_move(c, ev->x_root - X.start_x, ev->y_root - X.start_y); + if (PRESSED(ev->state, Button1)) + { + if (!X.reshaping) + { + client_move(c, ev->x_root - X.start_x, ev->y_root - X.start_y); + } + else + { + client_resize(c, ev->x_root - X.start_x, ev->y_root - X.start_y); + } + } } X.start_x = ev->x_root; X.start_y = ev->y_root; diff --git a/anvil.h b/anvil.h index 3988f32..ed23540 100644 --- a/anvil.h +++ b/anvil.h @@ -20,6 +20,7 @@ typedef struct { Window root; unsigned long black, white, gray; int start_x, start_y; + int reshaping; void (*eventfns[LASTEvent])(XEvent*); } XConf; @@ -70,6 +71,7 @@ Client* client_get(Window w); void client_raise(Client* c); void client_lower(Client* c); void client_move(Client* c, int xdiff, int ydiff); +void client_resize(Client* c, int xdiff, int ydiff); void client_close(Client* c); void client_focus(Client* c); diff --git a/client.c b/client.c index fe98ed5..88a3afe 100644 --- a/client.c +++ b/client.c @@ -119,6 +119,18 @@ void client_move(Client* c, int xdiff, int ydiff) XSync(X.disp, False); } +void client_resize(Client* c, int xdiff, int ydiff) +{ + c->w += xdiff; + c->h += ydiff; + if (c->w < 50) c->w = 50; + if (c->h < 50) c->h = 50; + XResizeWindow(X.disp, c->win, c->w, c->h); + XResizeWindow(X.disp, c->frame, + c->w + 2*BORDER_WIDTH, + c->h + 2*BORDER_WIDTH + TITLE_HEIGHT); +} + void client_close(Client* c) { /* TODO: handle wm_delete client message here */ -- 2.52.0