From 75bd780f0296b7a9b73068a05fc367c435455cfd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 11 Nov 2020 18:25:54 +0100 Subject: input: use XKB_MOD_NAME_* macros instead of hard-coded strings --- input.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 5d21a3bc..913b68dc 100644 --- a/input.c +++ b/input.c @@ -526,10 +526,10 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, if (seat->kbd.xkb_keymap != NULL) { seat->kbd.xkb_state = xkb_state_new(seat->kbd.xkb_keymap); - seat->kbd.mod_shift = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, "Shift"); - seat->kbd.mod_alt = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, "Mod1") ; - seat->kbd.mod_ctrl = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, "Control"); - seat->kbd.mod_meta = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, "Mod4"); + seat->kbd.mod_shift = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_SHIFT); + seat->kbd.mod_alt = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_ALT) ; + seat->kbd.mod_ctrl = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_CTRL); + seat->kbd.mod_meta = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_LOGO); seat->kbd.key_arrow_up = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "UP"); seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN"); -- cgit v1.3 From bdaf20ba71fe9ae5222f259e286f627c36603732 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 11 Nov 2020 18:28:13 +0100 Subject: input: track num lock state --- input.c | 4 ++++ wayland.h | 2 ++ 2 files changed, 6 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 913b68dc..4c59a555 100644 --- a/input.c +++ b/input.c @@ -530,6 +530,7 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, seat->kbd.mod_alt = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_ALT) ; seat->kbd.mod_ctrl = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_CTRL); seat->kbd.mod_meta = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_LOGO); + seat->kbd.mod_num = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_NUM); seat->kbd.key_arrow_up = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "UP"); seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN"); @@ -632,6 +633,7 @@ keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, seat->kbd.alt = false; seat->kbd.ctrl = false; seat->kbd.meta = false; + seat->kbd.num = false; if (seat->kbd.xkb_compose_state != NULL) xkb_compose_state_reset(seat->kbd.xkb_compose_state); @@ -1047,6 +1049,8 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, seat->kbd.xkb_state, seat->kbd.mod_ctrl, XKB_STATE_MODS_DEPRESSED); seat->kbd.meta = xkb_state_mod_index_is_active( seat->kbd.xkb_state, seat->kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); + seat->kbd.num = xkb_state_mod_index_is_active( + seat->kbd.xkb_state, seat->kbd.mod_num, XKB_STATE_MODS_LOCKED); } if (seat->kbd_focus && seat->kbd_focus->active_surface == TERM_SURF_GRID) diff --git a/wayland.h b/wayland.h index ac6dd9a7..7bf5eb80 100644 --- a/wayland.h +++ b/wayland.h @@ -163,6 +163,7 @@ struct seat { xkb_mod_index_t mod_alt; xkb_mod_index_t mod_ctrl; xkb_mod_index_t mod_meta; + xkb_mod_index_t mod_num; xkb_keycode_t key_arrow_up; xkb_keycode_t key_arrow_down; @@ -172,6 +173,7 @@ struct seat { bool alt; bool ctrl; bool meta; + bool num; struct { tll(struct key_binding_normal) key; -- cgit v1.3 From deb2c2db6d153c6f9e89a3180180edda5bc6786c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 11 Nov 2020 18:28:37 +0100 Subject: input: enforce ‘numerical’ keypad mode when Num Lock override is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When num lock override has been enabled via “CSI?1035h” (the default), keypad is always considered to be in ‘numerical’ mode. This affects how keypad keys are translated to escape sequences when Num Lock is active. The keypad has four modes: * Num Lock off, numerical mode * Num Lock off, application mode * Num Lock on, numerical mode * Num Lock on, application mode The keymap is identical for numerical and application mode when Num Lock is off, meaning the keypad effectively has three different modes. In XTerm, numerical and application mode _can_ be the same, **if** the ‘numLock’ resource is set to true (the default). It is only when ‘numLock’ is false that the application mode is actually used. This patch changes foot to do the same. We don’t expose an option, but do implement “CSI ? 1035”. Closes #194 --- input.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 4c59a555..d455a473 100644 --- a/input.c +++ b/input.c @@ -741,7 +741,8 @@ keymap_data_for_sym(xkb_keysym_t sym, size_t *count) } static const struct key_data * -keymap_lookup(struct terminal *term, xkb_keysym_t sym, enum modifier mods) +keymap_lookup(struct seat *seat, struct terminal *term, + xkb_keysym_t sym, enum modifier mods) { size_t count; const struct key_data *info = keymap_data_for_sym(sym, &count); @@ -749,16 +750,22 @@ keymap_lookup(struct terminal *term, xkb_keysym_t sym, enum modifier mods) if (info == NULL) return NULL; + const enum cursor_keys cursor_keys_mode = term->cursor_keys_mode; + const enum keypad_keys keypad_keys_mode + = (term->num_lock_modifier && seat->kbd.num + ? KEYPAD_NUMERICAL + : term->keypad_keys_mode); + for (size_t j = 0; j < count; j++) { if (info[j].modifiers != MOD_ANY && info[j].modifiers != mods) continue; if (info[j].cursor_keys_mode != CURSOR_KEYS_DONTCARE && - info[j].cursor_keys_mode != term->cursor_keys_mode) + info[j].cursor_keys_mode != cursor_keys_mode) continue; if (info[j].keypad_keys_mode != KEYPAD_DONTCARE && - info[j].keypad_keys_mode != term->keypad_keys_mode) + info[j].keypad_keys_mode != keypad_keys_mode) continue; return &info[j]; @@ -884,7 +891,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, keymap_mods |= seat->kbd.ctrl ? MOD_CTRL : MOD_NONE; keymap_mods |= seat->kbd.meta ? MOD_META : MOD_NONE; - const struct key_data *keymap = keymap_lookup(term, sym, keymap_mods); + const struct key_data *keymap = keymap_lookup(seat, term, sym, keymap_mods); if (keymap != NULL) { term_to_slave(term, keymap->seq, strlen(keymap->seq)); -- cgit v1.3