1
0
Fork 0
forked from wry/wry

config: add support for mod masks in shortcuts

This commit is contained in:
Julian Orth 2024-04-16 16:27:26 +02:00
parent 27f30f8d28
commit 90dbde99ab
15 changed files with 501 additions and 92 deletions

View file

@ -1127,11 +1127,12 @@ impl ConfigProxyHandler {
fn handle_add_shortcut(
&self,
seat: Seat,
mod_mask: Modifiers,
mods: Modifiers,
sym: KeySym,
) -> Result<(), CphError> {
let seat = self.get_seat(seat)?;
seat.add_shortcut(mods, sym);
seat.add_shortcut(mod_mask, mods, sym);
Ok(())
}
@ -1499,7 +1500,7 @@ impl ConfigProxyHandler {
self.handle_set_split(seat, axis).wrn("set_split")?
}
ClientMessage::AddShortcut { seat, mods, sym } => self
.handle_add_shortcut(seat, mods, sym)
.handle_add_shortcut(seat, Modifiers(!0), mods, sym)
.wrn("add_shortcut")?,
ClientMessage::RemoveShortcut { seat, mods, sym } => self
.handle_remove_shortcut(seat, mods, sym)
@ -1773,6 +1774,14 @@ impl ConfigProxyHandler {
ClientMessage::SetForward { seat, forward } => {
self.handle_set_forward(seat, forward).wrn("set_forward")?
}
ClientMessage::AddShortcut2 {
seat,
mod_mask,
mods,
sym,
} => self
.handle_add_shortcut(seat, mod_mask, mods, sym)
.wrn("add_shortcut")?,
}
Ok(())
}

View file

@ -73,7 +73,6 @@ use {
xkbcommon::{DynKeyboardState, KeyboardState, KeymapId, XkbKeymap, XkbState},
},
ahash::AHashMap,
jay_config::keyboard::mods::Modifiers,
smallvec::SmallVec,
std::{
cell::{Cell, RefCell},
@ -160,7 +159,7 @@ pub struct WlSeatGlobal {
pointer_owner: PointerOwnerHolder,
kb_owner: KbOwnerHolder,
dropped_dnd: RefCell<Option<DroppedDnd>>,
shortcuts: CopyHashMap<(u32, u32), Modifiers>,
shortcuts: RefCell<AHashMap<u32, SmallMap<u32, u32, 2>>>,
queue_link: Cell<Option<LinkedNode<Rc<Self>>>>,
tree_changed_handler: Cell<Option<SpawnedFuture<()>>>,
output: CloneCell<Rc<OutputNode>>,

View file

@ -42,7 +42,7 @@ use {
ModifiedKeySym,
},
smallvec::SmallVec,
std::{cell::RefCell, rc::Rc},
std::{cell::RefCell, collections::hash_map::Entry, rc::Rc},
};
#[derive(Default)]
@ -380,13 +380,18 @@ impl WlSeatGlobal {
if state == wl_keyboard::RELEASED {
mods |= RELEASE.0;
}
let scs = &*self.shortcuts.borrow();
let keysyms = xkb_state.unmodified_keysyms(key);
for &sym in keysyms {
if let Some(mods) = self.shortcuts.get(&(mods, sym)) {
shortcuts.push(ModifiedKeySym {
mods,
sym: KeySym(sym),
});
if let Some(key_mods) = scs.get(&sym) {
for (key_mods, mask) in key_mods {
if mods & mask == key_mods {
shortcuts.push(ModifiedKeySym {
mods: Modifiers(key_mods),
sym: KeySym(sym),
});
}
}
}
}
}
@ -608,15 +613,24 @@ impl WlSeatGlobal {
}
pub fn clear_shortcuts(&self) {
self.shortcuts.clear();
self.shortcuts.borrow_mut().clear();
}
pub fn add_shortcut(&self, mods: Modifiers, keysym: KeySym) {
self.shortcuts.set((mods.0, keysym.0), mods);
pub fn add_shortcut(&self, mod_mask: Modifiers, mods: Modifiers, keysym: KeySym) {
self.shortcuts
.borrow_mut()
.entry(keysym.0)
.or_default()
.insert(mods.0, mod_mask.0);
}
pub fn remove_shortcut(&self, mods: Modifiers, keysym: KeySym) {
self.shortcuts.remove(&(mods.0, keysym.0));
if let Entry::Occupied(mut oe) = self.shortcuts.borrow_mut().entry(keysym.0) {
oe.get_mut().remove(&mods.0);
if oe.get().is_empty() {
oe.remove();
}
}
}
pub fn trigger_tree_changed(&self) {