summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-01-26 20:25:23 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2024-01-26 20:25:23 -0500
commita068f40be0d17ba8a44f7cd2edb0e60d7d2453ad (patch)
tree4de9a9b6d9f938d1b817e82d89941bb2b18dbc0a
parentf95bb05a3b2b02c8e6921b128b6619acc79843cb (diff)
Implement dwmc patch
-rw-r--r--Makefile2
-rw-r--r--config.def.h141
-rw-r--r--dwm.c55
-rwxr-xr-xdwmc40
4 files changed, 178 insertions, 60 deletions
diff --git a/Makefile b/Makefile
index ffa69b4..5819b1e 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ dist: clean
install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
- cp -f dwm ${DESTDIR}${PREFIX}/bin
+ cp -f dwm dwmc ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
mkdir -p ${DESTDIR}${MANPREFIX}/man1
sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
diff --git a/config.def.h b/config.def.h
index 7f7eb4e..f011ad1 100644
--- a/config.def.h
+++ b/config.def.h
@@ -96,64 +96,8 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
-static const Key keys[] = {
+static const Key keys[] = { /* All other keys have migrated to sxhkd */
/* modifier key function argument */
- { MODKEY, XK_p, spawn, {.v = dmenucmd } },
- { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
- { MODKEY, XK_b, togglebar, {0} },
- { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } },
- { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } },
- { MODKEY, XK_j, focusstack, {.i = +1 } },
- { MODKEY, XK_k, focusstack, {.i = -1 } },
- { MODKEY, XK_i, incnmaster, {.i = +1 } },
- { MODKEY, XK_d, incnmaster, {.i = -1 } },
- { MODKEY, XK_h, setmfact, {.f = -0.05} },
- { MODKEY, XK_l, setmfact, {.f = +0.05} },
- { MODKEY|ShiftMask, XK_b, setcfact, {.f = +0.25} },
- { MODKEY|ShiftMask, XK_m, setcfact, {.f = -0.25} },
- { MODKEY|ShiftMask, XK_n, setcfact, {.f = 0.00} },
- { MODKEY|ShiftMask, XK_l, movestack, {.i = +1 } },
- { MODKEY|ShiftMask, XK_h, movestack, {.i = -1 } },
- { MODKEY, XK_Return, zoom, {0} },
- { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } },
- { MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } },
- { MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } },
- { MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } },
- { MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } },
- { MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } },
- { MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } },
- { MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } },
- { MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } },
- { MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } },
- { MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } },
- { MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } },
- { MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } },
- { MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } },
- { MODKEY|Mod4Mask, XK_0, togglegaps, {0} },
- { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} },
- { MODKEY, XK_Tab, view, {0} },
- { MODKEY|ShiftMask, XK_c, killclient, {0} },
- { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
- { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
- { MODKEY, XK_w, setlayout, {.v = &layouts[3]} },
- { MODKEY, XK_space, setlayout, {0} },
- { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
- { MODKEY, XK_0, view, {.ui = ~0 } },
- { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
- { MODKEY, XK_comma, focusmon, {.i = -1 } },
- { MODKEY, XK_period, focusmon, {.i = +1 } },
- { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
- { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
- TAGKEYS( XK_1, 0)
- TAGKEYS( XK_2, 1)
- TAGKEYS( XK_3, 2)
- TAGKEYS( XK_4, 3)
- TAGKEYS( XK_5, 4)
- TAGKEYS( XK_6, 5)
- TAGKEYS( XK_7, 6)
- TAGKEYS( XK_8, 7)
- TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
};
@@ -176,3 +120,86 @@ static const Button buttons[] = {
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
};
+void
+setlayoutex(const Arg *arg)
+{
+ setlayout(&((Arg) { .v = &layouts[arg->i] }));
+}
+
+void
+viewex(const Arg *arg)
+{
+ view(&((Arg) { .ui = 1 << arg->ui }));
+}
+
+void
+viewall(const Arg *arg)
+{
+ view(&((Arg){.ui = ~0}));
+}
+
+void
+toggleviewex(const Arg *arg)
+{
+ toggleview(&((Arg) { .ui = 1 << arg->ui }));
+}
+
+void
+tagex(const Arg *arg)
+{
+ tag(&((Arg) { .ui = 1 << arg->ui }));
+}
+
+void
+toggletagex(const Arg *arg)
+{
+ toggletag(&((Arg) { .ui = 1 << arg->ui }));
+}
+
+void
+tagall(const Arg *arg)
+{
+ tag(&((Arg){.ui = ~0}));
+}
+
+/* signal definitions */
+/* signum must be greater than 0 */
+/* trigger signals using `xsetroot -name "fsignal:<signame> [<type> <value>]"` */
+static Signal signals[] = {
+ /* signum function */
+ { "focusstack", focusstack },
+ { "setmfact", setmfact },
+ { "togglebar", togglebar },
+ { "incnmaster", incnmaster },
+ { "togglefloating", togglefloating },
+ { "focusmon", focusmon },
+ { "tagmon", tagmon },
+ { "zoom", zoom },
+ { "view", view },
+ { "viewall", viewall },
+ { "viewex", viewex },
+ { "toggleview", view },
+ { "toggleviewex", toggleviewex },
+ { "tag", tag },
+ { "tagall", tagall },
+ { "tagex", tagex },
+ { "toggletag", tag },
+ { "toggletagex", toggletagex },
+ { "killclient", killclient },
+ { "quit", quit },
+ { "setlayout", setlayout },
+ { "setlayoutex", setlayoutex },
+ { "rotatestack", rotatestack },
+ { "setcfact", setcfact },
+ { "movestack", movestack },
+ { "incrgaps", incrgaps },
+ { "incrigaps", incrigaps },
+ { "incrogaps", incrogaps },
+ { "incrihgaps", incrihgaps },
+ { "incrivgaps", incrivgaps },
+ { "incrohgaps", incrohgaps },
+ { "incrovgaps", incrovgaps },
+ { "togglegaps", togglegaps },
+ { "defaultgaps", defaultgaps },
+ { "sigstatusbar", sigstatusbar },
+};
diff --git a/dwm.c b/dwm.c
index d8dcf90..f5f3638 100644
--- a/dwm.c
+++ b/dwm.c
@@ -109,6 +109,11 @@ typedef struct {
} Key;
typedef struct {
+ const char * sig;
+ void (*func)(const Arg *);
+} Signal;
+
+typedef struct {
const char *symbol;
void (*arrange)(Monitor *);
} Layout;
@@ -155,6 +160,7 @@ static void arrange(Monitor *m);
static void arrangemon(Monitor *m);
static void attach(Client *c);
static void attachstack(Client *c);
+static int fake_signal(void);
static void buttonpress(XEvent *e);
static void checkotherwm(void);
static void cleanup(void);
@@ -1135,6 +1141,49 @@ keypress(XEvent *e)
keys[i].func(&(keys[i].arg));
}
+int
+fake_signal(void)
+{
+ char fsignal[256];
+ char indicator[9] = "fsignal:";
+ char str_sig[50];
+ char param[16];
+ int i, len_str_sig, n, paramn;
+ size_t len_fsignal, len_indicator = strlen(indicator);
+ Arg arg;
+
+ // Get root name property
+ if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) {
+ len_fsignal = strlen(fsignal);
+
+ // Check if this is indeed a fake signal
+ if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) {
+ paramn = sscanf(fsignal+len_indicator, "%s%n%s%n", str_sig, &len_str_sig, param, &n);
+
+ if (paramn == 1) arg = (Arg) {0};
+ else if (paramn > 2) return 1;
+ else if (strncmp(param, "i", n - len_str_sig) == 0)
+ sscanf(fsignal + len_indicator + n, "%i", &(arg.i));
+ else if (strncmp(param, "ui", n - len_str_sig) == 0)
+ sscanf(fsignal + len_indicator + n, "%u", &(arg.ui));
+ else if (strncmp(param, "f", n - len_str_sig) == 0)
+ sscanf(fsignal + len_indicator + n, "%f", &(arg.f));
+ else return 1;
+
+ // Check if a signal was found, and if so handle it
+ for (i = 0; i < LENGTH(signals); i++)
+ if (strncmp(str_sig, signals[i].sig, len_str_sig) == 0 && signals[i].func)
+ signals[i].func(&(arg));
+
+ // A fake signal was sent
+ return 1;
+ }
+ }
+
+ // No fake signal was sent, so proceed with update
+ return 0;
+}
+
void
killclient(const Arg *arg)
{
@@ -1351,8 +1400,10 @@ propertynotify(XEvent *e)
Window trans;
XPropertyEvent *ev = &e->xproperty;
- if ((ev->window == root) && (ev->atom == XA_WM_NAME))
- updatestatus();
+ if ((ev->window == root) && (ev->atom == XA_WM_NAME)) {
+ if (!fake_signal())
+ updatestatus();
+ }
else if (ev->state == PropertyDelete)
return; /* ignore */
else if ((c = wintoclient(ev->window))) {
diff --git a/dwmc b/dwmc
new file mode 100755
index 0000000..5ba22cc
--- /dev/null
+++ b/dwmc
@@ -0,0 +1,40 @@
+#!/usr/bin/env sh
+
+signal() {
+ xsetroot -name "fsignal:$*"
+}
+
+case $# in
+1)
+ case $1 in
+ setlayout | view | viewall | togglebar | togglefloating | zoom | killclient | quit | togglegaps | defaultgaps)
+ signal "$1"
+ ;;
+ *)
+ echo "Unknown command or missing one argument."
+ exit 1
+ ;;
+ esac
+ ;;
+2)
+ case $1 in
+ view)
+ signal "$1" ui "$2"
+ ;;
+ viewex | toggleviewex | tagex | toggletagex | setlayoutex | focusstack | incnmaster | focusmon | tagmon | rotatestack | movestack | incrgaps | incrigaps | incrogaps | incrihgaps | incrivgaps | incrohgaps | incrovgaps | sigstatusbar)
+ signal "$1" i "$2"
+ ;;
+ setmfact | setcfact)
+ signal "$1" f "$2"
+ ;;
+ *)
+ echo "Unknown command or one too many arguments."
+ exit 1
+ ;;
+ esac
+ ;;
+*)
+ echo "Too many arguments."
+ exit 1
+ ;;
+esac