From 37d7a7bb48362926cd3eda5c3c1d04dbf27952f5 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 21 Mar 2020 00:19:37 -0400 Subject: [PATCH] refactored and added logic to detect difference between drag on frame and titlebar in tiled mode --- anvil.h | 4 +++- client.c | 9 ++++----- mouse.c | 18 +++++++++++++----- tile.c | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/anvil.h b/anvil.h index 466e1ea..a4719d2 100644 --- a/anvil.h +++ b/anvil.h @@ -23,7 +23,9 @@ enum { M_INIT, M_IDLE, - M_RESIZE + M_RESIZE, + M_TILE_RESIZE, + M_COL_RESIZE }; typedef struct { diff --git a/client.c b/client.c index 79c1dfd..c2bbcdc 100644 --- a/client.c +++ b/client.c @@ -41,8 +41,7 @@ Client* client_add(Window win, XWindowAttributes* attr) wa.event_mask = EnterWindowMask | PropertyChangeMask | FocusChangeMask; wa.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; XChangeWindowAttributes(X.disp, c->win, CWEventMask | CWDontPropagate, &wa); - XReparentWindow(X.disp, c->win, c->frame, - BORDER_WIDTH, BORDER_WIDTH + TITLE_HEIGHT); + XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT); /* Map the window and draw the frame */ XAddToSaveSet(X.disp, c->win); @@ -105,11 +104,11 @@ void client_resize(Client* c, int xdiff, int ydiff) { c->w += xdiff; c->h += ydiff; - if (c->w < TITLE_HEIGHT+BORDER_WIDTH) c->w = TITLE_HEIGHT+BORDER_WIDTH; - if (c->h < TITLE_HEIGHT+BORDER_WIDTH) c->h = TITLE_HEIGHT+BORDER_WIDTH; + if (c->w < MIN_HEIGHT) c->w = MIN_HEIGHT; + if (c->h < MIN_HEIGHT) c->h = MIN_HEIGHT; if (c->flags & F_SHADED) { - XResizeWindow(X.disp, c->frame, c->w, TITLE_HEIGHT+BORDER_WIDTH); + XResizeWindow(X.disp, c->frame, c->w, MIN_HEIGHT); } else { diff --git a/mouse.c b/mouse.c index 30b5059..b02a2c5 100644 --- a/mouse.c +++ b/mouse.c @@ -10,7 +10,7 @@ static inline int PRESSED(int mods, int btn) static void float_click(XButtonEvent* ev, Location* loc) { - if ((ev->button == Button1) && (ev->y > (TITLE_HEIGHT + BORDER_WIDTH))) + if ((ev->button == Button1) && (ev->y > MIN_HEIGHT)) { X.mode = M_RESIZE; warp_mouse(loc->client); @@ -60,7 +60,11 @@ static void monocled_click(XButtonEvent* ev, Location* loc) static void stacked_click(XButtonEvent* ev, Location* loc) { - if (ev->button == Button2) + if (ev->button == Button1) + { + X.mode = (ev->y > MIN_HEIGHT ? M_COL_RESIZE : M_TILE_RESIZE); + } + else if (ev->button == Button2) { client_close(loc->client); } @@ -104,13 +108,17 @@ static void float_drag(XMotionEvent* ev, Location* loc) void mouse_up(XButtonEvent* ev, Location* loc) { - (void)ev, (void)loc; /* TODO: handle button 1 drag to resize, reposition, and move windows */ - /* TODO: check if we clicked in frame originally or if we clicked in titlebar */ - if (loc->column && !loc->column->focused) + if (X.mode == M_TILE_RESIZE) { stacked_addheight(loc->monitor, loc->column, loc->client, ev->y_root - X.start_y); } + else if (X.mode == M_COL_RESIZE) + { + puts("resize column"); + /* TODO: resize column */ + } + X.mode = M_IDLE; } static void monocled_drag(XMotionEvent* ev, Location* loc) diff --git a/tile.c b/tile.c index 9cce23d..cc0c7ae 100644 --- a/tile.c +++ b/tile.c @@ -102,7 +102,7 @@ void stacked_addheight(Monitor* mon, Column* col, Client* c, int amount) if (prev) { amount = (amount == 0 ? (int)(-c->h * 0.25) : amount); - int miny = (prev->y + TITLE_HEIGHT+BORDER_WIDTH); + int miny = (prev->y + MIN_HEIGHT); int maxy = min((mon->y + mon->h) , (c->y + c->h)) - MIN_HEIGHT; c->y = max(miny, min(maxy, c->y + amount)); prev->h = c->y - prev->y; -- 2.52.0