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

Clipboard.c: Fix: re-claim selection on reconnect

On reconnect claim the selection ownership if one of nxagent's clients is a selection owner. The code for this was already there but could not work because the lastSelectionOwner array was always dropped at the beginning of nxagentInitClipboard.
parent 8500b4bc
......@@ -2127,19 +2127,26 @@ Bool nxagentInitClipboard(WindowPtr pWin)
fprintf(stderr, "%s: Got called.\n", __func__);
#endif
SAFE_free(lastSelectionOwner);
if (!nxagentReconnectTrap)
{
SAFE_free(lastSelectionOwner);
lastSelectionOwner = (SelectionOwner *) malloc(nxagentMaxSelections * sizeof(SelectionOwner));
lastSelectionOwner = (SelectionOwner *) malloc(nxagentMaxSelections * sizeof(SelectionOwner));
if (lastSelectionOwner == NULL)
if (lastSelectionOwner == NULL)
{
FatalError("nxagentInitClipboard: Failed to allocate memory for the clipboard selections.\n");
}
nxagentInitSelectionOwner(nxagentPrimarySelection, XA_PRIMARY);
nxagentInitSelectionOwner(nxagentClipboardSelection, nxagentAtoms[10]); /* CLIPBOARD */
}
else
{
FatalError("nxagentInitClipboard: Failed to allocate memory for the clipboard selections.\n");
/* the clipboard selection atom might have changed on the new X
server. Primary is constant. */
lastSelectionOwner[nxagentClipboardSelection].selection = nxagentAtoms[10]; /* CLIPBOARD */
}
nxagentInitSelectionOwner(nxagentPrimarySelection, XA_PRIMARY);
nxagentInitSelectionOwner(nxagentClipboardSelection, nxagentAtoms[10]); /* CLIPBOARD */
#ifdef NXAGENT_TIMESTAMP
{
fprintf(stderr, "%s: Initializing start [%ld] milliseconds.\n", __func__,
......@@ -2229,22 +2236,23 @@ Bool nxagentInitClipboard(WindowPtr pWin)
if (nxagentReconnectTrap)
{
/*
* Only for PRIMARY and CLIPBOARD selections.
*/
for (int i = 0; i < nxagentMaxSelections; i++)
if (nxagentOption(Clipboard) == ClipboardServer ||
nxagentOption(Clipboard) == ClipboardBoth)
{
/*
* if we have a selection inform the (new) real Xserver and
* claim the ownership. Note that we report our serverWindow as
* owner, not the real window!
*/
if (lastSelectionOwner[i].client && lastSelectionOwner[i].window)
for (int i = 0; i < nxagentMaxSelections; i++)
{
XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime);
/*
* if we have a selection inform the (new) real Xserver and
* claim the ownership. Note that we report our serverWindow as
* owner, not the real window!
*/
if (lastSelectionOwner[i].client && lastSelectionOwner[i].window)
{
XSetSelectionOwner(nxagentDisplay, lastSelectionOwner[i].selection, serverWindow, CurrentTime);
}
}
}
/* FIXME: Shouldn't we reset lastServer* and lastClient* here? */
}
else
{
......
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