Update Smithay (virtual keyboard, layer-shell geometry, GPU profiling)
Browse files at this commit74d14be01f606ff519f1c4433715785c00aa0caaParent: 3ccb06f7 changed files +179 -8
- Cargo.lock +2 -2
- src/handlers/mod.rs +1 -2
- src/input/backend_ext.rs +7 -0
- src/input/mod.rs +29 -3
- src/niri.rs +7 -1
- src/protocols/mod.rs +1 -0
- src/protocols/virtual_keyboard.rs +132 -0
Cargo.lockmodified+2 -2
| @@ -3397,7 +3397,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" | |||
| 3397 | [[package]] | 3397 | [[package]] |
| 3398 | name = "smithay" | 3398 | name = "smithay" |
| 3399 | version = "0.7.0" | 3399 | version = "0.7.0" |
| 3400 | -source = "git+https://github.com/Smithay/smithay.git#ca932e042fa9ad150605c150a86275b85f9ad5b3" | 3400 | +source = "git+https://github.com/Smithay/smithay.git#2928e4f34541d957b7b3c3b3e13b2539cd44990f" |
| 3401 | dependencies = [ | 3401 | dependencies = [ |
| 3402 | "aliasable", | 3402 | "aliasable", |
| 3403 | "appendlist", | 3403 | "appendlist", |
| @@ -3471,7 +3471,7 @@ dependencies = [ | |||
| 3471 | [[package]] | 3471 | [[package]] |
| 3472 | name = "smithay-drm-extras" | 3472 | name = "smithay-drm-extras" |
| 3473 | version = "0.1.0" | 3473 | version = "0.1.0" |
| 3474 | -source = "git+https://github.com/Smithay/smithay.git#ca932e042fa9ad150605c150a86275b85f9ad5b3" | 3474 | +source = "git+https://github.com/Smithay/smithay.git#2928e4f34541d957b7b3c3b3e13b2539cd44990f" |
| 3475 | dependencies = [ | 3475 | dependencies = [ |
| 3476 | "drm", | 3476 | "drm", |
| 3477 | "libdisplay-info", | 3477 | "libdisplay-info", |
src/handlers/mod.rsmodified+1 -2
| @@ -68,7 +68,7 @@ use smithay::{ | |||
| 68 | delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, | 68 | delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, |
| 69 | delegate_relative_pointer, delegate_seat, delegate_security_context, delegate_session_lock, | 69 | delegate_relative_pointer, delegate_seat, delegate_security_context, delegate_session_lock, |
| 70 | delegate_single_pixel_buffer, delegate_tablet_manager, delegate_text_input_manager, | 70 | delegate_single_pixel_buffer, delegate_tablet_manager, delegate_text_input_manager, |
| 71 | - delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, | 71 | + delegate_viewporter, delegate_xdg_activation, |
| 72 | }; | 72 | }; |
| 73 | 73 | ||
| 74 | pub use crate::handlers::xdg_shell::KdeDecorationsModeState; | 74 | pub use crate::handlers::xdg_shell::KdeDecorationsModeState; |
| @@ -279,7 +279,6 @@ impl KeyboardShortcutsInhibitHandler for State { | |||
| 279 | 279 | ||
| 280 | delegate_input_method_manager!(State); | 280 | delegate_input_method_manager!(State); |
| 281 | delegate_keyboard_shortcuts_inhibit!(State); | 281 | delegate_keyboard_shortcuts_inhibit!(State); |
| 282 | -delegate_virtual_keyboard_manager!(State); | ||
| 283 | 282 | ||
| 284 | impl SelectionHandler for State { | 283 | impl SelectionHandler for State { |
| 285 | type SelectionUserData = Arc<[u8]>; | 284 | type SelectionUserData = Arc<[u8]>; |
src/input/backend_ext.rsmodified+7 -0
| @@ -4,6 +4,7 @@ use smithay::backend::winit::WinitVirtualDevice; | |||
| 4 | use smithay::output::Output; | 4 | use smithay::output::Output; |
| 5 | 5 | ||
| 6 | use crate::niri::State; | 6 | use crate::niri::State; |
| 7 | +use crate::protocols::virtual_keyboard::VirtualKeyboard; | ||
| 7 | use crate::protocols::virtual_pointer::VirtualPointer; | 8 | use crate::protocols::virtual_pointer::VirtualPointer; |
| 8 | 9 | ||
| 9 | pub trait NiriInputBackend: input::InputBackend<Device = Self::NiriDevice> { | 10 | pub trait NiriInputBackend: input::InputBackend<Device = Self::NiriDevice> { |
| @@ -44,6 +45,12 @@ impl NiriInputDevice for WinitVirtualDevice { | |||
| 44 | } | 45 | } |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 48 | +impl NiriInputDevice for VirtualKeyboard { | ||
| 49 | + fn output(&self, _: &State) -> Option<Output> { | ||
| 50 | + None | ||
| 51 | + } | ||
| 52 | +} | ||
| 53 | + | ||
| 47 | impl NiriInputDevice for VirtualPointer { | 54 | impl NiriInputDevice for VirtualPointer { |
| 48 | fn output(&self, _: &State) -> Option<Output> { | 55 | fn output(&self, _: &State) -> Option<Output> { |
| 49 | self.output().cloned() | 56 | self.output().cloned() |
src/input/mod.rsmodified+29 -3
| @@ -7,7 +7,7 @@ use std::time::Duration; | |||
| 7 | use calloop::timer::{TimeoutAction, Timer}; | 7 | use calloop::timer::{TimeoutAction, Timer}; |
| 8 | use input::event::gesture::GestureEventCoordinates as _; | 8 | use input::event::gesture::GestureEventCoordinates as _; |
| 9 | use niri_config::{ | 9 | use niri_config::{ |
| 10 | - Action, Bind, Binds, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds, Trigger, | 10 | + Action, Bind, Binds, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds, Trigger, Xkb, |
| 11 | }; | 11 | }; |
| 12 | use niri_ipc::LayoutSwitchTarget; | 12 | use niri_ipc::LayoutSwitchTarget; |
| 13 | use smithay::backend::input::{ | 13 | use smithay::backend::input::{ |
| @@ -48,6 +48,7 @@ use crate::dbus::freedesktop_a11y::KbMonBlock; | |||
| 48 | use crate::layout::scrolling::ScrollDirection; | 48 | use crate::layout::scrolling::ScrollDirection; |
| 49 | use crate::layout::{ActivateWindow, LayoutElement as _}; | 49 | use crate::layout::{ActivateWindow, LayoutElement as _}; |
| 50 | use crate::niri::{CastTarget, PointerVisibility, State}; | 50 | use crate::niri::{CastTarget, PointerVisibility, State}; |
| 51 | +use crate::protocols::virtual_keyboard::VirtualKeyboard; | ||
| 51 | use crate::ui::mru::{WindowMru, WindowMruUi}; | 52 | use crate::ui::mru::{WindowMru, WindowMruUi}; |
| 52 | use crate::ui::screenshot_ui::ScreenshotUi; | 53 | use crate::ui::screenshot_ui::ScreenshotUi; |
| 53 | use crate::utils::spawning::{spawn, spawn_sh}; | 54 | use crate::utils::spawning::{spawn, spawn_sh}; |
| @@ -360,11 +361,36 @@ impl State { | |||
| 360 | .is_some_and(KeyboardShortcutsInhibitor::is_active) | 361 | .is_some_and(KeyboardShortcutsInhibitor::is_active) |
| 361 | } | 362 | } |
| 362 | 363 | ||
| 363 | - fn on_keyboard<I: InputBackend>( | 364 | + fn on_keyboard<I: InputBackend + 'static>( |
| 364 | &mut self, | 365 | &mut self, |
| 365 | event: I::KeyboardKeyEvent, | 366 | event: I::KeyboardKeyEvent, |
| 366 | consumed_by_a11y: &mut bool, | 367 | consumed_by_a11y: &mut bool, |
| 367 | - ) { | 368 | + ) where |
| 369 | + I::Device: 'static, | ||
| 370 | + { | ||
| 371 | + // Reset the keymap when handling a physical keyboard after a virtual one. | ||
| 372 | + if self.niri.reset_keymap { | ||
| 373 | + let device = event.device(); | ||
| 374 | + let is_virtual_keyboard = (&device as &dyn Any) | ||
| 375 | + .downcast_ref::<VirtualKeyboard>() | ||
| 376 | + .is_some(); | ||
| 377 | + if !is_virtual_keyboard { | ||
| 378 | + self.niri.reset_keymap = false; | ||
| 379 | + | ||
| 380 | + let config = self.niri.config.borrow(); | ||
| 381 | + let xkb_config = config.input.keyboard.xkb.clone(); | ||
| 382 | + std::mem::drop(config); | ||
| 383 | + | ||
| 384 | + if xkb_config != Xkb::default() { | ||
| 385 | + self.set_xkb_config(xkb_config.to_xkb_config()); | ||
| 386 | + } else { | ||
| 387 | + // Use locale1 settings if xkb config is unset. | ||
| 388 | + let xkb = self.niri.xkb_from_locale1.clone().unwrap_or_default(); | ||
| 389 | + self.set_xkb_config(xkb.to_xkb_config()); | ||
| 390 | + } | ||
| 391 | + } | ||
| 392 | + } | ||
| 393 | + | ||
| 368 | let mod_key = self.backend.mod_key(&self.niri.config.borrow()); | 394 | let mod_key = self.backend.mod_key(&self.niri.config.borrow()); |
| 369 | 395 | ||
| 370 | let serial = SERIAL_COUNTER.next_serial(); | 396 | let serial = SERIAL_COUNTER.next_serial(); |
src/niri.rsmodified+7 -1
| @@ -331,6 +331,11 @@ pub struct Niri { | |||
| 331 | /// Most recent XKB settings from org.freedesktop.locale1. | 331 | /// Most recent XKB settings from org.freedesktop.locale1. |
| 332 | pub xkb_from_locale1: Option<Xkb>, | 332 | pub xkb_from_locale1: Option<Xkb>, |
| 333 | 333 | ||
| 334 | + /// Whether to reset the keymap on the next physical keyboard event. | ||
| 335 | + /// | ||
| 336 | + /// Set to true when handling virtual keyboard events which override the keymap. | ||
| 337 | + pub reset_keymap: bool, | ||
| 338 | + | ||
| 334 | pub cursor_manager: CursorManager, | 339 | pub cursor_manager: CursorManager, |
| 335 | pub cursor_texture_cache: CursorTextureCache, | 340 | pub cursor_texture_cache: CursorTextureCache, |
| 336 | pub cursor_shape_manager_state: CursorShapeManagerState, | 341 | pub cursor_shape_manager_state: CursorShapeManagerState, |
| @@ -1385,7 +1390,7 @@ impl State { | |||
| 1385 | } | 1390 | } |
| 1386 | } | 1391 | } |
| 1387 | 1392 | ||
| 1388 | - fn set_xkb_config(&mut self, xkb: XkbConfig) { | 1393 | + pub fn set_xkb_config(&mut self, xkb: XkbConfig) { |
| 1389 | let keyboard = self.niri.seat.get_keyboard().unwrap(); | 1394 | let keyboard = self.niri.seat.get_keyboard().unwrap(); |
| 1390 | let num_lock = keyboard.modifier_state().num_lock; | 1395 | let num_lock = keyboard.modifier_state().num_lock; |
| 1391 | if let Err(err) = keyboard.set_xkb_config(self, xkb) { | 1396 | if let Err(err) = keyboard.set_xkb_config(self, xkb) { |
| @@ -2505,6 +2510,7 @@ impl Niri { | |||
| 2505 | is_fdo_idle_inhibited: Arc::new(AtomicBool::new(false)), | 2510 | is_fdo_idle_inhibited: Arc::new(AtomicBool::new(false)), |
| 2506 | keyboard_shortcuts_inhibiting_surfaces: HashMap::new(), | 2511 | keyboard_shortcuts_inhibiting_surfaces: HashMap::new(), |
| 2507 | xkb_from_locale1: None, | 2512 | xkb_from_locale1: None, |
| 2513 | + reset_keymap: false, | ||
| 2508 | cursor_manager, | 2514 | cursor_manager, |
| 2509 | cursor_texture_cache: Default::default(), | 2515 | cursor_texture_cache: Default::default(), |
| 2510 | cursor_shape_manager_state, | 2516 | cursor_shape_manager_state, |
src/protocols/mod.rsmodified+1 -0
| @@ -4,6 +4,7 @@ pub mod gamma_control; | |||
| 4 | pub mod mutter_x11_interop; | 4 | pub mod mutter_x11_interop; |
| 5 | pub mod output_management; | 5 | pub mod output_management; |
| 6 | pub mod screencopy; | 6 | pub mod screencopy; |
| 7 | +pub mod virtual_keyboard; | ||
| 7 | pub mod virtual_pointer; | 8 | pub mod virtual_pointer; |
| 8 | 9 | ||
| 9 | pub mod raw; | 10 | pub mod raw; |
src/protocols/virtual_keyboard.rsadded+132 -0
| @@ -0,0 +1,132 @@ | |||
| 1 | +use smithay::backend::input::{ | ||
| 2 | + Device, DeviceCapability, Event, InputBackend, InputEvent, KeyState, KeyboardKeyEvent, Keycode, | ||
| 3 | + UnusedEvent, | ||
| 4 | +}; | ||
| 5 | +use smithay::delegate_virtual_keyboard_manager; | ||
| 6 | +use smithay::input::keyboard::xkb::ModMask; | ||
| 7 | +use smithay::input::keyboard::KeyboardHandle; | ||
| 8 | +use smithay::wayland::virtual_keyboard::VirtualKeyboardHandler; | ||
| 9 | + | ||
| 10 | +use crate::niri::State; | ||
| 11 | + | ||
| 12 | +pub struct VirtualKeyboardInputBackend; | ||
| 13 | + | ||
| 14 | +#[derive(Clone, Debug, Hash, Eq, PartialEq)] | ||
| 15 | +pub struct VirtualKeyboard; | ||
| 16 | + | ||
| 17 | +impl Device for VirtualKeyboard { | ||
| 18 | + fn id(&self) -> String { | ||
| 19 | + String::from("virtual keyboard") | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + fn name(&self) -> String { | ||
| 23 | + String::from("virtual keyboard") | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + fn has_capability(&self, capability: DeviceCapability) -> bool { | ||
| 27 | + matches!(capability, DeviceCapability::Keyboard) | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + fn usb_id(&self) -> Option<(u32, u32)> { | ||
| 31 | + None | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + fn syspath(&self) -> Option<std::path::PathBuf> { | ||
| 35 | + None | ||
| 36 | + } | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +pub struct VirtualKeyboardKeyEvent { | ||
| 40 | + pub keycode: Keycode, | ||
| 41 | + pub state: KeyState, | ||
| 42 | + pub time: u32, | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +impl Event<VirtualKeyboardInputBackend> for VirtualKeyboardKeyEvent { | ||
| 46 | + fn time(&self) -> u64 { | ||
| 47 | + self.time as u64 * 1000 // millis to micros | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + fn device(&self) -> VirtualKeyboard { | ||
| 51 | + VirtualKeyboard | ||
| 52 | + } | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +impl KeyboardKeyEvent<VirtualKeyboardInputBackend> for VirtualKeyboardKeyEvent { | ||
| 56 | + fn key_code(&self) -> Keycode { | ||
| 57 | + self.keycode | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + fn state(&self) -> KeyState { | ||
| 61 | + self.state | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + fn count(&self) -> u32 { | ||
| 65 | + 0 // Not used by niri | ||
| 66 | + } | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +impl InputBackend for VirtualKeyboardInputBackend { | ||
| 70 | + type Device = VirtualKeyboard; | ||
| 71 | + | ||
| 72 | + type KeyboardKeyEvent = VirtualKeyboardKeyEvent; | ||
| 73 | + type PointerAxisEvent = UnusedEvent; | ||
| 74 | + type PointerButtonEvent = UnusedEvent; | ||
| 75 | + type PointerMotionEvent = UnusedEvent; | ||
| 76 | + type PointerMotionAbsoluteEvent = UnusedEvent; | ||
| 77 | + | ||
| 78 | + type GestureSwipeBeginEvent = UnusedEvent; | ||
| 79 | + type GestureSwipeUpdateEvent = UnusedEvent; | ||
| 80 | + type GestureSwipeEndEvent = UnusedEvent; | ||
| 81 | + type GesturePinchBeginEvent = UnusedEvent; | ||
| 82 | + type GesturePinchUpdateEvent = UnusedEvent; | ||
| 83 | + type GesturePinchEndEvent = UnusedEvent; | ||
| 84 | + type GestureHoldBeginEvent = UnusedEvent; | ||
| 85 | + type GestureHoldEndEvent = UnusedEvent; | ||
| 86 | + | ||
| 87 | + type TouchDownEvent = UnusedEvent; | ||
| 88 | + type TouchUpEvent = UnusedEvent; | ||
| 89 | + type TouchMotionEvent = UnusedEvent; | ||
| 90 | + type TouchCancelEvent = UnusedEvent; | ||
| 91 | + type TouchFrameEvent = UnusedEvent; | ||
| 92 | + type TabletToolAxisEvent = UnusedEvent; | ||
| 93 | + type TabletToolProximityEvent = UnusedEvent; | ||
| 94 | + type TabletToolTipEvent = UnusedEvent; | ||
| 95 | + type TabletToolButtonEvent = UnusedEvent; | ||
| 96 | + | ||
| 97 | + type SwitchToggleEvent = UnusedEvent; | ||
| 98 | + | ||
| 99 | + type SpecialEvent = UnusedEvent; | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +impl VirtualKeyboardHandler for State { | ||
| 103 | + fn on_keyboard_event( | ||
| 104 | + &mut self, | ||
| 105 | + keycode: Keycode, | ||
| 106 | + state: KeyState, | ||
| 107 | + time: u32, | ||
| 108 | + _keyboard: KeyboardHandle<Self>, | ||
| 109 | + ) { | ||
| 110 | + // The virtual keyboard impl in Smithay changes the keymap, so we'll need to reset it on | ||
| 111 | + // the next real keyboard event. | ||
| 112 | + self.niri.reset_keymap = true; | ||
| 113 | + | ||
| 114 | + let event = VirtualKeyboardKeyEvent { | ||
| 115 | + keycode, | ||
| 116 | + state, | ||
| 117 | + time, | ||
| 118 | + }; | ||
| 119 | + self.process_input_event(InputEvent::<VirtualKeyboardInputBackend>::Keyboard { event }); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + // We handle modifiers when the key event is sent. | ||
| 123 | + fn on_keyboard_modifiers( | ||
| 124 | + &mut self, | ||
| 125 | + _depressed_mods: ModMask, | ||
| 126 | + _latched_mods: ModMask, | ||
| 127 | + _locked_mods: ModMask, | ||
| 128 | + _keyboard: KeyboardHandle<Self>, | ||
| 129 | + ) { | ||
| 130 | + } | ||
| 131 | +} | ||
| 132 | +delegate_virtual_keyboard_manager!(State); | ||