From ea91fb0559fcb6daf7185d63292b3fca7db91c6d Mon Sep 17 00:00:00 2001 From: UserXGnu Date: Sat, 10 Oct 2020 21:15:33 +0200 Subject: [PATCH] Adds toggleble attachaside feature --- config.def.h | 2 ++ instantwm.c | 37 ++++++++++++++++++++++++++++++++++--- instantwm.h | 4 ++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/config.def.h b/config.def.h index 46e7a1c6..92eb97dd 100644 --- a/config.def.h +++ b/config.def.h @@ -13,6 +13,7 @@ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ static const char *fonts[] = {"Cantarell-Regular:size=12", "Fira Code Nerd Font:size=12"}; +static int isattachaside = 0; static int barheight; static char xresourcesfont[30]; @@ -327,6 +328,7 @@ static Key keys[] = { {MODKEY | ShiftMask | Mod1Mask, XK_d, toggledoubledraw, {0} }, {MODKEY|ShiftMask, XK_w, warpfocus, {0} }, {MODKEY|Mod1Mask, XK_w, centerwindow, {0} }, + {MODKEY|Mod1Mask, XK_a, toggleattachaside, {0} }, {MODKEY|ShiftMask|ControlMask, XK_s, toggleshowtags, { .ui = 2 } }, {MODKEY, XK_i, incnmaster, {.i = +1}}, {MODKEY, XK_d, incnmaster, {.i = -1}}, diff --git a/instantwm.c b/instantwm.c index b7ce5c75..274a5941 100644 --- a/instantwm.c +++ b/instantwm.c @@ -757,6 +757,21 @@ attach(Client *c) c->mon->clients = c; } +void +attachaside(Client *c) { + if (!isattachaside) { + attach(c); + return; + } + Client *at = nexttagged(c); + if(!at) { + attach(c); + return; + } + c->next = at->next; + at->next = c; +} + void attachstack(Client *c) { @@ -2174,7 +2189,7 @@ manage(Window w, XWindowAttributes *wa) c->isfloating = c->oldstate = trans != None || c->isfixed; if (c->isfloating) XRaiseWindow(dpy, c->win); - attach(c); + attachaside(c); attachstack(c); XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (unsigned char *) &(c->win), 1); @@ -3176,6 +3191,16 @@ void shutkill(const Arg *arg) { killclient(arg); } +Client * +nexttagged(Client *c) { + Client *walked = c->mon->clients; + for(; + walked && (walked->isfloating || !ISVISIBLEONTAG(walked, c->tags)); + walked = walked->next + ); + return walked; +} + Client * nexttiled(Client *c) { @@ -3725,7 +3750,7 @@ sendmon(Client *c, Monitor *m) detachstack(c); c->mon = m; c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ - attach(c); + attachaside(c); attachstack(c); focus(NULL); arrange(NULL); @@ -4317,6 +4342,12 @@ tagtoright(const Arg *arg) { } +// toggle attach new clients to stack area +void +toggleattachaside(void) { + isattachaside = !isattachaside; +} + // toggle tag icon view void togglealttag(const Arg *arg) @@ -4969,7 +5000,7 @@ updategeom(void) m->clients = c->next; detachstack(c); c->mon = mons; - attach(c); + attachaside(c); attachstack(c); } if (m == selmon) diff --git a/instantwm.h b/instantwm.h index bbcaa00a..ce2f4e5c 100644 --- a/instantwm.h +++ b/instantwm.h @@ -23,6 +23,7 @@ #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]) || C->issticky) +#define ISVISIBLEONTAG(C, T) ((C->tags & T)) #define HIDDEN(C) ((getstate(C->win) == IconicState)) #define LENGTH(X) (sizeof X / sizeof X[0]) #define MOUSEMASK (BUTTONMASK|PointerMotionMask) @@ -189,6 +190,7 @@ void arrange(Monitor *m); void arrangemon(Monitor *m); void resetcursor(); void attach(Client *c); +void attachaside(Client *c); void attachstack(Client *c); void buttonpress(XEvent *e); void checkotherwm(void); @@ -244,6 +246,7 @@ void moveresize(const Arg *arg); void distributeclients(const Arg *arg); void keyresize(const Arg *arg); void centerwindow(); +Client *nexttagged(Client *c); Client *nexttiled(Client *c); void pop(Client *); void shutkill(const Arg *arg); @@ -292,6 +295,7 @@ void tagtoleft(const Arg *arg); void tagtoright(const Arg *arg); void uppress(const Arg *arg); void downpress(const Arg *arg); +void toggleattachaside(void); void togglealttag(const Arg *arg); void alttabfree(const Arg *arg); void toggleanimated(const Arg *arg);