mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
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
This commit is contained in:
parent
cf65ad49e8
commit
18b702b249
8 changed files with 42 additions and 49 deletions
|
|
@ -85,8 +85,11 @@
|
||||||
monitor's DPI is 0 (this is true for, for example, nested Wayland
|
monitor's DPI is 0 (this is true for, for example, nested Wayland
|
||||||
sessions, or in virtualized environments).
|
sessions, or in virtualized environments).
|
||||||
* No error response for empty `XTGETTCAP` request ([#1694][1694]).
|
* 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
|
[1694]: https://codeberg.org/dnkl/foot/issues/1694
|
||||||
|
[1717]: https://codeberg.org/dnkl/foot/issues/1717
|
||||||
|
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
|
||||||
4
input.c
4
input.c
|
|
@ -441,7 +441,7 @@ execute_binding(struct seat *seat, struct terminal *term,
|
||||||
}
|
}
|
||||||
|
|
||||||
case BIND_ACTION_UNICODE_INPUT:
|
case BIND_ACTION_UNICODE_INPUT:
|
||||||
unicode_mode_activate(seat);
|
unicode_mode_activate(term);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case BIND_ACTION_QUIT:
|
case BIND_ACTION_QUIT:
|
||||||
|
|
@ -1550,7 +1550,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
|
||||||
xassert(bindings != NULL);
|
xassert(bindings != NULL);
|
||||||
|
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
if (seat->unicode_mode.active) {
|
if (term->unicode_mode.active) {
|
||||||
unicode_mode_input(seat, term, sym);
|
unicode_mode_input(seat, term, sym);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
render.c
11
render.c
|
|
@ -1563,16 +1563,7 @@ static void
|
||||||
render_overlay(struct terminal *term)
|
render_overlay(struct terminal *term)
|
||||||
{
|
{
|
||||||
struct wayl_sub_surface *overlay = &term->window->overlay;
|
struct wayl_sub_surface *overlay = &term->window->overlay;
|
||||||
bool unicode_mode_active = false;
|
const bool unicode_mode_active = term->unicode_mode.active;
|
||||||
|
|
||||||
/* 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 enum overlay_style style =
|
const enum overlay_style style =
|
||||||
term->is_searching ? OVERLAY_SEARCH :
|
term->is_searching ? OVERLAY_SEARCH :
|
||||||
|
|
|
||||||
2
search.c
2
search.c
|
|
@ -1358,7 +1358,7 @@ execute_binding(struct seat *seat, struct terminal *term,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case BIND_ACTION_SEARCH_UNICODE_INPUT:
|
case BIND_ACTION_SEARCH_UNICODE_INPUT:
|
||||||
unicode_mode_activate(seat);
|
unicode_mode_activate(term);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case BIND_ACTION_SEARCH_COUNT:
|
case BIND_ACTION_SEARCH_COUNT:
|
||||||
|
|
|
||||||
|
|
@ -719,6 +719,12 @@ struct terminal {
|
||||||
bool ime_enabled;
|
bool ime_enabled;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool active;
|
||||||
|
int count;
|
||||||
|
char32_t character;
|
||||||
|
} unicode_mode;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool in_progress;
|
bool in_progress;
|
||||||
bool client_has_terminated;
|
bool client_has_terminated;
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,36 @@
|
||||||
#include "unicode-mode.h"
|
#include "unicode-mode.h"
|
||||||
|
|
||||||
#define LOG_MODULE "unicode-input"
|
#define LOG_MODULE "unicode-input"
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 1
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
unicode_mode_activate(struct seat *seat)
|
unicode_mode_activate(struct terminal *term)
|
||||||
{
|
{
|
||||||
if (seat->unicode_mode.active)
|
if (term->unicode_mode.active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
seat->unicode_mode.active = true;
|
term->unicode_mode.active = true;
|
||||||
seat->unicode_mode.character = u'\0';
|
term->unicode_mode.character = u'\0';
|
||||||
seat->unicode_mode.count = 0;
|
term->unicode_mode.count = 0;
|
||||||
unicode_mode_updated(seat);
|
unicode_mode_updated(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
unicode_mode_deactivate(struct seat *seat)
|
unicode_mode_deactivate(struct terminal *term)
|
||||||
{
|
{
|
||||||
if (!seat->unicode_mode.active)
|
if (!term->unicode_mode.active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
seat->unicode_mode.active = false;
|
term->unicode_mode.active = false;
|
||||||
unicode_mode_updated(seat);
|
unicode_mode_updated(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
unicode_mode_updated(struct seat *seat)
|
unicode_mode_updated(struct terminal *term)
|
||||||
{
|
{
|
||||||
struct terminal *term = seat->kbd_focus;
|
|
||||||
if (term == NULL)
|
if (term == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -52,10 +51,10 @@ unicode_mode_input(struct seat *seat, struct terminal *term,
|
||||||
{
|
{
|
||||||
char utf8[MB_CUR_MAX];
|
char utf8[MB_CUR_MAX];
|
||||||
size_t chars = c32rtomb(
|
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",
|
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 (chars != (size_t)-1) {
|
||||||
if (term->is_searching)
|
if (term->is_searching)
|
||||||
|
|
@ -64,7 +63,7 @@ unicode_mode_input(struct seat *seat, struct terminal *term,
|
||||||
term_to_slave(term, utf8, chars);
|
term_to_slave(term, utf8, chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
unicode_mode_deactivate(seat);
|
unicode_mode_deactivate(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (sym == XKB_KEY_Escape ||
|
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_d ||
|
||||||
sym == XKB_KEY_g)))
|
sym == XKB_KEY_g)))
|
||||||
{
|
{
|
||||||
unicode_mode_deactivate(seat);
|
unicode_mode_deactivate(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (sym == XKB_KEY_BackSpace) {
|
else if (sym == XKB_KEY_BackSpace) {
|
||||||
if (seat->unicode_mode.count > 0) {
|
if (term->unicode_mode.count > 0) {
|
||||||
seat->unicode_mode.character >>= 4;
|
term->unicode_mode.character >>= 4;
|
||||||
seat->unicode_mode.count--;
|
term->unicode_mode.count--;
|
||||||
unicode_mode_updated(seat);
|
unicode_mode_updated(term);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (seat->unicode_mode.count < 6) {
|
else if (term->unicode_mode.count < 6) {
|
||||||
int digit = -1;
|
int digit = -1;
|
||||||
|
|
||||||
/* 0-9, a-f, A-F */
|
/* 0-9, a-f, A-F */
|
||||||
|
|
@ -99,10 +98,10 @@ unicode_mode_input(struct seat *seat, struct terminal *term,
|
||||||
|
|
||||||
if (digit >= 0) {
|
if (digit >= 0) {
|
||||||
xassert(digit >= 0 && digit <= 0xf);
|
xassert(digit >= 0 && digit <= 0xf);
|
||||||
seat->unicode_mode.character <<= 4;
|
term->unicode_mode.character <<= 4;
|
||||||
seat->unicode_mode.character |= digit;
|
term->unicode_mode.character |= digit;
|
||||||
seat->unicode_mode.count++;
|
term->unicode_mode.count++;
|
||||||
unicode_mode_updated(seat);
|
unicode_mode_updated(term);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
#include <xkbcommon/xkbcommon-keysyms.h>
|
#include <xkbcommon/xkbcommon-keysyms.h>
|
||||||
|
|
||||||
#include "wayland.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
void unicode_mode_activate(struct seat *seat);
|
void unicode_mode_activate(struct terminal *term);
|
||||||
void unicode_mode_deactivate(struct seat *seat);
|
void unicode_mode_deactivate(struct terminal *term);
|
||||||
void unicode_mode_updated(struct seat *seat);
|
void unicode_mode_updated(struct terminal *term);
|
||||||
void unicode_mode_input(struct seat *seat, struct terminal *term,
|
void unicode_mode_input(struct seat *seat, struct terminal *term,
|
||||||
xkb_keysym_t sym);
|
xkb_keysym_t sym);
|
||||||
|
|
|
||||||
|
|
@ -243,12 +243,6 @@ struct seat {
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
} ime;
|
} ime;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct {
|
|
||||||
bool active;
|
|
||||||
int count;
|
|
||||||
char32_t character;
|
|
||||||
} unicode_mode;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum csd_surface {
|
enum csd_surface {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue