Skip to content

Commit

Permalink
protocols: add IME protocols
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kchibisov authored and YaLTeR committed Oct 1, 2023
1 parent f625ac8 commit 01440ab
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = ();
Expand Down
14 changes: 14 additions & 0 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 01440ab

Please sign in to comment.