VirtualBox

Changeset 22233 in vbox


Ignore:
Timestamp:
Aug 13, 2009 12:17:35 PM (15 years ago)
Author:
vboxsync
Message:

GuestHost/SharedClipboard/x11: remove more bits which XFIXES made unnecessary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp

    r22212 r22233  
    168168    Widget widget;
    169169
    170     /** Does VBox currently own the clipboard? */
    171     bool fOwnsClipboard;
    172170    /** Should we try to grab the clipboard on startup? */
    173171    bool fGrabClipboardOnStart;
     
    181179    /** What formats does VBox have on offer? */
    182180    uint32_t vboxFormats;
    183     /** Windows hosts and guests cache the clipboard data they receive.
    184      * Since we have no way of knowing whether their cache is still valid,
    185      * we always send a "data changed" message after a successful transfer
    186      * to invalidate it. */
    187     bool notifyVBox;
    188181    /** Cache of the last unicode data that we received */
    189182    void *pvUnicodeCache;
     
    401394 * @param  pTargets  the list of targets
    402395 * @param  cTargets  the size of the list in @a pTargets
    403  * @param  pChanged  This is set to true if the formats available have changed
    404  *                   from VBox's point of view, and to false otherwise.
    405  *                   Somehow this didn't feel right as a return value.
    406396 */
    407397static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx, Atom *pTargets,
    408                                       size_t cTargets, bool *pChanged)
    409 {
    410     bool changed = false;
     398                                      size_t cTargets)
     399{
    411400    AssertPtrReturnVoid(pCtx);
    412     AssertReturnVoid(VALID_PTR(pTargets) || cTargets == 0);
     401    AssertPtrReturnVoid(pTargets);
    413402    CLIPX11FORMAT bestTextFormat;
    414403    bestTextFormat = clipGetTextFormatFromTargets(pCtx, pTargets, cTargets);
    415404    if (pCtx->X11TextFormat != bestTextFormat)
    416405    {
    417         changed = true;
    418406        pCtx->X11TextFormat = bestTextFormat;
    419407#if defined(DEBUG) && !defined(TESTCASE)
     
    429417    }
    430418    pCtx->X11BitmapFormat = INVALID;  /* not yet supported */
    431     if (pChanged)
    432         *pChanged = changed;
    433419}
    434420
     
    443429                                 size_t cTargets)
    444430{
    445     bool changed = false;
    446 
    447431    LogRel2 (("%s: called\n", __PRETTY_FUNCTION__));
    448     if (pCtx->fOwnsClipboard)
    449         /* VBox raced us and we lost.  So we don't want to report anything. */
    450         return;
    451     clipGetFormatsFromTargets(pCtx, pTargets, cTargets, &changed);
     432    clipGetFormatsFromTargets(pCtx, pTargets, cTargets);
    452433    clipReportFormatsToVBox(pCtx);
    453434}
    454 
    455 #ifdef TESTCASE
    456 static bool clipTestTargetUpdate(CLIPBACKEND *pCtx)
    457 {
    458     bool success = true;
    459     bool changed = true;
    460     clipGetFormatsFromTargets(pCtx, NULL, 0, &changed);
    461     clipGetFormatsFromTargets(pCtx, NULL, 0, &changed);  /* twice */
    462     if (changed)
    463         success = false;
    464     Atom targets[3];
    465     targets[0] = clipGetAtom(NULL, "COMPOUND_TEXT");
    466     targets[1] = clipGetAtom(NULL, "text/plain");
    467     targets[2] = clipGetAtom(NULL, "TARGETS");
    468     clipGetFormatsFromTargets(pCtx, targets, RT_ELEMENTS(targets), &changed);
    469     if (!changed)
    470         success = false;
    471     clipGetFormatsFromTargets(pCtx, targets, RT_ELEMENTS(targets), &changed);
    472     if (changed)
    473         success = false;
    474     return success;
    475 }
    476 #endif
    477435
    478436/**
     
    488446    CLIPBACKEND *pCtx =
    489447            reinterpret_cast<CLIPBACKEND *>(pClientData);
    490     Atom *pTargets = (*atomType == XT_CONVERT_FAIL) ? NULL  /* timeout */
    491                                                     : (Atom *)pValue;
    492     size_t cTargets = pTargets ? *pcLen : 0;
    493448    LogRel2(("clipConvertX11Targets: pValue=%p, *pcLen=%u, *atomType=%d, XT_CONVERT_FAIL=%d\n",
    494449             pValue, *pcLen, *atomType, XT_CONVERT_FAIL));
    495     clipUpdateX11Targets(pCtx, pTargets, cTargets);
     450    if (   (*atomType == XT_CONVERT_FAIL)  /* timeout */
     451        || (pValue == NULL))               /* No data available */
     452    {
     453        clipReportEmptyX11CB(pCtx);
     454        return;
     455    }
     456    clipUpdateX11Targets(pCtx, (Atom *)pValue, *pcLen);
    496457    XtFree(reinterpret_cast<char *>(pValue));
    497458}
     
    502463void clipQueryX11CBFormats(CLIPBACKEND *pCtx)
    503464{
    504     LogRel2 (("%s: called\n", __PRETTY_FUNCTION__));
    505     /* Get the current clipboard contents if we don't own it ourselves */
    506     if (!pCtx->fOwnsClipboard)
    507     {
    508         LogRel2 (("%s: requesting the targets that the X11 clipboard offers\n",
    509                __PRETTY_FUNCTION__));
    510         XtGetSelectionValue(pCtx->widget,
    511                             clipGetAtom(pCtx->widget, "CLIPBOARD"),
    512                             clipGetAtom(pCtx->widget, "TARGETS"),
    513                             clipConvertX11Targets, pCtx,
    514                             CurrentTime);
    515     }
     465    LogRel2 (("%s: requesting the targets that the X11 clipboard offers\n",
     466           __PRETTY_FUNCTION__));
     467    XtGetSelectionValue(pCtx->widget,
     468                        clipGetAtom(pCtx->widget, "CLIPBOARD"),
     469                        clipGetAtom(pCtx->widget, "TARGETS"),
     470                        clipConvertX11Targets, pCtx,
     471                        CurrentTime);
    516472}
    517473
    518474#ifndef TESTCASE
     475
     476typedef struct {
     477    int type;                   /* event base */
     478    unsigned long serial;
     479    Bool send_event;
     480    Display *display;
     481    Window window;
     482    int subtype;
     483    Window owner;
     484    Atom selection;
     485    Time timestamp;
     486    Time selection_timestamp;
     487} XFixesSelectionNotifyEvent;
     488
    519489/**
    520490 * Wait until an event arrives and handle it if it is an XFIXES selection
     
    523493void clipPeekEventAndDoXFixesHandling(CLIPBACKEND *pCtx)
    524494{
    525     XEvent event = { 0 };
    526 
    527     if (XtAppPeekEvent(pCtx->appContext, &event))
    528         if (   !pCtx->fOwnsClipboard
    529             && (event.type == pCtx->fixesEventBase))
    530             clipQueryX11CBFormats(pCtx);
     495    union
     496    {
     497        XEvent event;
     498        XFixesSelectionNotifyEvent fixes;
     499    } event = { { 0 } };
     500
     501    if (XtAppPeekEvent(pCtx->appContext, &event.event))
     502        if (   (event.event.type == pCtx->fixesEventBase)
     503            && (event.fixes.owner != XtWindow(pCtx->widget)))
     504        {
     505            if (   (event.fixes.subtype == 0  /* XFixesSetSelectionOwnerNotify */)
     506                && (event.fixes.owner != 0))
     507                clipQueryX11CBFormats(pCtx);
     508            else
     509                clipReportEmptyX11CB(pCtx);
     510        }
    531511}
    532512
     
    776756    if (RT_SUCCESS(rc))
    777757    {
    778         pCtx->fOwnsClipboard = false;
    779758        clipResetX11Formats(pCtx);
    780759        pCtx->fGrabClipboardOnStart = grab;
     
    11601139
    11611140    LogRelFlowFunc(("\n"));
    1162     if (   !pCtx->fOwnsClipboard   /* Drop requests we receive too late. */
    1163         || !clipIsSupportedSelectionType(pCtx->widget, *atomSelection))
     1141    if (!clipIsSupportedSelectionType(pCtx->widget, *atomSelection))
    11641142        return false;
    11651143    if (*atomTarget == clipGetAtom(pCtx->widget, "TARGETS"))
     
    11731151}
    11741152
    1175 /**
    1176  * Notify VBox that we have returned the clipboard to X11.
    1177  */
    1178 static void clipReleaseCB(CLIPBACKEND *pCtx)
    1179 {
    1180     LogRelFlowFunc (("\n"));
    1181     /* The formats should be set to the right values as soon as X11 clipboard
    1182      * data becomes available. */
    1183     clipReportEmptyX11CB(pCtx);
    1184     pCtx->fOwnsClipboard = false;
    1185 }
    1186 
    1187 /**
    1188  * This is called by the X toolkit intrinsics to let us know that another
    1189  * X11 client has taken the clipboard.  In this case we notify VBox that
    1190  * X11 wants ownership of the clipboard.
    1191  * @note  X11 backend code, callback for XtOwnSelection
    1192  */
    1193 static void clipXtLoseSelectionProc(Widget widget, Atom *)
    1194 {
    1195     CLIPBACKEND *pCtx = clipLookupContext(widget);
    1196     LogRelFlowFunc (("\n"));
    1197     clipReleaseCB(pCtx);
    1198 }
    1199 
    12001153/** Structure used to pass information about formats that VBox supports */
    12011154typedef struct _CLIPNEWVBOXFORMATS
     
    12221175static void clipGrabX11CB(CLIPBACKEND *pCtx, uint32_t u32Formats)
    12231176{
    1224     /* Make sure we don't try to query ourselves if we get the clipboard */
    1225     pCtx->fOwnsClipboard = true;
    12261177    if (XtOwnSelection(pCtx->widget, clipGetAtom(pCtx->widget, "CLIPBOARD"),
    1227                        CurrentTime, clipXtConvertSelectionProc,
    1228                        clipXtLoseSelectionProc, 0))
     1178                       CurrentTime, clipXtConvertSelectionProc, NULL, 0))
    12291179    {
    12301180        pCtx->vboxFormats = u32Formats;
     
    12331183                       CurrentTime, clipXtConvertSelectionProc, NULL, 0);
    12341184    }
    1235     else
    1236         /* Someone raced us to get the clipboard and they won. */
    1237         pCtx->fOwnsClipboard = false;
    12381185}
    12391186
     
    15911538
    15921539    int rc = VINF_SUCCESS;
    1593     /* Do not continue if we already own the clipboard */
    1594     if (pCtx->fOwnsClipboard == true)
    1595         rc = VERR_TIMEOUT;
     1540    /*
     1541     * VBox wants to read data in the given format.
     1542     */
     1543    if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
     1544    {
     1545        pReq->mTextFormat = pCtx->X11TextFormat;
     1546        if (pReq->mTextFormat == INVALID)
     1547            /* VBox thinks we have data and we don't */
     1548            rc = VERR_NO_DATA;
     1549        else
     1550            /* Send out a request for the data to the current clipboard
     1551             * owner */
     1552            XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx->widget, "CLIPBOARD"),
     1553                                clipAtomForX11Format(pCtx->widget,
     1554                                                     pCtx->X11TextFormat),
     1555                                clipConvertX11CB,
     1556                                reinterpret_cast<XtPointer>(pReq),
     1557                                CurrentTime);
     1558    }
    15961559    else
    1597     {
    1598         /*
    1599          * VBox wants to read data in the given format.
    1600          */
    1601         if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    1602         {
    1603             pReq->mTextFormat = pCtx->X11TextFormat;
    1604             if (pReq->mTextFormat == INVALID)
    1605                 /* VBox thinks we have data and we don't */
    1606                 rc = VERR_NO_DATA;
    1607             else
    1608                 /* Send out a request for the data to the current clipboard
    1609                  * owner */
    1610                 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx->widget, "CLIPBOARD"),
    1611                                     clipAtomForX11Format(pCtx->widget,
    1612                                                          pCtx->X11TextFormat),
    1613                                     clipConvertX11CB,
    1614                                     reinterpret_cast<XtPointer>(pReq),
    1615                                     CurrentTime);
    1616         }
    1617         else
    1618             rc = VERR_NOT_IMPLEMENTED;
    1619     }
     1560        rc = VERR_NOT_IMPLEMENTED;
    16201561    if (RT_FAILURE(rc))
    16211562    {
     
    24362377    RTTestSub(hTest, "notification of switch to X11 clipboard");
    24372378    clipInvalidateFormats();
    2438     clipReleaseCB(pCtx);
     2379    clipReportEmptyX11CB(pCtx);
    24392380    RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0,
    24402381                     (hTest, "Failed to send a format update (release) notification\n"));
     
    24562397                           sizeof("hello world"), 8);
    24572398    clipSetTargetsFailure(false, true);
    2458     clipUpdateX11Targets(pCtx, NULL, 0);
     2399    Atom atom = XA_STRING;
     2400    long unsigned int cLen = 0;
     2401    int format = 8;
     2402    clipConvertX11Targets(NULL, (XtPointer) pCtx, NULL, &atom, NULL, &cLen,
     2403                          &format);
    24592404    RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0,
    24602405                     (hTest, "Wrong targets reported: %02X\n",
     
    24652410    RTTEST_CHECK_MSG(hTest, clipTestTextFormatConversion(pCtx),
    24662411                     (hTest, "failed to select the right X11 text formats\n"));
    2467     RTTEST_CHECK_MSG(hTest, clipTestTargetUpdate(pCtx),
    2468                      (hTest, "incorrect reporting of new selection targets\n"));
    24692412
    24702413    /*** Utf-8 from VBox ***/
     
    25562499    /*** No data in VBox clipboard ***/
    25572500    RTTestSub(hTest, "an empty VBox clipboard");
     2501    clipSetSelectionValues("TEXT", XA_STRING, "", sizeof(""), 8);
    25582502    clipEmptyVBox(pCtx, VINF_SUCCESS);
    2559     RTTEST_CHECK_MSG(hTest, pCtx->fOwnsClipboard,
     2503    RTTEST_CHECK_MSG(hTest, g_ownsSel,
    25602504                     (hTest, "VBox grabbed the clipboard with no data and we ignored it\n"));
    25612505    testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING");
     
    25632507    /*** An unknown VBox format ***/
    25642508    RTTestSub(hTest, "reading an unknown VBox format");
     2509    clipSetSelectionValues("TEXT", XA_STRING, "", sizeof(""), 8);
    25652510    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2);
    25662511    ClipAnnounceFormatToX11(pCtx, 0xa0000);
    2567     RTTEST_CHECK_MSG(hTest, pCtx->fOwnsClipboard,
     2512    RTTEST_CHECK_MSG(hTest, g_ownsSel,
    25682513                     (hTest, "VBox grabbed the clipboard with unknown data and we ignored it\n"));
    25692514    testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING");
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