Repository navigation
Force-close KeyboardPanel when owner close() throws #13648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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) | ||
| } | ||
| 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close()throws, assigningroot.open = falsebreaks the panel'sopen: root.openedbinding. 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.