From 8ff69175e7bf1d8899f524d8ed89b3db74642540 Mon Sep 17 00:00:00 2001 From: Guillaume Moutier Date: Tue, 17 Nov 2026 10:14:46 -0500 Subject: [PATCH] ccbox: fall back to wayland-0 socket and warn when clipboard is unwirable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add_clipboard_mounts() now uses \$WAYLAND_DISPLAY only when its socket exists, and falls back to \$XDG_RUNTIME_DIR/wayland-0 when the variable is unset or stale but the socket is live (shells born outside the graphical session: SSH, daemons, stripped envs) — mirrors libwayland's connect(NULL) default. - A clipboard-blind launch is no longer silent: log_warn 'No display server found' and the status line now reports enabled (Wayland) / (X11) / unavailable (no display server) instead of a blanket 'enabled'. - docs/usage.md clipboard section updated to match. --- docs/usage.md | 3 ++- lib/box-common.sh | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 8e79353..c62e97c 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -339,9 +339,10 @@ Restricts outbound connections to an allowlist baked into the image (GitHub, pac Image pasting (CTRL+V) requires display server access: -- **Linux/Wayland**: automatically detected via `$WAYLAND_DISPLAY` +- **Linux/Wayland**: automatically detected via `$WAYLAND_DISPLAY`, falling back to `wayland-0` in `$XDG_RUNTIME_DIR` when the variable is unset or stale but the socket exists (shells started outside the graphical session, e.g. over SSH or from a daemon) - **Linux/X11**: automatically detected via `$DISPLAY` and `/tmp/.X11-unix` - **macOS**: requires [XQuartz](https://www.xquartz.org/) with "Allow connections from network clients" enabled +- **None found**: the launcher prints a `[WARN] No display server found` line and reports `Clipboard: unavailable` in the status, so a clipboard-blind session is never silent To disable clipboard access: `ccbox --no-clipboard` diff --git a/lib/box-common.sh b/lib/box-common.sh index 271c08e..103a7a1 100644 --- a/lib/box-common.sh +++ b/lib/box-common.sh @@ -929,11 +929,22 @@ select_runtime() { # Clipboard/display access for image pasting (CTRL+V) add_clipboard_mounts() { if [[ "$OS_TYPE" == "linux" ]]; then - if [[ -n "$WAYLAND_DISPLAY" && -S "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]]; then + # A shell outside the graphical session (SSH, a daemon, a stripped + # env) can miss $WAYLAND_DISPLAY or carry a stale one while the + # socket is right there; fall back to the default name, like + # libwayland's wl_display_connect(NULL). + local wl_display="" + if [[ -n "$WAYLAND_DISPLAY" && -n "$XDG_RUNTIME_DIR" && -S "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]]; then + wl_display="$WAYLAND_DISPLAY" + elif [[ -n "$XDG_RUNTIME_DIR" && -S "${XDG_RUNTIME_DIR}/wayland-0" ]]; then + wl_display="wayland-0" + fi + if [[ -n "$wl_display" ]]; then # Wayland clipboard access - add_mount "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" "ro,nolabel" - add_env WAYLAND_DISPLAY "$WAYLAND_DISPLAY" + add_mount "${XDG_RUNTIME_DIR}/${wl_display}" "${XDG_RUNTIME_DIR}/${wl_display}" "ro,nolabel" + add_env WAYLAND_DISPLAY "$wl_display" add_env XDG_RUNTIME_DIR "$XDG_RUNTIME_DIR" + CLIPBOARD_STATUS="enabled (Wayland)" elif [[ -n "$DISPLAY" && -d /tmp/.X11-unix ]]; then # X11 clipboard access add_mount /tmp/.X11-unix /tmp/.X11-unix "ro,nolabel" @@ -941,12 +952,17 @@ add_clipboard_mounts() { if [[ -f "${HOME}/.Xauthority" ]]; then add_mount "${HOME}/.Xauthority" /home/coder/.Xauthority "ro" fi + CLIPBOARD_STATUS="enabled (X11)" + else + log_warn "No display server found: clipboard image pasting will not work" + CLIPBOARD_STATUS="unavailable (no display server)" fi elif [[ "$OS_TYPE" == "macos" ]]; then # macOS: basic X11 support via XQuartz (if available) if [[ -n "$DISPLAY" && -d /tmp/.X11-unix ]]; then add_mount /tmp/.X11-unix /tmp/.X11-unix "ro,nolabel" add_env DISPLAY "$DISPLAY" + CLIPBOARD_STATUS="enabled (X11)" fi fi } @@ -1302,7 +1318,7 @@ box_main() { log_info "Workspace: $WORKSPACE_DIR" log_info "Session: $SESSION_ID" log_info "Firewall: $(if $NO_FIREWALL; then echo 'disabled'; else echo 'enabled'; fi)" - log_info "Clipboard: $(if $NO_CLIPBOARD; then echo 'disabled'; else echo 'enabled'; fi)" + log_info "Clipboard: ${CLIPBOARD_STATUS:-$(if $NO_CLIPBOARD; then echo 'disabled'; else echo 'enabled'; fi)}" [[ -n "$MEMORY_BUDGET_STATUS" ]] && log_info "$MEMORY_BUDGET_STATUS" harness_log_status if $NO_GITHUB; then