From 011c91c98a76880744d35afa763c20db074d9c90 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 18 Jan 2024 19:20:46 +0400 Subject: Add an important hotkeys overlay --- src/input.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index 293bda93..595be712 100644 --- a/src/input.rs +++ b/src/input.rs @@ -54,6 +54,9 @@ impl State { self.niri.activate_monitors(&self.backend); } + let hide_hotkey_overlay = + self.niri.hotkey_overlay.is_open() && should_hide_hotkey_overlay(&event); + use InputEvent::*; match event { DeviceAdded { device } => self.on_device_added(device), @@ -82,6 +85,12 @@ impl State { TouchFrame { .. } => (), Special(_) => (), } + + // Do this last so that screenshot still gets it. + // FIXME: do this in a less cursed fashion somehow. + if hide_hotkey_overlay && self.niri.hotkey_overlay.hide() { + self.niri.queue_redraw_all(); + } } pub fn process_libinput_event(&mut self, event: &mut InputEvent) { @@ -557,6 +566,11 @@ impl State { Action::SetWindowHeight(change) => { self.niri.layout.set_window_height(change); } + Action::ShowHotkeyOverlay => { + if self.niri.hotkey_overlay.show() { + self.niri.queue_redraw_all(); + } + } } } @@ -1372,6 +1386,21 @@ fn should_activate_monitors(event: &InputEvent) -> bool { } } +fn should_hide_hotkey_overlay(event: &InputEvent) -> bool { + match event { + InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true, + InputEvent::PointerButton { .. } + | InputEvent::PointerAxis { .. } + | InputEvent::GestureSwipeBegin { .. } + | InputEvent::GesturePinchBegin { .. } + | InputEvent::TouchDown { .. } + | InputEvent::TouchMotion { .. } + | InputEvent::TabletToolTip { .. } + | InputEvent::TabletToolButton { .. } => true, + _ => false, + } +} + fn allowed_when_locked(action: &Action) -> bool { matches!( action, -- cgit