Files
qbz/crates/qbz-ui/ui/shell/CustomizeShortcutsModal.slint
T
vicrodh bf20144622 fix(hotkeys): solid arrow glyphs + centered reset-all icon
The thin Unicode arrows (left/right/up/down) were nearly headless at keycap
size even after the font bump, so the arrow-key shortcuts use solid triangle
glyphs now. The footer Reset All to Defaults icon rode high next to its label
(a bare fixed-size icon in the row) — wrapped in a centered column.

cc
2026-06-30 15:26:37 -06:00

367 lines
16 KiB
Plaintext

// "Customize Shortcuts" — the EDITABLE keybindings editor. 1:1 port of the
// Tauri `KeybindingsSettings.svelte` + `ShortcutInput.svelte`.
//
// Groups actions by category; each row shows its label and a clickable keycap
// button. Clicking the keycap enters RECORDING mode ("Press keys…"): the
// actual key capture happens in RUST (the winit handler reads
// KeybindingsState.recording-id and writes pending-display / conflict-label);
// this modal ONLY flips state via start-record / cancel-record and DISPLAYS
// the live combo + any conflict. A per-row reset appears when the binding is
// modified, a header badge counts modifications, and a footer "Reset All to
// Defaults" button reverts everything.
//
// Self-gated mount (ADR-010): AppShell mounts this with width/height 100%; the
// root fills the window and centers its panel over a dimming scrim. Opened via
// KeyboardShortcutsState.customize-open.
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { Spacing } from "../foundation/spacing.slint";
import {
KeyboardShortcutsState,
KeybindingsState,
KeybindingsActions,
KeybindingCategoryGroup,
} from "../state.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
// One editable category block (header + capture rows). Extracted so the body
// can lay the categories out across three columns instead of one tall column.
component KbEditGroup inherits VerticalLayout {
in property <KeybindingCategoryGroup> group;
spacing: Spacing.sm;
// Category header.
Text {
text: group.label;
color: Theme.text-muted;
font-size: Typography.legal;
font-weight: Typography.semibold;
}
for entry in group.rows: HorizontalLayout {
spacing: 10px;
min-height: 36px;
// LEFT: action label.
Text {
text: entry.label;
color: Theme.text-primary;
font-size: Typography.body;
vertical-alignment: center;
horizontal-stretch: 1;
}
// RIGHT: keycap capture button + reset, conflict message below.
VerticalLayout {
spacing: 4px;
alignment: center;
HorizontalLayout {
spacing: 8px;
alignment: end;
// Keycap button (Radius.sm rect, NOT a pill — ADR-008).
capture := Rectangle {
property <bool> recording: KeybindingsState.recording-id == entry.id;
property <bool> conflicting: self.recording && KeybindingsState.conflict-label != "";
width: Math.max(120px, cap-label.preferred-width + 24px);
height: 32px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
border-radius: Radius.sm;
background: capture.recording
? Theme.bg-hover
: (cap-ta.has-hover ? Theme.surface-hover : Theme.surface-elevated);
border-width: (capture.recording || entry.modified) ? 2px : 1px;
border-color: capture.conflicting
? Theme.danger
: (capture.recording
? Theme.accent
: (entry.modified ? Theme.accent : Theme.border-subtle));
cap-label := Text {
text: capture.recording
? (KeybindingsState.pending-display != ""
? KeybindingsState.pending-display
: @tr("Press keys…"))
: entry.shortcut;
color: Theme.text-primary;
font-size: Typography.body;
font-weight: Typography.medium;
font-family: "monospace";
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
}
cap-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
KeybindingsActions.start-record(entry.id);
}
}
}
// Per-row reset — only when modified.
if entry.modified: reset-row := Rectangle {
width: 30px;
height: 30px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
border-radius: Radius.sm;
background: reset-ta.has-hover ? Theme.surface-hover : Theme.surface-elevated;
border-width: 1px;
border-color: Theme.border-subtle;
QbzIcon {
source: @image-url("../assets/icons/rotate-ccw.svg");
width: 14px;
height: 14px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: reset-ta.has-hover ? Theme.text-primary : Theme.text-muted;
}
reset-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
KeybindingsActions.reset-one(entry.id);
}
}
}
}
// Conflict message BELOW the keycap.
if KeybindingsState.recording-id == entry.id
&& KeybindingsState.conflict-label != "": Text {
text: @tr("Already used by") + " " + KeybindingsState.conflict-label;
color: Theme.danger;
font-size: Typography.legal;
horizontal-alignment: right;
}
}
}
}
export component CustomizeShortcutsModal inherits Rectangle {
visible: KeyboardShortcutsState.customize-open;
if KeyboardShortcutsState.customize-open: Rectangle {
background: #000000bf;
// Scrim: a click outside the panel closes the editor (and cancels any
// in-progress recording so we never leave a dangling capture).
TouchArea {
mouse-cursor: default;
clicked => {
KeybindingsState.recording-id = "";
KeybindingsActions.cancel-record();
KeyboardShortcutsState.customize-open = false;
}
}
// The panel is a FocusScope so Escape cancels recording if recording,
// else closes the modal (mirrors the Svelte handler).
keys := FocusScope {
width: Math.min(root.width - 80px, 1080px);
height: Math.min(Math.max(420px, panel.preferred-height), root.height - 80px);
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
key-pressed(event) => {
if (event.text == Key.Escape) {
if (KeybindingsState.recording-id != "") {
KeybindingsActions.cancel-record();
} else {
KeyboardShortcutsState.customize-open = false;
}
return accept;
}
return reject;
}
// Deferred mount focus so Escape works immediately (synchronous
// focus during the remount races layout — same idiom as the
// PlaylistPickerModal).
focus-timer := Timer {
interval: 30ms;
running: true;
triggered => {
self.running = false;
keys.focus();
}
}
card := Rectangle {
border-radius: Radius.md;
background: Theme.surface-card;
border-width: 1px;
border-color: Theme.border-subtle;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
// Swallow clicks so they don't reach the scrim.
TouchArea { }
panel := VerticalLayout {
padding: 0px;
spacing: 0px;
// ---- Header: title + "N modified" badge + close-x -------
HorizontalLayout {
padding-left: Spacing.lg;
padding-right: Spacing.lg;
padding-top: Spacing.md;
padding-bottom: Spacing.md;
spacing: 10px;
Text {
text: @tr("Customize Shortcuts");
color: Theme.text-primary;
font-size: Typography.section;
font-weight: Typography.semibold;
vertical-alignment: center;
}
if KeybindingsState.modified-count > 0: Rectangle {
width: badge-label.preferred-width + 16px;
height: 20px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
border-radius: Radius.sm;
background: Theme.accent;
badge-label := Text {
text: KeybindingsState.modified-count + " " + @tr("modified");
color: Theme.accent-text;
font-size: Typography.legal;
font-weight: Typography.medium;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
}
}
// Spacer pushes the close-x to the right edge.
Rectangle { horizontal-stretch: 1; }
close-x := TouchArea {
width: 28px;
height: 28px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
mouse-cursor: pointer;
clicked => {
KeybindingsState.recording-id = "";
KeybindingsActions.cancel-record();
KeyboardShortcutsState.customize-open = false;
}
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 17px;
height: 17px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: close-x.has-hover ? Theme.text-primary : Theme.text-muted;
}
}
}
// Divider under the header.
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
// ---- Scrollable body ------------------------------------
Flickable {
vertical-stretch: 1;
viewport-width: self.width;
viewport-height: groups-col.preferred-height;
// Categories laid out across THREE columns (round-robin
// by index, same split as the read-only cheatsheet) so
// the editor fits without a tall scroll.
groups-col := HorizontalLayout {
padding-left: Spacing.lg;
padding-right: Spacing.lg;
padding-top: Spacing.md;
padding-bottom: Spacing.md;
spacing: Spacing.lg;
VerticalLayout {
alignment: start;
spacing: Spacing.lg;
for group in KeybindingsState.groups-col1: KbEditGroup { group: group; }
}
VerticalLayout {
alignment: start;
spacing: Spacing.lg;
for group in KeybindingsState.groups-col2: KbEditGroup { group: group; }
}
VerticalLayout {
alignment: start;
spacing: Spacing.lg;
for group in KeybindingsState.groups-col3: KbEditGroup { group: group; }
}
}
}
// Divider above the footer.
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
// ---- Footer: "Reset All to Defaults" --------------------
HorizontalLayout {
padding-left: Spacing.lg;
padding-right: Spacing.lg;
padding-top: Spacing.md;
padding-bottom: Spacing.md;
alignment: center;
reset-all := Rectangle {
property <bool> active: KeybindingsState.modified-count > 0;
height: 38px;
horizontal-stretch: 0;
border-radius: Radius.sm;
opacity: reset-all.active ? 1.0 : 0.3;
background: (reset-all.active && reset-all-ta.has-hover) ? Theme.danger-bg : transparent;
border-width: 1px;
border-color: Theme.danger;
reset-all-row := HorizontalLayout {
alignment: center;
spacing: 8px;
padding-left: 16px;
padding-right: 16px;
// Wrap the icon so it sits on the text's vertical
// center (a bare fixed-size icon in the row rode
// high next to the body-size label).
VerticalLayout {
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/rotate-ccw.svg");
width: 14px;
height: 14px;
tint: Theme.danger;
}
}
Text {
text: @tr("Reset All to Defaults");
color: Theme.danger;
font-size: Typography.body;
vertical-alignment: center;
}
}
reset-all-ta := TouchArea {
mouse-cursor: reset-all.active ? pointer : default;
clicked => {
if (reset-all.active) {
KeybindingsActions.reset-all();
}
}
}
}
}
}
}
}
}
}