#!/usr/bin/env bash set -euo pipefail # Fix CopyQ Flatpak on Ubuntu GNOME Wayland: # - Force XWayland because Flatpak cannot install CopyQ's GNOME Shell monitor. # - Start CopyQ automatically in the current user's desktop session. # - Disable unsupported primary-selection monitoring. # # Run as the desktop user, not with sudo: # bash fix-copyq-on-gnome-wayland.sh # # To undo the Flatpak override later: # flatpak override --user --reset com.github.hluk.copyq app_id="com.github.hluk.copyq" app_label="CopyQ" autostart_dir="${XDG_CONFIG_HOME:-$HOME/.config}/autostart" autostart_file="$autostart_dir/$app_id.desktop" start_log="${XDG_RUNTIME_DIR:-/tmp}/copyq-flatpak-start.log" if ! command -v flatpak >/dev/null 2>&1; then printf 'Error: flatpak is not installed.\n' >&2 exit 1 fi if ! flatpak info "$app_id" >/dev/null 2>&1; then printf 'Error: %s is not installed.\n' "$app_id" >&2 exit 1 fi printf '[1/5] Forcing %s to use XWayland...\n' "$app_label" flatpak override --user \ --socket=x11 \ --nosocket=wayland \ --env=QT_QPA_PLATFORM=xcb \ "$app_id" printf '[2/5] Creating desktop autostart entry...\n' mkdir -p "$autostart_dir" tmp_file="$(mktemp "$autostart_dir/.copyq-autostart.XXXXXX")" trap 'rm -f "$tmp_file"' EXIT cat >"$tmp_file" </dev/null 2>&1 || true sleep 1 nohup flatpak run \ --branch=stable \ --arch=x86_64 \ "$app_id" \ --start-server \ >"$start_log" 2>&1 & printf '[4/5] Waiting for the CopyQ server...\n' ready=0 for _ in $(seq 1 60); do if flatpak run --command=copyq "$app_id" count >/dev/null 2>&1; then ready=1 break fi sleep 0.5 done if [[ "$ready" -ne 1 ]]; then printf 'Error: CopyQ did not start. See %s\n' "$start_log" >&2 exit 2 fi printf '[5/5] Applying clipboard compatibility settings...\n' flatpak run --command=copyq "$app_id" config check_selection false >/dev/null flatpak run --command=copyq "$app_id" config run_selection false >/dev/null # Do not inject paste keystrokes after activating an item. On GNOME Wayland # that path requests Remote Desktop input-control permission from the portal. flatpak run --command=copyq "$app_id" config activate_pastes false >/dev/null flatpak run --command=copyq "$app_id" config tray_item_paste false >/dev/null printf '\nCopyQ is running with the XWayland compatibility configuration.\n' printf 'Autostart entry: %s\n' "$autostart_file" printf 'Current version: ' flatpak run --command=copyq "$app_id" --version | head -n 1