draganddrop.cpp revision 7404edd3ce48b26f2a8943eb24e922d3017c0710
/** @file
* X11 guest client - Drag and Drop.
*/
/*
* Copyright (C) 2011-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifdef VBOX_DND_WITH_XTEST
#endif
#include <iprt/critsect.h>
#include <limits.h>
# ifdef LOG_GROUP
# endif
#define LOG_GROUP LOG_GROUP_GUEST_DND
#include <VBox/VBoxGuestLib.h>
#include "VBox/HostServices/DragAndDropSvc.h"
#include "VBoxClient.h"
/* Enable this define to see the proxy window(s) when debugging
* their behavior. Don't have this enabled in release builds! */
#ifdef DEBUG
//# define VBOX_DND_DEBUG_WND
#endif
/* For X11 guest xDnD is used. See http://www.acc.umu.se/~vatten/XDND.html for
* a walk trough.
*
* H->G:
* For X11 this means mainly forwarding all the events from HGCM to the
* appropriate X11 events. There exists a proxy window, which is invisible and
* used for all the X11 communication. On a HGCM Enter event, we set our proxy
* window as XdndSelection owner with the given mime-types. On every HGCM move
* event, we move the X11 mouse cursor to the new position and query for the
* window below that position. Depending on if it is XdndAware, a new window or
* a known window, we send the appropriate X11 messages to it. On HGCM drop, we
* send a XdndDrop message to the current window and wait for a X11
* SelectionMessage from the target window. Because we didn't have the data in
* the requested mime-type, yet, we save that message and ask the host for the
* data. When the data is successfully received from the host, we put the data
* as a property to the window and send a X11 SelectionNotify event to the
* target window.
*
* G->H:
* This is a lot more trickery than H->G. When a pending event from HGCM
* arrives, we ask if there currently is an owner of the XdndSelection
* property. If so, our proxy window is shown (1x1, but without backing store)
* and some mouse event is triggered. This should be followed by an XdndEnter
* event send to the proxy window. From this event we can fetch the necessary
* info of the MIME types and allowed actions and send this back to the host.
* On a drop request from the host, we query for the selection and should get
* the data in the specified mime-type. This data is send back to the host.
* After that we send a XdndLeave event to the source window.
*
* To-do:
* - Cancelling (e.g. with ESC key) doesn't work.
*
* To-do:
* - INCR (incremental transfers) support.
* - Make this much more robust for crashes of the other party.
* - Really check for the Xdnd version and the supported features.
*/
#define VBOX_XDND_VERSION (4)
/* Shared struct used for adding new X11 events and HGCM messages to a single
* event queue. */
struct DnDEvent
{
enum DnDEventType
{
HGCM_Type = 1,
};
union
{
};
};
enum XA_Type
{
/* States */
XA_WM_STATE = 0,
/* Properties */
/* Mime Types */
/* xDnD */
/* Our own stop marker */
/* End marker */
};
class DragAndDropService;
/*******************************************************************************
*
* xHelpers Declaration
*
******************************************************************************/
class xHelpers
{
public:
{
if (!m_pInstance)
{
}
return m_pInstance;
}
{
}
{
return strAtom;
}
{
return format;
}
private:
{
/* Not all x11 atoms we use are defined in the headers. Create the
* additional one we need here. */
for (int i = 0; i < XA_End; ++i)
};
/* Private member vars */
static xHelpers *m_pInstance;
static const char *m_xAtomNames[XA_End];
};
/* Some xHelpers convenience defines. */
/*******************************************************************************
*
* xHelpers Implementation
*
******************************************************************************/
/* Has to be in sync with the XA_Type enum. */
const char *xHelpers::m_xAtomNames[] =
{
/* States */
"WM_STATE",
/* Properties */
"TARGETS",
"MULTIPLE",
"INCR",
/* Mime Types */
"TEXT",
/* xDnD */
"XdndSelection",
"XdndAware",
"XdndEnter",
"XdndLeave",
"XdndTypeList",
"XdndActionList",
"XdndPosition",
"XdndActionCopy",
"XdndActionMove",
"XdndActionLink",
"XdndStatus",
"XdndDrop",
"XdndFinished",
/* Our own stop marker */
"dndstop"
};
{
switch (xrc)
{
}
}
/* Todo: make this iterative */
{
/* No parent, nothing to do. */
if(wndParent == 0)
return 0;
int cProps = -1;
/* Fetch all x11 window properties of the parent window. */
if (cProps > 0)
{
/* We check the window for the WM_STATE property. */
for (int i = 0; i < cProps; ++i)
{
/* Found it. */
break;
}
/* Cleanup */
}
if (!wndApp)
{
int tmp;
unsigned int utmp;
/* Query the next child window of the parent window at the current
* mouse position. */
/* Recursive call our self to dive into the child tree. */
}
return wndApp;
}
/*******************************************************************************
*
* DragInstance Declaration
*
******************************************************************************/
/* For now only one DragInstance will exits when the app is running. In the
* future the support for having more than one D&D operation supported at the
* time will be necessary. */
class DragInstance
{
public:
enum State
{
Uninitialized = 0,
};
enum Mode
{
Unknown = 0,
HG,
};
public:
void uninit(void);
void reset(void);
/* X11 message processing. */
int onX11ClientMessage(const XEvent &e);
int onX11SelectionNotify(const XEvent &e);
int onX11SelectionRequest(const XEvent &e);
int onX11Event(const XEvent &e);
/* H->G */
int hgDrop();
#ifdef VBOX_WITH_DRAG_AND_DROP_GH
/* G->H */
int ghIsDnDPending();
#endif
/* X11 helpers. */
int proxyWinHide(void);
void registerForEvents(Window w) const;
protected:
int m_screenId;
long m_curVer;
/** Deferred host to guest selection event for sending to the
* target window as soon as data from the host arrived. */
/** Current operation mode. */
/** Current state of operation mode. */
/** The instance's own X event queue. */
/** Critical section for providing serialized access to list
* event queue's contents. */
/** Event for notifying this instance in case of a new
* event. */
};
/*******************************************************************************
*
* DragAndDropService Declaration
*
******************************************************************************/
{
public:
DragAndDropService(void)
: m_pDisplay(0)
, m_pCurDnD(0)
, m_fSrvStopping(false)
{}
virtual const char *getPidFilePath() { return ".vboxclient-draganddrop.pid"; }
virtual int run(bool fDaemonised = false);
virtual void cleanup(void)
{
/* Nothing to do, everything should be cleaned up automatically when the
};
private:
int x11DragAndDropInit(void);
void clearEventQueue();
/* Usually XCheckMaskEvent could be used for querying selected x11 events.
* Unfortunately this doesn't work exactly with the events we need. So we
* use this predicate method below and XCheckIfEvent. */
{
if (!pEvent)
return false;
// || ( pEvent->type == ClientMessage
// && reinterpret_cast<XClientMessageEvent*>(pEvent)->window == reinterpret_cast<Window>(pUser))
// || ( pEvent->type == SelectionRequest
// && reinterpret_cast<XSelectionRequestEvent*>(pEvent)->requestor == reinterpret_cast<Window>(pUser)))
return true;
return false;
}
/* Private member vars */
/** Our (thread-safe) event queue with
* mixed events (DnD HGCM / X11). */
/** Critical section for providing serialized access to list
* event queue's contents. */
bool m_fSrvStopping;
friend class DragInstance;
};
/*******************************************************************************
*
* DragInstanc Implementation
*
******************************************************************************/
: m_uClientID(0)
, m_pScreen(0)
, m_wndRoot(0)
, m_wndProxy(0)
, m_wndCur(0)
, m_curVer(-1)
{
uninit();
}
void DragInstance::uninit(void)
{
reset();
if (m_wndProxy != 0)
if (m_uClientID)
{
m_uClientID = 0;
}
m_screenId = -1;
m_pScreen = 0;
m_wndRoot = 0;
m_wndProxy = 0;
}
void DragInstance::reset(void)
{
/* Hide the proxy win. */
proxyWinHide();
/* If we are currently the Xdnd selection owner, clear that. */
if (w == m_wndProxy)
/* Clear any other DnD specific data on the proxy win. */
/* Reset the internal state. */
m_wndCur = 0;
m_curVer = -1;
}
/* Uri's */
/* Text */
<< "UTF8_STRING"
<< "TEXT"
<< "STRING"
/* OpenOffice formates */
<< "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\""
<< "application/x-openoffice-drawing;windows_formatname=\"Drawing Format\"";
{
int rc;
do
{
uninit();
if (RT_FAILURE(rc))
break;
if (RT_FAILURE(rc))
break;
if (RT_FAILURE(rc))
break;
/*
* Enough screens configured in the x11 server?
*/
{
break;
}
/* Get the screen number from the x11 server. */
// pDrag->screen = ScreenOfDisplay(m_pDisplay, u32ScreenId);
// if (!pDrag->screen)
// {
// rc = VERR_GENERAL_FAILURE;
// break;
// }
/* Now query the corresponding root window of this screen. */
if (!m_wndRoot)
{
break;
}
/*
* Create an invisible window which will act as proxy for the DnD
* operation. This window will be used for both the GH and HG
* direction.
*/
#ifdef VBOX_DND_DEBUG_WND
#endif
0, 0, /* Position */
1, 1, /* Width + height */
0, /* Border width */
CopyFromParent, /* Depth */
InputOnly, /* Class */
CopyFromParent, /* Visual */
&attr /* Attributes for value mask */);
if (!m_wndProxy)
{
break;
}
LogFlowThisFunc(("Created proxy window 0x%x at m_wndRoot=0x%x ...\n",
m_wndProxy, m_wndRoot));
/* Set the window's name for easier lookup. */
/* Make the new window Xdnd aware. */
reinterpret_cast<unsigned char*>(&ver), 1);
} while (0);
if (RT_SUCCESS(rc))
{
}
else
LogRel(("DnD: Initializing drag instance for screen %RU32 failed with rc=%Rrc\n",
u32ScreenId, rc));
return rc;
}
{
LogFlowThisFunc(("Event wnd=%#x, msg=%s\n",
int rc;
switch (m_mode)
{
case HG:
{
/* Client messages are used to inform us about the status of a XdndAware
* window, in response of some events we send to them. */
{
/* The XdndStatus message tell us if the window will accept the DnD
* event and with which action. We immediately send this info down to
* the host as a response of a previous DnD message. */
LogFlowThisFunc(("XA_XdndStatus wnd=%#x, accept=%RTbool, action=%s\n",
/** @todo Compare this with the allowed actions. */
}
{
rc = VINF_SUCCESS;
/* This message is send on a un/successful DnD drop request. */
LogFlowThisFunc(("XA_XdndFinished: wnd=%#x, success=%RTbool, action=%s\n",
reset();
}
else
{
LogFlowThisFunc(("Unhandled: wnd=%#x, msg=%s\n",
}
break;
}
case GH:
{
LogFlowThisFunc(("Enqueuing ClientMessage\n"));
m_eventQueue.append(e);
break;
}
default:
{
LogFlowThisFunc(("Unhandled: wnd=%#x, msg=%s\n",
break;
}
}
return rc;
}
{
int rc = VINF_SUCCESS;
switch (m_mode)
{
case GH:
{
{
LogFlowThisFunc(("Enqueuing SelectionNotify\n"));
m_eventQueue.append(e);
}
break;
}
default:
{
LogFlowThisFunc(("Unhandled: wnd=%#x, msg=%s\n",
break;
}
}
return rc;
}
{
LogFlowThisFunc(("Event owner=%#x, requestor=%#x, selection=%s, target=%s, prop=%s, time=%u\n",
e.xselectionrequest.time));
int rc;
switch (m_mode)
{
case HG:
{
rc = VINF_SUCCESS;
/*
* A window is asking for some data. Normally here the data would be copied
* into the selection buffer and send to the requestor. Obviously we can't
* do that, because we first need to ask the host for the data of the
* requested MIME type. This is done and later answered with the correct
* data -- see DragInstance::hgDataReceived().
*/
/* Is the requestor asking for the possible MIME types? */
{
/* If so, set the window property with the formats on the requestor
* window. */
XEvent s;
RT_ZERO(s);
if (RT_UNLIKELY(xrc == 0))
LogFlowThisFunc(("Error sending SelectionNotify event to wnd=%#x\n", e.xselectionrequest.requestor));
}
/* Is the requestor asking for a specific MIME type (we support)? */
{
LogFlowThisFunc(("wnd=%#x asking for data, format=%s\n",
/* If so, we need to inform the host about this request. Save the
* selection request event for later use. */
// || m_curWin != e.xselectionrequest.requestor)
{
LogFlowThisFunc(("Wrong state, refusing request\n"));
XEvent s;
RT_ZERO(s);
if (RT_UNLIKELY(xrc == 0))
LogFlowThisFunc(("Error sending SelectionNotify event to wnd=%#x\n", e.xselectionrequest.requestor));
}
else
{
LogFlowThisFunc(("Saving selection notify message\n"));
LogFlowThisFunc(("Requesting data from host as \"%s\", rc=%Rrc\n",
}
}
/* Anything else. */
else
{
LogFlowThisFunc(("Refusing unknown command\n"));
/* We don't understand this request message and therefore answer with an
* refusal messages. */
XEvent s;
RT_ZERO(s);
if (RT_UNLIKELY(xrc == 0))
LogFlowThisFunc(("Error sending SelectionNotify event to wnd=%#x\n", e.xselectionrequest.requestor));
}
break;
}
default:
{
LogFlowThisFunc(("Unhandled: wnd=%#x, msg=%s\n",
break;
}
}
return rc;
}
{
int rc;
switch (e.type)
{
case ButtonPress:
LogFlowThisFunc(("ButtonPress\n"));
rc = VINF_SUCCESS;
break;
case ButtonRelease:
LogFlowThisFunc(("ButtonRelease\n"));
rc = VINF_SUCCESS;
break;
case ClientMessage:
rc = onX11ClientMessage(e);
break;
case SelectionClear:
LogFlowThisFunc(("SelectionClear\n"));
reset();
rc = VINF_SUCCESS;
break;
case SelectionNotify:
rc = onX11SelectionNotify(e);
break;
case SelectionRequest:
rc = onX11SelectionRequest(e);
break;
/*case MotionNotify:
hide();
break;*/
default:
break;
}
return rc;
}
#ifdef VBOX_WITH_DRAG_AND_DROP_GH
{
LogFlowThisFunc(("iType=%d, uTimeoutMS=%RU32, cEventQueue=%zu\n",
bool fFound = false;
do
{
/* Check if there is a client message in the queue. */
{
if (RT_SUCCESS(rc2))
{
if (fFound)
{
m_eventQueue.removeAt(i);
evX = e;
}
if (fFound)
break;
}
}
if (fFound)
break;
if ( RT_FAILURE(rc2)
&& rc2 != VERR_TIMEOUT)
{
break;
}
}
LogFlowThisFunc(("Returning fFound=%RTbool, msRuntime=%RU64\n",
return fFound;
}
{
LogFlowThisFunc(("aType=%s, uTimeoutMS=%RU32, cEventQueue=%zu\n",
bool fFound = false;
do
{
/* Check if there is a client message in the queue. */
{
if (RT_SUCCESS(rc2))
{
if (e.type == ClientMessage)
{
m_eventQueue.removeAt(i);
fFound = true;
}
if (fFound)
break;
}
}
if (fFound)
break;
if ( RT_FAILURE(rc2)
&& rc2 != VERR_TIMEOUT)
{
break;
}
}
LogFlowThisFunc(("Returning fFound=%RTbool, msRuntime=%RU64\n",
return fFound;
}
#endif /* VBOX_WITH_DRAG_AND_DROP_GH */
/*
* Host -> Guest
*/
{
reset();
#ifdef DEBUG
LogFlow(("\n"));
#endif
/* If we have more than 3 formats we have to use the type list extension. */
/* Announce the possible actions */
/* Set the DnD selection owner to our window. */
return VINF_SUCCESS;
}
{
LogFlowThisFunc(("u32xPos=%RU32, u32yPos=%RU32, uAction=%RU32\n",
return VERR_INVALID_STATE;
int rc = VINF_SUCCESS;
/* Move the mouse cursor within the guest. */
/* Search for the application window below the cursor. */
{
/* Temp stuff for the XGetWindowProperty call. */
int fmt;
unsigned long cItems, cbRemaining;
/* Query the XdndAware property from the window. We are interested in
* the version and if it is XdndAware at all. */
else
{
else
{
}
}
}
/*
* Is the window under the cursor another one than our current one?
*/
&& m_curVer != -1)
{
/* We left the current XdndAware window. Announce this to the window. */
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.format = 32;
m.data.l[0] = m_wndProxy;
if (RT_UNLIKELY(xrc == 0))
}
/*
* Do we have a new window which now is under the cursor?
*/
{
/*
* We enter a new window. Announce the XdndEnter event to the new
* window. The first three mime types are attached to the event (the
* others could be requested by the XdndTypeList property from the
* window itself).
*/
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.format = 32;
m.data.l[0] = m_wndProxy;
m.data.l[1] = RT_MAKE_U32_FROM_U8(m_formats.size() > 3 ? 1 : 0, 0, 0, RT_MIN(VBOX_XDND_VERSION, newVer));
if (RT_UNLIKELY(xrc == 0))
}
if (newVer != -1)
{
LogFlowThisFunc(("Moving window=%#x, xPos=%RU32, yPos=%RU32\n",
/*
* Send a XdndPosition event with the proposed action to the guest.
*/
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.format = 32;
m.data.l[0] = m_wndProxy;
if (RT_UNLIKELY(xrc == 0))
}
&& newVer == -1)
{
/* No window to process, so send a ignore ack event to the host. */
}
return rc;
}
int DragInstance::hgDrop(void)
{
LogFlowThisFunc(("wndCur=%#x, mMode=%RU32, mState=%RU32\n",
return VERR_INVALID_STATE;
int rc = VINF_SUCCESS;
/* Send a drop event to the current window and reset our DnD status. */
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.format = 32;
m.data.l[0] = m_wndProxy;
if (RT_UNLIKELY(xrc == 0))
m_curVer = -1;
return rc;
}
{
return VERR_INVALID_STATE;
|| cData == 0))
return VERR_INVALID_PARAMETER;
return VERR_INVALID_STATE;
/* Make a copy of the data. The xserver will become the new owner. */
if (RT_UNLIKELY(!pvNewData))
return VERR_NO_MEMORY;
/*
* The host send us the DnD data in the requested mime type. This allows us
* to fill the XdndSelection property of the requestor window with the data
* and afterwards inform the host about the new status.
*/
XEvent s;
RT_ZERO(s);
// s.xselection.owner = m_selEvent.xselectionrequest.owner;
LogFlowThisFunc(("owner=%#x, requestor=%#x, sel_atom=%s, target_atom=%s, prop_atom=%s, time=%u\n",
s.xselection.time));
/* Fill up the property with the data. */
XChangeProperty(s.xselection.display, s.xselection.requestor, s.xselection.property, s.xselection.target, 8, PropModeReplace,
if (RT_UNLIKELY(xrc == 0))
return VINF_SUCCESS;
}
#ifdef VBOX_WITH_DRAG_AND_DROP_GH
int DragInstance::ghIsDnDPending(void)
{
int rc = VINF_SUCCESS;
/* Is this another window which has a Xdnd selection than our current one? */
if ( wndSelection
&& wndSelection != m_wndProxy)
{
/* Map the window on the current cursor position, which should provoke
* an XdndEnter event. */
proxyWinShow();
XEvent e;
if (waitForX11Msg(e, ClientMessage))
{
int xRc;
LogFlowThisFunc(("Received event=%s\n",
{
int f;
unsigned long n, a;
unsigned char *ret = 0;
reset();
LogFlowThisFunc(("XA_XdndEnter\n"));
#ifdef DEBUG
LogFlowThisFunc(("m_wndCur=%#x, x=%d, y=%d, width=%d, height=%d\n",
#endif
/* Check if the MIME types are in the message itself or if we need
* to fetch the XdndTypeList property from the window. */
{
for (int i = 2; i < 5; ++i)
{
LogFlowThisFunc(("Received format via message: %s\n",
}
}
else
{
&& n > 0
&& ret)
{
for (unsigned i = 0; i < RT_MIN(VBOX_MAX_XPROPERTIES, n); ++i)
{
LogFlowThisFunc(("Received format via XdndTypeList: %s\n",
}
}
}
/* Fetch the possible list of actions, if this property is set. */
&& n > 0
&& ret)
{
for (unsigned i = 0; i < RT_MIN(VBOX_MAX_XPROPERTIES, n); ++i)
{
LogFlowThisFunc(("Received action: %s\n",
}
}
/* Acknowledge the event by sending a Status msg back to the
* window. */
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.format = 32;
m.data.l[0] = m_wndProxy;
if (RT_UNLIKELY(xRc == 0))
LogFlowThisFunc(("Error sending xEvent\n"));
}
/* Did the source tell us where the cursor currently is? */
{
LogFlowThisFunc(("XA_XdndPosition\n"));
/* Reply with a XdndStatus message to tell the source whether
* the data can be dropped or not. */
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.format = 32;
m.data.l[0] = m_wndProxy;
if (RT_UNLIKELY(xRc == 0))
LogFlowThisFunc(("Error sending xEvent\n"));
}
{
LogFlowThisFunc(("XA_XdndLeave\n"));
}
}
/* Do we need to acknowledge at least one format to the host? */
{
LogFlowThisFunc(("Acknowledging m_uClientID=%RU32, allActions=0x%x, strFormats=%s, rc=%Rrc\n",
}
}
return rc;
}
{
LogFlowThisFunc(("strFormat=%s, uAction=%RU32\n",
int rc = VINF_SUCCESS;
/* Show the proxy window, so that the source will find it. */
#ifdef DEBUG
LogFlowThisFunc(("m_wndCur=%#x, x=%d, y=%d, width=%d, height=%d\n",
#endif
/* We send a fake release event to the current window, cause
* this should have the grab. */
1 /* Button */, false /* Release button */);
/* The fake button release event should lead to a XdndDrop event from the
* source. Because of showing our proxy window, other Xdnd events can
* occur before, e.g. a XdndPosition event. We are not interested
* in those, so just try to get the right one. */
5 * 1000 /* Timeout in ms */);
if (fDrop)
{
/* Request to convert the selection in the specific format and
* place it to our proxy window as property. */
/* Wait for the selection notify event. */
{
bool fCancel = false;
/* Make some paranoid checks. */
{
int iPropFormat;
unsigned long cItems, cbRemaining;
0 /* Offset */,
VBOX_MAX_XPROPERTIES /* Length of 32-bit multiples */,
True /* Delete property? */,
AnyPropertyType, /* Property type */
LogFlowThisFunc(("strType=%s, iPropFormat=%d, cItems=%RU32, cbRemaining=%RU32\n",
&& iPropFormat >= 8
&& cItems > 0
&& cbRemaining == 0)
{
/* For whatever reason some of the string MIME types are not
* zero terminated. Check that and correct it when necessary,
* because the guest side wants this in any case. */
{
if (pvDataTmp)
{
}
else
rc = VERR_NO_MEMORY;
}
else
{
/* Send the raw data to the host. */
}
LogFlowThisFunc(("Sent strFormat=%s with rc=%Rrc\n",
if (RT_SUCCESS(rc))
{
/* Confirm the result of the transfer to the source window. */
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.window = m_wndProxy;
m.format = 32;
if (RT_UNLIKELY(xrc == 0))
LogFlowThisFunc(("Error sending xEvent\n"));
}
else
fCancel = true;
}
else
{
{
/** @todo Support incremental transfers. */
AssertMsgFailed(("Incrementally transfers are not supported yet\n"));
}
else
{
AssertMsgFailed(("Not supported data type (%s)\n",
}
fCancel = true;
}
if (fCancel)
{
LogFlowFunc(("Cancelling drop ...\n"));
/* Cancel this. */
RT_ZERO(m);
m.type = ClientMessage;
m.display = m_pDisplay;
m.window = m_wndProxy;
m.format = 32;
if (RT_UNLIKELY(xrc == 0))
LogFlowThisFunc(("Error sending cancel event\n"));
}
/* Cleanup. */
if (pcData)
}
else
}
else
rc = VERR_TIMEOUT;
}
else
rc = VERR_TIMEOUT;
/* Inform the host on error. */
if (RT_FAILURE(rc))
{
}
/* At this point, we have either successfully transfered any data or not.
* So reset our internal state because we are done here for this transaction. */
reset();
return rc;
}
#endif /* VBOX_WITH_DRAG_AND_DROP_GH */
/*
* Helpers
*/
{
/* Move the guest pointer to the DnD position, so we can find the window
* below that position. */
return VINF_SUCCESS;
}
{
LogFlowThisFunc(("wndDest=%#x, rx=%d, ry=%d, iBtn=%d, fPress=%RTbool\n",
#if 0
// Create and setting up the event
{
}
// Press
LogFlowThisFunc(("Error sending XTestFakeButtonEvent event\n"));
XFlush (m_pDisplay);
// Release
LogFlowThisFunc(("Error sending XTestFakeButtonEvent event\n"));
XFlush (m_pDisplay);
#else
#ifdef VBOX_DND_WITH_XTEST
/** @todo Make this check run only once. */
{
LogFlowThisFunc(("XText extension available\n"));
if (RT_UNLIKELY(xrc == 0))
LogFlowThisFunc(("Error sending XTestFakeButtonEvent event\n"));
}
else
{
#endif
LogFlowThisFunc(("XText extension not available or disabled\n"));
iButton == 2 ? Button2MotionMask :
iButton == 3 ? Button3MotionMask :
iButton == 4 ? Button4MotionMask :
iButton == 5 ? Button5MotionMask*/ : 0;
//XTranslateCoordinates(m_pDisplay, eBtn.root, eBtn.window, eBtn.x_root, eBtn.y_root, &eBtn.x, &eBtn.y, &eBtn.subwindow);
#if 0
#else
0 /* Mask */,
#endif
if (RT_UNLIKELY(xrc == 0))
LogFlowThisFunc(("Error sending XSendEvent\n"));
#ifdef DEBUG
#endif
#ifdef VBOX_DND_WITH_XTEST
}
#endif
#endif
}
int *piRootY /*= NULL*/,
bool fMouseMove /*= false */) const
{
/* piRootX is optional. */
/* piRootY is optional. */
unsigned int iMask;
// XTestGrabControl(m_pDisplay, False);
#ifdef DEBUG_andy
LogFlowThisFunc(("fInRootWnd=%RTbool, wndRoot=0x%x, wndChild=0x%x, iRootX=%d, iRootY=%d\n",
#endif
if (piRootX)
if (piRootY)
if (fMouseMove)
// XTestGrabControl(m_pDisplay, True);
return VINF_SUCCESS; /** @todo Add error checking. */
}
int DragInstance::proxyWinHide(void)
{
return VINF_SUCCESS; /** @todo Add error checking. */
}
/* Currently not used. */
/** @todo Is this function still needed? */
{
if (wndThis == m_wndProxy)
return;
// XSelectInput(m_pDisplay, w, Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask);//| SubstructureNotifyMask);
// XSelectInput(m_pDisplay, w, ButtonMotionMask); //PointerMotionMask);
unsigned cChildren;
{
for (unsigned i = 0; i < cChildren; ++i)
}
}
{
if (lstActions.isEmpty())
return;
reinterpret_cast<const unsigned char*>(lstActions.raw()),
lstActions.size());
}
{
}
{
return;
/* We support TARGETS and the data types. */
/* Add the property with the property data to the window. */
}
{
}
{
return atomList;
}
{
if ( !pvData
|| !cbData)
while (cbStr)
{
/* Create a copy with max N chars, so that we are on the save side,
* even if the data isn't zero terminated. */
}
return lstAtom;
}
/* static */
{
/* Ignore is None. */
None);
}
/* static */
{
if (hasDnDCopyAction(uActions))
if (hasDnDMoveAction(uActions))
if (hasDnDLinkAction(uActions))
return actionList;
}
/* static */
{
return uAction;
}
/* static */
{
return uActions;
}
/** @todo Replace by DnDURIList? */
{
if ( !pvData
|| !cbData)
while (cbStr > 0)
{
/* Create a copy with max N chars, so that we are on the save side,
* even if the data isn't zero terminated. */
}
return lstString;
}
/** @todo Is this function really needed? */
void DragAndDropService::clearEventQueue(void)
{
}
/*******************************************************************************
* DragAndDropService implementation.
******************************************************************************/
{
int rc;
do
{
/* Initialize X11 DnD. */
rc = x11DragAndDropInit();
if (RT_FAILURE(rc))
break;
if (!m_pCurDnD)
{
rc = VERR_NO_MEMORY;
break;
}
/* Note: For multiple screen support in VBox it is not necessary to use
* another screen number than zero. Maybe in the future it will become
* necessary if VBox supports multiple X11 screens. */
if (RT_FAILURE(rc))
break;
LogRel(("DnD: Started\n"));
/* Enter the main event processing loop. */
do
{
DnDEvent e;
RT_ZERO(e);
LogFlowFunc(("Waiting for new event ...\n"));
if (RT_FAILURE(rc))
break;
("Event queue is empty when it shouldn't\n"));
e = m_eventQueue.first();
{
{
{
{
/* Enter is always followed by a move event. */
}
else /* Invalid parameter, skip. */
break;
/* Not breaking unconditionally is intentional. See comment above. */
}
{
e.hgcm.u.a.uDefAction);
break;
}
{
break;
}
{
break;
}
{
break;
}
{
#ifdef VBOX_WITH_DRAG_AND_DROP_GH
#endif
break;
}
{
#ifdef VBOX_WITH_DRAG_AND_DROP_GH
e.hgcm.u.a.uDefAction);
#endif
break;
}
default:
break;
}
/* Some messages require cleanup. */
{
#ifdef VBOX_WITH_DRAG_AND_DROP_GH
#endif
{
if (e.hgcm.pszFormats)
break;
}
{
if (e.hgcm.pszFormats)
break;
}
default:
break;
}
}
{
}
else
/* Make sure that any X11 requests have actually been sent to the
* server, since we are waiting for responses using poll() on
* another thread which will not automatically trigger flushing. */
} while (!ASMAtomicReadBool(&m_fSrvStopping));
} while (0);
return rc;
}
int DragAndDropService::x11DragAndDropInit(void)
{
/* Connect to the x11 server. */
if (!m_pDisplay)
/** @todo Correct errors. */
return VERR_NOT_FOUND;
if (!pHelpers)
return VERR_NO_MEMORY;
int rc = VINF_SUCCESS;
do
{
if (RT_FAILURE(rc))
break;
if (RT_FAILURE(rc))
break;
/* Event thread for events coming from the HGCM device. */
"HGCM-NOTIFY");
if (RT_FAILURE(rc))
break;
/* Event thread for events coming from the x11 system. */
"X11-NOTIFY");
} while (0);
/* No clean-up code for now, as we have no good way of testing it and things
if (RT_FAILURE(rc))
return rc;
}
/* static */
{
if (RT_FAILURE(rc))
{
return rc;
}
/* Number of invalid messages skipped in a row. */
int cMsgSkippedInvalid = 0;
DnDEvent e;
do
{
RT_ZERO(e);
/* Wait for new events. */
if (RT_SUCCESS(rc))
{
cMsgSkippedInvalid = 0; /* Reset skipped messages count. */
LogFlowFunc(("Adding new HGCM event ...\n"));
if (RT_FAILURE(rc))
break;
}
else
{
/* Old(er) hosts either are broken regarding DnD support or otherwise
* don't support the stuff we do on the guest side, so make sure we
* don't process invalid messages forever. */
if (rc == VERR_INVALID_PARAMETER)
if (cMsgSkippedInvalid > 3)
{
break;
}
}
return rc;
}
/* static */
{
int rc = VINF_SUCCESS;
DnDEvent e;
do
{
/*
* Wait for new events. We can't use XIfEvent here, cause this locks
* the window connection with a mutex and if no X11 events occurs this
* blocks any other calls we made to X11. So instead check for new
* events and if there are not any new one, sleep for a certain amount
* of time.
*/
{
RT_ZERO(e);
/* XNextEvent will block until a new X event becomes available. */
{
#ifdef DEBUG
{
case ClientMessage:
{
{
LogFlowFunc(("XA_XdndPosition x=%RI32, y=%RI32, dwAction=%RI32\n",
}
{
LogFlowFunc(("XA_XdndDrop\n"));
}
break;
}
default:
break;
}
#endif
LogFlowFunc(("Adding new X11 event ...\n"));
/* At the moment we only have one drag instance. */
}
}
else
return rc;
}
/* Static factory */
{
return pService;
}