mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 06:54:45 +03:00
parent
607287935f
commit
f11b240a1c
@ -15,36 +15,48 @@ use wayland_protocols::unstable::text_input::v3::client::zwp_text_input_v3::{
|
|||||||
Event, ZwpTextInputV3,
|
Event, ZwpTextInputV3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Default, Debug)]
|
||||||
|
struct PendingState {
|
||||||
|
pre_edit: Option<String>,
|
||||||
|
commit: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct Inner {
|
struct Inner {
|
||||||
input_by_seat: HashMap<u32, Attached<ZwpTextInputV3>>,
|
input_by_seat: HashMap<u32, Attached<ZwpTextInputV3>>,
|
||||||
keyboard_to_seat: HashMap<u32, u32>,
|
keyboard_to_seat: HashMap<u32, u32>,
|
||||||
surface_to_keyboard: HashMap<u32, u32>,
|
surface_to_keyboard: HashMap<u32, u32>,
|
||||||
|
pending_state: HashMap<u32, PendingState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Inner {
|
impl Inner {
|
||||||
fn handle_event(
|
fn handle_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
_input: Main<ZwpTextInputV3>,
|
input: Main<ZwpTextInputV3>,
|
||||||
event: Event,
|
event: Event,
|
||||||
_ddata: DispatchData,
|
_ddata: DispatchData,
|
||||||
_inner: &Arc<Mutex<Self>>,
|
_inner: &Arc<Mutex<Self>>,
|
||||||
) {
|
) {
|
||||||
log::trace!("{event:?}");
|
log::trace!("{event:?}");
|
||||||
let conn = WaylandConnection::get().unwrap().wayland();
|
let conn = WaylandConnection::get().unwrap().wayland();
|
||||||
|
let mut pending_state = self.pending_state.entry(wl_id(&**input)).or_default();
|
||||||
match event {
|
match event {
|
||||||
Event::PreeditString {
|
Event::PreeditString {
|
||||||
text,
|
text,
|
||||||
cursor_begin: _,
|
cursor_begin: _,
|
||||||
cursor_end: _,
|
cursor_end: _,
|
||||||
} => {
|
} => {
|
||||||
conn.dispatch_to_focused_window(WindowEvent::AdviseDeadKeyStatus(match text {
|
pending_state.pre_edit = text;
|
||||||
Some(text) => DeadKeyStatus::Composing(text),
|
|
||||||
None => DeadKeyStatus::None,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
Event::CommitString { text } => {
|
Event::CommitString { text } => {
|
||||||
if let Some(text) = text {
|
pending_state.commit = text;
|
||||||
|
conn.dispatch_to_focused_window(WindowEvent::AdviseDeadKeyStatus(
|
||||||
|
DeadKeyStatus::None,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Event::Done { serial } => {
|
||||||
|
*conn.last_serial.borrow_mut() = serial;
|
||||||
|
if let Some(text) = pending_state.commit.take() {
|
||||||
conn.dispatch_to_focused_window(WindowEvent::KeyEvent(KeyEvent {
|
conn.dispatch_to_focused_window(WindowEvent::KeyEvent(KeyEvent {
|
||||||
key: KeyCode::composed(&text),
|
key: KeyCode::composed(&text),
|
||||||
modifiers: Modifiers::NONE,
|
modifiers: Modifiers::NONE,
|
||||||
@ -53,11 +65,13 @@ impl Inner {
|
|||||||
raw: None,
|
raw: None,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
conn.dispatch_to_focused_window(WindowEvent::AdviseDeadKeyStatus(
|
let status = if let Some(text) = pending_state.pre_edit.take() {
|
||||||
DeadKeyStatus::None,
|
DeadKeyStatus::Composing(text)
|
||||||
));
|
} else {
|
||||||
|
DeadKeyStatus::None
|
||||||
|
};
|
||||||
|
conn.dispatch_to_focused_window(WindowEvent::AdviseDeadKeyStatus(status));
|
||||||
}
|
}
|
||||||
Event::Done { serial: _ } => {}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user