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.
This commit is contained in:
Kirill Chibisov
2023-09-30 23:16:20 +04:00
committed by Ivan Molodetskikh
parent 751345759a
commit d39da3f461
2 changed files with 39 additions and 2 deletions
+25 -2
View File
@@ -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 = ();
+14
View File
@@ -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,