From 406ad50dd681765e3f0cce85bcf5e1f8268c9149 Mon Sep 17 00:00:00 2001 From: awy Date: Sun, 25 Aug 2024 16:32:55 +0300 Subject: xkb-rules-switcher patch --- dwl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'dwl.c') diff --git a/dwl.c b/dwl.c index 09d4516..aabb4a4 100644 --- a/dwl.c +++ b/dwl.c @@ -385,6 +385,7 @@ static void setsel(struct wl_listener *listener, void *data); static void setup(void); static void spawn(const Arg *arg); static void startdrag(struct wl_listener *listener, void *data); +static void switchxkbrule(const Arg *arg); static int statusin(int fd, unsigned int mask, void *data); static void tag(const Arg *arg); static void tagmon(const Arg *arg); @@ -463,6 +464,7 @@ static struct wl_listener lock_listener = {.notify = locksession}; static struct wlr_seat *seat; static KeyboardGroup *kb_group; static unsigned int cursor_mode; +static unsigned int xkb_rule_index = 0; static Client *grabc; static int grabcx, grabcy; /* client-relative */ @@ -1104,7 +1106,7 @@ createkeyboardgroup(void) /* Prepare an XKB keymap and assign it to the keyboard group. */ context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules, + if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules[xkb_rule_index], XKB_KEYMAP_COMPILE_NO_FLAGS))) die("failed to compile keymap"); @@ -3093,6 +3095,21 @@ statusin(int fd, unsigned int mask, void *data) return 0; } +void +switchxkbrule(const Arg *arg) +{ + struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + struct xkb_keymap *keymap; + + xkb_rule_index = (xkb_rule_index + 1) % LENGTH(xkb_rules); + if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules[xkb_rule_index], + XKB_KEYMAP_COMPILE_NO_FLAGS))) + die("failed to compile keymap"); + wlr_keyboard_set_keymap(&kb_group->wlr_group->keyboard, keymap); + xkb_keymap_unref(keymap); + xkb_context_unref(context); +} + void tag(const Arg *arg) { -- cgit v1.2.3