- 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
@@ -268,6 +268,10 @@ pub(all) struct DesktopShell {
|
||||
/// (0: never). Saved in state.edn as :power {:screen-off 10 :suspend 0} when not the defaults.
|
||||
mut screen_off_min : Int
|
||||
mut suspend_min : Int
|
||||
/// Keyboard shortcuts (shortcuts.mbt); saved in state.edn as :shortcuts when not the defaults.
|
||||
shortcuts : Shortcuts
|
||||
/// The shortcut waiting for its new combo from the Shortcuts tab (-1: none).
|
||||
mut shortcut_capture : Int
|
||||
mut desk_set : Bool
|
||||
mut desk_x : Int
|
||||
mut desk_y : Int
|
||||
@@ -373,6 +377,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
dark_mode: true,
|
||||
screen_off_min: default_screen_off_min,
|
||||
suspend_min: default_suspend_min,
|
||||
shortcuts: Shortcuts::defaults(),
|
||||
shortcut_capture: -1,
|
||||
desk_set: false,
|
||||
desk_x: 0,
|
||||
desk_y: 0,
|
||||
|
||||
@@ -0,0 +1,489 @@
|
||||
///| Keyboard shortcuts: one table of the compositor's named actions and the key combo each is
|
||||
/// bound to. The compositor looks keys up here (compositor/host/shortcuts.mbt), the settings
|
||||
/// module's Shortcuts tab lists and rebinds them (the `shortcuts` capability), and state.edn keeps
|
||||
/// the ones that differ from the defaults:
|
||||
///
|
||||
/// :shortcuts {:show-desktop "Super+Ctrl+D" :screenshot-full ""} ; "" unbinds
|
||||
///
|
||||
/// A combo is modifiers plus one key, written "Super+Ctrl+Alt+Shift+Key" (modifiers in that order).
|
||||
/// "Super" alone is a tap of the Super key: pressed and released with nothing else in between.
|
||||
|
||||
///| Modifier bits, as in wl_keyboard.modifiers (xkb's depressed mask for the usual keymap).
|
||||
pub let mod_shift : UInt = 1
|
||||
|
||||
///|
|
||||
pub let mod_ctrl : UInt = 4
|
||||
|
||||
///|
|
||||
pub let mod_alt : UInt = 8
|
||||
|
||||
///|
|
||||
pub let mod_logo : UInt = 64
|
||||
|
||||
///| The modifiers a combo can hold (caps and num lock never count).
|
||||
pub let combo_mods : UInt = 1U | 4U | 8U | 64U
|
||||
|
||||
///| evdev code of the left Super key; a combo with this key and no modifiers is a Super tap.
|
||||
pub let key_super : UInt = 125
|
||||
|
||||
///| A key combo: modifier bits and an evdev key code.
|
||||
pub(all) struct KeyCombo {
|
||||
mods : UInt
|
||||
key : UInt
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///| What a shortcut does.
|
||||
pub(all) enum ShortcutAction {
|
||||
/// Open or close the launcher search.
|
||||
Launcher
|
||||
/// Minimize every window, or bring them back (showdesktop.mbt).
|
||||
ShowDesktop
|
||||
/// Hold the combo's modifiers and press its key to step through the windows (switcher.mbt);
|
||||
/// with Shift added it steps backwards.
|
||||
SwitchWindows
|
||||
/// Screenshots (screenshot.mbt).
|
||||
ShotRegion
|
||||
ShotFull
|
||||
ShotActiveWindow
|
||||
ShotWindowUnderCursor
|
||||
/// Recordings (recorder.mbt); the same shortcut again stops.
|
||||
RecordRegion
|
||||
RecordScreen
|
||||
RecordWindow
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///| One row of the shortcut table.
|
||||
pub(all) struct ShortcutDef {
|
||||
/// Its key in state.edn's :shortcuts map.
|
||||
id : String
|
||||
/// What the settings module shows.
|
||||
label : String
|
||||
action : ShortcutAction
|
||||
/// The default combo, as text.
|
||||
default_text : String
|
||||
}
|
||||
|
||||
///| Every shortcut, in the order the settings module lists them. When two are bound to the same
|
||||
/// combo the earlier one wins. The defaults are what the compositor has always used.
|
||||
pub let shortcut_table : Array[ShortcutDef] = [
|
||||
{ id: "launcher", label: "Open the launcher", action: Launcher, default_text: "Super" },
|
||||
{ id: "show-desktop", label: "Show the desktop", action: ShowDesktop, default_text: "Super+D" },
|
||||
{ id: "switch-windows", label: "Switch windows", action: SwitchWindows, default_text: "Alt+Tab" },
|
||||
{ id: "screenshot-region", label: "Screenshot: region", action: ShotRegion, default_text: "Super+Shift+S" },
|
||||
{ id: "screenshot-region-print", label: "Screenshot: region (Print)", action: ShotRegion, default_text: "Super+Shift+Print" },
|
||||
{ id: "screenshot-full", label: "Screenshot: full screen", action: ShotFull, default_text: "Print" },
|
||||
{ id: "screenshot-window", label: "Screenshot: active window", action: ShotActiveWindow, default_text: "Super+Print" },
|
||||
{ id: "screenshot-under-cursor", label: "Screenshot: window under cursor", action: ShotWindowUnderCursor, default_text: "Super+Ctrl+Print" },
|
||||
{ id: "record-region", label: "Record a region", action: RecordRegion, default_text: "Super+Shift+R" },
|
||||
{ id: "record-screen", label: "Record the screen", action: RecordScreen, default_text: "Super+Alt+R" },
|
||||
{ id: "record-window", label: "Record a window", action: RecordWindow, default_text: "Super+Ctrl+R" },
|
||||
]
|
||||
|
||||
///| evdev code -> key name, for the keys a combo can end in (US layout names).
|
||||
let key_names : Array[(UInt, String)] = [
|
||||
(1, "Escape"), (2, "1"), (3, "2"), (4, "3"), (5, "4"), (6, "5"), (7, "6"), (8, "7"), (9, "8"),
|
||||
(10, "9"), (11, "0"), (12, "Minus"), (13, "Equal"), (14, "Backspace"), (15, "Tab"), (16, "Q"),
|
||||
(17, "W"), (18, "E"), (19, "R"), (20, "T"), (21, "Y"), (22, "U"), (23, "I"), (24, "O"), (25, "P"),
|
||||
(26, "BracketLeft"), (27, "BracketRight"), (28, "Enter"), (30, "A"), (31, "S"), (32, "D"),
|
||||
(33, "F"), (34, "G"), (35, "H"), (36, "J"), (37, "K"), (38, "L"), (39, "Semicolon"),
|
||||
(40, "Apostrophe"), (41, "Grave"), (43, "Backslash"), (44, "Z"), (45, "X"), (46, "C"), (47, "V"),
|
||||
(48, "B"), (49, "N"), (50, "M"), (51, "Comma"), (52, "Period"), (53, "Slash"), (57, "Space"),
|
||||
(59, "F1"), (60, "F2"), (61, "F3"), (62, "F4"), (63, "F5"), (64, "F6"), (65, "F7"), (66, "F8"),
|
||||
(67, "F9"), (68, "F10"), (87, "F11"), (88, "F12"), (99, "Print"), (102, "Home"), (103, "Up"),
|
||||
(104, "PageUp"), (105, "Left"), (106, "Right"), (107, "End"), (108, "Down"), (109, "PageDown"),
|
||||
(110, "Insert"), (111, "Delete"), (113, "Mute"), (114, "VolumeDown"), (115, "VolumeUp"),
|
||||
(119, "Pause"), (163, "Next"), (164, "PlayPause"), (165, "Previous"), (224, "BrightnessDown"),
|
||||
(225, "BrightnessUp"),
|
||||
]
|
||||
|
||||
///| Other spellings `KeyCombo::parse` accepts (lower case).
|
||||
let key_aliases : Array[(String, String)] = [
|
||||
("esc", "escape"), ("return", "enter"), ("del", "delete"), ("ins", "insert"), ("pgup", "pageup"),
|
||||
("pgdn", "pagedown"), ("prtsc", "print"), ("printscreen", "print"), ("sysrq", "print"),
|
||||
("-", "minus"), ("=", "equal"), ("[", "bracketleft"), ("]", "bracketright"), (";", "semicolon"),
|
||||
("'", "apostrophe"), ("`", "grave"), ("\\", "backslash"), (",", "comma"), (".", "period"),
|
||||
("/", "slash"),
|
||||
]
|
||||
|
||||
///| evdev codes of the modifier keys themselves (Ctrl, Shift, Alt, Super; left and right).
|
||||
pub fn is_modifier_key(code : UInt) -> Bool {
|
||||
code == 29U || code == 97U || code == 42U || code == 54U || code == 56U || code == 100U ||
|
||||
code == 125U || code == 126U
|
||||
}
|
||||
|
||||
///| The modifier bit a modifier key sets (0 for other keys).
|
||||
pub fn modifier_of_key(code : UInt) -> UInt {
|
||||
match code {
|
||||
29U | 97U => mod_ctrl
|
||||
42U | 54U => mod_shift
|
||||
56U | 100U => mod_alt
|
||||
125U | 126U => mod_logo
|
||||
_ => 0U
|
||||
}
|
||||
}
|
||||
|
||||
///| The left-hand key for a modifier bit (what a client is told was released).
|
||||
pub fn key_of_modifier(m : UInt) -> UInt {
|
||||
if m == mod_ctrl {
|
||||
29U
|
||||
} else if m == mod_shift {
|
||||
42U
|
||||
} else if m == mod_alt {
|
||||
56U
|
||||
} else {
|
||||
125U
|
||||
}
|
||||
}
|
||||
|
||||
///| The name of an evdev key, or "" when combos can't use it.
|
||||
pub fn key_code_name(code : UInt) -> String {
|
||||
for e in key_names {
|
||||
if e.0 == code {
|
||||
return e.1
|
||||
}
|
||||
}
|
||||
""
|
||||
}
|
||||
|
||||
///| Whether this combo is a bare tap of the Super key.
|
||||
pub fn KeyCombo::is_super_tap(self : KeyCombo) -> Bool {
|
||||
self.mods == 0U && (self.key == 125U || self.key == 126U)
|
||||
}
|
||||
|
||||
///| A combo as text: "Super+Ctrl+Alt+Shift+Key", or "Super" for a Super tap.
|
||||
pub fn KeyCombo::to_text(self : KeyCombo) -> String {
|
||||
if self.is_super_tap() {
|
||||
return "Super"
|
||||
}
|
||||
let parts : Array[String] = []
|
||||
if (self.mods & mod_logo) != 0U {
|
||||
parts.push("Super")
|
||||
}
|
||||
if (self.mods & mod_ctrl) != 0U {
|
||||
parts.push("Ctrl")
|
||||
}
|
||||
if (self.mods & mod_alt) != 0U {
|
||||
parts.push("Alt")
|
||||
}
|
||||
if (self.mods & mod_shift) != 0U {
|
||||
parts.push("Shift")
|
||||
}
|
||||
let name = key_code_name(self.key)
|
||||
parts.push(if name == "" { "Key" + self.key.to_string() } else { name })
|
||||
parts.join("+")
|
||||
}
|
||||
|
||||
///| Parse "Super+Shift+S" (case doesn't matter; Meta/Win/Logo mean Super, Control means Ctrl).
|
||||
/// "Super" alone is a Super tap. None for anything else: unknown keys, no key, a modifier as the key.
|
||||
pub fn KeyCombo::parse(text : String) -> KeyCombo? {
|
||||
let parts : Array[String] = []
|
||||
for p in text.split("+") {
|
||||
parts.push(p.trim(chars=" ").to_string())
|
||||
}
|
||||
// "Ctrl++" names the plus key, which combos don't support; "" is no combo.
|
||||
if parts.length() == 0 || parts.iter().any(p => p == "") {
|
||||
return None
|
||||
}
|
||||
let mut mods = 0U
|
||||
for i = 0; i < parts.length() - 1; i = i + 1 {
|
||||
let m = mod_named(parts[i].to_lower())
|
||||
if m == 0U || (mods & m) != 0U {
|
||||
return None
|
||||
}
|
||||
mods = mods | m
|
||||
}
|
||||
let last = parts[parts.length() - 1].to_lower()
|
||||
if mod_named(last) == mod_logo && mods == 0U {
|
||||
return Some({ mods: 0U, key: key_super })
|
||||
}
|
||||
let mut name = last
|
||||
for a in key_aliases {
|
||||
if a.0 == last {
|
||||
name = a.1
|
||||
}
|
||||
}
|
||||
for e in key_names {
|
||||
if e.1.to_lower() == name {
|
||||
return Some({ mods, key: e.0 })
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///|
|
||||
fn mod_named(s : String) -> UInt {
|
||||
match s {
|
||||
"super" | "meta" | "win" | "logo" | "mod4" => mod_logo
|
||||
"ctrl" | "control" => mod_ctrl
|
||||
"alt" | "mod1" => mod_alt
|
||||
"shift" => mod_shift
|
||||
_ => 0U
|
||||
}
|
||||
}
|
||||
|
||||
///| The default combo of shortcut `i`.
|
||||
pub fn default_combo(i : Int) -> KeyCombo? {
|
||||
KeyCombo::parse(shortcut_table[i].default_text)
|
||||
}
|
||||
|
||||
///| The current bindings, one per `shortcut_table` row (None: unbound).
|
||||
pub(all) struct Shortcuts {
|
||||
bindings : Array[KeyCombo?]
|
||||
}
|
||||
|
||||
///| Every shortcut on its default combo.
|
||||
pub fn Shortcuts::defaults() -> Shortcuts {
|
||||
let bindings : Array[KeyCombo?] = []
|
||||
for i = 0; i < shortcut_table.length(); i = i + 1 {
|
||||
bindings.push(default_combo(i))
|
||||
}
|
||||
{ bindings, }
|
||||
}
|
||||
|
||||
///| The combo shortcut `i` is bound to.
|
||||
pub fn Shortcuts::binding(self : Shortcuts, i : Int) -> KeyCombo? {
|
||||
if i >= 0 && i < self.bindings.length() {
|
||||
self.bindings[i]
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
///| The combo shortcut `i` is bound to, as text ("" when unbound).
|
||||
pub fn Shortcuts::binding_text(self : Shortcuts, i : Int) -> String {
|
||||
match self.binding(i) {
|
||||
Some(c) => c.to_text()
|
||||
None => ""
|
||||
}
|
||||
}
|
||||
|
||||
///| Bind shortcut `i` to `combo` (None unbinds). False when `i` is out of range or the combo
|
||||
/// can't work for that action (window switching needs a modifier to hold).
|
||||
pub fn Shortcuts::set(self : Shortcuts, i : Int, combo : KeyCombo?) -> Bool {
|
||||
if i < 0 || i >= self.bindings.length() {
|
||||
return false
|
||||
}
|
||||
match combo {
|
||||
Some(c) =>
|
||||
if !combo_allowed(shortcut_table[i].action, c) {
|
||||
return false
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
self.bindings[i] = combo
|
||||
true
|
||||
}
|
||||
|
||||
///| Whether `action` can be bound to `c`: window switching is "hold modifiers, press a key", so it
|
||||
/// needs a modifier and a real key; anything can take a Super tap or a plain combo.
|
||||
pub fn combo_allowed(action : ShortcutAction, c : KeyCombo) -> Bool {
|
||||
match action {
|
||||
SwitchWindows => (c.mods & combo_mods) != 0U && !c.is_super_tap()
|
||||
_ => true
|
||||
}
|
||||
}
|
||||
|
||||
///| Put shortcut `i` back to its default.
|
||||
pub fn Shortcuts::reset(self : Shortcuts, i : Int) -> Unit {
|
||||
if i >= 0 && i < self.bindings.length() {
|
||||
self.bindings[i] = default_combo(i)
|
||||
}
|
||||
}
|
||||
|
||||
///| Put every shortcut back to its default.
|
||||
pub fn Shortcuts::reset_all(self : Shortcuts) -> Unit {
|
||||
for i = 0; i < self.bindings.length(); i = i + 1 {
|
||||
self.bindings[i] = default_combo(i)
|
||||
}
|
||||
}
|
||||
|
||||
///| Whether shortcut `i` is on its default combo.
|
||||
pub fn Shortcuts::is_default(self : Shortcuts, i : Int) -> Bool {
|
||||
self.binding(i) == default_combo(i)
|
||||
}
|
||||
|
||||
///| The first shortcut bound to exactly `combo` (modifiers outside `combo_mods` are ignored).
|
||||
pub fn Shortcuts::find(self : Shortcuts, combo : KeyCombo) -> Int? {
|
||||
let want : KeyCombo = { mods: combo.mods & combo_mods, key: combo.key }
|
||||
for i = 0; i < self.bindings.length(); i = i + 1 {
|
||||
match self.bindings[i] {
|
||||
Some(c) => if c.mods == want.mods && same_key(c.key, want.key) { return Some(i) }
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///| The left and right Super keys are one key for combos.
|
||||
fn same_key(a : UInt, b : UInt) -> Bool {
|
||||
a == b || ((a == 125U || a == 126U) && (b == 125U || b == 126U))
|
||||
}
|
||||
|
||||
///| The action bound to `combo`, if any.
|
||||
pub fn Shortcuts::lookup(self : Shortcuts, combo : KeyCombo) -> ShortcutAction? {
|
||||
match self.find(combo) {
|
||||
Some(i) => Some(shortcut_table[i].action)
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
///| Another shortcut bound to the same combo as shortcut `i` (the first such), if any.
|
||||
pub fn Shortcuts::conflict(self : Shortcuts, i : Int) -> Int? {
|
||||
match self.binding(i) {
|
||||
None => None
|
||||
Some(c) => {
|
||||
for j = 0; j < self.bindings.length(); j = j + 1 {
|
||||
if j != i {
|
||||
match self.bindings[j] {
|
||||
Some(d) => if d.mods == c.mods && same_key(d.key, c.key) { return Some(j) }
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| The bound combo of the first shortcut with `action` (for showing it, e.g. "Alt+Tab").
|
||||
pub fn Shortcuts::combo_for(self : Shortcuts, action : ShortcutAction) -> KeyCombo? {
|
||||
for i = 0; i < self.bindings.length(); i = i + 1 {
|
||||
if shortcut_table[i].action == action {
|
||||
match self.bindings[i] {
|
||||
Some(c) => return Some(c)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///| The shortcuts that differ from their defaults, as (state.edn id, combo text; "" unbound).
|
||||
pub fn Shortcuts::changed(self : Shortcuts) -> Array[(String, String)] {
|
||||
let out : Array[(String, String)] = []
|
||||
for i = 0; i < self.bindings.length(); i = i + 1 {
|
||||
if !self.is_default(i) {
|
||||
out.push((shortcut_table[i].id, self.binding_text(i)))
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///| Apply saved (id, text) pairs over the defaults: "" unbinds; unknown ids and combos that don't
|
||||
/// parse are ignored (the default stays).
|
||||
pub fn Shortcuts::apply_saved(self : Shortcuts, saved : Array[(String, String)]) -> Unit {
|
||||
for s in saved {
|
||||
for i = 0; i < shortcut_table.length(); i = i + 1 {
|
||||
if shortcut_table[i].id == s.0 {
|
||||
if s.1.trim(chars=" ").to_string() == "" {
|
||||
ignore(self.set(i, None))
|
||||
} else {
|
||||
match KeyCombo::parse(s.1) {
|
||||
Some(c) => ignore(self.set(i, Some(c)))
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Shortcut requests from the `shortcuts` capability (wit/host/plasmoids.wit `shortcut(s32)`):
|
||||
/// code = action * 1000 + index, action 0 capture, 1 reset, 2 reset all, 3 cancel the capture.
|
||||
pub fn DesktopShell::shortcut_request(self : DesktopShell, code : Int) -> Unit {
|
||||
if code < 0 {
|
||||
return
|
||||
}
|
||||
let i = code % 1000
|
||||
match code / 1000 {
|
||||
0 => self.start_shortcut_capture(i)
|
||||
1 => self.reset_shortcut(i)
|
||||
2 => self.reset_all_shortcuts()
|
||||
3 => self.cancel_shortcut_capture()
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| The shortcut waiting for its new combo, or -1.
|
||||
pub fn DesktopShell::shortcut_capturing(self : DesktopShell) -> Int {
|
||||
self.shortcut_capture
|
||||
}
|
||||
|
||||
///| Wait for the next key combo and bind shortcut `i` to it (`finish_shortcut_capture`).
|
||||
pub fn DesktopShell::start_shortcut_capture(self : DesktopShell, i : Int) -> Unit {
|
||||
if i >= 0 && i < shortcut_table.length() {
|
||||
self.shortcut_capture = i
|
||||
self.publish_shortcuts()
|
||||
}
|
||||
}
|
||||
|
||||
///| Stop waiting for a combo; the binding stays as it was.
|
||||
pub fn DesktopShell::cancel_shortcut_capture(self : DesktopShell) -> Unit {
|
||||
if self.shortcut_capture >= 0 {
|
||||
self.shortcut_capture = -1
|
||||
self.publish_shortcuts()
|
||||
}
|
||||
}
|
||||
|
||||
///| The combo pressed while capturing (None: unbind). Binds it, saves and ends the capture; false
|
||||
/// (still capturing) when the shortcut can't take that combo.
|
||||
pub fn DesktopShell::finish_shortcut_capture(self : DesktopShell, combo : KeyCombo?) -> Bool {
|
||||
let i = self.shortcut_capture
|
||||
if i < 0 || !self.shortcuts.set(i, combo) {
|
||||
return false
|
||||
}
|
||||
self.shortcut_capture = -1
|
||||
match self.shortcuts.conflict(i) {
|
||||
Some(j) => self.say(combo.map(c => c.to_text()).unwrap_or("") + " is also " + shortcut_table[j].label)
|
||||
None => ()
|
||||
}
|
||||
self.publish_shortcuts()
|
||||
self.save_state()
|
||||
true
|
||||
}
|
||||
|
||||
///| Bind shortcut `i` to `combo` directly (None unbinds) and save. False when it can't take it.
|
||||
pub fn DesktopShell::set_shortcut(self : DesktopShell, i : Int, combo : KeyCombo?) -> Bool {
|
||||
if !self.shortcuts.set(i, combo) {
|
||||
return false
|
||||
}
|
||||
self.publish_shortcuts()
|
||||
self.save_state()
|
||||
true
|
||||
}
|
||||
|
||||
///| Put shortcut `i` back to its default and save.
|
||||
pub fn DesktopShell::reset_shortcut(self : DesktopShell, i : Int) -> Unit {
|
||||
self.shortcut_capture = -1
|
||||
self.shortcuts.reset(i)
|
||||
self.publish_shortcuts()
|
||||
self.save_state()
|
||||
}
|
||||
|
||||
///| Put every shortcut back to its default and save.
|
||||
pub fn DesktopShell::reset_all_shortcuts(self : DesktopShell) -> Unit {
|
||||
self.shortcut_capture = -1
|
||||
self.shortcuts.reset_all()
|
||||
self.publish_shortcuts()
|
||||
self.save_state()
|
||||
}
|
||||
|
||||
///| Publish the shortcut table for the `shortcuts` capability: per row name, binding, default,
|
||||
/// the name of a conflicting shortcut ("" none), and whether it is capturing.
|
||||
pub fn DesktopShell::publish_shortcuts(self : DesktopShell) -> Unit {
|
||||
let t = @wasm.Table::new()
|
||||
for i = 0; i < shortcut_table.length(); i = i + 1 {
|
||||
t.str(shortcut_table[i].label)
|
||||
t.str(self.shortcuts.binding_text(i))
|
||||
t.str(shortcut_table[i].default_text)
|
||||
t.str(
|
||||
match self.shortcuts.conflict(i) {
|
||||
Some(j) => shortcut_table[j].label
|
||||
None => ""
|
||||
},
|
||||
)
|
||||
t.int(if self.shortcut_capture == i { 1 } else { 0 })
|
||||
t.end_row()
|
||||
}
|
||||
@wasm.publish(Shortcuts, t)
|
||||
}
|
||||
@@ -9,6 +9,9 @@
|
||||
/// :theme :light ; the settings module's Dark mode switch is off (absent: dark)
|
||||
/// :power {:screen-off 5 :suspend 30} ; minutes without input before the screen goes off /
|
||||
/// ; the computer suspends, 0 never (absent: 10 and 0)
|
||||
/// :shortcuts {:show-desktop "Super+Ctrl+D" :screenshot-full ""}
|
||||
/// ; keyboard shortcuts changed from their defaults ("" unbinds;
|
||||
/// ; ids and combo syntax in shortcuts.mbt)
|
||||
/// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]
|
||||
/// ; the windows open when the last session ended, reopened at
|
||||
/// ; the next start (see session.mbt in compositor/host)
|
||||
@@ -38,6 +41,8 @@ pub(all) struct SavedState {
|
||||
dark_mode : Bool?
|
||||
/// From `:power`: (screen-off, suspend) minutes; a missing one keeps its default.
|
||||
power : (Int?, Int?)
|
||||
/// From `:shortcuts`: (id, combo text) pairs; empty when the file doesn't say.
|
||||
shortcuts : Array[(String, String)]
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -51,7 +56,7 @@ let layout_names : Array[String] = ["tiling", "monocle", "floating"]
|
||||
///| The keys this build owns; everything else in the file is kept as it is.
|
||||
let owned_keys : Array[String] = [
|
||||
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows",
|
||||
"theme", "power",
|
||||
"theme", "power", "shortcuts",
|
||||
]
|
||||
|
||||
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
|
||||
@@ -97,6 +102,7 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
remember_windows: None,
|
||||
dark_mode: None,
|
||||
power: (None, None),
|
||||
shortcuts: [],
|
||||
}
|
||||
}
|
||||
let entries = read_state_file()
|
||||
@@ -208,6 +214,19 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
}
|
||||
_ => (None, None)
|
||||
},
|
||||
shortcuts: match lookup_key(entries, "shortcuts") {
|
||||
Some(Mapping(m)) => {
|
||||
let out : Array[(String, String)] = []
|
||||
for e in m {
|
||||
match e {
|
||||
(Keyword(k), Text(v)) | (Text(k), Text(v)) => out.push((k, v))
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
_ => []
|
||||
},
|
||||
dark_mode: match lookup_key(entries, "theme") {
|
||||
Some(Keyword("light")) => Some(false)
|
||||
Some(Keyword("dark")) => Some(true)
|
||||
@@ -245,6 +264,7 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
|
||||
Some(m) if m >= 0 => self.suspend_min = m
|
||||
_ => ()
|
||||
}
|
||||
self.shortcuts.apply_saved(st.shortcuts)
|
||||
match st.desk {
|
||||
Some((x, y)) => {
|
||||
self.desk_set = true
|
||||
@@ -323,6 +343,12 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
|
||||
(@edn.Value::Keyword("suspend"), @edn.Value::Integer(self.suspend_min.to_string())),
|
||||
])))
|
||||
}
|
||||
let changed = self.shortcuts.changed()
|
||||
if changed.length() > 0 {
|
||||
entries.insert(2, (@edn.Value::Keyword("shortcuts"), @edn.Value::Mapping(
|
||||
changed.map(c => (@edn.Value::Keyword(c.0), @edn.Value::Text(c.1))),
|
||||
)))
|
||||
}
|
||||
if !self.dark_mode {
|
||||
entries.insert(2, (@edn.Value::Keyword("theme"), @edn.Value::Keyword("light")))
|
||||
}
|
||||
|
||||
@@ -535,6 +535,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
|
||||
if self.widgets.iter().any(w => w.has_cap("power")) {
|
||||
@wasm.publish_power(self.screen_off_min, self.suspend_min)
|
||||
}
|
||||
if self.widgets.iter().any(w => w.has_cap("shortcuts")) {
|
||||
self.publish_shortcuts()
|
||||
}
|
||||
if self.widgets.iter().any(w => w.has_cap("screenshot")) {
|
||||
@wasm.publish_screenshot(self.screenshot_state)
|
||||
}
|
||||
@@ -656,6 +659,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
|
||||
Some(Screenshot(code)) => self.actions.push(Screenshot(code))
|
||||
Some(SetScreenOff(m)) => self.set_power_timeouts(m, self.suspend_min)
|
||||
Some(SetSuspendAfter(m)) => self.set_power_timeouts(self.screen_off_min, m)
|
||||
Some(Shortcut(code)) => self.shortcut_request(code)
|
||||
Some(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) }
|
||||
Some(Network(code, ssid, password)) => self.network_request(code, ssid, password)
|
||||
Some(SetInspector(on)) => self.set_inspecting(on)
|
||||
@@ -737,6 +741,8 @@ pub(all) enum SettingsTab {
|
||||
Panel
|
||||
/// Battery, idle timeouts, suspend / restart / power off.
|
||||
Power
|
||||
/// The keyboard shortcuts: rebind, reset.
|
||||
Shortcuts
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///| Open the settings module ("System settings") on `tab`, loading it into the panel first if it
|
||||
@@ -765,12 +771,13 @@ pub fn DesktopShell::open_settings(self : DesktopShell, tab : SettingsTab) -> Bo
|
||||
if w.popup_rect.w == 0 {
|
||||
ignore(self.deliver(w, false, PointerDown(0, 0)))
|
||||
}
|
||||
// The module's keys 1-4 pick its tabs.
|
||||
// The module's keys 1-5 pick its tabs.
|
||||
let key = match tab {
|
||||
Session => "1"
|
||||
Desktop => "2"
|
||||
Panel => "3"
|
||||
Power => "4"
|
||||
Shortcuts => "5"
|
||||
}
|
||||
ignore(self.deliver(w, true, KeyDown(key)))
|
||||
self.save_panel_config()
|
||||
|
||||
Reference in new issue
Block a user