From 499d5e86944275891f9addcb0af90bf0b532b174 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 19 Mar 2020 13:16:47 -0400 Subject: [PATCH] implemented switch to monocled mode, swapping through monocled clients, and added todos for various actions that still need to be implemented --- anvil.h | 2 ++ keys.c | 3 +++ mons.c | 17 +++++++++++++++-- mouse.c | 11 ++++++++++- tile.c | 30 ++++++++++++++++++++++++++++-- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/anvil.h b/anvil.h index 2818d8b..7d3abf9 100644 --- a/anvil.h +++ b/anvil.h @@ -179,8 +179,10 @@ void mouse_drag(XMotionEvent* ev, Location* loc); /* tile.c */ void monocled_add(Monitor* mon, Column* col, Client* c); void monocled_del(Monitor* mon, Column* col, Client* c); +void monocled_set(Monitor* mon, Column* col, Client* c); void stacked_add(Monitor* mon, Column* col, Client* c); void stacked_del(Monitor* mon, Column* col, Client* c); +void stacked_set(Monitor* mon, Column* col, Client* c); /* error.c */ extern int (*error_default)(Display* disp, XErrorEvent* ev); diff --git a/keys.c b/keys.c index 18018d1..887208c 100644 --- a/keys.c +++ b/keys.c @@ -45,6 +45,9 @@ static char* pickexec[] = { "pickexec", NULL }; static char* terminal[] = { "xterm", NULL }; static char* locker[] = { "slock", NULL }; +/* TODO: Add shortcuts to add/del columns and resize them */ +/* TODO: Add shortcuts to transfer windows between monitors */ +/* TODO: Add shortcuts to toggle between tiled and floating */ static Key keys[] = { { MODKEY|ShiftMask, XK_q, quit, { 0 } }, { MODKEY, XK_p, runcmd, { .cmd = pickexec } }, diff --git a/mons.c b/mons.c index 914767c..08fdacd 100644 --- a/mons.c +++ b/mons.c @@ -50,13 +50,25 @@ void mons_layer(Monitor* mon) wins = realloc(wins, ++nwins * sizeof(Window)); wins[nwins-1] = c->frame; } + /* add in the monocled windows first */ + for (Column* col = mon->cspace->columns; col; col = col->next) + { + if (col->focused) + { + wins = realloc(wins, ++nwins * sizeof(Window)); + wins[nwins-1] = col->focused->frame; + } + } /* now lower all of the tiled windows */ for (Column* col = mon->cspace->columns; col; col = col->next) { for (Client* c = col->clients; c; c = c->next) { - wins = realloc(wins, ++nwins * sizeof(Window)); - wins[nwins-1] = c->frame; + if (col->focused != c) + { + wins = realloc(wins, ++nwins * sizeof(Window)); + wins[nwins-1] = c->frame; + } } } if (nwins) @@ -64,6 +76,7 @@ void mons_layer(Monitor* mon) XRestackWindows(X.disp, wins, nwins); XSync(X.disp, False); } + xfree(wins); } /* adds a new client to the most appropriate monitor */ diff --git a/mouse.c b/mouse.c index 7c35742..8773d1d 100644 --- a/mouse.c +++ b/mouse.c @@ -1,5 +1,8 @@ #include "anvil.h" +/* TODO: warp the mouse to titlebar on various locations */ +/* TODO: make sure mouse warps to the correct titlebar and floating windows don't get in the way */ + static inline int PRESSED(int mods, int btn) { return ((mods & (1 << (btn + 7))) == (1 << (btn + 7))); @@ -34,7 +37,7 @@ static void monocled_click(XButtonEvent* ev, Location* loc) { if (ev->button == Button1) { - puts("switch to expanded"); + stacked_set(loc->monitor, loc->column, loc->client); } else if (ev->button == Button2) { @@ -49,6 +52,7 @@ static void monocled_click(XButtonEvent* ev, Location* loc) for (tail = loc->column->clients; tail && tail->next; tail = tail->next); client->next = NULL; tail->next = client; + monocled_set(loc->monitor, loc->column, loc->column->clients); } } mons_layer(loc->monitor); @@ -56,10 +60,15 @@ static void monocled_click(XButtonEvent* ev, Location* loc) static void stacked_click(XButtonEvent* ev, Location* loc) { + /* TODO: handle button 1 drag to resize, reposition, and move windows */ if (ev->button == Button2) { client_close(loc->client); } + else if (ev->button == Button3) + { + monocled_set(loc->monitor, loc->column, loc->client); + } } void mouse_click(XButtonEvent* ev, Location* loc) diff --git a/tile.c b/tile.c index e2b2ce6..1432c0f 100644 --- a/tile.c +++ b/tile.c @@ -16,8 +16,25 @@ void monocled_add(Monitor* mon, Column* col, Client* c) void monocled_del(Monitor* mon, Column* col, Client* c) { - (void)mon; col->clients = delclient(col->clients, c); + col->focused = col->clients; + c = col->clients; + if (c) + { + coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h)); + client_adjust(c); + } +} + +void monocled_set(Monitor* mon, Column* col, Client* c) +{ + col->clients = delclient(col->clients, c); + c->next = col->clients; + col->clients = c; + col->focused = c; + coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h)); + client_adjust(c); + mons_layer(mon); } void stacked_add(Monitor* mon, Column* col, Client* c) @@ -38,8 +55,8 @@ void stacked_add(Monitor* mon, Column* col, Client* c) max->h -= max->h/2; c->next = max->next; max->next = c; - client_adjust(max); client_adjust(c); + client_adjust(max); } else { @@ -71,3 +88,12 @@ void stacked_del(Monitor* mon, Column* col, Client* c) } } +void stacked_set(Monitor* mon, Column* col, Client* c) +{ + (void)mon, (void)col, (void)c; + puts("switching to stacked mode"); + /* TODO: implement switch back to stacked mode */ +} + + + -- 2.52.0