From 304f4069f31921ac9a1848056e3029ea43a6daa0 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 25 May 2023 14:37:30 -0700 Subject: [PATCH] Enable necessary protocols for supporting IMEs --- src/state.rs | 6 ++++ src/wayland/handlers/input_method.rs | 40 ++++++++++++++++++++++++ src/wayland/handlers/mod.rs | 3 ++ src/wayland/handlers/seat.rs | 2 +- src/wayland/handlers/text_input.rs | 6 ++++ src/wayland/handlers/virtual_keyboard.rs | 6 ++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/wayland/handlers/input_method.rs create mode 100644 src/wayland/handlers/text_input.rs create mode 100644 src/wayland/handlers/virtual_keyboard.rs diff --git a/src/state.rs b/src/state.rs index d41ed4525..4dd98dcab 100644 --- a/src/state.rs +++ b/src/state.rs @@ -63,6 +63,7 @@ use smithay::{ compositor::{CompositorClientState, CompositorState}, dmabuf::{DmabufFeedback, DmabufState}, fractional_scale::{with_fractional_scale, FractionalScaleManagerState}, + input_method::InputMethodManagerState, keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState, output::OutputManagerState, pointer_constraints::PointerConstraintsState, @@ -74,7 +75,9 @@ use smithay::{ session_lock::{LockSurface, SessionLockManagerState}, shell::{kde::decoration::KdeDecorationState, xdg::decoration::XdgDecorationState}, shm::ShmState, + text_input::TextInputManagerState, viewporter::ViewporterState, + virtual_keyboard::VirtualKeyboardManagerState, xwayland_keyboard_grab::XWaylandKeyboardGrabState, }, }; @@ -351,6 +354,9 @@ impl State { PointerConstraintsState::new::(&dh); PointerGesturesState::new::(&dh); SecurityContextState::new::(&dh, client_has_no_security_context); + InputMethodManagerState::new::(&dh, client_should_see_privileged_protocols); + TextInputManagerState::new::(&dh); + VirtualKeyboardManagerState::new::(&dh, client_should_see_privileged_protocols); let shell = Shell::new(&config, dh); diff --git a/src/wayland/handlers/input_method.rs b/src/wayland/handlers/input_method.rs new file mode 100644 index 000000000..c92c3438d --- /dev/null +++ b/src/wayland/handlers/input_method.rs @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-3.0-only + +use crate::state::State; +use smithay::{ + delegate_input_method_manager, + desktop::{space::SpaceElement, PopupKind, PopupManager}, + reexports::wayland_server::protocol::wl_surface::WlSurface, + utils::Rectangle, + wayland::input_method::{InputMethodHandler, PopupSurface}, +}; +use tracing::warn; + +impl InputMethodHandler for State { + fn new_popup(&mut self, surface: PopupSurface) { + if let Err(err) = self + .common + .shell + .popups + .track_popup(PopupKind::from(surface)) + { + warn!("Failed to track popup: {}", err); + } + } + + fn dismiss_popup(&mut self, surface: PopupSurface) { + if let Some(parent) = surface.get_parent().map(|parent| parent.surface.clone()) { + let _ = PopupManager::dismiss_popup(&parent, &PopupKind::from(surface)); + } + } + + fn parent_geometry(&self, parent: &WlSurface) -> Rectangle { + self.common + .shell + .element_for_wl_surface(parent) + .map(|e| e.geometry()) + .unwrap_or_default() + } +} + +delegate_input_method_manager!(State); diff --git a/src/wayland/handlers/mod.rs b/src/wayland/handlers/mod.rs index 14aa5308b..2edb9affe 100644 --- a/src/wayland/handlers/mod.rs +++ b/src/wayland/handlers/mod.rs @@ -7,6 +7,7 @@ pub mod decoration; pub mod dmabuf; pub mod drm_lease; pub mod fractional_scale; +pub mod input_method; pub mod keyboard_shortcuts_inhibit; pub mod layer_shell; pub mod output; @@ -22,9 +23,11 @@ pub mod security_context; pub mod selection; pub mod session_lock; pub mod shm; +pub mod text_input; pub mod toplevel_info; pub mod toplevel_management; pub mod viewporter; +pub mod virtual_keyboard; pub mod wl_drm; pub mod workspace; pub mod xdg_shell; diff --git a/src/wayland/handlers/seat.rs b/src/wayland/handlers/seat.rs index 929c92cba..cfb3651ad 100644 --- a/src/wayland/handlers/seat.rs +++ b/src/wayland/handlers/seat.rs @@ -46,7 +46,7 @@ impl SeatHandler for State { .and_then(|s| dh.get_client(s.id()).ok()) { set_data_device_focus(dh, seat, Some(client.clone())); - set_primary_focus(dh, seat, Some(client)) + set_primary_focus(dh, seat, Some(client)); } } } diff --git a/src/wayland/handlers/text_input.rs b/src/wayland/handlers/text_input.rs new file mode 100644 index 000000000..fb4f53b3f --- /dev/null +++ b/src/wayland/handlers/text_input.rs @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0-only + +use crate::state::State; +use smithay::delegate_text_input_manager; + +delegate_text_input_manager!(State); diff --git a/src/wayland/handlers/virtual_keyboard.rs b/src/wayland/handlers/virtual_keyboard.rs new file mode 100644 index 000000000..f39ff22a6 --- /dev/null +++ b/src/wayland/handlers/virtual_keyboard.rs @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0-only + +use crate::state::State; +use smithay::delegate_virtual_keyboard_manager; + +delegate_virtual_keyboard_manager!(State);