#!/bin/sh # Throwaway dev wrapper: run a command inside a nested labwc (wlroots-family # host) so the clipboard bridge uses the ext-data-control backend. # Usage: nested-labwc.sh [--x11] # Default command: kick with two wltest tabs. set -e REPO="${KICK_REPO:-/home/ahamilton/code/kick}" RUNTIME="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" export WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}" export WLR_WL_OUTPUTS="${WLR_WL_OUTPUTS:-1}" MODE=wayland if [ "$1" = "--x11" ]; then MODE=x11 shift fi if [ "$MODE" = x11 ]; then export WLR_BACKENDS=x11 export DISPLAY="${DISPLAY:-:0}" echo "[nested-labwc] x11 backend on $DISPLAY" else export WLR_BACKENDS=wayland echo "[nested-labwc] wayland backend under $WAYLAND_DISPLAY" fi before="$(ls "$RUNTIME"/wayland-* 2>/dev/null || true)" labwc -t "labwc-dev" >/tmp/labwc.log 2>&1 & LABWC_PID=$! trap 'kill "$LABWC_PID" 2>/dev/null || true' EXIT INT TERM # Discover labwc's socket: the wayland-N that wasn't there before. Only match # plain wayland- sockets (labwc's name); portal/other compositors create # wayland-proxy-* sockets at arbitrary times and must be ignored. SOCK="" for i in $(seq 1 150); do for s in "$RUNTIME"/wayland-*; do [ -e "$s" ] || continue b="${s##*/}" case "$b" in *.lock|*proxy*) continue ;; wayland-[0-9]*) case "$before" in *"$s"*) ;; *) SOCK="$b"; break 2 ;; esac ;; esac done if ! kill -0 "$LABWC_PID" 2>/dev/null; then echo "[nested-labwc] labwc exited early; tail:" >&2 tail -20 /tmp/labwc.log >&2 exit 1 fi sleep 0.1 done if [ -z "$SOCK" ]; then echo "[nested-labwc] no new wayland socket appeared" >&2 tail -20 /tmp/labwc.log >&2 exit 1 fi echo "[nested-labwc] nested labwc socket: $SOCK" export WAYLAND_DISPLAY="$SOCK" if [ "$#" -eq 0 ]; then set -- "$REPO/build/kick" \ "$REPO/build/wltest '#ff0000'" \ "$REPO/build/wltest '#0000ff'" fi "$@" rc=$? kill "$LABWC_PID" 2>/dev/null || true exit "$rc"