Skip to content
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

Feature Request: on_empty_keys patch #51

Closed
B4rc1 opened this issue Sep 27, 2020 · 0 comments
Closed

Feature Request: on_empty_keys patch #51

B4rc1 opened this issue Sep 27, 2020 · 0 comments

Comments

@B4rc1
Copy link

B4rc1 commented Sep 27, 2020

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

bakkeby added a commit that referenced this issue Sep 29, 2020
@B4rc1 B4rc1 closed this as completed Sep 29, 2020
SunJukebox pushed a commit to SunJukebox/dwm that referenced this issue Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant