From 137f3300f05cf44b759df074eba0a17213f6c2db Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 18 Mar 2020 22:11:47 -0400 Subject: [PATCH] added shading logic and fixed resizing --- anvil.c | 2 +- anvil.h | 2 ++ client.c | 32 +++++++++++++++++++++++++++----- mouse.c | 16 ++++++++++------ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/anvil.c b/anvil.c index bd74e7a..95feb8e 100644 --- a/anvil.c +++ b/anvil.c @@ -87,7 +87,7 @@ static void xunmapnotify(XEvent* e) { XUnmapEvent* ev = &(e->xunmap); Client* c = client_get(ev->window, NULL); - if (c && c->win == ev->window) + if (c && c->win == ev->window && !(c->flags & F_SHADED)) { XUnmapWindow(X.disp, c->frame); } diff --git a/anvil.h b/anvil.h index 4349b14..2818d8b 100644 --- a/anvil.h +++ b/anvil.h @@ -82,6 +82,7 @@ typedef struct { enum { F_WM_DELETE = (1 << 0), F_DIALOG = (1 << 1), + F_SHADED = (1 << 2), }; typedef struct Client { @@ -169,6 +170,7 @@ void client_close(Client* c); void client_focus(Client* c); void client_show(Client* c, int show); void client_readprops(Client* c); +void client_shade(Client* c); /* mouse.c */ void mouse_click(XButtonEvent* ev, Location* loc); diff --git a/client.c b/client.c index 0d78e9f..5d1d93b 100644 --- a/client.c +++ b/client.c @@ -108,11 +108,18 @@ void client_resize(Client* c, int xdiff, int ydiff) c->h += ydiff; if (c->w < 50) c->w = 50; if (c->h < 50) c->h = 50; - XResizeWindow(X.disp, c->frame, c->w, c->h); - XResizeWindow(X.disp, c->win, - c->w - 2*BORDER_WIDTH - 2, - c->h - 2*BORDER_WIDTH - TITLE_HEIGHT - 2 - ); + if (c->flags & F_SHADED) + { + XResizeWindow(X.disp, c->frame, c->w, TITLE_HEIGHT+BORDER_WIDTH); + } + else + { + XResizeWindow(X.disp, c->frame, c->w, c->h); + XResizeWindow(X.disp, c->win, + c->w - 2*BORDER_WIDTH - 2, + c->h - 2*BORDER_WIDTH - TITLE_HEIGHT - 2 + ); + } mons_place(c); } @@ -181,3 +188,18 @@ void client_readprops(Client* c) } xfree(protos); } + +void client_shade(Client* c) +{ + if (c->flags & F_SHADED) + { + c->flags &= ~F_SHADED; + XMapWindow(X.disp, c->win); + } + else + { + c->flags |= F_SHADED; + XUnmapWindow(X.disp, c->win); + } + client_adjust(c); +} diff --git a/mouse.c b/mouse.c index af0ae57..7c35742 100644 --- a/mouse.c +++ b/mouse.c @@ -7,10 +7,19 @@ static inline int PRESSED(int mods, int btn) static void float_click(XButtonEvent* ev, Location* loc) { - if (ev->button == Button2) + if ((ev->button == Button1) && (ev->y > (TITLE_HEIGHT + BORDER_WIDTH))) + { + X.mode = M_RESIZE; + warp_mouse(loc->client); + } + else if (ev->button == Button2) { client_close(loc->client); } + else if (ev->button == Button3) + { + client_shade(loc->client); + } else if (ev->button == Button4) { mons_lower(loc->monitor, loc->client); @@ -18,11 +27,6 @@ static void float_click(XButtonEvent* ev, Location* loc) else if (ev->button == Button5) { mons_raise(loc->monitor, loc->client); - if (ev->y > (TITLE_HEIGHT + BORDER_WIDTH)) - { - X.mode = M_RESIZE; - warp_mouse(loc->client); - } } } -- 2.52.0