diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml')
| -rw-r--r-- | accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml | 78 |
1 files changed, 78 insertions, 0 deletions
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 @@ | |||
| 1 | import Quickshell | ||
| 2 | import QtQuick | ||
| 3 | import qs.Services | ||
| 4 | |||
| 5 | Rectangle { | ||
| 6 | id: kbdWidget | ||
| 7 | |||
| 8 | property var keyboardAbbrev: { "English (programmer Dvorak)": "dvp", "English (US)": "us" } | ||
| 9 | |||
| 10 | width: kbdLabel.contentWidth + 8 | ||
| 11 | color: { | ||
| 12 | if (kbdMouseArea.containsMouse) { | ||
| 13 | return "#33808080"; | ||
| 14 | } | ||
| 15 | return "transparent"; | ||
| 16 | } | ||
| 17 | height: parent.height | ||
| 18 | anchors.verticalCenter: parent.verticalCenter | ||
| 19 | |||
| 20 | MouseArea { | ||
| 21 | id: kbdMouseArea | ||
| 22 | |||
| 23 | anchors.fill: parent | ||
| 24 | hoverEnabled: true | ||
| 25 | cursorShape: Qt.PointingHandCursor | ||
| 26 | enabled: true | ||
| 27 | onClicked: { | ||
| 28 | NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": "Next" } } }, _ => {}) | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | Text { | ||
| 33 | id: kbdLabel | ||
| 34 | |||
| 35 | font.pointSize: 10 | ||
| 36 | font.family: "Fira Sans" | ||
| 37 | color: { | ||
| 38 | if (NiriService.keyboardLayouts?.current_idx === 0) | ||
| 39 | return "#555"; | ||
| 40 | return "white"; | ||
| 41 | } | ||
| 42 | anchors.centerIn: parent | ||
| 43 | |||
| 44 | text: { | ||
| 45 | const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx]; | ||
| 46 | if (!currentLayout) | ||
| 47 | return ""; | ||
| 48 | return kbdWidget.keyboardAbbrev[currentLayout] ? kbdWidget.keyboardAbbrev[currentLayout] : currentLayout; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | PopupWindow { | ||
| 53 | anchor { | ||
| 54 | item: kbdMouseArea | ||
| 55 | edges: Edges.Bottom | ||
| 56 | } | ||
| 57 | visible: kbdMouseArea.containsMouse | ||
| 58 | |||
| 59 | implicitWidth: kbdTooltipText.contentWidth + 4 | ||
| 60 | implicitHeight: kbdTooltipText.contentHeight + 4 | ||
| 61 | color: "black" | ||
| 62 | |||
| 63 | Text { | ||
| 64 | id: kbdTooltipText | ||
| 65 | |||
| 66 | anchors.centerIn: parent | ||
| 67 | |||
| 68 | font.pointSize: 10 | ||
| 69 | font.family: "Fira Sans" | ||
| 70 | color: "white" | ||
| 71 | |||
| 72 | text: { | ||
| 73 | const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx]; | ||
| 74 | return currentLayout || ""; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
