From 896368ef56180220c276a801f450b3fbb83e580a Mon Sep 17 00:00:00 2001 From: Erik Simon Date: Fri, 25 Sep 2026 01:26:44 +0200 Subject: [PATCH] feat(terra): launcher most-used sort, power buttons, SUPER opens rail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Launcher sorts by launch count by default (persisted in quickshell's state dir); Ctrl+S or the sort chip toggles A–Z. - Logout/Reboot/Shutdown in the footer, each needing a confirming click. - SUPER now opens the launcher with the rail expanded; closing the launcher collapses the rail again unless it was already open. Co-Authored-By: Claude Opus 5.5 --- .../HyprChrome/Widgets/HyprChromeShell.qml | 37 +++++++- .../Widgets/Launcher/AppLauncher.qml | 28 ++++-- .../Widgets/Launcher/AppLauncherContent.qml | 92 ++++++++++++++++--- .../HyprChrome/Widgets/Launcher/AppModel.qml | 51 +++++++++- dotfiles/quickshell/open_launcher.sh | 2 +- 5 files changed, 186 insertions(+), 24 deletions(-) diff --git a/dotfiles/quickshell/HyprChrome/Widgets/HyprChromeShell.qml b/dotfiles/quickshell/HyprChrome/Widgets/HyprChromeShell.qml index 0e21110..3a7464a 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/HyprChromeShell.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/HyprChromeShell.qml @@ -1,5 +1,6 @@ pragma ComponentBehavior: Bound +import QtQuick import Quickshell import Quickshell.Hyprland import Quickshell.Wayland @@ -147,6 +148,40 @@ Scope { onPressed: shell.toggle() } + // SUPER — the launcher over an expanded rail, opened and closed as one. + GlobalShortcut { + name: "command" + description: "Open the launcher with the hyprchrome bar expanded" + onPressed: shell.toggleCommand() + } + + // Whether the rail was expanded BY toggleCommand, so closing the launcher + // only collapses a rail it opened. + property bool commandExpanded: false + + function toggleCommand() { + if (polkit.prompting || askpass.active) + return; + if (launcher.active) { + launcher.close(); + return; + } + shell.commandExpanded = !shell.expanded; + shell.expanded = true; + launcher.active = true; + } + + // The launcher closes itself (ESC, launch, click-off), so collapse follows it. + Connections { + target: launcher + function onActiveChanged() { + if (!launcher.active && shell.commandExpanded) { + shell.commandExpanded = false; + shell.expanded = false; + } + } + } + // Backdrop first: it is a layer below the bar, so stacking does not depend // on creation order, but keeping the declaration order the same as the // visual order costs nothing. @@ -236,7 +271,7 @@ Scope { screen: shell.focusedScreen } - // Primary application launcher — SUPER_L. Migrated out of + // Primary application launcher — SUPER_L (via `command` above). Migrated out of // widgets/launcher/; the ten remaining variants are still evaluation copies // and stay in shell.qml. Declared after the bar for the same reason the // prompt is: while it is open the bar is on Overlay too, and there is no diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncher.qml b/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncher.qml index c27ad19..2aece12 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncher.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncher.qml @@ -6,7 +6,7 @@ import Quickshell.Wayland import QtQuick import qs.HyprChrome.Theme -// Primary application launcher — the one on SUPER_L. +// Primary application launcher — the one on SUPER_L (via HyprChromeShell). // // Migrated from widgets/launcher/ApplicationLauncher.qml. Two things changed in // the move, both because HyprChromeShell now owns the state its surfaces share: @@ -34,11 +34,8 @@ Scope { function toggle() { root.active = !root.active; } function close() { root.active = false; } - // The name is legacy: this was "variant 8" of eleven, and both SUPER_L (via - // open_launcher.sh) and SUPER CTRL 8 still dispatch quickshell:launcher8. - // Renaming it means editing hosts/terra/home/hyprland.nix AND the script - // together, and neither takes effect until a deploy — so the shortcut would - // be dead in the running session in between. Kept as-is deliberately. + // Launcher alone, on SUPER CTRL 8. SUPER_L goes through the shell's + // `command` shortcut instead, which also expands the rail. GlobalShortcut { name: "launcher8" description: "Toggle dense application command index" @@ -83,9 +80,22 @@ Scope { root.active = false; } + // Hyprland runs a Lua config, which rejects a bare `dispatch exit`. + readonly property var powerCommands: ({ + logout: ["hyprctl", "dispatch", "hl.dsp.exit()"], + reboot: ["systemctl", "reboot"], + shutdown: ["systemctl", "poweroff"] + }) + + function power(action) { + root.active = false; + Quickshell.execDetached(win.powerCommands[action]); + } + onVisibleChanged: { if (visible) { content.clearSearch(); + content.disarmPower(); selectedIndex = 0; content.focusSearch(); } @@ -115,11 +125,17 @@ Scope { transformOrigin: Item.Center apps: model.apps selectedIndex: win.selectedIndex + sortMode: model.sortMode onSelectionRequested: index => win.selectedIndex = win.clampSelection(index) onMoveRequested: delta => win.move(delta) onLaunchRequested: index => win.launch(index) onDismissRequested: root.close() + onSortToggleRequested: { + model.toggleSort(); + win.selectedIndex = 0; + } + onPowerRequested: action => win.power(action) } } } diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncherContent.qml b/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncherContent.qml index f9e9ecb..eea254f 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncherContent.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppLauncherContent.qml @@ -17,6 +17,10 @@ Item { property int selectedIndex: 0 property bool showIcons: true property alias query: searchInput.text + property string sortMode: "usage" + + // Power action awaiting its confirming second click; "" when none. + property string armedPower: "" readonly property var selectedApp: apps.length > 0 && selectedIndex >= 0 && selectedIndex < apps.length ? apps[selectedIndex] : null @@ -25,9 +29,29 @@ Item { signal moveRequested(int delta) signal launchRequested(int index) signal dismissRequested + signal sortToggleRequested + signal powerRequested(string action) function focusSearch() { searchInput.forceActiveFocus(); } function clearSearch() { searchInput.text = ""; } + function disarmPower() { root.armedPower = ""; } + + // First click arms, second (within the timeout) fires: a stray click must + // not end the session. + function pressPower(action) { + if (root.armedPower === action) { + root.armedPower = ""; + root.powerRequested(action); + } else { + root.armedPower = action; + } + } + + Timer { + running: root.armedPower !== "" + interval: 3000 + onTriggered: root.disarmPower() + } implicitWidth: 1080 implicitHeight: 620 @@ -121,6 +145,11 @@ Item { onTextChanged: root.selectionRequested(0) Keys.onPressed: event => { + if (event.key === Qt.Key_S && (event.modifiers & Qt.ControlModifier)) { + root.sortToggleRequested(); + event.accepted = true; + return; + } switch (event.key) { case Qt.Key_Down: case Qt.Key_Tab: @@ -162,16 +191,24 @@ Item { } } - Rectangle { + MouseArea { + id: sortChip Layout.preferredWidth: 84 Layout.preferredHeight: 22 - color: Theme.accentAlpha(0.12) - border.width: 1 - border.color: Theme.hair + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: root.sortToggleRequested() + + Rectangle { + anchors.fill: parent + color: sortChip.containsMouse ? Theme.accentAlpha(0.28) : Theme.accentAlpha(0.12) + border.width: 1 + border.color: sortChip.containsMouse ? Theme.accent : Theme.hair + } Text { anchors.centerIn: parent - text: "LIVE INDEX" + text: root.sortMode === "usage" ? "SORT: USED" : "SORT: A–Z" color: Theme.accent font.family: Theme.microFont font.pixelSize: 7 @@ -191,7 +228,7 @@ Item { height: 424 panelId: "IDX" title: "APPLICATION TABLE" - meta: root.query.length > 0 ? "FILTER ACTIVE" : "A–Z / LOCAL" + meta: (root.query.length > 0 ? "FILTER ACTIVE" : "LOCAL") + (root.sortMode === "usage" ? " / MOST USED" : " / A–Z") ListView { id: appList @@ -587,13 +624,46 @@ Item { KeyHint { keyText: "↑ ↓"; actionText: "SELECT" } KeyHint { keyText: "ENTER"; actionText: "EXECUTE" } KeyHint { keyText: "ESC"; actionText: "ABORT" } + KeyHint { keyText: "CTRL+S"; actionText: "SORT" } Item { Layout.fillWidth: true } MicroText { text: "QRY:" + (root.query.length > 0 ? "ACTIVE" : "IDLE") } - MicroText { text: "CRC // A7F2" } - Rectangle { - Layout.preferredWidth: 76 - Layout.preferredHeight: 4 - color: Theme.accent + Rectangle { Layout.preferredWidth: 1; Layout.preferredHeight: 22; color: Theme.hair } + + Repeater { + model: [ + { action: "logout", label: "LOGOUT" }, + { action: "reboot", label: "REBOOT" }, + { action: "shutdown", label: "SHUTDOWN" } + ] + + MouseArea { + id: powerButton + required property var modelData + readonly property bool armed: root.armedPower === modelData.action + + Layout.preferredWidth: 96 + Layout.preferredHeight: 26 + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: root.pressPower(modelData.action) + + Rectangle { + anchors.fill: parent + color: powerButton.armed ? Theme.hot : powerButton.containsMouse ? Theme.accentAlpha(0.28) : Theme.accentAlpha(0.10) + border.width: 1 + border.color: powerButton.armed ? Theme.hot : powerButton.containsMouse ? Theme.accent : Theme.hair + } + + Text { + anchors.centerIn: parent + text: powerButton.armed ? "CONFIRM" : powerButton.modelData.label + color: powerButton.armed ? Theme.surface : Theme.accent + font.family: Theme.microFont + font.pixelSize: 8 + font.bold: true + font.letterSpacing: 1 + } + } } } } diff --git a/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppModel.qml b/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppModel.qml index 2acbdfc..b4ff66b 100644 --- a/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppModel.qml +++ b/dotfiles/quickshell/HyprChrome/Widgets/Launcher/AppModel.qml @@ -1,44 +1,85 @@ import Quickshell +import Quickshell.Io import QtQuick -// Non-visual, reusable app-search model shared by every launcher variant. +// Non-visual app-search model for the launcher. // Set `search`; read `apps` (a ranked, filtered list of DesktopEntry). QtObject { id: root property string search: "" + // "usage" (most launched first) | "name". Persisted with the counts. + readonly property string sortMode: store.sortMode + + function toggleSort() { + store.sortMode = store.sortMode === "usage" ? "name" : "usage"; + } + + function uses(a) { + return store.counts[a.id] ?? 0; + } + // `keywords`/`categories` come through as string lists, so coerce every // field to a string before matching (String([]) joins with commas). function haystack(a) { return (String(a.name || "") + " " + String(a.genericName || "") + " " + String(a.comment || "") + " " + String(a.keywords || "")).toLowerCase(); } + function byOrder(x, y) { + if (root.sortMode === "usage") { + const d = root.uses(y) - root.uses(x); + if (d !== 0) + return d; + } + return String(x.name).localeCompare(String(y.name)); + } + readonly property var apps: { const all = DesktopEntries.applications.values.filter(a => !a.noDisplay); const q = root.search.trim().toLowerCase(); if (q.length === 0) - return all.slice().sort((x, y) => String(x.name).localeCompare(String(y.name))); + return all.slice().sort(root.byOrder); const matches = all.filter(a => root.haystack(a).includes(q)); - // Prefix matches on the visible name rank first, then alphabetical. + // Prefix matches on the visible name rank first, then the sort mode. return matches.slice().sort((x, y) => { const xs = String(x.name).toLowerCase().startsWith(q) ? 0 : 1; const ys = String(y.name).toLowerCase().startsWith(q) ? 0 : 1; if (xs !== ys) return xs - ys; - return String(x.name).localeCompare(String(y.name)); + return root.byOrder(x, y); }); } function launch(index) { const list = root.apps; if (index >= 0 && index < list.length) { - list[index].execute(); + const app = list[index]; + app.execute(); + // Reassigned, not mutated: an in-place write notifies nothing. + const counts = Object.assign({}, store.counts); + counts[app.id] = (counts[app.id] ?? 0) + 1; + store.counts = counts; return true; } return false; } + + readonly property var file: FileView { + path: Quickshell.statePath("launcher.json") + onAdapterUpdated: writeAdapter() + onLoadFailed: error => { + if (error === FileViewError.FileNotFound) + writeAdapter(); + } + + JsonAdapter { + id: store + property string sortMode: "usage" + property var counts: ({}) + } + } } diff --git a/dotfiles/quickshell/open_launcher.sh b/dotfiles/quickshell/open_launcher.sh index 8329ea9..19ed1cf 100755 --- a/dotfiles/quickshell/open_launcher.sh +++ b/dotfiles/quickshell/open_launcher.sh @@ -1,3 +1,3 @@ #!/bin/bash -hyprctl dispatch 'hl.dsp.global ("quickshell:launcher8")' +hyprctl dispatch 'hl.dsp.global ("quickshell:command")'