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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
From d9b9797680ae58bdb910e3bc1f71408f6b67c0d5 Mon Sep 17 00:00:00 2001
From: Ben Collerson <benc@benc.cc>
Date: Sat, 15 Jun 2024 12:34:01 +1000
Subject: [PATCH] ungroup-keyboards
Ungroup keyboards based on device name. My use case is keeping the
ydotool virtual keyboard from from being grouped with other keyboards.
---
config.def.h | 7 +++++++
dwl.c | 29 ++++++++++++++++++++++++++++-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/config.def.h b/config.def.h
index a784eb4f..9ad1c256 100644
--- a/config.def.h
+++ b/config.def.h
@@ -57,6 +57,13 @@ static const struct xkb_rule_names xkb_rules = {
.options = NULL,
};
+/* keyboard input devices - used to ungroup named keyboard devices */
+static const KBInputRule kbinputrules[] = {
+ /* name kbcreate */
+ { "ydotoold virtual device", createungroupedkeyboard },
+ { NULL, createkeyboard },
+};
+
static const int repeat_rate = 25;
static const int repeat_delay = 600;
diff --git a/dwl.c b/dwl.c
index 5a31aeef..41db830b 100644
--- a/dwl.c
+++ b/dwl.c
@@ -141,6 +141,11 @@ typedef struct {
uint32_t resize; /* configure serial of a pending resize */
} Client;
+typedef struct {
+ const char *name;
+ void (*kbcreate)(struct wlr_keyboard *);
+} KBInputRule;
+
typedef struct {
uint32_t mod;
xkb_keysym_t keysym;
@@ -266,6 +271,7 @@ static void createmon(struct wl_listener *listener, void *data);
static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer);
static void createpointerconstraint(struct wl_listener *listener, void *data);
+static void createungroupedkeyboard(struct wlr_keyboard *keyboard);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptohint(void);
@@ -1089,6 +1095,20 @@ createpointerconstraint(struct wl_listener *listener, void *data)
&pointer_constraint->destroy, destroypointerconstraint);
}
+void
+createungroupedkeyboard(struct wlr_keyboard *keyboard)
+{
+ /* for keyboards that need their own keyboard group */
+ KeyboardGroup *group = createkeyboardgroup();
+
+ /* Set the keymap to match the group keymap */
+ wlr_keyboard_set_keymap(keyboard, group->wlr_group->keyboard.keymap);
+ LISTEN(&keyboard->base.events.destroy, &group->destroy, destroykeyboardgroup);
+
+ /* Add the new keyboard to the group */
+ wlr_keyboard_group_add_keyboard(group->wlr_group, keyboard);
+}
+
void
cursorconstrain(struct wlr_pointer_constraint_v1 *constraint)
{
@@ -1464,10 +1484,17 @@ inputdevice(struct wl_listener *listener, void *data)
* available. */
struct wlr_input_device *device = data;
uint32_t caps;
+ const KBInputRule *r;
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
- createkeyboard(wlr_keyboard_from_input_device(device));
+ for (r = kbinputrules; r < END(kbinputrules); r++) {
+ if (!r->name || strstr(device->name, r->name)) {
+ r->kbcreate(wlr_keyboard_from_input_device(device));
+ break;
+ }
+ }
+
break;
case WLR_INPUT_DEVICE_POINTER:
createpointer(wlr_pointer_from_input_device(device));
--
2.45.1
|