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;
4 4
5 use smithay::backend::allocator::dmabuf::Dmabuf;5 use smithay::backend::allocator::dmabuf::Dmabuf;
6 use smithay::backend::renderer::ImportDma;6 use smithay::backend::renderer::ImportDma;
7+use smithay::desktop::PopupKind;
7 use smithay::input::pointer::CursorImageStatus;8 use smithay::input::pointer::CursorImageStatus;
8 use smithay::input::{Seat, SeatHandler, SeatState};9 use smithay::input::{Seat, SeatHandler, SeatState};
9 use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;10 use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
10 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;11 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
11 use smithay::reexports::wayland_server::Resource;12 use smithay::reexports::wayland_server::Resource;
13+use smithay::utils::{Logical, Rectangle};
12 use smithay::wayland::data_device::{14 use smithay::wayland::data_device::{
13 set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,15 set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,
14 ServerDndGrabHandler,16 ServerDndGrabHandler,
15 };17 };
16 use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError};18 use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError};
19+use smithay::wayland::input_method::{InputMethodHandler, PopupSurface};
17 use smithay::wayland::primary_selection::{20 use smithay::wayland::primary_selection::{
18 set_primary_focus, PrimarySelectionHandler, PrimarySelectionState,21 set_primary_focus, PrimarySelectionHandler, PrimarySelectionState,
19 };22 };
20 use smithay::{23 use smithay::{
21- delegate_data_device, delegate_dmabuf, delegate_output, delegate_pointer_gestures,24+ delegate_data_device, delegate_dmabuf, delegate_input_method_manager, delegate_output,
22- delegate_presentation, delegate_primary_selection, delegate_seat, delegate_tablet_manager,25+ delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, delegate_seat,
26+ delegate_tablet_manager, delegate_text_input_manager, delegate_virtual_keyboard_manager,
23 };27 };
24 28
25 use crate::niri::State;29 use crate::niri::State;
@@ -48,6 +52,25 @@ impl SeatHandler for State {
48 delegate_seat!(State);52 delegate_seat!(State);
49 delegate_tablet_manager!(State);53 delegate_tablet_manager!(State);
50 delegate_pointer_gestures!(State);54 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);
51 74
52 impl DataDeviceHandler for State {75 impl DataDeviceHandler for State {
53 type SelectionUserData = ();76 type SelectionUserData = ();
src/niri.rsmodified+14 -0
@@ -53,6 +53,7 @@ use smithay::wayland::compositor::{
53 };53 };
54 use smithay::wayland::data_device::DataDeviceState;54 use smithay::wayland::data_device::DataDeviceState;
55 use smithay::wayland::dmabuf::DmabufFeedback;55 use smithay::wayland::dmabuf::DmabufFeedback;
56+use smithay::wayland::input_method::InputMethodManagerState;
56 use smithay::wayland::output::OutputManagerState;57 use smithay::wayland::output::OutputManagerState;
57 use smithay::wayland::pointer_gestures::PointerGesturesState;58 use smithay::wayland::pointer_gestures::PointerGesturesState;
58 use smithay::wayland::presentation::PresentationState;59 use smithay::wayland::presentation::PresentationState;
@@ -64,6 +65,8 @@ use smithay::wayland::shell::xdg::XdgShellState;
64 use smithay::wayland::shm::ShmState;65 use smithay::wayland::shm::ShmState;
65 use smithay::wayland::socket::ListeningSocketSource;66 use smithay::wayland::socket::ListeningSocketSource;
66 use smithay::wayland::tablet_manager::TabletManagerState;67 use smithay::wayland::tablet_manager::TabletManagerState;
68+use smithay::wayland::text_input::TextInputManagerState;
69+use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
67 use zbus::fdo::RequestNameFlags;70 use zbus::fdo::RequestNameFlags;
68 71
69 use crate::backend::{Backend, Tty, Winit};72 use crate::backend::{Backend, Tty, Winit};
@@ -108,6 +111,9 @@ pub struct Niri {
108 pub output_manager_state: OutputManagerState,111 pub output_manager_state: OutputManagerState,
109 pub seat_state: SeatState<State>,112 pub seat_state: SeatState<State>,
110 pub tablet_state: TabletManagerState,113 pub tablet_state: TabletManagerState,
114+ pub text_input_state: TextInputManagerState,
115+ pub input_method_state: InputMethodManagerState,
116+ pub virtual_keyboard_state: VirtualKeyboardManagerState,
111 pub pointer_gestures_state: PointerGesturesState,117 pub pointer_gestures_state: PointerGesturesState,
112 pub data_device_state: DataDeviceState,118 pub data_device_state: DataDeviceState,
113 pub primary_selection_state: PrimarySelectionState,119 pub primary_selection_state: PrimarySelectionState,
@@ -301,6 +307,11 @@ impl Niri {
301 let presentation_state =307 let presentation_state =
302 PresentationState::new::<State>(&display_handle, CLOCK_MONOTONIC as u32);308 PresentationState::new::<State>(&display_handle, CLOCK_MONOTONIC as u32);
303 309
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+
304 let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name());315 let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name());
305 let xkb = XkbConfig {316 let xkb = XkbConfig {
306 rules: &config_.input.keyboard.xkb.rules,317 rules: &config_.input.keyboard.xkb.rules,
@@ -650,6 +661,9 @@ impl Niri {
650 xdg_decoration_state,661 xdg_decoration_state,
651 kde_decoration_state,662 kde_decoration_state,
652 layer_shell_state,663 layer_shell_state,
664+ text_input_state,
665+ input_method_state,
666+ virtual_keyboard_state,
653 shm_state,667 shm_state,
654 output_manager_state,668 output_manager_state,
655 seat_state,669 seat_state,