1
0
Fork 0
forked from wry/wry

config: allow configuring the pointer-revert-key

This commit is contained in:
Julian Orth 2025-05-09 16:39:44 +02:00
parent 7b62909bb4
commit 599f0a8ae5
12 changed files with 98 additions and 4 deletions

View file

@ -1736,6 +1736,10 @@ impl ConfigClient {
self.window_match_handlers.borrow_mut().remove(&matcher); 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]) { fn handle_msg(&self, msg: &[u8]) {
self.handle_msg2(msg); self.handle_msg2(msg);
self.dispatch_futures(); self.dispatch_futures();

View file

@ -706,6 +706,10 @@ pub enum ClientMessage<'a> {
matcher: WindowMatcher, matcher: WindowMatcher,
tile_state: TileState, tile_state: TileState,
}, },
SetPointerRevertKey {
seat: Seat,
key: KeySym,
},
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]

View file

@ -8,7 +8,7 @@ use {
_private::{DEFAULT_SEAT_NAME, ipc::WorkspaceSource}, _private::{DEFAULT_SEAT_NAME, ipc::WorkspaceSource},
Axis, Direction, ModifiedKeySym, Workspace, Axis, Direction, ModifiedKeySym, Workspace,
input::{acceleration::AccelProfile, capability::Capability}, input::{acceleration::AccelProfile, capability::Capability},
keyboard::{Keymap, mods::Modifiers}, keyboard::{Keymap, mods::Modifiers, syms::KeySym},
video::Connector, video::Connector,
window::Window, window::Window,
}, },
@ -493,6 +493,16 @@ impl Seat {
pub fn focus_window(self, window: Window) { pub fn focus_window(self, window: Window) {
get!().focus_window(self, 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. /// A focus-follows-mouse mode.

View file

@ -2091,6 +2091,10 @@ impl ConfigProxyHandler {
.set(matcher, (m, tile_state)); .set(matcher, (m, tile_state));
Ok(()) 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) { fn spaces_change(&self) {
struct V; struct V;
@ -2909,6 +2913,9 @@ impl ConfigProxyHandler {
} => self } => self
.handle_set_window_matcher_initial_tile_state(matcher, tile_state) .handle_set_window_matcher_initial_tile_state(matcher, tile_state)
.wrn("set_window_matcher_initial_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(()) Ok(())
} }

View file

@ -95,6 +95,7 @@ use {
wire_ei::EiSeatId, wire_ei::EiSeatId,
}, },
ahash::AHashMap, ahash::AHashMap,
jay_config::keyboard::syms::{KeySym, SYM_Escape},
smallvec::SmallVec, smallvec::SmallVec,
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
@ -215,6 +216,7 @@ pub struct WlSeatGlobal {
ui_drag_highlight: Cell<Option<Rect>>, ui_drag_highlight: Cell<Option<Rect>>,
keyboard_node_serial: Cell<u64>, keyboard_node_serial: Cell<u64>,
tray_popups: CopyHashMap<(TrayItemId, XdgPopupId), Rc<dyn DynTrayItem>>, tray_popups: CopyHashMap<(TrayItemId, XdgPopupId), Rc<dyn DynTrayItem>>,
revert_key: Cell<KeySym>,
} }
const CHANGE_CURSOR_MOVED: u32 = 1 << 0; const CHANGE_CURSOR_MOVED: u32 = 1 << 0;
@ -288,6 +290,7 @@ impl WlSeatGlobal {
ei_seats: Default::default(), ei_seats: Default::default(),
ui_drag_highlight: Default::default(), ui_drag_highlight: Default::default(),
tray_popups: Default::default(), tray_popups: Default::default(),
revert_key: Cell::new(SYM_Escape),
}); });
slf.pointer_cursor.set_owner(slf.clone()); slf.pointer_cursor.set_owner(slf.clone());
let seat = slf.clone(); let seat = slf.clone();
@ -1071,6 +1074,10 @@ impl WlSeatGlobal {
}; };
tl.tl_set_pinned(true, pinned); tl.tl_set_pinned(true, pinned);
} }
pub fn set_pointer_revert_key(&self, key: KeySym) {
self.revert_key.set(key);
}
} }
impl CursorUserOwner for WlSeatGlobal { impl CursorUserOwner for WlSeatGlobal {

View file

@ -50,7 +50,7 @@ use {
input::SwitchEvent, input::SwitchEvent,
keyboard::{ keyboard::{
mods::{CAPS, Modifiers, NUM, RELEASE}, mods::{CAPS, Modifiers, NUM, RELEASE},
syms::{KeySym, SYM_Escape}, syms::KeySym,
}, },
}, },
kbvm::{ModifierMask, state_machine::Event}, kbvm::{ModifierMask, state_machine::Event},
@ -836,7 +836,7 @@ impl WlSeatGlobal {
let mut revert_pointer_to_default = false; let mut revert_pointer_to_default = false;
for props in keysyms { for props in keysyms {
let sym = props.keysym().0; 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; revert_pointer_to_default = true;
} }
if !self.state.lock.locked.get() { if !self.state.lock.locked.get() {

View file

@ -23,7 +23,7 @@ use {
jay_config::{ jay_config::{
Axis, Direction, Workspace, Axis, Direction, Workspace,
input::{SwitchEvent, acceleration::AccelProfile}, input::{SwitchEvent, acceleration::AccelProfile},
keyboard::{Keymap, ModifiedKeySym, mods::Modifiers}, keyboard::{Keymap, ModifiedKeySym, mods::Modifiers, syms::KeySym},
logging::LogLevel, logging::LogLevel,
status::MessageFormat, status::MessageFormat,
theme::Color, theme::Color,
@ -478,6 +478,7 @@ pub struct Config {
pub max_action_depth: u64, pub max_action_depth: u64,
pub client_rules: Vec<ClientRule>, pub client_rules: Vec<ClientRule>,
pub window_rules: Vec<WindowRule>, pub window_rules: Vec<WindowRule>,
pub pointer_revert_key: Option<KeySym>,
} }
#[derive(Debug, Error)] #[derive(Debug, Error)]

View file

@ -4,6 +4,7 @@ use {
Action, Config, Libei, Theme, UiDrag, Action, Config, Libei, Theme, UiDrag,
context::Context, context::Context,
extractor::{Extractor, ExtractorError, arr, bol, int, opt, recover, str, val}, extractor::{Extractor, ExtractorError, arr, bol, int, opt, recover, str, val},
keysyms::KEYSYMS,
parser::{DataType, ParseResult, Parser, UnexpectedDataType}, parser::{DataType, ParseResult, Parser, UnexpectedDataType},
parsers::{ parsers::{
action::ActionParser, action::ActionParser,
@ -129,6 +130,7 @@ impl Parser for ConfigParser<'_> {
max_action_depth_val, max_action_depth_val,
client_rules_val, client_rules_val,
window_rules_val, window_rules_val,
pointer_revert_key_str,
), ),
) = ext.extract(( ) = ext.extract((
( (
@ -174,6 +176,7 @@ impl Parser for ConfigParser<'_> {
recover(opt(int("max-action-depth"))), recover(opt(int("max-action-depth"))),
opt(val("clients")), opt(val("clients")),
opt(val("windows")), opt(val("windows")),
recover(opt(str("pointer-revert-key"))),
), ),
))?; ))?;
let mut keymap = None; 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)), 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 { Ok(Config {
keymap, keymap,
repeat_rate, repeat_rate,
@ -480,6 +490,7 @@ impl Parser for ConfigParser<'_> {
max_action_depth, max_action_depth,
client_rules, client_rules,
window_rules, window_rules,
pointer_revert_key,
}) })
} }
} }

View file

@ -1235,6 +1235,9 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
set_show_float_pin_icon(show); 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 { fn create_command(exec: &Exec) -> Command {

View file

@ -866,6 +866,10 @@
"description": "", "description": "",
"$ref": "#/$defs/WindowRule" "$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": [] "required": []

View file

@ -1738,6 +1738,28 @@ The table has the following fields:
The value of this field should be an array of [WindowRules](#types-WindowRule). 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.
<a name="types-Connector"></a> <a name="types-Connector"></a>
### `Connector` ### `Connector`

View file

@ -2555,6 +2555,27 @@ Config:
match.title-regex = "Spotify" match.title-regex = "Spotify"
action = { type = "move-to-workspace", name = "music" } 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: Idle: