From 844b6e049fc757edc9515e18cc983e4964633e0b Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 2 Nov 2025 09:58:47 +0800 Subject: [PATCH] opt: support hot-reload xkb_rules --- src/config/parse_config.h | 5 +++++ src/mango.c | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 15cea6d..b30fb34 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -2831,6 +2831,11 @@ void parse_config(void) { // 重置config结构体,确保所有指针初始化为NULL memset(&config, 0, sizeof(config)); + memset(&xkb_rules_rules, 0, sizeof(xkb_rules_rules)); + memset(&xkb_rules_model, 0, sizeof(xkb_rules_model)); + memset(&xkb_rules_layout, 0, sizeof(xkb_rules_layout)); + memset(&xkb_rules_variant, 0, sizeof(xkb_rules_variant)); + memset(&xkb_rules_options, 0, sizeof(xkb_rules_options)); // 初始化动态数组的指针为NULL,避免野指针 config.window_rules = NULL; diff --git a/src/mango.c b/src/mango.c index e3f5ade..8f2bd9b 100644 --- a/src/mango.c +++ b/src/mango.c @@ -4542,6 +4542,23 @@ void reset_keyboard_layout(void) { wlr_seat_set_keyboard(seat, keyboard); wlr_seat_keyboard_notify_modifiers(seat, &keyboard->modifiers); + InputDevice *id; + wl_list_for_each(id, &inputdevices, link) { + if (id->wlr_device->type != WLR_INPUT_DEVICE_KEYBOARD) { + continue; + } + + struct wlr_keyboard *tkb = (struct wlr_keyboard *)id->device_data; + + wlr_keyboard_set_keymap(tkb, keyboard->keymap); + wlr_keyboard_notify_modifiers(tkb, depressed, latched, locked, 0); + tkb->modifiers.group = 0; + + // 7. 更新 seat + wlr_seat_set_keyboard(seat, tkb); + wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); + } + // Cleanup xkb_keymap_unref(new_keymap);