Unverified Commit 28043201 authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/clipboard_debug' into 3.6.x

parents 2eb4a65e 60bce146
...@@ -140,6 +140,59 @@ static char szAgentUTF8_STRING[] = "UTF8_STRING"; ...@@ -140,6 +140,59 @@ static char szAgentUTF8_STRING[] = "UTF8_STRING";
static char szAgentNX_CUT_BUFFER_CLIENT[] = "NX_CUT_BUFFER_CLIENT"; static char szAgentNX_CUT_BUFFER_CLIENT[] = "NX_CUT_BUFFER_CLIENT";
/* /*
* some helpers for debugging output
*/
#ifdef DEBUG
const char * GetClientSelectionStageString(int stage)
{
switch(stage)
{
case SelectionStageNone: return("None"); break;;
case SelectionStageQuerySize: return("QuerySize"); break;;
case SelectionStageWaitSize: return("WaitSize"); break;;
case SelectionStageQueryData: return("QueryData"); break;;
case SelectionStageWaitData: return("WaitData"); break;;
default: return("UNKNOWN!"); break;;
}
}
#define SetClientSelectionStage(stage) do {fprintf(stderr, "%s: Changing selection stage from [%s] to [%s]\n", __func__, GetClientSelectionStageString(lastClientStage), GetClientSelectionStageString(SelectionStage##stage)); lastClientStage = SelectionStage##stage;} while (0)
#define PrintClientSelectionStage() do {fprintf(stderr, "%s: Current selection stage [%s]\n", __func__, GetClientSelectionStageString(lastClientStage));} while (0)
#else
#define SetClientSelectionStage(stage) do {lastClientStage = SelectionStage##stage;} while (0)
#define PrintClientSelectionStage()
#endif
/*
* see also nx-X11/lib/src/ErrDes.c
*/
const char * GetXErrorString(int code)
{
switch(code)
{
case Success: return("Success"); break;;
case BadRequest: return("BadRequest"); break;;
case BadValue: return("BadValue"); break;;
case BadWindow: return("BadWindow"); break;;
case BadPixmap: return("BadPixmap"); break;;
case BadAtom: return("BadAtom"); break;;
case BadCursor: return("BadCursor"); break;;
case BadFont: return("BadFont"); break;;
case BadMatch: return("BadMatch"); break;;
case BadDrawable: return("BadDrawable"); break;;
case BadAccess: return("BadAccess"); break;;
case BadAlloc: return("BadAlloc"); break;;
case BadColor: return("BadColor"); break;;
case BadGC: return("BadGC"); break;;
case BadIDChoice: return("BadIDChoice"); break;;
case BadName: return("BadName"); break;;
case BadLength: return("BadLength"); break;;
case BadImplementation: return("BadImplementation"); break;;
default: return("UNKNOWN!"); break;;
}
}
/*
* Save the values queried from X server. * Save the values queried from X server.
*/ */
...@@ -157,6 +210,139 @@ void nxagentNotifyConvertFailure(ClientPtr client, Window requestor, ...@@ -157,6 +210,139 @@ void nxagentNotifyConvertFailure(ClientPtr client, Window requestor,
Atom selection, Atom target, Time time); Atom selection, Atom target, Time time);
int nxagentSendNotify(xEvent *event); int nxagentSendNotify(xEvent *event);
void nxagentPrintClipboardStat(char *);
#ifdef DEBUG
void nxagentPrintSelectionStat(int sel)
{
SelectionOwner lOwner = lastSelectionOwner[sel];
Selection curSel = CurrentSelections[sel];
char *s =NULL;
#ifdef CLIENTIDS
fprintf(stderr, " lastSelectionOwner[].client [%p] index [%d] PID [%d] Cmd [%s]\n",
(void *)lOwner.client,
lOwner.client ? lOwner.client->index : -1,
GetClientPid(lOwner.client),
GetClientCmdName(lOwner.client));
#else
fprintf(stderr, " lastSelectionOwner[].client [%p] index [%d]\n",
(void *)lOwner.client,
lOwner.client ? lOwner.client->index : -1);
#endif
fprintf(stderr, " lastSelectionOwner[].window [0x%x]\n", lOwner.window);
fprintf(stderr, " lastSelectionOwner[].windowPtr [%p]\n", (void *)lOwner.windowPtr);
fprintf(stderr, " lastSelectionOwner[].lastTimeChanged [%u]\n", lOwner.lastTimeChanged);
/*
print the selection name.
*/
if (lOwner.client)
{
fprintf(stderr, " lastSelectionOwner[].selection [% 4d][%s] (local)\n", lOwner.selection, NameForAtom(lOwner.selection));
}
else
{
SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, lOwner.selection);
fprintf(stderr, " lastSelectionOwner[].selection [% 4d][%s] (remote)\n", lOwner.selection, validateString(s));
SAFE_XFree(s);
}
#ifdef CLIENTIDS
fprintf(stderr, " CurrentSelections[].client [%p] index [%d] PID [%d] Cmd [%s]\n",
(void *)curSel.client,
curSel.client ? curSel.client->index : -1,
GetClientPid(curSel.client),
GetClientCmdName(curSel.client));
#else
fprintf(stderr, " CurrentSelections[].client [%p] index [%d]\n",
(void *)curSel.client,
curSel.client ? curSel.client->index : -1);
#endif
fprintf(stderr, " CurrentSelections[].window [0x%x]\n", curSel.window);
return;
}
#endif
void nxagentPrintClipboardStat(char *header)
{
#ifdef DEBUG
char *s =NULL;
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, " 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 ");
switch(nxagentOption(Clipboard))
{
case ClipboardBoth: fprintf(stderr, "[Both]"); break;;
case ClipboardClient: fprintf(stderr, "[Client]"); break;;
case ClipboardServer: fprintf(stderr, "[Server]"); break;;
case ClipboardNone: fprintf(stderr, "[None]"); break;;
default: fprintf(stderr, "[UNKNOWN] (FAIL!)"); break;;
}
fprintf(stderr,"\n");
fprintf(stderr, "lastServer\n");
fprintf(stderr, " lastServerRequestor (Window) [0x%x]\n", lastServerRequestor);
SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, lastServerProperty);
fprintf(stderr, " lastServerProperty (Atom) [% 4d][%s]\n", lastServerProperty, s);
SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, lastServerTarget);
fprintf(stderr, " lastServerTarget (Atom) [% 4d][%s]\n", lastServerTarget, s);
fprintf(stderr, " lastServerTime (Time) [%u]\n", lastServerTime);
fprintf(stderr, "lastClient\n");
fprintf(stderr, " lastClientWindowPtr (WindowPtr) [%p]\n", (void *)lastClientWindowPtr);
fprintf(stderr, " lastClientClientPtr (ClientPtr) [%p]\n", (void *)lastClientClientPtr);
fprintf(stderr, " lastClientRequestor (Window) [0x%x]\n", lastClientRequestor);
fprintf(stderr, " lastClientProperty (Atom) [% 4d][%s]\n", lastClientProperty, NameForAtom(lastClientProperty));
fprintf(stderr, " lastClientSelection (Atom) [% 4d][%s]\n", lastClientSelection, NameForAtom(lastClientSelection));
fprintf(stderr, " lastClientTarget (Atom) [% 4d][%s]\n", lastClientTarget, NameForAtom(lastClientTarget));
fprintf(stderr, " lastClientTime (Time) [%u]\n", lastServerTime);
fprintf(stderr, " lastClientReqTime (Time) [%u]\n", lastServerTime);
fprintf(stderr, " lastClientPropertySize (unsigned long) [%lu]\n", lastClientPropertySize);
fprintf(stderr, " lastClientStage (ClientSelectionStage) [%d][%s]\n", lastClientStage, GetClientSelectionStageString(lastClientStage));
fprintf(stderr, "PRIMARY\n");
nxagentPrintSelectionStat(nxagentPrimarySelection);
fprintf(stderr, "CLIPBOARD\n");
nxagentPrintSelectionStat(nxagentClipboardSelection);
fprintf(stderr, "Atoms (server side)\n");
SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, serverTARGETS);
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, 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, nxagentClipboardAtom);
fprintf(stderr, " nxagentClipboardAtom [% 4d][%s]\n", nxagentClipboardAtom, s);
SAFE_XFree(s); s = XGetAtomName(nxagentDisplay, nxagentTimestampAtom);
fprintf(stderr, " nxagentTimestampAtom [% 4d][%s]\n", nxagentTimestampAtom, s);
fprintf(stderr, "Atoms (inside nxagent)\n");
fprintf(stderr, " clientTARGETS [% 4d][%s]\n", clientTARGETS, NameForAtom(clientTARGETS));
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, " clientCutProperty [% 4d][%s]\n", clientCutProperty, NameForAtom(clientCutProperty));
fprintf(stderr, " nxagentLastRequestedSelection [% 4d][%s]\n", nxagentLastRequestedSelection, NameForAtom(nxagentLastRequestedSelection));
fprintf(stderr, "\\------------------------------------------------------------------------------\n");
SAFE_XFree(s);
#endif
}
/* /*
* This is from NXproperty.c. * This is from NXproperty.c.
*/ */
...@@ -168,15 +354,39 @@ int GetWindowProperty(WindowPtr pWin, Atom property, long longOffset, long longL ...@@ -168,15 +354,39 @@ int GetWindowProperty(WindowPtr pWin, Atom property, long longOffset, long longL
Bool nxagentValidServerTargets(Atom target) Bool nxagentValidServerTargets(Atom target)
{ {
if (target == XA_STRING)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentValidServerTargets: Got called.\n"); fprintf(stderr, "%s: valid target [XA_STRING].\n", __func__);
#endif #endif
return True;
if (target == XA_STRING) return True; }
if (target == serverTEXT) return True; else if (target == serverTEXT)
{
#ifdef DEBUG
fprintf(stderr, "%s: valid target [TEXT].\n", __func__);
#endif
return True;
}
/* by dimbor */ /* by dimbor */
if (target == serverUTF8_STRING) return True; else if (target == serverUTF8_STRING)
{
#ifdef DEBUG
fprintf(stderr, "%s: valid target [UTF8_STRING].\n", __func__);
#endif
return True;
}
else if (target == serverTARGETS)
{
#ifdef DEBUG
fprintf(stderr, "%s: special target [TARGETS].\n", __func__);
#endif
return False;
}
#ifdef DEBUG
fprintf(stderr, "%s: invalid target [%u].\n", __func__, target);
#endif
return False; return False;
} }
...@@ -185,10 +395,12 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) ...@@ -185,10 +395,12 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
int i; int i;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentClearClipboard: Called with client [%p] window [%p].\n", fprintf(stderr, "%s: Called with client [%p] window [%p].\n", __func__,
(void *) pClient, (void *) pWindow); (void *) pClient, (void *) pWindow);
#endif #endif
nxagentPrintClipboardStat("before nxagentClearClipboard");
/* /*
* Only for PRIMARY and CLIPBOARD selections. * Only for PRIMARY and CLIPBOARD selections.
*/ */
...@@ -199,7 +411,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) ...@@ -199,7 +411,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
(pWindow != NULL && lastSelectionOwner[i].windowPtr == pWindow)) (pWindow != NULL && lastSelectionOwner[i].windowPtr == pWindow))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentClearClipboard: Resetting state with client [%p] window [%p].\n", fprintf(stderr, "%s: Resetting state with client [%p] window [%p].\n", __func__,
(void *) pClient, (void *) pWindow); (void *) pClient, (void *) pWindow);
#endif #endif
...@@ -209,7 +421,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) ...@@ -209,7 +421,7 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
lastSelectionOwner[i].lastTimeChanged = GetTimeInMillis(); lastSelectionOwner[i].lastTimeChanged = GetTimeInMillis();
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
lastServerRequestor = None; lastServerRequestor = None;
} }
...@@ -218,9 +430,10 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow) ...@@ -218,9 +430,10 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
if (pWindow == lastClientWindowPtr) if (pWindow == lastClientWindowPtr)
{ {
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
} }
nxagentPrintClipboardStat("after nxagentClearClipboard");
} }
void nxagentClearSelection(XEvent *X) void nxagentClearSelection(XEvent *X)
...@@ -228,19 +441,17 @@ void nxagentClearSelection(XEvent *X) ...@@ -228,19 +441,17 @@ void nxagentClearSelection(XEvent *X)
int i = 0; int i = 0;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentClearSelection: Got called.\n"); fprintf(stderr, "%s: SelectionClear event for selection [%lu].\n", __func__, X->xselectionclear.selection);
#endif #endif
nxagentPrintClipboardStat("before nxagentClearSelection");
if (agentClipboardStatus != 1 || if (agentClipboardStatus != 1 ||
nxagentOption(Clipboard) == ClipboardServer) nxagentOption(Clipboard) == ClipboardServer)
{ {
return; return;
} }
#ifdef DEBUG
fprintf(stderr, "nxagentClearSelection: SelectionClear event.\n");
#endif
while ((i < nxagentMaxSelections) && while ((i < nxagentMaxSelections) &&
(lastSelectionOwner[i].selection != X->xselectionclear.selection)) (lastSelectionOwner[i].selection != X->xselectionclear.selection))
{ {
...@@ -272,21 +483,21 @@ void nxagentClearSelection(XEvent *X) ...@@ -272,21 +483,21 @@ void nxagentClearSelection(XEvent *X)
} }
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
nxagentPrintClipboardStat("after nxagentClearSelection");
} }
void nxagentRequestSelection(XEvent *X) void nxagentRequestSelection(XEvent *X)
{ {
#ifdef DEBUG
int result;
#endif
int i = 0; int i = 0;
XSelectionEvent eventSelection; XSelectionEvent eventSelection = {0};
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentRequestSelection: Got called.\n"); fprintf(stderr, "%s: Got called.\n", __func__);
#endif #endif
nxagentPrintClipboardStat("before nxagentRequestSelection");
if (agentClipboardStatus != 1) if (agentClipboardStatus != 1)
{ {
return; return;
...@@ -311,10 +522,7 @@ FIXME: Do we need this? ...@@ -311,10 +522,7 @@ FIXME: Do we need this?
fprintf(stderr, "SelectionRequest event aborting sele=[%s] ext target=[%s] Atom size is [%d]\n", fprintf(stderr, "SelectionRequest event aborting sele=[%s] ext target=[%s] Atom size is [%d]\n",
validateString(NameForAtom(X->xselectionrequest.selection)), strTarget, sizeof(Atom)); validateString(NameForAtom(X->xselectionrequest.selection)), strTarget, sizeof(Atom));
if (strTarget != NULL) SAFE_XFree(strTarget);
{
XFree(strTarget);
}
*/ */
memset(&eventSelection, 0, sizeof(XSelectionEvent)); memset(&eventSelection, 0, sizeof(XSelectionEvent));
eventSelection.property = None; eventSelection.property = None;
...@@ -332,8 +540,7 @@ FIXME: Do we need this? ...@@ -332,8 +540,7 @@ FIXME: Do we need this?
1); 1);
eventSelection.property = X->xselectionrequest.property; eventSelection.property = X->xselectionrequest.property;
} }
else if (X->xselectionrequest.target == nxagentTimestampAtom)
if (X->xselectionrequest.target == nxagentTimestampAtom)
{ {
while ((i < NumCurrentSelections) && while ((i < NumCurrentSelections) &&
lastSelectionOwner[i].selection != X->xselectionrequest.selection) i++; lastSelectionOwner[i].selection != X->xselectionrequest.selection) i++;
...@@ -361,7 +568,7 @@ FIXME: Do we need this? ...@@ -361,7 +568,7 @@ FIXME: Do we need this?
eventSelection.time = X->xselectionrequest.time; eventSelection.time = X->xselectionrequest.time;
#ifdef DEBUG #ifdef DEBUG
result = int result =
#endif #endif
XSendEvent(nxagentDisplay, XSendEvent(nxagentDisplay,
eventSelection.requestor, eventSelection.requestor,
...@@ -370,13 +577,14 @@ FIXME: Do we need this? ...@@ -370,13 +577,14 @@ FIXME: Do we need this?
(XEvent *) &eventSelection); (XEvent *) &eventSelection);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: XSendEvent() returned [%s]\n", __func__, GetXErrorString(result));
if (result == BadValue || result == BadWindow) if (result == BadValue || result == BadWindow)
{ {
fprintf(stderr, "nxagentRequestSelection: WARNING! XSendEvent failed.\n"); fprintf(stderr, "%s: WARNING! XSendEvent failed.\n", __func__);
} }
else else
{ {
fprintf(stderr, "nxagentRequestSelection: XSendEvent sent to window [0x%lx].\n", fprintf(stderr, "%s: XSendEvent sent to window [0x%lx].\n", __func__,
eventSelection.requestor); eventSelection.requestor);
} }
#endif #endif
...@@ -390,6 +598,7 @@ FIXME: Do we need this? ...@@ -390,6 +598,7 @@ FIXME: Do we need this?
nxagentLastRequestedSelection = X->xselectionrequest.selection; nxagentLastRequestedSelection = X->xselectionrequest.selection;
/* FIXME: shouldn't we reset i to 0 here first? */
while ((i < nxagentMaxSelections) && while ((i < nxagentMaxSelections) &&
(lastSelectionOwner[i].selection != X->xselectionrequest.selection)) (lastSelectionOwner[i].selection != X->xselectionrequest.selection))
{ {
...@@ -405,7 +614,7 @@ FIXME: Do we need this? ...@@ -405,7 +614,7 @@ FIXME: Do we need this?
serverWindow, lastClientTime); serverWindow, lastClientTime);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentRequestSelection: Sent XConvertSelection.\n"); fprintf(stderr, "%s: Sent XConvertSelection.\n", __func__);
#endif #endif
} }
else else
...@@ -459,13 +668,13 @@ FIXME: Do we need this? ...@@ -459,13 +668,13 @@ FIXME: Do we need this?
NullGrab); NullGrab);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentRequestSelection: Executed TryClientEvents with clientCutProperty.\n"); fprintf(stderr, "%s: Executed TryClientEvents with clientCutProperty.\n", __func__);
#endif #endif
} }
else else
{ {
/* /*
* Probably we must to send a Notify * Probably we must send a Notify
* to requestor with property None. * to requestor with property None.
*/ */
...@@ -479,7 +688,7 @@ FIXME: Do we need this? ...@@ -479,7 +688,7 @@ FIXME: Do we need this?
eventSelection.time = X->xselectionrequest.time; eventSelection.time = X->xselectionrequest.time;
#ifdef DEBUG #ifdef DEBUG
result = int result =
#endif #endif
XSendEvent(nxagentDisplay, XSendEvent(nxagentDisplay,
eventSelection.requestor, eventSelection.requestor,
...@@ -488,11 +697,21 @@ FIXME: Do we need this? ...@@ -488,11 +697,21 @@ FIXME: Do we need this?
(XEvent *) &eventSelection); (XEvent *) &eventSelection);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentRequestSelection: Executed XSendEvent with property None.\n"); fprintf(stderr, "%s: XSendEvent() returned [%s]\n", __func__, GetXErrorString(result));
if (result == BadValue || result == BadWindow)
{
fprintf(stderr, "%s: WARNING! XSendEvent failed.\n", __func__);
}
else
{
fprintf(stderr, "%s: XSendEvent with property None sent to window [0x%lx].\n", __func__,
eventSelection.requestor);
}
#endif #endif
} }
} }
} }
nxagentPrintClipboardStat("after nxagentRequestSelection");
} }
void nxagentSendSelectionNotify(Atom property) void nxagentSendSelectionNotify(Atom property)
...@@ -500,7 +719,7 @@ void nxagentSendSelectionNotify(Atom property) ...@@ -500,7 +719,7 @@ void nxagentSendSelectionNotify(Atom property)
xEvent x; xEvent x;
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentSendSelectionNotify: Sending event to client [%d].\n", fprintf (stderr, "%s: Sending event to client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
...@@ -527,14 +746,14 @@ void nxagentTransferSelection(int resource) ...@@ -527,14 +746,14 @@ void nxagentTransferSelection(int resource)
if (lastClientClientPtr -> index != resource) if (lastClientClientPtr -> index != resource)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentTransferSelection: WARNING! Inconsistent resource [%d] with current client [%d].\n", fprintf (stderr, "%s: WARNING! Inconsistent resource [%d] with current client [%d].\n", __func__,
resource, lastClientClientPtr -> index); resource, lastClientClientPtr -> index);
#endif #endif
nxagentSendSelectionNotify(None); nxagentSendSelectionNotify(None);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
return; return;
} }
...@@ -543,6 +762,7 @@ void nxagentTransferSelection(int resource) ...@@ -543,6 +762,7 @@ void nxagentTransferSelection(int resource)
{ {
case SelectionStageQuerySize: case SelectionStageQuerySize:
{ {
PrintClientSelectionStage();
/* /*
* Don't get data yet, just get size. We skip * Don't get data yet, just get size. We skip
* this stage in current implementation and * this stage in current implementation and
...@@ -554,7 +774,7 @@ void nxagentTransferSelection(int resource) ...@@ -554,7 +774,7 @@ void nxagentTransferSelection(int resource)
if (nxagentLastClipboardClient == -1) if (nxagentLastClipboardClient == -1)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentTransferSelection: WARNING! Asynchronous GetProperty queue full.\n"); fprintf(stderr, "%s: WARNING! Asynchronous GetProperty queue full.\n", __func__);
#endif #endif
result = -1; result = -1;
...@@ -574,35 +794,32 @@ void nxagentTransferSelection(int resource) ...@@ -574,35 +794,32 @@ void nxagentTransferSelection(int resource)
if (result == -1) if (result == -1)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentTransferSelection: Aborting selection notify procedure for client [%d].\n", fprintf (stderr, "%s: Aborting selection notify procedure for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
nxagentSendSelectionNotify(None); nxagentSendSelectionNotify(None);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
return; return;
} }
#ifdef DEBUG SetClientSelectionStage(WaitSize);
fprintf (stderr, "nxagentTransferSelection: Setting stage to [%d] for client [%d].\n",
SelectionStageWaitSize, lastClientClientPtr -> index);
#endif
lastClientStage = SelectionStageWaitSize;
break; break;
} }
case SelectionStageQueryData: case SelectionStageQueryData:
{ {
PrintClientSelectionStage();
/* /*
* Request the selection data now. * Request the selection data now.
*/ */
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentTransferSelection: Getting property content from remote server.\n"); fprintf(stderr, "%s: Getting property content from remote server.\n", __func__);
#endif #endif
nxagentLastClipboardClient = NXGetCollectPropertyResource(nxagentDisplay); nxagentLastClipboardClient = NXGetCollectPropertyResource(nxagentDisplay);
...@@ -610,7 +827,7 @@ void nxagentTransferSelection(int resource) ...@@ -610,7 +827,7 @@ void nxagentTransferSelection(int resource)
if (nxagentLastClipboardClient == -1) if (nxagentLastClipboardClient == -1)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentTransferSelection: WARNING! Asynchronous GetProperty queue full.\n"); fprintf(stderr, "%s: WARNING! Asynchronous GetProperty queue full.\n", __func__);
#endif #endif
result = -1; result = -1;
...@@ -630,32 +847,27 @@ void nxagentTransferSelection(int resource) ...@@ -630,32 +847,27 @@ void nxagentTransferSelection(int resource)
if (result == -1) if (result == -1)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentTransferSelection: Aborting selection notify procedure for client [%d].\n", fprintf (stderr, "%s: Aborting selection notify procedure for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
nxagentSendSelectionNotify(None); nxagentSendSelectionNotify(None);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
return; return;
} }
#ifdef DEBUG SetClientSelectionStage(WaitData);
fprintf (stderr, "nxagentTransferSelection: Setting stage to [%d] for client [%d].\n",
SelectionStageWaitData, lastClientClientPtr -> index);
#endif
lastClientStage = SelectionStageWaitData;
break; break;
} }
default: default:
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentTransferSelection: WARNING! Inconsistent state [%d] for client [%d].\n", fprintf (stderr, "%s: WARNING! Inconsistent state [%s] for client [%d].\n", __func__,
lastClientStage, lastClientClientPtr -> index); GetClientSelectionStageString(lastClientStage), lastClientClientPtr -> index);
#endif #endif
break; break;
...@@ -691,29 +903,23 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -691,29 +903,23 @@ void nxagentCollectPropertyEvent(int resource)
if (result == 0) if (result == 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentCollectPropertyEvent: Failed to get reply data for client [%d].\n", fprintf (stderr, "%s: Failed to get reply data for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
nxagentSendSelectionNotify(None); nxagentSendSelectionNotify(None);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
if (pszReturnData != NULL)
{
XFree(pszReturnData);
}
SAFE_XFree(pszReturnData);
return; return;
} }
if (resultFormat != 8 && resultFormat != 16 && resultFormat != 32) if (resultFormat != 8 && resultFormat != 16 && resultFormat != 32)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentCollectPropertyEvent: WARNING! Invalid property " fprintf (stderr, "%s: WARNING! Invalid property value.\n", __func__);
"value.\n");
#endif #endif
if (lastClientClientPtr != NULL) if (lastClientClientPtr != NULL)
...@@ -722,13 +928,9 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -722,13 +928,9 @@ void nxagentCollectPropertyEvent(int resource)
} }
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
if (pszReturnData != NULL)
{
XFree(pszReturnData);
}
SAFE_XFree(pszReturnData);
return; return;
} }
...@@ -736,33 +938,30 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -736,33 +938,30 @@ void nxagentCollectPropertyEvent(int resource)
{ {
case SelectionStageWaitSize: case SelectionStageWaitSize:
{ {
PrintClientSelectionStage();
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentCollectPropertyEvent: Got size notify event for client [%d].\n", fprintf (stderr, "%s: Got size notify event for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
if (ulReturnBytesLeft == 0) if (ulReturnBytesLeft == 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentCollectPropertyEvent: Aborting selection notify procedure for client [%d].\n", fprintf (stderr, "%s: Aborting selection notify procedure for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
nxagentSendSelectionNotify(None); nxagentSendSelectionNotify(None);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
if (pszReturnData != NULL)
{
XFree(pszReturnData);
}
SAFE_XFree(pszReturnData);
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentCollectPropertyEvent: Got property size from remote server.\n"); fprintf(stderr, "%s: Got property size from remote server.\n", __func__);
#endif #endif
/* /*
...@@ -770,7 +969,7 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -770,7 +969,7 @@ void nxagentCollectPropertyEvent(int resource)
*/ */
lastClientPropertySize = ulReturnBytesLeft; lastClientPropertySize = ulReturnBytesLeft;
lastClientStage = SelectionStageQueryData; SetClientSelectionStage(QueryData);
nxagentTransferSelection(resource); nxagentTransferSelection(resource);
...@@ -778,33 +977,30 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -778,33 +977,30 @@ void nxagentCollectPropertyEvent(int resource)
} }
case SelectionStageWaitData: case SelectionStageWaitData:
{ {
PrintClientSelectionStage();
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentCollectPropertyEvent: Got data notify event for client [%d].\n", fprintf (stderr, "%s: Got data notify event for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
if (ulReturnBytesLeft != 0) if (ulReturnBytesLeft != 0)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentCollectPropertyEvent: Aborting selection notify procedure for client [%d].\n", fprintf (stderr, "%s: Aborting selection notify procedure for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
nxagentSendSelectionNotify(None); nxagentSendSelectionNotify(None);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
if (pszReturnData != NULL)
{
XFree(pszReturnData);
}
SAFE_XFree(pszReturnData);
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentCollectPropertyEvent: Got property content from remote server.\n"); fprintf(stderr, "%s: Got property content from remote server.\n", __func__);
#endif #endif
ChangeWindowProperty(lastClientWindowPtr, ChangeWindowProperty(lastClientWindowPtr,
...@@ -814,7 +1010,7 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -814,7 +1010,7 @@ void nxagentCollectPropertyEvent(int resource)
ulReturnItems, pszReturnData, 1); ulReturnItems, pszReturnData, 1);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentCollectPropertyEvent: Selection property [%s] changed to [%s]\n", fprintf(stderr, "%s: Selection property [%s] changed to [%s]\n", __func__,
validateString(NameForAtom(lastClientProperty)), pszReturnData); validateString(NameForAtom(lastClientProperty)), pszReturnData);
#endif #endif
...@@ -825,33 +1021,30 @@ void nxagentCollectPropertyEvent(int resource) ...@@ -825,33 +1021,30 @@ void nxagentCollectPropertyEvent(int resource)
*/ */
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
break; break;
} }
default: default:
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "nxagentCollectPropertyEvent: WARNING! Inconsistent state [%d] for client [%d].\n", fprintf (stderr, "%s: WARNING! Inconsistent state [%s] for client [%d].\n", __func__,
lastClientStage, lastClientClientPtr -> index); GetClientSelectionStageString(lastClientStage), lastClientClientPtr -> index);
#endif #endif
break; break;
} }
} }
XFree(pszReturnData); SAFE_XFree(pszReturnData);
pszReturnData = NULL;
} }
void nxagentNotifySelection(XEvent *X) void nxagentNotifySelection(XEvent *X)
{ {
int result;
XSelectionEvent eventSelection; XSelectionEvent eventSelection;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentNotifySelection: Got called.\n"); fprintf(stderr, "%s: Got called.\n", __func__);
#endif #endif
if (agentClipboardStatus != 1) if (agentClipboardStatus != 1)
...@@ -860,15 +1053,17 @@ void nxagentNotifySelection(XEvent *X) ...@@ -860,15 +1053,17 @@ void nxagentNotifySelection(XEvent *X)
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentNotifySelection: SelectionNotify event.\n"); fprintf(stderr, "%s: SelectionNotify event.\n", __func__);
#endif #endif
PrintClientSelectionStage();
if (lastClientWindowPtr != NULL) if (lastClientWindowPtr != NULL)
{ {
if ((lastClientStage == SelectionStageNone) && (X->xselection.property == serverCutProperty)) if ((lastClientStage == SelectionStageNone) && (X->xselection.property == serverCutProperty))
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentNotifySelection: Starting selection transferral for client [%d].\n", fprintf(stderr, "%s: Starting selection transferral for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
...@@ -883,7 +1078,7 @@ void nxagentNotifySelection(XEvent *X) ...@@ -883,7 +1078,7 @@ void nxagentNotifySelection(XEvent *X)
* tions. * tions.
*/ */
lastClientStage = SelectionStageQueryData; SetClientSelectionStage(QueryData);
lastClientPropertySize = 262144; lastClientPropertySize = 262144;
nxagentTransferSelection(lastClientClientPtr -> index); nxagentTransferSelection(lastClientClientPtr -> index);
...@@ -891,14 +1086,14 @@ void nxagentNotifySelection(XEvent *X) ...@@ -891,14 +1086,14 @@ void nxagentNotifySelection(XEvent *X)
else else
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentNotifySelection: WARNING! Resetting selection transferral for client [%d].\n", fprintf(stderr, "%s: WARNING! Resetting selection transferral for client [%d].\n", __func__,
lastClientClientPtr -> index); lastClientClientPtr -> index);
#endif #endif
nxagentSendSelectionNotify(None); nxagentSendSelectionNotify(None);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
} }
return; return;
...@@ -924,28 +1119,18 @@ void nxagentNotifySelection(XEvent *X) ...@@ -924,28 +1119,18 @@ void nxagentNotifySelection(XEvent *X)
unsigned long ulReturnBytesLeft; unsigned long ulReturnBytesLeft;
unsigned char *pszReturnData = NULL; unsigned char *pszReturnData = NULL;
result = GetWindowProperty(lastSelectionOwner[i].windowPtr, clientCutProperty, 0, 0, False, int result = GetWindowProperty(lastSelectionOwner[i].windowPtr, clientCutProperty, 0, 0, False,
AnyPropertyType, &atomReturnType, &resultFormat, AnyPropertyType, &atomReturnType, &resultFormat,
&ulReturnItems, &ulReturnBytesLeft, &pszReturnData); &ulReturnItems, &ulReturnBytesLeft, &pszReturnData);
#ifdef DEBUG
fprintf(stderr, "%s: GetWindowProperty() returned [%s]\n", __func__, GetXErrorString(result));
#endif
if (result == BadAlloc || result == BadAtom || if (result == BadAlloc || result == BadAtom ||
result == BadMatch || result == BadValue || result == BadWindow || result == BadValue)
result == BadWindow)
{ {
fprintf (stderr, "Client GetProperty failed error ="); fprintf (stderr, "Client GetProperty failed. Error = %s", GetXErrorString(result));
lastServerProperty = None; lastServerProperty = None;
switch (result)
{
case BadAtom:
fprintf (stderr, "BadAtom\n");
break;
case BadValue:
fprintf (stderr, "BadValue\n");
break;
case BadWindow:
fprintf (stderr, "BadWindow\n");
break;
}
} }
else else
{ {
...@@ -953,13 +1138,14 @@ void nxagentNotifySelection(XEvent *X) ...@@ -953,13 +1138,14 @@ void nxagentNotifySelection(XEvent *X)
ulReturnBytesLeft, False, AnyPropertyType, &atomReturnType, ulReturnBytesLeft, False, AnyPropertyType, &atomReturnType,
&resultFormat, &ulReturnItems, &ulReturnBytesLeft, &resultFormat, &ulReturnItems, &ulReturnBytesLeft,
&pszReturnData); &pszReturnData);
#ifdef DEBUG
fprintf(stderr, "%s: GetWindowProperty() returned [%s]\n", __func__, GetXErrorString(result));
#endif
if (result == BadAlloc || result == BadAtom || if (result == BadAlloc || result == BadAtom ||
result == BadMatch || result == BadValue || result == BadWindow || result == BadValue)
result == BadWindow)
{ {
fprintf (stderr, "SelectionNotify - XChangeProperty failed\n"); fprintf (stderr, "SelectionNotify - XChangeProperty failed. Error = %s\n", GetXErrorString(result));
lastServerProperty = None; lastServerProperty = None;
} }
else else
...@@ -973,10 +1159,12 @@ void nxagentNotifySelection(XEvent *X) ...@@ -973,10 +1159,12 @@ void nxagentNotifySelection(XEvent *X)
pszReturnData, pszReturnData,
ulReturnItems); ulReturnItems);
} }
#ifdef DEBUG
fprintf(stderr, "%s: XChangeProperty() returned [%s]\n", __func__, GetXErrorString(result));
#endif
/* /*
* XFree(pszReturnData); * SAFE_XFree(pszReturnData);
* pszReturnData=NULL;
*/ */
} }
...@@ -1003,7 +1191,7 @@ void nxagentNotifySelection(XEvent *X) ...@@ -1003,7 +1191,7 @@ void nxagentNotifySelection(XEvent *X)
*/ */
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentNotifySelection: Sending event to requestor.\n"); fprintf(stderr, "%s: Sending event to requestor [%p].\n", __func__, (void *)eventSelection.requestor);
#endif #endif
result = XSendEvent(nxagentDisplay, result = XSendEvent(nxagentDisplay,
...@@ -1012,6 +1200,9 @@ void nxagentNotifySelection(XEvent *X) ...@@ -1012,6 +1200,9 @@ void nxagentNotifySelection(XEvent *X)
0L, 0L,
(XEvent *) &eventSelection); (XEvent *) &eventSelection);
#ifdef DEBUG
fprintf(stderr, "%s: XSendEvent() returned [%s]\n", __func__, GetXErrorString(result));
#endif
if (result == BadValue || result == BadWindow) if (result == BadValue || result == BadWindow)
{ {
fprintf (stderr, "SelectionRequest - XSendEvent failed\n"); fprintf (stderr, "SelectionRequest - XSendEvent failed\n");
...@@ -1035,7 +1226,7 @@ void nxagentResetSelectionOwner(void) ...@@ -1035,7 +1226,7 @@ void nxagentResetSelectionOwner(void)
if (lastServerRequestor != None) if (lastServerRequestor != None)
{ {
#ifdef TEST #ifdef TEST
fprintf (stderr, "nxagentResetSelectionOwner: WARNING! Requestor window [0x%lx] already found.\n", fprintf(stderr, "%s: WARNING! Requestor window [0x%x] already found.\n", __func__,
lastServerRequestor); lastServerRequestor);
#endif #endif
...@@ -1050,7 +1241,7 @@ void nxagentResetSelectionOwner(void) ...@@ -1050,7 +1241,7 @@ void nxagentResetSelectionOwner(void)
{ {
XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime); XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime);
fprintf (stderr, "nxagentResetSelectionOwner: Reset clipboard state.\n"); fprintf(stderr, "%s: Reset clipboard state.\n", __func__);
lastSelectionOwner[i].client = NULL; lastSelectionOwner[i].client = NULL;
lastSelectionOwner[i].window = None; lastSelectionOwner[i].window = None;
...@@ -1059,7 +1250,7 @@ void nxagentResetSelectionOwner(void) ...@@ -1059,7 +1250,7 @@ void nxagentResetSelectionOwner(void)
} }
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
lastServerRequestor = None; lastServerRequestor = None;
...@@ -1070,7 +1261,7 @@ void nxagentSetSelectionOwner(Selection *pSelection) ...@@ -1070,7 +1261,7 @@ void nxagentSetSelectionOwner(Selection *pSelection)
{ {
int i; int i;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSetSelectionOwner: Got called.\n"); fprintf(stderr, "%s: Got called.\n", __func__);
#endif #endif
if (agentClipboardStatus != 1) if (agentClipboardStatus != 1)
...@@ -1079,14 +1270,14 @@ void nxagentSetSelectionOwner(Selection *pSelection) ...@@ -1079,14 +1270,14 @@ void nxagentSetSelectionOwner(Selection *pSelection)
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSetSelectionOwner: Setting selection owner to window [0x%lx].\n", fprintf(stderr, "%s: Setting selection owner to window [0x%x].\n", __func__,
serverWindow); serverWindow);
#endif #endif
#ifdef TEST #ifdef TEST
if (lastServerRequestor != None) if (lastServerRequestor != None)
{ {
fprintf (stderr, "nxagentSetSelectionOwner: WARNING! Requestor window [0x%lx] already found.\n", fprintf (stderr, "%s: WARNING! Requestor window [0x%x] already found.\n", __func__,
lastServerRequestor); lastServerRequestor);
} }
#endif #endif
...@@ -1109,7 +1300,7 @@ void nxagentSetSelectionOwner(Selection *pSelection) ...@@ -1109,7 +1300,7 @@ void nxagentSetSelectionOwner(Selection *pSelection)
} }
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
lastServerRequestor = None; lastServerRequestor = None;
...@@ -1118,7 +1309,7 @@ FIXME ...@@ -1118,7 +1309,7 @@ FIXME
if (XGetSelectionOwner(nxagentDisplay,pSelection->selection)==serverWindow) if (XGetSelectionOwner(nxagentDisplay,pSelection->selection)==serverWindow)
{ {
fprintf (stderr, "NXdispatch: SetSelectionOwner OK\n"); fprintf (stderr, "%s: SetSelectionOwner OK\n", __func__);
lastSelectionOwnerSelection = pSelection; lastSelectionOwnerSelection = pSelection;
lastSelectionOwnerClient = pSelection->client; lastSelectionOwnerClient = pSelection->client;
...@@ -1126,11 +1317,11 @@ FIXME ...@@ -1126,11 +1317,11 @@ FIXME
lastSelectionOwnerWindowPtr = pSelection->pWin; lastSelectionOwnerWindowPtr = pSelection->pWin;
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
lastServerRequestor = None; lastServerRequestor = None;
} }
else fprintf (stderr, "nxagentSetSelectionOwner: SetSelectionOwner failed\n"); else fprintf (stderr, "%s: SetSelectionOwner failed\n", __func__);
*/ */
} }
...@@ -1146,7 +1337,7 @@ FIXME: Why this pointer can be not a valid ...@@ -1146,7 +1337,7 @@ FIXME: Why this pointer can be not a valid
if (clients[client -> index] != client) if (clients[client -> index] != client)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentNotifyConvertFailure: WARNING! Invalid client pointer."); fprintf(stderr, "%s: WARNING! Invalid client pointer.", __func__);
#endif #endif
return; return;
...@@ -1196,27 +1387,27 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1196,27 +1387,27 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
if (lastClientWindowPtr != NULL) if (lastClientWindowPtr != NULL)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentConvertSelection: lastClientWindowPtr != NULL.\n"); fprintf(stderr, "%s: lastClientWindowPtr != NULL.\n", __func__);
#endif #endif
if ((GetTimeInMillis() - lastClientReqTime) > 5000) if ((GetTimeInMillis() - lastClientReqTime) > 5000)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentConvertSelection: timeout expired on last request, " fprintf(stderr, "%s: timeout expired on last request, "
"notifying failure to client\n"); "notifying failure to client\n", __func__);
#endif #endif
nxagentNotifyConvertFailure(lastClientClientPtr, lastClientRequestor, nxagentNotifyConvertFailure(lastClientClientPtr, lastClientRequestor,
lastClientSelection, lastClientTarget, lastClientTime); lastClientSelection, lastClientTarget, lastClientTime);
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
} }
else else
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentConvertSelection: got request " fprintf(stderr, "%s: got request "
"before timeout expired on last request, notifying failure to client\n"); "before timeout expired on last request, notifying failure to client\n", __func__);
#endif #endif
nxagentNotifyConvertFailure(client, requestor, selection, target, time); nxagentNotifyConvertFailure(client, requestor, selection, target, time);
...@@ -1226,8 +1417,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1226,8 +1417,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentConvertSelection: client [%d] ask for sel [%s] " fprintf(stderr, "%s: client [%d] ask for sel [%s] "
"on window [%lx] prop [%s] target [%s].\n", "on window [%x] prop [%s] target [%s].\n", __func__,
client -> index, validateString(NameForAtom(selection)), requestor, client -> index, validateString(NameForAtom(selection)), requestor,
validateString(NameForAtom(property)), validateString(NameForAtom(target))); validateString(NameForAtom(property)), validateString(NameForAtom(target)));
#endif #endif
...@@ -1274,7 +1465,6 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1274,7 +1465,6 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
if (target == MakeAtom("TIMESTAMP", 9, 1)) if (target == MakeAtom("TIMESTAMP", 9, 1))
{ {
xEvent x;
int i = 0; int i = 0;
while ((i < NumCurrentSelections) && while ((i < NumCurrentSelections) &&
...@@ -1282,6 +1472,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1282,6 +1472,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
if (i < NumCurrentSelections) if (i < NumCurrentSelections)
{ {
xEvent x;
ChangeWindowProperty(pWin, ChangeWindowProperty(pWin,
property, property,
target, target,
...@@ -1316,8 +1507,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1316,8 +1507,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
*/ */
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentConvertSelection: Consecutives request from client [%p] selection [%ld] " fprintf(stderr, "%s: Consecutives request from client [%p] selection [%u] "
"elapsed time [%lu] clientAccum [%d]\n", (void *) client, selection, "elapsed time [%u] clientAccum [%d]\n", __func__, (void *) client, selection,
GetTimeInMillis() - lastClientReqTime, clientAccum); GetTimeInMillis() - lastClientReqTime, clientAccum);
#endif #endif
...@@ -1337,7 +1528,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1337,7 +1528,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
(target == clientUTF8_STRING)) (target == clientUTF8_STRING))
{ {
lastClientWindowPtr = pWin; lastClientWindowPtr = pWin;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
lastClientRequestor = requestor; lastClientRequestor = requestor;
lastClientClientPtr = client; lastClientClientPtr = client;
lastClientTime = time; lastClientTime = time;
...@@ -1365,7 +1556,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1365,7 +1556,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentConvertSelection: Sent XConvertSelection with target=[%s], property [%s]\n", fprintf(stderr, "%s: Sent XConvertSelection with target=[%s], property [%s]\n", __func__,
validateString(NameForAtom(target)), validateString(NameForAtom(property))); validateString(NameForAtom(target)), validateString(NameForAtom(property)));
#endif #endif
...@@ -1376,8 +1567,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1376,8 +1567,8 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
xEvent x; xEvent x;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentConvertSelection: Xserver generates a SelectionNotify event " fprintf(stderr, "%s: Xserver generates a SelectionNotify event "
"to the requestor with property None.\n"); "to the requestor with property None.\n", __func__);
#endif #endif
memset(&x, 0, sizeof(xEvent)); memset(&x, 0, sizeof(xEvent));
...@@ -1396,14 +1587,21 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection, ...@@ -1396,14 +1587,21 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
int nxagentSendNotify(xEvent *event) int nxagentSendNotify(xEvent *event)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSendNotify: Got called.\n"); fprintf(stderr, "%s: Got called.\n", __func__);
#endif #endif
if (agentClipboardStatus != 1) if (agentClipboardStatus != 1)
{ {
#ifdef DEBUG
fprintf(stderr, "%s: agentClipboardStatus != 1 - doing nothing.\n", __func__);
#endif
return 0; return 0;
} }
#ifdef DEBUG
fprintf(stderr, "%s: property is [%d][%s].\n", __func__, event->u.selectionNotify.property, NameForAtom(event->u.selectionNotify.property));
#endif
if (event->u.selectionNotify.property == clientCutProperty) if (event->u.selectionNotify.property == clientCutProperty)
{ {
XSelectionEvent x; XSelectionEvent x;
...@@ -1438,20 +1636,25 @@ int nxagentSendNotify(xEvent *event) ...@@ -1438,20 +1636,25 @@ int nxagentSendNotify(xEvent *event)
x.time = CurrentTime; x.time = CurrentTime;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSendNotify: Propagating clientCutProperty.\n"); fprintf(stderr, "%s: Propagating clientCutProperty to requestor [%p].\n", __func__, (void *)x.requestor);
#endif #endif
result = XSendEvent (nxagentDisplay, x.requestor, False, result = XSendEvent (nxagentDisplay, x.requestor, False,
0L, (XEvent *) &x); 0L, (XEvent *) &x);
#ifdef DEBUG
fprintf(stderr, "%s: XSendEvent() returned [%s]\n", __func__, GetXErrorString(result));
#endif
if (result == BadValue || result == BadWindow) if (result == BadValue || result == BadWindow)
{ {
fprintf (stderr, "nxagentSendNotify: XSendEvent failed.\n"); fprintf (stderr, "%s: XSendEvent failed.\n", __func__);
} }
return 1; return 1;
} }
#ifdef DEBUG
fprintf(stderr, "%s: sent nothing.\n", __func__);
#endif
return 0; return 0;
} }
...@@ -1460,7 +1663,7 @@ WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin) ...@@ -1460,7 +1663,7 @@ WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin)
int i = 0; int i = 0;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentGetClipboardWindow: Got called.\n"); fprintf(stderr, "%s: Got called, property [%d][%s] window [%p].\n", __func__, property, NameForAtom(property), (void *)pWin);
#endif #endif
while ((i < nxagentMaxSelections) && while ((i < nxagentMaxSelections) &&
...@@ -1473,7 +1676,7 @@ WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin) ...@@ -1473,7 +1676,7 @@ WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin)
(lastSelectionOwner[i].windowPtr != NULL)) (lastSelectionOwner[i].windowPtr != NULL))
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentGetClipboardWindow: Returning last clipboard owner window.\n"); fprintf(stderr, "%s: Returning last clipboard owner window [%p].\n", __func__, (void *)lastSelectionOwner[i].windowPtr);
#endif #endif
return lastSelectionOwner[i].windowPtr; return lastSelectionOwner[i].windowPtr;
...@@ -1481,7 +1684,7 @@ WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin) ...@@ -1481,7 +1684,7 @@ WindowPtr nxagentGetClipboardWindow(Atom property, WindowPtr pWin)
else else
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentGetClipboardWindow: Returning original target window.\n"); fprintf(stderr, "%s: Returning original target window [%p].\n", __func__, (void *)pWin);
#endif #endif
return pWin; return pWin;
...@@ -1495,13 +1698,13 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1495,13 +1698,13 @@ int nxagentInitClipboard(WindowPtr pWin)
Window iWindow = nxagentWindow(pWin); Window iWindow = nxagentWindow(pWin);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentInitClipboard: Got called.\n"); fprintf(stderr, "%s: Got called.\n", __func__);
#endif #endif
free(lastSelectionOwner); free(lastSelectionOwner);
lastSelectionOwner = NULL; lastSelectionOwner = NULL;
lastSelectionOwner = (SelectionOwner *) malloc(2 * sizeof(SelectionOwner)); lastSelectionOwner = (SelectionOwner *) malloc(nxagentMaxSelections * sizeof(SelectionOwner));
if (lastSelectionOwner == NULL) if (lastSelectionOwner == NULL)
{ {
...@@ -1527,7 +1730,7 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1527,7 +1730,7 @@ int nxagentInitClipboard(WindowPtr pWin)
{ {
extern unsigned long startTime; extern unsigned long startTime;
fprintf(stderr, "nxagentInitClipboard: Initializing start [%d] milliseconds.\n", fprintf(stderr, "%s: Initializing start [%d] milliseconds.\n", __func__,
GetTimeInMillis() - startTime); GetTimeInMillis() - startTime);
} }
#endif #endif
...@@ -1547,14 +1750,14 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1547,14 +1750,14 @@ int nxagentInitClipboard(WindowPtr pWin)
if (serverCutProperty == None) if (serverCutProperty == None)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentInitClipboard: PANIC! Could not create NX_CUT_BUFFER_SERVER atom\n"); fprintf(stderr, "%s: PANIC! Could not create NX_CUT_BUFFER_SERVER atom\n", __func__);
#endif #endif
return -1; return -1;
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentInitClipboard: Setting owner of selection [%s][%d] on window 0x%lx\n", 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, iWindow);
#endif #endif
...@@ -1568,11 +1771,10 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1568,11 +1771,10 @@ int nxagentInitClipboard(WindowPtr pWin)
{ {
ErrorF("Unable to initialize XFixes extension.\n"); ErrorF("Unable to initialize XFixes extension.\n");
} }
else else
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentInitClipboard: Registering for XFixesSelectionNotify events.\n"); fprintf(stderr, "%s: Registering for XFixesSelectionNotify events.\n", __func__);
#endif #endif
for (i = 0; i < nxagentMaxSelections; i++) for (i = 0; i < nxagentMaxSelections; i++)
...@@ -1598,8 +1800,8 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1598,8 +1800,8 @@ int nxagentInitClipboard(WindowPtr pWin)
if (nxagentSessionId[0]) if (nxagentSessionId[0])
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentInitClipboard: setting the ownership of %s to %lx" fprintf(stderr, "%s: setting the ownership of %s to %lx"
" and registering for PropertyChangeMask events\n", " and registering for PropertyChangeMask events\n", __func__,
validateString(XGetAtomName(nxagentDisplay, nxagentAtoms[10])), iWindow); validateString(XGetAtomName(nxagentDisplay, nxagentAtoms[10])), iWindow);
#endif #endif
...@@ -1631,7 +1833,7 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1631,7 +1833,7 @@ int nxagentInitClipboard(WindowPtr pWin)
lastServerRequestor = None; lastServerRequestor = None;
lastClientWindowPtr = NULL; lastClientWindowPtr = NULL;
lastClientStage = SelectionStageNone; SetClientSelectionStage(None);
lastClientReqTime = GetTimeInMillis(); lastClientReqTime = GetTimeInMillis();
clientCutProperty = MakeAtom(szAgentNX_CUT_BUFFER_CLIENT, clientCutProperty = MakeAtom(szAgentNX_CUT_BUFFER_CLIENT,
...@@ -1644,8 +1846,8 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1644,8 +1846,8 @@ int nxagentInitClipboard(WindowPtr pWin)
if (clientCutProperty == None) if (clientCutProperty == None)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentInitClipboard: PANIC! " fprintf(stderr, "%s: PANIC! "
"Could not create NX_CUT_BUFFER_CLIENT atom.\n"); "Could not create NX_CUT_BUFFER_CLIENT atom.\n", __func__);
#endif #endif
return -1; return -1;
...@@ -1655,18 +1857,17 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1655,18 +1857,17 @@ int nxagentInitClipboard(WindowPtr pWin)
agentClipboardStatus = 1; agentClipboardStatus = 1;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentInitClipboard: Clipboard initialization completed.\n"); fprintf(stderr, "%s: Clipboard initialization completed.\n", __func__);
#endif #endif
#ifdef NXAGENT_TIMESTAMP #ifdef NXAGENT_TIMESTAMP
{ {
extern unsigned long startTime; extern unsigned long startTime;
fprintf(stderr, "nxagentInitClipboard: initializing ends [%d] milliseconds.\n", fprintf(stderr, "%s: initializing ends [%d] milliseconds.\n", __func__,
GetTimeInMillis() - startTime); GetTimeInMillis() - startTime);
} }
#endif #endif
return 1; return 1;
} }
...@@ -88,6 +88,11 @@ typedef struct ...@@ -88,6 +88,11 @@ typedef struct
nxagentWMStateRec; nxagentWMStateRec;
#endif #endif
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
int int
ProcChangeProperty(ClientPtr client) ProcChangeProperty(ClientPtr client)
{ {
...@@ -563,15 +568,25 @@ GetWindowProperty(pWin, property, longOffset, longLength, delete, ...@@ -563,15 +568,25 @@ GetWindowProperty(pWin, property, longOffset, longLength, delete,
unsigned long n, len, ind; unsigned long n, len, ind;
if (!pWin) if (!pWin)
{
#ifdef DEBUG
fprintf(stderr, "%s: invalid window\n", __func__);
#endif
return BadWindow; return BadWindow;
}
if (!ValidAtom(property)) if (!ValidAtom(property))
{ {
#ifdef DEBUG
fprintf(stderr, "%s: invalid atom [%d]\n", __func__, property);
#endif
return(BadAtom); return(BadAtom);
} }
if ((type != AnyPropertyType) && !ValidAtom(type)) if ((type != AnyPropertyType) && !ValidAtom(type))
{ {
#ifdef DEBUG
fprintf(stderr, "%s: invalid type [%d]\n", __func__, type);
#endif
return(BadAtom); return(BadAtom);
} }
...@@ -588,7 +603,12 @@ GetWindowProperty(pWin, property, longOffset, longLength, delete, ...@@ -588,7 +603,12 @@ GetWindowProperty(pWin, property, longOffset, longLength, delete,
if (!pProp) if (!pProp)
{
#ifdef DEBUG
fprintf(stderr, "%s: property not found [%d]\n", __func__, property);
#endif
return (BadAtom); return (BadAtom);
}
/* If the request type and actual type don't match. Return the /* If the request type and actual type don't match. Return the
property information, but not the data. */ property information, but not the data. */
...@@ -615,6 +635,9 @@ GetWindowProperty(pWin, property, longOffset, longLength, delete, ...@@ -615,6 +635,9 @@ GetWindowProperty(pWin, property, longOffset, longLength, delete,
if (n < ind) if (n < ind)
{ {
#ifdef DEBUG
fprintf(stderr, "%s: negative property len\n", __func__);
#endif
return BadValue; return BadValue;
} }
......
...@@ -44,4 +44,6 @@ static inline const char * validateString(const char *str) { ...@@ -44,4 +44,6 @@ static inline const char * validateString(const char *str) {
return str ? str : "(null)"; return str ? str : "(null)";
} }
#define SAFE_XFree(what) do {if (what) {XFree(what); what = NULL;}} while (0)
#endif /* __Utils_H__ */ #endif /* __Utils_H__ */
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