diff --git a/modules/_home/niri.nix b/modules/_home/niri.nix index 523c9cb..673dc48 100644 --- a/modules/_home/niri.nix +++ b/modules/_home/niri.nix @@ -53,8 +53,7 @@ in { input { keyboard { xkb { - layout "us,pt" - variant ",br" + layout "us,br" } } touchpad { diff --git a/quickshell/KeyboardLayout.qml b/quickshell/KeyboardLayout.qml index 39bfa2f..0f16652 100644 --- a/quickshell/KeyboardLayout.qml +++ b/quickshell/KeyboardLayout.qml @@ -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 } } } }