import Quickshell import Quickshell.Io import QtQuick BarPill { id: root property int currentIdx: 0 property var names: [] readonly property string shortName: { if (names.length === 0) return "??" const n = names[currentIdx] ?? "" if (n.includes("Portuguese")) return "PT" if (n.includes("English")) return "EN" // fallback: first two chars of first word return n.split(" ")[0].substring(0, 2).toUpperCase() } Process { command: ["niri", "msg", "--json", "keyboard-layouts"] running: true stdout: SplitParser { splitMarker: "" onRead: data => { try { const kl = JSON.parse(data) root.currentIdx = kl.current_idx root.names = kl.names } 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 font.pixelSize: Theme.fontSize font.family: Theme.font } Text { text: root.shortName color: Theme.text font.pixelSize: Theme.fontSize font.family: Theme.font 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 } } } } }