Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat(menus): the strip's menus open and work from the keyboard on Windows and Linux

Jareer9ec2cd38ce1d
diff --git a/src/crates/concat/ui/app.slint b/src/crates/concat/ui/app.slint
index 90f75d38..d0dfbb55 100644
--- a/src/crates/concat/ui/app.slint
+++ b/src/crates/concat/ui/app.slint
@@ -326,6 +326,18 @@ export component App inherits Window {
keys.focus();
}
+ // The strip's menus from the keyboard, the way Windows and Linux reach
+ // a menu bar: F10 opens File, Alt with a menu's letter opens that one,
+ // and in an open menu the arrows, Return and Escape do the rest. A Mac
+ // has its own conventions for this and none of them are these.
+ property <int> keyboard-menu: -1;
+ property <int> keyboard-menu-token;
+ property <bool> menu-by-keyboard;
+ function open-menu-from-keys(index: int) {
+ root.keyboard-menu = index;
+ root.keyboard-menu-token += 1;
+ }
+
/// The bottom-right notice: what just happened, said once. Set from Rust
/// and watched by its token — see ToastLayer, which owns the timing.
in property <ToastData> toast;
@@ -402,6 +414,26 @@ export component App inherits Window {
enabled: !root.on-start && !root.macos;
activated => { root.app-menu-selected("redo"); }
}
+ KeyBinding {
+ keys: @keys(F10);
+ enabled: !root.on-start && !root.macos && !root.phone;
+ activated => { root.open-menu-from-keys(0); }
+ }
+ KeyBinding {
+ keys: @keys(Alt + F);
+ enabled: !root.on-start && !root.macos && !root.phone;
+ activated => { root.open-menu-from-keys(0); }
+ }
+ KeyBinding {
+ keys: @keys(Alt + E);
+ enabled: !root.on-start && !root.macos && !root.phone;
+ activated => { root.open-menu-from-keys(1); }
+ }
+ KeyBinding {
+ keys: @keys(Alt + V);
+ enabled: !root.on-start && !root.macos && !root.phone;
+ activated => { root.open-menu-from-keys(2); }
+ }
// Open and Close Window work from the launch screen too: it opens
// projects, and it is a window.
KeyBinding {
@@ -559,11 +591,14 @@ export component App inherits Window {
status: root.project-status;
menu: root.open-menu;
- menu-opened(index, at-x) => {
+ keyboard-menu: root.keyboard-menu;
+ keyboard-token: root.keyboard-menu-token;
+ menu-opened(index, at-x, keyboard) => {
// Under the strip, which is 32px tall - both measured
// from the window's corner, past the system's bars.
appmenu.request-x = at-x + root.safe-area-insets.left;
appmenu.request-y = 32px + root.safe-area-insets.top;
+ root.menu-by-keyboard = keyboard;
root.menu-opened(index);
}
@@ -815,7 +850,10 @@ export component App inherits Window {
items: root.app-menu-items;
menu-height: root.app-menu-height;
token: root.app-menu-token;
+ keyboard: root.menu-by-keyboard;
selected(id) => { root.app-menu-selected(id); }
+ // The arrows walk the strip: File, Edit, View and round again.
+ neighbour(by) => { root.open-menu-from-keys(Math.mod(root.open-menu + by, 3)); }
}
// Last of all, and over everything including the sheets: an export that
diff --git a/src/crates/concat/ui/primitives/context-menu.slint b/src/crates/concat/ui/primitives/context-menu.slint
index 4b579a60..a26428a4 100644
--- a/src/crates/concat/ui/primitives/context-menu.slint
+++ b/src/crates/concat/ui/primitives/context-menu.slint
@@ -61,6 +61,44 @@ export component ContextMenu inherits Rectangle {
in property <length> menu-height;
callback selected(id: string);
+ /// Left or right from the keyboard: the menu beside this one, for a
+ /// menu bar to open. `by` is -1 or 1.
+ callback neighbour(by: int);
+
+ /// Opened from the keyboard: the first row is highlighted and the
+ /// surface takes the keys - the arrows, Return, Escape - so a menu is
+ /// usable without a pointer. Read when `token` changes.
+ in property <bool> keyboard;
+ /// The row the keyboard is on, or -1.
+ property <int> hot: -1;
+
+ /// Whether row `i` is one the keyboard can land on.
+ pure function usable(i: int) -> bool {
+ i >= 0 && i < root.items.length && root.items[i].kind == MenuRow.action
+ && root.items[i].enabled
+ }
+ pure function wrap(i: int) -> int {
+ Math.mod(i + root.items.length, root.items.length)
+ }
+ /// The next row the keyboard can land on from `from`, going `by`,
+ /// round the end. The expression language has no loop, so it looks a
+ /// fixed way ahead: past a separator and a heading is the most any of
+ /// these menus puts between two actions.
+ pure function next(from: int, by: int) -> int {
+ usable(wrap(from + by)) ? wrap(from + by)
+ : usable(wrap(from + 2 * by)) ? wrap(from + 2 * by)
+ : usable(wrap(from + 3 * by)) ? wrap(from + 3 * by)
+ : usable(wrap(from + 4 * by)) ? wrap(from + 4 * by)
+ : from
+ }
+ /// Reports row `i` and closes, the way a press on it does.
+ function choose(i: int) {
+ if (usable(i)) {
+ root.chosen = root.items[i].id;
+ report.running = true;
+ surface.close();
+ }
+ }
/// Where the menu was asked for, in this element's own coordinates.
property <length> at-x;
@@ -88,6 +126,9 @@ export component ContextMenu inherits Rectangle {
root.at-y = root.request-y + root.menu-height > root.height
? Math.max(0px, root.request-y - root.menu-height)
: root.request-y;
+ // From the top down, the way a menu opens from the keyboard
+ // everywhere: -1 steps onto row 0 or the first usable one.
+ root.hot = root.keyboard ? next(-1, 1) : -1;
surface.show();
}
}
@@ -114,6 +155,19 @@ export component ContextMenu inherits Rectangle {
}
}
+ /// Which way the keyboard left for the menu beside this one, held for
+ /// the same beat as `chosen`: the next menu's rows would otherwise be
+ /// built under this surface while it still stands.
+ property <int> leaving-by;
+ leave := Timer {
+ interval: 1ms;
+ running: false;
+ triggered => {
+ self.running = false;
+ root.neighbour(root.leaving-by);
+ }
+ }
+
surface := PopupWindow {
x: root.at-x;
y: root.at-y;
@@ -121,6 +175,33 @@ export component ContextMenu inherits Rectangle {
height: root.menu-height;
close-policy: close-on-click-outside;
+ // Made afresh each time the surface shows, so this is each opening.
+ FocusScope {
+ init => {
+ if (root.keyboard) {
+ self.focus();
+ }
+ }
+ key-pressed(event) => {
+ if (event.text == Key.DownArrow) {
+ root.hot = next(root.hot, 1);
+ } else if (event.text == Key.UpArrow) {
+ root.hot = next(root.hot < 0 ? 0 : root.hot, -1);
+ } else if (event.text == Key.Return || event.text == " ") {
+ choose(root.hot);
+ } else if (event.text == Key.Escape) {
+ surface.close();
+ } else if (event.text == Key.LeftArrow || event.text == Key.RightArrow) {
+ root.leaving-by = event.text == Key.LeftArrow ? -1 : 1;
+ leave.running = true;
+ surface.close();
+ } else {
+ return reject;
+ }
+ accept
+ }
+ }
+
Rectangle {
background: Theme.raised;
border-width: 1px;
@@ -132,7 +213,7 @@ export component ContextMenu inherits Rectangle {
padding: 6px;
alignment: start;
- for item in root.items: Rectangle {
+ for item[index] in root.items: Rectangle {
height: item.kind == MenuRow.separator ? MenuMetrics.separator
: item.kind == MenuRow.label ? MenuMetrics.label
: MenuMetrics.action;
@@ -160,12 +241,13 @@ export component ContextMenu inherits Rectangle {
if item.kind == MenuRow.action: row := Rectangle {
border-radius: Theme.r-xs;
- background: !(touch.has-hover && item.enabled) ? Colors.transparent
+ property <bool> lit: (touch.has-hover || root.hot == index) && item.enabled;
+ background: !row.lit ? Colors.transparent
: item.danger ? Theme.danger-soft
: Theme.field;
property <brush> ink: !item.enabled ? Theme.fg-dim
- : (item.danger && touch.has-hover) ? Theme.danger
+ : (item.danger && row.lit) ? Theme.danger
: Theme.fg;
HorizontalLayout {
diff --git a/src/crates/concat/ui/title-bar.slint b/src/crates/concat/ui/title-bar.slint
index a3541e91..188817e0 100644
--- a/src/crates/concat/ui/title-bar.slint
+++ b/src/crates/concat/ui/title-bar.slint
@@ -135,9 +135,15 @@ export component TitleBar inherits Rectangle {
callback close();
/// A menu was asked for: which one, and where its label sits in the strip,
/// so the sheet can hang off it.
- callback menu-opened(index: int, at-x: length);
+ callback menu-opened(index: int, at-x: length, keyboard: bool);
/// Which menu is open, or -1.
in property <int> menu: -1;
+ /// A menu asked for from the keyboard (F10, Alt+F/E/V, the arrows in
+ /// an open one): `keyboard-menu` is which, and a change of
+ /// `keyboard-token` is the asking. The label opens itself, since only
+ /// it knows where it is.
+ in property <int> keyboard-menu: -1;
+ in property <int> keyboard-token;
callback open-settings();
/// A view was picked from the add-panel list.
callback add-pane(kind: PaneKind);
@@ -204,21 +210,39 @@ export component TitleBar inherits Rectangle {
label: I18n.t("titleBar.file");
current: root.menu == 0;
clicked => {
- root.menu-opened(0, file.absolute-position.x - root.absolute-position.x);
+ root.menu-opened(0, file.absolute-position.x - root.absolute-position.x, false);
+ }
+ property <int> asked: root.keyboard-token;
+ changed asked => {
+ if (root.keyboard-menu == 0) {
+ root.menu-opened(0, file.absolute-position.x - root.absolute-position.x, true);
+ }
}
}
if !root.minimal: edit := MenuLabel {
label: I18n.t("titleBar.edit");
current: root.menu == 1;
clicked => {
- root.menu-opened(1, edit.absolute-position.x - root.absolute-position.x);
+ root.menu-opened(1, edit.absolute-position.x - root.absolute-position.x, false);
+ }
+ property <int> asked: root.keyboard-token;
+ changed asked => {
+ if (root.keyboard-menu == 1) {
+ root.menu-opened(1, edit.absolute-position.x - root.absolute-position.x, true);
+ }
}
}
if !root.minimal: view := MenuLabel {
label: I18n.t("titleBar.view");
current: root.menu == 2;
clicked => {
- root.menu-opened(2, view.absolute-position.x - root.absolute-position.x);
+ root.menu-opened(2, view.absolute-position.x - root.absolute-position.x, false);
+ }
+ property <int> asked: root.keyboard-token;
+ changed asked => {
+ if (root.keyboard-menu == 2) {
+ root.menu-opened(2, view.absolute-position.x - root.absolute-position.x, true);
+ }
}
}