From aa54758e75663781bff64f43e174768327861eda Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Mon, 10 Mar 2025 22:38:08 +0800 Subject: [PATCH] feat: support numlock on --- cage.1.scd | 3 +++ cage.c | 8 +++++++- seat.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cage.1.scd b/cage.1.scd index ed1f518..c207e01 100644 --- a/cage.1.scd +++ b/cage.1.scd @@ -33,6 +33,9 @@ activities outside the scope of the running application are prevented. *-s* Allow VT switching +*-n* + Enable numlock + *-v* Show the version number and exit. diff --git a/cage.c b/cage.c index 8f14746..2b75807 100644 --- a/cage.c +++ b/cage.c @@ -61,6 +61,8 @@ #include "xwayland.h" #endif +extern bool numlock; + void server_terminate(struct cg_server *server) { @@ -232,6 +234,7 @@ usage(FILE *file, const char *cage) " -m extend Extend the display across all connected outputs (default)\n" " -m last Use only the last connected output\n" " -s\t Allow VT switching\n" + " -n\t Enable numlock\n" " -v\t Show the version number and exit\n" "\n" " Use -- when you want to pass arguments to APPLICATION\n", @@ -242,7 +245,7 @@ static bool parse_args(struct cg_server *server, int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "dDhm:sv")) != -1) { + while ((c = getopt(argc, argv, "dDhm:snv")) != -1) { switch (c) { case 'd': server->xdg_decoration = true; @@ -260,6 +263,9 @@ parse_args(struct cg_server *server, int argc, char *argv[]) server->output_mode = CAGE_MULTI_OUTPUT_MODE_EXTEND; } break; + case 'n': + numlock = true; + break; case 's': server->allow_vt_switch = true; break; diff --git a/seat.c b/seat.c index cdf8798..28dce9f 100644 --- a/seat.c +++ b/seat.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ #include "xwayland.h" #endif +static uint32_t locked_mods = 0; +bool numlock = false; + static void drag_icon_update_position(struct cg_drag_icon *drag_icon); /* XDG toplevels may have nested surfaces, such as popup windows for context @@ -358,6 +362,15 @@ cg_keyboard_group_add(struct wlr_keyboard *keyboard, struct cg_seat *seat, bool cg_group->wlr_group->data = cg_group; wlr_keyboard_set_keymap(&cg_group->wlr_group->keyboard, keyboard->keymap); + if (numlock) { + xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keyboard->keymap, XKB_MOD_NAME_NUM); + if (mod_index != XKB_MOD_INVALID) + locked_mods |= (uint32_t)1 << mod_index; + } + + if (locked_mods) + wlr_keyboard_notify_modifiers(&cg_group->wlr_group->keyboard, 0, 0, locked_mods, 0); + wlr_keyboard_set_repeat_info(&cg_group->wlr_group->keyboard, keyboard->repeat_info.rate, keyboard->repeat_info.delay); @@ -397,6 +410,7 @@ handle_new_keyboard(struct cg_seat *seat, struct wlr_keyboard *keyboard, bool vi } wlr_keyboard_set_keymap(keyboard, keymap); + wlr_keyboard_notify_modifiers(keyboard, 0, 0, locked_mods, 0); xkb_keymap_unref(keymap); xkb_context_unref(context);