aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/island/Keyboard.qml
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-07 18:51:43 +0200
committerDanilo M. <danix@danix.xyz>2026-10-07 18:51:43 +0200
commite1094a80f0cec49e246a26f4f2f3307e344fd263 (patch)
treed669ffc66dcbe605ea5ba27e372f60a18ba8e80a /desktop/island/Keyboard.qml
parente005e2237c3c3ea7dab7e1059c7432245903959c (diff)
downloadquickshell-e1094a80f0cec49e246a26f4f2f3307e344fd263.tar.gz
quickshell-e1094a80f0cec49e246a26f4f2f3307e344fd263.zip
feat(island): keyboard layout of the main keyboard
The flag follows whichever keyboard Hyprland marks main, looked up on every activelayout event and every switch. wb-lang read a fixed device name and went blank when the keyboard moved from its dongle to USB. Flags copied from waybar-theme-udt, which goes away with waybar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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();
+ }
+ }
+}