From e3afb85f23c0e59b2a818094ee7b391ca2f3504d Mon Sep 17 00:00:00 2001 From: atagen Date: Mon, 16 Feb 2026 00:38:27 +1100 Subject: [PATCH] filter repeat events --- niri-s76-bridge.nu | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/niri-s76-bridge.nu b/niri-s76-bridge.nu index 2b5a2b1..58e933e 100755 --- a/niri-s76-bridge.nu +++ b/niri-s76-bridge.nu @@ -6,59 +6,58 @@ def main [] { } print "niri-s76-bridge started" - niri msg -j event-stream | lines | reduce --fold [] { |line, windows| + niri msg -j event-stream | lines | reduce --fold {focused: 0, windows: []} { |line, state| let event = $line | from json let event_type = $event | columns | first + mut windows = $state.windows + mut current = $state.focused match $event_type { "WindowsChanged" => { - mut acc = $windows for w in $event.WindowsChanged.windows { - if $w.pid != null and $w.is_focused { + if $w.pid != null and $w.is_focused and $w.pid != $current { notify-scheduler $w.pid + $current = $w.pid } if $w.pid != null { - let existing = $acc | where id == $w.id + let existing = $windows | where id == $w.id if ($existing | is-empty) { - $acc = ($acc | append {id: $w.id, pid: $w.pid}) + $windows = ($windows | append {id: $w.id, pid: $w.pid}) } } } - $acc } "WindowOpenedOrChanged" => { let w = $event.WindowOpenedOrChanged.window - if $w.is_focused and $w.pid != null { + if $w.is_focused and $w.pid != null and $w.pid != $current { notify-scheduler $w.pid + $current = $w.pid } if $w.pid != null { - let existing = $windows | where id == $w.id + let existing = $state.windows | where id == $w.id if ($existing | is-empty) { - $windows | append {id: $w.id, pid: $w.pid} - } else { - $windows + $windows = $windows | append {id: $w.id, pid: $w.pid} } - } else { - $windows } } "WindowFocusChanged" => { let focused_id = $event.WindowFocusChanged.id if $focused_id != null { - let match = $windows | where id == $focused_id + let match = $state.windows | where id == $focused_id if not ($match | is-empty) { let focused_pid = $match.0.pid - if $focused_pid != null { + if $focused_pid != null and $focused_pid != $current { notify-scheduler $focused_pid + $current = $focused_pid } } } - $windows } "WindowClosed" => { - $windows | where id != $event.WindowClosed.id + $windows = $windows | where id != $event.WindowClosed.id } - _ => $windows + _ => () } + {focused: $current, windows: $windows} } }