VirtualBox

Changeset 81656 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Nov 4, 2019 4:40:12 PM (5 years ago)
Author:
vboxsync
Message:

Shared Clipboard/X11: More cleanup.

File:
1 edited

Legend:

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

    r81655 r81656  
    117117    { "INVALID", INVALID, 0 },
    118118    { "UTF8_STRING", UTF8, VBOX_SHCL_FMT_UNICODETEXT },
    119     { "text/plain;charset=UTF-8", UTF8,
    120       VBOX_SHCL_FMT_UNICODETEXT },
    121     { "text/plain;charset=utf-8", UTF8,
    122       VBOX_SHCL_FMT_UNICODETEXT },
     119    { "text/plain;charset=UTF-8", UTF8, VBOX_SHCL_FMT_UNICODETEXT },
     120    { "text/plain;charset=utf-8", UTF8, VBOX_SHCL_FMT_UNICODETEXT },
    123121    { "STRING", TEXT, VBOX_SHCL_FMT_UNICODETEXT },
    124122    { "TEXT", TEXT, VBOX_SHCL_FMT_UNICODETEXT },
    125123    { "text/plain", TEXT, VBOX_SHCL_FMT_UNICODETEXT },
    126124    { "text/html", HTML, VBOX_SHCL_FMT_HTML },
    127     { "text/html;charset=utf-8", HTML,
    128       VBOX_SHCL_FMT_HTML },
     125    { "text/html;charset=utf-8", HTML, VBOX_SHCL_FMT_HTML },
    129126    { "image/bmp", BMP, VBOX_SHCL_FMT_BITMAP },
    130127    { "image/x-bmp", BMP, VBOX_SHCL_FMT_BITMAP },
     
    141138
    142139
    143 /** Return the atom corresponding to a supported X11 format.
     140/**
     141 * Returns the atom corresponding to a supported X11 format.
    144142 * @param widget a valid Xt widget
    145143 */
     
    149147}
    150148
    151 /** Return the CLIPFORMAT corresponding to a supported X11 format. */
     149/**
     150 * Returns the CLIPFORMAT corresponding to a supported X11 format.
     151 */
    152152static CLIPFORMAT clipRealFormatForX11Format(CLIPX11FORMAT format)
    153153{
     
    155155}
    156156
    157 /** Return the atom corresponding to a supported X11 format. */
     157/** Returns the atom corresponding to a supported X11 format. */
    158158static uint32_t clipVBoxFormatForX11Format(CLIPX11FORMAT format)
    159159{
     
    161161}
    162162
    163 /** Lookup the X11 format matching a given X11 atom.
    164  * @returns the format on success, NIL_CLIPX11FORMAT on failure
    165  * @param   widget a valid Xt widget
     163/**
     164 * Looks up the X11 format matching a given X11 atom.
     165 *
     166 * @returns The format on success, NIL_CLIPX11FORMAT on failure.
     167 * @param                       Widget a valid Xt widget.
    166168 */
    167169static CLIPX11FORMAT clipFindX11FormatByAtom(CLIPBACKEND *pCtx, Atom atomFormat)
     
    174176
    175177#ifdef TESTCASE
    176 /** Lookup the X11 format matching a given X11 atom text.
     178/**
     179 * Looks up the X11 format matching a given X11 atom text.
     180 *
    177181 * @returns the format on success, NIL_CLIPX11FORMAT on failure
    178  * @param   widget a valid Xt widget
     182 * @param                       Widget a valid Xt widget.
    179183 */
    180184static CLIPX11FORMAT clipFindX11FormatByAtomText(const char *pcsz)
     
    190194 * Enumerates supported X11 clipboard formats corresponding to a given VBox
    191195 * format.
    192  * @returns the next matching X11 format in the list, or NIL_CLIPX11FORMAT if
    193  *          there are no more
     196 *
     197 * @returns The next matching X11 format in the list, or NIL_CLIPX11FORMAT if
     198 *          there are no more.
    194199 * @param lastFormat  The value returned from the last call of this function.
    195200 *                    Use NIL_CLIPX11FORMAT to start the enumeration.
     
    273278} g_contexts[CLIP_MAX_CONTEXTS];
    274279
    275 /** Register a new X11 clipboard context. */
     280/** Registers a new X11 clipboard context. */
    276281static int clipRegisterContext(CLIPBACKEND *pCtx)
    277282{
     
    319324}
    320325
    321 /** Find an X11 clipboard context. */
     326/** Finds an X11 clipboard context. */
    322327static CLIPBACKEND *clipLookupContext(Widget widget)
    323328{
     
    335340}
    336341
    337 /** Convert an atom name string to an X11 atom, looking it up in a cache
    338  *  before asking the server */
     342/** Converts an atom name string to an X11 atom, looking it up in a cache
     343 *  before asking the server. */
    339344static Atom clipGetAtom(CLIPBACKEND *pCtx, const char *pszName)
    340345{
     
    379384
    380385/**
    381  * Report the formats currently supported by the X11 clipboard to VBox.
     386 * Reports the formats currently supported by the X11 clipboard to VBox.
    382387 */
    383388static void clipReportFormatsToVBox(CLIPBACKEND *pCtx)
     
    394399
    395400/**
    396  * Forget which formats were previously in the X11 clipboard.  Called when we
     401 * Forgets which formats were previously in the X11 clipboard.  Called when we
    397402 * grab the clipboard. */
    398403static void clipResetX11Formats(CLIPBACKEND *pCtx)
     
    403408}
    404409
    405 /** Tell VBox that X11 currently has nothing in its clipboard. */
     410/** Tells VBox that X11 currently has nothing in its clipboard. */
    406411static void clipReportEmptyX11CB(CLIPBACKEND *pCtx)
    407412{
     
    414419 * format we can support, and if so choose the ones we prefer (e.g. we like
    415420 * Utf8 better than plain text).
    416  * @param  pCtx      the clipboard backend context structure
    417  * @param  pTargets  the list of targets
    418  * @param  cTargets  the size of the list in @a pTargets
     421 *
     422 * @return Supported X clipboard format.
     423 * @param  pCtx                 The clipboard backend context structure.
     424 * @param  pTargets             The list of targets.
     425 * @param  cTargets             The size of the list in @a pTargets.
    419426 */
    420427static CLIPX11FORMAT clipGetTextFormatFromTargets(CLIPBACKEND *pCtx,
     
    422429                                                  size_t cTargets)
    423430{
     431    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
     432    AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
     433
    424434    CLIPX11FORMAT bestTextFormat = NIL_CLIPX11FORMAT;
    425435    CLIPFORMAT enmBestTextTarget = INVALID;
    426     AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
    427     AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
    428436    for (unsigned i = 0; i < cTargets; ++i)
    429437    {
     
    446454static bool clipTestTextFormatConversion(CLIPBACKEND *pCtx)
    447455{
    448     bool success = true;
     456    bool fSuccess = true;
    449457    CLIPX11FORMAT targets[2];
    450458    CLIPX11FORMAT x11Format;
     
    453461    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2);
    454462    if (clipRealFormatForX11Format(x11Format) != TEXT)
    455         success = false;
     463        fSuccess = false;
    456464    targets[0] = clipFindX11FormatByAtomText("UTF8_STRING");
    457465    targets[1] = clipFindX11FormatByAtomText("text/plain");
    458466    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2);
    459467    if (clipRealFormatForX11Format(x11Format) != UTF8)
    460         success = false;
    461     return success;
     468        fSuccess = false;
     469    return fSuccess;
    462470}
    463471#endif
    464472
    465473/**
    466  * Go through an array of X11 clipboard targets to see if they contain a bitmap
     474 * Goes through an array of X11 clipboard targets to see if they contain a bitmap
    467475 * format we can support, and if so choose the ones we prefer (e.g. we like
    468476 * BMP better than PNG because we don't have to convert).
    469  * @param  pCtx      the clipboard backend context structure
    470  * @param  pTargets  the list of targets
    471  * @param  cTargets  the size of the list in @a pTargets
     477 *
     478 * @return Supported X clipboard format.
     479 * @param  pCtx                 The clipboard backend context structure.
     480 * @param  pTargets             The list of targets.
     481 * @param  cTargets             The size of the list in @a pTargets.
    472482 */
    473483static CLIPX11FORMAT clipGetBitmapFormatFromTargets(CLIPBACKEND *pCtx,
     
    475485                                                    size_t cTargets)
    476486{
     487    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
     488    AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
     489
    477490    CLIPX11FORMAT bestBitmapFormat = NIL_CLIPX11FORMAT;
    478491    CLIPFORMAT enmBestBitmapTarget = INVALID;
    479     AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
    480     AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
    481492    for (unsigned i = 0; i < cTargets; ++i)
    482493    {
     
    497508
    498509/**
    499  * Go through an array of X11 clipboard targets to see if they contain a HTML
    500  * format we can support, and if so choose the ones we prefer
    501  * @param  pCtx      the clipboard backend context structure
    502  * @param  pTargets  the list of targets
    503  * @param  cTargets  the size of the list in @a pTargets
     510 * Goes through an array of X11 clipboard targets to see if they contain a HTML
     511 * format we can support, and if so choose the ones we prefer.
     512 *
     513 * @return Supported X clipboard format.
     514 * @param  pCtx                 The clipboard backend context structure.
     515 * @param  pTargets             The list of targets.
     516 * @param  cTargets             The size of the list in @a pTargets.
    504517 */
    505518static CLIPX11FORMAT clipGetHtmlFormatFromTargets(CLIPBACKEND *pCtx,
     
    507520                                                  size_t cTargets)
    508521{
     522    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
     523    AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
     524
    509525    CLIPX11FORMAT bestHTMLFormat = NIL_CLIPX11FORMAT;
    510526    CLIPFORMAT enmBestHtmlTarget = INVALID;
    511     AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
    512     AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
    513527    for (unsigned i = 0; i < cTargets; ++i)
    514528    {
     
    529543
    530544/**
    531  * Go through an array of X11 clipboard targets to see if we can support any
     545 * Goes through an array of X11 clipboard targets to see if we can support any
    532546 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8
    533547 * better than plain text).
    534  * @param  pCtx      the clipboard backend context structure
    535  * @param  pTargets  the list of targets
    536  * @param  cTargets  the size of the list in @a pTargets
     548 *
     549 * @param  pCtx                 The clipboard backend context structure.
     550 * @param  pTargets             The list of targets.
     551 * @param  cTargets             The size of the list in @a pTargets.
    537552 */
    538553static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx,
     
    565580
    566581/**
    567  * Update the context's information about targets currently supported by X11,
     582 * Updates the context's information about targets currently supported by X11,
    568583 * based on an array of X11 atoms.
    569  * @param  pCtx      the context to be updated
    570  * @param  pTargets  the array of atoms describing the targets supported
    571  * @param  cTargets  the size of the array @a pTargets
    572  */
    573 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets,
    574                                 size_t cTargets)
    575 {
    576     LogRel2 (("%s: called\n", __FUNCTION__));
     584 *
     585 * @param  pCtx                 The context to be updated.
     586 * @param  pTargets             The array of atoms describing the targets supported.
     587 * @param  cTargets             The size of the array @a pTargets.
     588 */
     589static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets, size_t cTargets)
     590{
     591    LogFlowFuncEnter();
    577592#ifndef VBOX_AFTER_5_2
    578593    pCtx->fBusy = false;
     
    585600    }
    586601#endif
    587     if (pTargets == NULL) {
     602    if (pTargets == NULL)
     603    {
    588604        /* No data available */
    589605        clipReportEmptyX11CB(pCtx);
     
    595611
    596612/**
    597  * Notify the VBox clipboard about available data formats, based on the
     613 * Notifies the VBox clipboard about available data formats, based on the
    598614 * "targets" information obtained from the X11 clipboard.
     615 *
    599616 * @note  Callback for XtGetSelectionValue
    600617 * @note  This function is treated as API glue, and as such is not part of any
     
    607624{
    608625    RT_NOREF(piFormat);
     626
    609627    CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pClient);
    610628    Atom *pAtoms = (Atom *)pValue;
    611629    unsigned i, j;
    612     LogRel2(("%s: pValue=%p, *pcLen=%u, *atomType=%d%s\n", __FUNCTION__,
    613              pValue, *pcLen, *atomType,
    614              *atomType == XT_CONVERT_FAIL ? " (XT_CONVERT_FAIL)" : ""));
     630
     631    LogFlowFunc(("pValue=%p, *pcLen=%u, *atomType=%d%s\n",
     632                 pValue, *pcLen, *atomType, *atomType == XT_CONVERT_FAIL ? " (XT_CONVERT_FAIL)" : ""));
     633
    615634    CLIPX11FORMAT *pFormats = NULL;
    616     if (*pcLen && pValue && (*atomType != XT_CONVERT_FAIL /* time out */))
    617         pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT));
     635    if (   *pcLen
     636        && pValue
     637        && (*atomType != XT_CONVERT_FAIL /* time out */))
     638    {
     639       pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT));
     640    }
    618641#if defined(DEBUG) && !defined(TESTCASE)
    619642    if (pValue)
     
    623646            {
    624647                char *pszName = XGetAtomName(XtDisplay(widget), pAtoms[i]);
    625                 LogRel2(("%s: found target %s\n", __FUNCTION__,
    626                          pszName));
     648                LogFunc(("Found target '%s'\n", pszName));
    627649                XFree(pszName);
    628650            }
    629651            else
    630                 LogRel2(("%s: found empty target\n", __FUNCTION__));
     652                LogFunc(("Found empty target\n"));
    631653    }
    632654#endif
     
    649671    }
    650672    else
    651         LogRel2(("%s: reporting empty targets (none reported or allocation failure).\n",
    652                  __FUNCTION__));
     673        LogFunc(("Reporting empty targets (none reported or allocation failure)\n"));
     674
    653675    clipUpdateX11Targets(pCtx, pFormats, *pcLen);
    654676    RTMemFree(pFormats);
     677
    655678    XtFree(reinterpret_cast<char *>(pValue));
    656679}
     
    665688static void clipQueryX11CBFormats(CLIPBACKEND *pCtx)
    666689{
    667     LogRel2 (("%s: requesting the targets that the X11 clipboard offers\n",
    668            __PRETTY_FUNCTION__));
     690    LogFlowFuncEnter();
     691
    669692#ifndef VBOX_AFTER_5_2
    670693    if (pCtx->fBusy)
     
    675698    pCtx->fBusy = true;
    676699#endif
     700
    677701#ifndef TESTCASE
    678702    XtGetSelectionValue(pCtx->widget,
     
    688712#ifndef TESTCASE
    689713
    690 typedef struct {
     714typedef struct
     715{
    691716    int type;                   /* event base */
    692717    unsigned long serial;
     
    702727
    703728/**
    704  * Wait until an event arrives and handle it if it is an XFIXES selection
     729 * Waits until an event arrives and handle it if it is an XFIXES selection
    705730 * event, which Xt doesn't know about.
    706731 */
     
    714739
    715740    if (XtAppPeekEvent(pCtx->appContext, &event.event))
     741    {
    716742        if (   (event.event.type == pCtx->fixesEventBase)
    717743            && (event.fixes.owner != XtWindow(pCtx->widget)))
     
    723749                clipReportEmptyX11CB(pCtx);
    724750        }
     751    }
    725752}
    726753
     
    732759{
    733760    RT_NOREF(hThreadSelf);
    734     LogRel(("Shared clipboard: Starting shared clipboard thread\n"));
     761    LogRel(("Shared Clipboard: Starting event thread\n"));
    735762
    736763    CLIPBACKEND *pCtx = (CLIPBACKEND *)pvUser;
     
    743770        XtAppProcessEvent(pCtx->appContext, XtIMAll);
    744771    }
    745     LogRel(("Shared clipboard: Shared clipboard thread terminated successfully\n"));
     772    LogRel(("Shared Clipboard: Event thread terminated successfully\n"));
    746773    return VINF_SUCCESS;
    747774}
     
    846873static void clipDrainWakeupPipe(XtPointer pUserData, int *, XtInputId *)
    847874{
     875    LogFlowFuncEnter();
     876
    848877    CLIPBACKEND *pCtx = (CLIPBACKEND *)pUserData;
    849878    char acBuf[WAKE_UP_STRING_LEN];
    850879
    851     LogRel2(("clipDrainWakeupPipe: called\n"));
    852880    while (read(pCtx->wakeupPipeRead, acBuf, sizeof(acBuf)) > 0) {}
    853881}
     
    874902    if (NULL == pDisplay)
    875903    {
    876         LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running.\n"));
     904        LogRel(("Shared Clipboard: Failed to connect to the X11 clipboard - the window system may not be running\n"));
    877905        rc = VERR_NOT_SUPPORTED;
    878906    }
     
    882910        rc = clipLoadXFixes(pDisplay, pCtx);
    883911        if (RT_FAILURE(rc))
    884            LogRel(("Shared clipboard: Failed to load the XFIXES extension.\n"));
     912           LogRel(("Shared Clipboard: Failed to load the XFIXES extension\n"));
    885913    }
    886914#endif
     
    893921        if (NULL == pCtx->widget)
    894922        {
    895             LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager.\n"));
     923            LogRel(("Shared Clipboard: Failed to construct the X11 window for the shared clipboard manager\n"));
    896924            rc = VERR_NO_MEMORY;
    897925        }
     
    924952            rc = RTErrConvertFromErrno(errno);
    925953        if (RT_FAILURE(rc))
    926             LogRel(("Shared clipboard: Failed to setup the termination mechanism.\n"));
     954            LogRel(("Shared Clipboard: Failed to setup the termination mechanism\n"));
    927955    }
    928956    else
     
    931959        clipUninit(pCtx);
    932960    if (RT_FAILURE(rc))
    933         LogRel(("Shared clipboard: Initialisation failed: %Rrc\n", rc));
     961        LogRel(("Shared Clipboard: Initialisation failed: %Rrc\n", rc));
    934962    return rc;
    935963}
    936964
    937965/**
    938  * Construct the X11 backend of the shared clipboard.
     966 * Constructs the X11 backend of the shared clipboard.
     967 *
    939968 * @note  X11 backend code
    940969 */
     
    950979         * This is important for VBoxHeadless.
    951980         */
    952         LogRelFunc(("X11 DISPLAY variable not set -- disabling shared clipboard\n"));
     981        LogRel(("Shared Clipboard: X11 DISPLAY variable not set -- disabling shared clipboard\n"));
    953982        pCtx->fHaveX11 = false;
    954983        return pCtx;
     
    957986    pCtx->fHaveX11 = true;
    958987
    959     LogRel(("Shared clipboard: Initializing X11 clipboard backend\n"));
     988    LogRel(("Shared Clipboard: Initializing X11 clipboard backend\n"));
    960989    if (pCtx)
    961990        pCtx->pFrontend = pFrontend;
     
    964993
    965994/**
    966  * Destruct the shared clipboard X11 backend.
     995 * Destructs the shared clipboard X11 backend.
     996 *
    967997 * @note  X11 backend code
    968998 */
     
    9841014{
    9851015    int rc = VINF_SUCCESS;
    986     LogFlowFunc(("\n"));
     1016
    9871017    /*
    9881018     * Immediately return if we are not connected to the X server.
     
    10041034        if (RT_FAILURE(rc))
    10051035        {
    1006             LogRel(("Shared clipboard: Failed to start the shared clipboard thread.\n"));
     1036            LogRel(("Shared Clipboard: Failed to start the shared clipboard thread\n"));
    10071037            clipUninit(pCtx);
    10081038        }
     
    10301060        return VINF_SUCCESS;
    10311061
    1032     LogRelFunc(("stopping the shared clipboard X11 backend\n"));
     1062    LogRel(("Shared Clipboard: Stopping X11 backend\n"));
     1063
    10331064    /* Write to the "stop" pipe */
    10341065    clipQueueToEventThread(pCtx, clipStopEventThreadWorker, (XtPointer) pCtx);
     
    10461077#endif
    10471078    if (RT_SUCCESS(rc))
     1079    {
    10481080        AssertRC(rcThread);
     1081    }
    10491082    else
    1050         LogRelFunc(("rc=%Rrc\n", rc));
     1083        LogRel(("Shared Clipboard: Stopping X11 backend failed with %Rrc\n", rc));
     1084
    10511085    clipUninit(pCtx);
    1052     LogFlowFunc(("returning %Rrc.\n", rc));
     1086
    10531087    RT_NOREF_PV(rcThread);
    10541088    return rc;
     
    10561090
    10571091/**
    1058  * Satisfy a request from X11 for clipboard targets supported by VBox.
    1059  *
    1060  * @returns iprt status code
    1061  * @param  atomTypeReturn The type of the data we are returning
    1062  * @param  pValReturn     A pointer to the data we are returning. This
    1063  *                        should be set to memory allocated by XtMalloc,
    1064  *                        which will be freed later by the Xt toolkit.
    1065  * @param  pcLenReturn    The length of the data we are returning
    1066  * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are
    1067  *                        returning
     1092 * Satisfies a request from X11 for clipboard targets supported by VBox.
     1093 *
     1094 * @returns VBox status code.
     1095 * @param  atomTypeReturn       The type of the data we are returning.
     1096 * @param  pValReturn           A pointer to the data we are returning. This
     1097 *                              should be set to memory allocated by XtMalloc,
     1098 *                              which will be freed later by the Xt toolkit.
     1099 * @param  pcLenReturn          The length of the data we are returning.
     1100 * @param  piFormatReturn       The format (8bit, 16bit, 32bit) of the data we are
     1101 *                              returning.
    10681102 * @note  X11 backend code, called by the XtOwnSelection callback.
    10691103 */
     
    10731107                                int *piFormatReturn)
    10741108{
    1075     Atom *atomTargets = (Atom *)XtMalloc(  (MAX_CLIP_X11_FORMATS + 3)
    1076                                          * sizeof(Atom));
     1109    LogFlowFuncEnter();
     1110
     1111    const unsigned cFixedTargets = 3;
     1112
     1113    Atom *atomTargets = (Atom *)XtMalloc((MAX_CLIP_X11_FORMATS + cFixedTargets) * sizeof(Atom));
    10771114    unsigned cTargets = 0;
    1078     LogFlowFunc (("called\n"));
    10791115    CLIPX11FORMAT format = NIL_CLIPX11FORMAT;
    10801116    do
     
    10871123        }
    10881124    } while (format != NIL_CLIPX11FORMAT);
    1089     /* We always offer these */
    1090     atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS");
     1125
     1126    /* We always offer these fixed targets. */
     1127    atomTargets[cTargets]     = clipGetAtom(pCtx, "TARGETS");
    10911128    atomTargets[cTargets + 1] = clipGetAtom(pCtx, "MULTIPLE");
    10921129    atomTargets[cTargets + 2] = clipGetAtom(pCtx, "TIMESTAMP");
     1130
    10931131    *atomTypeReturn = XA_ATOM;
    10941132    *pValReturn = (XtPointer)atomTargets;
    1095     *pcLenReturn = cTargets + 3;
     1133    *pcLenReturn = cTargets + cFixedTargets;
    10961134    *piFormatReturn = 32;
     1135
    10971136    return VINF_SUCCESS;
    10981137}
    10991138
    1100 /** This is a wrapper around ClipRequestDataForX11Callback that will cache the
     1139/**
     1140 * This is a wrapper around ClipRequestDataForX11Callback that will cache the
    11011141 * data returned.
    11021142 */
     
    11241164        rc = ClipRequestDataForX11Callback(pCtx->pFrontend, u32Format,
    11251165                                           ppv, pcb);
    1126     LogFlowFunc(("returning %Rrc\n", rc));
    11271166    if (RT_SUCCESS(rc))
    11281167        LogFlowFunc(("*ppv=%.*ls, *pcb=%u\n", *pcb, *ppv, *pcb));
     1168
     1169    LogFlowFuncLeaveRC(rc);
    11291170    return rc;
    11301171}
    11311172
    11321173/**
    1133  * Calculate a buffer size large enough to hold the source Windows format
    1134  * text converted into Unix Utf8, including the null terminator
    1135  * @returns iprt status code
    1136  * @param  pwsz       the source text in UCS-2 with Windows EOLs
    1137  * @param  cwc        the size in USC-2 elements of the source text, with or
    1138  *                    without the terminator
    1139  * @param  pcbActual  where to store the buffer size needed
     1174 * Calculates a buffer size large enough to hold the source Windows format
     1175 * text converted into Unix Utf8, including the null terminator.
     1176 *
     1177 * @returns VBox status code.
     1178 * @param  pwsz                 The source text in UCS-2 with Windows EOLs.
     1179 * @param  cwc                  The size in USC-2 elements of the source text, with or
     1180 *                              without the terminator.
     1181 * @param  pcbActual            Where to store the buffer size needed.
    11401182 */
    11411183static int clipWinTxtBufSizeForUtf8(PRTUTF16 pwsz, size_t cwc,
     
    11501192
    11511193/**
    1152  * Convert text from Windows format (UCS-2 with CRLF line endings) to standard
    1153  * Utf-8.
    1154  *
    1155  * @returns iprt status code
    1156  *
    1157  * @param  pwszSrc    the text to be converted
    1158  * @param  cbSrc      the length of @a pwszSrc in bytes
    1159  * @param  pszBuf     where to write the converted string
    1160  * @param  cbBuf      the size of the buffer pointed to by @a pszBuf
    1161  * @param  pcbActual  where to store the size of the converted string.
    1162  *                    optional.
     1194 * Converts text from Windows format (UCS-2 with CRLF line endings) to standard Utf-8.
     1195 *
     1196 * @returns VBox status code.
     1197 * @param  pwszSrc              The text to be converted.
     1198 * @param  cbSrc                The length of @a pwszSrc in bytes.
     1199 * @param  pszBuf               Where to write the converted string.
     1200 * @param  cbBuf                The size of the buffer pointed to by @a pszBuf.
     1201 * @param  pcbActual            Where to store the size of the converted string.
     1202 *                              optional.
    11631203 */
    11641204static int clipWinTxtToUtf8(PRTUTF16 pwszSrc, size_t cbSrc, char *pszBuf,
     
    11901230    if (pcbActual)
    11911231        *pcbActual = cbDest + 1;
    1192     LogFlowFunc(("returning %Rrc\n", rc));
     1232
    11931233    if (RT_SUCCESS(rc))
    1194         LogFlowFunc (("converted string is %.*s. Returning.\n", cbDest,
    1195                       pszBuf));
     1234        LogFlowFunc (("converted string is %.*s. Returning.\n", cbDest, pszBuf));
     1235
     1236    LogFlowFuncLeaveRC(rc);
    11961237    return rc;
    11971238}
    11981239
    11991240/**
    1200  * Satisfy a request from X11 to convert the clipboard text to Utf-8.  We
     1241 * Satisfies a request from X11 to convert the clipboard text to Utf-8.  We
    12011242 * return null-terminated text, but can cope with non-null-terminated input.
    12021243 *
    1203  * @returns iprt status code
    1204  * @param  pDisplay        an X11 display structure, needed for conversions
    1205  *                         performed by Xlib
    1206  * @param  pv              the text to be converted (UCS-2 with Windows EOLs)
    1207  * @param  cb              the length of the text in @cb in bytes
    1208  * @param  atomTypeReturn  where to store the atom for the type of the data
    1209  *                         we are returning
    1210  * @param  pValReturn      where to store the pointer to the data we are
    1211  *                         returning.  This should be to memory allocated by
    1212  *                         XtMalloc, which will be freed by the Xt toolkit
    1213  *                         later.
    1214  * @param  pcLenReturn     where to store the length of the data we are
    1215  *                         returning
    1216  * @param  piFormatReturn  where to store the bit width (8, 16, 32) of the
    1217  *                         data we are returning
     1244 * @returns VBox status code.
     1245 * @param  pDisplay             An X11 display structure, needed for conversions
     1246 *                              performed by Xlib.
     1247 * @param  pv                   The text to be converted (UCS-2 with Windows EOLs).
     1248 * @param  cb                   The length of the text in @cb in bytes.
     1249 * @param  atomTypeReturn       Where to store the atom for the type of the data
     1250 *                              we are returning.
     1251 * @param  pValReturn           Where to store the pointer to the data we are
     1252 *                              returning.  This should be to memory allocated by
     1253 *                              XtMalloc, which will be freed by the Xt toolkit
     1254 *                              later.
     1255 * @param  pcLenReturn          Where to store the length of the data we are
     1256 *                              returning.
     1257 * @param  piFormatReturn       Where to store the bit width (8, 16, 32) of the
     1258 *                              data we are returning.
    12181259 */
    12191260static int clipWinTxtToUtf8ForX11CB(Display *pDisplay, PRTUTF16 pwszSrc,
     
    12481289
    12491290/**
    1250  * Satisfy a request from X11 to convert the clipboard HTML fragment to Utf-8.  We
     1291 * Satisfies a request from X11 to convert the clipboard HTML fragment to Utf-8.  We
    12511292 * return null-terminated text, but can cope with non-null-terminated input.
    12521293 *
    1253  * @returns iprt status code
    1254  * @param  pDisplay        an X11 display structure, needed for conversions
    1255  *                         performed by Xlib
    1256  * @param  pv              the text to be converted (UTF8 with Windows EOLs)
    1257  * @param  cb              the length of the text in @cb in bytes
    1258  * @param  atomTypeReturn  where to store the atom for the type of the data
    1259  *                         we are returning
    1260  * @param  pValReturn      where to store the pointer to the data we are
    1261  *                         returning.  This should be to memory allocated by
    1262  *                         XtMalloc, which will be freed by the Xt toolkit
    1263  *                         later.
    1264  * @param  pcLenReturn     where to store the length of the data we are
    1265  *                         returning
    1266  * @param  piFormatReturn  where to store the bit width (8, 16, 32) of the
    1267  *                         data we are returning
     1294 * @returns VBox status code.
     1295 * @param  pDisplay             An X11 display structure, needed for conversions
     1296 *                              performed by Xlib.
     1297 * @param  pv                   The text to be converted (UTF8 with Windows EOLs).
     1298 * @param  cb                   The length of the text in @cb in bytes.
     1299 * @param  atomTypeReturn       Where to store the atom for the type of the data
     1300 *                              we are returning.
     1301 * @param  pValReturn           Where to store the pointer to the data we are
     1302 *                              returning.  This should be to memory allocated by
     1303 *                              XtMalloc, which will be freed by the Xt toolkit later.
     1304 * @param  pcLenReturn          Where to store the length of the data we are returning.
     1305 * @param  piFormatReturn       Where to store the bit width (8, 16, 32) of the
     1306 *                              data we are returning.
    12681307 */
    12691308static int clipWinHTMLToUtf8ForX11CB(Display *pDisplay, const char *pszSrc,
     
    12961335/**
    12971336 * Does this atom correspond to one of the two selection types we support?
    1298  * @param  widget   a valid Xt widget
    1299  * @param  selType  the atom in question
     1337 *
     1338 * @param  widget               A valid Xt widget.
     1339 * @param  selType              The atom in question.
    13001340 */
    13011341static bool clipIsSupportedSelectionType(CLIPBACKEND *pCtx, Atom selType)
     
    13061346
    13071347/**
    1308  * Remove a trailing nul character from a string by adjusting the string
     1348 * Removes a trailing nul character from a string by adjusting the string
    13091349 * length.  Some X11 applications don't like zero-terminated text...
    1310  * @param  pText   the text in question
    1311  * @param  pcText  the length of the text, adjusted on return
    1312  * @param  format  the format of the text
     1350 *
     1351 * @param  pText                The text in question.
     1352 * @param  pcText               The length of the text, adjusted on return.
     1353 * @param  format               The format of the text.
    13131354 */
    13141355static void clipTrimTrailingNul(XtPointer pText, unsigned long *pcText,
     
    13181359    AssertPtrReturnVoid(pcText);
    13191360    AssertReturnVoid((format == UTF8) || (format == TEXT) || (format == HTML));
     1361
    13201362    if (((char *)pText)[*pcText - 1] == '\0')
    13211363       --(*pcText);
     
    13291371{
    13301372    int rc = VINF_SUCCESS;
     1373
    13311374    CLIPX11FORMAT x11Format = clipFindX11FormatByAtom(pCtx, *atomTarget);
    13321375    CLIPFORMAT format = clipRealFormatForX11Format(x11Format);
     1376
    13331377    if (   ((format == UTF8) || (format == TEXT))
    13341378        && (pCtx->vboxFormats & VBOX_SHCL_FMT_UNICODETEXT))
     
    14091453    else
    14101454        rc = VERR_NOT_SUPPORTED;
     1455
     1456    LogFlowFuncLeaveRC(rc);
    14111457    return rc;
    14121458}
    14131459
    14141460/**
    1415  * Return VBox's clipboard data for an X11 client.
     1461 * Returns VBox's clipboard data for an X11 client.
     1462 *
    14161463 * @note  X11 backend code, callback for XtOwnSelection
    14171464 */
     
    14231470                                          int *piFormatReturn)
    14241471{
     1472    LogFlowFuncEnter();
     1473
    14251474    CLIPBACKEND *pCtx = clipLookupContext(widget);
    14261475    int rc = VINF_SUCCESS;
    14271476
    1428     LogFlowFunc(("\n"));
    14291477    if (!pCtx)
    14301478        return false;
     1479
    14311480    if (!clipIsSupportedSelectionType(pCtx, *atomSelection))
    14321481        return false;
     1482
    14331483    if (*atomTarget == clipGetAtom(pCtx, "TARGETS"))
    14341484        rc = clipCreateX11Targets(pCtx, atomTypeReturn, pValReturn,
     
    14371487        rc = clipConvertVBoxCBForX11(pCtx, atomTarget, atomTypeReturn,
    14381488                                     pValReturn, pcLenReturn, piFormatReturn);
     1489
    14391490    LogFlowFunc(("returning, internal status code %Rrc\n", rc));
    14401491    return RT_SUCCESS(rc);
     
    14611512
    14621513/**
    1463  * Take possession of the X11 clipboard (and middle-button selection).
     1514 * Takes possession of the X11 clipboard (and middle-button selection).
    14641515 */
    14651516static void clipGrabX11CB(CLIPBACKEND *pCtx, uint32_t u32Formats)
     
    14881539 * Worker function for ClipAnnounceFormatToX11 which runs on the
    14891540 * event thread.
    1490  * @param pUserData  Pointer to a CLIPNEWVBOXFORMATS structure containing
    1491  *                   information about the VBox formats available and the
    1492  *                   clipboard context data.  Must be freed by the worker.
     1541 *
     1542 * @param pUserData             Pointer to a CLIPNEWVBOXFORMATS structure containing
     1543 *                              information about the VBox formats available and the
     1544 *                              clipboard context data.  Must be freed by the worker.
    14931545 */
    14941546static void clipNewVBoxFormatsWorker(void *pUserData,
     
    14971549    CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pUserData;
    14981550    CLIPBACKEND *pCtx = pFormats->pCtx;
    1499     uint32_t u32Formats = pFormats->formats;
     1551
     1552    uint32_t fFormats = pFormats->formats;
     1553
    15001554    RTMemFree(pFormats);
    1501     LogFlowFunc (("u32Formats=0x%x\n", u32Formats));
     1555
     1556    LogFlowFunc (("fFormats=0x%x\n", fFormats));
     1557
    15021558    clipInvalidateVBoxCBCache(pCtx);
    1503     clipGrabX11CB(pCtx, u32Formats);
     1559    clipGrabX11CB(pCtx, fFormats);
    15041560    clipResetX11Formats(pCtx);
    1505     LogFlowFunc(("returning\n"));
     1561
     1562    LogFlowFuncLeave();
    15061563}
    15071564
     
    15091566 * VBox is taking possession of the shared clipboard.
    15101567 *
    1511  * @param u32Formats Clipboard formats that VBox is offering
     1568 * @param                       u32Formats Clipboard formats that VBox is offering.
    15121569 * @note  X11 backend code
    15131570 */
     
    15401597
    15411598/**
    1542  * Massage generic Utf16 with CR end-of-lines into the format Windows expects
     1599 * Massages generic Utf16 with CR end-of-lines into the format Windows expects
    15431600 * and return the result in a RTMemAlloc allocated buffer.
    15441601 *
    1545  * @returns  IPRT status code
    1546  * @param  pwcSrc     The source Utf16
    1547  * @param  cwcSrc     The number of 16bit elements in @a pwcSrc, not counting
    1548  *                    the terminating zero
    1549  * @param  ppwszDest  Where to store the buffer address
    1550  * @param  pcbDest    On success, where to store the number of bytes written.
    1551  *                    Undefined otherwise.  Optional
     1602 * @returns VBox status code.
     1603 * @param  pwcSrc               The source as Utf16.
     1604 * @param  cwcSrc               The number of 16bit elements in @a pwcSrc, not counting
     1605 *                              the terminating zero.
     1606 * @param  ppwszDest            Where to store the buffer address.
     1607 * @param  pcbDest              On success, where to store the number of bytes written.
     1608 *                              Undefined otherwise.  Optional.
    15521609 */
    15531610static int clipUtf16ToWinTxt(RTUTF16 *pwcSrc, size_t cwcSrc,
     
    15921649
    15931650/**
    1594  * Convert Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it
     1651 * Converts Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it
    15951652 * and return the result in a RTMemAlloc allocated buffer.
    15961653 *
    1597  * @returns  IPRT status code
    1598  * @param  pcSrc      The source Utf-8
    1599  * @param  cbSrc      The size of the source in bytes, not counting the
    1600  *                    terminating zero
    1601  * @param  ppwszDest  Where to store the buffer address
    1602  * @param  pcbDest    On success, where to store the number of bytes written.
    1603  *                    Undefined otherwise.  Optional
     1654 * @returns VBox status code.
     1655 * @param  pcSrc                The source Utf-8.
     1656 * @param  cbSrc                The size of the source in bytes, not counting the
     1657 *                              terminating zero.
     1658 * @param  ppwszDest            Where to store the buffer address.
     1659 * @param  pcbDest              On success, where to store the number of bytes written.
     1660 *                              Undefined otherwise.  Optional.
    16041661 */
    16051662static int clipUtf8ToWinTxt(const char *pcSrc, unsigned cbSrc,
     
    16281685
    16291686/**
    1630  * Convert Latin-1 text with CR end-of-lines into Utf-16 as Windows expects
     1687 * Converts Latin-1 text with CR end-of-lines into Utf-16 as Windows expects
    16311688 * it and return the result in a RTMemAlloc allocated buffer.
    16321689 *
    1633  * @returns  IPRT status code
    1634  * @param  pcSrc      The source text
    1635  * @param  cbSrc      The size of the source in bytes, not counting the
    1636  *                    terminating zero
    1637  * @param  ppwszDest  Where to store the buffer address
    1638  * @param  pcbDest    On success, where to store the number of bytes written.
    1639  *                    Undefined otherwise.  Optional
     1690 * @returns VBox status code.
     1691 * @param  pcSrc                The source text.
     1692 * @param  cbSrc                The size of the source in bytes, not counting the
     1693 *                              terminating zero.
     1694 * @param  ppwszDest            Where to store the buffer address.
     1695 * @param  pcbDest              On success, where to store the number of bytes written.
     1696 *                              Undefined otherwise.  Optional.
    16401697 */
    16411698static int clipLatin1ToWinTxt(char *pcSrc, unsigned cbSrc,
     
    17021759
    17031760/**
    1704 * Convert Utf16 text into UTF8 as Windows expects
     1761* Converts Utf16 text into UTF8 as Windows expects
    17051762* it and return the result in a RTMemAlloc allocated buffer.
    17061763*
    1707 * @returns  IPRT status code
    1708 * @param  pcSrc      The source text
    1709 * @param  cbSrc      The size of the source in bytes, not counting the
    1710 *                    terminating zero
    1711 * @param  ppwszDest  Where to store the buffer address
    1712 * @param  pcbDest    On success, where to store the number of bytes written.
    1713 *                    Undefined otherwise.  Optional
     1764* @returns VBox status code.
     1765* @param  pcSrc                 The source text.
     1766* @param  cbSrc                 The size of the source in bytes, not counting the
     1767*                               terminating zero.
     1768* @param  ppwszDest             Where to store the buffer address.
     1769* @param  pcbDest               On success, where to store the number of bytes written.
     1770*                               Undefined otherwise.  Optional.
    17141771*/
    17151772static int clipUTF16ToWinHTML(RTUTF16 *pwcBuf, size_t cb, char **ppszOut, uint32_t *pcOut)
     
    17971854
    17981855/**
    1799  * Convert the data obtained from the X11 clipboard to the required format,
     1856 * Converts the data obtained from the X11 clipboard to the required format,
    18001857 * place it in the buffer supplied and signal that data has arrived.
    1801  * Convert the text obtained UTF-16LE with Windows EOLs.
    1802  * Convert full BMP data to DIB format.
     1858 *
     1859 * Converts the text obtained UTF-16LE with Windows EOLs.
     1860 * Converts full BMP data to DIB format.
     1861 *
    18031862 * @note  X11 backend code, callback for XtGetSelectionValue, for use when
    18041863 *        the X11 clipboard contains a format we understand.
     
    19442003#ifndef TESTCASE
    19452004/**
    1946  * Convert the data obtained from the X11 clipboard to the required format,
     2005 * Converts the data obtained from the X11 clipboard to the required format,
    19472006 * place it in the buffer supplied and signal that data has arrived.
    1948  * Convert the text obtained UTF-16LE with Windows EOLs.
    1949  * Convert full BMP data to DIB format.
     2007 *
     2008 * Converts the text obtained UTF-16LE with Windows EOLs.
     2009 * Converts full BMP data to DIB format.
     2010 *
    19502011 * @note  X11 backend code, callback for XtGetSelectionValue, for use when
    19512012 *        the X11 clipboard contains a format we understand.
     
    20652126 * Called when VBox wants to read the X11 clipboard.
    20662127 *
    2067  * @returns iprt status code
    2068  * @param  pCtx      Context data for the clipboard backend
    2069  * @param  u32Format The format that the VBox would like to receive the data
    2070  *                   in
    2071  * @param  pv        Where to write the data to
    2072  * @param  cb        The size of the buffer to write the data to
    2073  * @param  pcbActual Where to write the actual size of the written data
    2074  * @note   We allocate a request structure which must be freed by the worker
     2128 * @returns VBox status code.
     2129 * @param  pCtx                 Context data for the clipboard backend.
     2130 * @param  u32Format            The format that the VBox would like to receive the data in.
     2131 * @param  pv                   Where to write the data to.
     2132 * @param  cb                   The size of the buffer to write the data to.
     2133 * @param  pcbActual            Where to write the actual size of the written data.
     2134 *
     2135 * @note   We allocate a request structure which must be freed by the worker.
    20752136 */
    20762137int ClipRequestDataFromX11(CLIPBACKEND *pCtx, uint32_t u32Format, CLIPREADCBREQ *pReq)
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