Settings > Shortcuts: rebind the compositor's keyboard shortcuts
CI / test (push) Failing after 18s

- 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:
Claude committed 2026-11-25 20:41:22 +00:00
1 parent 8ecdef17d4
commit 34885bfdda
30 files changed
+1304 -149

No files matched your search

+27 -10
View File
@@ -71,12 +71,19 @@ pub(all) struct ChandraCompositor {
mut press_fwd : Bool
mut kbd_win : UInt64?
mut mods : UInt
/// A Super key is down and nothing else was pressed since: releasing it opens the launcher.
/// A Super key is down and nothing else was pressed since: releasing it is a Super tap (the
/// launcher by default; shortcuts.mbt).
mut super_solo : Bool
/// Super+D (showdesktop.mbt): whether a Super key is held, whether the D press was swallowed,
/// and the windows it minimized (bottom to top) so a second Super+D can restore them.
/// Whether a Super key is held (shortcuts.mbt).
mut super_down : Bool
mut d_swallowed : Bool
/// Keys a shortcut used, whose release must not reach a client either (shortcuts.mbt).
sc_swallow : Array[UInt]
/// While the Shortcuts tab waits for a combo: keys it took (their releases are swallowed) and
/// whether Super is down alone (a Super tap binds "Super").
capture_swallow : Array[UInt]
mut capture_super : Bool
/// Show desktop (showdesktop.mbt): the windows it minimized (bottom to top) so doing it again
/// can restore them.
mut desktop_hidden : Array[UInt64]
mut layout_mode : @wm.LayoutMode
/// Set when the user asked to end the session (the logout button); the main loop then exits.
@@ -187,7 +194,9 @@ pub fn ChandraCompositor::new(
mods: 0U,
super_solo: false,
super_down: false,
d_swallowed: false,
sc_swallow: [],
capture_swallow: [],
capture_super: false,
desktop_hidden: [],
layout_mode: @wm.LayoutMode::Tiling,
quit_requested: false,
@@ -1260,6 +1269,15 @@ pub fn ChandraCompositor::handle_input(
time_ms : UInt,
) -> Unit {
self.note_activity(@sys.monotonic_ms())
match ev {
Key(code, pressed) => {
self.track_modifier_key(code, pressed)
if self.capture_key(code, pressed) {
return
}
}
_ => ()
}
if self.screenshot_input(ev, time_ms) {
return
}
@@ -1498,17 +1516,16 @@ pub fn ChandraCompositor::handle_input(
Key(code, pressed) =>
if self.switcher_key(code, pressed, time_ms) {
self.super_solo = false
} else if self.show_desktop_key(code, pressed) {
} else if self.shortcut_key(code, pressed) {
self.super_solo = false
} else if code == 125U || code == 126U {
// Super (left/right): a bare tap toggles the launcher search; never reaches clients.
// Super (left/right): a bare tap runs the shortcut bound to "Super" (the launcher by
// default); Super never reaches clients.
if pressed {
self.super_solo = true
} else if self.super_solo {
self.super_solo = false
if !self.shell.inspecting() {
self.shell.toggle_launcher()
}
self.super_tap()
}
} else if self.shell.inspecting() {
self.super_solo = false
+1 -7
View File
@@ -1,6 +1,6 @@
///| Screen recording, after Spectacle's recording modes.
///
/// Super+Shift+R puts the selection overlay up to pick a region to record (drag a rectangle or
/// Super+Shift+R (by default; the shortcut table can rebind it) puts the selection overlay up to pick a region to record (drag a rectangle or
/// click a window, Enter starts); Super+Alt+R records the whole screen; Super+Ctrl+R the window
/// under the pointer. While recording, a red "REC" pill with the elapsed time sits at the top
/// centre; clicking it, or any of the recording shortcuts again, stops. The pointer is drawn into
@@ -13,12 +13,6 @@
/// ffmpeg hasn't taken yet when the next one is due makes that next one wait (it is skipped).
/// Without ffmpeg on PATH a notification says so.
///| evdev code of R.
let key_r : UInt = 19
///| xkb Alt bit.
let mod_alt : UInt = 8
///| A recording in progress.
pub(all) struct Recording {
/// The part of the screen recorded (even width and height, as H.264 wants).
+7 -62
View File
@@ -7,7 +7,7 @@
/// picture, Escape cancels; F takes the whole screen and W the active window instead, the arrow
/// keys nudge the selection (Shift+arrows resize it).
///
/// The other Spectacle shortcuts take a picture at once: Print the full screen, Super+Print the
/// The other Spectacle shortcuts (these are the defaults) take a picture at once: Print the full screen, Super+Print the
/// active window, Super+Ctrl+Print the window under the pointer. The screenshot panel module
/// offers the same four modes.
///
@@ -16,13 +16,8 @@
/// user-dirs.dirs names one), put on the clipboard as image/png, and a notification with a
/// thumbnail confirms it for a few seconds.
///| evdev codes.
let key_s : UInt = 31
///|
let key_print : UInt = 99
///|
///| evdev codes (keys on the overlay; the shortcuts themselves are in the shortcut table,
/// compositor/shell/shortcuts.mbt, and can be rebound in Settings > Shortcuts).
let key_enter : UInt = 28
///|
@@ -46,9 +41,6 @@ let mod_shift : UInt = 1
///|
let mod_ctrl : UInt = 4
///|
let mod_logo : UInt = 64
///| What a screenshot takes.
pub(all) enum ShotMode {
/// Draw a rectangle on the overlay (or click a window).
@@ -595,10 +587,9 @@ fn ChandraCompositor::screenshot_input(self : ChandraCompositor, ev : @nested.In
}
}
///| A key, for the shortcuts and the overlay.
///| A key, for the overlay.
fn ChandraCompositor::screenshot_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool {
if code == key_lsuper || code == key_rsuper {
self.super_down = pressed // shared with Super+D
if self.shot is Some(_) {
self.super_solo = false
return true
@@ -613,60 +604,14 @@ fn ChandraCompositor::screenshot_key(self : ChandraCompositor, code : UInt, pres
}
return self.shot is Some(_)
}
let logo = self.super_down || (self.mods & mod_logo) != 0U
let shift = (self.mods & mod_shift) != 0U
let ctrl = (self.mods & mod_ctrl) != 0U
match self.shot {
Some(o) => {
self.shot_swallow.push(code)
self.overlay_key(o, code, shift, ctrl)
self.overlay_key(o, code, (self.mods & mod_shift) != 0U, (self.mods & mod_ctrl) != 0U)
true
}
None => {
if self.shell.inspecting() || self.switcher_on {
return false
}
if code == key_r && logo && (shift || ctrl || (self.mods & mod_alt) != 0U) {
self.shot_swallow.push(code)
self.super_solo = false
self.toggle_recording(
if shift {
ShotMode::Region
} else if ctrl {
ShotMode::WindowUnderCursor
} else {
ShotMode::FullScreen
},
)
return true
}
let mode = if code == key_s && logo && shift {
Some(ShotMode::Region)
} else if code == key_print {
Some(
if logo && shift {
ShotMode::Region
} else if logo && ctrl {
ShotMode::WindowUnderCursor
} else if logo {
ShotMode::ActiveWindow
} else {
ShotMode::FullScreen
},
)
} else {
None
}
match mode {
Some(m) => {
self.shot_swallow.push(code)
self.super_solo = false
self.take_screenshot(m)
true
}
None => false
}
}
// The shortcuts that start screenshots and recordings are in the shortcut table (shortcuts.mbt).
None => false
}
}
+124
View File
@@ -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
+252
View File
@@ -0,0 +1,252 @@
///| Keyboard shortcuts: the combo text format, the shortcut table (defaults, conflicts, saving),
/// rebinding through the compositor and through the settings module's Shortcuts tab.
///|
test "key combos parse and print, modifiers in a fixed order" {
let p = fn(s : String) { @shell.KeyCombo::parse(s).map(c => c.to_text()) }
assert_eq(p("Super+Shift+S"), Some("Super+Shift+S"))
assert_eq(p("shift+super+s"), Some("Super+Shift+S"))
assert_eq(p("Ctrl + Alt + Delete"), Some("Ctrl+Alt+Delete"))
assert_eq(p("Meta+PrtSc"), Some("Super+Print"))
assert_eq(p("Control+Return"), Some("Ctrl+Enter"))
assert_eq(p("Alt+Tab"), Some("Alt+Tab"))
assert_eq(p("F12"), Some("F12"))
assert_eq(p("Super"), Some("Super"))
assert_true(@shell.KeyCombo::parse("Super").unwrap().is_super_tap())
assert_eq(@shell.KeyCombo::parse("Super+Shift+S"), Some({ mods: 64U | 1U, key: 31U }))
// Not combos: nothing, a dangling +, unknown keys, a repeated modifier, a modifier alone.
for bad in ["", "Super+", "+S", "Hyper+S", "Super+Foo", "Shift+Shift+A", "Ctrl", "Ctrl+Alt"] {
assert_eq(@shell.KeyCombo::parse(bad), None)
}
}
///|
test "the default shortcuts are the compositor's long-standing combos" {
let want = [
("launcher", "Super"),
("show-desktop", "Super+D"),
("switch-windows", "Alt+Tab"),
("screenshot-region", "Super+Shift+S"),
("screenshot-region-print", "Super+Shift+Print"),
("screenshot-full", "Print"),
("screenshot-window", "Super+Print"),
("screenshot-under-cursor", "Super+Ctrl+Print"),
("record-region", "Super+Shift+R"),
("record-screen", "Super+Alt+R"),
("record-window", "Super+Ctrl+R"),
]
let sc = @shell.Shortcuts::defaults()
assert_eq(@shell.shortcut_table.length(), want.length())
for i, w in want {
assert_eq(@shell.shortcut_table[i].id, w.0)
assert_eq(sc.binding_text(i), w.1) // every default parses and prints back the same
assert_eq(sc.conflict(i), None)
assert_true(sc.is_default(i))
}
assert_eq(sc.lookup({ mods: 64U, key: 32U }), Some(@shell.ShortcutAction::ShowDesktop))
assert_eq(sc.lookup({ mods: 64U | 1U, key: 99U }), Some(@shell.ShortcutAction::ShotRegion))
assert_eq(sc.lookup({ mods: 0U, key: 99U }), Some(@shell.ShortcutAction::ShotFull))
// Caps lock (2) and num lock (16) don't change a combo; other modifiers do.
assert_eq(sc.lookup({ mods: 64U | 2U | 16U, key: 32U }), Some(@shell.ShortcutAction::ShowDesktop))
assert_eq(sc.lookup({ mods: 64U | 4U, key: 32U }), None)
assert_eq(sc.changed(), [])
}
///|
test "two shortcuts on one combo conflict; the one listed first wins" {
let sc = @shell.Shortcuts::defaults()
assert_true(sc.set(9, @shell.KeyCombo::parse("Super+D"))) // record the screen
assert_eq(sc.conflict(1), Some(9))
assert_eq(sc.conflict(9), Some(1))
assert_eq(sc.lookup({ mods: 64U, key: 32U }), Some(@shell.ShortcutAction::ShowDesktop))
// Left and right Super are the same key for combos.
assert_true(sc.set(0, Some({ mods: 0U, key: 126U })))
assert_eq(sc.binding_text(0), "Super")
assert_eq(sc.find({ mods: 0U, key: 125U }), Some(0))
// Unbound shortcuts conflict with nothing.
assert_true(sc.set(1, None))
assert_eq(sc.conflict(9), None)
assert_eq(sc.binding_text(1), "")
sc.reset(1)
assert_eq(sc.binding_text(1), "Super+D")
sc.reset_all()
assert_eq(sc.changed(), [])
}
///|
test "window switching needs a modifier to hold" {
let sc = @shell.Shortcuts::defaults()
assert_false(sc.set(2, @shell.KeyCombo::parse("Tab")))
assert_false(sc.set(2, @shell.KeyCombo::parse("Super")))
assert_true(sc.set(2, @shell.KeyCombo::parse("Super+Tab")))
assert_false(sc.set(99, @shell.KeyCombo::parse("Super+Tab")))
// Anything else takes any combo.
assert_true(sc.set(1, @shell.KeyCombo::parse("F9")))
}
///|
test "changed shortcuts round-trip as (id, text) pairs; bad saved entries keep the default" {
let a = @shell.Shortcuts::defaults()
ignore(a.set(1, @shell.KeyCombo::parse("Super+Ctrl+D")))
ignore(a.set(5, None))
let saved = a.changed()
assert_eq(saved, [("show-desktop", "Super+Ctrl+D"), ("screenshot-full", "")])
let b = @shell.Shortcuts::defaults()
b.apply_saved(saved)
assert_eq(b.bindings, a.bindings)
let c = @shell.Shortcuts::defaults()
c.apply_saved([("no-such-shortcut", "F1"), ("show-desktop", "Super+Nope"), ("switch-windows", "Tab")])
assert_eq(c.changed(), [])
}
///|
test "a rebound shortcut acts on its new combo at once and the old one goes to the client" {
let comp = new_comp("sc-rebind")
let key = fn(code : UInt, down : Bool, t : UInt) {
comp.handle_input(@nested.InputEvent::Key(code, down), t)
}
// The launcher moves from a Super tap to Ctrl+Space.
assert_true(comp.shell.set_shortcut(0, @shell.KeyCombo::parse("Ctrl+Space")))
key(125U, true, 1U)
key(125U, false, 2U)
assert_false(comp.shell.popup_open()) // a Super tap does nothing now
comp.handle_input(@nested.InputEvent::Modifiers(4U, 0U, 0U, 0U), 3U)
key(57U, true, 4U)
key(57U, false, 5U)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 6U)
assert_true(comp.shell.popup_open())
comp.shell.key_down("Escape")
assert_false(comp.shell.popup_open())
// Show desktop on Super+K: Super+D no longer shows the desktop, Super+K does.
assert_true(comp.shell.set_shortcut(1, @shell.KeyCombo::parse("Super+K")))
comp.desktop_hidden.push(42UL) // what a Super+D would clear
key(125U, true, 10U)
key(32U, true, 11U)
key(32U, false, 12U)
key(125U, false, 13U)
assert_eq(comp.desktop_hidden, [42UL])
key(125U, true, 20U)
key(37U, true, 21U)
key(37U, false, 22U)
key(125U, false, 23U)
assert_eq(comp.desktop_hidden, []) // nothing on screen: the toggle tried to bring windows back
assert_false(comp.shell.popup_open())
}
///|
test "capturing takes the next combo for the shortcut; Escape cancels, Backspace unbinds" {
let comp = new_comp("sc-capture")
let key = fn(code : UInt, down : Bool, t : UInt) {
comp.handle_input(@nested.InputEvent::Key(code, down), t)
}
// Show desktop: press Super+Ctrl+D.
comp.shell.start_shortcut_capture(1)
assert_eq(comp.shell.shortcut_capturing(), 1)
key(125U, true, 1U)
comp.handle_input(@nested.InputEvent::Modifiers(64U | 4U, 0U, 0U, 0U), 2U)
key(29U, true, 3U)
key(32U, true, 4U)
assert_eq(comp.shell.shortcut_capturing(), -1)
assert_eq(comp.shell.shortcuts.binding_text(1), "Super+Ctrl+D")
// Its releases are swallowed and the Super release is no tap (the launcher stays shut).
key(32U, false, 5U)
key(29U, false, 6U)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 7U)
key(125U, false, 8U)
assert_false(comp.shell.popup_open())
// Escape cancels: the binding stays.
comp.shell.start_shortcut_capture(1)
key(1U, true, 10U)
key(1U, false, 11U)
assert_eq(comp.shell.shortcut_capturing(), -1)
assert_eq(comp.shell.shortcuts.binding_text(1), "Super+Ctrl+D")
// Backspace unbinds.
comp.shell.start_shortcut_capture(5)
key(14U, true, 12U)
key(14U, false, 13U)
assert_eq(comp.shell.shortcuts.binding_text(5), "")
// A Super tap binds "Super"; window switching won't take a combo without a modifier.
comp.shell.start_shortcut_capture(1)
key(125U, true, 14U)
key(125U, false, 15U)
assert_eq(comp.shell.shortcuts.binding_text(1), "Super")
assert_false(comp.shell.popup_open())
comp.shell.start_shortcut_capture(2)
key(15U, true, 16U)
key(15U, false, 17U)
assert_eq(comp.shell.shortcut_capturing(), 2) // still waiting
key(125U, true, 18U)
key(15U, true, 19U)
key(15U, false, 20U)
key(125U, false, 21U)
assert_eq(comp.shell.shortcut_capturing(), -1)
assert_eq(comp.shell.shortcuts.binding_text(2), "Super+Tab")
// Reset all puts every default back.
comp.shell.reset_all_shortcuts()
assert_eq(comp.shell.shortcuts.changed(), [])
}
///|
test "the settings module's Shortcuts tab lists, captures, flags conflicts and resets" {
let comp = new_comp("sc-tab")
let slot = comp.shell.slot_of("session-settings")
assert_true(comp.shell.open_settings(Shortcuts))
ignore(comp.compose_frame())
let pr = comp.shell.slot_popup_rect(slot)
// A heading, the eleven shortcuts, "Reset all to defaults".
let n = @shell.shortcut_table.length()
assert_eq(pr.h, 40 + (n + 2) * 28 + 6)
// Shortcut i's row (the popup grows upwards from the panel, so read where it is now).
let row_y = fn(i : Int) { comp.shell.slot_popup_rect(slot).y + 40 + (1 + i) * 28 + 13 }
// Click "Show the desktop" and press Super+R: no other shortcut has that combo...
click_at(comp, pr.x + 40, row_y(1), 5U)
assert_eq(comp.shell.shortcut_capturing(), 1)
comp.handle_input(@nested.InputEvent::Key(125U, true), 10U)
comp.handle_input(@nested.InputEvent::Key(19U, true), 11U)
comp.handle_input(@nested.InputEvent::Key(19U, false), 12U)
comp.handle_input(@nested.InputEvent::Key(125U, false), 13U)
ignore(comp.compose_frame())
assert_eq(comp.shell.shortcuts.binding_text(1), "Super+R")
assert_eq(comp.shell.shortcuts.conflict(1), None)
assert_eq(comp.shell.slot_popup_rect(slot).h, pr.h)
// ...but putting record-the-screen on Super+R too shows a conflict line under the list.
assert_true(comp.shell.set_shortcut(9, @shell.KeyCombo::parse("Super+R")))
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).h, pr.h + 28)
// "Reset" at the end of row 1 puts show-desktop back; the conflict line goes.
click_at(comp, pr.x + pr.w - 20, row_y(1), 20U)
assert_eq(comp.shell.shortcuts.binding_text(1), "Super+D")
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).h, pr.h)
// "Reset all to defaults" (the last row).
click_at(comp, pr.x + 40, row_y(n), 30U)
assert_eq(comp.shell.shortcuts.changed(), [])
// A capture started from the tab ends when the popup closes.
click_at(comp, pr.x + 40, row_y(3), 40U)
assert_eq(comp.shell.shortcut_capturing(), 3)
comp.shell.key_down("Escape")
assert_eq(comp.shell.shortcut_capturing(), -1)
}
///|
test "changed shortcuts are saved to state.edn and restored" {
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
write_state_edn("{:note \"keep\"}\n")
let a = new_comp("sc-save-a")
a.shell.persist = true
a.restore_state()
assert_eq(a.shell.shortcuts.changed(), [])
assert_true(a.shell.set_shortcut(1, @shell.KeyCombo::parse("Super+Ctrl+D")))
assert_true(a.shell.set_shortcut(5, None))
let text = read_state_edn()
assert_true(text.contains(":shortcuts {:show-desktop \"Super+Ctrl+D\" :screenshot-full \"\"}"))
assert_true(text.contains(":note \"keep\""))
let b = new_comp("sc-save-b")
b.shell.persist = true
b.restore_state()
assert_eq(b.shell.shortcuts.binding_text(1), "Super+Ctrl+D")
assert_eq(b.shell.shortcuts.binding_text(5), "")
b.shell.reset_all_shortcuts()
assert_false(read_state_edn().contains(":shortcuts"))
}
}
+5 -36
View File
@@ -1,48 +1,17 @@
///| Super+D: show the desktop.
///| Show the desktop (Super+D by default; the shortcut lives in the shortcut table).
///
/// Minimizes every visible window of the active workspace and remembers them; Super+D again
/// Minimizes every visible window of the active workspace and remembers them; the shortcut again
/// (while nothing is on screen) brings them back in their old stacking order with the one that
/// was on top focused. Opening or restoring a window in between starts over: the next Super+D
/// clears the screen again. Neither the D press nor its release reaches a client.
///|
/// evdev codes.
let key_d : UInt32 = 32
/// was on top focused. Opening or restoring a window in between starts over: the next time
/// clears the screen again. Neither the key press nor its release reaches a client.
///|
/// evdev codes of the Super keys.
let key_lsuper : UInt32 = 125
///|
let key_rsuper : UInt32 = 126
///|
/// Handle a key for Super+D. Returns true when the key is consumed (not for clients).
fn ChandraCompositor::show_desktop_key(
self : ChandraCompositor,
code : UInt32,
pressed : Bool,
) -> Bool {
if code == key_lsuper || code == key_rsuper {
self.super_down = pressed
return false // the Super tap (launcher) is handled by the caller
}
if code != key_d {
return false
}
if !pressed {
// The release of a D we swallowed must not reach a client either.
let swallowed = self.d_swallowed
self.d_swallowed = false
return swallowed
}
if !self.super_down || self.shell.inspecting() {
return false
}
self.d_swallowed = true
self.toggle_show_desktop()
true
}
///|
/// Minimize all visible windows of the active workspace, or restore the ones Super+D hid.
pub fn ChandraCompositor::toggle_show_desktop(
+31 -14
View File
@@ -1,4 +1,4 @@
///| Alt+Tab window switcher.
///| Alt+Tab window switcher (the combo is "Switch windows" in the shortcut table).
///
/// Hold Alt and press Tab: a list of the open windows (minimized ones too), most recently used
/// first, with the previous window selected. Each further Tab moves down the list (Shift+Tab up,
@@ -7,9 +7,6 @@
/// that had focus is told Alt was let go so it doesn't think it is still held.
///| evdev codes.
let key_tab : UInt = 15
///|
let key_esc : UInt = 1
///|
@@ -70,29 +67,49 @@ fn ChandraCompositor::switcher_close(self : ChandraCompositor, commit : Bool) ->
}
///| Handle a key for the switcher. Returns true when the key is consumed (not for clients).
/// Its combo comes from the shortcut table ("switch windows", Alt+Tab by default): holding the
/// combo's modifiers, its key opens the switcher and steps down (Shift: up), and letting go of one
/// of those modifiers switches.
fn ChandraCompositor::switcher_key(self : ChandraCompositor, code : UInt, pressed : Bool, time_ms : UInt) -> Bool {
if code == key_lalt || code == key_ralt {
self.alt_down = pressed
if !pressed && self.switcher_on {
let combo = self.shell.shortcuts.combo_for(SwitchWindows)
let hold = match combo {
Some(c) => c.mods & @shell.combo_mods
None => 0U
}
if @shell.is_modifier_key(code) {
if !pressed && self.switcher_on && (@shell.modifier_of_key(code) & hold) != 0U {
self.switcher_close(true)
}
return false // clients still see Alt itself
return false // clients still see the modifiers themselves
}
let key = match combo {
Some(c) => c.key
None => 0U
}
if !pressed {
// Releases of keys we swallowed must not reach a client either.
return self.switcher_on && (code == key_tab || code == key_esc || code == key_up || code == key_down || code == key_left || code == key_right)
return self.switcher_on && (code == key || code == key_esc || code == key_up || code == key_down || code == key_left || code == key_right)
}
if code == key_tab && self.alt_down && !self.shell.inspecting() {
let shift = (self.mods & 1U) != 0U
// The combo's modifiers held (Shift may be added, to go backwards).
let held = self.held_mods()
let shift = (held & @shell.mod_shift) != 0U && (hold & @shell.mod_shift) == 0U
let combo_held = hold != 0U && (held & (@shell.combo_mods ^ @shell.mod_shift)) == (hold & (@shell.combo_mods ^ @shell.mod_shift)) &&
((hold & @shell.mod_shift) == 0U || (held & @shell.mod_shift) != 0U)
if code == key && combo_held && !self.shell.inspecting() {
if !self.switcher_on {
let c = self.switcher_candidates()
if c.length() < 2 {
return true // nothing to switch to; still not a client's Tab
return true // nothing to switch to; still not a client's key
}
// Let the client that had focus see Alt released: it won't get the real release.
// Let the client that had focus see the held modifiers released: it won't get the real
// releases.
match self.kbd_win {
Some(w) => {
self.server.keyboard_key(w, time_ms, key_lalt, false)
for m in [@shell.mod_alt, @shell.mod_ctrl, @shell.mod_logo, @shell.mod_shift] {
if (hold & m) != 0U {
self.server.keyboard_key(w, time_ms, @shell.key_of_modifier(m), false)
}
}
self.server.keyboard_modifiers(w, 0U, 0U, 0U, 0U)
}
None => ()