import Quickshell import QtQuick import qs.Services import Quickshell.Widgets 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 WrapperMouseArea { id: kbdMouseArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor enabled: true onClicked: { NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": "Next" } } }, _ => {}) } onWheel: event => { NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": event.angleDelta > 0 ? "Next" : "Prev" } } }, _ => {}) } 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 { id: tooltip property bool nextVisible: kbdMouseArea.containsMouse || tooltipMouseArea.containsMouse anchor { item: kbdMouseArea edges: Edges.Bottom | Edges.Left } visible: false onNextVisibleChanged: hangTimer.restart() Timer { id: hangTimer interval: 100 onTriggered: tooltip.visible = tooltip.nextVisible } implicitWidth: kbdTooltipText.contentWidth + 16 implicitHeight: kbdTooltipText.contentHeight + 16 color: "black" WrapperMouseArea { id: tooltipMouseArea hoverEnabled: true enabled: true anchors.centerIn: parent Text { id: kbdTooltipText font.pointSize: 10 font.family: "Fira Sans" color: "white" text: { const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx]; return currentLayout || ""; } } } } }