Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions shell/plugins/menu/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ Item {
var payload = ({})
try { payload = JSON.parse(payloadJson || "{}") } catch (e) { payload = ({}) }

// A select/input request left in flight when a new summon arrives
// (e.g. the trigger key repeated before the prior one was answered)
// would otherwise have its doneFile silently abandoned by
// openDmenu/openExistingMenu below, leaving the caller that's still
// polling for it (bin/omarchy-menu-select) blocked forever. Answer it
// as cancelled first so every summon always resolves.
if (root.requestActive) root.finishRequest(null)

Comment on lines +27 to +34
if (payload.fontFamily) root.fontFamily = payload.fontFamily

if (payload.mode === "select" || payload.mode === "input") {
Expand Down Expand Up @@ -66,8 +74,6 @@ Item {
property string filterText: ""
property int selectedIndex: 0
property bool cursorActive: false
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
property int requestSerial: 0
property int applySerial: 0
property var items: ({})
Comment on lines 116 to 117

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Keybindings no longer run

Removing applySerial breaks choosing a row in the keybindings menu. activateIndex() still runs applySerial = requestSerial before closing the menu or running the chosen command. Assigning to that undeclared name raises a QML error, so clicking a row or pressing Enter leaves the menu open and does nothing.

Remove the leftover assignment along with the unused resultProc, or restore the property.

property var itemOrder: []
property var navStack: []
Expand Down Expand Up @@ -126,12 +132,13 @@ Item {
root.selectionFile = ""
root.doneFile = ""

// Each answer gets its own process: a shared Process drops a command set
// while it is still running, which strands the caller waiting on it.
if (selection === null || selection === undefined) {
resultProc.command = ["bash", "-c", ": > " + Util.shellQuote(activeDoneFile)]
Quickshell.execDetached(["bash", "-c", ": > " + Util.shellQuote(activeDoneFile)])
} else {
resultProc.command = ["bash", "-c", "printf '%s\\n' " + Util.shellQuote(selection) + " > " + Util.shellQuote(activeSelectionFile) + "; : > " + Util.shellQuote(activeDoneFile)]
Quickshell.execDetached(["bash", "-c", "printf '%s\\n' " + Util.shellQuote(selection) + " > " + Util.shellQuote(activeSelectionFile) + "; : > " + Util.shellQuote(activeDoneFile)])
}
resultProc.running = true
}

function runAction(action) {
Expand Down Expand Up @@ -777,7 +784,6 @@ Item {
} else if (row.kind === "app") {
var appId = row.appId
var label = row.label
applySerial = requestSerial
opened = false
filterText = ""
if (root.appLibrary) root.appLibrary.launch(appId, label)
Expand Down Expand Up @@ -813,7 +819,6 @@ Item {
}

function applyDmenuSelection(value) {
applySerial = requestSerial
opened = false
filterText = ""
root.finishRequest(value)
Expand All @@ -822,7 +827,6 @@ Item {
function applySelected(id, action) {
if (!id) { cancel(); return }

applySerial = requestSerial
opened = false
filterText = ""
root.runAction(action)
Expand All @@ -835,7 +839,6 @@ Item {
}

function openExistingMenu(initialMenu) {
requestSerial += 1
mode = "menu"
requestActive = false
selectionFile = ""
Expand All @@ -859,7 +862,6 @@ Item {
}

function openDmenu(payload) {
requestSerial += 1
mode = payload.mode === "input" ? "input" : "select"
dmenuPrompt = String(payload.prompt || (mode === "input" ? "Input" : "Select"))
dmenuOptions = Array.isArray(payload.options) ? payload.options : []
Expand Down Expand Up @@ -939,14 +941,6 @@ Item {
}
}

Process {
id: resultProc
onExited: {
if (root.applySerial === root.requestSerial)
root.opened = false
}
}

PointerMoveGate {
id: pointerGate
referenceItem: card
Expand Down
12 changes: 12 additions & 0 deletions test/shell.d/menu-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ assert(
&& /onClicked:[\s\S]*root\.activateIndex\(row\.index, true\)/.test(menuQml),
'mouse activation carries pointer intent into subordinate menus'
)

const openBody = menuQml.match(/function open\(payloadJson\) \{([\s\S]*?)\n \}/)[1]
assert(
/if \(root\.requestActive\) root\.finishRequest\(null\)/.test(openBody)
&& openBody.indexOf('root.finishRequest(null)') < openBody.indexOf('root.openDmenu(payload)'),
'menu answers a request still in flight before a new summon replaces it'
)
const finishBody = menuQml.match(/function finishRequest\(selection\) \{([\s\S]*?)\n \}/)[1]
assert(
(finishBody.match(/Quickshell\.execDetached\(/g) || []).length === 2 && !/\.running = true/.test(finishBody),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Overlapping requests remain untested The new assertions inspect QML text but never run two overlapping select/input requests. A regression could leave the first caller waiting for its doneFile while these checks still pass. A runtime test that supersedes an active request and verifies both callers exit would cover the behavior this PR fixes.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

'menu writes every answer in a process of its own, so back-to-back answers cannot drop one'
)
JS

font_charset=$(fc-query --format='%{charset}' "$ROOT/default/fonts/omarchy/omarchy.ttf")
Expand Down