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 --- README.md | 3 ++- config.def.h | 17 +++++++++++------ dwl.c | 19 ++++++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a19f062..d422666 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # dwl - dwm for Wayland -v0.7 +v0.7 \ patches applied: [bar](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/bar) \ [hide vacant tags](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/hide_vacant_tags) \ [vanitygaps](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/vanitygaps) \ [swallow](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/swallow) \ +[xkb-rules-switcher](https://codeberg.org/wochap/dwl/src/branch/v0.6-b/xkb-rules-switcher/xkb-rules-switcher.patch) diff --git a/config.def.h b/config.def.h index bb95669..2258fdf 100644 --- a/config.def.h +++ b/config.def.h @@ -65,12 +65,16 @@ static const MonitorRule monrules[] = { }; /* keyboard */ -static const struct xkb_rule_names xkb_rules = { - /* can specify fields: rules, model, layout, variant, options */ - /* example: - .options = "ctrl:nocaps", - */ - .options = NULL, +static const struct xkb_rule_names xkb_rules[] = { + { + /* can specify fields: rules, model, layout, variant, options */ + .layout = "us", + .options = NULL, + }, + { + .layout = "ru", + .options = NULL, + }, }; static const int repeat_rate = 25; @@ -178,6 +182,7 @@ static const Key keys[] = { { MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} }, + { MODKEY, XKB_KEY_w, switchxkbrule, {0} }, TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0), TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1), TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2), 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