aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/island/Keyboard.qml
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/island/Keyboard.qml')
-rw-r--r--desktop/island/Keyboard.qml61
1 files changed, 61 insertions, 0 deletions
diff --git a/desktop/island/Keyboard.qml b/desktop/island/Keyboard.qml
new file mode 100644
index 0000000..1cbe9bc
--- /dev/null
+++ b/desktop/island/Keyboard.qml
@@ -0,0 +1,61 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+pragma Singleton
+
+import Quickshell
+import Quickshell.Io
+import Quickshell.Hyprland
+import QtQuick
+import "Logic.js" as Logic
+
+// The layout of whichever keyboard Hyprland marks main. Resolved per event,
+// never cached: the same keyboard is a different device over USB and over
+// its dongle, which is what broke wb-lang's hardcoded device name.
+Singleton {
+ id: root
+
+ property string keymap: ""
+ readonly property string flag: Logic.flagFor(keymap)
+
+ readonly property string mainKeyboard:
+ "hyprctl devices -j | jq -r '.keyboards[] | select(.main) | .name'"
+
+ Process {
+ id: query
+ running: true
+ command: ["sh", "-c",
+ "hyprctl devices -j | jq -r '.keyboards[] | select(.main) | .active_keymap'"]
+ stdout: StdioCollector { onStreamFinished: root.keymap = text.trim() }
+ }
+
+ Process { id: switcher }
+
+ function refresh() {
+ query.running = false;
+ query.running = true;
+ }
+
+ // dir is "next" or "prev", from the caller's own literal, never user text.
+ function cycle(dir) {
+ switcher.command = ["sh", "-c",
+ `hyprctl switchxkblayout "$(${root.mainKeyboard})" ${dir}`];
+ switcher.running = false;
+ switcher.running = true;
+ }
+
+ Connections {
+ target: Hyprland
+ function onRawEvent(event) {
+ if (event.name === "activelayout") root.refresh();
+ }
+ }
+}