summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml')
-rw-r--r--accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml104
1 files changed, 66 insertions, 38 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml b/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml
index 710ea10c..bc3750f9 100644
--- a/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml
+++ b/accounts/gkleen@sif/shell/quickshell/KeyboardLayout.qml
@@ -1,77 +1,105 @@
1import Quickshell 1import Quickshell
2import QtQuick 2import QtQuick
3import qs.Services 3import qs.Services
4import Quickshell.Widgets
4 5
5Rectangle { 6Item {
6 id: kbdWidget
7
8 property var keyboardAbbrev: { "English (programmer Dvorak)": "dvp", "English (US)": "us" }
9
10 width: kbdLabel.contentWidth + 8 7 width: kbdLabel.contentWidth + 8
11 color: {
12 if (kbdMouseArea.containsMouse) {
13 return "#33808080";
14 }
15 return "transparent";
16 }
17 height: parent.height 8 height: parent.height
18 anchors.verticalCenter: parent.verticalCenter 9 anchors.verticalCenter: parent.verticalCenter
19 10
20 MouseArea { 11 WrapperMouseArea {
21 id: kbdMouseArea 12 id: kbdMouseArea
22 13
23 anchors.fill: parent 14 anchors.fill: parent
15
24 hoverEnabled: true 16 hoverEnabled: true
25 cursorShape: Qt.PointingHandCursor 17 cursorShape: Qt.PointingHandCursor
26 enabled: true 18 enabled: true
27 onClicked: { 19 onClicked: {
28 NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": "Next" } } }, _ => {}) 20 NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": "Next" } } }, _ => {})
29 } 21 }
30 } 22 onWheel: event => {
23 NiriService.sendCommand({ "Action": { "SwitchLayout": { "layout": event.angleDelta > 0 ? "Next" : "Prev" } } }, _ => {})
24 }
31 25
32 Text { 26 Rectangle {
33 id: kbdLabel 27 id: kbdWidget
34 28
35 font.pointSize: 10 29 property var keyboardAbbrev: { "English (programmer Dvorak)": "dvp", "English (US)": "us" }
36 font.family: "Fira Sans" 30
37 color: { 31 anchors.fill: parent
38 if (NiriService.keyboardLayouts?.current_idx === 0) 32 color: {
39 return "#555"; 33 if (kbdMouseArea.containsMouse) {
40 return "white"; 34 return "#33808080";
41 } 35 }
42 anchors.centerIn: parent 36 return "transparent";
37 }
43 38
44 text: { 39 Text {
45 const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx]; 40 id: kbdLabel
46 if (!currentLayout) 41
47 return ""; 42 font.pointSize: 10
48 return kbdWidget.keyboardAbbrev[currentLayout] ? kbdWidget.keyboardAbbrev[currentLayout] : currentLayout; 43 font.family: "Fira Sans"
44 color: {
45 if (NiriService.keyboardLayouts?.current_idx === 0)
46 return "#555";
47 return "white";
48 }
49 anchors.centerIn: parent
50
51 text: {
52 const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx];
53 if (!currentLayout)
54 return "";
55 return kbdWidget.keyboardAbbrev[currentLayout] ? kbdWidget.keyboardAbbrev[currentLayout] : currentLayout;
56 }
57 }
49 } 58 }
50 } 59 }
51 60
52 PopupWindow { 61 PopupWindow {
62 id: tooltip
63
64 property bool nextVisible: kbdMouseArea.containsMouse || tooltipMouseArea.containsMouse
65
53 anchor { 66 anchor {
54 item: kbdMouseArea 67 item: kbdMouseArea
55 edges: Edges.Bottom 68 edges: Edges.Bottom | Edges.Left
69 }
70 visible: false
71
72 onNextVisibleChanged: hangTimer.restart()
73
74 Timer {
75 id: hangTimer
76 interval: 100
77 onTriggered: tooltip.visible = tooltip.nextVisible
56 } 78 }
57 visible: kbdMouseArea.containsMouse
58 79
59 implicitWidth: kbdTooltipText.contentWidth + 16 80 implicitWidth: kbdTooltipText.contentWidth + 16
60 implicitHeight: kbdTooltipText.contentHeight + 16 81 implicitHeight: kbdTooltipText.contentHeight + 16
61 color: "black" 82 color: "black"
62 83
63 Text { 84 WrapperMouseArea {
64 id: kbdTooltipText 85 id: tooltipMouseArea
86
87 hoverEnabled: true
88 enabled: true
65 89
66 anchors.centerIn: parent 90 anchors.centerIn: parent
67 91
68 font.pointSize: 10 92 Text {
69 font.family: "Fira Sans" 93 id: kbdTooltipText
70 color: "white" 94
95 font.pointSize: 10
96 font.family: "Fira Sans"
97 color: "white"
71 98
72 text: { 99 text: {
73 const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx]; 100 const currentLayout = NiriService.keyboardLayouts?.names?.[NiriService.keyboardLayouts.current_idx];
74 return currentLayout || ""; 101 return currentLayout || "";
102 }
75 } 103 }
76 } 104 }
77 } 105 }