From 9fc966ff7726d01267a6220483fb005c0efaa9c0 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 31 Aug 2025 12:12:23 +0200 Subject: ... --- .../gkleen@sif/shell/quickshell/KeyboardLayout.qml | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml (limited to 'accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml') diff --git a/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml b/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml new file mode 100644 index 00000000..4d3bd180 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml @@ -0,0 +1,78 @@ +import Quickshell +import QtQuick +import qs.Services + +Rectangle { + id: kbdWidget + + property var keyboardAbbrev: { "English (programmer Dvorak)": "dvp", "English (US)": "us" } + + width: kbdLabel.contentWidth + 8 + color: { + if (kbdMouseArea.containsMouse) { + return "#33808080"; + } + return "transparent"; + } + height: parent.height + anchors.verticalCenter: parent.verticalCenter + + MouseArea { + id: kbdMouseArea + + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + enabled: true + onClicked: { + NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": "Next" } } }, _ => {}) + } + } + + Text { + id: kbdLabel + + font.pointSize: 10 + font.family: "Fira Sans" + color: { + if (NiriService.keyboardLayouts?.current_idx === 0) + return "#555"; + return "white"; + } + anchors.centerIn: parent + + text: { + const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx]; + if (!currentLayout) + return ""; + return kbdWidget.keyboardAbbrev[currentLayout] ? kbdWidget.keyboardAbbrev[currentLayout] : currentLayout; + } + } + + PopupWindow { + anchor { + item: kbdMouseArea + edges: Edges.Bottom + } + visible: kbdMouseArea.containsMouse + + implicitWidth: kbdTooltipText.contentWidth + 4 + implicitHeight: kbdTooltipText.contentHeight + 4 + color: "black" + + Text { + id: kbdTooltipText + + anchors.centerIn: parent + + font.pointSize: 10 + font.family: "Fira Sans" + color: "white" + + text: { + const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx]; + return currentLayout || ""; + } + } + } +} -- cgit v1.2.3