Make IME support optional since not all compositors support it
This commit is contained in:
1 parent
daf58199aa
commit
da5b519340
5 files changed
+32
-22
No files matched your search
@@ -158,7 +158,7 @@ impl Dispatch<ZwpTextInputV3, TextInputData, WaylandState> for TextInputState {
|
||||
) {
|
||||
log::trace!("ZwpTextInputEvent: {event:?}");
|
||||
let mut pending_state = {
|
||||
let text_input = &mut state.text_input;
|
||||
let text_input = state.text_input.as_mut().unwrap();
|
||||
let mut inner = text_input.inner.lock().unwrap();
|
||||
inner.pending_state.entry(input.id()).or_default().clone()
|
||||
};
|
||||
@@ -201,6 +201,8 @@ impl Dispatch<ZwpTextInputV3, TextInputData, WaylandState> for TextInputState {
|
||||
|
||||
state
|
||||
.text_input
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
@@ -222,6 +224,8 @@ impl WaylandState {
|
||||
|
||||
impl Drop for WaylandState {
|
||||
fn drop(&mut self) {
|
||||
self.text_input.shutdown();
|
||||
if let Some(text_input) = self.text_input.as_mut() {
|
||||
text_input.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,20 +31,24 @@ impl Dispatch<WlKeyboard, KeyboardData> for WaylandState {
|
||||
if let Some(sud) = SurfaceUserData::try_from_wl(&surface) {
|
||||
let window_id = sud.window_id;
|
||||
state.keyboard_window_id.borrow_mut().replace(window_id);
|
||||
if let Some(input) = state.text_input.get_text_input_for_keyboard(keyboard) {
|
||||
input.enable();
|
||||
input.commit();
|
||||
if let Some(text_input) = &state.text_input {
|
||||
if let Some(input) = text_input.get_text_input_for_keyboard(keyboard) {
|
||||
input.enable();
|
||||
input.commit();
|
||||
}
|
||||
text_input.advise_surface(surface, keyboard);
|
||||
}
|
||||
state.text_input.advise_surface(surface, keyboard);
|
||||
} else {
|
||||
log::warn!("{:?}, no known surface", event);
|
||||
}
|
||||
}
|
||||
WlKeyboardEvent::Leave { serial, .. } => {
|
||||
*state.last_serial.borrow_mut() = *serial;
|
||||
if let Some(input) = state.text_input.get_text_input_for_keyboard(keyboard) {
|
||||
input.disable();
|
||||
input.commit();
|
||||
if let Some(text_input) = &state.text_input {
|
||||
if let Some(input) = text_input.get_text_input_for_keyboard(keyboard) {
|
||||
input.disable();
|
||||
input.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
WlKeyboardEvent::Key { serial, .. } | WlKeyboardEvent::Modifiers { serial, .. } => {
|
||||
|
||||
@@ -30,7 +30,9 @@ impl SeatHandler for WaylandState {
|
||||
let keyboard = seat.get_keyboard(qh, KeyboardData {});
|
||||
self.keyboard = Some(keyboard.clone());
|
||||
|
||||
self.text_input.advise_seat(&seat, &keyboard, qh);
|
||||
if let Some(text_input) = &self.text_input {
|
||||
text_input.advise_seat(&seat, &keyboard, qh);
|
||||
}
|
||||
}
|
||||
|
||||
if capability == Capability::Pointer && self.pointer.is_none() {
|
||||
|
||||
@@ -50,7 +50,7 @@ pub(super) struct WaylandState {
|
||||
registry: RegistryState,
|
||||
pub(super) output: OutputState,
|
||||
pub(super) compositor: CompositorState,
|
||||
pub(super) text_input: TextInputState,
|
||||
pub(super) text_input: Option<TextInputState>,
|
||||
pub(super) output_manager: Option<OutputManagerState>,
|
||||
pub(super) seat: SeatState,
|
||||
pub(super) xdg: XdgShell,
|
||||
@@ -85,7 +85,7 @@ impl WaylandState {
|
||||
registry: RegistryState::new(globals),
|
||||
output: OutputState::new(globals, qh),
|
||||
compositor: CompositorState::bind(globals, qh)?,
|
||||
text_input: TextInputState::bind(globals, qh)?,
|
||||
text_input: TextInputState::bind(globals, qh).ok(),
|
||||
output_manager: if config::configuration().enable_zwlr_output_manager {
|
||||
Some(OutputManagerState::bind(globals, qh)?)
|
||||
} else {
|
||||
@@ -141,12 +141,10 @@ impl OutputHandler for WaylandState {
|
||||
|
||||
fn update_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {
|
||||
log::trace!("update output: OutputHandler");
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn output_destroyed(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {
|
||||
log::trace!("output destroyed: OutputHandler");
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
// Undocumented in sctk 0.17: This is required to use have user data with a surface
|
||||
|
||||
@@ -873,14 +873,16 @@ impl WaylandWindowInner {
|
||||
let surface_udata = SurfaceUserData::from_wl(&surface);
|
||||
let factor = surface_udata.surface_data().scale_factor();
|
||||
|
||||
if let Some(input) = state.text_input.get_text_input_for_surface(&surface) {
|
||||
input.set_cursor_rectangle(
|
||||
rect.min_x() as i32 / factor,
|
||||
rect.min_y() as i32 / factor,
|
||||
rect.width() as i32 / factor,
|
||||
rect.height() as i32 / factor,
|
||||
);
|
||||
input.commit();
|
||||
if let Some(text_input) = &state.text_input {
|
||||
if let Some(input) = text_input.get_text_input_for_surface(&surface) {
|
||||
input.set_cursor_rectangle(
|
||||
rect.min_x() as i32 / factor,
|
||||
rect.min_y() as i32 / factor,
|
||||
rect.width() as i32 / factor,
|
||||
rect.height() as i32 / factor,
|
||||
);
|
||||
input.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user