Commit 5de8bac2 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

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.
parent 79867f4a
...@@ -524,10 +524,30 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) ...@@ -524,10 +524,30 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
nxagentPrintClipboardStat("after nxagentClearClipboard"); nxagentPrintClipboardStat("after nxagentClearClipboard");
} }
void nxagentClearSelection(XEvent *X) int nxagentFindLastSelectionOwnerIndex(Atom sel)
{ {
int i = 0; 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 #ifdef DEBUG
fprintf(stderr, "%s: SelectionClear event for selection [%lu].\n", __func__, X->xselectionclear.selection); fprintf(stderr, "%s: SelectionClear event for selection [%lu].\n", __func__, X->xselectionclear.selection);
#endif #endif
...@@ -540,11 +560,7 @@ void nxagentClearSelection(XEvent *X) ...@@ -540,11 +560,7 @@ void nxagentClearSelection(XEvent *X)
return; return;
} }
while ((i < nxagentMaxSelections) && int i = nxagentFindLastSelectionOwnerIndex(X->xselectionclear.selection);
(lastSelectionOwner[i].selection != X->xselectionclear.selection))
{
i++;
}
if (i < nxagentMaxSelections) if (i < nxagentMaxSelections)
{ {
...@@ -573,7 +589,6 @@ void nxagentClearSelection(XEvent *X) ...@@ -573,7 +589,6 @@ void nxagentClearSelection(XEvent *X)
void nxagentRequestSelection(XEvent *X) void nxagentRequestSelection(XEvent *X)
{ {
int i = 0;
XSelectionEvent eventSelection = {0}; XSelectionEvent eventSelection = {0};
#ifdef DEBUG #ifdef DEBUG
...@@ -628,10 +643,8 @@ FIXME: Do we need this? ...@@ -628,10 +643,8 @@ FIXME: Do we need this?
} }
else if (X->xselectionrequest.target == nxagentTimestampAtom) else if (X->xselectionrequest.target == nxagentTimestampAtom)
{ {
while ((i < NumCurrentSelections) && int i = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection);
lastSelectionOwner[i].selection != X->xselectionrequest.selection) i++; if (i < nxagentMaxSelections)
if (i < NumCurrentSelections)
{ {
XChangeProperty(nxagentDisplay, XChangeProperty(nxagentDisplay,
X->xselectionrequest.requestor, X->xselectionrequest.requestor,
...@@ -661,13 +674,8 @@ FIXME: Do we need this? ...@@ -661,13 +674,8 @@ FIXME: Do we need this?
nxagentLastRequestedSelection = X->xselectionrequest.selection; nxagentLastRequestedSelection = X->xselectionrequest.selection;
/* FIXME: shouldn't we reset i to 0 here first? */ /* find the index of the requested selection */
while ((i < nxagentMaxSelections) && int i = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection);
(lastSelectionOwner[i].selection != X->xselectionrequest.selection))
{
i++;
}
if (i < nxagentMaxSelections) if (i < nxagentMaxSelections)
{ {
if ((lastClientWindowPtr != NULL) && (lastSelectionOwner[i].client != NULL)) if ((lastClientWindowPtr != NULL) && (lastSelectionOwner[i].client != NULL))
...@@ -1109,13 +1117,7 @@ void nxagentNotifySelection(XEvent *X) ...@@ -1109,13 +1117,7 @@ void nxagentNotifySelection(XEvent *X)
} }
else else
{ {
int i = 0; int i = nxagentFindLastSelectionOwnerIndex(X->xselection.selection);
while ((i < nxagentMaxSelections) && (lastSelectionOwner[i].selection != X->xselection.selection))
{
i++;
}
if (i < nxagentMaxSelections) if (i < nxagentMaxSelections)
{ {
if ((lastSelectionOwner[i].client != NULL) && if ((lastSelectionOwner[i].client != NULL) &&
...@@ -1417,7 +1419,6 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1417,7 +1419,6 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
Window requestor, Atom property, Atom target, Time time) Window requestor, Atom property, Atom target, Time time)
{ {
const char *strTarget; const char *strTarget;
int i;
if (agentClipboardStatus != 1 || if (agentClipboardStatus != 1 ||
nxagentOption(Clipboard) == ClipboardServer) nxagentOption(Clipboard) == ClipboardServer)
...@@ -1433,7 +1434,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1433,7 +1434,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
* Only for PRIMARY and CLIPBOARD selections. * Only for PRIMARY and CLIPBOARD selections.
*/ */
for (i = 0; i < nxagentMaxSelections; i++) for (int i = 0; i < nxagentMaxSelections; i++)
{ {
if ((selection == CurrentSelections[i].selection) && if ((selection == CurrentSelections[i].selection) &&
(lastSelectionOwner[i].client != NULL)) (lastSelectionOwner[i].client != NULL))
...@@ -1510,11 +1511,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1510,11 +1511,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
if (target == MakeAtom("TIMESTAMP", 9, 1)) if (target == MakeAtom("TIMESTAMP", 9, 1))
{ {
int i = 0; int i = nxagentFindCurrentSelectionIndex(selection);
while ((i < NumCurrentSelections) &&
CurrentSelections[i].selection != selection) i++;
if (i < NumCurrentSelections) if (i < NumCurrentSelections)
{ {
ChangeWindowProperty(pWin, ChangeWindowProperty(pWin,
...@@ -1673,17 +1670,11 @@ int nxagentSendNotify(xEvent *event) ...@@ -1673,17 +1670,11 @@ int nxagentSendNotify(xEvent *event)
WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin) WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin)
{ {
int i = 0;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Got called, property [%d][%s] window [%p].\n", __func__, property, NameForAtom(property), (void *)pWin); fprintf(stderr, "%s: Got called, property [%d][%s] window [%p].\n", __func__, property, NameForAtom(property), (void *)pWin);
#endif #endif
while ((i < nxagentMaxSelections) && int i = nxagentFindLastSelectionOwnerIndex(nxagentLastRequestedSelection);
(lastSelectionOwner[i].selection != nxagentLastRequestedSelection))
{
i++;
}
if ((i < nxagentMaxSelections) && (property == clientCutProperty) && if ((i < nxagentMaxSelections) && (property == clientCutProperty) &&
(lastSelectionOwner[i].windowPtr != NULL)) (lastSelectionOwner[i].windowPtr != NULL))
......
...@@ -66,4 +66,5 @@ void nxagentClearSelection(); ...@@ -66,4 +66,5 @@ void nxagentClearSelection();
void nxagentRequestSelection(); void nxagentRequestSelection();
void nxagentNotifySelection(); void nxagentNotifySelection();
int nxagentFindCurrentSelectionIndex(Atom sel);
#endif /* __Clipboard_H__ */ #endif /* __Clipboard_H__ */
...@@ -2933,12 +2933,7 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X) ...@@ -2933,12 +2933,7 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X)
if (SelectionCallback) if (SelectionCallback)
{ {
int i = 0; int i = nxagentFindCurrentSelectionIndex(local);
while ((i < NumCurrentSelections) &&
CurrentSelections[i].selection != local)
i++;
if (i < NumCurrentSelections) if (i < NumCurrentSelections)
{ {
SelectionInfoRec info; SelectionInfoRec info;
......
...@@ -691,11 +691,7 @@ ProcConvertSelection(register ClientPtr client) ...@@ -691,11 +691,7 @@ ProcConvertSelection(register ClientPtr client)
(stuff->selection == MakeAtom("CLIPBOARD", 9, 0))) && (stuff->selection == MakeAtom("CLIPBOARD", 9, 0))) &&
nxagentOption(Clipboard) != ClipboardNone) nxagentOption(Clipboard) != ClipboardNone)
{ {
int i = 0; int i = nxagentFindCurrentSelectionIndex(stuff->selection);
while ((i < NumCurrentSelections) &&
CurrentSelections[i].selection != stuff->selection) i++;
if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None)) if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None))
{ {
if (nxagentConvertSelection(client, pWin, stuff->selection, stuff->requestor, if (nxagentConvertSelection(client, pWin, stuff->selection, stuff->requestor,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment