From e1094a80f0cec49e246a26f4f2f3307e344fd263 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 7 Oct 2026 18:51:43 +0200 Subject: 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 --- desktop/island/Keyboard.qml | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 desktop/island/Keyboard.qml (limited to 'desktop/island/Keyboard.qml') 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. +// +// 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(); + } + } +} -- cgit v1.2.3