Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 12 additions & 2 deletions shell/Ui/KeyboardPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ PanelWindow {
readonly property string barPos: bar ? bar.position : "top"

function close() {
if (owner && "close" in owner) owner.close()
else root.open = false
// A throwing plugin close() must not leave this overlay mapped with a
// full-screen input region — that locks every click on the desktop until
// the shell is restarted. Force root.open false when the owner fails.
try {
if (owner && "close" in owner) {
owner.close()
return
}
} catch (e) {
console.warn("KeyboardPanel: owner close() threw, forcing close:", e)
}
root.open = false

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 Thrown close breaks reopening When an owner's close() throws, assigning root.open = false breaks the panel's open: root.opened binding. The overlay closes, but later changes to the owner's open state cannot reopen it, leaving the plugin and its panel out of sync until the shell reloads.

}

function beginFocusPrime() {
Expand Down
117 changes: 117 additions & 0 deletions test/shell.d/fixtures/keyboard-panel-close/shell.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import QtQuick
import Quickshell
import qs.Ui

ShellRoot {
id: root

readonly property string resultPath: Quickshell.env("OMARCHY_QML_TEST_RESULT")
property var failures: []

function fail(message) {
failures.push(String(message))
}

function assertTrue(condition, message) {
if (!condition) fail(message)
}

function shellQuote(value) {
return "'" + String(value).replace(/'/g, "'\\''") + "'"
}

function writeResult() {
var payload = JSON.stringify({
ok: failures.length === 0,
failures: failures
})

if (resultPath) {
Quickshell.execDetached(["bash", "-lc", "printf '%s' " + shellQuote(payload) + " > " + shellQuote(resultPath)])
}
}

component FakeBar: QtObject {
property string position: "top"
property int barSize: 30
property var activePopout: null

function requestPopout(key) { activePopout = key }
function releasePopout(key) { if (activePopout === key) activePopout = null }
}

Item { id: anchor; width: 40; height: 30 }

FakeBar { id: throwingBar }
FakeBar { id: workingBar }

QtObject {
id: throwingOwner
property bool opened: true
function close() { throw new Error("owner close failed") }
}

QtObject {
id: workingOwner
property bool opened: true
property int closes: 0
function close() {
closes += 1
opened = false
}
}

KeyboardPanel {
id: throwingPanel
anchorItem: anchor
bar: throwingBar
owner: throwingOwner
open: throwingOwner.opened
}

KeyboardPanel {
id: workingPanel
anchorItem: anchor
bar: workingBar
owner: workingOwner
open: workingOwner.opened
}

function runChecks() {
assertTrue(throwingPanel.open && workingPanel.open, "both panels start open")
Comment on lines +80 to +81

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 Mapping is not tested The fixture checks visible after closing but never establishes that either overlay was mapped first. Since visible follows the panel's logical state and card opacity, the test can pass without exercising the mapped overlay or the pointer-input failure it is meant to prevent.

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!


try {
throwingPanel.close()
} catch (e) {
fail("KeyboardPanel.close() let the owner's exception escape: " + e)
}
assertTrue(!throwingPanel.open, "a throwing owner close() still closes the panel")
assertTrue(throwingBar.activePopout === null, "a throwing owner close() releases the bar popout")

workingPanel.close()
assertTrue(workingOwner.closes === 1, "a working owner close() is delegated exactly once")
assertTrue(!workingPanel.open, "a working owner close() closes the panel through its binding")

settle.start()
}

// The card fades out before the window unmaps, so check visibility after it.
Timer {
id: settle
interval: 1000
onTriggered: {
root.assertTrue(!throwingPanel.visible, "the overlay of a panel whose owner threw is unmapped")
root.assertTrue(!workingPanel.visible, "the overlay of a panel whose owner closed is unmapped")
root.writeResult()
quitTimer.start()
}
}

Timer {
id: quitTimer
interval: 300
onTriggered: Qt.quit()
}

Component.onCompleted: Qt.callLater(runChecks)
}
73 changes: 73 additions & 0 deletions test/shell.d/keyboard-panel-close-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

TMPDIR=""
QS_PID=""

cleanup() {
if [[ -n $QS_PID ]] && kill -0 "$QS_PID" 2>/dev/null; then
kill "$QS_PID" 2>/dev/null || true
wait "$QS_PID" 2>/dev/null || true
fi
if [[ -n $TMPDIR && -d $TMPDIR ]]; then
rm -rf "$TMPDIR"
fi
}
trap cleanup EXIT

require_compositor "keyboard panel close test"

if ! command -v quickshell >/dev/null 2>&1; then
skip "quickshell not installed; skipping keyboard panel close test"
exit 0
fi

require_command jq

TMPDIR=$(mktemp -d)
result="$TMPDIR/result.json"
log="$TMPDIR/quickshell.log"
config_dir="$TMPDIR/keyboard-panel-close"
mkdir -p "$config_dir" "$TMPDIR/home"
cp "$SHELL_TEST_DIR/fixtures/keyboard-panel-close/shell.qml" "$config_dir/shell.qml"
ln -s "$ROOT/shell/Ui" "$config_dir/Ui"
ln -s "$ROOT/shell/Commons" "$config_dir/Commons"

OMARCHY_PATH="$ROOT" \
OMARCHY_QML_TEST_RESULT="$result" \
HOME="$TMPDIR/home" \
XDG_CONFIG_HOME="$TMPDIR/home/.config" \
XDG_CACHE_HOME="$TMPDIR/home/.cache" \
XDG_STATE_HOME="$TMPDIR/home/.local/state" \
QML2_IMPORT_PATH="$ROOT/shell${QML2_IMPORT_PATH:+:$QML2_IMPORT_PATH}" \
QML_IMPORT_PATH="$ROOT/shell${QML_IMPORT_PATH:+:$QML_IMPORT_PATH}" \
PATH="$ROOT/bin:$PATH" \
quickshell -p "$config_dir" --no-color >"$log" 2>&1 &
QS_PID=$!

for _ in {1..80}; do
[[ -s $result ]] && break
if ! kill -0 "$QS_PID" 2>/dev/null; then
sed -n '1,220p' "$log" >&2
fail "keyboard panel close quickshell exited before writing result"
fi
sleep 0.1
done

[[ -s $result ]] || {
sed -n '1,220p' "$log" >&2
fail "keyboard panel close test timed out"
}

if ! jq -e '.ok == true' "$result" >/dev/null; then
printf 'Keyboard panel close result:\n' >&2
jq . "$result" >&2
printf 'Keyboard panel close log:\n' >&2
sed -n '1,220p' "$log" >&2
fail "a throwing owner close() cannot leave the keyboard panel overlay mapped"
fi

pass "a throwing owner close() cannot leave the keyboard panel overlay mapped"