Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
x11: Fix preedit for CJK and partially fix unresponsive keyboard with xim (#17373)
Fernando Tagawad7c45ccf2f61
diff --git a/Cargo.lock b/Cargo.lockindex 203fc934e7c..111360b9654 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -14079,7 +14079,7 @@ dependencies = [[[package]]name = "xim"version = "0.4.0"-source = "git+https://github.com/npmania/xim-rs?rev=27132caffc5b9bc9c432ca4afad184ab6e7c16af#27132caffc5b9bc9c432ca4afad184ab6e7c16af"+source = "git+https://github.com/XDeme1/xim-rs?rev=d50d461764c2213655cd9cf65a0ea94c70d3c4fd#d50d461764c2213655cd9cf65a0ea94c70d3c4fd"dependencies = ["ahash 0.8.11","hashbrown 0.14.5",@@ -14092,7 +14092,7 @@ dependencies = [[[package]]name = "xim-ctext"version = "0.3.0"-source = "git+https://github.com/npmania/xim-rs?rev=27132caffc5b9bc9c432ca4afad184ab6e7c16af#27132caffc5b9bc9c432ca4afad184ab6e7c16af"+source = "git+https://github.com/XDeme1/xim-rs?rev=d50d461764c2213655cd9cf65a0ea94c70d3c4fd#d50d461764c2213655cd9cf65a0ea94c70d3c4fd"dependencies = ["encoding_rs",]@@ -14100,7 +14100,7 @@ dependencies = [[[package]]name = "xim-parser"version = "0.2.1"-source = "git+https://github.com/npmania/xim-rs?rev=27132caffc5b9bc9c432ca4afad184ab6e7c16af#27132caffc5b9bc9c432ca4afad184ab6e7c16af"+source = "git+https://github.com/XDeme1/xim-rs?rev=d50d461764c2213655cd9cf65a0ea94c70d3c4fd#d50d461764c2213655cd9cf65a0ea94c70d3c4fd"dependencies = ["bitflags 2.6.0",]diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.tomlindex 4ce44ffce01..09b546fc326 100644--- a/crates/gpui/Cargo.toml+++ b/crates/gpui/Cargo.toml@@ -143,7 +143,7 @@ xkbcommon = { git = "https://github.com/ConradIrwin/xkbcommon-rs", rev = "fcbb46"wayland","x11",] }-xim = { git = "https://github.com/npmania/xim-rs", rev = "27132caffc5b9bc9c432ca4afad184ab6e7c16af", features = [+xim = { git = "https://github.com/XDeme1/xim-rs", rev = "d50d461764c2213655cd9cf65a0ea94c70d3c4fd", features = ["x11rb-xcb","x11rb-client",] }diff --git a/crates/gpui/src/platform/linux/x11/client.rs b/crates/gpui/src/platform/linux/x11/client.rsindex 0909d09f254..d6c806236a9 100644--- a/crates/gpui/src/platform/linux/x11/client.rs+++ b/crates/gpui/src/platform/linux/x11/client.rs@@ -201,9 +201,7 @@ impl X11ClientStatePtr {.build_ic_attributes().push(xim::AttributeName::InputStyle,- xim::InputStyle::PREEDIT_CALLBACKS- | xim::InputStyle::STATUS_NOTHING- | xim::InputStyle::PREEDIT_POSITION,+ xim::InputStyle::PREEDIT_CALLBACKS,).push(xim::AttributeName::ClientWindow, xim_handler.window).push(xim::AttributeName::FocusWindow, xim_handler.window)@@ -572,12 +570,7 @@ impl X11Client {let mut xim_handler = state.xim_handler.take().unwrap();let mut ic_attributes = ximc.build_ic_attributes()- .push(- AttributeName::InputStyle,- InputStyle::PREEDIT_CALLBACKS- | InputStyle::STATUS_NOTHING- | InputStyle::PREEDIT_NONE,- )+ .push(AttributeName::InputStyle, InputStyle::PREEDIT_CALLBACKS).push(AttributeName::ClientWindow, xim_handler.window).push(AttributeName::FocusWindow, xim_handler.window);@@ -605,12 +598,12 @@ impl X11Client {state.ximc = Some(ximc);}- pub fn disable_ime(&self) {+ pub fn reset_ime(&self) {let mut state = self.0.borrow_mut();state.composing = false;if let Some(mut ximc) = state.ximc.take() {let xim_handler = state.xim_handler.as_ref().unwrap();- ximc.destroy_ic(xim_handler.im_id, xim_handler.ic_id).ok();+ ximc.reset_ic(xim_handler.im_id, xim_handler.ic_id).ok();state.ximc = Some(ximc);}}@@ -768,6 +761,9 @@ impl X11Client {window.set_active(true);let mut state = self.0.borrow_mut();state.keyboard_focused_window = Some(event.event);+ if let Some(handler) = state.xim_handler.as_mut() {+ handler.window = event.event;+ }drop(state);self.enable_ime();}@@ -781,7 +777,7 @@ impl X11Client {}state.pre_edit_text.take();drop(state);- self.disable_ime();+ self.reset_ime();window.handle_ime_delete();}Event::XkbNewKeyboardNotify(_) | Event::MapNotify(_) => {@@ -940,8 +936,7 @@ impl X11Client {if state.composing && state.ximc.is_some() {drop(state);- self.disable_ime();- self.enable_ime();+ self.reset_ime();window.handle_ime_unmark();state = self.0.borrow_mut();} else if let Some(text) = state.pre_edit_text.take() {@@ -1199,9 +1194,7 @@ impl X11Client {.build_ic_attributes().push(xim::AttributeName::InputStyle,- xim::InputStyle::PREEDIT_CALLBACKS- | xim::InputStyle::STATUS_NOTHING- | xim::InputStyle::PREEDIT_POSITION,+ xim::InputStyle::PREEDIT_CALLBACKS,).push(xim::AttributeName::ClientWindow, xim_handler.window).push(xim::AttributeName::FocusWindow, xim_handler.window)diff --git a/crates/gpui/src/platform/linux/x11/xim_handler.rs b/crates/gpui/src/platform/linux/x11/xim_handler.rsindex 89b1ec3feb0..e1ccfd4cd97 100644--- a/crates/gpui/src/platform/linux/x11/xim_handler.rs+++ b/crates/gpui/src/platform/linux/x11/xim_handler.rs@@ -48,12 +48,7 @@ impl<C: Client<XEvent = xproto::KeyPressEvent>> ClientHandler<C> for XimHandler) -> Result<(), ClientError> {let ic_attributes = client.build_ic_attributes()- .push(- AttributeName::InputStyle,- InputStyle::PREEDIT_CALLBACKS- | InputStyle::STATUS_NOTHING- | InputStyle::PREEDIT_NONE,- )+ .push(AttributeName::InputStyle, InputStyle::PREEDIT_CALLBACKS).push(AttributeName::ClientWindow, self.window).push(AttributeName::FocusWindow, self.window).build();@@ -110,15 +105,6 @@ impl<C: Client<XEvent = xproto::KeyPressEvent>> ClientHandler<C> for XimHandlerclient.disconnect()}- fn handle_destroy_ic(- &mut self,- client: &mut C,- input_method_id: u16,- _input_context_id: u16,- ) -> Result<(), ClientError> {- client.close(input_method_id)- }-fn handle_preedit_draw(&mut self,_client: &mut C,