From 18b702b2495d4fb9328930eed9875731cff4cbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 21 May 2024 07:06:45 +0200 Subject: [PATCH] unicode-mode: move state from seat to term This fixes an issue where entering unicode-mode in one foot client, also enabled unicode-mode on other foot clients. Both visually (although glitchy), and in effect. The reason the state was originally in the seat objects, was to fully support multi-seat. That is, one seat/keyboard entering unicode-mode should not affect other seats/keyboards. The issue with this is that seat objects are Wayland global. Thus, in server mode, all seat objects are shared between the foot clients. There is a similarity with IME, which also keeps state in the seat. There's one big difference, however, and that is IME has Wayland native enter/leave events, that the compositor emits when windows are focused/unfocused. These events allow us to reset IME state. For our own Unicode mode, there is nothing similar. This patch moves the Unicode state from seats, to the terminal struct. This does mean that if one seat/keyboard enters Unicode mode, then *all* seats/keyboards will affect the unicode state. This potential downside is outweighed by the fact that different foot clients no longer affect each other. Closes #1717 --- CHANGELOG.md | 3 +++ input.c | 4 ++-- render.c | 11 +---------- search.c | 2 +- terminal.h | 6 ++++++ unicode-mode.c | 51 +++++++++++++++++++++++++------------------------- unicode-mode.h | 8 ++++---- wayland.h | 6 ------ 8 files changed, 42 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45b58778..0472c8a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,8 +85,11 @@ monitor's DPI is 0 (this is true for, for example, nested Wayland sessions, or in virtualized environments). * No error response for empty `XTGETTCAP` request ([#1694][1694]). +* Unicode-mode in one foot client affecting other clients, in foot + server mode ([#1717][1717]). [1694]: https://codeberg.org/dnkl/foot/issues/1694 +[1717]: https://codeberg.org/dnkl/foot/issues/1717 ### Security diff --git a/input.c b/input.c index 26f62629..33b5446c 100644 --- a/input.c +++ b/input.c @@ -441,7 +441,7 @@ execute_binding(struct seat *seat, struct terminal *term, } case BIND_ACTION_UNICODE_INPUT: - unicode_mode_activate(seat); + unicode_mode_activate(term); return true; case BIND_ACTION_QUIT: @@ -1550,7 +1550,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, xassert(bindings != NULL); if (pressed) { - if (seat->unicode_mode.active) { + if (term->unicode_mode.active) { unicode_mode_input(seat, term, sym); return; } diff --git a/render.c b/render.c index 804ccdc3..3a577482 100644 --- a/render.c +++ b/render.c @@ -1563,16 +1563,7 @@ static void render_overlay(struct terminal *term) { struct wayl_sub_surface *overlay = &term->window->overlay; - bool unicode_mode_active = false; - - /* Check if unicode mode is active on at least one seat focusing - * this terminal instance */ - tll_foreach(term->wl->seats, it) { - if (it->item.unicode_mode.active) { - unicode_mode_active = true; - break; - } - } + const bool unicode_mode_active = term->unicode_mode.active; const enum overlay_style style = term->is_searching ? OVERLAY_SEARCH : diff --git a/search.c b/search.c index 10541884..eaf8c34e 100644 --- a/search.c +++ b/search.c @@ -1358,7 +1358,7 @@ execute_binding(struct seat *seat, struct terminal *term, return true; case BIND_ACTION_SEARCH_UNICODE_INPUT: - unicode_mode_activate(seat); + unicode_mode_activate(term); return true; case BIND_ACTION_SEARCH_COUNT: diff --git a/terminal.h b/terminal.h index 2a0845ef..ba634185 100644 --- a/terminal.h +++ b/terminal.h @@ -719,6 +719,12 @@ struct terminal { bool ime_enabled; #endif + struct { + bool active; + int count; + char32_t character; + } unicode_mode; + struct { bool in_progress; bool client_has_terminated; diff --git a/unicode-mode.c b/unicode-mode.c index 6290de61..b902b5f4 100644 --- a/unicode-mode.c +++ b/unicode-mode.c @@ -1,37 +1,36 @@ #include "unicode-mode.h" #define LOG_MODULE "unicode-input" -#define LOG_ENABLE_DBG 0 +#define LOG_ENABLE_DBG 1 #include "log.h" #include "render.h" #include "search.h" void -unicode_mode_activate(struct seat *seat) +unicode_mode_activate(struct terminal *term) { - if (seat->unicode_mode.active) + if (term->unicode_mode.active) return; - seat->unicode_mode.active = true; - seat->unicode_mode.character = u'\0'; - seat->unicode_mode.count = 0; - unicode_mode_updated(seat); + term->unicode_mode.active = true; + term->unicode_mode.character = u'\0'; + term->unicode_mode.count = 0; + unicode_mode_updated(term); } void -unicode_mode_deactivate(struct seat *seat) +unicode_mode_deactivate(struct terminal *term) { - if (!seat->unicode_mode.active) + if (!term->unicode_mode.active) return; - seat->unicode_mode.active = false; - unicode_mode_updated(seat); + term->unicode_mode.active = false; + unicode_mode_updated(term); } void -unicode_mode_updated(struct seat *seat) +unicode_mode_updated(struct terminal *term) { - struct terminal *term = seat->kbd_focus; if (term == NULL) return; @@ -52,10 +51,10 @@ unicode_mode_input(struct seat *seat, struct terminal *term, { char utf8[MB_CUR_MAX]; size_t chars = c32rtomb( - utf8, seat->unicode_mode.character, &(mbstate_t){0}); + utf8, term->unicode_mode.character, &(mbstate_t){0}); LOG_DBG("Unicode input: 0x%06x -> %.*s", - seat->unicode_mode.character, (int)chars, utf8); + term->unicode_mode.character, (int)chars, utf8); if (chars != (size_t)-1) { if (term->is_searching) @@ -64,7 +63,7 @@ unicode_mode_input(struct seat *seat, struct terminal *term, term_to_slave(term, utf8, chars); } - unicode_mode_deactivate(seat); + unicode_mode_deactivate(term); } else if (sym == XKB_KEY_Escape || @@ -73,18 +72,18 @@ unicode_mode_input(struct seat *seat, struct terminal *term, sym == XKB_KEY_d || sym == XKB_KEY_g))) { - unicode_mode_deactivate(seat); + unicode_mode_deactivate(term); } else if (sym == XKB_KEY_BackSpace) { - if (seat->unicode_mode.count > 0) { - seat->unicode_mode.character >>= 4; - seat->unicode_mode.count--; - unicode_mode_updated(seat); + if (term->unicode_mode.count > 0) { + term->unicode_mode.character >>= 4; + term->unicode_mode.count--; + unicode_mode_updated(term); } } - else if (seat->unicode_mode.count < 6) { + else if (term->unicode_mode.count < 6) { int digit = -1; /* 0-9, a-f, A-F */ @@ -99,10 +98,10 @@ unicode_mode_input(struct seat *seat, struct terminal *term, if (digit >= 0) { xassert(digit >= 0 && digit <= 0xf); - seat->unicode_mode.character <<= 4; - seat->unicode_mode.character |= digit; - seat->unicode_mode.count++; - unicode_mode_updated(seat); + term->unicode_mode.character <<= 4; + term->unicode_mode.character |= digit; + term->unicode_mode.count++; + unicode_mode_updated(term); } } } diff --git a/unicode-mode.h b/unicode-mode.h index e7c75b9b..2f8d2b35 100644 --- a/unicode-mode.h +++ b/unicode-mode.h @@ -2,10 +2,10 @@ #include -#include "wayland.h" +#include "terminal.h" -void unicode_mode_activate(struct seat *seat); -void unicode_mode_deactivate(struct seat *seat); -void unicode_mode_updated(struct seat *seat); +void unicode_mode_activate(struct terminal *term); +void unicode_mode_deactivate(struct terminal *term); +void unicode_mode_updated(struct terminal *term); void unicode_mode_input(struct seat *seat, struct terminal *term, xkb_keysym_t sym); diff --git a/wayland.h b/wayland.h index 575af1bb..215640aa 100644 --- a/wayland.h +++ b/wayland.h @@ -243,12 +243,6 @@ struct seat { uint32_t serial; } ime; #endif - - struct { - bool active; - int count; - char32_t character; - } unicode_mode; }; enum csd_surface {