From 98989ceb7bc54dbc00100a45c18738900822fde8 Mon Sep 17 00:00:00 2001 From: warfl0p Date: Tue, 17 Nov 2026 10:56:10 +0100 Subject: [PATCH] Add global shortcuts and IPC to open the launcher on a root filter omacast:toggle-all, omacast:toggle-applications and omacast:toggle-commands open the launcher on that root filter, so omacast can cover both of Omarchy's keys (Super+Space for everything, Super+Alt+Space for apps). Pressed while another filter or view is showing, they switch to it; pressed again, they close it. The same is available over IPC (toggleFilter / showFilter) and the CLI (omacast toggle ). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018pJceMMwc1Cgj279fSphjU --- Launcher.qml | 58 +++++++++++++++++++++++++++++++++++----- README.md | 13 ++++++++- bin/omacast | 15 ++++++++--- core/RootSearch.js | 5 ++++ tests/rootsearch.test.js | 5 ++++ ui/LauncherWindow.qml | 15 ++++++++--- 6 files changed, 96 insertions(+), 15 deletions(-) diff --git a/Launcher.qml b/Launcher.qml index 27cc0af..4bfea60 100644 --- a/Launcher.qml +++ b/Launcher.qml @@ -4,6 +4,7 @@ import Quickshell.Io import Quickshell.Hyprland import qs.Commons import "ui" +import "core/RootSearch.js" as RootSearch Item { id: root @@ -35,10 +36,16 @@ Item { } - function show() { - if (root.opened) return - if (root.shell && root.shell.summon(root.pluginId, "{}")) return - root.open("{}") + // filter: a RootSearch.FILTERS id to open on (omacast:toggle-); + // "" keeps whatever the launcher was left on. + function show(filter) { + if (root.opened) { + if (filter) launcher.prepare({ filter: filter }) + return + } + var payload = JSON.stringify(filter ? { filter: filter } : {}) + if (root.shell && root.shell.summon(root.pluginId, payload)) return + root.open(payload) } function hide() { @@ -50,9 +57,11 @@ Item { root.close() } - function toggle() { - if (root.opened) root.hide() - else root.show() + // A filtered toggle closes only when that filter's root is on screen; + // otherwise it switches the open launcher to it. + function toggle(filter) { + if (root.opened && (!filter || (launcher.atRoot && launcher.rootFilter === filter))) root.hide() + else root.show(filter) } // A command's own hotkey toggles it: a second press while its view is on @@ -110,6 +119,29 @@ Item { onPressed: root.toggle() } + // Open on one root filter: hl.dsp.global("omacast:toggle-applications"), + // "omacast:toggle-commands" or "omacast:toggle-all". + GlobalShortcut { + appid: "omacast" + name: "toggle-all" + description: "Toggle omacast on All" + onPressed: root.toggle("all") + } + + GlobalShortcut { + appid: "omacast" + name: "toggle-applications" + description: "Toggle omacast on Applications" + onPressed: root.toggle("applications") + } + + GlobalShortcut { + appid: "omacast" + name: "toggle-commands" + description: "Toggle omacast on Commands" + onPressed: root.toggle("commands") + } + // Toggles Switch Theme directly: hl.dsp.global("omacast:theme"). GlobalShortcut { appid: "omacast" @@ -147,6 +179,18 @@ Item { return "shown" } + function toggleFilter(filter: string): string { + if (!RootSearch.isFilter(filter)) return "unknown-filter" + root.toggle(filter) + return root.opened ? "shown" : "hidden" + } + + function showFilter(filter: string): string { + if (!RootSearch.isFilter(filter)) return "unknown-filter" + root.show(filter) + return "shown" + } + function hide(): string { root.hide() return "hidden" diff --git a/README.md b/README.md index d580440..882a656 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,7 @@ disabled command, use Undo on the toast (`Ctrl+T`), or remove its `"enabled": fa ```sh omacast toggle | show | hide +omacast toggle applications # open on one root filter: all, applications or commands omacast run # e.g. builtin:emoji-picker, app:com.mitchellh.ghostty, omarchy:appearance.theme omacast call [json] # call any backend method; omacast call system.info lists them omacast doctor # checks the shell, IPC, the backend, QML errors in the shell log, and the hotkey @@ -293,9 +294,19 @@ omacast build-search # build the optional search helper (needs cargo) omacast install | uninstall ``` -Global shortcuts for Hyprland binds: `omacast:toggle`, `omacast:clipboard`, `omacast:emoji`, `omacast:theme`. +Global shortcuts for Hyprland binds: `omacast:toggle`, `omacast:toggle-all`, `omacast:toggle-applications`, +`omacast:toggle-commands`, `omacast:clipboard`, `omacast:emoji`, `omacast:theme`. Bind them with `submap_universal = true` so they still work while omacast is open. +The `toggle-` shortcuts open the launcher on that root filter, the way Omarchy splits +Super+Space (menu) and Super+Alt+Space (apps). Pressed while omacast shows another filter or view, +they switch to it; pressed again, they close it. Plain `omacast:toggle` keeps the filter you left. + +```lua +o.bind("ALT + SPACE", "omacast", hl.dsp.global("omacast:toggle-all"), { submap_universal = true }) +o.bind("SUPER + ALT + SPACE", "omacast apps", hl.dsp.global("omacast:toggle-applications"), { submap_universal = true }) +``` + ### Dependencies and network access omacast needs only what Omarchy ships: `omarchy-shell` (Quickshell), Hyprland, bash, `jq` and `socat`. diff --git a/bin/omacast b/bin/omacast index 52d01d9..771c750 100755 --- a/bin/omacast +++ b/bin/omacast @@ -33,8 +33,9 @@ usage() { Usage: omacast [args] Launcher - toggle Show or hide the launcher - show | hide Show or hide it + toggle [filter] Show or hide the launcher; filter opens it on + all, applications or commands + show [filter] | hide Show or hide it run Open a command directly call [json] Call a backend method, e.g. omacast call system.info @@ -355,7 +356,15 @@ cmd_doctor() { } case "${1:-}" in - toggle|show|hide) need_shell; ipc "$1" >/dev/null ;; + hide) need_shell; ipc hide >/dev/null ;; + toggle|show) + need_shell + if [[ -n ${2:-} ]]; then + [[ $(ipc "${1}Filter" "$2") != unknown-filter ]] || die "unknown filter: $2 (all, applications or commands)" + else + ipc "$1" >/dev/null + fi + ;; run) need_shell; [[ -n ${2:-} ]] || die "usage: omacast run "; ipc run "$2" ;; call) need_shell; [[ -n ${2:-} ]] || die "usage: omacast call [json]"; ipc call "$2" "${3:-}" ;; ping) need_shell; ipc ping ;; diff --git a/core/RootSearch.js b/core/RootSearch.js index 3a2a78a..fc4bc8f 100644 --- a/core/RootSearch.js +++ b/core/RootSearch.js @@ -300,6 +300,10 @@ var FILTERS = [ { id: "commands", title: "Commands" } ] +function isFilter(id) { + return FILTERS.some(function(f) { return f.id === id }) +} + function passesFilter(candidate, filter) { if (!filter || filter === "all") return true return (candidate.type === "application") === (filter === "applications") @@ -510,6 +514,7 @@ if (typeof module !== "undefined") { FALLBACKS: FALLBACKS, BUILTINS: BUILTINS, FILTERS: FILTERS, + isFilter: isFilter, fillArguments: fillArguments, missingArgument: missingArgument, confirmationFor: confirmationFor, diff --git a/tests/rootsearch.test.js b/tests/rootsearch.test.js index f745aa4..483e467 100644 --- a/tests/rootsearch.test.js +++ b/tests/rootsearch.test.js @@ -153,6 +153,11 @@ test("the root filter narrows by type and drops calculator and fallbacks", () => assert.deepEqual(RS.FILTERS.map((f) => f.id), ["all", "applications", "commands"]) }) +test("isFilter accepts only the root filter ids", () => { + for (const f of RS.FILTERS) assert.equal(RS.isFilter(f.id), true) + for (const bad of ["", "apps", "All", undefined, null, 1]) assert.equal(RS.isFilter(bad), false) +}) + test("power commands and delete-all ask for confirmation", () => { assert.equal(RS.confirmationFor("omarchy:system.shutdown", "open").primary, "Shut Down") assert.equal(RS.confirmationFor("omarchy:system.shutdown", "copy-command"), null) diff --git a/ui/LauncherWindow.qml b/ui/LauncherWindow.qml index 1071842..100322c 100644 --- a/ui/LauncherWindow.qml +++ b/ui/LauncherWindow.qml @@ -194,12 +194,18 @@ PanelWindow { function prepare(payload) { popTimer.stop() - if (typeof payload.query === "string") window.query = payload.query + // A filtered hotkey (omacast:toggle-) lands on an empty root with + // that filter, wherever the launcher was left. + var filter = RootSearch.isFilter(payload.filter) ? payload.filter : "" + var reset = filter !== "" && !(window.atRoot && window.query === "" && window.rootFilter === filter) + if (reset) window.popToRoot(filter) + else if (typeof payload.query === "string") window.query = payload.query window.closePopups() window.historyIndex = -1 // Hiding pops to root and rebuilds, so an unchanged root list is reused // and the card shows on the next frame instead of after a search. - if (typeof payload.query === "string" || window.rootKey() !== window.builtRootKey) window.rebuild(true) + if (reset) {} // popToRoot already rebuilt + else if (typeof payload.query === "string" || window.rootKey() !== window.builtRootKey) window.rebuild(true) else window.select(window.nextSelectable(-1, 1), 0) Qt.callLater(function() { keyCatcher.forceActiveFocus() }) } @@ -275,10 +281,11 @@ PanelWindow { onTriggered: window.popToRoot() } - function popToRoot() { + // filter: a RootSearch.FILTERS id to land on; "all" when omitted. + function popToRoot(filter) { window.stack = [{ kind: "root", title: "omacast", query: "" }] window.query = "" - window.rootFilter = "all" + window.rootFilter = filter || "all" window.clipboardFilter = "all" window.rebuild(true) }