From aee1dc3e9ca4d8deec5432d0c64921af6e301ecd Mon Sep 17 00:00:00 2001
From: Micah N Gorrell <m@minego.net>
Date: Wed, 27 Mar 2024 15:59:50 -0600
Subject: [PATCH 1/2] onpress, onrepeat, onrelease

---
 dwl.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/dwl.c b/dwl.c
index 5867b0c..43bbf0c 100644
--- a/dwl.c
+++ b/dwl.c
@@ -146,6 +146,10 @@ typedef struct {
 	xkb_keysym_t keysym;
 	void (*func)(const Arg *);
 	const Arg arg;
+
+	int on_press;
+	int on_repeat;
+	int on_release;
 } Key;
 
 typedef struct {
@@ -286,7 +290,7 @@ static void fullscreennotify(struct wl_listener *listener, void *data);
 static void handlesig(int signo);
 static void incnmaster(const Arg *arg);
 static void inputdevice(struct wl_listener *listener, void *data);
-static int keybinding(uint32_t mods, xkb_keysym_t sym);
+static int keybinding(uint32_t mods, xkb_keysym_t sym, int on_press, int on_repeat, int on_release);
 static void keypress(struct wl_listener *listener, void *data);
 static void keypressmod(struct wl_listener *listener, void *data);
 static int keyrepeat(void *data);
@@ -1428,7 +1432,7 @@ inputdevice(struct wl_listener *listener, void *data)
 }
 
 int
-keybinding(uint32_t mods, xkb_keysym_t sym)
+keybinding(uint32_t mods, xkb_keysym_t sym, int on_press, int on_repeat, int on_release)
 {
 	/*
 	 * Here we handle compositor keybindings. This is when the compositor is
@@ -1439,8 +1443,10 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
 	for (k = keys; k < END(keys); k++) {
 		if (CLEANMASK(mods) == CLEANMASK(k->mod)
 				&& sym == k->keysym && k->func) {
-			k->func(&k->arg);
-			return 1;
+			if ((on_press && k->on_press) || (on_repeat && k->on_repeat) || (on_release && k->on_release)) {
+				k->func(&k->arg);
+				return 1;
+			}
 		}
 	}
 	return 0;
@@ -1470,7 +1476,7 @@ keypress(struct wl_listener *listener, void *data)
 	 * attempt to process a compositor keybinding. */
 	if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
 		for (i = 0; i < nsyms; i++)
-			handled = keybinding(mods, syms[i]) || handled;
+			handled = keybinding(mods, syms[i], event->state == WL_KEYBOARD_KEY_STATE_PRESSED, 0, event->state == WL_KEYBOARD_KEY_STATE_RELEASED) || handled;
 	}
 
 	if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) {
@@ -1518,7 +1524,7 @@ keyrepeat(void *data)
 			1000 / group->wlr_group->keyboard.repeat_info.rate);
 
 	for (i = 0; i < group->nsyms; i++)
-		keybinding(group->mods, group->keysyms[i]);
+		keybinding(group->mods, group->keysyms[i], 0, 1, 0);
 
 	return 0;
 }
-- 
2.44.0


From 1875bb171c9b0cd2fb03bb7e6c3fb400e33eeaf1 Mon Sep 17 00:00:00 2001
From: Micah N Gorrell <m@minego.net>
Date: Wed, 27 Mar 2024 16:26:52 -0600
Subject: [PATCH 2/2] Modified logic so that an unmodified keybinding with
 default values for the new flags will behave as it does in vanilla, while
 keybindings with customized flags will function as expected

---
 dwl.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/dwl.c b/dwl.c
index 43bbf0c..55e7a40 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1443,7 +1443,11 @@ keybinding(uint32_t mods, xkb_keysym_t sym, int on_press, int on_repeat, int on_
 	for (k = keys; k < END(keys); k++) {
 		if (CLEANMASK(mods) == CLEANMASK(k->mod)
 				&& sym == k->keysym && k->func) {
-			if ((on_press && k->on_press) || (on_repeat && k->on_repeat) || (on_release && k->on_release)) {
+			if ((k->on_press == 0 && k->on_repeat == 0 && k->on_release == 0) ||
+				(on_press && k->on_press) ||
+				(on_repeat && k->on_repeat) ||
+				(on_release && k->on_release)
+			) {
 				k->func(&k->arg);
 				return 1;
 			}
-- 
2.44.0

