bakkeby / dwm-flexipatch

A dwm build with preprocessor directives to decide which patches to include during build time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: on_empty_keys patch

B4rc1 opened this issue · comments

commented

This patch is a port of InstantWM's on_empty_keys.
It allows you to configure key bindings for empty workspaces. Like so:

static const char* firefoxcmd[] = {"firefox", NULL};
static Key on_empty_keys[] = {
	/* modifier key            function                argument */
	{ 0,        XK_f,          spawn,                  {.v = firefoxcmd } },
};

patch:

diff --git a/config.def.h b/config.def.h
index 1c0b587..2da2290 100644
--- a/config.def.h
+++ b/config.def.h
@@ -113,3 +113,9 @@ static Button buttons[] = {
 	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
 };
 
+static const char* firefoxcmd[] = {"firefox", NULL};
+static Key on_empty_keys[] = {
+	/* modifier key            function                argument */
+	{ 0,        XK_f,          spawn,                  {.v = firefoxcmd } },
+};
+
diff --git a/dwm.c b/dwm.c
index 664c527..11bfaf0 100644
--- a/dwm.c
+++ b/dwm.c
@@ -141,6 +141,9 @@ typedef struct {
 	int monitor;
 } Rule;
 
+
+static int isempty;
+
 /* function declarations */
 static void applyrules(Client *c);
 static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@@ -804,6 +807,16 @@ focus(Client *c)
 	}
 	selmon->sel = c;
 	drawbars();
+
+	if (!c){
+		if (!isempty) {
+			isempty = 1;
+			grabkeys();
+		}
+	} else if (isempty) {
+		isempty = 0;
+		grabkeys();
+	}
 }
 
 /* there are some broken focus acquiring clients needing extra handling */
@@ -961,6 +974,14 @@ grabkeys(void)
 				for (j = 0; j < LENGTH(modifiers); j++)
 					XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
 						True, GrabModeAsync, GrabModeAsync);
+
+		if(!selmon->sel) {
+			for (i = 0; i < LENGTH(on_empty_keys); i++)
+				if ((code = XKeysymToKeycode(dpy, on_empty_keys[i].keysym)))
+					for (j = 0; j < LENGTH(modifiers); j++)
+						XGrabKey(dpy, code, on_empty_keys[i].mod | modifiers[j], root,
+								True, GrabModeAsync, GrabModeAsync);
+		}
 	}
 }
 
@@ -997,6 +1018,13 @@ keypress(XEvent *e)
 		&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
 		&& keys[i].func)
 			keys[i].func(&(keys[i].arg));
+	if(!selmon->sel) {
+		for (i = 0; i < LENGTH(on_empty_keys); i++)
+			if (keysym == on_empty_keys[i].keysym
+					&& CLEANMASK(on_empty_keys[i].mod) == CLEANMASK(ev->state)
+					&& on_empty_keys[i].func)
+				on_empty_keys[i].func(&(on_empty_keys[i].arg));
+	}
 }
 
 void