From faf1e5c0a3413783d9c213ed8243732d771defe0 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 13 Dec 2024 17:46:36 +0700 Subject: [PATCH] #4441 re-claim the clipboard selection whenever we get a token this can be disabled by setting XPRA_CLIPBOARD_RECLAIM=0 --- xpra/x11/gtk_x11/clipboard.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/xpra/x11/gtk_x11/clipboard.py b/xpra/x11/gtk_x11/clipboard.py index 5932e23ad4..9f8d5e53c2 100644 --- a/xpra/x11/gtk_x11/clipboard.py +++ b/xpra/x11/gtk_x11/clipboard.py @@ -8,6 +8,7 @@ from typing import List, Dict, Tuple, Iterable, Callable, Any from gi.repository import GLib, GObject, Gdk # @UnresolvedImport +from xpra.util import envbool from xpra.gtk_common.error import xsync, xswallow from xpra.gtk_common.gobject_util import one_arg_signal, n_arg_signal from xpra.gtk_common.gtk_util import get_default_root_window @@ -48,6 +49,8 @@ MAX_DATA_SIZE : int = 4*1024*1024 +RECLAIM = envbool("XPRA_CLIPBOARD_RECLAIM", True) + BLACKLISTED_CLIPBOARD_CLIENTS: List[str] = os.environ.get( "XPRA_BLACKLISTED_CLIPBOARD_CLIENTS", "clipit,Software,gnome-shell" @@ -187,15 +190,14 @@ def claim(self) -> None: try: with xsync: owner = X11Window.XGetSelectionOwner(self._selection) - if owner==self.xid: - self.owned = True - log("claim() we already own the '%s' selection", self._selection) - return - setsel = X11Window.XSetSelectionOwner(self.xid, self._selection, time) - owner = X11Window.XGetSelectionOwner(self._selection) - self.owned = owner==self.xid - log("claim_selection: set selection owner returned %s, owner=%#x, owned=%s", - setsel, owner, self.owned) + if RECLAIM or not self.owned: + setsel = X11Window.XSetSelectionOwner(self.xid, self._selection, time) + owner = X11Window.XGetSelectionOwner(self._selection) + self.owned = owner == self.xid + log("claim_selection: set selection owner returned %s, owner=%#x, owned=%s", + setsel, owner, self.owned) + else: + log("we already owned the %r selection", self._selection) if not self.owned: log.warn("Warning: we failed to get ownership of the '%s' clipboard selection", self._selection) return