aboutsummaryrefslogtreecommitdiffstats
path: root/patches/numlock-capslock-0.8.patch
blob: 8b3f53ffabb1ec686cf42c9d453f5e2645ff69a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From ba40e5a9866b3a22a9d56c9e30068a3d776e0991 Mon Sep 17 00:00:00 2001
From: A Frederick Christensen <dwl@ivories.org>
Date: Wed, 25 Feb 2026 19:59:18 -0600
Subject: [PATCH] Apply numlock-capslock patch

---
 config.def.h |  4 ++++
 dwl.c        | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/config.def.h b/config.def.h
index 8a6eda0..074fb88 100644
--- a/config.def.h
+++ b/config.def.h
@@ -56,6 +56,10 @@ static const struct xkb_rule_names xkb_rules = {
 	.options = NULL,
 };
 
+/* numlock and capslock */
+static const int numlock = 1;
+static const int capslock = 0;
+
 static const int repeat_rate = 25;
 static const int repeat_delay = 600;
 
diff --git a/dwl.c b/dwl.c
index 44f3ad9..c6ace09 100644
--- a/dwl.c
+++ b/dwl.c
@@ -14,6 +14,7 @@
 #include <wayland-server-core.h>
 #include <wlr/backend.h>
 #include <wlr/backend/libinput.h>
+#include <wlr/interfaces/wlr_keyboard.h>
 #include <wlr/render/allocator.h>
 #include <wlr/render/wlr_renderer.h>
 #include <wlr/types/wlr_alpha_modifier_v1.h>
@@ -355,6 +356,7 @@ static void zoom(const Arg *arg);
 /* variables */
 static pid_t child_pid = -1;
 static int locked;
+static uint32_t locked_mods = 0;
 static void *exclusive_focus;
 static struct wl_display *dpy;
 static struct wl_event_loop *event_loop;
@@ -943,6 +945,8 @@ createkeyboard(struct wlr_keyboard *keyboard)
 	/* Set the keymap to match the group keymap */
 	wlr_keyboard_set_keymap(keyboard, kb_group->wlr_group->keyboard.keymap);
 
+	wlr_keyboard_notify_modifiers(keyboard, 0, 0, locked_mods, 0);
+
 	/* Add the new keyboard to the group */
 	wlr_keyboard_group_add_keyboard(kb_group->wlr_group, keyboard);
 }
@@ -964,6 +968,21 @@ createkeyboardgroup(void)
 		die("failed to compile keymap");
 
 	wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap);
+	if (numlock) {
+		xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM);
+		if (mod_index != XKB_MOD_INVALID)
+			locked_mods |= (uint32_t)1 << mod_index;
+	}
+
+	if (capslock) {
+		xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CAPS);
+		if (mod_index != XKB_MOD_INVALID)
+			locked_mods |= (uint32_t)1 << mod_index;
+	}
+
+	if (locked_mods)
+		wlr_keyboard_notify_modifiers(&group->wlr_group->keyboard, 0, 0, locked_mods, 0);
+
 	xkb_keymap_unref(keymap);
 	xkb_context_unref(context);
 
-- 
2.52.0