bar: add kblayout popout

This commit is contained in:
2 * r + 2 * t 2025-08-19 17:30:33 +10:00
parent e60fa05504
commit 660f09959d
4 changed files with 17 additions and 7 deletions

View file

@ -42,11 +42,9 @@ StyledRect {
}
// Keyboard layout icon
Loader {
Layout.alignment: Qt.AlignHCenter
asynchronous: true
WrappedLoader {
name: "kblayout"
active: Config.bar.status.showKbLayout
visible: active
sourceComponent: StyledText {
animate: true

View file

@ -52,6 +52,11 @@ Item {
}
}
Popout {
name: "kblayout"
source: "KbLayout.qml"
}
Repeater {
model: ScriptModel {
values: [...SystemTray.items.values]

View file

@ -0,0 +1,6 @@
import qs.components
import qs.services
StyledText {
text: qsTr("Keyboard layout: %1").arg(Hyprland.kbLayoutFull)
}

View file

@ -15,7 +15,8 @@ Singleton {
readonly property HyprlandWorkspace focusedWorkspace: Hyprland.focusedWorkspace
readonly property HyprlandMonitor focusedMonitor: Hyprland.focusedMonitor
readonly property int activeWsId: focusedWorkspace?.id ?? 1
property string kbLayout: "?"
readonly property string kbLayout: kbLayoutFull.slice(0, 2).toLowerCase()
property string kbLayoutFull: "?"
function dispatch(request: string): void {
Hyprland.dispatch(request);
@ -34,7 +35,7 @@ Singleton {
return;
if (n === "activelayout") {
root.kbLayout = event.parse(2)[1].slice(0, 2).toLowerCase();
root.kbLayoutFull = event.parse(2)[1];
} else if (["workspace", "moveworkspace", "activespecial", "focusedmon"].includes(n)) {
Hyprland.refreshWorkspaces();
Hyprland.refreshMonitors();
@ -55,7 +56,7 @@ Singleton {
running: true
command: ["hyprctl", "-j", "devices"]
stdout: StdioCollector {
onStreamFinished: root.kbLayout = JSON.parse(text).keyboards.find(k => k.main).active_keymap.slice(0, 2).toLowerCase()
onStreamFinished: root.kbLayoutFull = JSON.parse(text).keyboards.find(k => k.main).active_keymap
}
}
}