x11: synthesize clearing dead key state when forgotten by system

It's not clear exactly how this triggers, but in setups where
a compose key has been configured (against the default for the
configured keyboard layout), it seems as though certain events
that indicate when composition is complete are not delivered,
leaving the compose cursor in an inconsistent state.

This commit attempts to detect that composing->!composing
state transition and bubble it up; when we return Nothing
and had previously had a composition string we're return
a bool to cause the caller to emit an event that clears
the composition state.

I'm not totally sure this is 100% right, but I think
it may help with the case we're discussing in
https://github.com/wez/wezterm/issues/4841
This commit is contained in:
Wez Furlong committed 2024-01-23 15:02:50 -07:00
1 parent 045e92be1b
commit eb3a78b0cb
2 files changed
+31 -7

No files matched your search

+5 -1
View File
@@ -947,7 +947,11 @@ impl TermWindow {
Ok(true)
}
WindowEvent::AdviseDeadKeyStatus(status) => {
log::trace!("DeadKeyStatus now: {:?}", status);
if self.config.debug_key_events {
log::info!("DeadKeyStatus now: {:?}", status);
} else {
log::trace!("DeadKeyStatus now: {:?}", status);
}
self.dead_key_status = status;
self.update_title();
// Ensure that we repaint so that any composing
+26 -6
View File
@@ -38,7 +38,7 @@ struct Compose {
enum FeedResult {
Composing(String),
Composed(String, xkb::Keysym),
Nothing(String, xkb::Keysym),
Nothing(String, xkb::Keysym, bool),
Cancelled,
}
@@ -54,6 +54,8 @@ impl Compose {
xsym: xkb::Keysym,
key_state: &RefCell<xkb::State>,
) -> FeedResult {
let had_composition = !self.composition.is_empty();
if matches!(
self.state.status(),
ComposeStatus::Nothing | ComposeStatus::Cancelled | ComposeStatus::Composed
@@ -62,7 +64,8 @@ impl Compose {
}
let previously_composing = !self.composition.is_empty();
self.state.feed(xsym);
let feed_result = self.state.feed(xsym);
log::trace!("feed {xsym} -> result {feed_result:?}");
match self.state.status() {
ComposeStatus::Composing => {
@@ -112,7 +115,9 @@ impl Compose {
}
ComposeStatus::Nothing => {
let utf8 = key_state.borrow().key_get_utf8(xcode);
FeedResult::Nothing(utf8, xsym)
let clear_dead_key_state = had_composition;
self.composition.clear();
FeedResult::Nothing(utf8, xsym, clear_dead_key_state)
}
ComposeStatus::Cancelled => {
self.state.reset();
@@ -292,7 +297,7 @@ impl KeyboardWithFallback {
events.dispatch(WindowEvent::AdviseDeadKeyStatus(DeadKeyStatus::None));
sym
}
FeedResult::Nothing(utf8, sym) => {
FeedResult::Nothing(utf8, sym, clear_dead_key_state) => {
// Composition had no special expansion.
// Xkb will return a textual representation of the key even when
// it is not generally useful; for example, when CTRL, ALT or SUPER
@@ -315,9 +320,20 @@ impl KeyboardWithFallback {
log::trace!(
"process_key_event: RawKeyEvent FeedResult::Nothing: \
{utf8:?}, {sym:?}. kc -> {kc:?} fallback_feed={fallback_feed:?}"
{utf8:?}, {sym:?}. kc -> {kc:?} fallback_feed={fallback_feed:?} \
clear_dead_key_state={clear_dead_key_state}"
);
if clear_dead_key_state {
// Some setups don't guarantee to trigger a state transition
// that will clear out the composition state, so we will
// synthesize it for ourselves here: since the
// FeedResult::Nothing case will emit a key to the GUI
// layer we take that as a signal that composition is
// complete and emit an event to clear it
events.dispatch(WindowEvent::AdviseDeadKeyStatus(DeadKeyStatus::None));
}
// If we have a modified key, and its expansion is non-ascii, such as cyrillic
// "Es" (which appears visually similar to "c" in latin texts), then consider
// this key expansion against the default latin layout.
@@ -333,7 +349,11 @@ impl KeyboardWithFallback {
// Consider shortcuts like CTRL-C against the default
// latin layout
match fallback_feed {
FeedResult::Nothing(_fb_utf8, fb_sym) => {
FeedResult::Nothing(
_fb_utf8,
fb_sym,
_clear_dead_key_state,
) => {
log::trace!(
"process_key_event: RawKeyEvent using fallback \
sym {fb_sym} because layout would expand to \