Skip to content

Instantly share code, notes, and snippets.

@shuairan
Created February 14, 2026 23:16
Show Gist options
  • Select an option

  • Save shuairan/edbf4b670353960c6baeaf3a82b3ebf0 to your computer and use it in GitHub Desktop.

Select an option

Save shuairan/edbf4b670353960c6baeaf3a82b3ebf0 to your computer and use it in GitHub Desktop.
#!/bin/bash
declare -A MONITOR_WIDTH_CONFIG=(
["DP-1"]="50%"
["DP-2"]="100%"
)
LAST_OUTPUT=""
LAST_ACTIVE_WINDOW=""
niri msg --json event-stream | while read -r line; do
if echo "$line" | jq -e 'has("WindowOpenedOrChanged")' > /dev/null; then
WINDOW_DATA=$(niri msg -j focused-window)
IS_FLOATING=$(echo "$WINDOW_DATA" | jq -r '.is_floating')
if [ "$IS_FLOATING" = "false" ]; then
CURRENT_OUTPUT=$(niri msg -j focused-output | jq -r '.name // empty')
if [ "$CURRENT_OUTPUT" != "$LAST_OUTPUT" ] && [ -n "$CURRENT_OUTPUT" ]; then
WIDTH="${MONITOR_WIDTH_CONFIG[$CURRENT_OUTPUT]}"
if [ -n "$WIDTH" ]; then
niri msg action set-column-width "$WIDTH"
fi
LAST_OUTPUT="$CURRENT_OUTPUT"
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment