1
0
Fork 0
forked from wry/wry

Merge pull request #460 from mahkoh/jorth/release-on-revert

config: allow configuring the pointer-revert-key
This commit is contained in:
mahkoh 2025-05-09 16:41:54 +02:00 committed by GitHub
commit e0e336bc69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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);
}
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();

View file

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

View file

@ -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.

View file

@ -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(())
}

View file

@ -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<Option<Rect>>,
keyboard_node_serial: Cell<u64>,
tray_popups: CopyHashMap<(TrayItemId, XdgPopupId), Rc<dyn DynTrayItem>>,
revert_key: Cell<KeySym>,
}
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 {

View file

@ -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() {

View file

@ -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<ClientRule>,
pub window_rules: Vec<WindowRule>,
pub pointer_revert_key: Option<KeySym>,
}
#[derive(Debug, Error)]

View file

@ -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,
})
}
}

View file

@ -1235,6 +1235,9 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
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 {

View file

@ -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": []

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).
- `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>
### `Connector`

View file

@ -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: