VirtualBox

Ignore:
Timestamp:
Jul 9, 2009 11:26:00 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49818
Message:

HostServices/SharedClipboard: refactor target handling, clean up test and fix repeat grabbing of the clipboard when X11 has no targets on offer

File:
1 edited

Legend:

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

    r21429 r21430  
    333333    CLIPFORMAT enmBestTextTarget = INVALID;
    334334    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
    335     AssertPtrReturn(pTargets, NIL_CLIPX11FORMAT);
     335    AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
    336336    for (unsigned i = 0; i < cTargets; ++i)
    337337    {
     
    390390    bool changed = false;
    391391    AssertPtrReturnVoid(pCtx);
    392     AssertPtrReturnVoid(pTargets);
     392    AssertReturnVoid(VALID_PTR(pTargets) || cTargets == 0);
    393393    CLIPX11FORMAT bestTextFormat;
    394394    bestTextFormat = clipGetTextFormatFromTargets(pCtx, pTargets, cTargets);
     
    414414
    415415/**
     416 * Update the context's information about targets currently supported by X11,
     417 * based on an array of X11 atoms.
     418 * @param  pCtx      the context to be updated
     419 * @param  pTargets  the array of atoms describing the targets supported
     420 * @param  cTargets  the size of the array @a pTargets
     421 */
     422static void clipUpdateX11Targets(CLIPBACKEND *pCtx, Atom *pTargets,
     423                                 size_t cTargets)
     424{
     425    bool changed = true;
     426
     427    Log3 (("%s: called\n", __PRETTY_FUNCTION__));
     428    if (pCtx->fOwnsClipboard)
     429        /* VBox raced us and we lost.  So we don't want to report anything. */
     430        return;
     431    clipGetFormatsFromTargets(pCtx, pTargets, cTargets, &changed);
     432    if (changed)
     433        clipReportFormatsToVBox(pCtx);
     434}
     435
     436/**
    416437 * Notify the VBox clipboard about available data formats, based on the
    417438 * "targets" information obtained from the X11 clipboard.
     
    425446    CLIPBACKEND *pCtx =
    426447            reinterpret_cast<CLIPBACKEND *>(pClientData);
    427     Atom *pTargets = reinterpret_cast<Atom *>(pValue);
    428     size_t cTargets = *pcLen;
    429     bool changed = true;
    430 
    431     Log3 (("%s: called\n", __PRETTY_FUNCTION__));
    432     if (pCtx->fOwnsClipboard)
    433         /* VBox raced us and we lost.  So we don't want to report anything. */
    434         changed = false;
    435     else if (   (*atomType == XT_CONVERT_FAIL)  /* timeout */
    436              || !pTargets  /* Conversion failed */)
    437         clipResetX11Formats(pCtx);
    438     else
    439         clipGetFormatsFromTargets(pCtx, pTargets, cTargets, &changed);
    440     if (changed)
    441         clipReportFormatsToVBox(pCtx);
     448    Atom *pTargets = (*atomType == XT_CONVERT_FAIL) ? NULL  /* timeout */
     449                                                    : (Atom *)pValue;
     450    size_t cTargets = pTargets ? *pcLen : 0;
     451    clipUpdateX11Targets(pCtx, pTargets, cTargets);
    442452    XtFree(reinterpret_cast<char *>(pValue));
    443453}
     
    15881598}
    15891599
    1590 static bool clipPollTargets()
    1591 {
    1592     if (!g_pfnPoller)
    1593         return false;
    1594     g_pfnPoller(g_pPollerData, NULL);
    1595     return true;
    1596 }
    1597 
    15981600/* For the purpose of the test case, we just execute the procedure to be
    15991601 * scheduled, as we are running single threaded. */
     
    19571959}
    19581960
     1961static void clipSendTargetUpdate(CLIPBACKEND *pCtx)
     1962{
     1963    clipUpdateX11Targets(pCtx, g_selTarget, RT_ELEMENTS(g_selTarget));
     1964}
     1965
    19591966/* Configure if and how the X11 TARGETS clipboard target will fail */
    19601967static void clipSetTargetsFailure(bool fTimeout, bool fFailure)
     
    20532060{
    20542061    bool retval = false;
    2055     if (!clipPollTargets())
    2056         RTPrintf("Failed to poll for targets\n");
    2057     else if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
     2062    clipSendTargetUpdate(pCtx);
     2063    if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    20582064        RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats());
    20592065    else
     
    21122118{
    21132119    bool retval = false;
    2114     if (!clipPollTargets())
    2115         RTPrintf("Failed to poll for targets\n");
    2116     else if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
     2120    clipSendTargetUpdate(pCtx);
     2121    if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    21172122        RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats());
    21182123    else
     
    23352340    clipSetSelectionValues("CLIPBOARD", XA_STRING, "Test",
    23362341                           sizeof("Test"), 8);
    2337     if (!clipPollTargets())
    2338     {
    2339         RTPrintf("Failed to poll for targets\n");
    2340         ++cErrs;
    2341     }
    2342     else if (clipQueryFormats() != 0)
     2342    clipSendTargetUpdate(pCtx);
     2343    if (clipQueryFormats() != 0)
    23432344    {
    23442345        RTPrintf("Failed to send a format update notification\n");
     
    23982399    }
    23992400
    2400     /*** Targets timeout from X11 ***/
    2401     RTPrintf(TEST_NAME ": TESTING X11 targets timeout\n");
    2402     clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world",
    2403                            sizeof("hello world"), 8);
    2404     clipSetTargetsFailure(true, false);
    2405     if (!clipPollTargets())
    2406     {
    2407         RTPrintf("Failed to poll for targets\n");
    2408         ++cErrs;
    2409     }
    2410     else if (clipQueryFormats() != 0)
    2411     {
    2412         RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats());
    2413         ++cErrs;
    2414     }
    2415 
    24162401    /*** Targets failure from X11 ***/
    24172402    RTPrintf(TEST_NAME ": TESTING X11 targets conversion failure\n");
     
    24192404                           sizeof("hello world"), 8);
    24202405    clipSetTargetsFailure(false, true);
    2421     if (!clipPollTargets())
    2422     {
    2423         RTPrintf("Failed to poll for targets\n");
    2424         ++cErrs;
    2425     }
    2426     else if (clipQueryFormats() != 0)
     2406    clipUpdateX11Targets(pCtx, NULL, 0);
     2407    if (clipQueryFormats() != 0)
    24272408    {
    24282409        RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats());
Note: See TracChangeset for help on using the changeset viewer.

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