Skip to content

Commit 35c8e54

Browse files
committed
feat: handle virtual keyboard by ourself
1 parent af9ce53 commit 35c8e54

File tree

4 files changed

+52
-23
lines changed

4 files changed

+52
-23
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ tracy-client = { version = "0.18.2", default-features = false }
2727

2828
[workspace.dependencies.smithay]
2929
# version = "0.4.1"
30-
git = "https://github.com/Smithay/smithay.git"
31-
# path = "../smithay"
30+
# git = "https://github.com/Smithay/smithay.git"
31+
path = "../smithay"
3232
default-features = false
3333

3434
[workspace.dependencies.smithay-drm-extras]

src/input/mod.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use crate::niri::{CastTarget, PointerVisibility, State};
4646
use crate::ui::screenshot_ui::ScreenshotUi;
4747
use crate::utils::spawning::spawn;
4848
use crate::utils::{center, get_monotonic_time, ResizeEdge};
49+
use smithay::input::keyboard::KeyboardHandle;
4950

5051
pub mod backend_ext;
5152
pub mod move_grab;
@@ -333,12 +334,17 @@ impl State {
333334
.is_some_and(KeyboardShortcutsInhibitor::is_active)
334335
}
335336

336-
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
337+
pub fn on_keyboard_real(
338+
&mut self,
339+
key: Keycode,
340+
state: KeyState,
341+
time: u32,
342+
keyboard: KeyboardHandle<Self>,
343+
) {
337344
let mod_key = self.backend.mod_key(&self.niri.config.borrow());
338345

339346
let serial = SERIAL_COUNTER.next_serial();
340-
let time = Event::time_msec(&event);
341-
let pressed = event.state() == KeyState::Pressed;
347+
let pressed = state == KeyState::Pressed;
342348

343349
// Stop bind key repeat on any release. This won't work 100% correctly in cases like:
344350
// 1. Press Mod
@@ -362,22 +368,13 @@ impl State {
362368
// Accessibility modifier grabs should override XKB state changes (e.g. Caps Lock), so we
363369
// need to process them before keyboard.input() below.
364370
#[cfg(feature = "dbus")]
365-
if self.a11y_process_key(
366-
Duration::from_millis(u64::from(time)),
367-
event.key_code(),
368-
event.state(),
369-
) {
371+
if self.a11y_process_key(Duration::from_millis(u64::from(time)), key, state) {
370372
return;
371373
}
372374

373-
let Some(Some(bind)) = self.niri.seat.get_keyboard().unwrap().input(
374-
self,
375-
event.key_code(),
376-
event.state(),
377-
serial,
378-
time,
379-
|this, mods, keysym| {
380-
let key_code = event.key_code();
375+
let Some(Some(bind)) =
376+
keyboard.input(self, key, state, serial, time, |this, mods, keysym| {
377+
let key_code = key;
381378
let modified = keysym.modified_sym();
382379
let raw = keysym.raw_latin_sym_or_raw_current_sym();
383380

@@ -438,8 +435,8 @@ impl State {
438435
}
439436

440437
res
441-
},
442-
) else {
438+
})
439+
else {
443440
return;
444441
};
445442

@@ -452,6 +449,15 @@ impl State {
452449
self.start_key_repeat(bind);
453450
}
454451

452+
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
453+
self.on_keyboard_real(
454+
event.key_code(),
455+
event.state(),
456+
Event::time_msec(&event),
457+
self.niri.seat.get_keyboard().unwrap(),
458+
);
459+
}
460+
455461
fn start_key_repeat(&mut self, bind: Bind) {
456462
if !bind.repeat {
457463
return;

src/niri.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use niri_config::{
1818
WarpMouseToFocusMode, WorkspaceReference, Xkb,
1919
};
2020
use smithay::backend::allocator::Fourcc;
21-
use smithay::backend::input::Keycode;
21+
use smithay::backend::input::{KeyState, Keycode};
2222
use smithay::backend::renderer::damage::OutputDamageTracker;
2323
use smithay::backend::renderer::element::memory::MemoryRenderBufferRenderElement;
2424
use smithay::backend::renderer::element::surface::{
@@ -45,6 +45,8 @@ use smithay::desktop::{
4545
find_popup_root_surface, layer_map_for_output, LayerMap, LayerSurface, PopupGrab, PopupManager,
4646
PopupUngrabStrategy, Space, Window, WindowSurfaceType,
4747
};
48+
use smithay::input::keyboard::xkb::ModMask;
49+
use smithay::input::keyboard::KeyboardHandle;
4850
use smithay::input::keyboard::Layout as KeyboardLayout;
4951
use smithay::input::pointer::{
5052
CursorIcon, CursorImageStatus, CursorImageSurfaceData, Focus,
@@ -106,7 +108,7 @@ use smithay::wayland::socket::ListeningSocketSource;
106108
use smithay::wayland::tablet_manager::TabletManagerState;
107109
use smithay::wayland::text_input::TextInputManagerState;
108110
use smithay::wayland::viewporter::ViewporterState;
109-
use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
111+
use smithay::wayland::virtual_keyboard::{VirtualKeyboardHandler, VirtualKeyboardManagerState};
110112
use smithay::wayland::xdg_activation::XdgActivationState;
111113
use smithay::wayland::xdg_foreign::XdgForeignState;
112114

@@ -6267,6 +6269,28 @@ fn scale_relocate_crop<E: Element>(
62676269
CropRenderElement::from_element(elem, output_scale, ws_geo)
62686270
}
62696271

6272+
impl VirtualKeyboardHandler for State {
6273+
fn on_keyboard_event(
6274+
&mut self,
6275+
keycode: Keycode,
6276+
state: KeyState,
6277+
time: u32,
6278+
keyboard: KeyboardHandle<Self>,
6279+
) {
6280+
self.on_keyboard_real(keycode, state, time, keyboard);
6281+
}
6282+
6283+
/// We handle modifiers when the key event is sent
6284+
fn on_keyboard_modifiers(
6285+
&mut self,
6286+
_depressed_mods: ModMask,
6287+
_latched_mods: ModMask,
6288+
_locked_mods: ModMask,
6289+
_keyboard: KeyboardHandle<Self>,
6290+
) {
6291+
}
6292+
}
6293+
62706294
niri_render_elements! {
62716295
OutputRenderElements<R> => {
62726296
Monitor = MonitorRenderElement<R>,

0 commit comments

Comments
 (0)