VirtualBox

Changeset 85920 in vbox


Ignore:
Timestamp:
Aug 28, 2020 9:40:55 AM (4 years ago)
Author:
vboxsync
Message:

DnD/X11: A bit of cleanup + renaming; no functional changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp

    r85746 r85920  
    5353 * For X11 guest Xdnd is used. See http://www.acc.umu.se/~vatten/XDND.html for
    5454 * a walk trough.
     55 *
     56 * Also useful pages:
     57 *     - https://www.freedesktop.org/wiki/Draganddropwarts/
     58 *     - https://www.freedesktop.org/wiki/Specifications/XDNDRevision/
    5559 *
    5660 * Host -> Guest:
     
    8690 */
    8791
    88 #define VBOX_XDND_VERSION    (4)
     92/*********************************************************************************************************************************
     93 * Definitions                                                                                                                   *
     94 ********************************************************************************************************************************/
     95
     96/** The Xdnd protocol version we support. */
     97#define VBOX_XDND_VERSION                       (5)
     98
     99/** Whether the target window accepts the data being dragged over or not. */
     100#define VBOX_XDND_STATUS_FLAG_ACCEPT            0x1
     101/** Whether the target window wants XdndPosition messages while dragging stuff over it. */
     102#define VBOX_XDND_STATUS_FLAG_WANTS_POS         0x2
     103
     104/** Whether the target window accepted the drop data or not. */
     105#define VBOX_XDND_FINISHED_FLAG_SUCCEEDED       0x1
     106
     107/** How many X properties our proxy window can hold. */
    89108#define VBOX_MAX_XPROPERTIES (LONG_MAX-1)
    90109
     
    218237#define VBoxDnDAtomList RTCList<Atom>
    219238
    220 /*******************************************************************************
    221  *
    222  * xHelpers Declaration
    223  *
    224  ******************************************************************************/
    225 
    226239class xHelpers
    227240{
     
    302315#define xAtomToString(xa) xHelpers::getInstance()->xAtomToString((xa))
    303316
    304 /*******************************************************************************
    305  *
    306  * xHelpers Implementation
    307  *
    308  ******************************************************************************/
     317/*********************************************************************************************************************************
     318 * xHelpers implementation.                                                                                                      *
     319 ********************************************************************************************************************************/
    309320
    310321xHelpers *xHelpers::m_pInstance = NULL;
     
    418429}
    419430
    420 /*******************************************************************************
    421  *
    422  * DragInstance Declaration
    423  *
    424  ******************************************************************************/
    425 
    426431#ifdef DEBUG
    427432# define VBOX_DND_FN_DECL_LOG(x) inline x /* For LogFlowXXX logging. */
     
    430435#endif
    431436
    432 /** @todo Move all proxy window-related stuff into this class! Clean up this mess. */
     437/**
     438 * Class which handles a single drag'n drop proxy window.
     439 ** @todo Move all proxy window-related stuff into this class! Clean up this mess.
     440 */
    433441class VBoxDnDProxyWnd
    434442{
     
    570578
    571579    /* Atom / HGCM formatting helpers. */
    572     int             toAtomList(const RTCList<RTCString> &lstFormats, VBoxDnDAtomList &lstAtoms) const;
    573     int             toAtomList(const void *pvData, uint32_t cbData, VBoxDnDAtomList &lstAtoms) const;
     580    int             appendToAtomList(const RTCList<RTCString> &lstFormats, VBoxDnDAtomList &lstAtoms) const;
     581    int             appendToAtomList(const void *pvData, uint32_t cbData, VBoxDnDAtomList &lstAtoms) const;
    574582    static Atom     toAtomAction(VBOXDNDACTION dndAction);
    575583    static int      toAtomActions(VBOXDNDACTIONLIST dndActionList, VBoxDnDAtomList &lstAtoms);
     
    627635};
    628636
    629 /*******************************************************************************
    630  *
    631  * DragAndDropService Declaration
    632  *
    633  ******************************************************************************/
    634 
     637/**
     638 * Service class which implements drag'n drop.
     639 */
    635640class DragAndDropService
    636641{
     
    677682};
    678683
    679 /*******************************************************************************
    680  *
    681  * DragInstanc Implementation
    682  *
    683  ******************************************************************************/
     684/*********************************************************************************************************************************
     685 * DragInstanc implementation.                                                                                                   *
     686 ********************************************************************************************************************************/
    684687
    685688DragInstance::DragInstance(Display *pDisplay, DragAndDropService *pParent)
     
    885888
    886889        /* Make the new window Xdnd aware. */
    887         Atom ver = VBOX_XDND_VERSION;
     890        Atom atmVer = VBOX_XDND_VERSION;
    888891        XChangeProperty(m_pDisplay, m_wndProxy.hWnd, xAtom(XA_XdndAware), XA_ATOM, 32, PropModeReplace,
    889                         reinterpret_cast<unsigned char*>(&ver), 1);
     892                        reinterpret_cast<unsigned char*>(&atmVer), 1);
    890893    } while (0);
    891894
     
    12481251 * @param   e                       X11 event to handle.
    12491252 */
    1250 int DragInstance::onX11SelectionRequest(const XEvent &e)
    1251 {
    1252     AssertReturn(e.type == SelectionRequest, VERR_INVALID_PARAMETER);
     1253int DragInstance::onX11SelectionRequest(const XEvent &evReq)
     1254{
     1255    AssertReturn(evReq.type == SelectionRequest, VERR_INVALID_PARAMETER);
     1256
     1257    const XSelectionRequestEvent *pEvReq = &evReq.xselectionrequest;
    12531258
    12541259    LogFlowThisFunc(("mode=%RU32, state=%RU32\n", m_enmMode, m_enmState));
    12551260    LogFlowThisFunc(("Event owner=%#x, requestor=%#x, selection=%s, target=%s, prop=%s, time=%u\n",
    1256                      e.xselectionrequest.owner,
    1257                      e.xselectionrequest.requestor,
    1258                      xAtomToString(e.xselectionrequest.selection).c_str(),
    1259                      xAtomToString(e.xselectionrequest.target).c_str(),
    1260                      xAtomToString(e.xselectionrequest.property).c_str(),
    1261                      e.xselectionrequest.time));
     1261                     pEvReq->owner,
     1262                     pEvReq->requestor,
     1263                     xAtomToString(pEvReq->selection).c_str(),
     1264                     xAtomToString(pEvReq->target).c_str(),
     1265                     xAtomToString(pEvReq->property).c_str(),
     1266                     pEvReq->time));
    12621267    int rc;
    12631268
     
    12681273            rc = VINF_SUCCESS;
    12691274
    1270             char *pszWndName = wndX11GetNameA(e.xselectionrequest.requestor);
     1275            char *pszWndName = wndX11GetNameA(pEvReq->requestor);
    12711276            AssertPtr(pszWndName);
    12721277
     
    12761281             */
    12771282
    1278             XEvent s;
    1279             RT_ZERO(s);
    1280             s.xselection.type      = SelectionNotify;
    1281             s.xselection.display   = e.xselectionrequest.display;
    1282             s.xselection.requestor = e.xselectionrequest.requestor;
    1283             s.xselection.selection = e.xselectionrequest.selection;
    1284             s.xselection.target    = e.xselectionrequest.target;
    1285             s.xselection.property  = None;                          /* "None" means refusal. */
    1286             s.xselection.time      = e.xselectionrequest.time;
    1287 
    1288             const XSelectionRequestEvent *pReq = &e.xselectionrequest;
     1283            XEvent evResp;
     1284            RT_ZERO(evResp);
     1285
     1286            XSelectionEvent *pEvResp = &evResp.xselection;
     1287
     1288            pEvResp->type      = SelectionNotify;
     1289            pEvResp->display   = pEvReq->display;
     1290            pEvResp->requestor = pEvReq->requestor;
     1291            pEvResp->selection = pEvReq->selection;
     1292            pEvResp->target    = pEvReq->target;
     1293            pEvResp->property  = None;                          /* "None" means refusal. */
     1294            pEvResp->time      = pEvReq->time;
    12891295
    12901296#ifdef DEBUG
     
    12941300#endif
    12951301            /* Is the requestor asking for the possible MIME types? */
    1296             if (pReq->target == xAtom(XA_TARGETS))
     1302            if (pEvReq->target == xAtom(XA_TARGETS))
    12971303            {
    1298                 VBClLogInfo("Target window %#x ('%s') asking for target list\n", e.xselectionrequest.requestor, pszWndName);
     1304                VBClLogInfo("Target window %#x ('%s') asking for target list\n", pEvReq->requestor, pszWndName);
    12991305
    13001306                /* If so, set the window property with the formats on the requestor
    13011307                 * window. */
    1302                 rc = wndXDnDSetFormatList(pReq->requestor, pReq->property, m_lstFormats);
     1308                rc = wndXDnDSetFormatList(pEvReq->requestor, pEvReq->property, m_lstFormats);
    13031309                if (RT_SUCCESS(rc))
    1304                     s.xselection.property = pReq->property;
     1310                    pEvResp->property = pEvReq->property;
    13051311            }
    13061312            /* Is the requestor asking for a specific MIME type (we support)? */
    1307             else if (m_lstFormats.contains(pReq->target))
     1313            else if (m_lstFormats.contains(pEvReq->target))
    13081314            {
    13091315                VBClLogInfo("Target window %#x ('%s') is asking for data as '%s'\n",
    1310                             pReq->requestor, pszWndName, xAtomToString(pReq->target).c_str());
     1316                            pEvReq->requestor, pszWndName, xAtomToString(pEvReq->target).c_str());
    13111317
    13121318                /* Did we not drop our stuff to the guest yet? Bail out. */
    13131319                if (m_enmState != Dropped)
    13141320                {
    1315                     LogFlowThisFunc(("Wrong state (%RU32), refusing request\n", m_enmState));
     1321                    VBClLogError("Data not dropped by the host on the guest yet (client state %RU32, mode %RU32), refusing selection request by guest\n",
     1322                                 m_enmState, m_enmMode);
    13161323                }
    13171324                /* Did we not store the requestor's initial selection request yet? Then do so now. */
     
    13191326                {
    13201327                    /* Get the data format the requestor wants from us. */
    1321                     RTCString strFormat = xAtomToString(pReq->target);
     1328                    RTCString strFormat = xAtomToString(pEvReq->target);
    13221329                    Assert(strFormat.isNotEmpty());
    13231330                    VBClLogInfo("Target window=%#x requested data from host as '%s', rc=%Rrc\n",
    1324                                 pReq->requestor, strFormat.c_str(), rc);
     1331                                pEvReq->requestor, strFormat.c_str(), rc);
    13251332
    13261333                    /* Make a copy of the MIME data to be passed back. The X server will be become
     
    13311338
    13321339                    /* Always return the requested property. */
    1333                     s.xselection.property = pReq->property;
     1340                    evResp.xselection.property = pEvReq->property;
    13341341
    13351342                    /* Note: Always seems to return BadRequest. Seems fine. */
    1336                     int xRc = XChangeProperty(s.xselection.display, s.xselection.requestor, s.xselection.property,
    1337                                               s.xselection.target, 8, PropModeReplace,
     1343                    int xRc = XChangeProperty(pEvResp->display, pEvResp->requestor, pEvResp->property,
     1344                                              pEvResp->target, 8, PropModeReplace,
    13381345                                              reinterpret_cast<const unsigned char*>(pvData), cbData);
    13391346
    13401347                    LogFlowFunc(("Changing property '%s' (target '%s') of window=%RU32: %s\n",
    1341                                  xAtomToString(pReq->property).c_str(),
    1342                                  xAtomToString(pReq->target).c_str(),
    1343                                  pReq->requestor,
     1348                                 xAtomToString(pEvReq->property).c_str(),
     1349                                 xAtomToString(pEvReq->target).c_str(),
     1350                                 pEvReq->requestor,
    13441351                                 gX11->xErrorToString(xRc).c_str()));
    13451352                    RT_NOREF(xRc);
     
    13501357            {
    13511358                VBClLogError("Refusing unknown command/format '%s' of wnd=%#x ('%s')\n",
    1352                              xAtomToString(e.xselectionrequest.target).c_str(), pReq->requestor, pszWndName);
     1359                             xAtomToString(pEvReq->target).c_str(), pEvReq->requestor, pszWndName);
    13531360                rc = VERR_NOT_SUPPORTED;
    13541361            }
    13551362
    13561363            LogFlowThisFunc(("Offering type '%s', property '%s' to wnd=%#x ...\n",
    1357                              xAtomToString(pReq->target).c_str(),
    1358                              xAtomToString(pReq->property).c_str(), pReq->requestor));
    1359 
    1360             int xRc = XSendEvent(pReq->display, pReq->requestor, True /* Propagate */, 0, &s);
     1364                             xAtomToString(pEvReq->target).c_str(),
     1365                             xAtomToString(pEvReq->property).c_str(), pEvReq->requestor));
     1366
     1367            int xRc = XSendEvent(pEvReq->display, pEvReq->requestor, True /* Propagate */, 0, &evResp);
    13611368            if (xRc == 0)
    1362                 VBClLogError("Error sending SelectionNotify(1) event to wnd=%#x: %s\n", pReq->requestor,
    1363                              gX11->xErrorToString(xRc).c_str());
    1364             XFlush(pReq->display);
     1369                VBClLogError("Error sending SelectionNotify(1) event to wnd=%#x: %s\n",
     1370                             pEvReq->requestor, gX11->xErrorToString(xRc).c_str());
     1371            XFlush(pEvReq->display);
    13651372
    13661373            if (pszWndName)
     
    13971404         */
    13981405        case ButtonPress:
     1406            RT_FALL_THROUGH();
    13991407        case ButtonRelease:
    1400             LogFlowThisFunc(("Mouse button press/release\n"));
     1408        {
     1409            VBClLogInfo("Mouse button %s\n", e.type == ButtonPress ? "pressed" : "released");
     1410
     1411            reset();
     1412
    14011413            rc = VINF_SUCCESS;
    1402 
    1403             reset();
    1404             break;
     1414            break;
     1415        }
    14051416
    14061417        case ClientMessage:
     
    16201631            break;
    16211632
    1622         rc = toAtomList(lstFormats, m_lstFormats);
     1633        rc = appendToAtomList(lstFormats, m_lstFormats);
    16231634        if (RT_FAILURE(rc))
    16241635            break;
     
    16981709    {
    16991710        /* Temp stuff for the XGetWindowProperty call. */
    1700         Atom atmp;
     1711        Atom atmTmp;
    17011712        int fmt;
    17021713        unsigned long cItems, cbRemaining;
     
    17071718        xRc = XGetWindowProperty(m_pDisplay, wndCursor, xAtom(XA_XdndAware),
    17081719                                 0, 2, False, AnyPropertyType,
    1709                                  &atmp, &fmt, &cItems, &cbRemaining, &pcData);
     1720                                 &atmTmp, &fmt, &cItems, &cbRemaining, &pcData);
    17101721        if (xRc != Success)
    17111722        {
     
    18241835         * Send a XdndPosition event with the proposed action to the guest.
    18251836         */
    1826         Atom pa = toAtomAction(dndActionDefault);
    1827         LogFlowThisFunc(("strAction=%s\n", xAtomToString(pa).c_str()));
     1837        Atom atmAction = toAtomAction(dndActionDefault);
     1838        LogFlowThisFunc(("strAction=%s\n", xAtomToString(atmAction).c_str()));
    18281839
    18291840        XClientMessageEvent m;
     
    18351846        m.format       = 32;
    18361847        m.data.l[XdndPositionWindow]    = m_wndProxy.hWnd;               /* X window ID of source window. */
     1848        m.data.l[XdndPositionFlags]     = 0;                             /* Reserved, set to 0. */
    18371849        m.data.l[XdndPositionXY]        = RT_MAKE_U32(uPosY, uPosX);     /* Cursor coordinates relative to the root window. */
    18381850        m.data.l[XdndPositionTimeStamp] = CurrentTime;                   /* Timestamp for retrieving data. */
    1839         m.data.l[XdndPositionAction]    = pa;                            /* Actions requested by the user. */
     1851        m.data.l[XdndPositionAction]    = atmAction;                     /* Actions requested by the user. */
    18401852
    18411853        xRc = XSendEvent(m_pDisplay, wndCursor, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
     
    27762788 * @param   wndThis                 Window to set the format list for.
    27772789 * @param   lstActions              Reference to list of XDnD actions to set.
    2778  *
    2779  * @remark
    27802790 */
    27812791int DragInstance::wndXDnDSetActionList(Window wndThis, const VBoxDnDAtomList &lstActions) const
     
    28142824    XChangeProperty(m_pDisplay, wndThis, atmProp,
    28152825                    XA_ATOM, 32, PropModeReplace,
    2816                     reinterpret_cast<const unsigned char*>(lstFormatsExt.raw()),
    2817                     lstFormatsExt.size());
     2826                    reinterpret_cast<const unsigned char*>(lstFormats.raw()),
     2827                    lstFormats.size());
    28182828
    28192829    return VINF_SUCCESS;
     
    28212831
    28222832/**
    2823  * Converts a RTCString list to VBoxDnDAtomList list.
     2833 * Appends a RTCString list to VBoxDnDAtomList list.
    28242834 *
    28252835 * @returns IPRT status code.
     
    28272837 * @param   lstAtoms                Reference to VBoxDnDAtomList list to store results in.
    28282838 */
    2829 int DragInstance::toAtomList(const RTCList<RTCString> &lstFormats, VBoxDnDAtomList &lstAtoms) const
     2839int DragInstance::appendToAtomList(const RTCList<RTCString> &lstFormats, VBoxDnDAtomList &lstAtoms) const
    28302840{
    28312841    for (size_t i = 0; i < lstFormats.size(); ++i)
     
    28362846
    28372847/**
    2838  * Converts a raw-data string list to VBoxDnDAtomList list.
     2848 * Appends a raw-data string list to VBoxDnDAtomList list.
    28392849 *
    28402850 * @returns IPRT status code.
     
    28432853 * @param   lstAtoms                Reference to VBoxDnDAtomList list to store results in.
    28442854 */
    2845 int DragInstance::toAtomList(const void *pvData, uint32_t cbData, VBoxDnDAtomList &lstAtoms) const
     2855int DragInstance::appendToAtomList(const void *pvData, uint32_t cbData, VBoxDnDAtomList &lstAtoms) const
    28462856{
    28472857    RT_NOREF1(lstAtoms);
     
    29522962}
    29532963
    2954 /*******************************************************************************
    2955  * VBoxDnDProxyWnd implementation.
    2956  ******************************************************************************/
     2964/*********************************************************************************************************************************
     2965 * VBoxDnDProxyWnd implementation.                                                                                               *
     2966 ********************************************************************************************************************************/
    29572967
    29582968VBoxDnDProxyWnd::VBoxDnDProxyWnd(void)
     
    30203030}
    30213031
    3022 /*******************************************************************************
    3023  * DragAndDropService implementation.
    3024  ******************************************************************************/
     3032/*********************************************************************************************************************************
     3033 * DragAndDropService implementation.                                                                                            *
     3034 ********************************************************************************************************************************/
    30253035
    30263036/**
     
    34483458            XNextEvent(pThis->m_pDisplay, &e.x11);
    34493459            {
    3450 #ifdef DEBUG
    3451                 switch (e.x11.type)
    3452                 {
    3453                     case ClientMessage:
    3454                     {
    3455                         XClientMessageEvent *pEvent = reinterpret_cast<XClientMessageEvent*>(&e);
    3456                         AssertPtr(pEvent);
    3457 
    3458                         RTCString strType = xAtomToString(pEvent->message_type);
    3459                         LogFlowFunc(("ClientMessage: %s from wnd=%#x\n", strType.c_str(), pEvent->window));
    3460                         break;
    3461                     }
    3462 
    3463                     default:
    3464                         LogFlowFunc(("Received X event type=%d\n", e.x11.type));
    3465                         break;
    3466                 }
    3467 #endif
    34683460                /* At the moment we only have one drag instance. */
    34693461                DragInstance *pInstance = pThis->m_pCurDnD;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette