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/programs/Xserver/hw/nxagent/Clipboard.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 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