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
+1303 -148

No files matched your search

+2 -1
View File
@@ -109,7 +109,8 @@ goes through `scripts/as-root`, which prefers run0 and falls back to sudo, doas
* Window positions are remembered per app, and on login the session reopens the windows the last * Window positions are remembered per app, and on login the session reopens the windows the last
one ended with (switch it off in Settings, or start with `--no-restore`). one ended with (switch it off in Settings, or start with `--no-restore`).
**Shortcuts** **Shortcuts** (the defaults; rebind any of them in Settings > Shortcuts: click one and press the
new keys)
| Keys | Action | | Keys | Action |
|---|---| |---|---|
@@ -6,6 +6,7 @@ import {
"chandra/desktop/interface/chandra/desktop/modules" @modules, "chandra/desktop/interface/chandra/desktop/modules" @modules,
"chandra/desktop/interface/chandra/desktop/power" @power, "chandra/desktop/interface/chandra/desktop/power" @power,
"chandra/desktop/interface/chandra/desktop/system" @system, "chandra/desktop/interface/chandra/desktop/system" @system,
"chandra/desktop/interface/chandra/desktop/shortcuts" @shortcuts,
"chandra/desktop/lib/ui" @ui, "chandra/desktop/lib/ui" @ui,
} }
@@ -13,16 +13,22 @@
/// menu's "Modules..." opens this tab; /// menu's "Modules..." opens this tab;
/// - Power: the battery (`system`, when there is one), how long without input before the screen /// - 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, /// 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 /// 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 /// 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 /// (or 1-5) 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 /// the highlighted panel module (or resets the highlighted shortcut) and PageUp/PageDown move it,
/// panel.edn. /// 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. ///| 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 let margin : Int = 6
@@ -44,7 +50,7 @@ let switch_w : Int = 34
let switch_h : Int = 18 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. ///| A popup row.
enum Row { enum Row {
@@ -66,6 +72,18 @@ enum Row {
Timeout(Int, String) Timeout(Int, String)
/// Suspend (0), power off (1) or restart (2) now. /// Suspend (0), power off (1) or restart (2) now.
PowerNow(Int, String) 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). ///| The timeout choices, in minutes (0: never).
@@ -179,6 +197,21 @@ fn rows() -> Array[Row] {
rs.push(PowerNow(2, "Restart")) rs.push(PowerNow(2, "Restart"))
rs.push(PowerNow(1, "Power off")) 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")) rs.push(Heading("In the panel, left to right"))
let loaded = @modules.loaded() let loaded = @modules.loaded()
@@ -330,6 +363,7 @@ let hover_btn : Ref[Int] = { val: -1 }
///| ///|
fn set_tab(i : Int) -> Unit { fn set_tab(i : Int) -> Unit {
cancel_capture()
tab.val = i tab.val = i
armed.val = -1 armed.val = -1
hover.val = first_active(rows()) hover.val = first_active(rows())
@@ -338,14 +372,27 @@ fn set_tab(i : Int) -> Unit {
///| ///|
fn close() -> Unit { fn close() -> Unit {
cancel_capture()
open_.val = false open_.val = false
armed.val = -1 armed.val = -1
hover.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 ///| 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). /// 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) { if !active(rs, i) {
return return
} }
@@ -367,6 +414,15 @@ fn act(rs : Array[Row], i : Int, btn~ : Int = -1) -> Unit {
armed.val = a armed.val = a
} }
Info(_) => () 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, _) => { Setting(k, _) => {
let idx = k.reinterpret_as_uint() let idx = k.reinterpret_as_uint()
@settings.set_setting(idx, !@settings.is_on(idx)) @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.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)) 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) => { Timeout(k, label) => {
let m = if k == 0 { @power.screen_off_minutes() } else { @power.suspend_minutes() } 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)) 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 } 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)) 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 }) 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 { } else {
-1 -1
} }
act(rs, i, btn~) act(rs, i, btn~, x=p.x)
// A module list changes length: keep the highlight on a real row. // A module list changes length: keep the highlight on a real row.
let after = rows() let after = rows()
hover.val = if active(after, i) { i } else { first_active(after) } 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 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 _ => false
} }
} else if k == "ArrowDown" || k == "Down" { } 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" { } else if k == "ArrowLeft" || k == "Left" {
set_tab((tab.val + tab_names.length() - 1) % tab_names.length()) set_tab((tab.val + tab_names.length() - 1) % tab_names.length())
true 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()) set_tab(k[0].to_int() - '1'.to_int())
true true
} else { } else {
+27 -10
View File
@@ -71,12 +71,19 @@ pub(all) struct ChandraCompositor {
mut press_fwd : Bool mut press_fwd : Bool
mut kbd_win : UInt64? mut kbd_win : UInt64?
mut mods : UInt 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 mut super_solo : Bool
/// Super+D (showdesktop.mbt): whether a Super key is held, whether the D press was swallowed, /// Whether a Super key is held (shortcuts.mbt).
/// and the windows it minimized (bottom to top) so a second Super+D can restore them.
mut super_down : Bool 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 desktop_hidden : Array[UInt64]
mut layout_mode : @wm.LayoutMode mut layout_mode : @wm.LayoutMode
/// Set when the user asked to end the session (the logout button); the main loop then exits. /// 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, mods: 0U,
super_solo: false, super_solo: false,
super_down: false, super_down: false,
d_swallowed: false, sc_swallow: [],
capture_swallow: [],
capture_super: false,
desktop_hidden: [], desktop_hidden: [],
layout_mode: @wm.LayoutMode::Tiling, layout_mode: @wm.LayoutMode::Tiling,
quit_requested: false, quit_requested: false,
@@ -1260,6 +1269,15 @@ pub fn ChandraCompositor::handle_input(
time_ms : UInt, time_ms : UInt,
) -> Unit { ) -> Unit {
self.note_activity(@sys.monotonic_ms()) 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) { if self.screenshot_input(ev, time_ms) {
return return
} }
@@ -1498,17 +1516,16 @@ pub fn ChandraCompositor::handle_input(
Key(code, pressed) => Key(code, pressed) =>
if self.switcher_key(code, pressed, time_ms) { if self.switcher_key(code, pressed, time_ms) {
self.super_solo = false self.super_solo = false
} else if self.show_desktop_key(code, pressed) { } else if self.shortcut_key(code, pressed) {
self.super_solo = false self.super_solo = false
} else if code == 125U || code == 126U { } 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 { if pressed {
self.super_solo = true self.super_solo = true
} else if self.super_solo { } else if self.super_solo {
self.super_solo = false self.super_solo = false
if !self.shell.inspecting() { self.super_tap()
self.shell.toggle_launcher()
}
} }
} else if self.shell.inspecting() { } else if self.shell.inspecting() {
self.super_solo = false self.super_solo = false
+1 -7
View File
@@ -1,6 +1,6 @@
///| Screen recording, after Spectacle's recording modes. ///| 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 /// 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 /// 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 /// 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). /// 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. /// 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. ///| A recording in progress.
pub(all) struct Recording { pub(all) struct Recording {
/// The part of the screen recorded (even width and height, as H.264 wants). /// The part of the screen recorded (even width and height, as H.264 wants).
+6 -61
View File
@@ -7,7 +7,7 @@
/// picture, Escape cancels; F takes the whole screen and W the active window instead, the arrow /// picture, Escape cancels; F takes the whole screen and W the active window instead, the arrow
/// keys nudge the selection (Shift+arrows resize it). /// 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 /// active window, Super+Ctrl+Print the window under the pointer. The screenshot panel module
/// offers the same four modes. /// 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 /// user-dirs.dirs names one), put on the clipboard as image/png, and a notification with a
/// thumbnail confirms it for a few seconds. /// thumbnail confirms it for a few seconds.
///| evdev codes. ///| evdev codes (keys on the overlay; the shortcuts themselves are in the shortcut table,
let key_s : UInt = 31 /// compositor/shell/shortcuts.mbt, and can be rebound in Settings > Shortcuts).
///|
let key_print : UInt = 99
///|
let key_enter : UInt = 28 let key_enter : UInt = 28
///| ///|
@@ -46,9 +41,6 @@ let mod_shift : UInt = 1
///| ///|
let mod_ctrl : UInt = 4 let mod_ctrl : UInt = 4
///|
let mod_logo : UInt = 64
///| What a screenshot takes. ///| What a screenshot takes.
pub(all) enum ShotMode { pub(all) enum ShotMode {
/// Draw a rectangle on the overlay (or click a window). /// 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 { fn ChandraCompositor::screenshot_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool {
if code == key_lsuper || code == key_rsuper { if code == key_lsuper || code == key_rsuper {
self.super_down = pressed // shared with Super+D
if self.shot is Some(_) { if self.shot is Some(_) {
self.super_solo = false self.super_solo = false
return true return true
@@ -613,62 +604,16 @@ fn ChandraCompositor::screenshot_key(self : ChandraCompositor, code : UInt, pres
} }
return self.shot is Some(_) 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 { match self.shot {
Some(o) => { Some(o) => {
self.shot_swallow.push(code) 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 true
} }
// The shortcuts that start screenshots and recordings are in the shortcut table (shortcuts.mbt).
None => false None => false
} }
} }
}
}
///| A key press on the overlay. ///| A key press on the overlay.
fn ChandraCompositor::overlay_key(self : ChandraCompositor, o : ShotOverlay, code : UInt, shift : Bool, ctrl : Bool) -> Unit { fn ChandraCompositor::overlay_key(self : ChandraCompositor, o : ShotOverlay, code : UInt, shift : Bool, ctrl : Bool) -> Unit {
+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 /// (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 /// was on top focused. Opening or restoring a window in between starts over: the next time
/// clears the screen again. Neither the D press nor its release reaches a client. /// clears the screen again. Neither the key press nor its release reaches a client.
///|
/// evdev codes.
let key_d : UInt32 = 32
///| ///|
/// evdev codes of the Super keys.
let key_lsuper : UInt32 = 125 let key_lsuper : UInt32 = 125
///| ///|
let key_rsuper : UInt32 = 126 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. /// Minimize all visible windows of the active workspace, or restore the ones Super+D hid.
pub fn ChandraCompositor::toggle_show_desktop( 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 /// 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, /// 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. /// that had focus is told Alt was let go so it doesn't think it is still held.
///| evdev codes. ///| evdev codes.
let key_tab : UInt = 15
///|
let key_esc : UInt = 1 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). ///| 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 { fn ChandraCompositor::switcher_key(self : ChandraCompositor, code : UInt, pressed : Bool, time_ms : UInt) -> Bool {
if code == key_lalt || code == key_ralt { let combo = self.shell.shortcuts.combo_for(SwitchWindows)
self.alt_down = pressed let hold = match combo {
if !pressed && self.switcher_on { 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) 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 { if !pressed {
// Releases of keys we swallowed must not reach a client either. // 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() { // The combo's modifiers held (Shift may be added, to go backwards).
let shift = (self.mods & 1U) != 0U 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 { if !self.switcher_on {
let c = self.switcher_candidates() let c = self.switcher_candidates()
if c.length() < 2 { 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 { match self.kbd_win {
Some(w) => { 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) self.server.keyboard_modifiers(w, 0U, 0U, 0U, 0U)
} }
None => () None => ()
+6
View File
@@ -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. /// (0: never). Saved in state.edn as :power {:screen-off 10 :suspend 0} when not the defaults.
mut screen_off_min : Int mut screen_off_min : Int
mut suspend_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_set : Bool
mut desk_x : Int mut desk_x : Int
mut desk_y : Int mut desk_y : Int
@@ -373,6 +377,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
dark_mode: true, dark_mode: true,
screen_off_min: default_screen_off_min, screen_off_min: default_screen_off_min,
suspend_min: default_suspend_min, suspend_min: default_suspend_min,
shortcuts: Shortcuts::defaults(),
shortcut_capture: -1,
desk_set: false, desk_set: false,
desk_x: 0, desk_x: 0,
desk_y: 0, desk_y: 0,
+489
View File
@@ -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)
}
+27 -1
View File
@@ -9,6 +9,9 @@
/// :theme :light ; the settings module's Dark mode switch is off (absent: dark) /// :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 / /// :power {:screen-off 5 :suspend 30} ; minutes without input before the screen goes off /
/// ; the computer suspends, 0 never (absent: 10 and 0) /// ; 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}] /// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]
/// ; the windows open when the last session ended, reopened at /// ; the windows open when the last session ended, reopened at
/// ; the next start (see session.mbt in compositor/host) /// ; the next start (see session.mbt in compositor/host)
@@ -38,6 +41,8 @@ pub(all) struct SavedState {
dark_mode : Bool? dark_mode : Bool?
/// From `:power`: (screen-off, suspend) minutes; a missing one keeps its default. /// From `:power`: (screen-off, suspend) minutes; a missing one keeps its default.
power : (Int?, Int?) 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. ///| The keys this build owns; everything else in the file is kept as it is.
let owned_keys : Array[String] = [ let owned_keys : Array[String] = [
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows", "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. ///| 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, remember_windows: None,
dark_mode: None, dark_mode: None,
power: (None, None), power: (None, None),
shortcuts: [],
} }
} }
let entries = read_state_file() let entries = read_state_file()
@@ -208,6 +214,19 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
} }
_ => (None, None) _ => (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") { dark_mode: match lookup_key(entries, "theme") {
Some(Keyword("light")) => Some(false) Some(Keyword("light")) => Some(false)
Some(Keyword("dark")) => Some(true) 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 Some(m) if m >= 0 => self.suspend_min = m
_ => () _ => ()
} }
self.shortcuts.apply_saved(st.shortcuts)
match st.desk { match st.desk {
Some((x, y)) => { Some((x, y)) => {
self.desk_set = true 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())), (@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 { if !self.dark_mode {
entries.insert(2, (@edn.Value::Keyword("theme"), @edn.Value::Keyword("light"))) entries.insert(2, (@edn.Value::Keyword("theme"), @edn.Value::Keyword("light")))
} }
+8 -1
View File
@@ -535,6 +535,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
if self.widgets.iter().any(w => w.has_cap("power")) { if self.widgets.iter().any(w => w.has_cap("power")) {
@wasm.publish_power(self.screen_off_min, self.suspend_min) @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")) { if self.widgets.iter().any(w => w.has_cap("screenshot")) {
@wasm.publish_screenshot(self.screenshot_state) @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(Screenshot(code)) => self.actions.push(Screenshot(code))
Some(SetScreenOff(m)) => self.set_power_timeouts(m, self.suspend_min) Some(SetScreenOff(m)) => self.set_power_timeouts(m, self.suspend_min)
Some(SetSuspendAfter(m)) => self.set_power_timeouts(self.screen_off_min, m) 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(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) }
Some(Network(code, ssid, password)) => self.network_request(code, ssid, password) Some(Network(code, ssid, password)) => self.network_request(code, ssid, password)
Some(SetInspector(on)) => self.set_inspecting(on) Some(SetInspector(on)) => self.set_inspecting(on)
@@ -737,6 +741,8 @@ pub(all) enum SettingsTab {
Panel Panel
/// Battery, idle timeouts, suspend / restart / power off. /// Battery, idle timeouts, suspend / restart / power off.
Power Power
/// The keyboard shortcuts: rebind, reset.
Shortcuts
} derive(Eq, Debug) } derive(Eq, Debug)
///| Open the settings module ("System settings") on `tab`, loading it into the panel first if it ///| 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 { if w.popup_rect.w == 0 {
ignore(self.deliver(w, false, PointerDown(0, 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 { let key = match tab {
Session => "1" Session => "1"
Desktop => "2" Desktop => "2"
Panel => "3" Panel => "3"
Power => "4" Power => "4"
Shortcuts => "5"
} }
ignore(self.deliver(w, true, KeyDown(key))) ignore(self.deliver(w, true, KeyDown(key)))
self.save_panel_config() self.save_panel_config()
+7
View File
@@ -263,6 +263,8 @@ pub(all) enum HostTable {
NetStatus NetStatus
/// Wi-Fi networks in range (siiii: ssid signal secured active saved). /// Wi-Fi networks in range (siiii: ssid signal secured active saved).
NetNetworks NetNetworks
/// Keyboard shortcuts (ssssi: name binding default-binding conflict capturing).
Shortcuts
} }
///| ///|
@@ -287,6 +289,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Icons => 7U Icons => 7U
NetStatus => 8U NetStatus => 8U
NetNetworks => 9U NetNetworks => 9U
Shortcuts => 10U
} }
// Most tables are republished every frame unchanged: skip the copy into the host then. // Most tables are republished every frame unchanged: skip the copy into the host then.
let slot = id.reinterpret_as_int() let slot = id.reinterpret_as_int()
@@ -359,6 +362,9 @@ pub(all) enum HostRequest {
/// A network module's action (0 scan, 1 disconnect, 2/3 Wi-Fi off/on, 4/5 airplane mode /// A network module's action (0 scan, 1 disconnect, 2/3 Wi-Fi off/on, 4/5 airplane mode
/// off/on, 6 connect, 7 forget), with the network name and password where it needs them. /// off/on, 6 connect, 7 forget), with the network name and password where it needs them.
Network(Int, String, String) Network(Int, String, String)
/// The shortcuts capability: action * 1000 + index (0 capture, 1 reset, 2 reset all, 3 cancel
/// the capture).
Shortcut(Int)
} derive(Eq, Debug) } derive(Eq, Debug)
///| ///|
@@ -381,6 +387,7 @@ pub fn next_request() -> HostRequest? {
Some(SetSuspendAfter(m)) => Some(SetSuspendAfter(m)) Some(SetSuspendAfter(m)) => Some(SetSuspendAfter(m))
Some(PowerAction(a)) => Some(PowerAction(a)) Some(PowerAction(a)) => Some(PowerAction(a))
Some(Network(r)) => Some(Network(r.action, r.ssid, r.password)) Some(Network(r)) => Some(Network(r.action, r.ssid, r.password))
Some(Shortcut(code)) => Some(Shortcut(code))
} }
} }
+7
View File
@@ -695,6 +695,8 @@ pub(all) enum HostTable {
NetStatus NetStatus
/// Wi-Fi networks in range (siiii: ssid signal secured active saved). /// Wi-Fi networks in range (siiii: ssid signal secured active saved).
NetNetworks NetNetworks
/// Keyboard shortcuts (ssssi: name binding default-binding conflict capturing).
Shortcuts
} }
///| Publish `t` as the data behind `which` for every module's next call. ///| Publish `t` as the data behind `which` for every module's next call.
@@ -710,6 +712,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Icons => 7 Icons => 7
NetStatus => 8 NetStatus => 8
NetNetworks => 9 NetNetworks => 9
Shortcuts => 10
} }
let out : Array[Byte] = [] let out : Array[Byte] = []
for k = 0; k < 4; k = k + 1 { for k = 0; k < 4; k = k + 1 {
@@ -781,6 +784,9 @@ pub(all) enum HostRequest {
/// A network module's action (0 scan, 1 disconnect, 2/3 Wi-Fi off/on, 4/5 airplane mode /// A network module's action (0 scan, 1 disconnect, 2/3 Wi-Fi off/on, 4/5 airplane mode
/// off/on, 6 connect, 7 forget), with the network name and password where it needs them. /// off/on, 6 connect, 7 forget), with the network name and password where it needs them.
Network(Int, String, String) Network(Int, String, String)
/// The shortcuts capability: action * 1000 + index (0 capture, 1 reset, 2 reset all, 3 cancel
/// the capture).
Shortcut(Int)
} derive(Eq, Debug) } derive(Eq, Debug)
///| ///|
@@ -820,6 +826,7 @@ pub fn next_request() -> HostRequest? {
None => Some(Network(code, s, "")) None => Some(Network(code, s, ""))
} }
} }
18 => Some(Shortcut(c_host_req_int()))
_ => None _ => None
} }
} }
+15 -2
View File
@@ -59,14 +59,15 @@ enum {
K_PW_SCREEN, K_PW_SET_SCREEN, K_PW_SUSP, K_PW_SET_SUSP, K_PW_SUSPEND, K_PW_OFF, K_PW_REBOOT, K_PW_SCREEN, K_PW_SET_SCREEN, K_PW_SUSP, K_PW_SET_SUSP, K_PW_SUSPEND, K_PW_OFF, K_PW_REBOOT,
K_BAT_READ, K_BAT_READ,
K_NET_STATUS, K_NET_LIST, K_NET_SCAN, K_NET_CONNECT, K_NET_DISCONNECT, K_NET_FORGET, K_NET_SET_WIFI, K_NET_STATUS, K_NET_LIST, K_NET_SCAN, K_NET_CONNECT, K_NET_DISCONNECT, K_NET_FORGET, K_NET_SET_WIFI,
K_NET_SET_AIRPLANE K_NET_SET_AIRPLANE,
K_SC_LIST, K_SC_CAPTURE, K_SC_CANCEL, K_SC_RESET, K_SC_RESET_ALL
}; };
typedef struct Env { Inst *inst; int kind; } Env; typedef struct Env { Inst *inst; int kind; } Env;
/* ---- host data the shell publishes before calling a guest ---- /* ---- host data the shell publishes before calling a guest ----
* A table is [u32 rows] then rows of fields, each field a LE i32 ('i') or a u32 byte length + UTF-8 ('s'). */ * A table is [u32 rows] then rows of fields, each field a LE i32 ('i') or a u32 byte length + UTF-8 ('s'). */
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, T_ICONS, enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, T_ICONS,
T_NET_STATUS, T_NET_NETWORKS, T_N }; T_NET_STATUS, T_NET_NETWORKS, T_SHORTCUTS, T_N };
typedef struct { uint8_t *data; size_t len; } Blob; typedef struct { uint8_t *data; size_t len; } Blob;
static Blob tables[T_N]; static Blob tables[T_N];
static int32_t host_ints[12] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i), static int32_t host_ints[12] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
@@ -393,6 +394,13 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
* "ssid\x1fpassword" (see wit/host/plasmoids.wit network-request). */ * "ssid\x1fpassword" (see wit/host/plasmoids.wit network-request). */
case K_NET_STATUS: build_record(in, T_NET_STATUS, "iissbbbb", a0); break; case K_NET_STATUS: build_record(in, T_NET_STATUS, "iissbbbb", a0); break;
case K_NET_LIST: build_list(in, T_NET_NETWORKS, "sibbb", a0); break; case K_NET_LIST: build_list(in, T_NET_NETWORKS, "sibbb", a0); break;
/* Shortcuts: the list from table 10 (name binding default conflict capturing); request 18 is
* action * 1000 + index (0 capture, 1 reset, 2 reset all, 3 cancel the capture). */
case K_SC_LIST: build_list(in, T_SHORTCUTS, "ssssb", a0); break;
case K_SC_CAPTURE: if (a0 >= 0 && a0 < 1000) push_req(18, a0, NULL); break;
case K_SC_RESET: if (a0 >= 0 && a0 < 1000) push_req(18, 1000 + a0, NULL); break;
case K_SC_RESET_ALL: push_req(18, 2000, NULL); break;
case K_SC_CANCEL: push_req(18, 3000, NULL); break;
case K_NET_SCAN: push_req(16, 0, NULL); break; case K_NET_SCAN: push_req(16, 0, NULL); break;
case K_NET_DISCONNECT: push_req(16, 1, NULL); break; case K_NET_DISCONNECT: push_req(16, 1, NULL); break;
case K_NET_SET_WIFI: push_req(16, a0 ? 3 : 2, NULL); break; case K_NET_SET_WIFI: push_req(16, a0 ? 3 : 2, NULL); break;
@@ -588,6 +596,11 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "power") && !strcmp(fn, "suspend")) return K_PW_SUSPEND; if (!strcmp(iface, "power") && !strcmp(fn, "suspend")) return K_PW_SUSPEND;
if (!strcmp(iface, "power") && !strcmp(fn, "power-off")) return K_PW_OFF; if (!strcmp(iface, "power") && !strcmp(fn, "power-off")) return K_PW_OFF;
if (!strcmp(iface, "power") && !strcmp(fn, "reboot")) return K_PW_REBOOT; if (!strcmp(iface, "power") && !strcmp(fn, "reboot")) return K_PW_REBOOT;
if (!strcmp(iface, "shortcuts") && !strcmp(fn, "shortcuts")) return K_SC_LIST;
if (!strcmp(iface, "shortcuts") && !strcmp(fn, "capture")) return K_SC_CAPTURE;
if (!strcmp(iface, "shortcuts") && !strcmp(fn, "cancel-capture")) return K_SC_CANCEL;
if (!strcmp(iface, "shortcuts") && !strcmp(fn, "reset")) return K_SC_RESET;
if (!strcmp(iface, "shortcuts") && !strcmp(fn, "reset-all")) return K_SC_RESET_ALL;
if (!strcmp(iface, "network") && !strcmp(fn, "status")) return K_NET_STATUS; if (!strcmp(iface, "network") && !strcmp(fn, "status")) return K_NET_STATUS;
if (!strcmp(iface, "network") && !strcmp(fn, "wifi-networks")) return K_NET_LIST; if (!strcmp(iface, "network") && !strcmp(fn, "wifi-networks")) return K_NET_LIST;
if (!strcmp(iface, "network") && !strcmp(fn, "scan")) return K_NET_SCAN; if (!strcmp(iface, "network") && !strcmp(fn, "scan")) return K_NET_SCAN;
+1
View File
@@ -269,6 +269,7 @@ impl chandra::host::plasmoids::Host for State {
Req::Network(action, ssid, password) => { Req::Network(action, ssid, password) => {
R::Network(chandra::host::plasmoids::NetworkRequest { action, ssid, password }) R::Network(chandra::host::plasmoids::NetworkRequest { action, ssid, password })
} }
Req::Shortcut(code) => R::Shortcut(code),
}) })
} }
+37 -1
View File
@@ -57,6 +57,8 @@ pub enum Req {
/// A network action (0 scan, 1 disconnect, 2/3 Wi-Fi off/on, 4/5 airplane mode off/on, /// A network action (0 scan, 1 disconnect, 2/3 Wi-Fi off/on, 4/5 airplane mode off/on,
/// 6 connect, 7 forget), the network's name and the password. /// 6 connect, 7 forget), the network's name and the password.
Network(i32, String, String), Network(i32, String, String),
/// A shortcuts request: action * 1000 + index (0 capture, 1 reset, 2 reset all, 3 cancel).
Shortcut(i32),
} }
pub const T_APPS: usize = 0; pub const T_APPS: usize = 0;
@@ -72,11 +74,13 @@ pub const T_ICONS: usize = 7;
pub const T_NET_STATUS: usize = 8; pub const T_NET_STATUS: usize = 8;
/// Wi-Fi networks in range (siiii): ssid signal secured active saved. /// Wi-Fi networks in range (siiii): ssid signal secured active saved.
pub const T_NET_NETWORKS: usize = 9; pub const T_NET_NETWORKS: usize = 9;
/// Keyboard shortcuts (ssssi): name binding default-binding conflict capturing.
pub const T_SHORTCUTS: usize = 10;
/// Host data every module reads from, shared by all loaded modules. /// Host data every module reads from, shared by all loaded modules.
#[derive(Default)] #[derive(Default)]
pub struct Shared { pub struct Shared {
pub tables: [Vec<u8>; 10], pub tables: [Vec<u8>; 11],
pub layout_mode: i32, pub layout_mode: i32,
pub wallpaper: i32, pub wallpaper: i32,
/// Which session settings are on: bit i for row i of the session settings table. /// Which session settings are on: bit i for row i of the session settings table.
@@ -352,6 +356,38 @@ impl d::power::Host for PState {
} }
} }
impl d::shortcuts::Host for PState {
fn shortcuts(&mut self) -> Vec<d::shortcuts::Shortcut> {
self.rows(T_SHORTCUTS, "ssssi")
.iter()
.filter(|r| r.len() == 5)
.map(|r| d::shortcuts::Shortcut {
name: s(&r[0]),
binding: s(&r[1]),
default_binding: s(&r[2]),
conflict: s(&r[3]),
capturing: i(&r[4]) != 0,
})
.collect()
}
fn capture(&mut self, index: u32) {
if index < 1000 {
self.shared.borrow_mut().requests.push_back(Req::Shortcut(index as i32));
}
}
fn cancel_capture(&mut self) {
self.shared.borrow_mut().requests.push_back(Req::Shortcut(3000));
}
fn reset(&mut self, index: u32) {
if index < 1000 {
self.shared.borrow_mut().requests.push_back(Req::Shortcut(1000 + index as i32));
}
}
fn reset_all(&mut self) {
self.shared.borrow_mut().requests.push_back(Req::Shortcut(2000));
}
}
impl d::screenshot::Host for PState { impl d::screenshot::Host for PState {
fn take(&mut self, mode: u32) { fn take(&mut self, mode: u32) {
if mode <= 3 { if mode <= 3 {
@@ -0,0 +1,4 @@
Keyboard shortcuts: the compositor's named actions (open the launcher, show the desktop, switch
windows, screenshots, recordings) and the key combo each is bound to. The shell keeps changed
combos in state.edn and they apply at once; a module with this capability (the settings
module's Shortcuts tab) lists and rebinds them.
@@ -0,0 +1,43 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportShortcuts(p0 : Int) = "chandra:desktop/shortcuts@0.1.0" "shortcuts"
///|
fn wasmImportCapture(p0 : Int) = "chandra:desktop/shortcuts@0.1.0" "capture"
///|
fn wasmImportCancelCapture() = "chandra:desktop/shortcuts@0.1.0" "cancel-capture"
///|
fn wasmImportReset(p0 : Int) = "chandra:desktop/shortcuts@0.1.0" "reset"
///|
fn wasmImportResetAll() = "chandra:desktop/shortcuts@0.1.0" "reset-all"
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,62 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Shortcut {
name : String; binding : String; default_binding : String; conflict : String; capturing : Bool
}
///|
/// Every shortcut, in the order they are listed.
pub fn shortcuts() -> Array[Shortcut] {
let return_area = mbt_ffi_malloc(8)
wasmImportShortcuts(return_area);
let array : Array[Shortcut] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 36)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 24), mbt_ffi_load32((iter_base) + 28))
array.push(Shortcut::{name : result, binding : result0, default_binding : result1, conflict : result2, capturing : (mbt_ffi_load8_u((iter_base) + 32) != 0)})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Bind shortcut `index` to the next key combo pressed anywhere: the compositor takes that key
/// instead of acting on it. Escape cancels, Backspace unbinds. Window switching needs a combo
/// with a modifier (it keeps waiting otherwise).
pub fn capture(index : UInt) -> Unit {
wasmImportCapture((index).reinterpret_as_int());
}
///|
/// Stop waiting for a combo; the binding stays as it was.
pub fn cancel_capture() -> Unit {
wasmImportCancelCapture();
}
///|
/// Put shortcut `index` back to its default combo.
pub fn reset(index : UInt) -> Unit {
wasmImportReset((index).reinterpret_as_int());
}
///|
pub fn reset_all() -> Unit {
wasmImportResetAll();
}
@@ -110,6 +110,7 @@ pub(all) enum Request {
PowerAction(Int32) PowerAction(Int32)
Network(NetworkRequest) Network(NetworkRequest)
MoveInstance(InstanceMove) MoveInstance(InstanceMove)
Shortcut(Int32)
} }
pub(all) struct SettingChange { pub(all) struct SettingChange {
+7 -1
View File
@@ -58,6 +58,7 @@ pub(all) enum Request {
PowerAction(Int) PowerAction(Int)
Network(NetworkRequest) Network(NetworkRequest)
MoveInstance(InstanceMove) MoveInstance(InstanceMove)
Shortcut(Int)
} }
///| ///|
/// A native file-chooser dialog (zenity on the host session) for "Add widget". /// A native file-chooser dialog (zenity on the host session) for "Add widget".
@@ -390,7 +391,8 @@ pub fn set_config(handle : UInt, key : String, value : String) -> Bool {
/// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s), 6 session /// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s), 6 session
/// settings (s), 7 icons (si: app id, raster image handle from `raster.load-image`) served by `icons.app-icon`, /// settings (s), 7 icons (si: app id, raster image handle from `raster.load-image`) served by `icons.app-icon`,
/// 8 network status (one row, iissiiii: state signal name message wifi-enabled airplane /// 8 network status (one row, iissiiii: state signal name message wifi-enabled airplane
/// can-manage has-wifi), 9 Wi-Fi networks (siiii: ssid signal secured active saved). /// can-manage has-wifi), 9 Wi-Fi networks (siiii: ssid signal secured active saved), 10 keyboard
/// shortcuts (ssssi: name binding default-binding conflict capturing).
pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit { pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit {
let ptr = mbt_ffi_bytes2ptr(rows) let ptr = mbt_ffi_bytes2ptr(rows)
@@ -564,6 +566,10 @@ pub fn next_request() -> Request? {
Request::MoveInstance(InstanceMove::{slot : result4, delta : mbt_ffi_load32((return_area) + 16)}) Request::MoveInstance(InstanceMove::{slot : result4, delta : mbt_ffi_load32((return_area) + 16)})
} }
16 => {
Request::Shortcut(mbt_ffi_load32((return_area) + 8))
}
_ => panic() _ => panic()
} }
+1
View File
@@ -259,6 +259,7 @@ fn request_val(r : @wasm.HostRequest) -> @wt.Val {
"network", "network",
Some(Record([("action", S32(action)), ("ssid", Str(ssid)), ("password", Str(password))])), Some(Record([("action", S32(action)), ("ssid", Str(ssid)), ("password", Str(password))])),
) )
Shortcut(n) => Variant("shortcut", Some(S32(n)))
} }
} }
+31
View File
@@ -151,6 +151,37 @@ interface session-settings {
set-setting: func(index: u32, on: bool); set-setting: func(index: u32, on: bool);
} }
/// Keyboard shortcuts: the compositor's named actions (open the launcher, show the desktop, switch
/// windows, screenshots, recordings) and the key combo each is bound to. The shell keeps changed
/// combos in state.edn and they apply at once; a module with this capability (the settings
/// module's Shortcuts tab) lists and rebinds them.
interface shortcuts {
record shortcut {
/// What it does ("Show the desktop").
name: string,
/// Its combo as text, modifiers first ("Super+Shift+S"; "Super" alone is a tap of the Super
/// key); empty when unbound.
binding: string,
/// The combo it has by default.
default-binding: string,
/// The name of another shortcut on the same combo, or empty. The one listed first wins.
conflict: string,
/// Waiting for its new combo (see `capture`).
capturing: bool,
}
/// Every shortcut, in the order they are listed.
shortcuts: func() -> list<shortcut>;
/// Bind shortcut `index` to the next key combo pressed anywhere: the compositor takes that key
/// instead of acting on it. Escape cancels, Backspace unbinds. Window switching needs a combo
/// with a modifier (it keeps waiting otherwise).
capture: func(index: u32);
/// Stop waiting for a combo; the binding stays as it was.
cancel-capture: func();
/// Put shortcut `index` back to its default combo.
reset: func(index: u32);
reset-all: func();
}
/// Screenshots and screen recordings, after KDE Spectacle. The compositor captures (it alone sees /// Screenshots and screen recordings, after KDE Spectacle. The compositor captures (it alone sees
/// the screen); a module with this capability offers the modes and starts them. /// the screen); a module with this capability offers the modes and starts them.
interface screenshot { interface screenshot {
+5 -1
View File
@@ -56,7 +56,8 @@ interface plasmoids {
/// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s), 6 session /// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s), 6 session
/// settings (s), 7 icons (si: app id, raster image handle from `raster.load-image`) served by `icons.app-icon`, /// settings (s), 7 icons (si: app id, raster image handle from `raster.load-image`) served by `icons.app-icon`,
/// 8 network status (one row, iissiiii: state signal name message wifi-enabled airplane /// 8 network status (one row, iissiiii: state signal name message wifi-enabled airplane
/// can-manage has-wifi), 9 Wi-Fi networks (siiii: ssid signal secured active saved). /// can-manage has-wifi), 9 Wi-Fi networks (siiii: ssid signal secured active saved), 10 keyboard
/// shortcuts (ssssi: name binding default-binding conflict capturing).
publish-table: func(which: u32, rows: list<u8>); publish-table: func(which: u32, rows: list<u8>);
/// Layout mode (0 tiling, 1 monocle, 2 floating) and whether the Interface Explorer is on. /// Layout mode (0 tiling, 1 monocle, 2 floating) and whether the Interface Explorer is on.
publish-state: func(layout-mode: s32, inspector-on: bool); publish-state: func(layout-mode: s32, inspector-on: bool);
@@ -136,6 +137,9 @@ interface plasmoids {
power-action(s32), power-action(s32),
network(network-request), network(network-request),
move-instance(instance-move), move-instance(instance-move),
/// The shortcuts capability: action * 1000 + index (0 capture, 1 reset, 2 reset all,
/// 3 cancel the capture).
shortcut(s32),
} }
/// The next pending request, oldest first. /// The next pending request, oldest first.
next-request: func() -> option<request>; next-request: func() -> option<request>;
+3 -1
View File
@@ -83,6 +83,7 @@ world plasmoid-host {
import power; import power;
import battery; import battery;
import network; import network;
import shortcuts;
export plasmoid; export plasmoid;
} }
@@ -94,7 +95,7 @@ world logout-widget {
/// The settings module: session switches (restore, window places, dark mode), the wallpaper, the /// The settings module: session switches (restore, window places, dark mode), the wallpaper, the
/// panel's modules (load, unload, browse; the panel menu's "Modules..." opens that tab), and power /// panel's modules (load, unload, browse; the panel menu's "Modules..." opens that tab), and power
/// (idle timeouts, battery, suspend / restart / power off). /// (idle timeouts, battery, suspend / restart / power off) and keyboard shortcuts (rebind, reset).
world session-settings-widget { world session-settings-widget {
include widget; include widget;
import session-settings; import session-settings;
@@ -102,6 +103,7 @@ world session-settings-widget {
import modules; import modules;
import power; import power;
import system; import system;
import shortcuts;
} }
/// Screenshot and screen recording launcher. /// Screenshot and screen recording launcher.
+1 -1
View File
@@ -1,3 +1,3 @@
The settings module: session switches (restore, window places, dark mode), the wallpaper, the The settings module: session switches (restore, window places, dark mode), the wallpaper, the
panel's modules (load, unload, browse; the panel menu's "Modules..." opens that tab), and power panel's modules (load, unload, browse; the panel menu's "Modules..." opens that tab), and power
(idle timeouts, battery, suspend / restart / power off). (idle timeouts, battery, suspend / restart / power off) and keyboard shortcuts (rebind, reset).