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