forge
Explore
Log in

Don't you dare go Hollow

protocols: add IME protocols

Browse files at this commit

d39da3f46112395e5e359efd756e9c510c03e243Kirill ChibisovParent: 7513457
This commit adds support for the `input_method_v2`, `text_input_v3`,
and `virtual_keyboard`. The implementation follows the one in the
anvil and catacomb, but those protocols are mostly enabled and
forget type of things.

Fixes #22.
src/handlers/mod.rsmodified+25 -2
@@ -4,22 +4,26 @@ mod xdg_shell;
44
55 use smithay::backend::allocator::dmabuf::Dmabuf;
66 use smithay::backend::renderer::ImportDma;
7+use smithay::desktop::PopupKind;
78 use smithay::input::pointer::CursorImageStatus;
89 use smithay::input::{Seat, SeatHandler, SeatState};
910 use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
1011 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
1112 use smithay::reexports::wayland_server::Resource;
13+use smithay::utils::{Logical, Rectangle};
1214 use smithay::wayland::data_device::{
1315 set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,
1416 ServerDndGrabHandler,
1517 };
1618 use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError};
19+use smithay::wayland::input_method::{InputMethodHandler, PopupSurface};
1720 use smithay::wayland::primary_selection::{
1821 set_primary_focus, PrimarySelectionHandler, PrimarySelectionState,
1922 };
2023 use smithay::{
21- delegate_data_device, delegate_dmabuf, delegate_output, delegate_pointer_gestures,
22- delegate_presentation, delegate_primary_selection, delegate_seat, delegate_tablet_manager,
24+ delegate_data_device, delegate_dmabuf, delegate_input_method_manager, delegate_output,
25+ delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, delegate_seat,
26+ delegate_tablet_manager, delegate_text_input_manager, delegate_virtual_keyboard_manager,
2327 };
2428
2529 use crate::niri::State;
@@ -48,6 +52,25 @@ impl SeatHandler for State {
4852 delegate_seat!(State);
4953 delegate_tablet_manager!(State);
5054 delegate_pointer_gestures!(State);
55+delegate_text_input_manager!(State);
56+
57+impl InputMethodHandler for State {
58+ fn new_popup(&mut self, surface: PopupSurface) {
59+ if let Err(err) = self.niri.popups.track_popup(PopupKind::from(surface)) {
60+ warn!("error tracking ime popup {err:?}");
61+ }
62+ }
63+ fn parent_geometry(&self, parent: &WlSurface) -> Rectangle<i32, Logical> {
64+ self.niri
65+ .monitor_set
66+ .find_window_and_output(parent)
67+ .map(|(window, _)| window.geometry())
68+ .unwrap_or_default()
69+ }
70+}
71+
72+delegate_input_method_manager!(State);
73+delegate_virtual_keyboard_manager!(State);
5174
5275 impl DataDeviceHandler for State {
5376 type SelectionUserData = ();
src/niri.rsmodified+14 -0
@@ -53,6 +53,7 @@ use smithay::wayland::compositor::{
5353 };
5454 use smithay::wayland::data_device::DataDeviceState;
5555 use smithay::wayland::dmabuf::DmabufFeedback;
56+use smithay::wayland::input_method::InputMethodManagerState;
5657 use smithay::wayland::output::OutputManagerState;
5758 use smithay::wayland::pointer_gestures::PointerGesturesState;
5859 use smithay::wayland::presentation::PresentationState;
@@ -64,6 +65,8 @@ use smithay::wayland::shell::xdg::XdgShellState;
6465 use smithay::wayland::shm::ShmState;
6566 use smithay::wayland::socket::ListeningSocketSource;
6667 use smithay::wayland::tablet_manager::TabletManagerState;
68+use smithay::wayland::text_input::TextInputManagerState;
69+use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
6770 use zbus::fdo::RequestNameFlags;
6871
6972 use crate::backend::{Backend, Tty, Winit};
@@ -108,6 +111,9 @@ pub struct Niri {
108111 pub output_manager_state: OutputManagerState,
109112 pub seat_state: SeatState<State>,
110113 pub tablet_state: TabletManagerState,
114+ pub text_input_state: TextInputManagerState,
115+ pub input_method_state: InputMethodManagerState,
116+ pub virtual_keyboard_state: VirtualKeyboardManagerState,
111117 pub pointer_gestures_state: PointerGesturesState,
112118 pub data_device_state: DataDeviceState,
113119 pub primary_selection_state: PrimarySelectionState,
@@ -301,6 +307,11 @@ impl Niri {
301307 let presentation_state =
302308 PresentationState::new::<State>(&display_handle, CLOCK_MONOTONIC as u32);
303309
310+ let text_input_state = TextInputManagerState::new::<State>(&display_handle);
311+ let input_method_state = InputMethodManagerState::new::<State>(&display_handle);
312+ let virtual_keyboard_state =
313+ VirtualKeyboardManagerState::new::<State, _>(&display_handle, |_| true);
314+
304315 let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name());
305316 let xkb = XkbConfig {
306317 rules: &config_.input.keyboard.xkb.rules,
@@ -650,6 +661,9 @@ impl Niri {
650661 xdg_decoration_state,
651662 kde_decoration_state,
652663 layer_shell_state,
664+ text_input_state,
665+ input_method_state,
666+ virtual_keyboard_state,
653667 shm_state,
654668 output_manager_state,
655669 seat_state,