Files
chandra/compositor/host/shortcuts.mbt
Claude 27252a97ab
CI / test (push) Canceled after 0s
Emoji picker (Super+.): search, tabs, skin tones, recents, text-input-v3 insertion
Compositor-drawn Win+. style picker. The focused app keeps keyboard focus so
its text-input-v3 field stays enabled; the emoji goes in with commit_string,
or onto the clipboard with a visible notice when the app has no text field.
Shortcut lives in the shortcut table (rebindable in Settings > Shortcuts).

- compositor/wayland/text_input.mbt: zwp_text_input_manager_v3 (global 12)
- compositor/emoji: Emoji 18.0 + CLDR 49 data (Unicode License), search,
  picker model, CBDT/CBLC + GSUB reader for Noto Color Emoji
- Chandra's own pinned bitmap Noto Color Emoji (scripts/fetch-emoji-font.sh,
  just emoji-font); Fedora's COLRv1 copy can't be drawn. Missing font shows
  an error panel.
- raster WIT: emoji-font, emoji-has, emoji-image; served by wasmhost
- state.edn :emoji {:recent [...] :skin-tone n}
- tests incl. a fake text-input client; docs/emoji-picker.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkABDGJixotaqFv2X2
2026-11-26 07:00:22 +00:00

155 lines
5.8 KiB
MoonBit

///| 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
}
let combo : @shell.KeyCombo = { mods: self.held_mods(), key: code }
match self.shell.shortcuts.lookup(combo) {
// Window switching is the switcher's (switcher_key runs before this).
Some(SwitchWindows) => false
// Super+2 .. Super+9 aren't in the table: they follow the "Open dock app" combo.
None | Some(DockApps) =>
match self.shell.shortcuts.dock_app(combo) {
Some(n) if self.open_dock_app(n) => {
self.sc_swallow.push(code)
self.super_solo = false
true
}
Some(_) => false
None => 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()
self.overview_sync() // the overview opens (or closes) with it
}
ShowDesktop => self.toggle_show_desktop()
Overview => if !self.shell.inspecting() { self.toggle_overview() }
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)
DockApps => ignore(self.open_dock_app(1))
EmojiPicker => self.toggle_emoji_picker()
}
}
///| Super+`n`: the dock's `n`-th app, as if its icon were clicked. False when there is no dock
/// or no such app (the key then goes to the focused window as usual).
fn ChandraCompositor::open_dock_app(self : ChandraCompositor, n : Int) -> Bool {
if self.shell.inspecting() || !self.shell.open_dock_item(n) {
return false
}
self.run_shell_actions()
self.damage.mark_full()
true
}
///| evdev code of Backspace (unbinds while capturing).
let key_backspace : UInt = 14