New patches

This commit is contained in:
Alexis Jhon Gaspar 2023-09-07 19:13:16 +08:00
parent ac35798e0a
commit f36129f156
20 changed files with 899 additions and 2136 deletions

View file

@ -39,6 +39,7 @@ or
## Current bugs
- ~~Taskbar not working properly~~ (fixed in commit [e9015f2](https://github.com/Lucas-mother3/suckless-utils/commit/e9015f2d2a09ef66f1c9e188b277c89d23635195) & [7085f9](https://github.com/Lucas-mother3/suckless-utils/commit/7085f97d80fc203d6f54d0209af07007c0347880)). Thanks, [Speedie](https://speedie.gq)!
- Unhiding a hidden window (using the show/hide function) crashes dwm
## Patching even further

View file

@ -65,6 +65,11 @@ static const Rule rules[] = {
{ "Firefox", NULL, NULL, 1 << 8, 0, 0, -1 },
};
/* window following */
#define WFACTIVE '>'
#define WFINACTIVE 'v'
#define WFDEFAULT WFINACTIVE
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
@ -73,12 +78,16 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win
static const int decorhints = 1; /* 1 means respect decoration hints */
#include "layouts.c"
#include "horizgrid.c"
#include "gaplessgrid.c"
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
{ "HHH", grid },
{ "-#-", horizgrid },
{ "###", gaplessgrid },
};
/* key definitions */
@ -113,6 +122,7 @@ static Key keys[] = {
{ Mod4Mask, XK_e, spawn, {.v = thunarcmd } },
{ Mod4Mask, XK_Print, spawn, SHCMD("maim ~/Pictures/Screenshot_$(date +%s).png") },
{ MODKEY|ShiftMask, XK_b, togglebar, {0} },
{ MODKEY|ShiftMask, XK_n, togglefollow, {0} },
{ MODKEY, XK_j, focusstackvis, {.i = +1 } },
{ MODKEY, XK_k, focusstackvis, {.i = -1 } },
{ MODKEY|ShiftMask, XK_j, focusstackhid, {.i = +1 } },
@ -128,6 +138,8 @@ static Key keys[] = {
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_g, setlayout, {.v = &layouts[3]} },
{ MODKEY|ShiftMask, XK_t, setlayout, {.v = &layouts[4]} },
{ MODKEY|ShiftMask, XK_f, setlayout, {.v = &layouts[5]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY|ShiftMask, XK_f, togglefullscr, {0} },
@ -135,10 +147,12 @@ static Key keys[] = {
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY, XK_s, show, {0} },
{ MODKEY, XK_h, hide, {0} },
{ ControlMask|ShiftMask, XK_s, show, {0} },
{ ControlMask|ShiftMask, XK_h, hide, {0} },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_h, layoutscroll, {.i = -1 } },
{ MODKEY|ShiftMask, XK_l, layoutscroll, {.i = +1 } },
{ MODKEY, XK_minus, setgaps, {.i = -1 } },
{ MODKEY, XK_equal, setgaps, {.i = +1 } },
{ MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
@ -164,6 +178,7 @@ static Button buttons[] = {
{ ClkButton, 0, Button1, spawn, {.v = dmenucmd } },
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
{ ClkFollowSymbol, 0, Button1, togglefollow, {0} },
{ ClkWinTitle, 0, Button1, togglewin, {0} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },

BIN
dwm/dwm

Binary file not shown.

165
dwm/dwm.c
View file

@ -79,7 +79,7 @@ enum { NetSupported, NetWMName, NetWMIcon, NetWMState, NetWMCheck,
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkButton, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
ClkClientWin, ClkRootWin, ClkFollowSymbol, ClkLast }; /* clicks */
typedef union {
int i;
@ -127,8 +127,10 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
typedef struct Pertag Pertag;
struct Monitor {
char ltsymbol[16];
char wfsymbol[2];
float mfact;
int nmaster;
int num;
@ -157,6 +159,8 @@ struct Monitor {
Window barwin;
Window tabwin;
const Layout *lt[2];
int ltcur; /* current layout */
Pertag *pertag;
};
typedef struct {
@ -231,6 +235,7 @@ static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
static void layoutscroll(const Arg *arg);
static void setgaps(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
@ -246,6 +251,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
static void togglefollow(const Arg *arg);
static void togglefullscr(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
@ -320,6 +326,15 @@ static Colormap cmap;
unsigned int tagw[LENGTH(tags)];
struct Pertag {
unsigned int curtag, prevtag; /* current and previous tag */
int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
};
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@ -507,6 +522,8 @@ buttonpress(XEvent *e)
arg.ui = 1 << i;
} else if (ev->x < x + blw)
click = ClkLtSymbol;
else if (ev->x < x + blw + TEXTW(selmon->wfsymbol))
click = ClkFollowSymbol;
/* 2px right padding */
else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
click = ClkStatusText;
@ -720,6 +737,7 @@ Monitor *
createmon(void)
{
Monitor *m;
unsigned int i;
m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1;
@ -728,10 +746,26 @@ createmon(void)
m->showbar = showbar;
m->topbar = topbar;
m->gappx = gappx;
m->ltcur = 0;
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
m->nTabs = 0;
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
m->pertag = ecalloc(1, sizeof(Pertag));
m->pertag->curtag = m->pertag->prevtag = 1;
for (i = 0; i <= LENGTH(tags); i++) {
m->pertag->nmasters[i] = m->nmaster;
m->pertag->mfacts[i] = m->mfact;
m->pertag->ltidxs[i][0] = m->lt[0];
m->pertag->ltidxs[i][1] = m->lt[1];
m->pertag->sellts[i] = m->sellt;
m->pertag->showbars[i] = m->showbar;
}
m->wfsymbol[0] = WFDEFAULT;
m->wfsymbol[1] = '\0';
return m;
}
@ -850,6 +884,9 @@ drawbar(Monitor *m)
drw_setscheme(drw, scheme[SchemeNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
w = TEXTW(m->wfsymbol);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->wfsymbol, 0);
if ((w = m->ww - tw - x) > bh) {
if (n > 0) {
int remainder = w % n;
@ -1219,7 +1256,16 @@ hidewin(Client *c) {
void
incnmaster(const Arg *arg)
{
unsigned int i;
selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
for(i=0; i<LENGTH(tags); ++i)
if(selmon->tagset[selmon->seltags] & 1<<i)
selmon->pertag->nmasters[i+1] = selmon->nmaster;
if(selmon->pertag->curtag == 0)
{
selmon->pertag->nmasters[0] = selmon->nmaster;
}
arrange(selmon);
}
@ -1764,14 +1810,48 @@ setgaps(const Arg *arg)
arrange(selmon);
}
void
layoutscroll(const Arg *arg)
{
if (!arg || !arg->i)
return;
int switchto = selmon->ltcur + arg->i;
int l = LENGTH(layouts);
if (switchto == l)
switchto = 0;
else if(switchto < 0)
switchto = l - 1;
selmon->ltcur = switchto;
Arg arg2 = {.v= &layouts[switchto] };
setlayout(&arg2);
}
void
setlayout(const Arg *arg)
{
unsigned int i;
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
selmon->sellt ^= 1;
if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout *)arg->v;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
for(i=0; i<LENGTH(tags); ++i)
if(selmon->tagset[selmon->seltags] & 1<<i)
{
selmon->pertag->ltidxs[i+1][selmon->sellt] = selmon->lt[selmon->sellt];
selmon->pertag->sellts[i+1] = selmon->sellt;
}
if(selmon->pertag->curtag == 0)
{
selmon->pertag->ltidxs[0][selmon->sellt] = selmon->lt[selmon->sellt];
selmon->pertag->sellts[0] = selmon->sellt;
}
if (selmon->sel)
arrange(selmon);
else
@ -1783,13 +1863,24 @@ void
setmfact(const Arg *arg)
{
float f;
unsigned int i;
if (!arg || !selmon->lt[selmon->sellt]->arrange)
return;
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
if (arg->f == 0.0)
f = mfact;
if (f < 0.05 || f > 0.95)
return;
selmon->mfact = f;
for(i=0; i<LENGTH(tags); ++i)
if(selmon->tagset[selmon->seltags] & 1<<i)
selmon->pertag->mfacts[i+1] = f;
if(selmon->pertag->curtag == 0)
{
selmon->pertag->mfacts[0] = f;
}
arrange(selmon);
}
@ -2154,6 +2245,8 @@ tag(const Arg *arg)
focus(NULL);
arrange(selmon);
}
if (selmon->wfsymbol[0] == WFACTIVE)
view(arg);
}
void
@ -2162,6 +2255,8 @@ tagmon(const Arg *arg)
if (!selmon->sel || !mons->next)
return;
sendmon(selmon->sel, dirtomon(arg->i));
if (selmon->wfsymbol[0] == WFACTIVE)
focusmon(arg);
}
void
@ -2201,12 +2296,28 @@ tile(Monitor *m)
void
togglebar(const Arg *arg)
{
unsigned int i;
selmon->showbar = !selmon->showbar;
for(i=0; i<LENGTH(tags); ++i)
if(selmon->tagset[selmon->seltags] & 1<<i)
selmon->pertag->showbars[i+1] = selmon->showbar;
if(selmon->pertag->curtag == 0)
{
selmon->pertag->showbars[0] = selmon->showbar;
}
updatebarpos(selmon);
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
arrange(selmon);
}
void
togglefollow(const Arg *arg)
{
selmon->wfsymbol[0] = (selmon->wfsymbol[0] == WFACTIVE) ? WFINACTIVE : WFACTIVE;
drawbars();
}
void
togglefloating(const Arg *arg)
{
@ -2247,9 +2358,33 @@ void
toggleview(const Arg *arg)
{
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
int i;
if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
if (newtagset == ~0) {
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = 0;
}
/* test if the user did not select the same tag */
if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
selmon->pertag->prevtag = selmon->pertag->curtag;
for (i = 0; !(newtagset & 1 << i); i++) ;
selmon->pertag->curtag = i + 1;
}
/* apply settings for this view */
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
togglebar(NULL);
focus(NULL);
arrange(selmon);
}
@ -2613,11 +2748,37 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
int i;
unsigned int tmptag;
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK)
if (arg->ui & TAGMASK) {
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
selmon->pertag->prevtag = selmon->pertag->curtag;
if (arg->ui == ~0)
selmon->pertag->curtag = 0;
else {
for (i = 0; !(arg->ui & 1 << i); i++) ;
selmon->pertag->curtag = i + 1;
}
} else {
tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
}
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
togglebar(NULL);
focus(NULL);
arrange(selmon);
}

BIN
dwm/dwm.o

Binary file not shown.

35
dwm/gaplessgrid.c Normal file
View file

@ -0,0 +1,35 @@
void
gaplessgrid(Monitor *m) {
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
Client *c;
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
if(n == 0)
return;
/* grid dimensions */
for(cols = 0; cols <= n/2; cols++)
if(cols*cols >= n)
break;
if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
cols = 2;
rows = n/cols;
/* window geometries */
cw = cols ? m->ww / cols : m->ww;
cn = 0; /* current column number */
rn = 0; /* current row number */
for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if(i/rows + 1 > cols - n%cols)
rows = n/cols + 1;
ch = rows ? m->wh / rows : m->wh;
cx = m->wx + cn*cw;
cy = m->wy + rn*ch;
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
rn++;
if(rn >= rows) {
rn = 0;
cn++;
}
}
}

32
dwm/horizgrid.c Normal file
View file

@ -0,0 +1,32 @@
void
horizgrid(Monitor *m) {
Client *c;
unsigned int n, i;
int w = 0;
int ntop, nbottom = 0;
/* Count windows */
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if(n == 0)
return;
else if(n == 1) { /* Just fill the whole screen */
c = nexttiled(m->clients);
resize(c, m->wx, m->wy, m->ww - (2*c->bw), m->wh - (2*c->bw), False);
} else if(n == 2) { /* Split vertically */
w = m->ww / 2;
c = nexttiled(m->clients);
resize(c, m->wx, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
c = nexttiled(c->next);
resize(c, m->wx + w, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
} else {
ntop = n / 2;
nbottom = n - ntop;
for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
if(i < ntop)
resize(c, m->wx + i * m->ww / ntop, m->wy, m->ww / ntop - (2*c->bw), m->wh / 2 - (2*c->bw), False);
else
resize(c, m->wx + (i - ntop) * m->ww / nbottom, m->wy + m->wh / 2, m->ww / nbottom - (2*c->bw), m->wh / 2 - (2*c->bw), False);
}
}
}

View file

@ -0,0 +1,43 @@
URL: http://dwm.suckless.org/patches/gapless_grid
Add gapless grid layout.
Index: dwm/gaplessgrid.c
===================================================================
--- /dev/null
+++ dwm/gaplessgrid.c
@@ -0,0 +1,35 @@
+void
+gaplessgrid(Monitor *m) {
+ unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
+ Client *c;
+
+ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
+ if(n == 0)
+ return;
+
+ /* grid dimensions */
+ for(cols = 0; cols <= n/2; cols++)
+ if(cols*cols >= n)
+ break;
+ if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
+ cols = 2;
+ rows = n/cols;
+
+ /* window geometries */
+ cw = cols ? m->ww / cols : m->ww;
+ cn = 0; /* current column number */
+ rn = 0; /* current row number */
+ for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
+ if(i/rows + 1 > cols - n%cols)
+ rows = n/cols + 1;
+ ch = rows ? m->wh / rows : m->wh;
+ cx = m->wx + cn*cw;
+ cy = m->wy + rn*ch;
+ resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
+ rn++;
+ if(rn >= rows) {
+ rn = 0;
+ cn++;
+ }
+ }
+}

View file

@ -0,0 +1,70 @@
From 064e1d48631cd9b03f32b42d7be79677197ee42f Mon Sep 17 00:00:00 2001
From: Marshall Mason <marshallmason3@gmail.com>
Date: Mon, 9 Nov 2015 12:38:28 -0800
Subject: [PATCH] Added horizgrid function
---
config.def.h | 2 ++
horizgrid.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
create mode 100644 horizgrid.c
diff --git a/config.def.h b/config.def.h
index eaae8f3..c2ad519 100644
--- a/config.def.h
+++ b/config.def.h
@@ -36,11 +36,13 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95]
static const int nmaster = 1; /* number of clients in master area */
static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
+#include "horizgrid.c"
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
+ { "###", horizgrid },
};
/* key definitions */
diff --git a/horizgrid.c b/horizgrid.c
new file mode 100644
index 0000000..51ce0f8
--- /dev/null
+++ b/horizgrid.c
@@ -0,0 +1,32 @@
+void
+horizgrid(Monitor *m) {
+ Client *c;
+ unsigned int n, i;
+ int w = 0;
+ int ntop, nbottom = 0;
+
+ /* Count windows */
+ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+
+ if(n == 0)
+ return;
+ else if(n == 1) { /* Just fill the whole screen */
+ c = nexttiled(m->clients);
+ resize(c, m->wx, m->wy, m->ww - (2*c->bw), m->wh - (2*c->bw), False);
+ } else if(n == 2) { /* Split vertically */
+ w = m->ww / 2;
+ c = nexttiled(m->clients);
+ resize(c, m->wx, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
+ c = nexttiled(c->next);
+ resize(c, m->wx + w, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
+ } else {
+ ntop = n / 2;
+ nbottom = n - ntop;
+ for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
+ if(i < ntop)
+ resize(c, m->wx + i * m->ww / ntop, m->wy, m->ww / ntop - (2*c->bw), m->wh / 2 - (2*c->bw), False);
+ else
+ resize(c, m->wx + (i - ntop) * m->ww / nbottom, m->wy + m->wh / 2, m->ww / nbottom - (2*c->bw), m->wh / 2 - (2*c->bw), False);
+ }
+ }
+}
--
2.1.4

View file

@ -0,0 +1,67 @@
diff --git a/config.def.h b/config.def.h
index 4c56466..11ee7b5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -90,6 +90,8 @@ static Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_h, layoutscroll, {.i = -1 } },
+ { MODKEY|ShiftMask, XK_l, layoutscroll, {.i = +1 } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
diff --git a/dwm.c b/dwm.c
index 1e37fcf..24effbc 100644
--- a/dwm.c
+++ b/dwm.c
@@ -148,6 +148,7 @@ struct Monitor {
Monitor *next;
Window barwin;
const Layout *lt[2];
+ int ltcur; /* current layout */
};
typedef struct {
@@ -227,6 +228,7 @@ static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
+static void layoutscroll(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
@@ -725,6 +727,7 @@ createmon(void)
m->nmaster = nmaster;
m->showbar = showbar;
m->topbar = topbar;
+ m->ltcur = 0;
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
@@ -1667,6 +1670,25 @@ setfullscreen(Client *c, int fullscreen)
}
}
+void
+layoutscroll(const Arg *arg)
+{
+ if (!arg || !arg->i)
+ return;
+ int switchto = selmon->ltcur + arg->i;
+ int l = LENGTH(layouts);
+
+ if (switchto == l)
+ switchto = 0;
+ else if(switchto < 0)
+ switchto = l - 1;
+
+ selmon->ltcur = switchto;
+ Arg arg2 = {.v= &layouts[switchto] };
+ setlayout(&arg2);
+
+}
+
void
setlayout(const Arg *arg)
{

View file

@ -0,0 +1,224 @@
diff -up a/dwm.c b/dwm.c
--- a/dwm.c 2020-05-23 00:20:34.877944603 +0200
+++ b/dwm.c 2020-06-22 12:49:55.298859682 +0200
@@ -111,6 +111,7 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
+typedef struct Pertag Pertag;
struct Monitor {
char ltsymbol[16];
float mfact;
@@ -130,6 +131,7 @@ struct Monitor {
Monitor *next;
Window barwin;
const Layout *lt[2];
+ Pertag *pertag;
};
typedef struct {
@@ -271,6 +273,15 @@ static Window root, wmcheckwin;
/* configuration, allows nested code to access above variables */
#include "config.h"
+struct Pertag {
+ unsigned int curtag, prevtag; /* current and previous tag */
+ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
+ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
+ unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
+ const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
+ int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
+};
+
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@@ -631,6 +642,7 @@ Monitor *
createmon(void)
{
Monitor *m;
+ unsigned int i;
m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1;
@@ -641,6 +653,20 @@ createmon(void)
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+ m->pertag = ecalloc(1, sizeof(Pertag));
+ m->pertag->curtag = m->pertag->prevtag = 1;
+
+ for (i = 0; i <= LENGTH(tags); i++) {
+ m->pertag->nmasters[i] = m->nmaster;
+ m->pertag->mfacts[i] = m->mfact;
+
+ m->pertag->ltidxs[i][0] = m->lt[0];
+ m->pertag->ltidxs[i][1] = m->lt[1];
+ m->pertag->sellts[i] = m->sellt;
+
+ m->pertag->showbars[i] = m->showbar;
+ }
+
return m;
}
@@ -966,7 +992,16 @@ grabkeys(void)
void
incnmaster(const Arg *arg)
{
+ unsigned int i;
selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
+ for(i=0; i<LENGTH(tags); ++i)
+ if(selmon->tagset[selmon->seltags] & 1<<i)
+ selmon->pertag->nmasters[i+1] = selmon->nmaster;
+
+ if(selmon->pertag->curtag == 0)
+ {
+ selmon->pertag->nmasters[0] = selmon->nmaster;
+ }
arrange(selmon);
}
@@ -1500,11 +1535,26 @@ setfullscreen(Client *c, int fullscreen)
void
setlayout(const Arg *arg)
{
+ unsigned int i;
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
selmon->sellt ^= 1;
if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout *)arg->v;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
+
+ for(i=0; i<LENGTH(tags); ++i)
+ if(selmon->tagset[selmon->seltags] & 1<<i)
+ {
+ selmon->pertag->ltidxs[i+1][selmon->sellt] = selmon->lt[selmon->sellt];
+ selmon->pertag->sellts[i+1] = selmon->sellt;
+ }
+
+ if(selmon->pertag->curtag == 0)
+ {
+ selmon->pertag->ltidxs[0][selmon->sellt] = selmon->lt[selmon->sellt];
+ selmon->pertag->sellts[0] = selmon->sellt;
+ }
+
if (selmon->sel)
arrange(selmon);
else
@@ -1516,13 +1566,24 @@ void
setmfact(const Arg *arg)
{
float f;
+ unsigned int i;
if (!arg || !selmon->lt[selmon->sellt]->arrange)
return;
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
- if (f < 0.1 || f > 0.9)
+ if (arg->f == 0.0)
+ f = mfact;
+ if (f < 0.05 || f > 0.95)
return;
selmon->mfact = f;
+ for(i=0; i<LENGTH(tags); ++i)
+ if(selmon->tagset[selmon->seltags] & 1<<i)
+ selmon->pertag->mfacts[i+1] = f;
+
+ if(selmon->pertag->curtag == 0)
+ {
+ selmon->pertag->mfacts[0] = f;
+ }
arrange(selmon);
}
@@ -1699,7 +1760,16 @@ tile(Monitor *m)
void
togglebar(const Arg *arg)
{
+ unsigned int i;
selmon->showbar = !selmon->showbar;
+ for(i=0; i<LENGTH(tags); ++i)
+ if(selmon->tagset[selmon->seltags] & 1<<i)
+ selmon->pertag->showbars[i+1] = selmon->showbar;
+
+ if(selmon->pertag->curtag == 0)
+ {
+ selmon->pertag->showbars[0] = selmon->showbar;
+ }
updatebarpos(selmon);
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
arrange(selmon);
@@ -1738,9 +1808,33 @@ void
toggleview(const Arg *arg)
{
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
+ int i;
if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
+
+ if (newtagset == ~0) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ selmon->pertag->curtag = 0;
+ }
+
+ /* test if the user did not select the same tag */
+ if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ for (i = 0; !(newtagset & 1 << i); i++) ;
+ selmon->pertag->curtag = i + 1;
+ }
+
+ /* apply settings for this view */
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
+
+ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
+ togglebar(NULL);
+
focus(NULL);
arrange(selmon);
}
@@ -2035,11 +2129,37 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
+ int i;
+ unsigned int tmptag;
+
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
selmon->seltags ^= 1; /* toggle sel tagset */
- if (arg->ui & TAGMASK)
+ if (arg->ui & TAGMASK) {
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+
+ if (arg->ui == ~0)
+ selmon->pertag->curtag = 0;
+ else {
+ for (i = 0; !(arg->ui & 1 << i); i++) ;
+ selmon->pertag->curtag = i + 1;
+ }
+ } else {
+ tmptag = selmon->pertag->prevtag;
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ selmon->pertag->curtag = tmptag;
+ }
+
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
+
+ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
+ togglebar(NULL);
+
focus(NULL);
arrange(selmon);
}

View file

@ -0,0 +1,142 @@
diff '--color=auto' -up dwm-6.3/config.def.h windowfollow-impl-6-3/config.def.h
--- dwm-6.3/config.def.h 2022-01-07 11:42:18.000000000 +0000
+++ windowfollow-impl-6-3/config.def.h 2022-10-02 18:32:22.244267491 +0100
@@ -31,6 +31,11 @@ static const Rule rules[] = {
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
};
+/* window following */
+#define WFACTIVE '>'
+#define WFINACTIVE 'v'
+#define WFDEFAULT WFINACTIVE
+
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
@@ -65,6 +70,7 @@ static Key keys[] = {
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
+ { MODKEY, XK_n, togglefollow, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
@@ -103,6 +109,7 @@ static Button buttons[] = {
/* click event mask button function argument */
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
+ { ClkFollowSymbol, 0, Button1, togglefollow, {0} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
diff '--color=auto' -up dwm-6.3/dwm.1 windowfollow-impl-6-3/dwm.1
--- dwm-6.3/dwm.1 2022-01-07 11:42:18.000000000 +0000
+++ windowfollow-impl-6-3/dwm.1 2022-10-02 18:32:22.244267491 +0100
@@ -44,7 +44,8 @@ command.
.TP
.B Button1
click on a tag label to display all windows with that tag, click on the layout
-label toggles between tiled and floating layout.
+label toggles between tiled and floating layout, click on the window follow
+icon toggles it on and off.
.TP
.B Button3
click on a tag label adds/removes all windows with that tag to/from the view.
@@ -80,6 +81,9 @@ Send focused window to next screen, if a
.B Mod1\-b
Toggles bar on and off.
.TP
+.B Mod1\-n
+Toggles window following on and off.
+.TP
.B Mod1\-t
Sets tiled layout.
.TP
diff '--color=auto' -up dwm-6.3/dwm.c windowfollow-impl-6-3/dwm.c
--- dwm-6.3/dwm.c 2022-01-07 11:42:18.000000000 +0000
+++ windowfollow-impl-6-3/dwm.c 2022-10-02 18:32:22.244267491 +0100
@@ -65,7 +65,7 @@ enum { NetSupported, NetWMName, NetWMSta
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
- ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
+ ClkClientWin, ClkRootWin, ClkFollowSymbol, ClkLast }; /* clicks */
typedef union {
int i;
@@ -113,6 +113,7 @@ typedef struct {
struct Monitor {
char ltsymbol[16];
+ char wfsymbol[2];
float mfact;
int nmaster;
int num;
@@ -212,6 +213,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
+static void togglefollow(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
@@ -440,6 +442,8 @@ buttonpress(XEvent *e)
arg.ui = 1 << i;
} else if (ev->x < x + blw)
click = ClkLtSymbol;
+ else if (ev->x < x + blw + TEXTW(selmon->wfsymbol))
+ click = ClkFollowSymbol;
else if (ev->x > selmon->ww - (int)TEXTW(stext))
click = ClkStatusText;
else
@@ -642,6 +646,8 @@ createmon(void)
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+ m->wfsymbol[0] = WFDEFAULT;
+ m->wfsymbol[1] = '\0';
return m;
}
@@ -732,6 +738,9 @@ drawbar(Monitor *m)
drw_setscheme(drw, scheme[SchemeNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+ w = TEXTW(m->wfsymbol);
+ x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->wfsymbol, 0);
+
if ((w = m->ww - tw - x) > bh) {
if (m->sel) {
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
@@ -1664,6 +1673,8 @@ tag(const Arg *arg)
focus(NULL);
arrange(selmon);
}
+ if (selmon->wfsymbol[0] == WFACTIVE)
+ view(arg);
}
void
@@ -1672,6 +1683,8 @@ tagmon(const Arg *arg)
if (!selmon->sel || !mons->next)
return;
sendmon(selmon->sel, dirtomon(arg->i));
+ if (selmon->wfsymbol[0] == WFACTIVE)
+ focusmon(arg);
}
void
@@ -1712,6 +1725,13 @@ togglebar(const Arg *arg)
}
void
+togglefollow(const Arg *arg)
+{
+ selmon->wfsymbol[0] = (selmon->wfsymbol[0] == WFACTIVE) ? WFINACTIVE : WFACTIVE;
+ drawbars();
+}
+
+void
togglefloating(const Arg *arg)
{
if (!selmon->sel)

View file

@ -208,6 +208,8 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ XK_NO_MOD, XK_F11, fullscreen, {.i = 0} },
{ MODKEY, XK_Return, fullscreen, {.i = 0} },
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
{ TERMMOD, XK_Return, newterm, {.i = 0} },

View file

@ -0,0 +1,69 @@
diff -r -u a/config.def.h b/config.def.h
--- a/config.def.h 2022-01-07 06:41:35.000000000 -0500
+++ b/config.def.h 2022-01-15 13:32:01.644320198 -0500
@@ -201,6 +201,8 @@
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
+ { XK_NO_MOD, XK_F11, fullscreen, {.i = 0} },
+ { MODKEY, XK_Return, fullscreen, {.i = 0} },
};
/*
diff -r -u a/st.h b/st.h
--- a/st.h 2022-01-07 06:41:35.000000000 -0500
+++ b/st.h 2022-01-15 13:32:40.084320514 -0500
@@ -81,6 +81,7 @@
void redraw(void);
void draw(void);
+void fullscreen(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);
diff -r -u a/x.c b/x.c
--- a/x.c 2022-01-07 06:41:35.000000000 -0500
+++ b/x.c 2022-01-15 13:50:28.164329295 -0500
@@ -94,6 +94,7 @@
Drawable buf;
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid;
+ Atom netwmstate, netwmfullscreen;
struct {
XIM xim;
XIC xic;
@@ -744,6 +745,24 @@
xw.specbuf = xrealloc(xw.specbuf, col * sizeof(GlyphFontSpec));
}
+void
+fullscreen(const Arg *arg)
+{
+ XEvent ev;
+
+ memset(&ev, 0, sizeof(ev));
+
+ ev.xclient.type = ClientMessage;
+ ev.xclient.message_type = xw.netwmstate;
+ ev.xclient.display = xw.dpy;
+ ev.xclient.window = xw.win;
+ ev.xclient.format = 32;
+ ev.xclient.data.l[0] = 2; /* _NET_WM_STATE_TOGGLE */
+ ev.xclient.data.l[1] = xw.netwmfullscreen;
+
+ XSendEvent(xw.dpy, DefaultRootWindow(xw.dpy), False, SubstructureNotifyMask|SubstructureRedirectMask, &ev);
+}
+
ushort
sixd_to_16bit(int x)
{
@@ -1208,6 +1227,9 @@
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
+ xw.netwmstate = XInternAtom(xw.dpy, "_NET_WM_STATE", False);
+ xw.netwmfullscreen = XInternAtom(xw.dpy, "_NET_WM_STATE_FULLSCREEN", False);
+
win.mode = MODE_NUMLOCK;
resettitle();
xhints();

BIN
st/st

Binary file not shown.

View file

@ -159,6 +159,12 @@ Copy the selected text to the clipboard selection.
.TP
.B Ctrl-Shift-v
Paste from the clipboard selection.
.TP
.B Ctrl-Shift-Return
Launch a new session.
.TP
.B F11 or Alt+Return
Fullscreen mode.
.SH CUSTOMIZATION
.B st
can be customized by creating a custom config.h and (re)compiling the source

View file

@ -86,6 +86,7 @@ void draw(void);
void newterm(const Arg *);
void kscrolldown(const Arg *);
void kscrollup(const Arg *);
void fullscreen(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);

22
st/x.c
View file

@ -96,6 +96,7 @@ typedef struct {
Drawable buf;
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid;
Atom netwmstate, netwmfullscreen;
struct {
XIM xim;
XIC xic;
@ -769,6 +770,24 @@ xresize(int col, int row)
xw.specbuf = xrealloc(xw.specbuf, col * sizeof(GlyphFontSpec));
}
void
fullscreen(const Arg *arg)
{
XEvent ev;
memset(&ev, 0, sizeof(ev));
ev.xclient.type = ClientMessage;
ev.xclient.message_type = xw.netwmstate;
ev.xclient.display = xw.dpy;
ev.xclient.window = xw.win;
ev.xclient.format = 32;
ev.xclient.data.l[0] = 2; /* _NET_WM_STATE_TOGGLE */
ev.xclient.data.l[1] = xw.netwmfullscreen;
XSendEvent(xw.dpy, DefaultRootWindow(xw.dpy), False, SubstructureNotifyMask|SubstructureRedirectMask, &ev);
}
ushort
sixd_to_16bit(int x)
{
@ -1248,6 +1267,9 @@ xinit(int cols, int rows)
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
xw.netwmstate = XInternAtom(xw.dpy, "_NET_WM_STATE", False);
xw.netwmfullscreen = XInternAtom(xw.dpy, "_NET_WM_STATE_FULLSCREEN", False);
win.mode = MODE_NUMLOCK;
resettitle();
xhints();

File diff suppressed because it is too large Load diff

BIN
st/x.o

Binary file not shown.