From 9a2cd626f186c26d593a977accb262d0e161b432 Mon Sep 17 00:00:00 2001 From: Riey Date: Wed, 24 Feb 2021 18:16:40 +0900 Subject: [PATCH] Fix xim bug (#305) --- docs/CHANGELOG.md | 1 + src/frontends/wayland/src/main.rs | 16 ++++++++-------- src/frontends/xim/src/handler.rs | 23 +++++++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9e35a54c..d54ce8d7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,7 @@ * Fix cho-jung bug `웬 + ㅊ$ㅜ = 웬ㅊ` * Fix composable jungseong bug `ㅇ + $ㅆ$ㅜ + $ㅊ$ㅔ + = 웇` +* Fix xim bug [#304](https://github.com/Riey/kime/issues/304) ## 1.1.2 diff --git a/src/frontends/wayland/src/main.rs b/src/frontends/wayland/src/main.rs index afee8550..8710e602 100644 --- a/src/frontends/wayland/src/main.rs +++ b/src/frontends/wayland/src/main.rs @@ -225,25 +225,25 @@ impl KimeContext { self.engine.update_hangul_state(); } - let bypass = ret & InputResult_CONSUMED == 0; - if ret & InputResult_HAS_PREEDIT != 0 { self.preedit(self.engine.preedit_str().into()); } else { self.clear_preedit(); } - if ret & InputResult_NEED_RESET != 0 { - self.commit_string(self.engine.commit_str().into()); - self.engine.reset(); - } else if ret & InputResult_NEED_FLUSH != 0 { + if ret & InputResult_NEED_RESET | InputResult_NEED_FLUSH != 0 { self.commit_string(self.engine.commit_str().into()); - self.engine.flush(); + + if ret & InputResult_NEED_RESET != 0 { + self.engine.reset(); + } else { + self.engine.flush(); + } } self.commit(); - if bypass { + if ret & InputResult_CONSUMED == 0 { // Bypassed key's repeat will be handled by the clients. // // Reference: diff --git a/src/frontends/xim/src/handler.rs b/src/frontends/xim/src/handler.rs index 24023c90..276238d0 100644 --- a/src/frontends/xim/src/handler.rs +++ b/src/frontends/xim/src/handler.rs @@ -75,6 +75,10 @@ impl KimeHandler { return Ok(()); } + if user_ic.user_data.engine.preedit_str().is_empty() { + return Ok(()); + } + if let Some(pe) = user_ic.user_data.pe.as_mut() { // Draw in server (already have pe_window) let pe = self.preedit_windows.get_mut(pe).unwrap(); @@ -196,7 +200,7 @@ impl ServerHandler> for KimeHandler { server: &mut X11rbServer, user_ic: &mut xim::UserInputContext, ) -> Result<(), xim::ServerError> { - log::trace!("spot: {:?}", user_ic.ic.preedit_spot()); + log::debug!("spot: {:?}", user_ic.ic.preedit_spot()); self.clear_preedit(server, user_ic)?; self.preedit(server, user_ic)?; @@ -277,18 +281,17 @@ impl ServerHandler> for KimeHandler { self.clear_preedit(server, user_ic)?; } - if ret & InputResult_NEED_FLUSH != 0 { - user_ic.user_data.engine.flush(); - } - - if ret & InputResult_NEED_RESET != 0 { + if ret & InputResult_NEED_RESET | InputResult_NEED_FLUSH != 0 { self.commit(server, user_ic)?; - user_ic.user_data.engine.reset(); - } - let bypass = ret & InputResult_CONSUMED == 0; + if ret & InputResult_NEED_RESET != 0 { + user_ic.user_data.engine.reset(); + } else { + user_ic.user_data.engine.flush(); + } + } - Ok(!bypass) + Ok(ret & InputResult_CONSUMED != 0) } fn handle_destory_ic(