Skip to content

Adds togglable attachaside feature #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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}},
Expand Down
37 changes: 34 additions & 3 deletions instantwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -4969,7 +5000,7 @@ updategeom(void)
m->clients = c->next;
detachstack(c);
c->mon = mons;
attach(c);
attachaside(c);
attachstack(c);
}
if (m == selmon)
Expand Down
4 changes: 4 additions & 0 deletions instantwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down