From 325ad6dd4e950546514448a838ce03027103d0bd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 25 Nov 2021 15:21:53 +0100 Subject: input: finalize mouse selection on a pointer-leave event on the GRID surface If a mouse selection was ongoing, and the user switched workspace (probably using the keyboard...), and then back, the selection was still treated as ongoing, while all other mouse state has been reset. This meant the user had to tap at least once to stop the selection. --- input.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index 0aef43cc..02035909 100644 --- a/input.c +++ b/input.c @@ -1531,8 +1531,11 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, render_refresh_csd(old_moused); break; - case TERM_SURF_NONE: case TERM_SURF_GRID: + selection_finalize(seat, old_moused, seat->pointer.serial); + break; + + case TERM_SURF_NONE: case TERM_SURF_SEARCH: case TERM_SURF_SCROLLBACK_INDICATOR: case TERM_SURF_RENDER_TIMER: -- cgit v1.3 From 9f3dba683e0b308de9d41982089342f532634528 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 17 Nov 2021 17:51:41 +0100 Subject: input: refactor: new function: legacy_kbd_protocol() This breaks out all handling of key escapes to-be-sent to the client, to a separate function, legacy_kbd_protocol(). That is, the key press/release handler first handles key generic handling, such as starting and stopping the repeat timer. Then it checks for foot keyboard bindings. If not bindings match, we need to pass the keyboard event to the client. This code has now been separated out into a new function. --- input.c | 212 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 107 insertions(+), 105 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 02035909..f5f6d754 100644 --- a/input.c +++ b/input.c @@ -983,6 +983,109 @@ get_current_modifiers(const struct seat *seat, } } +static void +legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, + enum modifier mods, size_t count, + const uint8_t utf8[static count], uint32_t state) +{ + const struct key_data *keymap; + if (sym == XKB_KEY_Escape && mods == MOD_NONE && term->modify_escape_key) { + static const struct key_data esc = {.seq = "\033[27;1;27~"}; + keymap = &esc; + } else + keymap = keymap_lookup(term, sym, mods); + + if (keymap != NULL) { + term_to_slave(term, keymap->seq, strlen(keymap->seq)); + return; + } + + if (count == 0) + return; + +#define is_control_key(x) ((x) >= 0x40 && (x) <= 0x7f) +#define IS_CTRL(x) ((x) < 0x20 || ((x) >= 0x7f && (x) <= 0x9f)) + + LOG_DBG("term->modify_other_keys=%d, count=%d, is_ctrl=%d (utf8=0x%02x), sym=%d", + term->modify_other_keys_2, count, IS_CTRL(utf8[0]), utf8[0], sym); + + bool ctrl_is_in_effect = (mods & MOD_CTRL) != 0; + bool ctrl_seq = is_control_key(sym) || (count == 1 && IS_CTRL(utf8[0])); + + if (mods != MOD_NONE && (term->modify_other_keys_2 || + (ctrl_is_in_effect && !ctrl_seq))) + { + static const int mod_param_map[32] = { + [MOD_SHIFT] = 2, + [MOD_ALT] = 3, + [MOD_SHIFT | MOD_ALT] = 4, + [MOD_CTRL] = 5, + [MOD_SHIFT | MOD_CTRL] = 6, + [MOD_ALT | MOD_CTRL] = 7, + [MOD_SHIFT | MOD_ALT | MOD_CTRL] = 8, + [MOD_META] = 9, + [MOD_META | MOD_SHIFT] = 10, + [MOD_META | MOD_ALT] = 11, + [MOD_META | MOD_SHIFT | MOD_ALT] = 12, + [MOD_META | MOD_CTRL] = 13, + [MOD_META | MOD_SHIFT | MOD_CTRL] = 14, + [MOD_META | MOD_ALT | MOD_CTRL] = 15, + [MOD_META | MOD_SHIFT | MOD_ALT | MOD_CTRL] = 16, + }; + + xassert(mods < sizeof(mod_param_map) / sizeof(mod_param_map[0])); + int modify_param = mod_param_map[mods]; + xassert(modify_param != 0); + + char reply[1024]; + size_t n = xsnprintf(reply, sizeof(reply), "\x1b[27;%d;%d~", modify_param, sym); + term_to_slave(term, reply, n); + } + + else if (mods & MOD_ALT) { + /* + * When the alt modifier is pressed, we do one out of three things: + * + * 1. we prefix the output bytes with ESC + * 2. we set the 8:th bit in the output byte + * 3. we ignore the alt modifier + * + * #1 is configured with \E[?1036, and is on by default + * + * If #1 has been disabled, we use #2, *if* it's a single + * byte we're emitting. Since this is an UTF-8 terminal, + * we then UTF8-encode the 8-bit character. #2 is + * configured with \E[?1034, and is on by default. + * + * Lastly, if both #1 and #2 have been disabled, the alt + * modifier is ignored. + */ + if (term->meta.esc_prefix) { + term_to_slave(term, "\x1b", 1); + term_to_slave(term, utf8, count); + } + + else if (term->meta.eight_bit && count == 1) { + const wchar_t wc = 0x80 | utf8[0]; + + char wc_as_utf8[8]; + mbstate_t ps = {0}; + size_t chars = wcrtomb(wc_as_utf8, wc, &ps); + + if (chars != (size_t)-1) + term_to_slave(term, wc_as_utf8, chars); + else + term_to_slave(term, wc_as_utf8, count); + } + + else { + /* Alt ignored */ + term_to_slave(term, utf8, count); + } + } else + term_to_slave(term, utf8, count); +} + static void key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, uint32_t key, uint32_t state) @@ -995,7 +1098,6 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, return; } - if (state == XKB_KEY_UP) { stop_repeater(seat, key); return; @@ -1120,24 +1222,6 @@ 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; - if (sym == XKB_KEY_Escape && keymap_mods == MOD_NONE && term->modify_escape_key) { - static const struct key_data esc = {.seq = "\033[27;1;27~"}; - keymap = &esc; - } else - keymap = keymap_lookup(term, sym, keymap_mods); - - if (keymap != NULL) { - term_to_slave(term, keymap->seq, strlen(keymap->seq)); - - term_reset_view(term); - selection_cancel(term); - goto maybe_repeat; - } - - if (compose_status == XKB_COMPOSE_CANCELLED) - goto maybe_repeat; - /* * Compose, and maybe emit "normal" character */ @@ -1145,13 +1229,13 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, xassert(seat->kbd.xkb_compose_state != NULL || compose_status != XKB_COMPOSE_COMPOSED); + if (compose_status == XKB_COMPOSE_CANCELLED) + goto maybe_repeat; + int count = compose_status == XKB_COMPOSE_COMPOSED ? xkb_compose_state_get_utf8(seat->kbd.xkb_compose_state, NULL, 0) : xkb_state_key_get_utf8(seat->kbd.xkb_state, key, NULL, 0); - if (count <= 0) - goto maybe_repeat; - /* Buffer for translated key. Use a static buffer in most cases, * and use a malloc:ed buffer when necessary */ uint8_t buf[32]; @@ -1166,89 +1250,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (seat->kbd.xkb_compose_state != NULL) xkb_compose_state_reset(seat->kbd.xkb_compose_state); -#define is_control_key(x) ((x) >= 0x40 && (x) <= 0x7f) -#define IS_CTRL(x) ((x) < 0x20 || ((x) >= 0x7f && (x) <= 0x9f)) - - LOG_DBG("term->modify_other_keys=%d, count=%d, is_ctrl=%d (utf8=0x%02x), sym=%d", - term->modify_other_keys_2, count, IS_CTRL(utf8[0]), utf8[0], sym); - - bool ctrl_is_in_effect = (keymap_mods & MOD_CTRL) != 0; - bool ctrl_seq = is_control_key(sym) || (count == 1 && IS_CTRL(utf8[0])); - - if (keymap_mods != MOD_NONE && (term->modify_other_keys_2 || - (ctrl_is_in_effect && !ctrl_seq))) - { - static const int mod_param_map[32] = { - [MOD_SHIFT] = 2, - [MOD_ALT] = 3, - [MOD_SHIFT | MOD_ALT] = 4, - [MOD_CTRL] = 5, - [MOD_SHIFT | MOD_CTRL] = 6, - [MOD_ALT | MOD_CTRL] = 7, - [MOD_SHIFT | MOD_ALT | MOD_CTRL] = 8, - [MOD_META] = 9, - [MOD_META | MOD_SHIFT] = 10, - [MOD_META | MOD_ALT] = 11, - [MOD_META | MOD_SHIFT | MOD_ALT] = 12, - [MOD_META | MOD_CTRL] = 13, - [MOD_META | MOD_SHIFT | MOD_CTRL] = 14, - [MOD_META | MOD_ALT | MOD_CTRL] = 15, - [MOD_META | MOD_SHIFT | MOD_ALT | MOD_CTRL] = 16, - }; - - xassert(keymap_mods < sizeof(mod_param_map) / sizeof(mod_param_map[0])); - int modify_param = mod_param_map[keymap_mods]; - xassert(modify_param != 0); - - char reply[1024]; - size_t n = xsnprintf(reply, sizeof(reply), "\x1b[27;%d;%d~", modify_param, sym); - term_to_slave(term, reply, n); - } - - else { - if (mods & (1 << seat->kbd.mod_alt)) { - /* - * When the alt modifier is pressed, we do one out of three things: - * - * 1. we prefix the output bytes with ESC - * 2. we set the 8:th bit in the output byte - * 3. we ignore the alt modifier - * - * #1 is configured with \E[?1036, and is on by default - * - * If #1 has been disabled, we use #2, *if* it's a single - * byte we're emitting. Since this is an UTF-8 terminal, - * we then UTF8-encode the 8-bit character. #2 is - * configured with \E[?1034, and is on by default. - * - * Lastly, if both #1 and #2 have been disabled, the alt - * modifier is ignored. - */ - if (term->meta.esc_prefix) { - term_to_slave(term, "\x1b", 1); - term_to_slave(term, utf8, count); - } - - else if (term->meta.eight_bit && count == 1) { - const wchar_t wc = 0x80 | utf8[0]; - - char utf8[8]; - mbstate_t ps = {0}; - size_t chars = wcrtomb(utf8, wc, &ps); - - if (chars != (size_t)-1) - term_to_slave(term, utf8, chars); - else - term_to_slave(term, utf8, count); - } - - else { - /* Alt ignored */ - term_to_slave(term, utf8, count); - } - } else - term_to_slave(term, utf8, count); - } + legacy_kbd_protocol(seat, term, sym, keymap_mods, count, utf8, state); if (utf8 != buf) free(utf8); -- cgit v1.3 From 2d85dbec6bbc0bfcb4ebfe219a024cd3f929a0d3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 20 Nov 2021 19:23:39 +0100 Subject: input: enable repeat while COMPOSING --- input.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index f5f6d754..e9d3e22b 100644 --- a/input.c +++ b/input.c @@ -1128,10 +1128,8 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, seat->kbd.xkb_compose_state); } - if (compose_status == XKB_COMPOSE_COMPOSING) { - /* TODO: goto maybe_repeat? */ - return; - } + if (compose_status == XKB_COMPOSE_COMPOSING) + goto maybe_repeat; xkb_mod_mask_t mods, consumed; get_current_modifiers(seat, &mods, &consumed, key); -- cgit v1.3 From ab5dfa3f3b5eab1a0763856c8d24792c0f07c12d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 20 Nov 2021 19:24:00 +0100 Subject: input: wip: add support for kitty kbd protocol “Disambiguate escape codes” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most things appear to work as in kitty. There’s one known difference: tri-state keys don’t generate the same unshifted symbol while holding Shift (but e.g. Ctrl+a and Ctrl+Shift+a *does* generate the same base symbol). For example, the Swedish keyboard layout has double quote, ‘2’ and ‘@’ on the same key. ‘2’ is the base (unshifted) symbol. Double quote is Shift+2. ‘@’ is AltGr+2. Kitty generates the same base symbol for ‘2’ and double quote (the base symbol is, as expected, ‘2’). But, for ‘@’ kitty generates the base symbol ‘@’. Currently, foot generates the base symbol by calling xkb_keysym_to_lower(). I _think_ what we need to do is “consume” the shift modifier, and then re-retrieve the symbol (given the current xkb state and key pressed). --- input.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 193 insertions(+), 21 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index e9d3e22b..9db2318d 100644 --- a/input.c +++ b/input.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -985,15 +986,22 @@ get_current_modifiers(const struct seat *seat, static void legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, - enum modifier mods, size_t count, - const uint8_t utf8[static count], uint32_t state) + xkb_mod_mask_t mods, xkb_mod_mask_t consumed, + size_t count, const uint8_t utf8[static count], + uint32_t state) { + enum modifier keymap_mods = MOD_NONE; + keymap_mods |= seat->kbd.shift ? MOD_SHIFT : MOD_NONE; + keymap_mods |= seat->kbd.alt ? MOD_ALT : MOD_NONE; + keymap_mods |= seat->kbd.ctrl ? MOD_CTRL : MOD_NONE; + keymap_mods |= seat->kbd.meta ? MOD_META : MOD_NONE; + const struct key_data *keymap; - if (sym == XKB_KEY_Escape && mods == MOD_NONE && term->modify_escape_key) { + if (sym == XKB_KEY_Escape && keymap_mods == MOD_NONE && term->modify_escape_key) { static const struct key_data esc = {.seq = "\033[27;1;27~"}; keymap = &esc; } else - keymap = keymap_lookup(term, sym, mods); + keymap = keymap_lookup(term, sym, keymap_mods); if (keymap != NULL) { term_to_slave(term, keymap->seq, strlen(keymap->seq)); @@ -1009,11 +1017,11 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, LOG_DBG("term->modify_other_keys=%d, count=%d, is_ctrl=%d (utf8=0x%02x), sym=%d", term->modify_other_keys_2, count, IS_CTRL(utf8[0]), utf8[0], sym); - bool ctrl_is_in_effect = (mods & MOD_CTRL) != 0; + bool ctrl_is_in_effect = (keymap_mods & MOD_CTRL) != 0; bool ctrl_seq = is_control_key(sym) || (count == 1 && IS_CTRL(utf8[0])); - if (mods != MOD_NONE && (term->modify_other_keys_2 || - (ctrl_is_in_effect && !ctrl_seq))) + if (keymap_mods != MOD_NONE && (term->modify_other_keys_2 || + (ctrl_is_in_effect && !ctrl_seq))) { static const int mod_param_map[32] = { [MOD_SHIFT] = 2, @@ -1033,8 +1041,8 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, [MOD_META | MOD_SHIFT | MOD_ALT | MOD_CTRL] = 16, }; - xassert(mods < sizeof(mod_param_map) / sizeof(mod_param_map[0])); - int modify_param = mod_param_map[mods]; + xassert(keymap_mods < sizeof(mod_param_map) / sizeof(mod_param_map[0])); + int modify_param = mod_param_map[keymap_mods]; xassert(modify_param != 0); char reply[1024]; @@ -1042,7 +1050,7 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, term_to_slave(term, reply, n); } - else if (mods & MOD_ALT) { + else if (keymap_mods & MOD_ALT) { /* * When the alt modifier is pressed, we do one out of three things: * @@ -1086,6 +1094,168 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, term_to_slave(term, utf8, count); } +static void +kitty_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, + xkb_mod_mask_t mods, xkb_mod_mask_t consumed, + size_t count, const uint8_t utf8[static count], + uint32_t utf32, enum xkb_compose_status compose_status, + uint32_t state) +{ + /* TODO: shift seems to already have been excluded from ‘mods’*/ + xkb_mod_mask_t effective = mods & ~consumed; + + if (compose_status == XKB_COMPOSE_COMPOSED) { + term_to_slave(term, utf8, count); + return; + } + + if (effective == 0) { + switch (sym) { + case XKB_KEY_Return: term_to_slave(term, "\r", 1); return; + case XKB_KEY_BackSpace: term_to_slave(term, "\x7f", 1); return; + case XKB_KEY_Tab: term_to_slave(term, "\t", 1); return; + } + + if (iswprint(utf32)) { + term_to_slave(term, utf8, count); + return; + } + } + + unsigned int encoded_mods = 0; + encoded_mods |= mods & (1 << seat->kbd.mod_shift) ? (1 << 0) : 0; + encoded_mods |= mods & (1 << seat->kbd.mod_alt) ? (1 << 1) : 0; + encoded_mods |= mods & (1 << seat->kbd.mod_ctrl) ? (1 << 2) : 0; + encoded_mods |= mods & (1 << seat->kbd.mod_meta) ? (1 << 3) : 0; + encoded_mods++; + + int key = -1; + char final; + + switch (sym) { + case XKB_KEY_Escape: key = 27; final = 'u'; break; + case XKB_KEY_Return: key = 13; final = 'u'; break; + case XKB_KEY_Tab: key = 9; final = 'u'; break; + case XKB_KEY_BackSpace: key = 127; final = 'u'; break; + case XKB_KEY_Insert: key = 2; final = '~'; break; + case XKB_KEY_Delete: key = 3; final = '~'; break; + case XKB_KEY_Left: key = 1; final = 'D'; break; + case XKB_KEY_Right: key = 1; final = 'C'; break; + case XKB_KEY_Up: key = 1; final = 'A'; break; + case XKB_KEY_Down: key = 1; final = 'B'; break; + case XKB_KEY_Page_Up: key = 5; final = '~'; break; + case XKB_KEY_Page_Down: key = 6; final = '~'; break; + case XKB_KEY_Home: key = 1; final = 'H'; break; + case XKB_KEY_End: key = 1; final = 'F'; break; + case XKB_KEY_Caps_Lock: key = 57358; final = 'u'; break; + case XKB_KEY_Scroll_Lock: key = 57359; final = 'u'; break; + case XKB_KEY_Num_Lock: key = 57360; final = 'u'; break; + case XKB_KEY_Print: key = 57361; final = 'u'; break; + case XKB_KEY_Pause: key = 57362; final = 'u'; break; + case XKB_KEY_Menu: key = 57363; final = 'u'; break; + case XKB_KEY_F1: key = 1; final = 'P'; break; + case XKB_KEY_F2: key = 1; final = 'Q'; break; + case XKB_KEY_F3: key = 1; final = 'R'; break; + case XKB_KEY_F4: key = 1; final = 'S'; break; + case XKB_KEY_F5: key = 15; final = '~'; break; + case XKB_KEY_F6: key = 17; final = '~'; break; + case XKB_KEY_F7: key = 18; final = '~'; break; + case XKB_KEY_F8: key = 19; final = '~'; break; + case XKB_KEY_F9: key = 20; final = '~'; break; + case XKB_KEY_F10: key = 21; final = '~'; break; + case XKB_KEY_F11: key = 23; final = '~'; break; + case XKB_KEY_F12: key = 24; final = '~'; break; + case XKB_KEY_F13: key = 57376; final = 'u'; break; + case XKB_KEY_F14: key = 57377; final = 'u'; break; + case XKB_KEY_F15: key = 57378; final = 'u'; break; + case XKB_KEY_F16: key = 57379; final = 'u'; break; + case XKB_KEY_F17: key = 57380; final = 'u'; break; + case XKB_KEY_F18: key = 57381; final = 'u'; break; + case XKB_KEY_F19: key = 57382; final = 'u'; break; + case XKB_KEY_F20: key = 57383; final = 'u'; break; + case XKB_KEY_F21: key = 57384; final = 'u'; break; + case XKB_KEY_F22: key = 57385; final = 'u'; break; + case XKB_KEY_F23: key = 57386; final = 'u'; break; + case XKB_KEY_F24: key = 57387; final = 'u'; break; + case XKB_KEY_F25: key = 57388; final = 'u'; break; + case XKB_KEY_F26: key = 57389; final = 'u'; break; + case XKB_KEY_F27: key = 57390; final = 'u'; break; + case XKB_KEY_F28: key = 57391; final = 'u'; break; + case XKB_KEY_F29: key = 57392; final = 'u'; break; + case XKB_KEY_F30: key = 57393; final = 'u'; break; + case XKB_KEY_F31: key = 57394; final = 'u'; break; + case XKB_KEY_F32: key = 57395; final = 'u'; break; + case XKB_KEY_F33: key = 57396; final = 'u'; break; + case XKB_KEY_F34: key = 57397; final = 'u'; break; + case XKB_KEY_F35: key = 57398; final = 'u'; break; + case XKB_KEY_KP_0: key = 57399; final = 'u'; break; + case XKB_KEY_KP_1: key = 57400; final = 'u'; break; + case XKB_KEY_KP_2: key = 57401; final = 'u'; break; + case XKB_KEY_KP_3: key = 57402; final = 'u'; break; + case XKB_KEY_KP_4: key = 57403; final = 'u'; break; + case XKB_KEY_KP_5: key = 57404; final = 'u'; break; + case XKB_KEY_KP_6: key = 57405; final = 'u'; break; + case XKB_KEY_KP_7: key = 57406; final = 'u'; break; + case XKB_KEY_KP_8: key = 57407; final = 'u'; break; + case XKB_KEY_KP_9: key = 57408; final = 'u'; break; + case XKB_KEY_KP_Decimal: key = 57409; final = 'u'; break; + case XKB_KEY_KP_Divide: key = 57410; final = 'u'; break; + case XKB_KEY_KP_Multiply: key = 57411; final = 'u'; break; + case XKB_KEY_KP_Subtract: key = 57412; final = 'u'; break; + case XKB_KEY_KP_Add: key = 57413; final = 'u'; break; + case XKB_KEY_KP_Enter: key = 57414; final = 'u'; break; + case XKB_KEY_KP_Equal: key = 57415; final = 'u'; break; + case XKB_KEY_KP_Separator: key = 57416; final = 'u'; break; + case XKB_KEY_KP_Left: key = 57417; final = 'u'; break; + case XKB_KEY_KP_Right: key = 57418; final = 'u'; break; + case XKB_KEY_KP_Up: key = 57419; final = 'u'; break; + case XKB_KEY_KP_Down: key = 57420; final = 'u'; break; + case XKB_KEY_KP_Page_Up: key = 57421; final = 'u'; break; + case XKB_KEY_KP_Page_Down: key = 57422; final = 'u'; break; + case XKB_KEY_KP_Home: key = 57423; final = 'u'; break; + case XKB_KEY_KP_End: key = 57424; final = 'u'; break; + case XKB_KEY_KP_Insert: key = 57425; final = 'u'; break; + case XKB_KEY_KP_Delete: key = 57426; final = 'u'; break; + case XKB_KEY_KP_Begin: key = 1; final = 'E'; break; + + default: + if (count > 0) { + if (effective == 0) { + term_to_slave(term, utf8, count); + return; + } + + /* TODO: this isn’t correct */ + key = xkb_keysym_to_lower(sym); + final = 'u'; + } + break; + } + + xassert(encoded_mods >= 1); + + char buf[16]; + int bytes; + + if (key < 0) + return; + + if (final == 'u' || final == '~') { + if (encoded_mods > 1) + bytes = snprintf(buf, sizeof(buf), "\x1b[%u;%u%c", + key, encoded_mods, final); + else + bytes = snprintf(buf, sizeof(buf), "\x1b[%u%c", key, final); + } else { + if (encoded_mods > 1) + bytes = snprintf(buf, sizeof(buf), "\x1b[1;%u%c", encoded_mods, final); + else + bytes = snprintf(buf, sizeof(buf), "\x1b[%c", final); + } + + term_to_slave(term, buf, bytes); +} + static void key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, uint32_t key, uint32_t state) @@ -1214,11 +1384,6 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, * Keys generating escape sequences */ - enum modifier keymap_mods = MOD_NONE; - keymap_mods |= seat->kbd.shift ? MOD_SHIFT : MOD_NONE; - keymap_mods |= seat->kbd.alt ? MOD_ALT : MOD_NONE; - keymap_mods |= seat->kbd.ctrl ? MOD_CTRL : MOD_NONE; - keymap_mods |= seat->kbd.meta ? MOD_META : MOD_NONE; /* * Compose, and maybe emit "normal" character @@ -1238,18 +1403,25 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, * and use a malloc:ed buffer when necessary */ uint8_t buf[32]; uint8_t *utf8 = count < sizeof(buf) ? buf : xmalloc(count + 1); + uint32_t utf32 = (uint32_t)-1; - compose_status == XKB_COMPOSE_COMPOSED - ? xkb_compose_state_get_utf8( - seat->kbd.xkb_compose_state, (char *)utf8, count + 1) - : xkb_state_key_get_utf8( + if (compose_status == XKB_COMPOSE_COMPOSED) { + xkb_compose_state_get_utf8( + seat->kbd.xkb_compose_state, (char *)utf8, count + 1); + } else { + xkb_state_key_get_utf8( seat->kbd.xkb_state, key, (char *)utf8, count + 1); + utf32 = xkb_state_key_get_utf32(seat->kbd.xkb_state, key); + } + + if (term->grid->kitty_kbd.flags[term->grid->kitty_kbd.idx] != 0) + kitty_kbd_protocol(seat, term, sym, mods, consumed, count, utf8, utf32, compose_status, state); + else + legacy_kbd_protocol(seat, term, sym, mods, consumed, count, utf8, state); if (seat->kbd.xkb_compose_state != NULL) xkb_compose_state_reset(seat->kbd.xkb_compose_state); - legacy_kbd_protocol(seat, term, sym, keymap_mods, count, utf8, state); - if (utf8 != buf) free(utf8); -- cgit v1.3 From b9d03c16a6f01aa1d1154423761e447bc171ee11 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 20 Nov 2021 20:31:59 +0100 Subject: input: kitty: use base symbol instead of lowering the symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When emitting an escape sequence for a printable character, with modifiers (e.g. ctrl+a), use the key’s base symbol instead of “lowering” it. This means we now handle e.g. ctrl+2 and ctrl+shift+2, with Swedish layout. There’s a twist however. We *only* use the base symbol if the modifiers that is used to “generate” the symbol are “significant”. Significant modifiers are, in this context, modifiers we can encode in the kitty escape sequences. In the Swedish layout, pressing AltGr+2 results in ‘@’. AltGr cannot be encoded in the kitty protocol. If we were to use the base symbol, AltGr+Alt+2 would result in exactly the same escape sequence as Alt+2. --- input.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- wayland.h | 2 + 2 files changed, 142 insertions(+), 22 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 9db2318d..f2dad7bc 100644 --- a/input.c +++ b/input.c @@ -674,6 +674,8 @@ 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_caps = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_CAPS); + 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"); @@ -961,16 +963,30 @@ UNITTEST xassert(strcmp(info->seq, "\033[27;3;13~") == 0); } -static void -get_current_modifiers(const struct seat *seat, - xkb_mod_mask_t *effective, - xkb_mod_mask_t *consumed, uint32_t key) +static xkb_mod_mask_t +get_insignificant_modifiers(const struct seat *seat) +{ + const xkb_mod_mask_t caps = 1 << seat->kbd.mod_caps; + const xkb_mod_mask_t num = 1 << seat->kbd.mod_num; + return caps | num; +} + +static xkb_mod_mask_t +get_significant_modifiers(const struct seat *seat) { const xkb_mod_mask_t ctrl = 1 << seat->kbd.mod_ctrl; const xkb_mod_mask_t alt = 1 << seat->kbd.mod_alt; const xkb_mod_mask_t shift = 1 << seat->kbd.mod_shift; const xkb_mod_mask_t meta = 1 << seat->kbd.mod_meta; - const xkb_mod_mask_t significant = ctrl | alt | shift | meta; + return ctrl | alt | shift | meta; +} + +static void +get_current_modifiers(const struct seat *seat, + xkb_mod_mask_t *effective, + xkb_mod_mask_t *consumed, uint32_t key) +{ + const xkb_mod_mask_t significant = get_significant_modifiers(seat); if (effective != NULL) { *effective = xkb_state_serialize_mods( @@ -984,11 +1000,32 @@ get_current_modifiers(const struct seat *seat, } } +struct kbd_ctx { + xkb_layout_index_t layout; + xkb_keycode_t key; + xkb_keysym_t sym; + + struct { + const xkb_keysym_t *syms; + size_t count; + } level0_syms; + + xkb_mod_mask_t mods; + xkb_mod_mask_t consumed; + + struct { + const uint8_t *buf; + size_t count; + } utf8; + uint32_t utf32; + + enum xkb_compose_status compose_status; + enum wl_keyboard_key_state key_state; +}; + static void -legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, - xkb_mod_mask_t mods, xkb_mod_mask_t consumed, - size_t count, const uint8_t utf8[static count], - uint32_t state) +legacy_kbd_protocol(struct seat *seat, struct terminal *term, + const struct kbd_ctx *ctx) { enum modifier keymap_mods = MOD_NONE; keymap_mods |= seat->kbd.shift ? MOD_SHIFT : MOD_NONE; @@ -996,6 +1033,10 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, keymap_mods |= seat->kbd.ctrl ? MOD_CTRL : MOD_NONE; keymap_mods |= seat->kbd.meta ? MOD_META : MOD_NONE; + const xkb_keysym_t sym = ctx->sym; + const size_t count = ctx->utf8.count; + const uint8_t *const utf8 = ctx->utf8.buf; + const struct key_data *keymap; if (sym == XKB_KEY_Escape && keymap_mods == MOD_NONE && term->modify_escape_key) { static const struct key_data esc = {.seq = "\033[27;1;27~"}; @@ -1095,16 +1136,18 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, } static void -kitty_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, - xkb_mod_mask_t mods, xkb_mod_mask_t consumed, - size_t count, const uint8_t utf8[static count], - uint32_t utf32, enum xkb_compose_status compose_status, - uint32_t state) +kitty_kbd_protocol(struct seat *seat, struct terminal *term, + const struct kbd_ctx *ctx) { - /* TODO: shift seems to already have been excluded from ‘mods’*/ - xkb_mod_mask_t effective = mods & ~consumed; - - if (compose_status == XKB_COMPOSE_COMPOSED) { + const xkb_mod_mask_t mods = ctx->mods; + const xkb_mod_mask_t consumed = ctx->consumed; + const xkb_mod_mask_t effective = mods & ~consumed; + const xkb_keysym_t sym = ctx->sym; + const uint32_t utf32 = ctx->utf32; + const uint8_t *const utf8 = ctx->utf8.buf; + const size_t count = ctx->utf8.count; + + if (ctx->compose_status == XKB_COMPOSE_COMPOSED) { term_to_slave(term, utf8, count); return; } @@ -1225,8 +1268,64 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, xkb_keysym_t sym, return; } - /* TODO: this isn’t correct */ - key = xkb_keysym_to_lower(sym); + /* + * Use keysym (typically its Unicode codepoint value). + * + * If the keysym is shifted, use its unshifted codepoint + * instead. In other words, ctrl+a and ctrl+shift+a should + * both use the same value for ‘key’ (97 - i.a. ‘a’). + * + * However, if a non-significant modifier was used to + * generate the symbol. This is needed since we cannot + * encode non-significant modifiers, and thus the “extra” + * modifier(s) would get lost. + * + * Example: + * + * the Swedish layout has ‘2’, QUOTATION MARK (“double + * quote”), ‘@’, and ‘²’ on the same key. ‘2’ is the base + * symbol. + * + * Shift+2 results in QUOTATION MARK + * AltGr+2 results in ‘@’ + * AltGr+Shift+2 results in ‘²’ + * + * The kitty kbd protocol can’t encode AltGr. So, if we + * always used the base symbol (‘2’), Alt+Shift+2 would + * result in the same escape sequence as + * AltGr+Alt+Shift+2. + * + * (yes, this matches what kitty does, as of 0.23.1) + */ + + /* Get the key’s shift level */ + xkb_level_index_t lvl = xkb_state_key_get_level( + seat->kbd.xkb_state, ctx->key, ctx->layout); + + /* And get all modifier combinations that, combined with + * the pressed key, results in the current shift level */ + xkb_mod_mask_t masks[32]; + size_t mask_count = xkb_keymap_key_get_mods_for_level( + seat->kbd.xkb_keymap, ctx->key, ctx->layout, lvl, + masks, ALEN(masks)); + + xkb_mod_mask_t significant = get_significant_modifiers(seat); + xkb_mod_mask_t insignificant = get_insignificant_modifiers(seat); + + /* Check modifier combinations - if a combination has + * modifiers not in our set of ‘significant’ modifiers, + * use key sym as-is */ + bool use_level0_sym = true; + for (size_t i = 0; i < mask_count; i++) { + if ((masks[i] & ~insignificant & ~significant) > 0) { + use_level0_sym = false; + break; + } + } + + key = use_level0_sym && ctx->level0_syms.count > 0 + ? ctx->level0_syms.syms[0] + : sym; final = 'u'; } break; @@ -1414,10 +1513,29 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, utf32 = xkb_state_key_get_utf32(seat->kbd.xkb_state, key); } + struct kbd_ctx ctx = { + .layout = layout_idx, + .key = key, + .sym = sym, + .level0_syms = { + .syms = raw_syms, + .count = raw_count, + }, + .mods = mods, + .consumed = consumed, + .utf8 = { + .buf = utf8, + .count = count, + }, + .utf32 = utf32, + .compose_status = compose_status, + .key_state = state, + }; + if (term->grid->kitty_kbd.flags[term->grid->kitty_kbd.idx] != 0) - kitty_kbd_protocol(seat, term, sym, mods, consumed, count, utf8, utf32, compose_status, state); + kitty_kbd_protocol(seat, term, &ctx); else - legacy_kbd_protocol(seat, term, sym, mods, consumed, count, utf8, state); + legacy_kbd_protocol(seat, term, &ctx); if (seat->kbd.xkb_compose_state != NULL) xkb_compose_state_reset(seat->kbd.xkb_compose_state); diff --git a/wayland.h b/wayland.h index 0fffc0a7..c36dff52 100644 --- a/wayland.h +++ b/wayland.h @@ -195,6 +195,8 @@ 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_caps; + xkb_mod_index_t mod_num; xkb_keycode_t key_arrow_up; xkb_keycode_t key_arrow_down; -- cgit v1.3 From db746d72edb2fdacf3cc9dbdf1acfc6b70ec3b08 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 11:27:31 +0100 Subject: input: get_current_modifiers() no longer strips insignificant mods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our internal binding handling cares about a different set of modifiers, compared to the kitty keyboard protocol. To handle this, get_current_modifiers() has been modified, to no longer strip the “unsignificant” modifiers. This is now up to the caller to do. To help, we keep two masks (for significant modifiers) in the seat struct; one for our internal binding handling (and the legacy keyboard protocol), and one for the kitty keyboard protocol. These two masks are updated when the seat’s keymap is updated/changed. --- input.c | 58 ++++++++++++++++++++++++---------------------------------- wayland.h | 3 +++ 2 files changed, 27 insertions(+), 34 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index f2dad7bc..c55bab3d 100644 --- a/input.c +++ b/input.c @@ -677,6 +677,16 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, seat->kbd.mod_caps = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_CAPS); seat->kbd.mod_num = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_NUM); + seat->kbd.bind_significant = + 1 << seat->kbd.mod_shift | + 1 << seat->kbd.mod_alt | + 1 << seat->kbd.mod_ctrl | + 1 << seat->kbd.mod_meta; + + seat->kbd.kitty_significant = seat->kbd.bind_significant | + 1 << seat->kbd.mod_caps | + 1 << seat->kbd.mod_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"); } @@ -963,41 +973,18 @@ UNITTEST xassert(strcmp(info->seq, "\033[27;3;13~") == 0); } -static xkb_mod_mask_t -get_insignificant_modifiers(const struct seat *seat) -{ - const xkb_mod_mask_t caps = 1 << seat->kbd.mod_caps; - const xkb_mod_mask_t num = 1 << seat->kbd.mod_num; - return caps | num; -} - -static xkb_mod_mask_t -get_significant_modifiers(const struct seat *seat) -{ - const xkb_mod_mask_t ctrl = 1 << seat->kbd.mod_ctrl; - const xkb_mod_mask_t alt = 1 << seat->kbd.mod_alt; - const xkb_mod_mask_t shift = 1 << seat->kbd.mod_shift; - const xkb_mod_mask_t meta = 1 << seat->kbd.mod_meta; - return ctrl | alt | shift | meta; -} - static void get_current_modifiers(const struct seat *seat, xkb_mod_mask_t *effective, xkb_mod_mask_t *consumed, uint32_t key) { - const xkb_mod_mask_t significant = get_significant_modifiers(seat); - if (effective != NULL) { *effective = xkb_state_serialize_mods( seat->kbd.xkb_state, XKB_STATE_MODS_EFFECTIVE); - *effective &= significant; } - if (consumed != NULL) { + if (consumed != NULL) *consumed = xkb_state_key_get_consumed_mods(seat->kbd.xkb_state, key); - *consumed &= significant; - } } struct kbd_ctx { @@ -1139,8 +1126,8 @@ static void kitty_kbd_protocol(struct seat *seat, struct terminal *term, const struct kbd_ctx *ctx) { - const xkb_mod_mask_t mods = ctx->mods; - const xkb_mod_mask_t consumed = ctx->consumed; + const xkb_mod_mask_t mods = ctx->mods & seat->kbd.kitty_significant; + const xkb_mod_mask_t consumed = ctx->consumed & seat->kbd.kitty_significant; const xkb_mod_mask_t effective = mods & ~consumed; const xkb_keysym_t sym = ctx->sym; const uint32_t utf32 = ctx->utf32; @@ -1170,6 +1157,8 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, encoded_mods |= mods & (1 << seat->kbd.mod_alt) ? (1 << 1) : 0; encoded_mods |= mods & (1 << seat->kbd.mod_ctrl) ? (1 << 2) : 0; encoded_mods |= mods & (1 << seat->kbd.mod_meta) ? (1 << 3) : 0; + encoded_mods |= mods & (1 << seat->kbd.mod_caps) ? (1 << 6) : 0; + encoded_mods |= mods & (1 << seat->kbd.mod_num) ? (1 << 7) : 0; encoded_mods++; int key = -1; @@ -1309,15 +1298,12 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, seat->kbd.xkb_keymap, ctx->key, ctx->layout, lvl, masks, ALEN(masks)); - xkb_mod_mask_t significant = get_significant_modifiers(seat); - xkb_mod_mask_t insignificant = get_insignificant_modifiers(seat); - /* Check modifier combinations - if a combination has * modifiers not in our set of ‘significant’ modifiers, * use key sym as-is */ bool use_level0_sym = true; for (size_t i = 0; i < mask_count; i++) { - if ((masks[i] & ~insignificant & ~significant) > 0) { + if ((masks[i] & ~seat->kbd.kitty_significant) > 0) { use_level0_sym = false; break; } @@ -1403,6 +1389,9 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, xkb_mod_mask_t mods, consumed; get_current_modifiers(seat, &mods, &consumed, key); + xkb_mod_mask_t bind_mods = mods & seat->kbd.bind_significant; + xkb_mod_mask_t bind_consumed = consumed & seat->kbd.bind_significant; + xkb_layout_index_t layout_idx = xkb_state_key_get_layout(seat->kbd.xkb_state, key); @@ -1414,13 +1403,13 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (should_repeat) start_repeater(seat, key); search_input( - seat, term, key, sym, mods, consumed, raw_syms, raw_count, serial); + seat, term, key, sym, bind_mods, bind_consumed, raw_syms, raw_count, serial); return; } else if (urls_mode_is_active(term)) { if (should_repeat) start_repeater(seat, key); urls_input( - seat, term, key, sym, mods, consumed, raw_syms, raw_count, serial); + seat, term, key, sym, bind_mods, bind_consumed, raw_syms, raw_count, serial); return; } @@ -1450,14 +1439,14 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, /* Match translated symbol */ if (bind->sym == sym && - bind->mods == (mods & ~consumed) && + bind->mods == (bind_mods & ~bind_consumed) && execute_binding( seat, term, bind->action, bind->pipe_argv, serial)) { goto maybe_repeat; } - if (bind->mods != mods) + if (bind->mods != bind_mods) continue; /* Match untranslated symbols */ @@ -2299,6 +2288,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, xkb_mod_mask_t mods; get_current_modifiers(seat, &mods, NULL, 0); + mods &= seat->kbd.bind_significant; /* Ignore Shift when matching modifiers, since it is * used to enable selection in mouse grabbing client diff --git a/wayland.h b/wayland.h index c36dff52..a2e1d17e 100644 --- a/wayland.h +++ b/wayland.h @@ -198,6 +198,9 @@ struct seat { xkb_mod_index_t mod_caps; xkb_mod_index_t mod_num; + xkb_mod_mask_t bind_significant; + xkb_mod_mask_t kitty_significant; + xkb_keycode_t key_arrow_up; xkb_keycode_t key_arrow_down; -- cgit v1.3 From e744cee7604eb0a98c4468d9f2160f440b851c7e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 11:38:36 +0100 Subject: input: kitty: printables are emitted as text, even if Caps- or Num-Lock is in effect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure if this is the best/correct way to do it. But kitty seems to ignore at least Num-Lock for printables, while it _does_ affect other keys. For example, Return, which usually emits ‘\r’, are affected by Num-Lock and emit ‘CSI 13;129u’. Note that as soon as some other modifier is in effect, the Num-Lock modifier *is* encoded in the CSI, also for printables. --- input.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index c55bab3d..6a1c29bc 100644 --- a/input.c +++ b/input.c @@ -1145,11 +1145,22 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_BackSpace: term_to_slave(term, "\x7f", 1); return; case XKB_KEY_Tab: term_to_slave(term, "\t", 1); return; } + } - if (iswprint(utf32)) { - term_to_slave(term, utf8, count); - return; - } + /* + * Printables without any modifiers are printed as is. + * + * TODO: plain text keys (a-z, 0-9 etc) are still printed as text, + * even when NumLock is active, despite NumLock being a + * significant modifier, *and* despite NumLock affecting other + * keys, like Return and Backspace; figure out if there’s some + * better magic than filtering out Caps- and Num-Lock here.. + */ + if (iswprint(utf32) && (effective & ~(1 << seat->kbd.mod_caps | + 1 << seat->kbd.mod_num)) == 0) + { + term_to_slave(term, utf8, count); + return; } unsigned int encoded_mods = 0; -- cgit v1.3 From ebad4bba2898cb285f69d42cfeb02b19bb142e1b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 11:44:53 +0100 Subject: input: kitty: disable CSI for Caps- and Num-Lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure why these keys have CSIs in the kitty spec; they don’t emit anything. Could it be that they are used if the keys are *not* modifiers in the current layout? --- input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 6a1c29bc..b4a46ec7 100644 --- a/input.c +++ b/input.c @@ -1190,9 +1190,9 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_Page_Down: key = 6; final = '~'; break; case XKB_KEY_Home: key = 1; final = 'H'; break; case XKB_KEY_End: key = 1; final = 'F'; break; - case XKB_KEY_Caps_Lock: key = 57358; final = 'u'; break; + //case XKB_KEY_Caps_Lock: key = 57358; final = 'u'; break; case XKB_KEY_Scroll_Lock: key = 57359; final = 'u'; break; - case XKB_KEY_Num_Lock: key = 57360; final = 'u'; break; + //case XKB_KEY_Num_Lock: key = 57360; final = 'u'; break; case XKB_KEY_Print: key = 57361; final = 'u'; break; case XKB_KEY_Pause: key = 57362; final = 'u'; break; case XKB_KEY_Menu: key = 57363; final = 'u'; break; -- cgit v1.3 From 8fb641a7ed66bf57ca77e0a6d574c3be43d4ce0e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 11:53:22 +0100 Subject: input: handle “invalid” XKB modifiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A modifier may not exist in a specific layout. This is indicated by XKB returning XKB_MOD_INVALID from xkb_keymap_mod_get_index(). --- input.c | 88 ++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 31 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index b4a46ec7..8be6639d 100644 --- a/input.c +++ b/input.c @@ -362,10 +362,14 @@ conf_modifiers_to_mask(const struct seat *seat, const struct config_key_modifiers *modifiers) { xkb_mod_mask_t mods = 0; - mods |= modifiers->shift << seat->kbd.mod_shift; - mods |= modifiers->ctrl << seat->kbd.mod_ctrl; - mods |= modifiers->alt << seat->kbd.mod_alt; - mods |= modifiers->meta << seat->kbd.mod_meta; + if (seat->kbd.mod_shift != XKB_MOD_INVALID) + mods |= modifiers->shift << seat->kbd.mod_shift; + if (seat->kbd.mod_ctrl != XKB_MOD_INVALID) + mods |= modifiers->ctrl << seat->kbd.mod_ctrl; + if (seat->kbd.mod_alt != XKB_MOD_INVALID) + mods |= modifiers->alt << seat->kbd.mod_alt; + if (seat->kbd.mod_meta != XKB_MOD_INVALID) + mods |= modifiers->meta << seat->kbd.mod_meta; return mods; } @@ -677,15 +681,21 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, seat->kbd.mod_caps = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_CAPS); seat->kbd.mod_num = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_NUM); - seat->kbd.bind_significant = - 1 << seat->kbd.mod_shift | - 1 << seat->kbd.mod_alt | - 1 << seat->kbd.mod_ctrl | - 1 << seat->kbd.mod_meta; - - seat->kbd.kitty_significant = seat->kbd.bind_significant | - 1 << seat->kbd.mod_caps | - 1 << seat->kbd.mod_num; + seat->kbd.bind_significant = 0; + if (seat->kbd.mod_shift != XKB_MOD_INVALID) + seat->kbd.bind_significant |= 1 << seat->kbd.mod_shift; + if (seat->kbd.mod_alt != XKB_MOD_INVALID) + seat->kbd.bind_significant |= 1 << seat->kbd.mod_alt; + if (seat->kbd.mod_ctrl != XKB_MOD_INVALID) + seat->kbd.bind_significant |= 1 << seat->kbd.mod_ctrl; + if (seat->kbd.mod_meta != XKB_MOD_INVALID) + seat->kbd.bind_significant |= 1 << seat->kbd.mod_meta; + + seat->kbd.kitty_significant = seat->kbd.bind_significant; + if (seat->kbd.mod_caps != XKB_MOD_INVALID) + seat->kbd.kitty_significant |= 1 << seat->kbd.mod_caps; + if (seat->kbd.mod_num != XKB_MOD_INVALID) + seat->kbd.kitty_significant |= 1 << seat->kbd.mod_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"); @@ -1129,6 +1139,9 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, const xkb_mod_mask_t mods = ctx->mods & seat->kbd.kitty_significant; const xkb_mod_mask_t consumed = ctx->consumed & seat->kbd.kitty_significant; const xkb_mod_mask_t effective = mods & ~consumed; + const xkb_mod_mask_t caps_num = + (seat->kbd.mod_caps != XKB_MOD_INVALID ? 1 << seat->kbd.mod_caps : 0) | + (seat->kbd.mod_num != XKB_MOD_INVALID ? 1 << seat->kbd.mod_num : 0); const xkb_keysym_t sym = ctx->sym; const uint32_t utf32 = ctx->utf32; const uint8_t *const utf8 = ctx->utf8.buf; @@ -1156,20 +1169,24 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, * keys, like Return and Backspace; figure out if there’s some * better magic than filtering out Caps- and Num-Lock here.. */ - if (iswprint(utf32) && (effective & ~(1 << seat->kbd.mod_caps | - 1 << seat->kbd.mod_num)) == 0) - { + if (iswprint(utf32) && (effective & ~caps_num) == 0) { term_to_slave(term, utf8, count); return; } unsigned int encoded_mods = 0; - encoded_mods |= mods & (1 << seat->kbd.mod_shift) ? (1 << 0) : 0; - encoded_mods |= mods & (1 << seat->kbd.mod_alt) ? (1 << 1) : 0; - encoded_mods |= mods & (1 << seat->kbd.mod_ctrl) ? (1 << 2) : 0; - encoded_mods |= mods & (1 << seat->kbd.mod_meta) ? (1 << 3) : 0; - encoded_mods |= mods & (1 << seat->kbd.mod_caps) ? (1 << 6) : 0; - encoded_mods |= mods & (1 << seat->kbd.mod_num) ? (1 << 7) : 0; + if (seat->kbd.mod_shift != XKB_MOD_INVALID) + encoded_mods |= mods & (1 << seat->kbd.mod_shift) ? (1 << 0) : 0; + if (seat->kbd.mod_alt != XKB_MOD_INVALID) + encoded_mods |= mods & (1 << seat->kbd.mod_alt) ? (1 << 1) : 0; + if (seat->kbd.mod_ctrl != XKB_MOD_INVALID) + encoded_mods |= mods & (1 << seat->kbd.mod_ctrl) ? (1 << 2) : 0; + if (seat->kbd.mod_meta != XKB_MOD_INVALID) + encoded_mods |= mods & (1 << seat->kbd.mod_meta) ? (1 << 3) : 0; + if (seat->kbd.mod_caps != XKB_MOD_INVALID) + encoded_mods |= mods & (1 << seat->kbd.mod_caps) ? (1 << 6) : 0; + if (seat->kbd.mod_num != XKB_MOD_INVALID) + encoded_mods |= mods & (1 << seat->kbd.mod_num) ? (1 << 7) : 0; encoded_mods++; int key = -1; @@ -1577,14 +1594,22 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, seat->kbd.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); /* Update state of modifiers we're interested in for e.g mouse events */ - seat->kbd.shift = xkb_state_mod_index_is_active( - seat->kbd.xkb_state, seat->kbd.mod_shift, XKB_STATE_MODS_EFFECTIVE); - seat->kbd.alt = xkb_state_mod_index_is_active( - seat->kbd.xkb_state, seat->kbd.mod_alt, XKB_STATE_MODS_EFFECTIVE); - seat->kbd.ctrl = xkb_state_mod_index_is_active( - seat->kbd.xkb_state, seat->kbd.mod_ctrl, XKB_STATE_MODS_EFFECTIVE); - seat->kbd.meta = xkb_state_mod_index_is_active( - seat->kbd.xkb_state, seat->kbd.mod_meta, XKB_STATE_MODS_EFFECTIVE); + seat->kbd.shift = seat->kbd.mod_shift != XKB_MOD_INVALID + ? xkb_state_mod_index_is_active( + seat->kbd.xkb_state, seat->kbd.mod_shift, XKB_STATE_MODS_EFFECTIVE) + : false; + seat->kbd.alt = seat->kbd.mod_alt != XKB_MOD_INVALID + ? xkb_state_mod_index_is_active( + seat->kbd.xkb_state, seat->kbd.mod_alt, XKB_STATE_MODS_EFFECTIVE) + : false; + seat->kbd.ctrl = seat->kbd.mod_ctrl != XKB_MOD_INVALID + ? xkb_state_mod_index_is_active( + seat->kbd.xkb_state, seat->kbd.mod_ctrl, XKB_STATE_MODS_EFFECTIVE) + : false; + seat->kbd.meta = seat->kbd.mod_meta != XKB_MOD_INVALID + ? xkb_state_mod_index_is_active( + seat->kbd.xkb_state, seat->kbd.mod_meta, XKB_STATE_MODS_EFFECTIVE) + : false; } if (seat->kbd_focus && seat->kbd_focus->active_surface == TERM_SURF_GRID) @@ -2304,7 +2329,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, /* Ignore Shift when matching modifiers, since it is * used to enable selection in mouse grabbing client * applications */ - mods &= ~(1 << seat->kbd.mod_shift); + if (seat->kbd.mod_shift != XKB_MOD_INVALID) + mods &= ~(1 << seat->kbd.mod_shift); const struct mouse_binding *match = NULL; -- cgit v1.3 From a08494a766973cb580dc09ff4d5b3efb40f6ecb5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 11:59:28 +0100 Subject: input: kitty: only emit CSIs for Caps- and Num-Lock when they aren’t modifiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 8be6639d..06f5b731 100644 --- a/input.c +++ b/input.c @@ -1207,9 +1207,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_Page_Down: key = 6; final = '~'; break; case XKB_KEY_Home: key = 1; final = 'H'; break; case XKB_KEY_End: key = 1; final = 'F'; break; - //case XKB_KEY_Caps_Lock: key = 57358; final = 'u'; break; case XKB_KEY_Scroll_Lock: key = 57359; final = 'u'; break; - //case XKB_KEY_Num_Lock: key = 57360; final = 'u'; break; case XKB_KEY_Print: key = 57361; final = 'u'; break; case XKB_KEY_Pause: key = 57362; final = 'u'; break; case XKB_KEY_Menu: key = 57363; final = 'u'; break; @@ -1278,6 +1276,20 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_KP_Delete: key = 57426; final = 'u'; break; case XKB_KEY_KP_Begin: key = 1; final = 'E'; break; + case XKB_KEY_Caps_Lock: + if (seat->kbd.mod_caps == XKB_MOD_INVALID) { + key = 57358; + final = 'u'; + } + break; + + case XKB_KEY_Num_Lock: + if (seat->kbd.mod_num == XKB_MOD_INVALID) { + key = 57360; + final = 'u'; + } + break; + default: if (count > 0) { if (effective == 0) { -- cgit v1.3 From 66171f104588a280e598ceb38dc90d9acdce060f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 12:01:16 +0100 Subject: input: rename ‘meta’ to ‘super’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 22 +++++++++++----------- terminal.c | 2 +- wayland.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 06f5b731..fed52a49 100644 --- a/input.c +++ b/input.c @@ -368,8 +368,8 @@ conf_modifiers_to_mask(const struct seat *seat, mods |= modifiers->ctrl << seat->kbd.mod_ctrl; if (seat->kbd.mod_alt != XKB_MOD_INVALID) mods |= modifiers->alt << seat->kbd.mod_alt; - if (seat->kbd.mod_meta != XKB_MOD_INVALID) - mods |= modifiers->meta << seat->kbd.mod_meta; + if (seat->kbd.mod_super != XKB_MOD_INVALID) + mods |= modifiers->meta << seat->kbd.mod_super; return mods; } @@ -677,7 +677,7 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, 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.mod_super = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_LOGO); seat->kbd.mod_caps = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_CAPS); seat->kbd.mod_num = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_NUM); @@ -688,8 +688,8 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, seat->kbd.bind_significant |= 1 << seat->kbd.mod_alt; if (seat->kbd.mod_ctrl != XKB_MOD_INVALID) seat->kbd.bind_significant |= 1 << seat->kbd.mod_ctrl; - if (seat->kbd.mod_meta != XKB_MOD_INVALID) - seat->kbd.bind_significant |= 1 << seat->kbd.mod_meta; + if (seat->kbd.mod_super != XKB_MOD_INVALID) + seat->kbd.bind_significant |= 1 << seat->kbd.mod_super; seat->kbd.kitty_significant = seat->kbd.bind_significant; if (seat->kbd.mod_caps != XKB_MOD_INVALID) @@ -801,7 +801,7 @@ keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, seat->kbd.shift = false; seat->kbd.alt = false; seat->kbd.ctrl = false; - seat->kbd.meta = false; + seat->kbd.super = false; if (seat->kbd.xkb_compose_state != NULL) xkb_compose_state_reset(seat->kbd.xkb_compose_state); @@ -1028,7 +1028,7 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, keymap_mods |= seat->kbd.shift ? MOD_SHIFT : MOD_NONE; keymap_mods |= seat->kbd.alt ? MOD_ALT : MOD_NONE; keymap_mods |= seat->kbd.ctrl ? MOD_CTRL : MOD_NONE; - keymap_mods |= seat->kbd.meta ? MOD_META : MOD_NONE; + keymap_mods |= seat->kbd.super ? MOD_META : MOD_NONE; const xkb_keysym_t sym = ctx->sym; const size_t count = ctx->utf8.count; @@ -1181,8 +1181,8 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, encoded_mods |= mods & (1 << seat->kbd.mod_alt) ? (1 << 1) : 0; if (seat->kbd.mod_ctrl != XKB_MOD_INVALID) encoded_mods |= mods & (1 << seat->kbd.mod_ctrl) ? (1 << 2) : 0; - if (seat->kbd.mod_meta != XKB_MOD_INVALID) - encoded_mods |= mods & (1 << seat->kbd.mod_meta) ? (1 << 3) : 0; + if (seat->kbd.mod_super != XKB_MOD_INVALID) + encoded_mods |= mods & (1 << seat->kbd.mod_super) ? (1 << 3) : 0; if (seat->kbd.mod_caps != XKB_MOD_INVALID) encoded_mods |= mods & (1 << seat->kbd.mod_caps) ? (1 << 6) : 0; if (seat->kbd.mod_num != XKB_MOD_INVALID) @@ -1618,9 +1618,9 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, ? xkb_state_mod_index_is_active( seat->kbd.xkb_state, seat->kbd.mod_ctrl, XKB_STATE_MODS_EFFECTIVE) : false; - seat->kbd.meta = seat->kbd.mod_meta != XKB_MOD_INVALID + seat->kbd.super = seat->kbd.mod_super != XKB_MOD_INVALID ? xkb_state_mod_index_is_active( - seat->kbd.xkb_state, seat->kbd.mod_meta, XKB_STATE_MODS_EFFECTIVE) + seat->kbd.xkb_state, seat->kbd.mod_super, XKB_STATE_MODS_EFFECTIVE) : false; } diff --git a/terminal.c b/terminal.c index a56ead03..e5c3ac65 100644 --- a/terminal.c +++ b/terminal.c @@ -2829,7 +2829,7 @@ term_mouse_grabbed(const struct terminal *term, struct seat *seat) return term->mouse_tracking == MOUSE_NONE || (seat->kbd_focus == term && seat->kbd.shift && - !seat->kbd.alt && /*!seat->kbd.ctrl &&*/ !seat->kbd.meta); + !seat->kbd.alt && /*!seat->kbd.ctrl &&*/ !seat->kbd.super); } void diff --git a/wayland.h b/wayland.h index a2e1d17e..d415588b 100644 --- a/wayland.h +++ b/wayland.h @@ -194,7 +194,7 @@ struct seat { xkb_mod_index_t mod_shift; xkb_mod_index_t mod_alt; xkb_mod_index_t mod_ctrl; - xkb_mod_index_t mod_meta; + xkb_mod_index_t mod_super; xkb_mod_index_t mod_caps; xkb_mod_index_t mod_num; @@ -208,7 +208,7 @@ struct seat { bool shift; bool alt; bool ctrl; - bool meta; + bool super; struct { key_binding_list_t key; -- cgit v1.3 From 1ec218c3ac0bf101a6b3e94945fc8fe0ed337c5f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 12:20:26 +0100 Subject: input: kitty: map ISO_Left_Tab to Tab --- input.c | 1 + 1 file changed, 1 insertion(+) (limited to 'input.c') diff --git a/input.c b/input.c index fed52a49..09595956 100644 --- a/input.c +++ b/input.c @@ -1196,6 +1196,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_Escape: key = 27; final = 'u'; break; case XKB_KEY_Return: key = 13; final = 'u'; break; case XKB_KEY_Tab: key = 9; final = 'u'; break; + case XKB_KEY_ISO_Left_Tab: key = 9; final = 'u'; break; case XKB_KEY_BackSpace: key = 127; final = 'u'; break; case XKB_KEY_Insert: key = 2; final = '~'; break; case XKB_KEY_Delete: key = 3; final = '~'; break; -- cgit v1.3 From 9933284ab1d1dd4baf0a3bd5c056b7c9dc5c70f4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 12:39:40 +0100 Subject: input: kitty: add ‘media’ keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 09595956..e1f4959e 100644 --- a/input.c +++ b/input.c @@ -1277,6 +1277,20 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_KP_Delete: key = 57426; final = 'u'; break; case XKB_KEY_KP_Begin: key = 1; final = 'E'; break; + case XKB_KEY_XF86AudioPlay: key = 57428; final = 'u'; break; + case XKB_KEY_XF86AudioPause: key = 57429; final = 'u'; break; + //case XKB_KEY_XF86AudioPlayPause: key = 57430; final = 'u'; break; + //case XKB_KEY_XF86AudioReverse: key = 57431; final = 'u'; break; + case XKB_KEY_XF86AudioStop: key = 57432; final = 'u'; break; + case XKB_KEY_XF86AudioForward: key = 57433; final = 'u'; break; + case XKB_KEY_XF86AudioRewind: key = 57434; final = 'u'; break; + case XKB_KEY_XF86AudioNext: key = 57435; final = 'u'; break; + case XKB_KEY_XF86AudioPrev: key = 57436; final = 'u'; break; + case XKB_KEY_XF86AudioRecord: key = 57437; final = 'u'; break; + case XKB_KEY_XF86AudioLowerVolume: key = 57438; final = 'u'; break; + case XKB_KEY_XF86AudioRaiseVolume: key = 57439; final = 'u'; break; + case XKB_KEY_XF86AudioMute: key = 57440; final = 'u'; break; + case XKB_KEY_Caps_Lock: if (seat->kbd.mod_caps == XKB_MOD_INVALID) { key = 57358; -- cgit v1.3 From 6930abe9452487d1b0e5842081d55437766ee469 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 12:40:04 +0100 Subject: input: kitty: add shift/alt/ctrl/super/hyper/meta keys --- input.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index e1f4959e..d8fee4e4 100644 --- a/input.c +++ b/input.c @@ -1305,6 +1305,54 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, } break; + case XKB_KEY_Shift_L: + case XKB_KEY_Shift_R: + if (seat->kbd.mod_shift == XKB_MOD_INVALID) { + key = sym == XKB_KEY_Shift_L ? 57441 : 57447; + final = 'u'; + } + break; + + case XKB_KEY_Control_L: + case XKB_KEY_Control_R: + if (seat->kbd.mod_ctrl == XKB_MOD_INVALID) { + key = sym == XKB_KEY_Control_L ? 57442 : 57448; + final = 'u'; + } + break; + + case XKB_KEY_Alt_L: + case XKB_KEY_Alt_R: + if (seat->kbd.mod_alt == XKB_MOD_INVALID) { + key = sym == XKB_KEY_Alt_L ? 57443 : 57449; + final = 'u'; + } + break; + + case XKB_KEY_Super_L: + case XKB_KEY_Super_R: + if (seat->kbd.mod_super == XKB_MOD_INVALID) { + key = sym == XKB_KEY_Super_L ? 57444 : 57450; + final = 'u'; + } + break; + + case XKB_KEY_Hyper_L: + case XKB_KEY_Hyper_R: + //if (seat->kbd.mod_hyper == XKB_MOD_INVALID) { + key = sym == XKB_KEY_Hyper_L ? 57445 : 57451; + final = 'u'; + //} + break; + + case XKB_KEY_Meta_L: + case XKB_KEY_Meta_R: + //if (seat->kbd.mod_meta == XKB_MOD_INVALID) { + key = sym == XKB_KEY_Meta_L ? 57446 : 57452; + final = 'u'; + //} + break; + default: if (count > 0) { if (effective == 0) { -- cgit v1.3 From 07068165ece205666cbb82196c3746e6b2b30776 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 13:53:52 +0100 Subject: input: only report modifiers when “Report all keys as escape codes” is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 78 ++++++++++++++--------------------------------------------------- 1 file changed, 17 insertions(+), 61 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index d8fee4e4..773c6c0c 100644 --- a/input.c +++ b/input.c @@ -1291,67 +1291,23 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_XF86AudioRaiseVolume: key = 57439; final = 'u'; break; case XKB_KEY_XF86AudioMute: key = 57440; final = 'u'; break; - case XKB_KEY_Caps_Lock: - if (seat->kbd.mod_caps == XKB_MOD_INVALID) { - key = 57358; - final = 'u'; - } - break; - - case XKB_KEY_Num_Lock: - if (seat->kbd.mod_num == XKB_MOD_INVALID) { - key = 57360; - final = 'u'; - } - break; - - case XKB_KEY_Shift_L: - case XKB_KEY_Shift_R: - if (seat->kbd.mod_shift == XKB_MOD_INVALID) { - key = sym == XKB_KEY_Shift_L ? 57441 : 57447; - final = 'u'; - } - break; - - case XKB_KEY_Control_L: - case XKB_KEY_Control_R: - if (seat->kbd.mod_ctrl == XKB_MOD_INVALID) { - key = sym == XKB_KEY_Control_L ? 57442 : 57448; - final = 'u'; - } - break; - - case XKB_KEY_Alt_L: - case XKB_KEY_Alt_R: - if (seat->kbd.mod_alt == XKB_MOD_INVALID) { - key = sym == XKB_KEY_Alt_L ? 57443 : 57449; - final = 'u'; - } - break; - - case XKB_KEY_Super_L: - case XKB_KEY_Super_R: - if (seat->kbd.mod_super == XKB_MOD_INVALID) { - key = sym == XKB_KEY_Super_L ? 57444 : 57450; - final = 'u'; - } - break; - - case XKB_KEY_Hyper_L: - case XKB_KEY_Hyper_R: - //if (seat->kbd.mod_hyper == XKB_MOD_INVALID) { - key = sym == XKB_KEY_Hyper_L ? 57445 : 57451; - final = 'u'; - //} - break; - - case XKB_KEY_Meta_L: - case XKB_KEY_Meta_R: - //if (seat->kbd.mod_meta == XKB_MOD_INVALID) { - key = sym == XKB_KEY_Meta_L ? 57446 : 57452; - final = 'u'; - //} - break; +#if 0 /* TODO: enable when “Report all keys as escape codes” is enabled */ + case XKB_KEY_Caps_Lock: key = 57358; final = 'u'; break; + case XKB_KEY_Num_Lock: key = 57360; final = 'u'; break; + + case XKB_KEY_Shift_L: key = 57441; final = 'u'; break; + case XKB_KEY_Control_L: key = 57442; final = 'u'; break; + case XKB_KEY_Alt_L: key = 57443; final = 'u'; break; + case XKB_KEY_Super_L: key = 57444; final = 'u'; break; + case XKB_KEY_Hyper_L: key = 57445; final = 'u'; break; + case XKB_KEY_Meta_L: key = 57446; final = 'u'; break; + case XKB_KEY_Shift_R: key = 57447; final = 'u'; break; + case XKB_KEY_Control_R: key = 57448; final = 'u'; break; + case XKB_KEY_Alt_R: key = 57449; final = 'u'; break; + case XKB_KEY_Super_R: key = 57450; final = 'u'; break; + case XKB_KEY_Hyper_R: key = 57451; final = 'u'; break; + case XKB_KEY_Meta_R: key = 57452; final = 'u'; break; +#endif default: if (count > 0) { -- cgit v1.3 From ce8ea2db66db0f81312df8fc993aa47d200a1305 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 15:05:38 +0100 Subject: input: legacy: reduce size of reply buffer Its maximum size is known; the only two variables are two integers. We know the maximum length of an integer converted to a string. --- input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index 773c6c0c..9d4efe34 100644 --- a/input.c +++ b/input.c @@ -1083,7 +1083,7 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, int modify_param = mod_param_map[keymap_mods]; xassert(modify_param != 0); - char reply[1024]; + char reply[32]; size_t n = xsnprintf(reply, sizeof(reply), "\x1b[27;%d;%d~", modify_param, sym); term_to_slave(term, reply, n); } -- cgit v1.3 From 42d1fcb48443091672ac11a76985297f994f08c0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 15:06:41 +0100 Subject: input: grammar: “an UTF-8” -> “a UTF-8” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 9d4efe34..211d3dc8 100644 --- a/input.c +++ b/input.c @@ -1098,10 +1098,10 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, * * #1 is configured with \E[?1036, and is on by default * - * If #1 has been disabled, we use #2, *if* it's a single - * byte we're emitting. Since this is an UTF-8 terminal, - * we then UTF8-encode the 8-bit character. #2 is - * configured with \E[?1034, and is on by default. + * If #1 has been disabled, we use #2, *if* it's a single byte + * we're emitting. Since this is a UTF-8 terminal, we then + * UTF8-encode the 8-bit character. #2 is configured with + * \E[?1034, and is on by default. * * Lastly, if both #1 and #2 have been disabled, the alt * modifier is ignored. -- cgit v1.3 From 546bcd66b7a96ab9dfc3e3e598efd604a6e95858 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 15:07:38 +0100 Subject: input: legacy: use ALEN(mod_param_map) --- input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index 211d3dc8..2c2cfa96 100644 --- a/input.c +++ b/input.c @@ -1079,7 +1079,7 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, [MOD_META | MOD_SHIFT | MOD_ALT | MOD_CTRL] = 16, }; - xassert(keymap_mods < sizeof(mod_param_map) / sizeof(mod_param_map[0])); + xassert(keymap_mods < ALEN(mod_param_map)); int modify_param = mod_param_map[keymap_mods]; xassert(modify_param != 0); -- cgit v1.3 From 913dd8b4a600538a0d90c2847395d0ad92ae5ea4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 27 Nov 2021 18:44:29 +0100 Subject: input: get_current_modifiers(): use xkb_state_key_get_consumed_mods2() Explicitly request consumed modifiers using the `XKB` mode. --- input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 2c2cfa96..b37a02f7 100644 --- a/input.c +++ b/input.c @@ -993,8 +993,10 @@ get_current_modifiers(const struct seat *seat, seat->kbd.xkb_state, XKB_STATE_MODS_EFFECTIVE); } - if (consumed != NULL) - *consumed = xkb_state_key_get_consumed_mods(seat->kbd.xkb_state, key); + if (consumed != NULL) { + *consumed = xkb_state_key_get_consumed_mods2( + seat->kbd.xkb_state, key, XKB_CONSUMED_MODE_XKB); + } } struct kbd_ctx { -- cgit v1.3 From 8f41a8dc941c4bddbe7134498a25c41546c5188f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 27 Nov 2021 18:45:23 +0100 Subject: input: kitty: use `XKB_CONSUMED_MODE_GTK` when retrieving consumed mods --- input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index b37a02f7..f97deb93 100644 --- a/input.c +++ b/input.c @@ -1139,7 +1139,8 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, const struct kbd_ctx *ctx) { const xkb_mod_mask_t mods = ctx->mods & seat->kbd.kitty_significant; - const xkb_mod_mask_t consumed = ctx->consumed & seat->kbd.kitty_significant; + const xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods2( + seat->kbd.xkb_state, ctx->key, XKB_CONSUMED_MODE_GTK) & seat->kbd.kitty_significant; const xkb_mod_mask_t effective = mods & ~consumed; const xkb_mod_mask_t caps_num = (seat->kbd.mod_caps != XKB_MOD_INVALID ? 1 << seat->kbd.mod_caps : 0) | -- cgit v1.3 From a55a3daae7280350f413bcb7570104480fcbebcd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 28 Nov 2021 16:48:30 +0100 Subject: input: regression: special keys don’t reset view and cancel selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an issue where e.g. holding down ctrl would cancel the selection, thus making it impossible to copy text to the clipboard. --- input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index f97deb93..0c981376 100644 --- a/input.c +++ b/input.c @@ -1594,8 +1594,10 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (utf8 != buf) free(utf8); - term_reset_view(term); - selection_cancel(term); + if (count > 0) { + term_reset_view(term); + selection_cancel(term); + } maybe_repeat: clock_gettime( -- cgit v1.3 From 5c2557b42116dd6d0f86c90b2cf04cd43f80a36e Mon Sep 17 00:00:00 2001 From: Jonas Ådahl Date: Fri, 19 Nov 2021 15:02:48 +0100 Subject: terminal: Make seat xcursor update focus aware When term_xcursor_update_for_seat() was called on e.g. keyboard focus loss, it'd update the curret xcursor to 'text' even if it was e.g. on top of the window title, or resize areas. This makes the function a bit more focus aware, and will not be so eager to set the text xcursor. --- input.c | 2 +- input.h | 2 ++ terminal.c | 43 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 9 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 0aef43cc..5f864a8d 100644 --- a/input.c +++ b/input.c @@ -1372,7 +1372,7 @@ is_bottom_right(const struct terminal *term, int x, int y) (term->active_surface == TERM_SURF_BORDER_BOTTOM && x > term->width + 1 * csd_border_size * term->scale - 10 * term->scale))); } -static const char * +const char * xcursor_for_csd_border(struct terminal *term, int x, int y) { if (is_top_left(term, x, y)) return XCURSOR_TOP_LEFT_CORNER; diff --git a/input.h b/input.h index 68b8719d..5a2c7a67 100644 --- a/input.h +++ b/input.h @@ -26,3 +26,5 @@ extern const struct wl_keyboard_listener keyboard_listener; extern const struct wl_pointer_listener pointer_listener; void input_repeat(struct seat *seat, uint32_t key); + +const char * xcursor_for_csd_border(struct terminal *term, int x, int y); diff --git a/terminal.c b/terminal.c index df8128fc..83204675 100644 --- a/terminal.c +++ b/terminal.c @@ -3015,14 +3015,41 @@ term_mouse_motion(struct terminal *term, int button, int row, int col, void term_xcursor_update_for_seat(struct terminal *term, struct seat *seat) { - const char *xcursor - = seat->pointer.hidden ? XCURSOR_HIDDEN - : term->is_searching ? XCURSOR_LEFT_PTR - : (seat->mouse.col >= 0 && - seat->mouse.row >= 0 && - term_mouse_grabbed(term, seat)) ? XCURSOR_TEXT - : term->is_searching ? XCURSOR_TEXT - : XCURSOR_LEFT_PTR; + const char *xcursor; + + switch (term->active_surface) { + case TERM_SURF_GRID: { + xcursor = seat->pointer.hidden ? XCURSOR_HIDDEN + : term->is_searching ? XCURSOR_LEFT_PTR + : (seat->mouse.col >= 0 && + seat->mouse.row >= 0 && + term_mouse_grabbed(term, seat)) ? XCURSOR_TEXT + : term->is_searching ? XCURSOR_TEXT + : XCURSOR_LEFT_PTR; + break; + } + case TERM_SURF_SEARCH: + case TERM_SURF_SCROLLBACK_INDICATOR: + case TERM_SURF_RENDER_TIMER: + case TERM_SURF_JUMP_LABEL: + case TERM_SURF_TITLE: + case TERM_SURF_BUTTON_MINIMIZE: + case TERM_SURF_BUTTON_MAXIMIZE: + case TERM_SURF_BUTTON_CLOSE: + xcursor = XCURSOR_LEFT_PTR; + break; + + case TERM_SURF_BORDER_LEFT: + case TERM_SURF_BORDER_RIGHT: + case TERM_SURF_BORDER_TOP: + case TERM_SURF_BORDER_BOTTOM: + xcursor = xcursor_for_csd_border(term, seat->mouse.x, seat->mouse.y); + break; + + case TERM_SURF_NONE: + default: + return; + } render_xcursor_set(seat, term, xcursor); } -- cgit v1.3 From c0ce131f1a4195585cc89f58ab65cfd7658ca0b7 Mon Sep 17 00:00:00 2001 From: Jonas Ådahl Date: Fri, 19 Nov 2021 15:04:51 +0100 Subject: input: Update mouse x/y coordinates on wl_pointer_enter Otherwise if you don't receive motion event before e.g. button pressed, the coordinates will be incorrect. This happens when e.g. you get alt-tabbed so that the mouse cursor ends up on top of the terminal window, but the mouse never actually moved. --- input.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 5f864a8d..35baf3d4 100644 --- a/input.c +++ b/input.c @@ -1405,11 +1405,18 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, struct wl_window *win = wl_surface_get_user_data(surface); struct terminal *term = win->term; + int x = wl_fixed_to_int(surface_x) * term->scale; + int y = wl_fixed_to_int(surface_y) * term->scale; + seat->pointer.serial = serial; seat->pointer.hidden = false; + seat->mouse.x = x; + seat->mouse.y = y; - LOG_DBG("pointer-enter: pointer=%p, serial=%u, surface = %p, new-moused = %p", - (void *)wl_pointer, serial, (void *)surface, (void *)term); + LOG_DBG("pointer-enter: pointer=%p, serial=%u, surface = %p, new-moused = %p, " + "x=%d, y=%d", + (void *)wl_pointer, serial, (void *)surface, (void *)term, + x, y); xassert(tll_length(seat->mouse.buttons) == 0); @@ -1418,9 +1425,6 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, seat->mouse_focus = term; - int x = wl_fixed_to_int(surface_x) * term->scale; - int y = wl_fixed_to_int(surface_y) * term->scale; - switch ((term->active_surface = term_surface_kind(term, surface))) { case TERM_SURF_GRID: { /* -- cgit v1.3 From 38741baf9afc2697c7e508cb87c3b2983de9f0af Mon Sep 17 00:00:00 2001 From: Jonas Ådahl Date: Fri, 19 Nov 2021 15:08:46 +0100 Subject: input: Add support for xdg_toplevl.show_window_menu() This makes, if the compositor supports it, the window menu appear when right clicking on the title bar. --- input.c | 10 ++++++++++ render.c | 9 +-------- render.h | 9 +++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 35baf3d4..7e0cde75 100644 --- a/input.c +++ b/input.c @@ -1924,6 +1924,16 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, close(fd); } } + + if (button == BTN_RIGHT && tll_length(seat->mouse.buttons) == 1) { + struct csd_data info; + info = get_csd_data(term, CSD_SURF_TITLE); + xdg_toplevel_show_window_menu( + win->xdg_toplevel, + seat->wl_seat, + seat->pointer.serial, + seat->mouse.x + info.x, seat->mouse.y + info.y); + } } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) { diff --git a/render.c b/render.c index 46cc0f75..76fe7c95 100644 --- a/render.c +++ b/render.c @@ -1521,14 +1521,7 @@ render_worker_thread(void *_ctx) return -1; } -struct csd_data { - int x; - int y; - int width; - int height; -}; - -static struct csd_data +struct csd_data get_csd_data(const struct terminal *term, enum csd_surface surf_idx) { xassert(term->window->csd_mode == CSD_YES); diff --git a/render.h b/render.h index 1179a5dc..145aaba8 100644 --- a/render.h +++ b/render.h @@ -24,3 +24,12 @@ struct render_worker_context { struct terminal *term; }; int render_worker_thread(void *_ctx); + +struct csd_data { + int x; + int y; + int width; + int height; +}; + +struct csd_data get_csd_data(const struct terminal *term, enum csd_surface surf_idx); -- cgit v1.3 From 73a048f9d37af86264c5c48b7889e20f3e57f693 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 29 Nov 2021 19:31:48 +0100 Subject: input: regression: reset view (and cancel selection) on “handled” input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a regression, where the view (and selection) was only reset if the keyboard input resulted in plain text. That is, key presses like enter, arrows etc did not. --- input.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 0c981376..bafd413b 100644 --- a/input.c +++ b/input.c @@ -1022,7 +1022,7 @@ struct kbd_ctx { enum wl_keyboard_key_state key_state; }; -static void +static bool legacy_kbd_protocol(struct seat *seat, struct terminal *term, const struct kbd_ctx *ctx) { @@ -1045,11 +1045,11 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, if (keymap != NULL) { term_to_slave(term, keymap->seq, strlen(keymap->seq)); - return; + return true; } if (count == 0) - return; + return false; #define is_control_key(x) ((x) >= 0x40 && (x) <= 0x7f) #define IS_CTRL(x) ((x) < 0x20 || ((x) >= 0x7f && (x) <= 0x9f)) @@ -1132,9 +1132,11 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, } } else term_to_slave(term, utf8, count); + + return true; } -static void +static bool kitty_kbd_protocol(struct seat *seat, struct terminal *term, const struct kbd_ctx *ctx) { @@ -1152,14 +1154,14 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, if (ctx->compose_status == XKB_COMPOSE_COMPOSED) { term_to_slave(term, utf8, count); - return; + return true; } if (effective == 0) { switch (sym) { - case XKB_KEY_Return: term_to_slave(term, "\r", 1); return; - case XKB_KEY_BackSpace: term_to_slave(term, "\x7f", 1); return; - case XKB_KEY_Tab: term_to_slave(term, "\t", 1); return; + case XKB_KEY_Return: term_to_slave(term, "\r", 1); return true; + case XKB_KEY_BackSpace: term_to_slave(term, "\x7f", 1); return true; + case XKB_KEY_Tab: term_to_slave(term, "\t", 1); return true; } } @@ -1174,7 +1176,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, */ if (iswprint(utf32) && (effective & ~caps_num) == 0) { term_to_slave(term, utf8, count); - return; + return true; } unsigned int encoded_mods = 0; @@ -1316,7 +1318,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, if (count > 0) { if (effective == 0) { term_to_slave(term, utf8, count); - return; + return true; } /* @@ -1385,7 +1387,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, int bytes; if (key < 0) - return; + return false; if (final == 'u' || final == '~') { if (encoded_mods > 1) @@ -1401,6 +1403,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, } term_to_slave(term, buf, bytes); + return true; } static void @@ -1583,10 +1586,9 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, .key_state = state, }; - if (term->grid->kitty_kbd.flags[term->grid->kitty_kbd.idx] != 0) - kitty_kbd_protocol(seat, term, &ctx); - else - legacy_kbd_protocol(seat, term, &ctx); + bool handled = term->grid->kitty_kbd.flags[term->grid->kitty_kbd.idx] != 0 + ? kitty_kbd_protocol(seat, term, &ctx) + : legacy_kbd_protocol(seat, term, &ctx); if (seat->kbd.xkb_compose_state != NULL) xkb_compose_state_reset(seat->kbd.xkb_compose_state); @@ -1594,7 +1596,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (utf8 != buf) free(utf8); - if (count > 0) { + if (handled) { term_reset_view(term); selection_cancel(term); } -- cgit v1.3 From fce13c4106afa3509536802d2c7d74e4d8b8e50d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 30 Nov 2021 22:15:13 +0100 Subject: input: make csd_data variable ‘const’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index b8b27d4c..e3b14297 100644 --- a/input.c +++ b/input.c @@ -2282,8 +2282,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } if (button == BTN_RIGHT && tll_length(seat->mouse.buttons) == 1) { - struct csd_data info; - info = get_csd_data(term, CSD_SURF_TITLE); + const struct csd_data info = get_csd_data(term, CSD_SURF_TITLE); xdg_toplevel_show_window_menu( win->xdg_toplevel, seat->wl_seat, -- cgit v1.3 From 63e8b1b2924aef94316e621513fd938eb0acc4e9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 1 Dec 2021 20:03:18 +0100 Subject: input: fix debug log format specifier; ‘count’ is a size_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'input.c') diff --git a/input.c b/input.c index e3b14297..ef81b637 100644 --- a/input.c +++ b/input.c @@ -1054,7 +1054,7 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, #define is_control_key(x) ((x) >= 0x40 && (x) <= 0x7f) #define IS_CTRL(x) ((x) < 0x20 || ((x) >= 0x7f && (x) <= 0x9f)) - LOG_DBG("term->modify_other_keys=%d, count=%d, is_ctrl=%d (utf8=0x%02x), sym=%d", + LOG_DBG("term->modify_other_keys=%d, count=%zu, is_ctrl=%d (utf8=0x%02x), sym=%d", term->modify_other_keys_2, count, IS_CTRL(utf8[0]), utf8[0], sym); bool ctrl_is_in_effect = (keymap_mods & MOD_CTRL) != 0; -- cgit v1.3 From 1619e83c13875f71f79e5ca0e4504dd59dd81d79 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 1 Dec 2021 20:04:01 +0100 Subject: input: always update the xcursor shape in pointer enter/motion events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that term_xcursor_update_for_seat() takes the current surface into account (i.e. doesn’t assume the cursor is over the main grid), there’s no longer any need to call render_xcursor_set() directly. Thus, we can simply call term_xcursor_update_for_seat() on **all** pointer enter and motion events. As long as we take care to update the internal state to reflect the, possibly new, current surface before doing so. Also make sure to **always** reset the seat’s “current” xcursor pointer on pointer leave events. This is done without actually sending anything to the compositor, but is necessary to ensure that we *do* send a request to update the xcursor on the next pointer enter event. --- CHANGELOG.md | 1 + input.c | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) (limited to 'input.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index 97f20302..1a725822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ * CSD border not being dimmed when window is not focused. * Visual corruption with large CSD borders (https://codeberg.org/dnkl/foot/issues/823). +* Mouse cursor shape sometimes not being updated correctly. ### Security diff --git a/input.c b/input.c index ef81b637..055c0fc8 100644 --- a/input.c +++ b/input.c @@ -1773,12 +1773,13 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, xassert(tll_length(seat->mouse.buttons) == 0); - /* Scale may have changed */ - wayl_reload_xcursor_theme(seat, term->scale); - seat->mouse_focus = term; + term->active_surface = term_surface_kind(term, surface); + + wayl_reload_xcursor_theme(seat, term->scale); /* Scale may have changed */ + term_xcursor_update_for_seat(term, seat); - switch ((term->active_surface = term_surface_kind(term, surface))) { + switch (term->active_surface) { case TERM_SURF_GRID: { /* * Translate x,y pixel coordinate to a cell coordinate, or -1 @@ -1796,7 +1797,6 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, else seat->mouse.row = (y - term->margins.top) / term->cell_height; - term_xcursor_update_for_seat(term, seat); break; } @@ -1805,20 +1805,15 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_RENDER_TIMER: case TERM_SURF_JUMP_LABEL: case TERM_SURF_TITLE: - render_xcursor_set(seat, term, XCURSOR_LEFT_PTR); - break; - case TERM_SURF_BORDER_LEFT: case TERM_SURF_BORDER_RIGHT: case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: - render_xcursor_set(seat, term, xcursor_for_csd_border(term, x, y)); break; case TERM_SURF_BUTTON_MINIMIZE: case TERM_SURF_BUTTON_MAXIMIZE: case TERM_SURF_BUTTON_CLOSE: - render_xcursor_set(seat, term, XCURSOR_LEFT_PTR); render_refresh_csd(term); break; @@ -1847,9 +1842,11 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, wl_callback_destroy(seat->pointer.xcursor_callback); seat->pointer.xcursor_callback = NULL; seat->pointer.xcursor_pending = false; - seat->pointer.xcursor = NULL; } + /* Reset last-set-xcursor, to ensure we update it on a pointer-enter event */ + seat->pointer.xcursor = NULL; + /* Reset mouse state */ seat->mouse.x = seat->mouse.y = 0; seat->mouse.col = seat->mouse.row = 0; @@ -1876,7 +1873,6 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, enum term_surface active_surface = old_moused->active_surface; old_moused->active_surface = TERM_SURF_NONE; - term_xcursor_update_for_seat(old_moused, seat); switch (active_surface) { case TERM_SURF_BUTTON_MINIMIZE: @@ -1929,6 +1925,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, seat->mouse.x = x; seat->mouse.y = y; + term_xcursor_update_for_seat(term, seat); + enum term_surface surf_kind = term->active_surface; int button = 0; bool send_to_client = false; @@ -1966,7 +1964,6 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BORDER_RIGHT: case TERM_SURF_BORDER_TOP: case TERM_SURF_BORDER_BOTTOM: - render_xcursor_set(seat, term, xcursor_for_csd_border(term, x, y)); break; case TERM_SURF_GRID: { @@ -2017,8 +2014,6 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, xassert(seat->mouse.col == -1 || (seat->mouse.col >= 0 && seat->mouse.col < term->cols)); xassert(seat->mouse.row == -1 || (seat->mouse.row >= 0 && seat->mouse.row < term->rows)); - term_xcursor_update_for_seat(term, seat); - /* Cursor has moved to a different cell since last time */ bool cursor_is_on_new_cell = old_col != seat->mouse.col || old_row != seat->mouse.row; -- cgit v1.3