aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2023-09-30 23:16:20 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-01 06:29:33 +0300
commitd39da3f46112395e5e359efd756e9c510c03e243 (patch)
tree1af201d65db3bb8180f84cd0996970d1fb3dbc31 /src
parent751345759a0b45f4f6d79cdd1c65a71780cb4a27 (diff)
downloadniri-d39da3f46112395e5e359efd756e9c510c03e243.tar.gz
niri-d39da3f46112395e5e359efd756e9c510c03e243.tar.bz2
niri-d39da3f46112395e5e359efd756e9c510c03e243.zip
protocols: add IME protocols
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.
Diffstat (limited to 'src')
-rw-r--r--src/handlers/mod.rs27
-rw-r--r--src/niri.rs14
2 files changed, 39 insertions, 2 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
index 7340e437..743fd93c 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<i32, Logical> {
+ 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 b2fe0c41..eea0a2c0 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<State>,
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::<State>(&display_handle, CLOCK_MONOTONIC as u32);
+ let text_input_state = TextInputManagerState::new::<State>(&display_handle);
+ let input_method_state = InputMethodManagerState::new::<State>(&display_handle);
+ let virtual_keyboard_state =
+ VirtualKeyboardManagerState::new::<State, _>(&display_handle, |_| true);
+
let mut seat: Seat<State> = 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,