From fba367160b09aee08cb2ec96dc86e32f56e7fa44 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 11:47:39 +0100 Subject: Clipboard.c: refactor nxagent*SelectionOwner expect an index instead of a pointer All calls referenced lastSelectionOwner so let the function directly use it and only pass the required index. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 56 +++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index b42396731..da0899dd7 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -493,21 +493,30 @@ Bool nxagentValidServerTargets(XlibAtom target) return False; } -void nxagentClearSelectionOwner(SelectionOwner *owner) +void nxagentInitSelectionOwner(int index, Atom selection) { - /* there's no owner on nxagent side anymore */ - owner->client = NULL; - owner->window = None; - owner->lastTimeChanged = GetTimeInMillis(); - /* FIXME: why is windowPtr not cleared in the function? */ + lastSelectionOwner[index].selection = selection; + lastSelectionOwner[index].client = NullClient; + lastSelectionOwner[index].window = screenInfo.screens[0]->root->drawable.id; + lastSelectionOwner[index].windowPtr = NULL; + lastSelectionOwner[index].lastTimeChanged = GetTimeInMillis(); } -void nxagentStoreSelectionOwner(SelectionOwner *owner, Selection *sel) +/* there's no owner on nxagent side anymore */ +void nxagentClearSelectionOwner(int index) { - owner->client = sel->client; - owner->window = sel->window; - owner->windowPtr = sel->pWin; - owner->lastTimeChanged = GetTimeInMillis(); + lastSelectionOwner[index].client = NULL; + lastSelectionOwner[index].window = None; + lastSelectionOwner[index].lastTimeChanged = GetTimeInMillis(); + /* FIXME: why is windowPtr not cleared in the function? */ +} + +void nxagentStoreSelectionOwner(int index, Selection *sel) +{ + lastSelectionOwner[index].client = sel->client; + lastSelectionOwner[index].window = sel->window; + lastSelectionOwner[index].windowPtr = sel->pWin; + lastSelectionOwner[index].lastTimeChanged = GetTimeInMillis(); } void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) @@ -534,7 +543,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) #endif /* FIXME: why is windowPtr not cleared in the function? */ - nxagentClearSelectionOwner(&lastSelectionOwner[i]); + nxagentClearSelectionOwner(i); lastSelectionOwner[i].windowPtr = NULL; lastClientWindowPtr = NULL; @@ -618,7 +627,7 @@ void nxagentClearSelection(XEvent *X) CurrentSelections[i].window = screenInfo.screens[0]->root->drawable.id; CurrentSelections[i].client = NullClient; - nxagentClearSelectionOwner(&lastSelectionOwner[i]); + nxagentClearSelectionOwner(i); } lastClientWindowPtr = NULL; @@ -1418,7 +1427,7 @@ void nxagentResetSelectionOwner(void) fprintf(stderr, "%s: Reset selection state for selection [%d].\n", __func__, i); #endif - nxagentClearSelectionOwner(&lastSelectionOwner[i]); + nxagentClearSelectionOwner(i); lastSelectionOwner[i].windowPtr = NULL; } @@ -1570,7 +1579,7 @@ void nxagentSetSelectionOwner(Selection *pSelection) * points to the struct that contains all information about the * owner window. */ - nxagentStoreSelectionOwner(&lastSelectionOwner[i], pSelection); + nxagentStoreSelectionOwner(i, pSelection); } } @@ -2009,15 +2018,6 @@ WindowPtr nxagentGetClipboardWindow(Atom property) } } -void nxagentInitSelectionOwner(SelectionOwner *owner, Atom selection) -{ - owner->selection = selection; - owner->client = NullClient; - owner->window = screenInfo.screens[0]->root->drawable.id; - owner->windowPtr = NULL; - owner->lastTimeChanged = GetTimeInMillis(); -} - int nxagentInitClipboard(WindowPtr pWin) { Window iWindow = nxagentWindow(pWin); @@ -2037,8 +2037,8 @@ int nxagentInitClipboard(WindowPtr pWin) serverTIMESTAMP = nxagentAtoms[11]; /* TIMESTAMP */ - nxagentInitSelectionOwner(&lastSelectionOwner[nxagentPrimarySelection], XA_PRIMARY); - nxagentInitSelectionOwner(&lastSelectionOwner[nxagentClipboardSelection], nxagentAtoms[10]); /* CLIPBOARD */ + nxagentInitSelectionOwner(nxagentPrimarySelection, XA_PRIMARY); + nxagentInitSelectionOwner(nxagentClipboardSelection, nxagentAtoms[10]); /* CLIPBOARD */ #ifdef NXAGENT_TIMESTAMP { @@ -2143,8 +2143,8 @@ int nxagentInitClipboard(WindowPtr pWin) } else { - lastSelectionOwner[nxagentPrimarySelection].client = NULL; - lastSelectionOwner[nxagentClipboardSelection].client = NULL; + nxagentClearSelectionOwner(nxagentPrimarySelection); + nxagentClearSelectionOwner(nxagentClipboardSelection); lastServerRequestor = None; -- cgit v1.2.3 From 1feb4985ebc5abb20bcd59ace1ee190c9cddbaac Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 16:27:15 +0100 Subject: Clipboard.c: make agentClipboardStatus a Boolean and add debugging information around its checks. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 57 +++++++++++++++++++------- 1 file changed, 43 insertions(+), 14 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index da0899dd7..8fd6dc7bb 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -67,7 +67,7 @@ extern Selection *CurrentSelections; int nxagentLastClipboardClient = -1; -static int agentClipboardStatus; +static int agentClipboardInitialized = False; #ifdef DEBUG static int clientAccum; #endif @@ -285,14 +285,14 @@ void nxagentPrintClipboardStat(char *header) fprintf(stderr, "/----- Clipboard internal status - %s -----\n", header); fprintf(stderr, " current time (Time) [%u]\n", GetTimeInMillis()); - fprintf(stderr, " agentClipboardStatus (int) [%d]\n", agentClipboardStatus); + fprintf(stderr, " agentClipboardInitialized (Bool) [%s]\n", agentClipboardInitialized ? "True" : "False"); fprintf(stderr, " clientAccum (int) [%d]\n", clientAccum); fprintf(stderr, " nxagentMaxSelections (int) [%d]\n", nxagentMaxSelections); fprintf(stderr, " NumCurrentSelections (int) [%d]\n", NumCurrentSelections); fprintf(stderr, " serverWindow (Window) [0x%x]\n", serverWindow); fprintf(stderr, " nxagentLastClipboardClient (int) [%d]\n", nxagentLastClipboardClient); - fprintf(stderr, " ClipboardMode "); + fprintf(stderr, " Clipboard mode "); switch(nxagentOption(Clipboard)) { case ClipboardBoth: fprintf(stderr, "[Both]"); break;; @@ -597,9 +597,19 @@ void nxagentClearSelection(XEvent *X) nxagentPrintClipboardStat("before nxagentClearSelection"); - if (agentClipboardStatus != 1 || - nxagentOption(Clipboard) == ClipboardServer) + if (!agentClipboardInitialized) { + #ifdef DEBUG + fprintf(stderr, "%s: clipboard not initialized - doing nothing.\n", __func__); + #endif + return; + } + + if (nxagentOption(Clipboard) == ClipboardServer) + { + #ifdef DEBUG + fprintf(stderr, "%s: clipboard mode 'server' - doing nothing.\n", __func__); + #endif return; } @@ -696,8 +706,11 @@ void nxagentRequestSelection(XEvent *X) nxagentPrintClipboardStat("before nxagentRequestSelection"); - if (agentClipboardStatus != 1) + if (!agentClipboardInitialized) { + #ifdef DEBUG + fprintf(stderr, "%s: clipboard not initialized - doing nothing.\n", __func__); + #endif return; } @@ -1215,8 +1228,11 @@ void nxagentCollectPropertyEvent(int resource) */ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) { - if (agentClipboardStatus != 1) + if (!agentClipboardInitialized) { + #ifdef DEBUG + fprintf(stderr, "%s: clipboard not initialized - doing nothing.\n", __func__); + #endif return; } @@ -1521,8 +1537,11 @@ void nxagentSetSelectionCallback(CallbackListPtr *callbacks, void *data, */ void nxagentSetSelectionOwner(Selection *pSelection) { - if (agentClipboardStatus != 1) + if (!agentClipboardInitialized) { + #ifdef DEBUG + fprintf(stderr, "%s: clipboard not initialized - doing nothing.\n", __func__); + #endif return; } @@ -1637,9 +1656,19 @@ void nxagentNotifyConvertFailure(ClientPtr client, Window requestor, int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, Window requestor, Atom property, Atom target, Time time) { - if (agentClipboardStatus != 1 || - nxagentOption(Clipboard) == ClipboardServer) + if (!agentClipboardInitialized) { + #ifdef DEBUG + fprintf(stderr, "%s: clipboard not initialized - doing nothing.\n", __func__); + #endif + return 0; + } + + if (nxagentOption(Clipboard) == ClipboardServer) + { + #ifdef DEBUG + fprintf(stderr, "%s: clipboard mode 'server' - doing nothing.\n", __func__); + #endif return 0; } @@ -1894,10 +1923,10 @@ int nxagentSendNotify(xEvent *event) fprintf(stderr, "%s: Got called.\n", __func__); #endif - if (agentClipboardStatus != 1) + if (!agentClipboardInitialized) { #ifdef DEBUG - fprintf(stderr, "%s: agentClipboardStatus != 1 - doing nothing.\n", __func__); + fprintf(stderr, "%s: clipboard not initialized - doing nothing.\n", __func__); #endif return 0; } @@ -2049,7 +2078,7 @@ int nxagentInitClipboard(WindowPtr pWin) } #endif - agentClipboardStatus = 0; + agentClipboardInitialized = False; serverWindow = iWindow; /* @@ -2170,7 +2199,7 @@ int nxagentInitClipboard(WindowPtr pWin) } } - agentClipboardStatus = 1; + agentClipboardInitialized = True; #ifdef DEBUG fprintf(stderr, "%s: Clipboard initialization completed.\n", __func__); -- cgit v1.2.3 From 5540a14925a0145444bf11c507d53bbcf633508a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 16:28:18 +0100 Subject: Clipboard.c: add nxagentMatchSelectionOwner helper function --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 8fd6dc7bb..52f06f47d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -519,6 +519,12 @@ void nxagentStoreSelectionOwner(int index, Selection *sel) lastSelectionOwner[index].lastTimeChanged = GetTimeInMillis(); } +Bool nxagentMatchSelectionOwner(int index, ClientPtr pClient, WindowPtr pWindow) +{ + return ((pClient && lastSelectionOwner[index].client == pClient) || + (pWindow && lastSelectionOwner[index].windowPtr == pWindow)); +} + void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) { #ifdef DEBUG @@ -534,8 +540,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) for (int i = 0; i < nxagentMaxSelections; i++) { - if ((pClient != NULL && lastSelectionOwner[i].client == pClient) || - (pWindow != NULL && lastSelectionOwner[i].windowPtr == pWindow)) + if (nxagentMatchSelectionOwner(i, pClient, pWindow)) { #ifdef TEST fprintf(stderr, "%s: Resetting state with client [%p] window [%p].\n", __func__, -- cgit v1.2.3 From 9226abf6673fa5378f59ef76226472de07f81e85 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 16:29:02 +0100 Subject: Clipboard.c: add FIXMEs --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 52f06f47d..623b7a642 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -795,6 +795,7 @@ void nxagentRequestSelection(XEvent *X) * used to obtain the selection. * * FIXME: ensure we are reporting an _external_ timestamp + * FIXME: for a 32 bit property list we need to pass a "long" array, not "char"! */ int i = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); @@ -1816,6 +1817,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, /* * The same client made consecutive requests of clipboard content * with less than 5 seconds time interval between them. + * FIXME: this does not take the selection into account, so a + * client requesting PRIMARY and CLIPBOARD would match here, too */ fprintf(stderr, "%s: Consecutives request from client [%p] selection [%u] " -- cgit v1.2.3 From ffce5337d8a682a1ac88476cdda074c8a5109247 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 16:29:24 +0100 Subject: Clipboard.c: reformat some comments --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 623b7a642..1279848fc 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -1579,10 +1579,8 @@ void nxagentSetSelectionOwner(Selection *pSelection) { #ifdef DEBUG fprintf(stderr, "%s: lastSelectionOwner.client [%p] index [%d] -> [%p] index [%d]\n", __func__, - (void *)lastSelectionOwner[i].client, - CLINDEX(lastSelectionOwner[i].client), - (void *)pSelection->client, - CLINDEX(pSelection->client)); + (void *)lastSelectionOwner[i].client, CLINDEX(lastSelectionOwner[i].client), + (void *)pSelection->client, CLINDEX(pSelection->client)); fprintf(stderr, "%s: lastSelectionOwner.window [0x%x] -> [0x%x]\n", __func__, lastSelectionOwner[i].window, pSelection->window); fprintf(stderr, "%s: lastSelectionOwner.windowPtr [%p] -> [%p] [0x%x] (serverWindow: [0x%x])\n", __func__, @@ -1616,7 +1614,7 @@ void nxagentSetSelectionOwner(Selection *pSelection) /* FIXME - if (XGetSelectionOwner(nxagentDisplay,pSelection->selection)==serverWindow) + if (XGetSelectionOwner(nxagentDisplay,pSelection->selection) == serverWindow) { fprintf (stderr, "%s: SetSelectionOwner OK\n", __func__); -- cgit v1.2.3 From cc01d49929f3d1ada9184a07f16184a50aa9ebd6 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 17:30:14 +0100 Subject: Clipboard.c, NXproperty.c: match prototypes The prototype for nxagentGetClipboardWindow has been changed in 63320437ed4e95246ce62193560098f986ac265c but the changes have not made it into NXproperty.c... --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 5 +++++ nx-X11/programs/Xserver/hw/nxagent/NXproperty.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 1279848fc..ca9c32486 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2033,6 +2033,11 @@ int nxagentSendNotify(xEvent *event) return 0; } +/* + * This is called from NXproperty.c to determine if a client sets the + * property we are waiting for. + * FIXME: in addition we should check if the client is the one we expect + */ WindowPtr nxagentGetClipboardWindow(Atom property) { int i = nxagentFindLastSelectionOwnerIndex(nxagentLastRequestedSelection); diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c b/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c index 9799d80d5..cc10ad760 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXproperty.c @@ -94,7 +94,7 @@ nxagentWMStateRec; #undef DEBUG #ifdef NXAGENT_CLIPBOARD -extern WindowPtr nxagentGetClipboardWindow(Atom, WindowPtr); +extern WindowPtr nxagentGetClipboardWindow(Atom); #endif #ifdef NXAGENT_ARTSD @@ -135,7 +135,7 @@ ProcChangeProperty(ClientPtr client) REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize); #ifdef NXAGENT_CLIPBOARD - pWin = nxagentGetClipboardWindow(stuff->property, NULL); + pWin = nxagentGetClipboardWindow(stuff->property); if (pWin == NULL) #endif -- cgit v1.2.3 From 3a935c674baa34e28080b1685f0f8f4823579d93 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 17:42:27 +0100 Subject: Clipboard.c: Fix formatting --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index ca9c32486..c35c1d22d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -280,7 +280,7 @@ void nxagentPrintSelectionStat(int sel) void nxagentPrintClipboardStat(char *header) { #ifdef DEBUG - char *s =NULL; + char *s = NULL; fprintf(stderr, "/----- Clipboard internal status - %s -----\n", header); @@ -301,7 +301,7 @@ void nxagentPrintClipboardStat(char *header) case ClipboardNone: fprintf(stderr, "[None]"); break;; default: fprintf(stderr, "[UNKNOWN] (FAIL!)"); break;; } - fprintf(stderr,"\n"); + fprintf(stderr, "\n"); fprintf(stderr, "lastServer\n"); fprintf(stderr, " lastServerRequestor (Window) [0x%x]\n", lastServerRequestor); -- cgit v1.2.3 From 8c36f1dd216abdb887f08fafc53156991e4f5e98 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 17:43:58 +0100 Subject: Clipboard.c: fix string formatting directives --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index c35c1d22d..7324a6175 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2084,7 +2084,7 @@ int nxagentInitClipboard(WindowPtr pWin) { extern unsigned long startTime; - fprintf(stderr, "%s: Initializing start [%d] milliseconds.\n", __func__, + fprintf(stderr, "%s: Initializing start [%ld] milliseconds.\n", __func__, GetTimeInMillis() - startTime); } #endif @@ -2220,7 +2220,7 @@ int nxagentInitClipboard(WindowPtr pWin) { extern unsigned long startTime; - fprintf(stderr, "%s: initializing ends [%d] milliseconds.\n", __func__, + fprintf(stderr, "%s: initializing ends [%ld] milliseconds.\n", __func__, GetTimeInMillis() - startTime); } #endif -- cgit v1.2.3 From fa7fb7499fdf3625e28eb018a5ee9748d4b69dfe Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 17:59:08 +0100 Subject: Clipboard.c: avoid nested extern --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 7324a6175..f8383ccd9 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -223,6 +223,10 @@ int nxagentSendNotify(xEvent *event); void nxagentPrintClipboardStat(char *); +#ifdef NXAGENT_TIMESTAMP +extern unsigned long startTime; +#endif + #ifdef DEBUG void nxagentPrintSelectionStat(int sel) { @@ -2082,8 +2086,6 @@ int nxagentInitClipboard(WindowPtr pWin) #ifdef NXAGENT_TIMESTAMP { - extern unsigned long startTime; - fprintf(stderr, "%s: Initializing start [%ld] milliseconds.\n", __func__, GetTimeInMillis() - startTime); } @@ -2218,8 +2220,6 @@ int nxagentInitClipboard(WindowPtr pWin) #ifdef NXAGENT_TIMESTAMP { - extern unsigned long startTime; - fprintf(stderr, "%s: initializing ends [%ld] milliseconds.\n", __func__, GetTimeInMillis() - startTime); } -- cgit v1.2.3 From b2af0c68602652b8d35a1d303eaa0a9a41285a2e Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 18:00:55 +0100 Subject: Clipboard: make nxagentInitClipboard return a Boolean --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 12 ++++++++---- nx-X11/programs/Xserver/hw/nxagent/Clipboard.h | 2 +- nx-X11/programs/Xserver/hw/nxagent/Window.c | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index f8383ccd9..2b8a6f9b0 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2062,7 +2062,11 @@ WindowPtr nxagentGetClipboardWindow(Atom property) } } -int nxagentInitClipboard(WindowPtr pWin) +/* + * Initialize the clipboard + * Returns: True for success else False + */ +Bool nxagentInitClipboard(WindowPtr pWin) { Window iWindow = nxagentWindow(pWin); @@ -2111,7 +2115,7 @@ int nxagentInitClipboard(WindowPtr pWin) fprintf(stderr, "%s: PANIC! Could not create NX_CUT_BUFFER_SERVER atom\n", __func__); #endif - return -1; + return False; } #ifdef TEST @@ -2208,7 +2212,7 @@ int nxagentInitClipboard(WindowPtr pWin) "Could not create NX_CUT_BUFFER_CLIENT atom.\n", __func__); #endif - return -1; + return False; } } @@ -2225,5 +2229,5 @@ int nxagentInitClipboard(WindowPtr pWin) } #endif - return 1; + return True; } diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h index c2e783cb9..e63513a4c 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h @@ -47,7 +47,7 @@ extern XFixesAgentInfoRec nxagentXFixesInfo; * data with the X server. */ -extern int nxagentInitClipboard(WindowPtr pWindow); +extern Bool nxagentInitClipboard(WindowPtr pWindow); /* * Called whenever a client or a window is diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index aa8831055..0d36c7960 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -2802,7 +2802,7 @@ Bool nxagentReconnectAllWindows(void *p0) fprintf(stderr, "nxagentReconnectAllWindows: All windows reconfigured.\n"); #endif - if (nxagentInitClipboard(screenInfo.screens[0]->root) == -1) + if (!nxagentInitClipboard(screenInfo.screens[0]->root)) { #ifdef WARNING fprintf(stderr, "nxagentReconnectAllWindows: WARNING! Couldn't initialize the clipboard.\n"); -- cgit v1.2.3 From f05a2eca579e17c8d7d0b3327e794d1f615e432a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 18:56:54 +0100 Subject: Clipboard.c: fix timeout comparison We had comparisions for >5000 and <5000, but =5000 was not explicitly handled. In that case the code took an unexpected path. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 2b8a6f9b0..3a5488d18 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -1698,7 +1698,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, fprintf(stderr, "%s: lastClientWindowPtr != NULL.\n", __func__); #endif - if ((GetTimeInMillis() - lastClientReqTime) > 5000) + if ((GetTimeInMillis() - lastClientReqTime) >= 5000) { #ifdef DEBUG fprintf(stderr, "%s: timeout expired on last request, " @@ -1858,7 +1858,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, lastClientTarget = target; /* if the last client request time is more than 5s ago update it. Why? */ - if ((GetTimeInMillis() - lastClientReqTime) > 5000) + if ((GetTimeInMillis() - lastClientReqTime) >= 5000) lastClientReqTime = GetTimeInMillis(); if (selection == MakeAtom("CLIPBOARD", 9, 0)) -- cgit v1.2.3 From 166102e072073282768bd4b66c982b49b490284f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 19:00:59 +0100 Subject: Clipboard.c: use macros instead of hardcoced values for timeouts --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 3a5488d18..5cc59e3b3 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -146,6 +146,17 @@ static char szAgentCOMPOUND_TEXT[] = "COMPOUND_TEXT"; static char szAgentUTF8_STRING[] = "UTF8_STRING"; static char szAgentNX_CUT_BUFFER_CLIENT[] = "NX_CUT_BUFFER_CLIENT"; +/* number of milliseconds to wait for a conversion from the real X server. */ +#define CONVERSION_TIMEOUT 5000 + +#ifdef DEBUG +/* + * Time window (milliseconds) within to detect multiple conversion + * calls of the same client. + */ +#define ACCUM_TIME 5000 +#endif + /* * some helpers for debugging output */ @@ -1698,7 +1709,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, fprintf(stderr, "%s: lastClientWindowPtr != NULL.\n", __func__); #endif - if ((GetTimeInMillis() - lastClientReqTime) >= 5000) + if ((GetTimeInMillis() - lastClientReqTime) >= CONVERSION_TIMEOUT) { #ifdef DEBUG fprintf(stderr, "%s: timeout expired on last request, " @@ -1814,7 +1825,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, } #ifdef DEBUG - if (lastClientClientPtr == client && (GetTimeInMillis() - lastClientReqTime < 5000)) + if (lastClientClientPtr == client && (GetTimeInMillis() - lastClientReqTime < ACCUM_TIME)) { /* * The same client made consecutive requests of clipboard content @@ -1858,7 +1869,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, lastClientTarget = target; /* if the last client request time is more than 5s ago update it. Why? */ - if ((GetTimeInMillis() - lastClientReqTime) >= 5000) + if ((GetTimeInMillis() - lastClientReqTime) >= CONVERSION_TIMEOUT) lastClientReqTime = GetTimeInMillis(); if (selection == MakeAtom("CLIPBOARD", 9, 0)) -- cgit v1.2.3 From 1d0d547306b6bf124aa06d85f13b8272bfc46e35 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 19:06:59 +0100 Subject: Clipboard.c: add more explaining comments --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 31 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 5cc59e3b3..12d578f90 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -185,6 +185,9 @@ const char * GetClientSelectionStageString(int stage) /* * see also nx-X11/lib/src/ErrDes.c + * + * We use our own version to avoid Xlib doing expensive calls. + * FIXME: Must check if XGetErrorText() is really causing traffic over the wire. */ const char * GetXErrorString(int code) { @@ -668,9 +671,8 @@ void nxagentClearSelection(XEvent *X) /* * Send a SelectionNotify event as reply to the RequestSelection * event X. If success is True take the property from the event, else - * take None (which reports "failed/denied" to the requestor. + * take None (which reports "failed/denied" to the requestor). */ - void nxagentReplyRequestSelection(XEvent *X, Bool success) { XSelectionEvent eventSelection = { @@ -752,8 +754,7 @@ void nxagentRequestSelection(XEvent *X) { /* * the selection request target is TARGETS. The requestor is - * asking for a list of supported data formats. Currently - * there's only one format we support: XA_STRING + * asking for a list of supported data formats. * * The selection does not matter here, we will return this for * PRIMARY and CLIPBOARD. @@ -1703,6 +1704,12 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, } } + /* + * if lastClientWindowPtr is set we are waiting for an answer from + * the real X server. If that answer takes more than 5 seconds we + * consider the conversion failed and tell our client about that. + * The new request that lead us here is then processed. + */ if (lastClientWindowPtr != NULL) { #ifdef TEST @@ -1724,6 +1731,11 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, } else { + /* + * we got another convert request while already waiting for an + * answer from the real X server to a previous convert request, + * which we cannot handle (yet). So return an error. + */ #ifdef DEBUG fprintf(stderr, "%s: got request " "before timeout expired on last request, notifying failure to client\n", __func__); @@ -1758,7 +1770,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, * for a list of supported data formats. Currently there's 4 of them. * * FIXME: I am wondering if we should align this with - * nxagentRequestSelection, where we only report one format. + * nxagentRequestSelection, where we use another target list. */ if (target == clientTARGETS) { @@ -1976,9 +1988,9 @@ int nxagentSendNotify(xEvent *event) * .property must be a server-side Atom. As this property is only * set on our serverWindow and normally there are no other * properties except serverCutProperty, the only thing we need to - * ensure is that the internal Atom clientCutProperty must differ + * ensure is that the internal Atom clientCutProperty differs * from the server-side serverCutProperty Atom. The actual name is - * not important. To be clean here we use a seperate + * not important. To be clean here we use a separate * serverClientCutProperty. */ @@ -2192,6 +2204,11 @@ Bool nxagentInitClipboard(WindowPtr pWin) for (int i = 0; i < nxagentMaxSelections; i++) { + /* + * 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, iWindow, CurrentTime); -- cgit v1.2.3 From 28f07b52638716bb57121ca2b7d7ed2d2bebf64c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 19:07:19 +0100 Subject: Clipboard.c: more debugging output --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 12d578f90..3c74b7825 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -1925,6 +1925,10 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, else { /* deny request */ + #ifdef DEBUG + fprintf(stderr, "%s: Unsupported target [%d][%s] - denying request\n", __func__, target, + validateString(NameForAtom(target))); + #endif SendSelectionNotifyEventToClient(client, time, requestor, selection, target, None); return 1; -- cgit v1.2.3 From 8574c233a601d7f864258ab06718e01c1eadc179 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 21:58:16 +0100 Subject: Clipboard.c: split combined check By splitting it up we can print appropriate debug messages. More important: The code tried to handle the special targets for all other cases where it should only deny the request. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 50 +++++++++++++++++--------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 3c74b7825..454cf1483 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -736,19 +736,31 @@ void nxagentRequestSelection(XEvent *X) return; } - /* - * check if this request needs special treatment by checking - * if any of the following is true: - * - this is a special request like TARGETS or TIMESTAMP - * - lastServerRequestor in non-NULL (= we are currenty in the transfer phase) - * - the selection in this request is none we own. - * In all cases we'll send back a SelectionNotify event with an - * appropriate answer - */ - if (!nxagentValidServerTargets(X->xselectionrequest.target) || - (lastServerRequestor != None) || - ((X->xselectionrequest.selection != lastSelectionOwner[nxagentPrimarySelection].selection) && - (X->xselectionrequest.selection != lastSelectionOwner[nxagentClipboardSelection].selection))) + /* lastServerRequestor in non-NULL (= we are currenty in the transfer phase) */ + if (lastServerRequestor != None) + { + #ifdef DEBUG + fprintf(stderr, "%s: denying additional request during transfer phase.\n", __func__); + #endif + + nxagentReplyRequestSelection(X, False); + return; + } + + /* the selection in this request is none we own. */ + if ((X->xselectionrequest.selection != lastSelectionOwner[nxagentPrimarySelection].selection) && + (X->xselectionrequest.selection != lastSelectionOwner[nxagentClipboardSelection].selection)) + { + #ifdef DEBUG + fprintf(stderr, "%s: not owning selection [%ld] - denying request.\n", __func__, X->xselectionrequest.selection); + #endif + + nxagentReplyRequestSelection(X, False); + return; + } + + /* this is a special request like TARGETS or TIMESTAMP */ + if (!nxagentValidServerTargets(X->xselectionrequest.target)) { if (X->xselectionrequest.target == serverTARGETS) { @@ -830,15 +842,21 @@ void nxagentRequestSelection(XEvent *X) } else { - /* deny the request */ + /* + * unknown special request - probably bug! Check if this code handles all cases + * that are handled in nxagentValidServerTargets! + */ + #ifdef DEBUG + fprintf(stderr, "%s: unknown special target [%ld] - denying request.\n", __func__, X->xselectionrequest.target); + #endif nxagentReplyRequestSelection(X, False); } return; } /* - * reaching this means the request is neither a special request nor - * invalid. We can process it now. + * reaching this means the request is a normal, valid request. We + * can process it now. */ /* -- cgit v1.2.3 From eb51bcb6da690f15871a6d71a3d727d69088c449 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 23:14:17 +0100 Subject: Clipboard.c: drop superflous variable --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 454cf1483..4e119d806 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2113,8 +2113,6 @@ WindowPtr nxagentGetClipboardWindow(Atom property) */ Bool nxagentInitClipboard(WindowPtr pWin) { - Window iWindow = nxagentWindow(pWin); - #ifdef DEBUG fprintf(stderr, "%s: Got called.\n", __func__); #endif @@ -2141,7 +2139,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) #endif agentClipboardInitialized = False; - serverWindow = iWindow; + serverWindow = nxagentWindow(pWin); /* * Local property to hold pasted data. @@ -2165,10 +2163,10 @@ Bool nxagentInitClipboard(WindowPtr pWin) #ifdef TEST fprintf(stderr, "%s: Setting owner of selection [%s][%d] on window 0x%x\n", __func__, - "NX_CUT_BUFFER_SERVER", (int) serverCutProperty, iWindow); + "NX_CUT_BUFFER_SERVER", (int) serverCutProperty, serverWindow); #endif - XSetSelectionOwner(nxagentDisplay, serverCutProperty, iWindow, CurrentTime); + XSetSelectionOwner(nxagentDisplay, serverCutProperty, serverWindow, CurrentTime); if (XQueryExtension(nxagentDisplay, "XFIXES", @@ -2186,7 +2184,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) for (int i = 0; i < nxagentMaxSelections; i++) { - XFixesSelectSelectionInput(nxagentDisplay, iWindow, + XFixesSelectSelectionInput(nxagentDisplay, serverWindow, lastSelectionOwner[i].selection, XFixesSetSelectionOwnerNotifyMask | XFixesSelectionWindowDestroyNotifyMask | @@ -2209,10 +2207,10 @@ Bool nxagentInitClipboard(WindowPtr pWin) #ifdef TEST fprintf(stderr, "%s: setting the ownership of %s to %lx" " and registering for PropertyChangeMask events\n", __func__, - validateString(XGetAtomName(nxagentDisplay, nxagentAtoms[10])), iWindow); + validateString(XGetAtomName(nxagentDisplay, nxagentAtoms[10])), serverWindow); #endif - XSetSelectionOwner(nxagentDisplay, nxagentAtoms[10], iWindow, CurrentTime); + XSetSelectionOwner(nxagentDisplay, nxagentAtoms[10], serverWindow, CurrentTime); pWin -> eventMask |= PropertyChangeMask; nxagentChangeWindowAttributes(pWin, CWEventMask); } @@ -2233,7 +2231,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) */ if (lastSelectionOwner[i].client && lastSelectionOwner[i].window) { - XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, iWindow, CurrentTime); + XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime); } } } -- cgit v1.2.3 From 509ae051b2fdb94e587ef8360b2e5985f9c1abc2 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 17 Nov 2019 23:28:53 +0100 Subject: Clipboard.c: check pointer before usage The code also worked with pWindow being NULL but it did some unnecessary stuff. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 4e119d806..5abb52f94 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -576,7 +576,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) } } - if (pWindow == lastClientWindowPtr) + if (pWindow && pWindow == lastClientWindowPtr) { lastClientWindowPtr = NULL; SetClientSelectionStage(None); -- cgit v1.2.3 From 7d9c5ad4d388f5ccd54b64e21e6ef3d89fcf64fd Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 18 Nov 2019 00:45:17 +0100 Subject: Clipboard: align reported targets Always report the same list of available targets to internal and external requests. --- nx-X11/programs/Xserver/hw/nxagent/Atoms.c | 1 + nx-X11/programs/Xserver/hw/nxagent/Atoms.h | 2 +- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 36 +++++++++++++++++--------- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c index 6bd945de7..d9775b720 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c @@ -91,6 +91,7 @@ static char *nxagentAtomNames[NXAGENT_NUMBER_OF_ATOMS + 1] = "_NET_WM_STATE", /* 13 */ "_NET_WM_STATE_FULLSCREEN", /* 14 */ "NX_CUT_BUFFER_CLIENT", /* 15 */ + "COMPOUND_TEXT", /* 16 */ NULL, NULL }; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Atoms.h b/nx-X11/programs/Xserver/hw/nxagent/Atoms.h index f770c7e66..d04874f25 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Atoms.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Atoms.h @@ -30,7 +30,7 @@ #include "../../include/window.h" #include "screenint.h" -#define NXAGENT_NUMBER_OF_ATOMS 17 +#define NXAGENT_NUMBER_OF_ATOMS 18 extern Atom nxagentAtoms[NXAGENT_NUMBER_OF_ATOMS]; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 5abb52f94..97f58a14a 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -133,15 +133,18 @@ static Time lastServerTime; static XlibAtom serverTARGETS; static XlibAtom serverTIMESTAMP; static XlibAtom serverTEXT; +static XlibAtom serverCOMPOUND_TEXT; static XlibAtom serverUTF8_STRING; static XlibAtom serverClientCutProperty; static Atom clientTARGETS; +static Atom clientTIMESTAMP; static Atom clientTEXT; static Atom clientCOMPOUND_TEXT; static Atom clientUTF8_STRING; static char szAgentTARGETS[] = "TARGETS"; static char szAgentTEXT[] = "TEXT"; +static char szAgentTIMESTAMP[] = "TIMESTAMP"; static char szAgentCOMPOUND_TEXT[] = "COMPOUND_TEXT"; static char szAgentUTF8_STRING[] = "UTF8_STRING"; static char szAgentNX_CUT_BUFFER_CLIENT[] = "NX_CUT_BUFFER_CLIENT"; @@ -354,6 +357,8 @@ void nxagentPrintClipboardStat(char *header) fprintf(stderr, " serverTARGETS [% 4d][%s]\n", serverTARGETS, validateString(s)); SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverTEXT); fprintf(stderr, " serverTEXT [% d][%s]\n", serverTEXT, s); + SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverCOMPOUND_TEXT); + fprintf(stderr, " serverCOMPOUND_TEXT [% d][%s]\n", serverCOMPOUND_TEXT, s); SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverUTF8_STRING); fprintf(stderr, " serverUTF8_STRING [% 4d][%s]\n", serverUTF8_STRING, s); SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverCutProperty); @@ -366,6 +371,7 @@ void nxagentPrintClipboardStat(char *header) fprintf(stderr, "Atoms (inside nxagent)\n"); fprintf(stderr, " clientTARGETS [% 4d][%s]\n", clientTARGETS, NameForAtom(clientTARGETS)); + fprintf(stderr, " clientTIMESTAMP [% 4d][%s]\n", clientTIMESTAMP, NameForAtom(clientTIMESTAMP)); fprintf(stderr, " clientTEXT [% 4d][%s]\n", clientTEXT, NameForAtom(clientTEXT)); fprintf(stderr, " clientCOMPOUND_TEXT [% 4d][%s]\n", clientCOMPOUND_TEXT, NameForAtom(clientCOMPOUND_TEXT)); fprintf(stderr, " clientUTF8_STRING [% 4d][%s]\n", clientUTF8_STRING, NameForAtom(clientUTF8_STRING)); @@ -490,6 +496,13 @@ Bool nxagentValidServerTargets(XlibAtom target) #endif return True; } + else if (target == serverCOMPOUND_TEXT) + { + #ifdef DEBUG + fprintf(stderr, "%s: valid target [COMPOUND_TEXT].\n", __func__); + #endif + return True; + } else if (target == serverTARGETS) { #ifdef DEBUG @@ -771,15 +784,14 @@ void nxagentRequestSelection(XEvent *X) * The selection does not matter here, we will return this for * PRIMARY and CLIPBOARD. * - * FIXME: I am wondering if we should align this with - * nxagentConvertSelection, where we report more formats. + * The list is aligned with the one in nxagentConvertSelection. + * * FIXME: the perfect solution should not just answer with * XA_STRING but ask the real owner what format it supports. The * should then be sent to the original requestor. - * FIXME: add serverCOMPOUND_TEXT? */ - long targets[] = {XA_STRING, serverUTF8_STRING, serverTEXT, serverTARGETS, serverTIMESTAMP}; + long targets[] = {XA_STRING, serverUTF8_STRING, serverTEXT, serverCOMPOUND_TEXT, serverTARGETS, serverTIMESTAMP}; int numTargets = sizeof(targets) / sizeof(targets[0]); #ifdef DEBUG @@ -1785,15 +1797,13 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, /* * The selection request target is TARGETS. The requestor is asking - * for a list of supported data formats. Currently there's 4 of them. + * for a list of supported data formats. * - * FIXME: I am wondering if we should align this with - * nxagentRequestSelection, where we use another target list. + * The list is aligned with the one in nxagentRequestSelection. */ if (target == clientTARGETS) { - /* --- Order changed by dimbor (prevent sending COMPOUND_TEXT to client --- */ - Atom targets[] = {XA_STRING, clientUTF8_STRING, clientTEXT, clientCOMPOUND_TEXT}; + Atom targets[] = {XA_STRING, clientUTF8_STRING, clientTEXT, clientCOMPOUND_TEXT, clientTARGETS, clientTIMESTAMP}; int numTargets = sizeof(targets) / sizeof(targets[0]); #ifdef DEBUG @@ -1827,7 +1837,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, * support conversion to TIMESTAMP, returning the timestamp they * used to obtain the selection." */ - if (target == MakeAtom("TIMESTAMP", 9, 1)) + if (target == clientTIMESTAMP) { int i = nxagentFindCurrentSelectionIndex(selection); if (i < NumCurrentSelections) @@ -2051,10 +2061,10 @@ int nxagentSendNotify(xEvent *event) { eventSelection.target = serverTEXT; } - /*else if (event->u.selectionNotify.target == clientCOMPOUND_TEXT) + else if (event->u.selectionNotify.target == clientCOMPOUND_TEXT) { eventSelection.target = serverCOMPOUND_TEXT; - }*/ + } else { eventSelection.target = XA_STRING; @@ -2149,6 +2159,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) serverTARGETS = nxagentAtoms[6]; /* TARGETS */ serverTEXT = nxagentAtoms[7]; /* TEXT */ serverUTF8_STRING = nxagentAtoms[12]; /* UTF8_STRING */ + serverCOMPOUND_TEXT = nxagentAtoms[16]; /* COMPOUND_TEXT */ /* see nxagentSendNotify for an explanation */ serverClientCutProperty = nxagentAtoms[15]; /* NX_CUT_BUFFER_CLIENT */ @@ -2252,6 +2263,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) clientTEXT = MakeAtom(szAgentTEXT, strlen(szAgentTEXT), True); clientCOMPOUND_TEXT = MakeAtom(szAgentCOMPOUND_TEXT, strlen(szAgentCOMPOUND_TEXT), True); clientUTF8_STRING = MakeAtom(szAgentUTF8_STRING, strlen(szAgentUTF8_STRING), True); + clientTIMESTAMP = MakeAtom(szAgentTIMESTAMP, strlen(szAgentTIMESTAMP), True); if (clientCutProperty == None) { -- cgit v1.2.3 From 8500b4bc0d1bb00bf5ace9e173ce1eebc9e6e6b6 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 18 Nov 2019 00:56:27 +0100 Subject: Clipboard.c: reorder atom allocation code Place the allocation directly before the check for success. Use the same order for server and client atoms. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 97f58a14a..69cc7ecc5 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2136,7 +2136,6 @@ Bool nxagentInitClipboard(WindowPtr pWin) FatalError("nxagentInitClipboard: Failed to allocate memory for the clipboard selections.\n"); } - serverTIMESTAMP = nxagentAtoms[11]; /* TIMESTAMP */ nxagentInitSelectionOwner(nxagentPrimarySelection, XA_PRIMARY); nxagentInitSelectionOwner(nxagentClipboardSelection, nxagentAtoms[10]); /* CLIPBOARD */ @@ -2151,17 +2150,18 @@ Bool nxagentInitClipboard(WindowPtr pWin) agentClipboardInitialized = False; serverWindow = nxagentWindow(pWin); - /* - * Local property to hold pasted data. - */ - - serverCutProperty = nxagentAtoms[5]; /* NX_CUT_BUFFER_SERVER */ serverTARGETS = nxagentAtoms[6]; /* TARGETS */ serverTEXT = nxagentAtoms[7]; /* TEXT */ - serverUTF8_STRING = nxagentAtoms[12]; /* UTF8_STRING */ serverCOMPOUND_TEXT = nxagentAtoms[16]; /* COMPOUND_TEXT */ - /* see nxagentSendNotify for an explanation */ + serverUTF8_STRING = nxagentAtoms[12]; /* UTF8_STRING */ + serverTIMESTAMP = nxagentAtoms[11]; /* TIMESTAMP */ + + /* + * Local properties to hold pasted data. + * see nxagentSendNotify for an explanation + */ serverClientCutProperty = nxagentAtoms[15]; /* NX_CUT_BUFFER_CLIENT */ + serverCutProperty = nxagentAtoms[5]; /* NX_CUT_BUFFER_SERVER */ if (serverCutProperty == None) { @@ -2257,14 +2257,14 @@ Bool nxagentInitClipboard(WindowPtr pWin) SetClientSelectionStage(None); lastClientReqTime = GetTimeInMillis(); - clientCutProperty = MakeAtom(szAgentNX_CUT_BUFFER_CLIENT, - strlen(szAgentNX_CUT_BUFFER_CLIENT), 1); clientTARGETS = MakeAtom(szAgentTARGETS, strlen(szAgentTARGETS), True); clientTEXT = MakeAtom(szAgentTEXT, strlen(szAgentTEXT), True); clientCOMPOUND_TEXT = MakeAtom(szAgentCOMPOUND_TEXT, strlen(szAgentCOMPOUND_TEXT), True); clientUTF8_STRING = MakeAtom(szAgentUTF8_STRING, strlen(szAgentUTF8_STRING), True); clientTIMESTAMP = MakeAtom(szAgentTIMESTAMP, strlen(szAgentTIMESTAMP), True); + clientCutProperty = MakeAtom(szAgentNX_CUT_BUFFER_CLIENT, + strlen(szAgentNX_CUT_BUFFER_CLIENT), True); if (clientCutProperty == None) { #ifdef PANIC -- cgit v1.2.3 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') 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 From 634d4fc8174dcd5adac2b4e20bfbacdb8385f065 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 18 Nov 2019 01:35:50 +0100 Subject: Clipboard.c: clear all selections in nxagentInitClipboard The new code effectively does the same the old one did. But if we change the number of selections the new code will still work correctly while the old one would not. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index a3d8fb5c1..e77984472 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2256,8 +2256,10 @@ Bool nxagentInitClipboard(WindowPtr pWin) } else { - nxagentClearSelectionOwner(nxagentPrimarySelection); - nxagentClearSelectionOwner(nxagentClipboardSelection); + for (int i = 0; i < nxagentMaxSelections; i++) + { + nxagentClearSelectionOwner(i); + } lastServerRequestor = None; -- cgit v1.2.3 From 5d1577abed04e7ea413616232248c7058f960492 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 18 Nov 2019 07:38:16 +0100 Subject: Clipboard.c: reorder nxagentInitClipboard It makes sense to measure time and set the initialized flag right at the start. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index e77984472..44948859d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2127,6 +2127,16 @@ Bool nxagentInitClipboard(WindowPtr pWin) fprintf(stderr, "%s: Got called.\n", __func__); #endif + #ifdef NXAGENT_TIMESTAMP + { + fprintf(stderr, "%s: Clipboard init starts at [%ld] ms.\n", __func__, + GetTimeInMillis() - startTime); + } + #endif + + agentClipboardInitialized = False; + serverWindow = nxagentWindow(pWin); + if (!nxagentReconnectTrap) { SAFE_free(lastSelectionOwner); @@ -2147,15 +2157,6 @@ Bool nxagentInitClipboard(WindowPtr pWin) lastSelectionOwner[nxagentClipboardSelection].selection = nxagentAtoms[10]; /* CLIPBOARD */ } - #ifdef NXAGENT_TIMESTAMP - { - fprintf(stderr, "%s: Initializing start [%ld] milliseconds.\n", __func__, - GetTimeInMillis() - startTime); - } - #endif - - agentClipboardInitialized = False; - serverWindow = nxagentWindow(pWin); serverTARGETS = nxagentAtoms[6]; /* TARGETS */ serverTEXT = nxagentAtoms[7]; /* TEXT */ @@ -2294,7 +2295,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) #ifdef NXAGENT_TIMESTAMP { - fprintf(stderr, "%s: initializing ends [%ld] milliseconds.\n", __func__, + fprintf(stderr, "%s: Clipboard init ends at [%ld] ms.\n", __func__, GetTimeInMillis() - startTime); } #endif -- cgit v1.2.3 From 15ef708747d26bef2a7ecb28130724a35b6637a5 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Nov 2019 23:57:10 +0100 Subject: Clipboard.c: describe nxagentFind*Index --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 44948859d..19ad34ee8 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -598,6 +598,10 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) nxagentPrintClipboardStat("after nxagentClearClipboard"); } +/* + * Find the index of the lastSelectionOwner with the selection + * sel. sel is an atom on the real X server. + */ int nxagentFindLastSelectionOwnerIndex(XlibAtom sel) { int i = 0; @@ -609,6 +613,10 @@ int nxagentFindLastSelectionOwnerIndex(XlibAtom sel) return i; } +/* + * Find the index of CurrentSelection with the selection + * sel. sel is an internal atom. + */ int nxagentFindCurrentSelectionIndex(Atom sel) { int i = 0; -- cgit v1.2.3 From 2b59a199332809722e5fceb891b6845f328054bc Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Nov 2019 23:58:17 +0100 Subject: Clipboard.c: simplify nxagentSetSelectionOwner We do not need to loop over all selections. We have a helper for that. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 59 ++++++++++++-------------- 1 file changed, 26 insertions(+), 33 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 19ad34ee8..6b8123643 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -1622,42 +1622,35 @@ void nxagentSetSelectionOwner(Selection *pSelection) } #endif - /* - * Only for PRIMARY and CLIPBOARD selections. - */ - - for (int i = 0; i < nxagentMaxSelections; i++) + int i = nxagentFindCurrentSelectionIndex(pSelection->selection); + if (i < NumCurrentSelections) { - /* FIXME: using CurrentSelections with the index limited my MaxSelections looks wrong */ - if (pSelection->selection == CurrentSelections[i].selection) - { - #ifdef DEBUG - fprintf(stderr, "%s: lastSelectionOwner.client [%p] index [%d] -> [%p] index [%d]\n", __func__, - (void *)lastSelectionOwner[i].client, CLINDEX(lastSelectionOwner[i].client), - (void *)pSelection->client, CLINDEX(pSelection->client)); - fprintf(stderr, "%s: lastSelectionOwner.window [0x%x] -> [0x%x]\n", __func__, - lastSelectionOwner[i].window, pSelection->window); - fprintf(stderr, "%s: lastSelectionOwner.windowPtr [%p] -> [%p] [0x%x] (serverWindow: [0x%x])\n", __func__, - (void *)lastSelectionOwner[i].windowPtr, (void *)pSelection->pWin, - nxagentWindow(pSelection->pWin), serverWindow); - fprintf(stderr, "%s: lastSelectionOwner.lastTimeChanged [%d]\n", __func__, - lastSelectionOwner[i].lastTimeChanged); - #endif + #ifdef DEBUG + fprintf(stderr, "%s: lastSelectionOwner.client [%p] index [%d] -> [%p] index [%d]\n", __func__, + (void *)lastSelectionOwner[i].client, CLINDEX(lastSelectionOwner[i].client), + (void *)pSelection->client, CLINDEX(pSelection->client)); + fprintf(stderr, "%s: lastSelectionOwner.window [0x%x] -> [0x%x]\n", __func__, + lastSelectionOwner[i].window, pSelection->window); + fprintf(stderr, "%s: lastSelectionOwner.windowPtr [%p] -> [%p] [0x%x] (serverWindow: [0x%x])\n", __func__, + (void *)lastSelectionOwner[i].windowPtr, (void *)pSelection->pWin, + nxagentWindow(pSelection->pWin), serverWindow); + fprintf(stderr, "%s: lastSelectionOwner.lastTimeChanged [%d]\n", __func__, + lastSelectionOwner[i].lastTimeChanged); + #endif - /* - * inform the real X server that our serverWindow is the - * clipboard owner. - */ - XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime); + /* + * inform the real X server that our serverWindow is the + * clipboard owner. + */ + XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime); - /* - * The real owner window (inside nxagent) is stored in - * lastSelectionOwner.window. lastSelectionOwner.windowPtr - * points to the struct that contains all information about the - * owner window. - */ - nxagentStoreSelectionOwner(i, pSelection); - } + /* + * The real owner window (inside nxagent) is stored in + * lastSelectionOwner.window. lastSelectionOwner.windowPtr + * points to the struct that contains all information about the + * owner window. + */ + nxagentStoreSelectionOwner(i, pSelection); } lastClientWindowPtr = NULL; -- cgit v1.2.3 From 6c0536a20b965ddb1de8ca00d8919d8c43bf109b Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 22 Nov 2019 00:24:35 +0100 Subject: Clipboard.c: introduce helper macro IS_INTERNAL_OWNER Using this macro makes the code more readable --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 6b8123643..cef663033 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -98,6 +98,8 @@ typedef struct _SelectionOwner static SelectionOwner *lastSelectionOwner; static XlibAtom nxagentLastRequestedSelection; +#define IS_INTERNAL_OWNER(lsoindex) (lastSelectionOwner[lsoindex].client != NULL) + /* * Needed to handle the notify selection event to * be sent to client once the selection property @@ -661,7 +663,7 @@ void nxagentClearSelection(XEvent *X) if (i < nxagentMaxSelections) { - if (lastSelectionOwner[i].client != NULL) + if (IS_INTERNAL_OWNER(i)) { /* send a SelectionClear event to (our) previous owner */ xEvent x = {0}; @@ -888,7 +890,7 @@ void nxagentRequestSelection(XEvent *X) int i = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); if (i < nxagentMaxSelections) { - if ((lastClientWindowPtr != NULL) && (lastSelectionOwner[i].client != NULL)) + if (lastClientWindowPtr != NULL && IS_INTERNAL_OWNER(i)) { /* * Request the real X server to transfer the selection content @@ -910,7 +912,7 @@ void nxagentRequestSelection(XEvent *X) * the selection to the clientCutProperty on nxagent's root * window */ - if (lastSelectionOwner[i].client != NULL && + if (IS_INTERNAL_OWNER(i) && nxagentOption(Clipboard) != ClipboardClient) { /* @@ -1361,9 +1363,9 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) if (i < nxagentMaxSelections) { /* if the last owner was an internal one */ - if ((lastSelectionOwner[i].client != NULL) && - (lastSelectionOwner[i].windowPtr != NULL) && - (X->xselection.property == serverClientCutProperty)) + if (IS_INTERNAL_OWNER(i) && + lastSelectionOwner[i].windowPtr != NULL && + X->xselection.property == serverClientCutProperty) { Atom atomReturnType; int resultFormat; @@ -1725,8 +1727,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, for (int i = 0; i < nxagentMaxSelections; i++) { - if ((selection == CurrentSelections[i].selection) && - (lastSelectionOwner[i].client != NULL)) + if (selection == CurrentSelections[i].selection && + IS_INTERNAL_OWNER(i)) { /* * There is a client owner on the agent side, let normal dix stuff happen. @@ -2248,7 +2250,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) * claim the ownership. Note that we report our serverWindow as * owner, not the real window! */ - if (lastSelectionOwner[i].client && lastSelectionOwner[i].window) + if (IS_INTERNAL_OWNER(i) && lastSelectionOwner[i].window) { XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime); } -- cgit v1.2.3 From feedae86bfa5601ed591efce9e97ddb4e463ca93 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 22 Nov 2019 20:41:31 +0100 Subject: Clipboard.c: cosmetics/typo fix/untabify --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 84 +++++++++++++------------- nx-X11/programs/Xserver/hw/nxagent/Clipboard.h | 1 - 2 files changed, 41 insertions(+), 44 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index cef663033..0709954b9 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -555,7 +555,7 @@ void nxagentStoreSelectionOwner(int index, Selection *sel) Bool nxagentMatchSelectionOwner(int index, ClientPtr pClient, WindowPtr pWindow) { return ((pClient && lastSelectionOwner[index].client == pClient) || - (pWindow && lastSelectionOwner[index].windowPtr == pWindow)); + (pWindow && lastSelectionOwner[index].windowPtr == pWindow)); } void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) @@ -660,7 +660,6 @@ void nxagentClearSelection(XEvent *X) } int i = nxagentFindLastSelectionOwnerIndex(X->xselectionclear.selection); - if (i < nxagentMaxSelections) { if (IS_INTERNAL_OWNER(i)) @@ -759,7 +758,7 @@ void nxagentRequestSelection(XEvent *X) return; } - /* lastServerRequestor in non-NULL (= we are currenty in the transfer phase) */ + /* lastServerRequestor in non-NULL (= we are currently in the transfer phase) */ if (lastServerRequestor != None) { #ifdef DEBUG @@ -806,14 +805,14 @@ void nxagentRequestSelection(XEvent *X) #ifdef DEBUG { - fprintf(stderr, "%s: Sending %d available targets:\n", __func__, numTargets); - for (int i = 0; i < numTargets; i++) - { - char *s = XGetAtomName(nxagentDisplay, targets[i]); - fprintf(stderr, "%s: %ld %s\n", __func__, targets[i], s); - SAFE_XFree(s); - } - fprintf(stderr, "\n"); + fprintf(stderr, "%s: Sending %d available targets:\n", __func__, numTargets); + for (int i = 0; i < numTargets; i++) + { + char *s = XGetAtomName(nxagentDisplay, targets[i]); + fprintf(stderr, "%s: %ld %s\n", __func__, targets[i], s); + SAFE_XFree(s); + } + fprintf(stderr, "\n"); } #endif @@ -917,7 +916,7 @@ void nxagentRequestSelection(XEvent *X) { /* * store who on the real X server requested the data and how - * and where it wants to have it + * and where it wants to have it */ lastServerProperty = X->xselectionrequest.property; lastServerRequestor = X->xselectionrequest.requestor; @@ -955,16 +954,16 @@ void nxagentRequestSelection(XEvent *X) #ifdef DEBUG fprintf(stderr, "%s: sent SelectionRequest event to client [%d] property [%d][%s]" \ - "target [%d][%s] requestor [0x%x].\n", __func__, - CLINDEX(lastSelectionOwner[i].client), - x.u.selectionRequest.property, NameForAtom(x.u.selectionRequest.property), - x.u.selectionRequest.target, NameForAtom(x.u.selectionRequest.target), - x.u.selectionRequest.requestor); + "target [%d][%s] requestor [0x%x].\n", __func__, + CLINDEX(lastSelectionOwner[i].client), + x.u.selectionRequest.property, NameForAtom(x.u.selectionRequest.property), + x.u.selectionRequest.target, NameForAtom(x.u.selectionRequest.target), + x.u.selectionRequest.requestor); #endif } else { - /* deny the request */ + /* deny the request */ nxagentReplyRequestSelection(X, False); } } @@ -992,10 +991,10 @@ static void endTransfer(Bool success) #ifdef DEBUG if (success == SELECTION_SUCCESS) fprintf(stderr, "%s: sending notification to client [%d], property [%d][%s]\n", __func__, - CLINDEX(lastClientClientPtr), lastClientProperty, NameForAtom(lastClientProperty)); + CLINDEX(lastClientClientPtr), lastClientProperty, NameForAtom(lastClientProperty)); else fprintf(stderr, "%s: sending negative notification to client [%d]\n", __func__, - CLINDEX(lastClientClientPtr)); + CLINDEX(lastClientClientPtr)); #endif SendSelectionNotifyEventToClient(lastClientClientPtr, @@ -1130,7 +1129,7 @@ void nxagentTransferSelection(int resource) SetClientSelectionStage(WaitData); /* we've seen situations where you had to move the mouse or press a - key to let the transfer complete. Flushing here fixed it */ + key to let the transfer complete. Flushing here fixed it */ NXFlushDisplay(nxagentDisplay, NXFlushLink); break; @@ -1380,7 +1379,7 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) #ifdef DEBUG fprintf(stderr, "%s: GetWindowProperty() window [0x%x] property [%d] returned [%s]\n", __func__, - lastSelectionOwner[i].window, clientCutProperty, GetXErrorString(result)); + lastSelectionOwner[i].window, clientCutProperty, GetXErrorString(result)); #endif if (result == BadAlloc || result == BadAtom || result == BadWindow || result == BadValue) @@ -1396,7 +1395,7 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) &pszReturnData); #ifdef DEBUG fprintf(stderr, "%s: GetWindowProperty() window [0x%x] property [%d] returned [%s]\n", __func__, - lastSelectionOwner[i].window, clientCutProperty, GetXErrorString(result)); + lastSelectionOwner[i].window, clientCutProperty, GetXErrorString(result)); #endif if (result == BadAlloc || result == BadAtom || @@ -1460,7 +1459,7 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) }; #ifdef DEBUG fprintf(stderr, "%s: Sending SelectionNotify event to requestor [%p].\n", __func__, - (void *)eventSelection.requestor); + (void *)eventSelection.requestor); #endif SendSelectionNotifyEventToServer(&eventSelection); @@ -1629,15 +1628,15 @@ void nxagentSetSelectionOwner(Selection *pSelection) { #ifdef DEBUG fprintf(stderr, "%s: lastSelectionOwner.client [%p] index [%d] -> [%p] index [%d]\n", __func__, - (void *)lastSelectionOwner[i].client, CLINDEX(lastSelectionOwner[i].client), - (void *)pSelection->client, CLINDEX(pSelection->client)); + (void *)lastSelectionOwner[i].client, CLINDEX(lastSelectionOwner[i].client), + (void *)pSelection->client, CLINDEX(pSelection->client)); fprintf(stderr, "%s: lastSelectionOwner.window [0x%x] -> [0x%x]\n", __func__, - lastSelectionOwner[i].window, pSelection->window); + lastSelectionOwner[i].window, pSelection->window); fprintf(stderr, "%s: lastSelectionOwner.windowPtr [%p] -> [%p] [0x%x] (serverWindow: [0x%x])\n", __func__, - (void *)lastSelectionOwner[i].windowPtr, (void *)pSelection->pWin, - nxagentWindow(pSelection->pWin), serverWindow); + (void *)lastSelectionOwner[i].windowPtr, (void *)pSelection->pWin, + nxagentWindow(pSelection->pWin), serverWindow); fprintf(stderr, "%s: lastSelectionOwner.lastTimeChanged [%d]\n", __func__, - lastSelectionOwner[i].lastTimeChanged); + lastSelectionOwner[i].lastTimeChanged); #endif /* @@ -1928,7 +1927,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, { #ifdef DEBUG fprintf(stderr, "%s: Sending XConvertSelection with target [%d][UTF8_STRING], property [%d][NX_CUT_BUFFER_SERVER]\n", __func__, - serverUTF8_STRING, serverCutProperty); + serverUTF8_STRING, serverCutProperty); #endif XConvertSelection(nxagentDisplay, selection, serverUTF8_STRING, serverCutProperty, serverWindow, CurrentTime); @@ -1937,7 +1936,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, { #ifdef DEBUG fprintf(stderr, "%s: Sending XConvertSelection with target [%d][%s], property [%d][NX_CUT_BUFFER_SERVER]\n", __func__, - XA_STRING, validateString(NameForAtom(XA_STRING)), serverCutProperty); + XA_STRING, validateString(NameForAtom(XA_STRING)), serverCutProperty); #endif XConvertSelection(nxagentDisplay, selection, XA_STRING, serverCutProperty, @@ -1947,7 +1946,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, /* FIXME: check returncode of XConvertSelection */ #ifdef DEBUG - fprintf(stderr, "%s: Sent XConvertSelection with target=[%s], property [%s]\n", __func__, + fprintf(stderr, "%s: Sent XConvertSelection with target [%s], property [%s]\n", __func__, validateString(NameForAtom(target)), validateString(NameForAtom(property))); #endif @@ -1973,7 +1972,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, * trigger the dispatch loop in Events.c to run * nxagentHandleSelectionNotifyFromXServer which in turn will take * care of transferring the selection content from the owning client - * to to a property of the server window. + * to a property of the server window. * * Returning 1 here means the client request will not be further * handled by dix. Returning 0 means a SelectionNotify event being @@ -2001,8 +2000,8 @@ int nxagentSendNotify(xEvent *event) #ifdef DEBUG fprintf(stderr, "%s: property is [%d][%s].\n", __func__, - event->u.selectionNotify.property, - NameForAtom(event->u.selectionNotify.property)); + event->u.selectionNotify.property, + NameForAtom(event->u.selectionNotify.property)); fprintf(stderr, "%s: requestor is [0x%x].\n", __func__, event->u.selectionNotify.requestor); fprintf(stderr, "%s: lastServerRequestor is [0x%x].\n", __func__, lastServerRequestor); #endif @@ -2021,7 +2020,7 @@ int nxagentSendNotify(xEvent *event) * Setup selection notify event to real server. * * .property must be a server-side Atom. As this property is only - * set on our serverWindow and normally there are no other + * set on our serverWindow and normally there are few other * properties except serverCutProperty, the only thing we need to * ensure is that the internal Atom clientCutProperty differs * from the server-side serverCutProperty Atom. The actual name is @@ -2108,8 +2107,8 @@ WindowPtr nxagentGetClipboardWindow(Atom property) { #ifdef DEBUG fprintf(stderr, "%s: Returning last [%d] selection owner window [%p] (0x%x).\n", __func__, - lastSelectionOwner[i].selection, - (void *)lastSelectionOwner[i].windowPtr, WINDOWID(lastSelectionOwner[i].windowPtr)); + lastSelectionOwner[i].selection, + (void *)lastSelectionOwner[i].windowPtr, WINDOWID(lastSelectionOwner[i].windowPtr)); #endif return lastSelectionOwner[i].windowPtr; @@ -2155,12 +2154,11 @@ Bool nxagentInitClipboard(WindowPtr pWin) } else { - /* the clipboard selection atom might have changed on the new X + /* the clipboard selection atom might have changed on a new X server. Primary is constant. */ lastSelectionOwner[nxagentClipboardSelection].selection = nxagentAtoms[10]; /* CLIPBOARD */ } - serverTARGETS = nxagentAtoms[6]; /* TARGETS */ serverTEXT = nxagentAtoms[7]; /* TEXT */ serverCOMPOUND_TEXT = nxagentAtoms[16]; /* COMPOUND_TEXT */ @@ -2168,7 +2166,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) serverTIMESTAMP = nxagentAtoms[11]; /* TIMESTAMP */ /* - * Local properties to hold pasted data. + * Server side properties to hold pasted data. * see nxagentSendNotify for an explanation */ serverClientCutProperty = nxagentAtoms[15]; /* NX_CUT_BUFFER_CLIENT */ @@ -2241,7 +2239,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) if (nxagentReconnectTrap) { if (nxagentOption(Clipboard) == ClipboardServer || - nxagentOption(Clipboard) == ClipboardBoth) + nxagentOption(Clipboard) == ClipboardBoth) { for (int i = 0; i < nxagentMaxSelections; i++) { diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h index e63513a4c..6df5a3134 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h @@ -36,7 +36,6 @@ typedef struct _XFixesAgentInfo int EventBase; int ErrorBase; int Initialized; - } XFixesAgentInfoRec; extern XFixesAgentInfoRec nxagentXFixesInfo; -- cgit v1.2.3 From 68125b06e852c96d60c1ee704f1700de8aa6c629 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 22 Nov 2019 21:15:54 +0100 Subject: Clipboard.c: Use Find*Index helpers at more locations --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 31 +++++++++++++------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 0709954b9..715895cf0 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -770,15 +770,17 @@ void nxagentRequestSelection(XEvent *X) } /* the selection in this request is none we own. */ - if ((X->xselectionrequest.selection != lastSelectionOwner[nxagentPrimarySelection].selection) && - (X->xselectionrequest.selection != lastSelectionOwner[nxagentClipboardSelection].selection)) { - #ifdef DEBUG - fprintf(stderr, "%s: not owning selection [%ld] - denying request.\n", __func__, X->xselectionrequest.selection); - #endif + int i = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); + if (i == nxagentMaxSelections) + { + #ifdef DEBUG + fprintf(stderr, "%s: not owning selection [%ld] - denying request.\n", __func__, X->xselectionrequest.selection); + #endif - nxagentReplyRequestSelection(X, False); - return; + nxagentReplyRequestSelection(X, False); + return; + } } /* this is a special request like TARGETS or TIMESTAMP */ @@ -1724,16 +1726,13 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, return 0; } - for (int i = 0; i < nxagentMaxSelections; i++) + int i = nxagentFindCurrentSelectionIndex(selection); + if (i < NumCurrentSelections && IS_INTERNAL_OWNER(i)) { - if (selection == CurrentSelections[i].selection && - IS_INTERNAL_OWNER(i)) - { - /* - * There is a client owner on the agent side, let normal dix stuff happen. - */ - return 0; - } + /* + * There is a client owner on the agent side, let normal dix stuff happen. + */ + return 0; } /* -- cgit v1.2.3 From 80ab8932d65486ab47f722c2282ad2acc9d1f11b Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 16 Dec 2019 18:31:49 +0100 Subject: Options.h: comment on the four clipboard options --- nx-X11/programs/Xserver/hw/nxagent/Options.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Options.h b/nx-X11/programs/Xserver/hw/nxagent/Options.h index d791d2294..166508ac3 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Options.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Options.h @@ -49,6 +49,24 @@ typedef enum _BackingStoreMode } BackingStoreMode; +/* since nx 2.0.0-32 clipboard data exchange can be limited. Client + here means "nxclient": + + Enable or disable copy and paste operations from the user's desktop + to the NX session or vice versa. This option can take four values: + + client The content copied on the client can be pasted inside the + NX session. + + server The content copied inside the NX session can be pasted + on the client. + + both The copy & paste operations are allowed both between the + client and the NX session and viceversa. + + none The copy&paste operations between the client and the NX + session are never allowed. +*/ typedef enum _ClipboardMode { ClipboardBoth, -- cgit v1.2.3 From 65877a19995504bc9c2a8cdb17c0ae9f6770534a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 16 Dec 2019 18:32:39 +0100 Subject: Clipboard.c: fix handling of clipboard=none/client/server/both option --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 715895cf0..8d55c74d7 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -911,10 +911,11 @@ void nxagentRequestSelection(XEvent *X) /* * if one of our clients owns the selection we ask it to copy * the selection to the clientCutProperty on nxagent's root - * window + * window on the real X server. */ if (IS_INTERNAL_OWNER(i) && - nxagentOption(Clipboard) != ClipboardClient) + (nxagentOption(Clipboard) == ClipboardServer || + nxagentOption(Clipboard) == ClipboardBoth)) { /* * store who on the real X server requested the data and how @@ -1563,7 +1564,7 @@ void nxagentSetSelectionCallback(CallbackListPtr *callbacks, void *data, #endif if ((pCurSel->pWin != NULL) && - (nxagentOption(Clipboard) != ClipboardNone) && + (nxagentOption(Clipboard) != ClipboardNone) && /* FIXME: shouldn't we also check for != ClipboardClient? */ ((pCurSel->selection == XA_PRIMARY) || (pCurSel->selection == MakeAtom("CLIPBOARD", 9, 0)))) { -- cgit v1.2.3 From 7cda101247ee8c4d75a4fd9daee4b175f6e54f7c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 16 Dec 2019 18:35:47 +0100 Subject: Clipboard.c: flush more often to ensure a smooth clipboard experience --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 8d55c74d7..9707c19bd 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -432,7 +432,7 @@ Status SendSelectionNotifyEventToServer(XSelectionEvent *event_to_send) } #endif - //NXFlushDisplay(nxagentDisplay, NXFlushLink); + NXFlushDisplay(nxagentDisplay, NXFlushLink); return result; } @@ -714,8 +714,6 @@ void nxagentReplyRequestSelection(XEvent *X, Bool success) } SendSelectionNotifyEventToServer(&eventSelection); - - NXFlushDisplay(nxagentDisplay, NXFlushLink); } /* -- cgit v1.2.3 From 84382e916b69f3a00b636af6961aaa5b0ede8697 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 16 Dec 2019 18:42:04 +0100 Subject: Clipboard.c: CLINDEX and GetXErrorString are only used for debugging --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 9707c19bd..8cc00fca0 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -186,7 +186,6 @@ const char * GetClientSelectionStageString(int stage) #else #define SetClientSelectionStage(stage) do {lastClientStage = SelectionStage##stage;} while (0) #define PrintClientSelectionStage() -#endif /* * see also nx-X11/lib/src/ErrDes.c @@ -219,6 +218,7 @@ const char * GetXErrorString(int code) default: return("UNKNOWN!"); break;; } } +#endif /* * Save the values queried from X server. @@ -1777,7 +1777,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, } } - #if defined(TEST) || defined(DEBUG) + #ifdef DEBUG fprintf(stderr, "%s: client [%d] requests sel [%s] " "on window [%x] prop [%d][%s] target [%d][%s].\n", __func__, CLINDEX(client), validateString(NameForAtom(selection)), requestor, -- cgit v1.2.3 From ee5cf733fed11c68db5d41f821e4e3b8f5296770 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 16 Dec 2019 22:17:02 +0100 Subject: Clipboard.c: change order of if clause to better match the comment above it --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 8cc00fca0..1aafeceaa 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -2011,9 +2011,15 @@ int nxagentSendNotify(xEvent *event) * which can be nxagents themselves). In that case we return 0 (tell * dix to go on) and do nothing! */ - if (event->u.selectionNotify.property == clientCutProperty && lastServerRequestor != None) + if (event->u.selectionNotify.property != clientCutProperty || lastServerRequestor == None) + { + #ifdef DEBUG + fprintf(stderr, "%s: sent nothing.\n", __func__); + #endif + return 0; + } + else { - /* * Setup selection notify event to real server. * @@ -2086,10 +2092,6 @@ int nxagentSendNotify(xEvent *event) return 1; } - #ifdef DEBUG - fprintf(stderr, "%s: sent nothing.\n", __func__); - #endif - return 0; } /* -- cgit v1.2.3 From 40c243fd203eabea5f97a1f797663173f478213a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 16 Dec 2019 22:47:23 +0100 Subject: Clipboard.c: add clientCLIPBOARD variable the MakeAtom call previously used is as good as using a variable but with the variable it is a) easier to read/understand and b) consistent with the other client* variables. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 1aafeceaa..db5bfd65f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -143,6 +143,7 @@ static Atom clientTIMESTAMP; static Atom clientTEXT; static Atom clientCOMPOUND_TEXT; static Atom clientUTF8_STRING; +static Atom clientCLIPBOARD; static char szAgentTARGETS[] = "TARGETS"; static char szAgentTEXT[] = "TEXT"; @@ -150,6 +151,7 @@ static char szAgentTIMESTAMP[] = "TIMESTAMP"; static char szAgentCOMPOUND_TEXT[] = "COMPOUND_TEXT"; static char szAgentUTF8_STRING[] = "UTF8_STRING"; static char szAgentNX_CUT_BUFFER_CLIENT[] = "NX_CUT_BUFFER_CLIENT"; +static char szAgentCLIPBOARD[] = "CLIPBOARD"; /* number of milliseconds to wait for a conversion from the real X server. */ #define CONVERSION_TIMEOUT 5000 @@ -377,6 +379,7 @@ void nxagentPrintClipboardStat(char *header) fprintf(stderr, " clientTEXT [% 4d][%s]\n", clientTEXT, NameForAtom(clientTEXT)); fprintf(stderr, " clientCOMPOUND_TEXT [% 4d][%s]\n", clientCOMPOUND_TEXT, NameForAtom(clientCOMPOUND_TEXT)); fprintf(stderr, " clientUTF8_STRING [% 4d][%s]\n", clientUTF8_STRING, NameForAtom(clientUTF8_STRING)); + fprintf(stderr, " clientCLIPBOARD [% 4d][%s]\n", clientCLIPBOARD, NameForAtom(clientCLIPBOARD)); fprintf(stderr, " clientCutProperty [% 4d][%s]\n", clientCutProperty, NameForAtom(clientCutProperty)); fprintf(stderr, " nxagentLastRequestedSelection [% 4d][%s]\n", nxagentLastRequestedSelection, NameForAtom(nxagentLastRequestedSelection)); @@ -1564,7 +1567,7 @@ void nxagentSetSelectionCallback(CallbackListPtr *callbacks, void *data, if ((pCurSel->pWin != NULL) && (nxagentOption(Clipboard) != ClipboardNone) && /* FIXME: shouldn't we also check for != ClipboardClient? */ ((pCurSel->selection == XA_PRIMARY) || - (pCurSel->selection == MakeAtom("CLIPBOARD", 9, 0)))) + (pCurSel->selection == clientCLIPBOARD))) { #ifdef DEBUG fprintf(stderr, "%s: calling nxagentSetSelectionOwner\n", __func__); @@ -1912,7 +1915,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, if ((GetTimeInMillis() - lastClientReqTime) >= CONVERSION_TIMEOUT) lastClientReqTime = GetTimeInMillis(); - if (selection == MakeAtom("CLIPBOARD", 9, 0)) + if (selection == clientCLIPBOARD) { selection = lastSelectionOwner[nxagentClipboardSelection].selection; } @@ -2048,7 +2051,7 @@ int nxagentSendNotify(xEvent *event) * X servers (defined in Xatom.h). */ - if (event->u.selectionNotify.selection == MakeAtom("CLIPBOARD", 9, 0)) + if (event->u.selectionNotify.selection == clientCLIPBOARD) { eventSelection.selection = lastSelectionOwner[nxagentClipboardSelection].selection; } @@ -2274,6 +2277,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) clientCOMPOUND_TEXT = MakeAtom(szAgentCOMPOUND_TEXT, strlen(szAgentCOMPOUND_TEXT), True); clientUTF8_STRING = MakeAtom(szAgentUTF8_STRING, strlen(szAgentUTF8_STRING), True); clientTIMESTAMP = MakeAtom(szAgentTIMESTAMP, strlen(szAgentTIMESTAMP), True); + clientCLIPBOARD = MakeAtom(szAgentCLIPBOARD, strlen(szAgentCLIPBOARD), True); clientCutProperty = MakeAtom(szAgentNX_CUT_BUFFER_CLIENT, strlen(szAgentNX_CUT_BUFFER_CLIENT), True); -- cgit v1.2.3 From d210c584c7505276e04018f206de5c0109f6ff63 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 16 Dec 2019 23:11:13 +0100 Subject: Clipboard.c: rename variables/atoms to better reflect their meaning Unfortunately we cannot rename NX_CUT_BUFFER_SERVER, too, without breaking compatibility because this one is used to signal nomachine's nxclient after the splash screen is gone (see Splash.c, Window.c and ArticaProject/nx-libs#838) --- nx-X11/programs/Xserver/hw/nxagent/Atoms.c | 5 +- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 68 +++++++++++++------------- nx-X11/programs/Xserver/hw/nxagent/Clipboard.h | 2 +- nx-X11/programs/Xserver/hw/nxagent/Splash.c | 4 +- nx-X11/programs/Xserver/hw/nxagent/Window.c | 2 +- nx-X11/programs/Xserver/hw/nxagent/Windows.h | 2 +- 6 files changed, 43 insertions(+), 40 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c index d9775b720..4e9b7fb1f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c @@ -81,6 +81,9 @@ static char *nxagentAtomNames[NXAGENT_NUMBER_OF_ATOMS + 1] = "WM_NX_READY", /* 3 */ "MCOPGLOBALS", /* 4 */ "NX_CUT_BUFFER_SERVER", /* 5 */ + /* Unfortunately we cannot rename this to NX_SELTRANS_TO_AGENT + because nomachine's nxclient is depending on this + selection */ "TARGETS", /* 6 */ "TEXT", /* 7 */ "NX_AGENT_SIGNATURE", /* 8 */ @@ -90,7 +93,7 @@ static char *nxagentAtomNames[NXAGENT_NUMBER_OF_ATOMS + 1] = "UTF8_STRING", /* 12 */ "_NET_WM_STATE", /* 13 */ "_NET_WM_STATE_FULLSCREEN", /* 14 */ - "NX_CUT_BUFFER_CLIENT", /* 15 */ + "NX_SELTRANS_FROM_AGENT", /* 15 */ "COMPOUND_TEXT", /* 16 */ NULL, NULL diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index db5bfd65f..d488e92a9 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -72,7 +72,7 @@ static int agentClipboardInitialized = False; static int clientAccum; #endif -XlibAtom serverCutProperty; +XlibAtom serverTransToAgentProperty; Atom clientCutProperty; static Window serverWindow; @@ -137,7 +137,7 @@ static XlibAtom serverTIMESTAMP; static XlibAtom serverTEXT; static XlibAtom serverCOMPOUND_TEXT; static XlibAtom serverUTF8_STRING; -static XlibAtom serverClientCutProperty; +static XlibAtom serverTransFromAgentProperty; static Atom clientTARGETS; static Atom clientTIMESTAMP; static Atom clientTEXT; @@ -365,10 +365,10 @@ void nxagentPrintClipboardStat(char *header) fprintf(stderr, " serverCOMPOUND_TEXT [% d][%s]\n", serverCOMPOUND_TEXT, s); SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverUTF8_STRING); fprintf(stderr, " serverUTF8_STRING [% 4d][%s]\n", serverUTF8_STRING, s); - SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverCutProperty); - fprintf(stderr, " serverCutProperty [% 4d][%s]\n", serverCutProperty, s); - SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverClientCutProperty); - fprintf(stderr, " serverClientCutProperty [% 4d][%s]\n", serverClientCutProperty, s); + SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverTransToAgentProperty); + fprintf(stderr, " serverTransToAgentProperty [% 4d][%s]\n", serverTransFromAgentProperty, s); + SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverTransFromAgentProperty); + fprintf(stderr, " serverTransFromAgentProperty [% 4d][%s]\n", serverTransToAgentProperty, s); SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverTIMESTAMP); fprintf(stderr, " serverTIMESTAMP [% 4d][%s]\n", serverTIMESTAMP, s); @@ -896,11 +896,11 @@ void nxagentRequestSelection(XEvent *X) { /* * Request the real X server to transfer the selection content - * to the NX_CUT_BUFFER_CLIENT property of the serverWindow. + * to the NX_CUT_BUFFER_SERVER property of the serverWindow. * FIXME: document how we can end up here */ XConvertSelection(nxagentDisplay, CurrentSelections[i].selection, - X->xselectionrequest.target, serverCutProperty, + X->xselectionrequest.target, serverTransToAgentProperty, serverWindow, lastClientTime); #ifdef DEBUG @@ -1057,7 +1057,7 @@ void nxagentTransferSelection(int resource) result = NXCollectProperty(nxagentDisplay, nxagentLastClipboardClient, serverWindow, - serverCutProperty, + serverTransToAgentProperty, 0, 0, False, @@ -1111,7 +1111,7 @@ void nxagentTransferSelection(int resource) result = NXCollectProperty(nxagentDisplay, nxagentLastClipboardClient, serverWindow, - serverCutProperty, + serverTransToAgentProperty, 0, lastClientPropertySize, False, @@ -1323,11 +1323,11 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) * We reach here after a paste inside the nxagent, triggered by * the XConvertSelection call in nxagentConvertSelection(). This * means that data we need has been transferred to the - * serverCutProperty of the serverWindow (our window on the real X + * serverTransToAgentProperty of the serverWindow (our window on the real X * server). We now need to transfer it to the original requestor, * which is stored in the lastClient* variables. */ - if ((lastClientStage == SelectionStageNone) && (X->xselection.property == serverCutProperty)) + if ((lastClientStage == SelectionStageNone) && (X->xselection.property == serverTransToAgentProperty)) { #ifdef DEBUG fprintf(stderr, "%s: Starting selection transferral for client [%d].\n", __func__, @@ -1368,7 +1368,7 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) /* if the last owner was an internal one */ if (IS_INTERNAL_OWNER(i) && lastSelectionOwner[i].windowPtr != NULL && - X->xselection.property == serverClientCutProperty) + X->xselection.property == serverTransFromAgentProperty) { Atom atomReturnType; int resultFormat; @@ -1902,7 +1902,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, SetClientSelectionStage(None); /* * store the original requestor, we need that later after - * serverCutProperty contains the desired selection content + * serverTransToAgentProperty contains the desired selection content */ lastClientRequestor = requestor; lastClientClientPtr = client; @@ -1927,20 +1927,20 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, if (target == clientUTF8_STRING) { #ifdef DEBUG - fprintf(stderr, "%s: Sending XConvertSelection with target [%d][UTF8_STRING], property [%d][NX_CUT_BUFFER_SERVER]\n", __func__, - serverUTF8_STRING, serverCutProperty); + fprintf(stderr, "%s: Sending XConvertSelection with target [%d][%s], property [%d][%s]\n", __func__, + serverUTF8_STRING, szAgentUTF8_STRING, serverTransToAgentProperty, "NX_CUT_BUFFER_SERVER"); #endif - XConvertSelection(nxagentDisplay, selection, serverUTF8_STRING, serverCutProperty, + XConvertSelection(nxagentDisplay, selection, serverUTF8_STRING, serverTransToAgentProperty, serverWindow, CurrentTime); } else { #ifdef DEBUG - fprintf(stderr, "%s: Sending XConvertSelection with target [%d][%s], property [%d][NX_CUT_BUFFER_SERVER]\n", __func__, - XA_STRING, validateString(NameForAtom(XA_STRING)), serverCutProperty); + fprintf(stderr, "%s: Sending XConvertSelection with target [%d][%s], property [%d][%s]\n", __func__, + XA_STRING, validateString(NameForAtom(XA_STRING)), serverTransToAgentProperty, "NX_CUT_BUFFER_SERVER"); #endif - XConvertSelection(nxagentDisplay, selection, XA_STRING, serverCutProperty, + XConvertSelection(nxagentDisplay, selection, XA_STRING, serverTransToAgentProperty, serverWindow, CurrentTime); } @@ -2028,18 +2028,18 @@ int nxagentSendNotify(xEvent *event) * * .property must be a server-side Atom. As this property is only * set on our serverWindow and normally there are few other - * properties except serverCutProperty, the only thing we need to - * ensure is that the internal Atom clientCutProperty differs - * from the server-side serverCutProperty Atom. The actual name is - * not important. To be clean here we use a separate - * serverClientCutProperty. + * properties except serverTransToAgentProperty, the only thing + * we need to ensure is that the internal Atom clientCutProperty + * differs from the server-side serverTransToAgentProperty + * Atom. The actual name is not important. To be clean here we use + * a separate serverTransFromAgentProperty. */ XSelectionEvent eventSelection = { .requestor = serverWindow, .selection = event->u.selectionNotify.selection, .target = event->u.selectionNotify.target, - .property = serverClientCutProperty, + .property = serverTransFromAgentProperty, .time = CurrentTime, }; @@ -2172,24 +2172,24 @@ Bool nxagentInitClipboard(WindowPtr pWin) * Server side properties to hold pasted data. * see nxagentSendNotify for an explanation */ - serverClientCutProperty = nxagentAtoms[15]; /* NX_CUT_BUFFER_CLIENT */ - serverCutProperty = nxagentAtoms[5]; /* NX_CUT_BUFFER_SERVER */ + serverTransFromAgentProperty = nxagentAtoms[15]; /* NX_SELTRANS_FROM_AGENT */ + serverTransToAgentProperty = nxagentAtoms[5]; /* NX_CUT_BUFFER_SERVER */ - if (serverCutProperty == None) + if (serverTransToAgentProperty == None) { #ifdef PANIC - fprintf(stderr, "%s: PANIC! Could not create NX_CUT_BUFFER_SERVER atom\n", __func__); + fprintf(stderr, "%s: PANIC! Could not create %s atom\n", __func__, "NX_CUT_BUFFER_SERVER"); #endif return False; } #ifdef TEST - fprintf(stderr, "%s: Setting owner of selection [%s][%d] on window 0x%x\n", __func__, - "NX_CUT_BUFFER_SERVER", (int) serverCutProperty, serverWindow); + fprintf(stderr, "%s: Setting owner of selection [%d][%s] on window 0x%x\n", __func__, + (int) serverTransToAgentProperty, "NX_CUT_BUFFER_SERVER", serverWindow); #endif - XSetSelectionOwner(nxagentDisplay, serverCutProperty, serverWindow, CurrentTime); + XSetSelectionOwner(nxagentDisplay, serverTransToAgentProperty, serverWindow, CurrentTime); if (XQueryExtension(nxagentDisplay, "XFIXES", @@ -2285,7 +2285,7 @@ Bool nxagentInitClipboard(WindowPtr pWin) { #ifdef PANIC fprintf(stderr, "%s: PANIC! " - "Could not create NX_CUT_BUFFER_CLIENT atom.\n", __func__); + "Could not create %s atom.\n", __func__, szAgentNX_CUT_BUFFER_CLIENT); #endif return False; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h index 6df5a3134..a7d22ab97 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h @@ -41,7 +41,7 @@ typedef struct _XFixesAgentInfo extern XFixesAgentInfoRec nxagentXFixesInfo; /* - * Create the NX_CUT_BUFFER_CLIENT atom and + * Create the NX_SELTRANS_FROM_AGENT atom and * initialize the required property to exchange * data with the X server. */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/Splash.c b/nx-X11/programs/Xserver/hw/nxagent/Splash.c index 058269a73..323155299 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Splash.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Splash.c @@ -412,10 +412,10 @@ void nxagentRemoveSplashWindow(void) #ifdef TEST fprintf(stderr, "%s: setting the ownership of %s (%d) on window 0x%lx\n", __func__ - "NX_CUT_BUFFER_SERVER", (int)serverCutProperty, nxagentWindow(screenInfo.screens[0]->root)); + "NX_CUT_BUFFER_SERVER", (int)serverTransToAgentProperty, nxagentWindow(screenInfo.screens[0]->root)); #endif - XSetSelectionOwner(nxagentDisplay, serverCutProperty, + XSetSelectionOwner(nxagentDisplay, serverTransToAgentProperty, nxagentWindow(screenInfo.screens[0]->root), CurrentTime); } diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index 0d36c7960..40af9c60e 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -2602,7 +2602,7 @@ void nxagentMapDefaultWindows(void) * to notify of the agent start. */ - XSetSelectionOwner(nxagentDisplay, serverCutProperty, + XSetSelectionOwner(nxagentDisplay, serverTransToAgentProperty, nxagentDefaultWindows[i], CurrentTime); } diff --git a/nx-X11/programs/Xserver/hw/nxagent/Windows.h b/nx-X11/programs/Xserver/hw/nxagent/Windows.h index c742577f5..aa4629b47 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Windows.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Windows.h @@ -178,7 +178,7 @@ do\ WindowPtr nxagentWindowPtr(Window window); #ifdef XlibAtom -extern XlibAtom serverCutProperty; +extern XlibAtom serverTransToAgentProperty; #endif /* -- cgit v1.2.3 From d634f26bb54dea56830b16bdc7f555c08f59dc03 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 17 Dec 2019 22:56:25 +0100 Subject: Clipboard.c: extend/reformat some comments --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index d488e92a9..adc02a17c 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -912,7 +912,8 @@ void nxagentRequestSelection(XEvent *X) /* * if one of our clients owns the selection we ask it to copy * the selection to the clientCutProperty on nxagent's root - * window on the real X server. + * window in the first step. We then later push that property's + * content to the real X server. */ if (IS_INTERNAL_OWNER(i) && (nxagentOption(Clipboard) == ClipboardServer || @@ -1036,10 +1037,10 @@ void nxagentTransferSelection(int resource) int result; PrintClientSelectionStage(); + /* - * Don't get data yet, just get size. We skip - * this stage in current implementation and - * go straight to the data. + * Don't get data yet, just get size. We skip this stage in + * current implementation and go straight to the data. */ nxagentLastClipboardClient = NXGetCollectPropertyResource(nxagentDisplay); @@ -1323,9 +1324,9 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) * We reach here after a paste inside the nxagent, triggered by * the XConvertSelection call in nxagentConvertSelection(). This * means that data we need has been transferred to the - * serverTransToAgentProperty of the serverWindow (our window on the real X - * server). We now need to transfer it to the original requestor, - * which is stored in the lastClient* variables. + * serverTransToAgentProperty of the serverWindow (our window on + * the real X server). We now need to transfer it to the original + * requestor, which is stored in the lastClient* variables. */ if ((lastClientStage == SelectionStageNone) && (X->xselection.property == serverTransToAgentProperty)) { @@ -1365,7 +1366,10 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) int i = nxagentFindLastSelectionOwnerIndex(X->xselection.selection); if (i < nxagentMaxSelections) { - /* if the last owner was an internal one */ + /* if the last owner was an internal one, read the + * clientCutProperty and push the contents to the + * lastServerRequestor on the real X server. + */ if (IS_INTERNAL_OWNER(i) && lastSelectionOwner[i].windowPtr != NULL && X->xselection.property == serverTransFromAgentProperty) -- cgit v1.2.3 From 30fb45b2a65aa8cf1a544339b1288119319de455 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 17 Dec 2019 22:56:44 +0100 Subject: Clipboard.c: cleanup parentheses --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index adc02a17c..47eaa946d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -610,8 +610,8 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) int nxagentFindLastSelectionOwnerIndex(XlibAtom sel) { int i = 0; - while ((i < nxagentMaxSelections) && - (lastSelectionOwner[i].selection != sel)) + while (i < nxagentMaxSelections && + lastSelectionOwner[i].selection != sel) { i++; } @@ -625,8 +625,8 @@ int nxagentFindLastSelectionOwnerIndex(XlibAtom sel) int nxagentFindCurrentSelectionIndex(Atom sel) { int i = 0; - while ((i < NumCurrentSelections) && - (CurrentSelections[i].selection != sel)) + while (i < NumCurrentSelections && + CurrentSelections[i].selection != sel) { i++; } @@ -1328,7 +1328,8 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X) * the real X server). We now need to transfer it to the original * requestor, which is stored in the lastClient* variables. */ - if ((lastClientStage == SelectionStageNone) && (X->xselection.property == serverTransToAgentProperty)) + if (lastClientStage == SelectionStageNone && + X->xselection.property == serverTransToAgentProperty) { #ifdef DEBUG fprintf(stderr, "%s: Starting selection transferral for client [%d].\n", __func__, @@ -1568,10 +1569,10 @@ void nxagentSetSelectionCallback(CallbackListPtr *callbacks, void *data, fprintf(stderr, "%s: pCurSel->selection [%s]\n", __func__, NameForAtom(pCurSel->selection)); #endif - if ((pCurSel->pWin != NULL) && - (nxagentOption(Clipboard) != ClipboardNone) && /* FIXME: shouldn't we also check for != ClipboardClient? */ - ((pCurSel->selection == XA_PRIMARY) || - (pCurSel->selection == clientCLIPBOARD))) + if (pCurSel->pWin != NULL && + nxagentOption(Clipboard) != ClipboardNone && /* FIXME: shouldn't we also check for != ClipboardClient? */ + (pCurSel->selection == XA_PRIMARY || + pCurSel->selection == clientCLIPBOARD)) { #ifdef DEBUG fprintf(stderr, "%s: calling nxagentSetSelectionOwner\n", __func__); @@ -1897,10 +1898,10 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, } #endif - if ((target == clientTEXT) || - (target == XA_STRING) || - (target == clientCOMPOUND_TEXT) || - (target == clientUTF8_STRING)) + if (target == clientTEXT || + target == XA_STRING || + target == clientCOMPOUND_TEXT || + target == clientUTF8_STRING) { lastClientWindowPtr = pWin; SetClientSelectionStage(None); @@ -2109,8 +2110,9 @@ int nxagentSendNotify(xEvent *event) WindowPtr nxagentGetClipboardWindow(Atom property) { int i = nxagentFindLastSelectionOwnerIndex(nxagentLastRequestedSelection); - if ((i < nxagentMaxSelections) && (property == clientCutProperty) && - (lastSelectionOwner[i].windowPtr != NULL)) + if (i < nxagentMaxSelections && + property == clientCutProperty && + lastSelectionOwner[i].windowPtr != NULL) { #ifdef DEBUG fprintf(stderr, "%s: Returning last [%d] selection owner window [%p] (0x%x).\n", __func__, -- cgit v1.2.3