From a8b401b11df3b05336358f1bc7b4ee06f9ef53b5 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 13 Dec 2023 16:36:49 +0000 Subject: [PATCH] input: Only capture `Escape`, if a grab is active --- src/config/key_bindings.rs | 7 ------- src/input/mod.rs | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/config/key_bindings.rs b/src/config/key_bindings.rs index 68f644d1..f4fd85bc 100644 --- a/src/config/key_bindings.rs +++ b/src/config/key_bindings.rs @@ -319,11 +319,4 @@ pub fn add_default_bindings( output_next.iter().copied(), Action::MoveToOutput(output_next_dir), ); - - insert_binding( - key_bindings, - KeyModifiers::default(), - std::iter::once(Keysym::Escape), - Action::Escape, - ); } diff --git a/src/input/mod.rs b/src/input/mod.rs index 8d847c5b..0764b8ce 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -2,7 +2,7 @@ use crate::{ backend::render::cursor::CursorState, - config::{xkb_config_to_wl, Action, Config, KeyPattern}, + config::{xkb_config_to_wl, Action, Config, KeyPattern, KeyModifiers}, shell::{ focus::{target::PointerFocusTarget, FocusDirection}, grabs::{ResizeEdge, SeatMenuGrabState, SeatMoveGrabState}, @@ -282,6 +282,8 @@ impl State { let serial = SERIAL_COUNTER.next_serial(); let time = Event::time_msec(&event); let keyboard = seat.get_keyboard().unwrap(); + let pointer = seat.get_pointer().unwrap(); + let is_grabbed = keyboard.is_grabbed() || pointer.is_grabbed(); let current_focus = keyboard.current_focus(); if let Some((action, pattern)) = keyboard .input( @@ -452,6 +454,28 @@ impl State { } } + // cancel grabs + if is_grabbed + && handle.modified_sym() == Keysym::Escape + && state == KeyState::Pressed + && !modifiers.alt + && !modifiers.ctrl + && !modifiers.logo + && !modifiers.shift + { + userdata + .get::() + .unwrap() + .add(&handle, None); + return FilterResult::Intercept(Some(( + Action::Escape, + KeyPattern { + modifiers: KeyModifiers::default(), + key: Some(Keysym::Escape), + } + ))); + } + // Skip released events for initially surpressed keys if state == KeyState::Released { if let Some(tokens) = userdata.get::().unwrap().filter(&handle) {