Commit cb3e44a1 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Clipboard.c: Refactor nxagentCollectPropertyEvent

parent 9006e19a
...@@ -930,6 +930,13 @@ void nxagentTransferSelection(int resource) ...@@ -930,6 +930,13 @@ void nxagentTransferSelection(int resource)
} }
} }
/*
Called from Events.c/nxagentHandlePropertyNotify
This event is generated after XChangeProperty(), XDeleteProperty() or
XGetWindowProperty(delete=True)
*/
void nxagentCollectPropertyEvent(int resource) void nxagentCollectPropertyEvent(int resource)
{ {
Atom atomReturnType; Atom atomReturnType;
...@@ -940,9 +947,8 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -940,9 +947,8 @@ void nxagentCollectPropertyEvent(int resource)
int result; int result;
/* /*
* We have received the notification so * We have received the notification so we can safely retrieve data
* we can safely retrieve data from the * from the client structure.
* client structure.
*/ */
result = NXGetCollectedProperty(nxagentDisplay, result = NXGetCollectedProperty(nxagentDisplay,
...@@ -958,28 +964,21 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -958,28 +964,21 @@ void nxagentCollectPropertyEvent(int resource)
if (result == 0) if (result == 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "%s: Failed to get reply data for client [%d].\n", __func__, fprintf (stderr, "%s: Failed to get reply data.\n", __func__);
CLINDEX(lastClientClientPtr));
#endif #endif
endTransfer(SELECTION_FAULT); endTransfer(SELECTION_FAULT);
SAFE_XFree(pszReturnData);
return;
} }
else if (resultFormat != 8 && resultFormat != 16 && resultFormat != 32)
if (resultFormat != 8 && resultFormat != 16 && resultFormat != 32)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "%s: WARNING! Invalid property value.\n", __func__); fprintf (stderr, "%s: WARNING! Invalid property format.\n", __func__);
#endif #endif
endTransfer(SELECTION_FAULT); endTransfer(SELECTION_FAULT);
SAFE_XFree(pszReturnData);
return;
} }
else
{
switch (lastClientStage) switch (lastClientStage)
{ {
case SelectionStageWaitSize: case SelectionStageWaitSize:
...@@ -993,16 +992,13 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -993,16 +992,13 @@ void nxagentCollectPropertyEvent(int resource)
if (ulReturnBytesLeft == 0) if (ulReturnBytesLeft == 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "%s: Aborting selection notify procedure for client [%d].\n", __func__, fprintf (stderr, "%s: Aborting selection notify procedure.\n", __func__);
CLINDEX(lastClientClientPtr));
#endif #endif
endTransfer(SELECTION_FAULT); endTransfer(SELECTION_FAULT);
SAFE_XFree(pszReturnData);
return;
} }
else
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Got property size from remote server.\n", __func__); fprintf(stderr, "%s: Got property size from remote server.\n", __func__);
#endif #endif
...@@ -1010,12 +1006,11 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -1010,12 +1006,11 @@ void nxagentCollectPropertyEvent(int resource)
/* /*
* Request the selection data now. * Request the selection data now.
*/ */
lastClientPropertySize = ulReturnBytesLeft; lastClientPropertySize = ulReturnBytesLeft;
SetClientSelectionStage(QueryData); SetClientSelectionStage(QueryData);
nxagentTransferSelection(resource); nxagentTransferSelection(resource);
}
break; break;
} }
case SelectionStageWaitData: case SelectionStageWaitData:
...@@ -1029,16 +1024,13 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -1029,16 +1024,13 @@ void nxagentCollectPropertyEvent(int resource)
if (ulReturnBytesLeft != 0) if (ulReturnBytesLeft != 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "%s: Aborting selection notify procedure for client [%d].\n", __func__, fprintf (stderr, "%s: Aborting selection notify procedure.\n", __func__);
CLINDEX(lastClientClientPtr));
#endif #endif
endTransfer(SELECTION_FAULT); endTransfer(SELECTION_FAULT);
SAFE_XFree(pszReturnData);
return;
} }
else
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Got property content from remote server.\n", __func__); fprintf(stderr, "%s: Got property content from remote server.\n", __func__);
#endif #endif
...@@ -1050,12 +1042,15 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -1050,12 +1042,15 @@ void nxagentCollectPropertyEvent(int resource)
ulReturnItems, pszReturnData, 1); ulReturnItems, pszReturnData, 1);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Selection property [%s] changed to [%s]\n", __func__, fprintf(stderr, "%s: Selection property [%d][%s] changed to [\"%*.*s\"...]\n", __func__,
validateString(NameForAtom(lastClientProperty)), pszReturnData); lastClientProperty, validateString(NameForAtom(lastClientProperty)),
(int)(min(20, ulReturnItems * resultFormat / 8)),
(int)(min(20, ulReturnItems * resultFormat / 8)),
pszReturnData);
#endif #endif
endTransfer(SELECTION_SUCCESS); endTransfer(SELECTION_SUCCESS);
}
break; break;
} }
default: default:
...@@ -1064,11 +1059,10 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -1064,11 +1059,10 @@ void nxagentCollectPropertyEvent(int resource)
fprintf (stderr, "%s: WARNING! Inconsistent state [%s] for client [%d].\n", __func__, fprintf (stderr, "%s: WARNING! Inconsistent state [%s] for client [%d].\n", __func__,
GetClientSelectionStageString(lastClientStage), CLINDEX(lastClientClientPtr)); GetClientSelectionStageString(lastClientStage), CLINDEX(lastClientClientPtr));
#endif #endif
break; break;
} }
} }
}
SAFE_XFree(pszReturnData); SAFE_XFree(pszReturnData);
} }
......
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