From d8cdb9f1866c39e1bad7171590804ed95935d6f9 Mon Sep 17 00:00:00 2001 From: Ben Collerson Date: Sun, 16 Jun 2024 13:57:42 +1000 Subject: [PATCH] add ungroup-keyboards patch --- patches/ungroup-keyboards/README.md | 13 +++ .../ungroup-keyboards/ungroup-keyboards.patch | 96 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 patches/ungroup-keyboards/README.md create mode 100644 patches/ungroup-keyboards/ungroup-keyboards.patch diff --git a/patches/ungroup-keyboards/README.md b/patches/ungroup-keyboards/README.md new file mode 100644 index 0000000..f9a17f0 --- /dev/null +++ b/patches/ungroup-keyboards/README.md @@ -0,0 +1,13 @@ +### Description +Ungroup keyboard input devices based on device name. + +I wrote this patch was because keyboard device grouping breaks the behaviour of +the ydotool virtual device. This patch fixes my issue #558 in the codeberg +issue tracker. + +### Download +- [git branch](https://codeberg.org/bencc/dwl/src/branch/ungroup-keyboards) +- [2024-06-16](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/ungroup-keyboards/ungroup-keyboard.patch) + +### Authors +- [Ben Collerson](https://codeberg.org/bencc) diff --git a/patches/ungroup-keyboards/ungroup-keyboards.patch b/patches/ungroup-keyboards/ungroup-keyboards.patch new file mode 100644 index 0000000..029a6a6 --- /dev/null +++ b/patches/ungroup-keyboards/ungroup-keyboards.patch @@ -0,0 +1,96 @@ +From 511055bbce063f722c2db2d8b56dbe7f132f3319 Mon Sep 17 00:00:00 2001 +From: Ben Collerson +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 | 28 +++++++++++++++++++++++++++- + 2 files changed, 34 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..227b33bf 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,16 @@ 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; + case WLR_INPUT_DEVICE_POINTER: + createpointer(wlr_pointer_from_input_device(device)); +-- +2.45.1 +