diff --git a/shell/Ui/PanelKeyCatcher.qml b/shell/Ui/PanelKeyCatcher.qml index a49ebcdb..b110b223 100644 --- a/shell/Ui/PanelKeyCatcher.qml +++ b/shell/Ui/PanelKeyCatcher.qml @@ -14,7 +14,7 @@ import QtQuick // onActivateRequested: root.activateCursor() // onCloseRequested: root.close() // onDeleteRequested: root.deleteSelected() -// onTextKey: function(t) { if (t === "r") root.refresh() } +// onTextKey: function(t, modifiers) { if (t === "r") root.refresh() } // // Column { ... panel content ... } // } @@ -41,7 +41,8 @@ Item { signal closeRequested() signal deleteRequested() signal tabRequested(int direction) - signal textKey(string text) + // The held modifiers ride along, so a panel can tell Alt+T from T. + signal textKey(string text, int modifiers) focus: true Keys.priority: Keys.BeforeItem @@ -79,7 +80,7 @@ Item { deleteRequested(); event.accepted = true; return } if (event.text && event.text.length === 1) { - textKey(event.text) + textKey(event.text, event.modifiers) } } } diff --git a/shell/plugins/panels/elsewhen/Panel.qml b/shell/plugins/panels/elsewhen/Panel.qml index 773cc9f6..b36df90d 100644 --- a/shell/plugins/panels/elsewhen/Panel.qml +++ b/shell/plugins/panels/elsewhen/Panel.qml @@ -758,10 +758,12 @@ Panel { } onTabRequested: function(direction) { root.switchPanel(direction) } // "+" searches in either view; "j" jumps on the globe, "a" adds on the list. - // "t" flips 24-hour and AM/PM time, like clicking a row's time. - onTextKey: function(text) { + // "t" flips 24-hour and AM/PM time, like clicking a row's time, and Alt+T + // flips Fahrenheit and Celsius, like clicking a temperature. + onTextKey: function(text, modifiers) { var key = text.toLowerCase() if (key === "r") root.refresh() + else if (key === "t" && (modifiers & Qt.AltModifier)) root.toggleUnits() else if (key === "t") root.toggleHour24() else if (root.globeMode && (key === "+" || key === "j")) { if (globeLoader.item) globeLoader.item.startJump() diff --git a/test/shell.d/panel-key-catcher-test.sh b/test/shell.d/panel-key-catcher-test.sh new file mode 100755 index 00000000..36eb8f87 --- /dev/null +++ b/test/shell.d/panel-key-catcher-test.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +# /usr/bin/qmltestrunner is the Qt 5 binary, which exits 0 having run nothing. +qml_test_runner="" +for candidate in /usr/lib/qt6/bin/qmltestrunner /usr/lib/qt6/qmltestrunner; do + if [[ -x $candidate ]]; then + qml_test_runner=$candidate + break + fi +done + +if [[ -z $qml_test_runner ]]; then + skip "qt6 qmltestrunner not found; skipping panel key catcher tests" + exit 0 +fi + +output=$(QT_QPA_PLATFORM=offscreen QT_QUICK_BACKEND=software "$qml_test_runner" -input "$SHELL_TEST_DIR/panel-key-catcher/qml" -o -,txt 2>&1) || + fail "panel key catcher passes modifiers with text keys" "$output" +pass "panel key catcher passes modifiers with text keys" diff --git a/test/shell.d/panel-key-catcher/qml/tst_modifiers.qml b/test/shell.d/panel-key-catcher/qml/tst_modifiers.qml new file mode 100644 index 00000000..58acffdf --- /dev/null +++ b/test/shell.d/panel-key-catcher/qml/tst_modifiers.qml @@ -0,0 +1,45 @@ +import QtQuick +import QtTest +import "../../../../shell/Ui" + +// Text keys carry their modifiers, so a panel can tell Alt+T from T. +Item { + id: root + width: 100 + height: 100 + + property string lastText: "" + property int lastModifiers: -1 + + PanelKeyCatcher { + id: catcher + anchors.fill: parent + onTextKey: function(text, modifiers) { + root.lastText = text + root.lastModifiers = modifiers + } + } + + TestCase { + name: "PanelKeyCatcherModifiers" + when: windowShown + + function init() { + catcher.forceActiveFocus() + root.lastText = "" + root.lastModifiers = -1 + } + + function test_plainLetterHasNoModifiers() { + keyClick(Qt.Key_T) + compare(root.lastText, "t") + compare(root.lastModifiers & Qt.AltModifier, 0) + } + + function test_altLetterCarriesAlt() { + keyClick(Qt.Key_T, Qt.AltModifier) + compare(root.lastText.toLowerCase(), "t") + verify(root.lastModifiers & Qt.AltModifier) + } + } +}