diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 7340e437d..743fd93c6 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -4,22 +4,26 @@ mod xdg_shell; use smithay::backend::allocator::dmabuf::Dmabuf; use smithay::backend::renderer::ImportDma; +use smithay::desktop::PopupKind; use smithay::input::pointer::CursorImageStatus; use smithay::input::{Seat, SeatHandler, SeatState}; use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::Resource; +use smithay::utils::{Logical, Rectangle}; use smithay::wayland::data_device::{ set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler, }; use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError}; +use smithay::wayland::input_method::{InputMethodHandler, PopupSurface}; use smithay::wayland::primary_selection::{ set_primary_focus, PrimarySelectionHandler, PrimarySelectionState, }; use smithay::{ - delegate_data_device, delegate_dmabuf, delegate_output, delegate_pointer_gestures, - delegate_presentation, delegate_primary_selection, delegate_seat, delegate_tablet_manager, + delegate_data_device, delegate_dmabuf, delegate_input_method_manager, delegate_output, + delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, delegate_seat, + delegate_tablet_manager, delegate_text_input_manager, delegate_virtual_keyboard_manager, }; use crate::niri::State; @@ -48,6 +52,25 @@ impl SeatHandler for State { delegate_seat!(State); delegate_tablet_manager!(State); delegate_pointer_gestures!(State); +delegate_text_input_manager!(State); + +impl InputMethodHandler for State { + fn new_popup(&mut self, surface: PopupSurface) { + if let Err(err) = self.niri.popups.track_popup(PopupKind::from(surface)) { + warn!("error tracking ime popup {err:?}"); + } + } + fn parent_geometry(&self, parent: &WlSurface) -> Rectangle { + self.niri + .monitor_set + .find_window_and_output(parent) + .map(|(window, _)| window.geometry()) + .unwrap_or_default() + } +} + +delegate_input_method_manager!(State); +delegate_virtual_keyboard_manager!(State); impl DataDeviceHandler for State { type SelectionUserData = (); diff --git a/src/niri.rs b/src/niri.rs index b2fe0c41b..eea0a2c09 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -53,6 +53,7 @@ use smithay::wayland::compositor::{ }; use smithay::wayland::data_device::DataDeviceState; use smithay::wayland::dmabuf::DmabufFeedback; +use smithay::wayland::input_method::InputMethodManagerState; use smithay::wayland::output::OutputManagerState; use smithay::wayland::pointer_gestures::PointerGesturesState; use smithay::wayland::presentation::PresentationState; @@ -64,6 +65,8 @@ use smithay::wayland::shell::xdg::XdgShellState; use smithay::wayland::shm::ShmState; use smithay::wayland::socket::ListeningSocketSource; use smithay::wayland::tablet_manager::TabletManagerState; +use smithay::wayland::text_input::TextInputManagerState; +use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; use zbus::fdo::RequestNameFlags; use crate::backend::{Backend, Tty, Winit}; @@ -108,6 +111,9 @@ pub struct Niri { pub output_manager_state: OutputManagerState, pub seat_state: SeatState, pub tablet_state: TabletManagerState, + pub text_input_state: TextInputManagerState, + pub input_method_state: InputMethodManagerState, + pub virtual_keyboard_state: VirtualKeyboardManagerState, pub pointer_gestures_state: PointerGesturesState, pub data_device_state: DataDeviceState, pub primary_selection_state: PrimarySelectionState, @@ -301,6 +307,11 @@ impl Niri { let presentation_state = PresentationState::new::(&display_handle, CLOCK_MONOTONIC as u32); + let text_input_state = TextInputManagerState::new::(&display_handle); + let input_method_state = InputMethodManagerState::new::(&display_handle); + let virtual_keyboard_state = + VirtualKeyboardManagerState::new::(&display_handle, |_| true); + let mut seat: Seat = seat_state.new_wl_seat(&display_handle, backend.seat_name()); let xkb = XkbConfig { rules: &config_.input.keyboard.xkb.rules, @@ -650,6 +661,9 @@ impl Niri { xdg_decoration_state, kde_decoration_state, layer_shell_state, + text_input_state, + input_method_state, + virtual_keyboard_state, shm_state, output_manager_state, seat_state,