diff options
author | awy <awy@tutamail.com> | 2024-08-25 16:32:55 +0300 |
---|---|---|
committer | awy <awy@tutamail.com> | 2024-08-25 16:32:55 +0300 |
commit | 406ad50dd681765e3f0cce85bcf5e1f8268c9149 (patch) | |
tree | a4ef45338e045371ac8300a7a05f5926e72af602 | |
parent | 6b2aaedbcffff422b239f858ff21c03dc3a7d67d (diff) |
xkb-rules-switcher patch
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | config.def.h | 17 | ||||
-rw-r--r-- | dwl.c | 19 |
3 files changed, 31 insertions, 8 deletions
@@ -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), @@ -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"); @@ -3094,6 +3096,21 @@ statusin(int fd, unsigned int mask, void *data) } 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) { Client *sel = focustop(selmon); |