diff --git a/shell/services/AppLibrary.qml b/shell/services/AppLibrary.qml index 97b3ed6caa60..a195acea5d96 100644 --- a/shell/services/AppLibrary.qml +++ b/shell/services/AppLibrary.qml @@ -30,6 +30,8 @@ Item { // it: the OSD shows with duration 0, so only closeLaunchFeedback() takes it // down. property bool launchOsdOpen: false + property bool launchOsdShowPending: false + property bool launchOsdCloseQueued: false property string launchOsdMessage: "" // Emitted whenever the visible application set may have changed: desktop @@ -184,12 +186,20 @@ Item { launchTimeout.restart() } + function showLaunchOsd() { + root.launchOsdOpen = true + root.launchOsdShowPending = true + launchOsdShow.command = ["omarchy-shell", "osd", "show", JSON.stringify({ icon: "󱓞", message: root.launchOsdMessage, duration: 0 })] + launchOsdShow.running = true + } + function closeLaunchFeedback(serial) { if (serial !== root.launchSerial) return launchDelay.stop() launchTimeout.stop() if (root.launchOsdOpen) { - Quickshell.execDetached(["omarchy-shell", "osd", "close"]) + if (root.launchOsdShowPending) root.launchOsdCloseQueued = true + else Quickshell.execDetached(["omarchy-shell", "osd", "close"]) root.launchOsdOpen = false } } @@ -259,8 +269,7 @@ Item { interval: 2000 onTriggered: { if (root.toplevelCount() > root.launchToplevelCount || ToplevelManager.activeToplevel !== root.launchActiveToplevel) return - root.launchOsdOpen = true - Quickshell.execDetached(["omarchy-shell", "osd", "show", JSON.stringify({ icon: "󱓞", message: root.launchOsdMessage, duration: 0 })]) + root.showLaunchOsd() } } @@ -270,6 +279,19 @@ Item { onTriggered: root.closeLaunchFeedback(root.launchSerial) } + // Show and close are separate omarchy-shell calls. Close waits for show to + // finish, so a close cannot reach the OSD first and leave it open forever. + // launchOsdShowPending covers the gap before `running` turns true. + Process { + id: launchOsdShow + onExited: { + root.launchOsdShowPending = false + if (!root.launchOsdCloseQueued) return + root.launchOsdCloseQueued = false + Quickshell.execDetached(["omarchy-shell", "osd", "close"]) + } + } + Connections { target: DesktopEntries.applications function onValuesChanged() { diff --git a/test/shell.d/fixtures/launch-osd-order/shell.qml b/test/shell.d/fixtures/launch-osd-order/shell.qml new file mode 100644 index 000000000000..fd2f16f92003 --- /dev/null +++ b/test/shell.d/fixtures/launch-osd-order/shell.qml @@ -0,0 +1,33 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import "services" + +// Shows the launch OSD and closes it in the same turn, while the stubbed +// `omarchy-shell osd show` is still running. Nothing runs in between, so window +// changes on the desktop cannot cancel the launch first. The test then checks +// that the close reached omarchy-shell after the show. +ShellRoot { + id: root + + AppLibrary { id: appLibrary } + + FileView { + id: resultFile + path: Quickshell.env("OMARCHY_QML_TEST_RESULT") + atomicWrites: true + } + + Timer { + id: settle + interval: 1500 + onTriggered: resultFile.setText(JSON.stringify({ ok: true })) + } + + Component.onCompleted: { + appLibrary.beginLaunchFeedback("Test") + appLibrary.showLaunchOsd() + appLibrary.closeLaunchFeedback(appLibrary.launchSerial) + settle.start() + } +} diff --git a/test/shell.d/launch-osd-order-test.sh b/test/shell.d/launch-osd-order-test.sh new file mode 100755 index 000000000000..d7ee2240f1c7 --- /dev/null +++ b/test/shell.d/launch-osd-order-test.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +require_quickshell "launch OSD order test" + +# A slow `osd show` must not let the following `osd close` overtake it: the +# launch OSD has no duration, so a close that lands first leaves it open. +qml_fixture_scratch +osd_log="$QML_FIXTURE_TMP/osd.log" +cat >"$QML_FIXTURE_TMP/bin/omarchy-shell" <<'SH' +#!/bin/bash +[[ $2 == "show" ]] && sleep 0.5 +echo "$2" >>"$OSD_LOG" +SH +chmod +x "$QML_FIXTURE_TMP/bin/omarchy-shell" + +OSD_LOG="$osd_log" run_qml_fixture launch-osd-order "launch OSD fixture runs" services Commons + +[[ $(cat "$osd_log" 2>/dev/null | tr '\n' ' ') == "show close " ]] || + fail "launch OSD close waits for show" "omarchy-shell calls: $(cat "$osd_log" 2>/dev/null | tr '\n' ' ')" +pass "launch OSD close waits for show"