feat: support numlock on

This commit is contained in:
DreamMaoMao 2025-03-10 22:38:08 +08:00
parent 360e259ca5
commit aa54758e75
3 changed files with 24 additions and 1 deletions

View file

@ -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.

8
cage.c
View file

@ -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;

14
seat.c
View file

@ -22,6 +22,7 @@
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_keyboard_group.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_scene.h>
@ -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);