From 599f0a8ae51d46eeb5f84102bee4e1628c768ce6 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Fri, 9 May 2025 16:39:44 +0200 Subject: [PATCH] config: allow configuring the pointer-revert-key --- jay-config/src/_private/client.rs | 4 ++++ jay-config/src/_private/ipc.rs | 4 ++++ jay-config/src/input.rs | 12 +++++++++++- src/config/handler.rs | 7 +++++++ src/ifs/wl_seat.rs | 7 +++++++ src/ifs/wl_seat/event_handling.rs | 4 ++-- toml-config/src/config.rs | 3 ++- toml-config/src/config/parsers/config.rs | 11 +++++++++++ toml-config/src/lib.rs | 3 +++ toml-spec/spec/spec.generated.json | 4 ++++ toml-spec/spec/spec.generated.md | 22 ++++++++++++++++++++++ toml-spec/spec/spec.yaml | 21 +++++++++++++++++++++ 12 files changed, 98 insertions(+), 4 deletions(-) diff --git a/jay-config/src/_private/client.rs b/jay-config/src/_private/client.rs index e03ec7fb..2adc6875 100644 --- a/jay-config/src/_private/client.rs +++ b/jay-config/src/_private/client.rs @@ -1736,6 +1736,10 @@ impl ConfigClient { self.window_match_handlers.borrow_mut().remove(&matcher); } + pub fn set_pointer_revert_key(&self, seat: Seat, key: KeySym) { + self.send(&ClientMessage::SetPointerRevertKey { seat, key }); + } + fn handle_msg(&self, msg: &[u8]) { self.handle_msg2(msg); self.dispatch_futures(); diff --git a/jay-config/src/_private/ipc.rs b/jay-config/src/_private/ipc.rs index 6aa10326..681ee4b7 100644 --- a/jay-config/src/_private/ipc.rs +++ b/jay-config/src/_private/ipc.rs @@ -706,6 +706,10 @@ pub enum ClientMessage<'a> { matcher: WindowMatcher, tile_state: TileState, }, + SetPointerRevertKey { + seat: Seat, + key: KeySym, + }, } #[derive(Serialize, Deserialize, Debug)] diff --git a/jay-config/src/input.rs b/jay-config/src/input.rs index 0a6045dc..c80b6dcd 100644 --- a/jay-config/src/input.rs +++ b/jay-config/src/input.rs @@ -8,7 +8,7 @@ use { _private::{DEFAULT_SEAT_NAME, ipc::WorkspaceSource}, Axis, Direction, ModifiedKeySym, Workspace, input::{acceleration::AccelProfile, capability::Capability}, - keyboard::{Keymap, mods::Modifiers}, + keyboard::{Keymap, mods::Modifiers, syms::KeySym}, video::Connector, window::Window, }, @@ -493,6 +493,16 @@ impl Seat { pub fn focus_window(self, window: Window) { get!().focus_window(self, window) } + + /// Sets the key that can be used to revert the pointer to the default state. + /// + /// Pressing this key cancels any grabs, drags, selections, etc. + /// + /// The default is `SYM_Escape`. Setting this to `SYM_NoSymbol` effectively disables + /// this functionality. + pub fn set_pointer_revert_key(self, sym: KeySym) { + get!().set_pointer_revert_key(self, sym); + } } /// A focus-follows-mouse mode. diff --git a/src/config/handler.rs b/src/config/handler.rs index 9f693fe6..069cf35e 100644 --- a/src/config/handler.rs +++ b/src/config/handler.rs @@ -2091,6 +2091,10 @@ impl ConfigProxyHandler { .set(matcher, (m, tile_state)); Ok(()) } + fn handle_set_pointer_revert_key(&self, seat: Seat, key: KeySym) -> Result<(), CphError> { + self.get_seat(seat)?.set_pointer_revert_key(key); + Ok(()) + } fn spaces_change(&self) { struct V; @@ -2909,6 +2913,9 @@ impl ConfigProxyHandler { } => self .handle_set_window_matcher_initial_tile_state(matcher, tile_state) .wrn("set_window_matcher_initial_tile_state")?, + ClientMessage::SetPointerRevertKey { seat, key } => self + .handle_set_pointer_revert_key(seat, key) + .wrn("set_pointer_revert_key")?, } Ok(()) } diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index f9fffa7a..43491d6b 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -95,6 +95,7 @@ use { wire_ei::EiSeatId, }, ahash::AHashMap, + jay_config::keyboard::syms::{KeySym, SYM_Escape}, smallvec::SmallVec, std::{ cell::{Cell, RefCell}, @@ -215,6 +216,7 @@ pub struct WlSeatGlobal { ui_drag_highlight: Cell>, keyboard_node_serial: Cell, tray_popups: CopyHashMap<(TrayItemId, XdgPopupId), Rc>, + revert_key: Cell, } const CHANGE_CURSOR_MOVED: u32 = 1 << 0; @@ -288,6 +290,7 @@ impl WlSeatGlobal { ei_seats: Default::default(), ui_drag_highlight: Default::default(), tray_popups: Default::default(), + revert_key: Cell::new(SYM_Escape), }); slf.pointer_cursor.set_owner(slf.clone()); let seat = slf.clone(); @@ -1071,6 +1074,10 @@ impl WlSeatGlobal { }; tl.tl_set_pinned(true, pinned); } + + pub fn set_pointer_revert_key(&self, key: KeySym) { + self.revert_key.set(key); + } } impl CursorUserOwner for WlSeatGlobal { diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 956dbad8..27f292f9 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -50,7 +50,7 @@ use { input::SwitchEvent, keyboard::{ mods::{CAPS, Modifiers, NUM, RELEASE}, - syms::{KeySym, SYM_Escape}, + syms::KeySym, }, }, kbvm::{ModifierMask, state_machine::Event}, @@ -836,7 +836,7 @@ impl WlSeatGlobal { let mut revert_pointer_to_default = false; for props in keysyms { let sym = props.keysym().0; - if sym == SYM_Escape.0 && mods == 0 { + if sym == self.revert_key.get().0 && mods == 0 { revert_pointer_to_default = true; } if !self.state.lock.locked.get() { diff --git a/toml-config/src/config.rs b/toml-config/src/config.rs index 06bf1873..192cae7b 100644 --- a/toml-config/src/config.rs +++ b/toml-config/src/config.rs @@ -23,7 +23,7 @@ use { jay_config::{ Axis, Direction, Workspace, input::{SwitchEvent, acceleration::AccelProfile}, - keyboard::{Keymap, ModifiedKeySym, mods::Modifiers}, + keyboard::{Keymap, ModifiedKeySym, mods::Modifiers, syms::KeySym}, logging::LogLevel, status::MessageFormat, theme::Color, @@ -478,6 +478,7 @@ pub struct Config { pub max_action_depth: u64, pub client_rules: Vec, pub window_rules: Vec, + pub pointer_revert_key: Option, } #[derive(Debug, Error)] diff --git a/toml-config/src/config/parsers/config.rs b/toml-config/src/config/parsers/config.rs index f93723c7..2a1e2ac2 100644 --- a/toml-config/src/config/parsers/config.rs +++ b/toml-config/src/config/parsers/config.rs @@ -4,6 +4,7 @@ use { Action, Config, Libei, Theme, UiDrag, context::Context, extractor::{Extractor, ExtractorError, arr, bol, int, opt, recover, str, val}, + keysyms::KEYSYMS, parser::{DataType, ParseResult, Parser, UnexpectedDataType}, parsers::{ action::ActionParser, @@ -129,6 +130,7 @@ impl Parser for ConfigParser<'_> { max_action_depth_val, client_rules_val, window_rules_val, + pointer_revert_key_str, ), ) = ext.extract(( ( @@ -174,6 +176,7 @@ impl Parser for ConfigParser<'_> { recover(opt(int("max-action-depth"))), opt(val("clients")), opt(val("windows")), + recover(opt(str("pointer-revert-key"))), ), ))?; let mut keymap = None; @@ -444,6 +447,13 @@ impl Parser for ConfigParser<'_> { Err(e) => log::warn!("Could not parse the window rules: {}", self.0.error(e)), } } + let mut pointer_revert_key = None; + if let Some(value) = pointer_revert_key_str { + match KEYSYMS.get(value.value) { + Some(s) => pointer_revert_key = Some(*s), + None => log::warn!("Unknown keysym: {}", self.0.error3(value.span)), + } + } Ok(Config { keymap, repeat_rate, @@ -480,6 +490,7 @@ impl Parser for ConfigParser<'_> { max_action_depth, client_rules, window_rules, + pointer_revert_key, }) } } diff --git a/toml-config/src/lib.rs b/toml-config/src/lib.rs index b70cb692..af42da4f 100644 --- a/toml-config/src/lib.rs +++ b/toml-config/src/lib.rs @@ -1235,6 +1235,9 @@ fn load_config(initial_load: bool, persistent: &Rc) { set_show_float_pin_icon(show); } } + if let Some(key) = config.pointer_revert_key { + persistent.seat.set_pointer_revert_key(key); + } } fn create_command(exec: &Exec) -> Command { diff --git a/toml-spec/spec/spec.generated.json b/toml-spec/spec/spec.generated.json index d2c1b491..92c92194 100644 --- a/toml-spec/spec/spec.generated.json +++ b/toml-spec/spec/spec.generated.json @@ -866,6 +866,10 @@ "description": "", "$ref": "#/$defs/WindowRule" } + }, + "pointer-revert-key": { + "type": "string", + "description": "Sets the keysym that can be used to revert the pointer to the default state.\n\nPressing this key cancels any grabs, drags, selections, etc.\n\nThe default is `Escape`. Setting this to `NoSymbol` effectively disables\nthis functionality.\n\nThe value of the string should be the name of a keysym. The authoritative location\nfor these names is [1] with the `XKB_KEY_` prefix removed.\n\n[1]: https://github.com/xkbcommon/libxkbcommon/blob/master/include/xkbcommon/xkbcommon-keysyms.h\n\n- Example:\n\n ```toml\n pointer-revert-key = \"NoSymbol\"\n ```\n" } }, "required": [] diff --git a/toml-spec/spec/spec.generated.md b/toml-spec/spec/spec.generated.md index 96e76355..1ca471be 100644 --- a/toml-spec/spec/spec.generated.md +++ b/toml-spec/spec/spec.generated.md @@ -1738,6 +1738,28 @@ The table has the following fields: The value of this field should be an array of [WindowRules](#types-WindowRule). +- `pointer-revert-key` (optional): + + Sets the keysym that can be used to revert the pointer to the default state. + + Pressing this key cancels any grabs, drags, selections, etc. + + The default is `Escape`. Setting this to `NoSymbol` effectively disables + this functionality. + + The value of the string should be the name of a keysym. The authoritative location + for these names is [1] with the `XKB_KEY_` prefix removed. + + [1]: https://github.com/xkbcommon/libxkbcommon/blob/master/include/xkbcommon/xkbcommon-keysyms.h + + - Example: + + ```toml + pointer-revert-key = "NoSymbol" + ``` + + The value of this field should be a string. + ### `Connector` diff --git a/toml-spec/spec/spec.yaml b/toml-spec/spec/spec.yaml index 5e2055d6..2d49ef38 100644 --- a/toml-spec/spec/spec.yaml +++ b/toml-spec/spec/spec.yaml @@ -2555,6 +2555,27 @@ Config: match.title-regex = "Spotify" action = { type = "move-to-workspace", name = "music" } ``` + pointer-revert-key: + kind: string + required: false + description: | + Sets the keysym that can be used to revert the pointer to the default state. + + Pressing this key cancels any grabs, drags, selections, etc. + + The default is `Escape`. Setting this to `NoSymbol` effectively disables + this functionality. + + The value of the string should be the name of a keysym. The authoritative location + for these names is [1] with the `XKB_KEY_` prefix removed. + + [1]: https://github.com/xkbcommon/libxkbcommon/blob/master/include/xkbcommon/xkbcommon-keysyms.h + + - Example: + + ```toml + pointer-revert-key = "NoSymbol" + ``` Idle: