- 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
@@ -6,6 +6,7 @@ import {
|
||||
"chandra/desktop/interface/chandra/desktop/modules" @modules,
|
||||
"chandra/desktop/interface/chandra/desktop/power" @power,
|
||||
"chandra/desktop/interface/chandra/desktop/system" @system,
|
||||
"chandra/desktop/interface/chandra/desktop/shortcuts" @shortcuts,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
|
||||
@@ -13,16 +13,22 @@
|
||||
/// menu's "Modules..." opens this tab;
|
||||
/// - Power: the battery (`system`, when there is one), how long without input before the screen
|
||||
/// turns off and before the computer suspends (a click steps through the choices), and Suspend,
|
||||
/// Restart and Power off now (`power`); Restart and Power off ask for a second click.
|
||||
/// Restart and Power off now (`power`); Restart and Power off ask for a second click;
|
||||
/// - Shortcuts: the compositor's keyboard shortcuts (`shortcuts`) with their combos. Click one (or
|
||||
/// Enter) and press the new keys: the compositor takes that combo for it (Escape cancels,
|
||||
/// Backspace unbinds; clicking the row again also cancels). "Reset" at the end of a changed
|
||||
/// row, or Backspace on the highlighted row, puts it back; "Reset all to defaults" does every
|
||||
/// one. Combos two shortcuts share are shown in red and listed under the shortcuts.
|
||||
///
|
||||
/// Clicking a row acts at once and the popup stays open; a row in the panel list only acts through
|
||||
/// its buttons, so a stray click doesn't remove anything. Up/Down move the highlight, Left/Right
|
||||
/// (or 1-4) switch tabs, Enter or Space acts on the highlighted row, Backspace or Delete removes
|
||||
/// the highlighted panel module and PageUp/PageDown move it, Escape or a click elsewhere closes. The shell remembers settings and wallpaper in state.edn, the panel in
|
||||
/// panel.edn.
|
||||
/// (or 1-5) switch tabs, Enter or Space acts on the highlighted row, Backspace or Delete removes
|
||||
/// the highlighted panel module (or resets the highlighted shortcut) and PageUp/PageDown move it,
|
||||
/// Escape or a click elsewhere closes. The shell remembers settings, wallpaper and shortcuts in
|
||||
/// state.edn, the panel in panel.edn.
|
||||
|
||||
///| Popup geometry: the tab bar, then a column of rows, with a margin around them.
|
||||
let popup_w : Int = 320
|
||||
let popup_w : Int = 360
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
@@ -44,7 +50,7 @@ let switch_w : Int = 34
|
||||
let switch_h : Int = 18
|
||||
|
||||
///|
|
||||
let tab_names : Array[String] = ["Session", "Desktop", "Panel", "Power"]
|
||||
let tab_names : Array[String] = ["Session", "Desktop", "Panel", "Power", "Shortcuts"]
|
||||
|
||||
///| A popup row.
|
||||
enum Row {
|
||||
@@ -66,6 +72,18 @@ enum Row {
|
||||
Timeout(Int, String)
|
||||
/// Suspend (0), power off (1) or restart (2) now.
|
||||
PowerNow(Int, String)
|
||||
/// A keyboard shortcut: its index and what the host says about it.
|
||||
Shortcut(Int, @shortcuts.Shortcut)
|
||||
/// "Reset all to defaults" (the shortcuts).
|
||||
ResetShortcuts
|
||||
}
|
||||
|
||||
///| Width of the "Reset" button at the end of a changed shortcut's row.
|
||||
let reset_w : Int = 50
|
||||
|
||||
///| Conflicting combos are drawn in this red.
|
||||
fn conflict_color() -> @types.Color {
|
||||
@ui.color(220, 72, 64, 255)
|
||||
}
|
||||
|
||||
///| The timeout choices, in minutes (0: never).
|
||||
@@ -179,6 +197,21 @@ fn rows() -> Array[Row] {
|
||||
rs.push(PowerNow(2, "Restart"))
|
||||
rs.push(PowerNow(1, "Power off"))
|
||||
}
|
||||
4 => {
|
||||
rs.push(Heading("Click one, then press its new keys"))
|
||||
let list = @shortcuts.shortcuts()
|
||||
for i = 0; i < list.length(); i = i + 1 {
|
||||
rs.push(Shortcut(i, list[i]))
|
||||
}
|
||||
// Each shared combo once, under the list: which shortcut gets it.
|
||||
for i = 0; i < list.length(); i = i + 1 {
|
||||
let sc = list[i]
|
||||
if sc.conflict != "" && !list[:i].iter().any(e => e.binding == sc.binding) {
|
||||
rs.push(Info("! " + sc.binding + " is used twice: " + sc.name + " wins"))
|
||||
}
|
||||
}
|
||||
rs.push(ResetShortcuts)
|
||||
}
|
||||
_ => {
|
||||
rs.push(Heading("In the panel, left to right"))
|
||||
let loaded = @modules.loaded()
|
||||
@@ -330,6 +363,7 @@ let hover_btn : Ref[Int] = { val: -1 }
|
||||
|
||||
///|
|
||||
fn set_tab(i : Int) -> Unit {
|
||||
cancel_capture()
|
||||
tab.val = i
|
||||
armed.val = -1
|
||||
hover.val = first_active(rows())
|
||||
@@ -338,14 +372,27 @@ fn set_tab(i : Int) -> Unit {
|
||||
|
||||
///|
|
||||
fn close() -> Unit {
|
||||
cancel_capture()
|
||||
open_.val = false
|
||||
armed.val = -1
|
||||
hover.val = -1
|
||||
}
|
||||
|
||||
///| Stop a shortcut capture this module started, if one is waiting.
|
||||
fn cancel_capture() -> Unit {
|
||||
if tab.val == 4 && @shortcuts.shortcuts().iter().any(s => s.capturing) {
|
||||
@shortcuts.cancel_capture()
|
||||
}
|
||||
}
|
||||
|
||||
///| Whether a popup-local x is on the "Reset" button of a changed shortcut row.
|
||||
fn on_reset(sc : @shortcuts.Shortcut, x : Int) -> Bool {
|
||||
sc.binding != sc.default_binding && !sc.capturing && x >= popup_w - margin - reset_w
|
||||
}
|
||||
|
||||
///| Act on row `i`: flip a setting, show a wallpaper, load a module, or browse. A panel-list row
|
||||
/// acts only through button `btn` (0 move up, 1 move down, 2 remove).
|
||||
fn act(rs : Array[Row], i : Int, btn~ : Int = -1) -> Unit {
|
||||
fn act(rs : Array[Row], i : Int, btn~ : Int = -1, x~ : Int = 0) -> Unit {
|
||||
if !active(rs, i) {
|
||||
return
|
||||
}
|
||||
@@ -367,6 +414,15 @@ fn act(rs : Array[Row], i : Int, btn~ : Int = -1) -> Unit {
|
||||
armed.val = a
|
||||
}
|
||||
Info(_) => ()
|
||||
Shortcut(k, sc) =>
|
||||
if sc.capturing {
|
||||
@shortcuts.cancel_capture()
|
||||
} else if on_reset(sc, x) {
|
||||
@shortcuts.reset(k.reinterpret_as_uint())
|
||||
} else {
|
||||
@shortcuts.capture(k.reinterpret_as_uint())
|
||||
}
|
||||
ResetShortcuts => @shortcuts.reset_all()
|
||||
Setting(k, _) => {
|
||||
let idx = k.reinterpret_as_uint()
|
||||
@settings.set_setting(idx, !@settings.is_on(idx))
|
||||
@@ -586,7 +642,12 @@ pub fn popup() -> PopupSurface? {
|
||||
ops.push(@ui.stroke_rect(@ui.rect(bx, by, bw, bh), if hot { p.accent } else { p.border }, width=1, radius=r))
|
||||
ops.push(@ui.text(w / 2, by + bh / 2, label, fs - 2, if hot { p.foreground } else { p.foreground_muted }, align=CENTER))
|
||||
}
|
||||
Info(text) => ops.push(@ui.text(margin + 10, mid, text, fs - 1, p.foreground))
|
||||
Info(text) =>
|
||||
if text.has_prefix("! ") {
|
||||
ops.push(@ui.text(margin + 10, mid, text, fs - 2, conflict_color()))
|
||||
} else {
|
||||
ops.push(@ui.text(margin + 10, mid, text, fs - 1, p.foreground))
|
||||
}
|
||||
Timeout(k, label) => {
|
||||
let m = if k == 0 { @power.screen_off_minutes() } else { @power.suspend_minutes() }
|
||||
ops.push(@ui.text(margin + 10, mid, label, fs - 1, list_fg))
|
||||
@@ -596,6 +657,28 @@ pub fn popup() -> PopupSurface? {
|
||||
let text = if armed.val == a { "Click again to " + label.to_lower() } else { label }
|
||||
ops.push(@ui.text(margin + 10, mid, text, fs - 1, list_fg, bold=armed.val == a))
|
||||
}
|
||||
Shortcut(_, sc) => {
|
||||
ops.push(@ui.text(margin + 10, mid, sc.name, fs - 1, list_fg))
|
||||
let changed = sc.binding != sc.default_binding
|
||||
let right = w - margin - 10
|
||||
let combo_x = if changed && !sc.capturing { right - reset_w } else { right }
|
||||
if sc.capturing {
|
||||
ops.push(@ui.text(right, mid, "Press keys...", fs - 2, if hot { list_fg } else { p.accent }, align=RIGHT, bold=true))
|
||||
} else {
|
||||
let (text, fg) = if sc.binding == "" {
|
||||
("Unbound", if hot { list_fg } else { p.foreground_muted })
|
||||
} else if sc.conflict != "" {
|
||||
(sc.binding, conflict_color())
|
||||
} else {
|
||||
(sc.binding, list_fg)
|
||||
}
|
||||
ops.push(@ui.text(combo_x, mid, text, fs - 2, fg, align=RIGHT, bold=true))
|
||||
if changed {
|
||||
ops.push(@ui.text(right, mid, "Reset", fs - 3, if hot { list_fg } else { p.accent }, align=RIGHT))
|
||||
}
|
||||
}
|
||||
}
|
||||
ResetShortcuts => ops.push(@ui.text(margin + 10, mid, "Reset all to defaults", fs - 1, list_fg, bold=true))
|
||||
}
|
||||
}
|
||||
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
|
||||
@@ -645,7 +728,7 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
act(rs, i, btn~)
|
||||
act(rs, i, btn~, x=p.x)
|
||||
// A module list changes length: keep the highlight on a real row.
|
||||
let after = rows()
|
||||
hover.val = if active(after, i) { i } else { first_active(after) }
|
||||
@@ -701,6 +784,11 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
}
|
||||
true
|
||||
}
|
||||
// Back to the default for the highlighted shortcut.
|
||||
Some(Shortcut(i, _)) if k == "Backspace" || k == "Delete" => {
|
||||
@shortcuts.reset(i.reinterpret_as_uint())
|
||||
true
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
} else if k == "ArrowDown" || k == "Down" {
|
||||
@@ -715,7 +803,7 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
} else if k == "ArrowLeft" || k == "Left" {
|
||||
set_tab((tab.val + tab_names.length() - 1) % tab_names.length())
|
||||
true
|
||||
} else if k == "1" || k == "2" || k == "3" || k == "4" {
|
||||
} else if k == "1" || k == "2" || k == "3" || k == "4" || k == "5" {
|
||||
set_tab(k[0].to_int() - '1'.to_int())
|
||||
true
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user