From 70e6fc4f0d9696a2a637e08b6067e591211ecc04 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 2 Apr 2020 15:25:15 -0400 Subject: [PATCH] added mouse action to toggle between floating and tiled --- anvil.c | 8 ++++---- anvil.h | 6 ++++-- client.c | 4 ++-- mons.c | 26 ++++++++++++++++++-------- mouse.c | 6 +++--- tile.c | 1 + 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/anvil.c b/anvil.c index f9d5f00..91372f9 100644 --- a/anvil.c +++ b/anvil.c @@ -135,14 +135,14 @@ static void xdestroynotify(XEvent* e) { XDestroyWindowEvent* ev = &(e->xdestroywindow); printf("DESTROY(w: 0x%lx)\n", ev->window); - Client* c = client_get(ev->window, NULL); - if (c) + Location loc = {0}; + if (mons_find(ev->window, &loc)) { - if (Focused == c) + if (Focused == loc.client) { Focused = NULL; } - mons_delclient(c); + mons_delclient(&loc); } } diff --git a/anvil.h b/anvil.h index b7ea56a..6035295 100644 --- a/anvil.h +++ b/anvil.h @@ -48,7 +48,8 @@ typedef struct { enum { F_WM_DELETE = (1 << 0), F_DIALOG = (1 << 1), - F_SHADED = (1 << 2), + F_FLOATING = (1 << 2), + F_SHADED = (1 << 3), }; typedef struct Node { @@ -136,7 +137,8 @@ extern Monitor* Monitors; void mons_init(void); void mons_layer(Monitor* mon); void mons_addclient(Client* c); -void mons_delclient(Client* c); +void mons_delclient(Location* loc); +void mons_togglefloat(Location* loc); int mons_find(Window win, Location* loc); void mons_place(Client* c); void mons_wspace(int i); diff --git a/client.c b/client.c index c06f283..8ad5ef5 100644 --- a/client.c +++ b/client.c @@ -14,7 +14,7 @@ void client_initall(void) if (XGetWindowAttributes(X.disp, wins[i], &attr) && !attr.override_redirect) { Client* c = client_add(wins[i], &attr); - c->flags |= F_DIALOG; + c->flags |= F_FLOATING; } } xfree(wins); @@ -172,7 +172,7 @@ void client_readprops(Client* c) X.disp, c->win, atom("_NET_WM_WINDOW_TYPE"), 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype); if (wintype && *wintype == atom("_NET_WM_WINDOW_TYPE_DIALOG")) { - c->flags |= F_DIALOG; + c->flags |= F_DIALOG|F_FLOATING; } xfree(wintype); diff --git a/mons.c b/mons.c index f4a00a7..69d1de9 100644 --- a/mons.c +++ b/mons.c @@ -97,16 +97,26 @@ void mons_addclient(Client* c) client_warpmouse(c); } -void mons_delclient(Client* c) +void mons_delclient(Location* loc) { - Location loc = {0}; - if (mons_find(c->win, &loc)) + remove_client(loc, loc->client); + xfree(loc->client->name); + XDestroyWindow(X.disp, loc->client->frame); + free(loc->client); +} + +void mons_togglefloat(Location* loc) +{ + remove_client(loc, loc->client); + if (loc->client->flags & (F_FLOATING)) + { + loc->client->flags &= ~F_FLOATING; + } + else { - remove_client(&loc, c); - xfree(c->name); - XDestroyWindow(X.disp, c->frame); - free(c); + loc->client->flags |= F_FLOATING; } + mons_addclient(loc->client); } int mons_find(Window win, Location* loc) @@ -415,7 +425,7 @@ static Client* client_find(Client* clients, Window win) static void add_client(Monitor* mon, Client* c, int ptrx) { - if (X.mode == M_INIT || c->flags & F_DIALOG) + if (X.mode == M_INIT || c->flags & (F_DIALOG|F_FLOATING)) { c->next = mon->cspace->floating; mon->cspace->floating = c; diff --git a/mouse.c b/mouse.c index f2d9611..cd940df 100644 --- a/mouse.c +++ b/mouse.c @@ -23,7 +23,7 @@ static void float_click(XButtonEvent* ev, Location* loc) } else if (ev->state & (MODKEY|ShiftMask)) { - puts("to tile mode"); + mons_togglefloat(loc); } else { @@ -58,7 +58,7 @@ static void monocled_click(XButtonEvent* ev, Location* loc) } else if (ev->state & (MODKEY|ShiftMask)) { - puts("to float mode"); + mons_togglefloat(loc); } else { @@ -94,7 +94,7 @@ static void stacked_click(XButtonEvent* ev, Location* loc) } else if (ev->state & (MODKEY|ShiftMask)) { - puts("to float mode"); + mons_togglefloat(loc); } else { diff --git a/tile.c b/tile.c index c58b28e..43cc049 100644 --- a/tile.c +++ b/tile.c @@ -48,6 +48,7 @@ void monocled_set(Monitor* mon, Column* col, Client* c) col->clients = c; col->focused = c; coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h)); + client_setshade(c, 0); client_adjust(c); mons_layer(mon); } -- 2.52.0