From 25079ae75cb6952b0542aa343bd5a52c81d135d4 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 22 Nov 2024 15:44:58 -0800 Subject: [PATCH] Add a `raw_modifiers` argument to `update_modifiers` This can be used for things like nested compositors, that want to propagate the modifier state as expressed by the compositor. --- examples/data_device.rs | 3 ++- examples/generic_simple_window.rs | 3 ++- examples/simple_layer.rs | 3 ++- examples/simple_window.rs | 3 ++- examples/themed_window.rs | 3 ++- src/seat/keyboard/mod.rs | 18 +++++++++++++++++- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/examples/data_device.rs b/examples/data_device.rs index 804fe052d..dda6c8876 100644 --- a/examples/data_device.rs +++ b/examples/data_device.rs @@ -31,7 +31,7 @@ use smithay_client_toolkit::{ registry::{ProvidesRegistryState, RegistryState}, registry_handlers, seat::{ - keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers}, + keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers, RawModifiers}, pointer::{PointerEvent, PointerEventKind, PointerHandler, BTN_LEFT}, Capability, SeatHandler, SeatState, }, @@ -461,6 +461,7 @@ impl KeyboardHandler for DataDeviceWindow { _: &wl_keyboard::WlKeyboard, _serial: u32, modifiers: Modifiers, + _raw_modifiers: RawModifiers, _layout: u32, ) { self.modifiers = modifiers; diff --git a/examples/generic_simple_window.rs b/examples/generic_simple_window.rs index db88c15fc..cd257bc99 100644 --- a/examples/generic_simple_window.rs +++ b/examples/generic_simple_window.rs @@ -8,7 +8,7 @@ use smithay_client_toolkit::{ registry::{ProvidesRegistryState, RegistryState}, registry_handlers, seat::{ - keyboard::{KeyEvent, KeyboardHandler, Modifiers}, + keyboard::{KeyEvent, KeyboardHandler, Modifiers, RawModifiers}, pointer::{PointerEvent, PointerEventKind, PointerHandler}, Capability, SeatHandler, SeatState, }, @@ -349,6 +349,7 @@ impl KeyboardHandler for SimpleWindow { _: &wl_keyboard::WlKeyboard, _serial: u32, modifiers: Modifiers, + _raw_modifiers: RawModifiers, _layout: u32, ) { println!("Update modifiers: {modifiers:?}"); diff --git a/examples/simple_layer.rs b/examples/simple_layer.rs index 481fd1ad3..a11b84e1b 100644 --- a/examples/simple_layer.rs +++ b/examples/simple_layer.rs @@ -10,7 +10,7 @@ use smithay_client_toolkit::{ registry::{ProvidesRegistryState, RegistryState}, registry_handlers, seat::{ - keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers}, + keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers, RawModifiers}, pointer::{PointerEvent, PointerEventKind, PointerHandler}, Capability, SeatHandler, SeatState, }, @@ -344,6 +344,7 @@ impl KeyboardHandler for SimpleLayer { _: &wl_keyboard::WlKeyboard, _serial: u32, modifiers: Modifiers, + _raw_modifiers: RawModifiers, _layout: u32, ) { println!("Update modifiers: {modifiers:?}"); diff --git a/examples/simple_window.rs b/examples/simple_window.rs index 5d20b0a1c..1986ef333 100644 --- a/examples/simple_window.rs +++ b/examples/simple_window.rs @@ -12,7 +12,7 @@ use smithay_client_toolkit::{ registry::{ProvidesRegistryState, RegistryState}, registry_handlers, seat::{ - keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers}, + keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers, RawModifiers}, pointer::{PointerEvent, PointerEventKind, PointerHandler}, Capability, SeatHandler, SeatState, }, @@ -388,6 +388,7 @@ impl KeyboardHandler for SimpleWindow { _: &wl_keyboard::WlKeyboard, _serial: u32, modifiers: Modifiers, + _raw_modifiers: RawModifiers, _layout: u32, ) { println!("Update modifiers: {modifiers:?}"); diff --git a/examples/themed_window.rs b/examples/themed_window.rs index 5be0f9453..3a59f3aa5 100644 --- a/examples/themed_window.rs +++ b/examples/themed_window.rs @@ -19,7 +19,7 @@ use smithay_client_toolkit::{ registry::{ProvidesRegistryState, RegistryState}, registry_handlers, seat::{ - keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers}, + keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers, RawModifiers}, pointer::{ CursorIcon, PointerData, PointerEvent, PointerEventKind, PointerHandler, ThemeSpec, ThemedPointer, @@ -483,6 +483,7 @@ impl KeyboardHandler for SimpleWindow { _: &wl_keyboard::WlKeyboard, _serial: u32, _: Modifiers, + _raw_modifiers: RawModifiers, _layout: u32, ) { } diff --git a/src/seat/keyboard/mod.rs b/src/seat/keyboard/mod.rs index f61a26b07..b35dfc0ff 100644 --- a/src/seat/keyboard/mod.rs +++ b/src/seat/keyboard/mod.rs @@ -181,6 +181,7 @@ pub trait KeyboardHandler: Sized { /// /// This happens when one of the modifier keys, such as "Shift", "Control" or "Alt" is pressed or /// released. + #[allow(clippy::too_many_arguments)] fn update_modifiers( &mut self, conn: &Connection, @@ -188,6 +189,7 @@ pub trait KeyboardHandler: Sized { keyboard: &wl_keyboard::WlKeyboard, serial: u32, modifiers: Modifiers, + raw_modifiers: RawModifiers, layout: u32, ); @@ -257,6 +259,14 @@ pub struct KeyEvent { pub utf8: Option, } +/// State of keyboard modifiers, in raw form sent by compositor. +#[derive(Debug, Clone, Copy, Default)] +pub struct RawModifiers { + pub depressed: u32, + pub latched: u32, + pub locked: u32, +} + /// The state of keyboard modifiers /// /// Each field of this indicates whether a specified modifier is active. @@ -830,9 +840,15 @@ where // Drop guard before calling user code. drop(guard); + let raw_modifiers = RawModifiers { + depressed: mods_depressed, + latched: mods_latched, + locked: mods_locked, + }; + // Always issue the modifiers update for the user. let modifiers = udata.update_modifiers(); - data.update_modifiers(conn, qh, keyboard, serial, modifiers, group); + data.update_modifiers(conn, qh, keyboard, serial, modifiers, raw_modifiers, group); } wl_keyboard::Event::RepeatInfo { rate, delay } => {