#!/bin/bash
niri msg event-stream | while read -r line; do
  if echo "$line" | grep -q 'Keyboard layout switched'; then
    layout=$(echo "$line" | grep -oP '\d+$')
    if [ "$layout" = "1" ]; then
      brightnessctl -d'input12::capslock' s 1
    else
      brightnessctl -d'input12::capslock' s 0
    fi
  fi
done
