From 20120205bb93b1195b59b68e452f90a6e394075c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 18 Nov 2019 01:11:26 +0100 Subject: Clipboard.c: Fix: re-claim selection on reconnect On reconnect claim the selection ownership if one of nxagent's clients is a selection owner. The code for this was already there but could not work because the lastSelectionOwner array was always dropped at the beginning of nxagentInitClipboard. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 48 +++++++++++++++----------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Clipboard.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 69cc7ecc5..a3d8fb5c1 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2127,19 +2127,26 @@ Bool nxagentInitClipboard(WindowPtr pWin) fprintf(stderr, "%s: Got called.\n", __func__); #endif - SAFE_free(lastSelectionOwner); + if (!nxagentReconnectTrap) + { + SAFE_free(lastSelectionOwner); - lastSelectionOwner = (SelectionOwner *) malloc(nxagentMaxSelections * sizeof(SelectionOwner)); + lastSelectionOwner = (SelectionOwner *) malloc(nxagentMaxSelections * sizeof(SelectionOwner)); - if (lastSelectionOwner == NULL) + if (lastSelectionOwner == NULL) + { + FatalError("nxagentInitClipboard: Failed to allocate memory for the clipboard selections.\n"); + } + nxagentInitSelectionOwner(nxagentPrimarySelection, XA_PRIMARY); + nxagentInitSelectionOwner(nxagentClipboardSelection, nxagentAtoms[10]); /* CLIPBOARD */ + } + else { - FatalError("nxagentInitClipboard: Failed to allocate memory for the clipboard selections.\n"); + /* the clipboard selection atom might have changed on the new X + server. Primary is constant. */ + lastSelectionOwner[nxagentClipboardSelection].selection = nxagentAtoms[10]; /* CLIPBOARD */ } - - nxagentInitSelectionOwner(nxagentPrimarySelection, XA_PRIMARY); - nxagentInitSelectionOwner(nxagentClipboardSelection, nxagentAtoms[10]); /* CLIPBOARD */ - #ifdef NXAGENT_TIMESTAMP { fprintf(stderr, "%s: Initializing start [%ld] milliseconds.\n", __func__, @@ -2229,22 +2236,23 @@ Bool nxagentInitClipboard(WindowPtr pWin) if (nxagentReconnectTrap) { - /* - * Only for PRIMARY and CLIPBOARD selections. - */ - - for (int i = 0; i < nxagentMaxSelections; i++) + if (nxagentOption(Clipboard) == ClipboardServer || + nxagentOption(Clipboard) == ClipboardBoth) { - /* - * if we have a selection inform the (new) real Xserver and - * claim the ownership. Note that we report our serverWindow as - * owner, not the real window! - */ - if (lastSelectionOwner[i].client && lastSelectionOwner[i].window) + for (int i = 0; i < nxagentMaxSelections; i++) { - XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime); + /* + * if we have a selection inform the (new) real Xserver and + * claim the ownership. Note that we report our serverWindow as + * owner, not the real window! + */ + if (lastSelectionOwner[i].client && lastSelectionOwner[i].window) + { + XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime); + } } } + /* FIXME: Shouldn't we reset lastServer* and lastClient* here? */ } else { -- cgit v1.2.3