diff options
author | Ulrich Sibiller <uli42@gmx.de> | 2019-08-05 16:08:40 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2019-09-29 17:44:07 +0200 |
commit | 5de8bac22e710ec6a17789fca88f5f0b49351773 (patch) | |
tree | 551fc2d7a7ffe11f0ca1a8c697f42c5ef8db8a04 /nx-X11/programs | |
parent | 79867f4a0ee04c40a35402435902abe9849dcd93 (diff) | |
download | nx-libs-5de8bac22e710ec6a17789fca88f5f0b49351773.tar.gz nx-libs-5de8bac22e710ec6a17789fca88f5f0b49351773.tar.bz2 nx-libs-5de8bac22e710ec6a17789fca88f5f0b49351773.zip |
Clipboard.c: introduce nxagentFind*Index functions
At some places we were using NumCurrentSelections. We replace that by
nxagentMaxSelections because they always have the identical value.
Diffstat (limited to 'nx-X11/programs')
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 69 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Clipboard.h | 1 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Events.c | 7 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c | 6 |
4 files changed, 33 insertions, 50 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index a5dade03e..0452cd193 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -524,10 +524,30 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) nxagentPrintClipboardStat("after nxagentClearClipboard"); } -void nxagentClearSelection(XEvent *X) +int nxagentFindLastSelectionOwnerIndex(Atom sel) { int i = 0; + while ((i < nxagentMaxSelections) && + (lastSelectionOwner[i].selection != sel)) + { + i++; + } + return i; +} +int nxagentFindCurrentSelectionIndex(Atom sel) +{ + int i = 0; + while ((i < NumCurrentSelections) && + (CurrentSelections[i].selection != sel)) + { + i++; + } + return i; +} + +void nxagentClearSelection(XEvent *X) +{ #ifdef DEBUG fprintf(stderr, "%s: SelectionClear event for selection [%lu].\n", __func__, X->xselectionclear.selection); #endif @@ -540,11 +560,7 @@ void nxagentClearSelection(XEvent *X) return; } - while ((i < nxagentMaxSelections) && - (lastSelectionOwner[i].selection != X->xselectionclear.selection)) - { - i++; - } + int i = nxagentFindLastSelectionOwnerIndex(X->xselectionclear.selection); if (i < nxagentMaxSelections) { @@ -573,7 +589,6 @@ void nxagentClearSelection(XEvent *X) void nxagentRequestSelection(XEvent *X) { - int i = 0; XSelectionEvent eventSelection = {0}; #ifdef DEBUG @@ -628,10 +643,8 @@ FIXME: Do we need this? } else if (X->xselectionrequest.target == nxagentTimestampAtom) { - while ((i < NumCurrentSelections) && - lastSelectionOwner[i].selection != X->xselectionrequest.selection) i++; - - if (i < NumCurrentSelections) + int i = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); + if (i < nxagentMaxSelections) { XChangeProperty(nxagentDisplay, X->xselectionrequest.requestor, @@ -661,13 +674,8 @@ FIXME: Do we need this? nxagentLastRequestedSelection = X->xselectionrequest.selection; - /* FIXME: shouldn't we reset i to 0 here first? */ - while ((i < nxagentMaxSelections) && - (lastSelectionOwner[i].selection != X->xselectionrequest.selection)) - { - i++; - } - + /* find the index of the requested selection */ + int i = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); if (i < nxagentMaxSelections) { if ((lastClientWindowPtr != NULL) && (lastSelectionOwner[i].client != NULL)) @@ -1109,13 +1117,7 @@ void nxagentNotifySelection(XEvent *X) } else { - int i = 0; - - while ((i < nxagentMaxSelections) && (lastSelectionOwner[i].selection != X->xselection.selection)) - { - i++; - } - + int i = nxagentFindLastSelectionOwnerIndex(X->xselection.selection); if (i < nxagentMaxSelections) { if ((lastSelectionOwner[i].client != NULL) && @@ -1417,7 +1419,6 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, Window requestor, Atom property, Atom target, Time time) { const char *strTarget; - int i; if (agentClipboardStatus != 1 || nxagentOption(Clipboard) == ClipboardServer) @@ -1433,7 +1434,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, * Only for PRIMARY and CLIPBOARD selections. */ - for (i = 0; i < nxagentMaxSelections; i++) + for (int i = 0; i < nxagentMaxSelections; i++) { if ((selection == CurrentSelections[i].selection) && (lastSelectionOwner[i].client != NULL)) @@ -1510,11 +1511,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, if (target == MakeAtom("TIMESTAMP", 9, 1)) { - int i = 0; - - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != selection) i++; - + int i = nxagentFindCurrentSelectionIndex(selection); if (i < NumCurrentSelections) { ChangeWindowProperty(pWin, @@ -1673,17 +1670,11 @@ int nxagentSendNotify(xEvent *event) WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin) { - int i = 0; - #ifdef DEBUG fprintf(stderr, "%s: Got called, property [%d][%s] window [%p].\n", __func__, property, NameForAtom(property), (void *)pWin); #endif - while ((i < nxagentMaxSelections) && - (lastSelectionOwner[i].selection != nxagentLastRequestedSelection)) - { - i++; - } + int i = nxagentFindLastSelectionOwnerIndex(nxagentLastRequestedSelection); if ((i < nxagentMaxSelections) && (property == clientCutProperty) && (lastSelectionOwner[i].windowPtr != NULL)) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h index 62fc32fd9..2f43469ae 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.h @@ -66,4 +66,5 @@ void nxagentClearSelection(); void nxagentRequestSelection(); void nxagentNotifySelection(); +int nxagentFindCurrentSelectionIndex(Atom sel); #endif /* __Clipboard_H__ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index e9de1450d..4a13f15ad 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -2933,12 +2933,7 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X) if (SelectionCallback) { - int i = 0; - - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != local) - i++; - + int i = nxagentFindCurrentSelectionIndex(local); if (i < NumCurrentSelections) { SelectionInfoRec info; diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c b/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c index b7a054913..4a9ae73ae 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c @@ -691,11 +691,7 @@ ProcConvertSelection(register ClientPtr client) (stuff->selection == MakeAtom("CLIPBOARD", 9, 0))) && nxagentOption(Clipboard) != ClipboardNone) { - int i = 0; - - while ((i < NumCurrentSelections) && - CurrentSelections[i].selection != stuff->selection) i++; - + int i = nxagentFindCurrentSelectionIndex(stuff->selection); if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None)) { if (nxagentConvertSelection(client, pWin, stuff->selection, stuff->requestor, |