fix lang change hotkey

This commit is contained in:
Zoty 2026-04-23 10:42:20 -03:00
parent b41168aaaf
commit 90dd142107
Signed by: Zoty
SSH key fingerprint: SHA256:WsGEGivgl37t3Mth6uugXMOgMCTR7QolIepNbC+j/tA
2 changed files with 16 additions and 23 deletions

View file

@ -4,6 +4,7 @@ import QtQuick
BarPill {
id: root
layer.enabled: true
property int currentIdx: 0
property var names: []
@ -18,33 +19,25 @@ BarPill {
}
Process {
command: ["niri", "msg", "--json", "keyboard-layouts"]
command: ["niri", "msg", "--json", "event-stream"]
running: true
stdout: SplitParser {
splitMarker: ""
splitMarker: "\n"
onRead: data => {
try {
const kl = JSON.parse(data)
root.currentIdx = kl.current_idx
root.names = kl.names
const ev = JSON.parse(data)
if (ev.KeyboardLayoutsChanged) {
const kl = ev.KeyboardLayoutsChanged.keyboard_layouts
root.currentIdx = kl.current_idx
root.names = kl.names
} else if (ev.KeyboardLayoutSwitched) {
root.currentIdx = ev.KeyboardLayoutSwitched.idx
}
} catch (e) {}
}
}
}
Connections {
target: niri
function onRawEventReceived(event) {
try {
const ev = JSON.parse(event)
if (!ev.KeyboardLayoutsChanged) return
const kl = ev.KeyboardLayoutsChanged.keyboard_layouts
root.currentIdx = kl.current_idx
root.names = kl.names
} catch (e) {}
}
}
Text {
text: "󰌌"
color: Theme.purple
@ -52,6 +45,7 @@ BarPill {
font.family: Theme.font
}
Text {
id: shortNameText
text: root.shortName
color: Theme.text
font.pixelSize: Theme.fontSize
@ -60,9 +54,9 @@ BarPill {
Behavior on text {
// Flash the label on layout change
SequentialAnimation {
PropertyAnimation { target: parent; property: "opacity"; to: 0; duration: 80 }
PropertyAction { target: parent; property: "text" }
PropertyAnimation { target: parent; property: "opacity"; to: 1; duration: 80 }
PropertyAnimation { target: shortNameText; property: "opacity"; to: 0; duration: 80 }
PropertyAction { target: shortNameText; property: "text" }
PropertyAnimation { target: shortNameText; property: "opacity"; to: 1; duration: 80 }
}
}
}