#!/bin/sh
# Hyprland propagates PRIMARY ownership across the Xwayland boundary but not the
# contents, so Xwayland clients get an empty middle-click paste. Its proxy will
# still serve a direct STRING request, but it advertises no text target, and Qt
# asks for TARGETS first and gives up. See hyprwm/Hyprland#6603.

wl-paste --primary --watch xclip -selection primary -i &

# Mapping a new Xwayland window makes Hyprland seize PRIMARY back, so re-push
# whenever the X side stops offering a text target.
while sleep 1; do
    wl-paste --primary --no-newline >/dev/null 2>&1 || continue
    xclip -o -selection primary -t TARGETS 2>/dev/null | grep -qE 'STRING|text/plain' && continue
    wl-paste --primary --no-newline 2>/dev/null | xclip -selection primary -i
done
