- One shortcut table (compositor/shell/shortcuts.mbt): named actions with their default combos,
the same as before: Super tap launcher, Super+D, Alt+Tab, Super+Shift+S, Super+Shift+Print,
Print, Super+Print, Super+Ctrl+Print, Super+Shift+R, Super+Alt+R, Super+Ctrl+R. Combos are
"Super+Ctrl+Alt+Shift+Key" text (parse/print, aliases like Meta, PrtSc, Return); "Super" alone
is a Super tap. Two shortcuts on one combo conflict and the one listed first wins.
- The compositor looks every non-modifier key press up in the table (compositor/host/
shortcuts.mbt) instead of the hardcoded checks in showdesktop/screenshot/recorder; the switcher
reads its combo from it (hold the combo's modifiers, its key steps, Shift reverses, releasing a
held modifier switches). Matching is now exact on Super/Ctrl/Alt/Shift (caps/num lock ignored),
so e.g. Super+Shift+D or Ctrl+Print no longer fire Super+D / Print.
- Settings gets a fifth tab, Shortcuts (key 5, SettingsTab::Shortcuts): every shortcut and its
combo. Click a row (or Enter) and press the new keys: the compositor captures the combo before
anything else sees it (Escape cancels, Backspace unbinds, a Super tap binds "Super"; window
switching keeps waiting until the combo has a modifier). Changed rows get a Reset button
(Backspace/Delete on the highlighted row too), plus "Reset all to defaults"; conflicting combos
show in red with a line saying which shortcut wins. The popup is 360 px wide for the fifth tab.
- New `shortcuts` capability (shortcuts, capture, cancel-capture, reset, reset-all), served from
host table 10 and request 18 by the wasmer/wasmtime stub, host-wasm and the MoonBit wasmhost
(chandra:host/plasmoids `shortcut(s32)`).
- Changes are kept in state.edn as :shortcuts {:show-desktop "Super+Ctrl+D" ...} (only the ones
that differ; "" unbinds), applied at startup and live.
- There were no window-management or tiling key shortcuts to move into the table.
- Tests: combo parsing/printing, defaults, conflicts, switcher constraint, save/restore pairs,
rebinding through the compositor, capture (Escape/Backspace/Super tap), the Shortcuts tab
(capture, conflict line, Reset, Reset all) and the state.edn round trip.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjypNwGHE9WeFvnWLA
This commit is contained in:
30 files changed
+1304
-149
No files matched your search
@@ -0,0 +1,124 @@
|
||||
///| Keyboard shortcuts: the compositor's end of the shortcut table (compositor/shell/shortcuts.mbt).
|
||||
///
|
||||
/// Every key press that isn't a modifier is looked up as a combo (the held modifiers plus the key)
|
||||
/// and, when a shortcut has it, runs that shortcut's action instead of reaching a client; its
|
||||
/// release is swallowed too. A Super tap (Super pressed and let go alone) runs the shortcut bound to
|
||||
/// "Super", the launcher by default. Window switching is driven from switcher.mbt, which reads its
|
||||
/// combo from the same table. While the settings module's Shortcuts tab waits for a new combo
|
||||
/// (`shell.shortcut_capturing()`), the next combo pressed is taken for it here and does nothing else.
|
||||
|
||||
///| The modifiers held now, as combo bits. The Super and Alt keys are tracked from their own key
|
||||
/// events as well, as the nested host doesn't always report them in the modifier mask.
|
||||
pub fn ChandraCompositor::held_mods(self : ChandraCompositor) -> UInt {
|
||||
let mut m = self.mods & @shell.combo_mods
|
||||
if self.super_down {
|
||||
m = m | @shell.mod_logo
|
||||
}
|
||||
if self.alt_down {
|
||||
m = m | @shell.mod_alt
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
///| Keep track of the Super and Alt keys (for combos and the Super tap).
|
||||
fn ChandraCompositor::track_modifier_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Unit {
|
||||
if code == key_lsuper || code == key_rsuper {
|
||||
self.super_down = pressed
|
||||
} else if code == key_lalt || code == key_ralt {
|
||||
self.alt_down = pressed
|
||||
}
|
||||
}
|
||||
|
||||
///| While the Shortcuts tab waits for a combo: take the next one for it. Escape cancels, Backspace
|
||||
/// unbinds; a Super tap binds "Super". True when the key was used (it goes nowhere else).
|
||||
fn ChandraCompositor::capture_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool {
|
||||
let shell = self.shell
|
||||
if shell.shortcut_capturing() < 0 {
|
||||
// The release of a key the capture took.
|
||||
if !pressed && self.capture_swallow.contains(code) {
|
||||
self.capture_swallow.retain(c => c != code)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
self.super_solo = false
|
||||
if code == key_lsuper || code == key_rsuper {
|
||||
if pressed {
|
||||
self.capture_super = true
|
||||
} else if self.capture_super {
|
||||
self.capture_super = false
|
||||
ignore(shell.finish_shortcut_capture(Some({ mods: 0U, key: @shell.key_super })))
|
||||
}
|
||||
return true // Super never reaches clients
|
||||
}
|
||||
if @shell.is_modifier_key(code) {
|
||||
return false // other modifiers pass, so clients keep their state right
|
||||
}
|
||||
self.capture_super = false
|
||||
if !pressed {
|
||||
return true
|
||||
}
|
||||
self.capture_swallow.push(code)
|
||||
let mods = self.held_mods()
|
||||
if mods == 0U && code == key_esc {
|
||||
shell.cancel_shortcut_capture()
|
||||
} else if mods == 0U && code == key_backspace {
|
||||
ignore(shell.finish_shortcut_capture(None))
|
||||
} else {
|
||||
ignore(shell.finish_shortcut_capture(Some({ mods, key: code })))
|
||||
}
|
||||
self.damage.mark_full()
|
||||
true
|
||||
}
|
||||
|
||||
///| A key for the shortcut table: runs the action bound to the combo it makes with the held
|
||||
/// modifiers. True when the key was used (neither it nor its release reaches a client).
|
||||
fn ChandraCompositor::shortcut_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool {
|
||||
if !pressed {
|
||||
if self.sc_swallow.contains(code) {
|
||||
self.sc_swallow.retain(c => c != code)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
if @shell.is_modifier_key(code) || self.shell.inspecting() {
|
||||
return false
|
||||
}
|
||||
match self.shell.shortcuts.lookup({ mods: self.held_mods(), key: code }) {
|
||||
// Window switching is the switcher's (switcher_key runs before this).
|
||||
None | Some(SwitchWindows) => false
|
||||
Some(action) => {
|
||||
self.sc_swallow.push(code)
|
||||
self.run_shortcut(action)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| A Super tap: the shortcut bound to "Super" (the launcher by default), if any.
|
||||
fn ChandraCompositor::super_tap(self : ChandraCompositor) -> Unit {
|
||||
match self.shell.shortcuts.lookup({ mods: 0U, key: @shell.key_super }) {
|
||||
None | Some(SwitchWindows) => ()
|
||||
Some(action) => self.run_shortcut(action)
|
||||
}
|
||||
}
|
||||
|
||||
///| Do what a shortcut stands for.
|
||||
pub fn ChandraCompositor::run_shortcut(self : ChandraCompositor, action : @shell.ShortcutAction) -> Unit {
|
||||
self.super_solo = false
|
||||
match action {
|
||||
Launcher => if !self.shell.inspecting() { self.shell.toggle_launcher() }
|
||||
ShowDesktop => self.toggle_show_desktop()
|
||||
SwitchWindows => ()
|
||||
ShotRegion => self.take_screenshot(ShotMode::Region)
|
||||
ShotFull => self.take_screenshot(ShotMode::FullScreen)
|
||||
ShotActiveWindow => self.take_screenshot(ShotMode::ActiveWindow)
|
||||
ShotWindowUnderCursor => self.take_screenshot(ShotMode::WindowUnderCursor)
|
||||
RecordRegion => self.toggle_recording(ShotMode::Region)
|
||||
RecordScreen => self.toggle_recording(ShotMode::FullScreen)
|
||||
RecordWindow => self.toggle_recording(ShotMode::WindowUnderCursor)
|
||||
}
|
||||
}
|
||||
|
||||
///| evdev code of Backspace (unbinds while capturing).
|
||||
let key_backspace : UInt = 14
|
||||
Reference in new issue
Block a user