mirror of
https://github.com/wez/wezterm.git
synced 2024-11-13 07:22:52 +03:00
x11: ime: enable pre-edit callbacks to show compose status
This also adjusts the IME position so that it doesn't obscure the composition status. refs: https://github.com/fcitx/xcb-imdkit/issues/9
This commit is contained in:
parent
90e244d731
commit
1dc5af5e69
@ -74,6 +74,7 @@ wayland-protocols = {version="0.29", optional=true}
|
||||
wayland-client = {version="0.29", optional=true}
|
||||
wayland-egl = {version="0.29", optional=true}
|
||||
xcb-imdkit = "0.1"
|
||||
#xcb-imdkit = { path = "../../github/xcb-imdkit-rs" }
|
||||
|
||||
[target.'cfg(target_os="macos")'.dependencies]
|
||||
cocoa = "0.20"
|
||||
|
@ -4,7 +4,7 @@ use crate::os::x11::window::XWindowInner;
|
||||
use crate::os::x11::xsettings::*;
|
||||
use crate::os::Connection;
|
||||
use crate::spawn::*;
|
||||
use crate::Appearance;
|
||||
use crate::{Appearance, DeadKeyStatus};
|
||||
use anyhow::{anyhow, bail, Context as _};
|
||||
use mio::unix::EventedFd;
|
||||
use mio::{Evented, Events, Poll, PollOpt, Ready, Token};
|
||||
@ -477,7 +477,7 @@ impl XConnection {
|
||||
xcb_imdkit::ImeClient::unsafe_new(
|
||||
&conn,
|
||||
screen_num,
|
||||
xcb_imdkit::InputStyle::DEFAULT,
|
||||
xcb_imdkit::InputStyle::PREEDIT_CALLBACKS,
|
||||
config::configuration().xim_im_name.as_deref(),
|
||||
)
|
||||
};
|
||||
@ -529,6 +529,33 @@ impl XConnection {
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let conn = conn.clone();
|
||||
conn.clone()
|
||||
.ime
|
||||
.borrow_mut()
|
||||
.set_preedit_draw_cb(move |window_id, info| {
|
||||
if let Some(window) = conn.window_by_id(window_id) {
|
||||
let mut inner = window.lock().unwrap();
|
||||
|
||||
let text = info.text();
|
||||
let status = DeadKeyStatus::Composing(text);
|
||||
inner.dispatch_ime_compose_status(status);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let conn = conn.clone();
|
||||
conn.clone()
|
||||
.ime
|
||||
.borrow_mut()
|
||||
.set_preedit_done_cb(move |window_id| {
|
||||
if let Some(window) = conn.window_by_id(window_id) {
|
||||
let mut inner = window.lock().unwrap();
|
||||
inner.dispatch_ime_compose_status(DeadKeyStatus::None);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let conn = conn.clone();
|
||||
conn.clone()
|
||||
|
@ -4,9 +4,9 @@ use crate::connection::ConnectionOps;
|
||||
use crate::os::xkeysyms;
|
||||
use crate::os::{Connection, Window};
|
||||
use crate::{
|
||||
Appearance, Clipboard, Dimensions, MouseButtons, MouseCursor, MouseEvent, MouseEventKind,
|
||||
MousePress, Point, Rect, ScreenPoint, WindowDecorations, WindowEvent, WindowEventSender,
|
||||
WindowOps, WindowState,
|
||||
Appearance, Clipboard, DeadKeyStatus, Dimensions, MouseButtons, MouseCursor, MouseEvent,
|
||||
MouseEventKind, MousePress, Point, Rect, ScreenPoint, WindowDecorations, WindowEvent,
|
||||
WindowEventSender, WindowOps, WindowState,
|
||||
};
|
||||
use anyhow::{anyhow, Context as _};
|
||||
use async_trait::async_trait;
|
||||
@ -423,6 +423,11 @@ impl XWindowInner {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn dispatch_ime_compose_status(&mut self, status: DeadKeyStatus) {
|
||||
self.events
|
||||
.dispatch(WindowEvent::AdviseDeadKeyStatus(status));
|
||||
}
|
||||
|
||||
pub fn dispatch_ime_text(&mut self, text: &str) {
|
||||
let key_event = KeyEvent {
|
||||
key: KeyCode::Composed(text.into()),
|
||||
@ -982,7 +987,7 @@ impl XWindowInner {
|
||||
self.conn().ime.borrow_mut().update_pos(
|
||||
self.window_id,
|
||||
self.last_cursor_position.min_x() as i16,
|
||||
self.last_cursor_position.max_y() as i16,
|
||||
(self.last_cursor_position.max_y() + self.last_cursor_position.height()) as i16,
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user