Skip to content

Instantly share code, notes, and snippets.

@harrigan
Created March 15, 2026 14:45
Show Gist options
  • Select an option

  • Save harrigan/cc89eb867e2d473f2014e9b7136dc213 to your computer and use it in GitHub Desktop.

Select an option

Save harrigan/cc89eb867e2d473f2014e9b7136dc213 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
trap 'echo "Error: Script failed due to command above."' ERR
# Workaround for xwayland-satellite not propagating keyboard focus
# to X11 clients on niri.
# https://github.com/Supreeeme/xwayland-satellite/issues/263
#
# Watches niri's JSON event stream for focus changes and uses xdotool
# to activate and click the X11 window, which is needed for toolkits
# like Java Swing to accept keyboard input.
niri msg --json event-stream | jq --unbuffered -r 'select(has("WindowFocusChanged")) | "focus"' | while read -r _; do
sleep 0.05
if win=$(xdotool getactivewindow 2>/dev/null); then
xdotool windowactivate --sync "$win"
xdotool click --window "$win" 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment