Skip to content

Commit

Permalink
Add a raw_modifiers argument to update_modifiers
Browse files Browse the repository at this point in the history
This can be used for things like nested compositors, that want to
propagate the modifier state as expressed by the compositor.
  • Loading branch information
ids1024 committed Nov 22, 2024
1 parent 618a876 commit 45963e8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/data_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -461,6 +461,7 @@ impl KeyboardHandler for DataDeviceWindow {
_: &wl_keyboard::WlKeyboard,
_serial: u32,
modifiers: Modifiers,
_raw_modifiers: RawModifiers,
_layout: u32,
) {
self.modifiers = modifiers;
Expand Down
3 changes: 2 additions & 1 deletion examples/generic_simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -349,6 +349,7 @@ impl<T: Test + 'static> KeyboardHandler for SimpleWindow<T> {
_: &wl_keyboard::WlKeyboard,
_serial: u32,
modifiers: Modifiers,
_raw_modifiers: RawModifiers,
_layout: u32,
) {
println!("Update modifiers: {modifiers:?}");
Expand Down
3 changes: 2 additions & 1 deletion examples/simple_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -344,6 +344,7 @@ impl KeyboardHandler for SimpleLayer {
_: &wl_keyboard::WlKeyboard,
_serial: u32,
modifiers: Modifiers,
_raw_modifiers: RawModifiers,
_layout: u32,
) {
println!("Update modifiers: {modifiers:?}");
Expand Down
3 changes: 2 additions & 1 deletion examples/simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -388,6 +388,7 @@ impl KeyboardHandler for SimpleWindow {
_: &wl_keyboard::WlKeyboard,
_serial: u32,
modifiers: Modifiers,
_raw_modifiers: RawModifiers,
_layout: u32,
) {
println!("Update modifiers: {modifiers:?}");
Expand Down
3 changes: 2 additions & 1 deletion examples/themed_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -483,6 +483,7 @@ impl KeyboardHandler for SimpleWindow {
_: &wl_keyboard::WlKeyboard,
_serial: u32,
_: Modifiers,
_raw_modifiers: RawModifiers,
_layout: u32,
) {
}
Expand Down
17 changes: 16 additions & 1 deletion src/seat/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub trait KeyboardHandler: Sized {
keyboard: &wl_keyboard::WlKeyboard,
serial: u32,
modifiers: Modifiers,
raw_modifiers: RawModifiers,
layout: u32,
);

Expand Down Expand Up @@ -257,6 +258,14 @@ pub struct KeyEvent {
pub utf8: Option<String>,
}

/// 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.
Expand Down Expand Up @@ -830,9 +839,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 } => {
Expand Down

0 comments on commit 45963e8

Please sign in to comment.