forge
Explore
Log in

Don't you dare go Hollow

Handle modifiers even when consumed by a11y

Browse files at this commit

f46338c18b77d9b4d1e0a30e8a29c84defc82a2dIvan MolodetskikhParent: 07c166b
This is apparently required: Orca expects us to keep track of modifiers
sent in KeyboardMonitor even during an Orca modifier key combo.
src/dbus/freedesktop_a11y.rsmodified+29 -7
@@ -44,6 +44,17 @@ pub struct KeyboardMonitor {
4444 iface: Arc<OnceLock<InterfaceRef<Self>>>,
4545 }
4646
47+/// Keyboard monitor key block reason.
48+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49+pub enum KbMonBlock {
50+ /// Not blocked.
51+ Pass,
52+ /// Blocked, and this is the first press/release of the a11y modifier.
53+ ModifierFirstPress,
54+ /// Blocked, and this is not the a11y modifier.
55+ Block,
56+}
57+
4758 /// Interface for monitoring of keyboard input by assistive technologies.
4859 ///
4960 /// This interface is used by assistive technologies to monitor keyboard input of the compositor.
@@ -211,7 +222,7 @@ impl KeyboardMonitor {
211222 mods: u32,
212223 keysym: Keysym,
213224 unichar: u32,
214- ) -> bool {
225+ ) -> KbMonBlock {
215226 let _span = tracy_client::span!("KeyboardMonitor::process_key");
216227
217228 let mut ctxt = self.iface.get().unwrap().signal_emitter().clone();
@@ -250,7 +261,7 @@ impl KeyboardMonitor {
250261 // second press that got handled normally.
251262 if !data.suppressed_keys.contains(&keysym) {
252263 trace!("handling release for second press of grabbed modifier: {keysym:?}");
253- return false;
264+ return KbMonBlock::Pass;
254265 }
255266 } else {
256267 let last_press_entry = data
@@ -263,7 +274,7 @@ impl KeyboardMonitor {
263274 // Modifier pressed twice; handle it as normal.
264275 if time <= last_press.saturating_add(repeat_delay) {
265276 trace!("handling second press of grabbed modifier: {keysym:?}");
266- return false;
277+ return KbMonBlock::Pass;
267278 }
268279 }
269280 }
@@ -293,7 +304,13 @@ impl KeyboardMonitor {
293304 }
294305 }
295306
296- block
307+ if !block {
308+ KbMonBlock::Pass
309+ } else if data.grabbed_mods.contains(&keysym) {
310+ KbMonBlock::ModifierFirstPress
311+ } else {
312+ KbMonBlock::Block
313+ }
297314 }
298315 }
299316
@@ -430,9 +447,14 @@ impl Start for KeyboardMonitor {
430447 }
431448
432449 impl State {
433- pub fn a11y_process_key(&mut self, time: Duration, keycode: Keycode, state: KeyState) -> bool {
450+ pub fn a11y_process_key(
451+ &mut self,
452+ time: Duration,
453+ keycode: Keycode,
454+ state: KeyState,
455+ ) -> KbMonBlock {
434456 if self.niri.a11y_keyboard_monitor.is_none() {
435- return false;
457+ return KbMonBlock::Pass;
436458 }
437459
438460 let keyboard = self.niri.seat.get_keyboard().unwrap();
@@ -454,7 +476,7 @@ impl State {
454476 let released = state == KeyState::Released;
455477
456478 let Some(monitor) = &self.niri.a11y_keyboard_monitor else {
457- return false;
479+ return KbMonBlock::Pass;
458480 };
459481 monitor.process_key(repeat_delay, time, keycode, released, mods, keysym, unichar)
460482 }
src/input/mod.rsmodified+28 -8
@@ -41,6 +41,8 @@ use touch_overview_grab::TouchOverviewGrab;
4141 use self::move_grab::MoveGrab;
4242 use self::resize_grab::ResizeGrab;
4343 use self::spatial_movement_grab::SpatialMovementGrab;
44+#[cfg(feature = "dbus")]
45+use crate::dbus::freedesktop_a11y::KbMonBlock;
4446 use crate::layout::scrolling::ScrollDirection;
4547 use crate::layout::{ActivateWindow, LayoutElement as _};
4648 use crate::niri::{CastTarget, PointerVisibility, State};
@@ -388,15 +390,26 @@ impl State {
388390
389391 // Accessibility modifier grabs should override XKB state changes (e.g. Caps Lock), so we
390392 // need to process them before keyboard.input() below.
393+ //
394+ // Other accessibility-grabbed keys should still update our XKB state, but not cause any
395+ // other changes.
391396 #[cfg(feature = "dbus")]
392- if self.a11y_process_key(
393- Duration::from_millis(u64::from(time)),
394- event.key_code(),
395- event.state(),
396- ) {
397- *consumed_by_a11y = true;
398- return;
399- }
397+ let block = {
398+ let block = self.a11y_process_key(
399+ Duration::from_millis(u64::from(time)),
400+ event.key_code(),
401+ event.state(),
402+ );
403+ if block != KbMonBlock::Pass {
404+ *consumed_by_a11y = true;
405+ }
406+ // The accessibility modifier first press must not change XKB state, so we return
407+ // early here.
408+ if block == KbMonBlock::ModifierFirstPress {
409+ return;
410+ }
411+ block
412+ };
400413
401414 let Some(Some(bind)) = self.niri.seat.get_keyboard().unwrap().input(
402415 self,
@@ -405,6 +418,13 @@ impl State {
405418 serial,
406419 time,
407420 |this, mods, keysym| {
421+ // After updating XKB state from accessibility-grabbed keys, return right away and
422+ // don't handle them.
423+ #[cfg(feature = "dbus")]
424+ if block != KbMonBlock::Pass {
425+ return FilterResult::Intercept(None);
426+ }
427+
408428 let key_code = event.key_code();
409429 let modified = keysym.modified_sym();
410430 let raw = keysym.raw_latin_sym_or_raw_current_sym();