From aea61a74fb79452b65850c645548ae958002249f Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 12 Jul 2017 00:00:51 -0400 Subject: [PATCH 1/2] remove the the redundant code, fix a bug --- src/os/unix.rs | 8 ++++++++ src/platform/linux/x11/mod.rs | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/os/unix.rs b/src/os/unix.rs index 9d897a76..bcf2dcd1 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -42,6 +42,8 @@ pub trait WindowExt { fn get_xlib_screen_id(&self) -> Option<*mut libc::c_void>; fn get_xlib_xconnection(&self) -> Option>; + + fn send_xim_spot(&self, x: i16, y: i16); /// This function returns the underlying `xcb_connection_t` of an xlib `Display`. /// @@ -121,6 +123,12 @@ impl WindowExt for Window { } } + fn send_xim_spot(&self, x: i16, y: i16) { + if let LinuxWindow::X(ref w) = self.window { + w.send_xim_spot(x, y); + } + } + #[inline] fn get_wayland_surface(&self) -> Option<*mut libc::c_void> { use wayland_client::Proxy; diff --git a/src/platform/linux/x11/mod.rs b/src/platform/linux/x11/mod.rs index c046ac25..398a7cfd 100644 --- a/src/platform/linux/x11/mod.rs +++ b/src/platform/linux/x11/mod.rs @@ -685,6 +685,7 @@ impl Window2 { x_events_loop.windows.lock().unwrap().insert(win.id(), WindowData { im: im, ic: ic, + spot: ffi::XPoint {x: 0, y: 0}, config: None, multitouch: window.multitouch, cursor_pos: None, @@ -701,6 +702,26 @@ impl Window2 { pub fn id(&self) -> WindowId { self.window.id() } + + #[inline] + pub fn send_xim_spot(&self, x: i16, y: i16) { + if let (Some(windows), Some(display)) = (self.windows.upgrade(), self.display.upgrade()) { + let nspot = ffi::XPoint{x: x, y: y}; + let mut windows = windows.lock().unwrap(); + let mut w = windows.get_mut(&self.window.id()).unwrap(); + if w.spot.x == x && w.spot.y == y { + return + } + w.spot = nspot; + unsafe { + let preedit_attr = (display.xlib.XVaCreateNestedList) + (0, b"spotLocation\0", &nspot, ptr::null::<()>()); + (display.xlib.XSetICValues)(w.ic, b"preeditAttributes\0", + preedit_attr, ptr::null::<()>()); + (display.xlib.XFree)(preedit_attr); + } + } + } } impl Drop for Window2 { @@ -722,6 +743,7 @@ struct WindowData { config: Option, im: ffi::XIM, ic: ffi::XIC, + spot: ffi::XPoint, multitouch: bool, cursor_pos: Option<(f64, f64)>, } From d6b9faacc994a71b8fe3d3ba749cbc54cfe83994 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 12 Jul 2017 13:26:11 -0400 Subject: [PATCH 2/2] rename the field --- src/platform/linux/x11/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platform/linux/x11/mod.rs b/src/platform/linux/x11/mod.rs index 7469405b..1fa11c9e 100644 --- a/src/platform/linux/x11/mod.rs +++ b/src/platform/linux/x11/mod.rs @@ -701,7 +701,7 @@ impl Window2 { x_events_loop.windows.lock().unwrap().insert(win.id(), WindowData { im: im, ic: ic, - spot: ffi::XPoint {x: 0, y: 0}, + ic_spot: ffi::XPoint {x: 0, y: 0}, config: None, multitouch: window.multitouch, cursor_pos: None, @@ -725,10 +725,10 @@ impl Window2 { let nspot = ffi::XPoint{x: x, y: y}; let mut windows = windows.lock().unwrap(); let mut w = windows.get_mut(&self.window.id()).unwrap(); - if w.spot.x == x && w.spot.y == y { + if w.ic_spot.x == x && w.ic_spot.y == y { return } - w.spot = nspot; + w.ic_spot = nspot; unsafe { let preedit_attr = (display.xlib.XVaCreateNestedList) (0, b"spotLocation\0", &nspot, ptr::null::<()>()); @@ -759,7 +759,7 @@ struct WindowData { config: Option, im: ffi::XIM, ic: ffi::XIC, - spot: ffi::XPoint, + ic_spot: ffi::XPoint, multitouch: bool, cursor_pos: Option<(f64, f64)>, }