VirtualBox

Ignore:
Timestamp:
Oct 26, 2020 9:21:51 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141086
Message:

Shared Clipboard/X11: More cleanup + documentation. Renamed some functions which aren't actually callbacks and unified terminology (acronym CB could mean clipboard *or* callback, confusing). No functional changes. bugref:9848

Location:
trunk/src/VBox/GuestHost/SharedClipboard
Files:
2 edited

Legend:

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

    r86693 r86702  
    9292class formats;
    9393SHCL_X11_DECL(Atom) clipGetAtom(PSHCLX11CTX pCtx, const char *pszName);
    94 SHCL_X11_DECL(void) clipQueryX11FormatsCallback(PSHCLX11CTX pCtx);
     94SHCL_X11_DECL(void) clipQueryX11Formats(PSHCLX11CTX pCtx);
    9595
    9696
     
    470470 * @param  pCtx                 The X11 clipboard context to use.
    471471 */
    472 SHCL_X11_DECL(void) clipReportEmptyX11CB(PSHCLX11CTX pCtx)
     472SHCL_X11_DECL(void) clipReportEmpty(PSHCLX11CTX pCtx)
    473473{
    474474    clipResetX11Formats(pCtx);
     
    668668        /* We may already be out of date. */
    669669        pCtx->fXtNeedsUpdate = false;
    670         clipQueryX11FormatsCallback(pCtx);
     670        clipQueryX11Formats(pCtx);
    671671        return;
    672672    }
     
    675675    {
    676676        /* No data available */
    677         clipReportEmptyX11CB(pCtx);
     677        clipReportEmpty(pCtx);
    678678        return;
    679679    }
     
    766766 * @param   pCtx                The X11 clipboard context to use.
    767767 */
    768 SHCL_X11_DECL(void) clipQueryX11FormatsCallback(PSHCLX11CTX pCtx)
     768SHCL_X11_DECL(void) clipQueryX11Formats(PSHCLX11CTX pCtx)
    769769{
    770770#ifndef TESTCASE
     
    824824            if (   (event.fixes.subtype == 0  /* XFixesSetSelectionOwnerNotify */)
    825825                && (event.fixes.owner != 0))
    826                 clipQueryX11FormatsCallback(pCtx);
     826                clipQueryX11Formats(pCtx);
    827827            else
    828                 clipReportEmptyX11CB(pCtx);
     828                clipReportEmpty(pCtx);
    829829        }
    830830    }
     
    836836 * @returns VBox status code.
    837837 * @param   hThreadSelf             Associated thread handle.
    838  * @param   pvUser                  Pointer to user-provided thread data.
     838 * @param   pvUser                  Pointer to the X11 clipboard context to use.
    839839 */
    840840static DECLCALLBACK(int) clipEventThread(RTTHREAD hThreadSelf, void *pvUser)
    841841{
    842842    RT_NOREF(hThreadSelf);
     843    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
    843844
    844845    LogRel(("Shared Clipboard: Starting X11 event thread\n"));
     
    847848
    848849    if (pCtx->fGrabClipboardOnStart)
    849         clipQueryX11FormatsCallback(pCtx);
     850        clipQueryX11Formats(pCtx);
    850851
    851852    /* We're now ready to run, tell parent. */
     
    891892}
    892893
    893 /** Worker function for stopping the clipboard which runs on the event
    894  * thread. */
    895 static void clipStopEventThreadWorker(void *pUserData, void *)
    896 {
    897 
    898     PSHCLX11CTX pCtx = (SHCLX11CTX *)pUserData;
     894/**
     895 * Worker function for stopping the clipboard which runs on the event
     896 * thread.
     897 *
     898 * @param   pvUserData          Pointer to the X11 clipboard context to use.
     899 */
     900static void clipStopEventThreadWorker(void *pvUserData, void *)
     901{
     902
     903    PSHCLX11CTX pCtx = (PSHCLX11CTX)pvUserData;
    899904
    900905    /* This might mean that we are getting stopped twice. */
     
    967972 * This is the callback which is scheduled when data is available on the
    968973 * wakeup pipe.  It simply reads all data from the pipe.
    969  */
    970 static void clipDrainWakeupPipe(XtPointer pUserData, int *, XtInputId *)
     974 *
     975 * @param   pvUserData          Pointer to the X11 clipboard context to use.
     976 */
     977static void clipDrainWakeupPipe(XtPointer pvUserData, int *, XtInputId *)
    971978{
    972979    LogFlowFuncEnter();
    973980
    974     PSHCLX11CTX pCtx = (SHCLX11CTX *)pUserData;
     981    PSHCLX11CTX pCtx = (PSHCLX11CTX)pvUserData;
    975982    char acBuf[WAKE_UP_STRING_LEN];
    976983
     
    13461353 *                              data we are returning.
    13471354 */
    1348 static int clipUtf16CRLFToUtf8LF(Display *pDisplay, PRTUTF16 pwszSrc,
    1349                                  size_t cbSrc, Atom *atomTarget,
    1350                                  Atom *atomTypeReturn,
    1351                                  XtPointer *pValReturn,
    1352                                  unsigned long *pcLenReturn,
    1353                                  int *piFormatReturn)
     1355static int clipConvertUtf16ToX11Data(Display *pDisplay, PRTUTF16 pwszSrc,
     1356                                     size_t cbSrc, Atom *atomTarget,
     1357                                     Atom *atomTypeReturn,
     1358                                     XtPointer *pValReturn,
     1359                                     unsigned long *pcLenReturn,
     1360                                     int *piFormatReturn)
    13541361{
    13551362    RT_NOREF(pDisplay);
     
    14061413 *                              data we are returning.
    14071414 */
    1408 static int clipWinHTMLToUtf8ForX11CB(Display *pDisplay, const char *pszSrc,
     1415static int clipConvertHtmlToX11Data(Display *pDisplay, const char *pszSrc,
    14091416                                    size_t cbSrc, Atom *atomTarget,
    14101417                                    Atom *atomTypeReturn,
     
    14641471}
    14651472
    1466 static int clipConvertVBoxCBForX11(PSHCLX11CTX pCtx, Atom *atomTarget,
    1467                                    Atom *atomTypeReturn,
    1468                                    XtPointer *pValReturn,
    1469                                    unsigned long *pcLenReturn,
    1470                                    int *piFormatReturn)
     1473static int clipConvertToX11Data(PSHCLX11CTX pCtx, Atom *atomTarget,
     1474                                Atom *atomTypeReturn,
     1475                                XtPointer *pValReturn,
     1476                                unsigned long *pcLenReturn,
     1477                                int *piFormatReturn)
    14711478{
    14721479    int rc = VINF_SUCCESS;
     
    14941501                || (fmtX11 == SHCLX11FMT_TEXT)))
    14951502        {
    1496             rc = clipUtf16CRLFToUtf8LF(XtDisplay(pCtx->pWidget),
    1497                                        (PRTUTF16)pv, cb, atomTarget,
    1498                                        atomTypeReturn, pValReturn,
    1499                                        pcLenReturn, piFormatReturn);
     1503            rc = clipConvertUtf16ToX11Data(XtDisplay(pCtx->pWidget),
     1504                                           (PRTUTF16)pv, cb, atomTarget,
     1505                                           atomTypeReturn, pValReturn,
     1506                                           pcLenReturn, piFormatReturn);
    15001507        }
    15011508
     
    15401547        if (RT_SUCCESS(rc))
    15411548        {
    1542             /*
    1543              * The common VBox HTML encoding will be - Utf8
    1544              * because it more general for HTML formats then UTF16
    1545              * X11 clipboard returns UTF-16, so before sending it we should
    1546              * convert it to UTF8.
    1547              * It's very strange but here we get UTF-16 from x11 clipboard
    1548              * in same time we send UTF-8 to x11 clipboard and it's work.
     1549            /**
     1550             * The common VBox HTML encoding will be UTF-8.
     1551             * Before sending it to the X11 clipboard we have to convert it to UTF-8 first.
     1552             *
     1553             * Strange that we get UTF-16 from the X11 clipboard, but
     1554             * in same time we send UTF-8 to X11 clipboard and it works.
     1555             ** @todo r=andy Verify this.
    15491556             */
    1550             rc = clipWinHTMLToUtf8ForX11CB(XtDisplay(pCtx->pWidget),
    1551                                            (const char*)pv, cb, atomTarget,
    1552                                            atomTypeReturn, pValReturn,
    1553                                            pcLenReturn, piFormatReturn);
     1557            rc = clipConvertHtmlToX11Data(XtDisplay(pCtx->pWidget),
     1558                                          (const char*)pv, cb, atomTarget,
     1559                                          atomTypeReturn, pValReturn,
     1560                                          pcLenReturn, piFormatReturn);
    15541561            if (RT_SUCCESS(rc))
    15551562                clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtX11);
     
    16231630                                  pcLenReturn, piFormatReturn);
    16241631    else
    1625         rc = clipConvertVBoxCBForX11(pCtx, atomTarget, atomTypeReturn,
    1626                                      pValReturn, pcLenReturn, piFormatReturn);
     1632        rc = clipConvertToX11Data(pCtx, atomTarget, atomTypeReturn,
     1633                                  pValReturn, pcLenReturn, piFormatReturn);
    16271634
    16281635    LogFlowFunc(("returning %RTbool, rc=%Rrc\n", RT_SUCCESS(rc), rc));
     
    16411648} CLIPNEWVBOXFORMATS, *PCLIPNEWVBOXFORMATS;
    16421649
    1643 /** Invalidates the local cache of the data in the VBox clipboard. */
    1644 static void clipInvalidateVBoxCBCache(PSHCLX11CTX pCtx)
     1650
     1651
     1652/**
     1653 * Invalidates the local cache of the data in the VBox clipboard.
     1654 *
     1655 * @param   pCtx                The X11 clipboard context to use.
     1656 */
     1657static void clipInvalidateClipboardCache(PSHCLX11CTX pCtx)
    16451658{
    16461659    if (pCtx->pvUnicodeCache != NULL)
     
    16531666/**
    16541667 * Takes possession of the X11 clipboard (and middle-button selection).
    1655  */
    1656 static void clipGrabX11CB(PSHCLX11CTX pCtx, SHCLFORMATS Formats)
     1668 *
     1669 * @param   pCtx                The X11 clipboard context to use.
     1670 * @param   uFormats            Clipboard formats to set.
     1671 */
     1672static void clipGrabX11Clipboard(PSHCLX11CTX pCtx, SHCLFORMATS uFormats)
    16571673{
    16581674    LogFlowFuncEnter();
     
    16611677                       CurrentTime, clipXtConvertSelectionProc, NULL, 0))
    16621678    {
    1663         pCtx->vboxFormats = Formats;
     1679        pCtx->vboxFormats = uFormats;
     1680
    16641681        /* Grab the middle-button paste selection too. */
    16651682        XtOwnSelection(pCtx->pWidget, clipGetAtom(pCtx, "PRIMARY"),
     
    16821699 * event thread.
    16831700 *
    1684  * @param pUserData             Pointer to a CLIPNEWVBOXFORMATS structure containing
     1701 * @param pvUserData            Pointer to a CLIPNEWVBOXFORMATS structure containing
    16851702 *                              information about the VBox formats available and the
    16861703 *                              clipboard context data.  Must be freed by the worker.
    16871704 */
    1688 static void ShClX11ReportFormatsToX11Worker(void *pUserData, void * /* interval */)
    1689 {
    1690     CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pUserData;
    1691     PSHCLX11CTX pCtx = pFormats->pCtx;
    1692 
    1693     uint32_t fFormats = pFormats->Formats;
     1705static void ShClX11ReportFormatsToX11Worker(void *pvUserData, void * /* interval */)
     1706{
     1707    AssertPtrReturnVoid(pvUserData);
     1708
     1709    CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pvUserData;
     1710
     1711    PSHCLX11CTX pCtx     = pFormats->pCtx;
     1712    SHCLFORMATS fFormats = pFormats->Formats;
    16941713
    16951714    RTMemFree(pFormats);
     
    16971716    LogFlowFunc (("fFormats=0x%x\n", fFormats));
    16981717
    1699     clipInvalidateVBoxCBCache(pCtx);
    1700     clipGrabX11CB(pCtx, fFormats);
     1718    clipInvalidateClipboardCache(pCtx);
     1719    clipGrabX11Clipboard(pCtx, fFormats);
    17011720    clipResetX11Formats(pCtx);
    17021721
     
    17051724
    17061725/**
    1707  * Announces new clipboard formats to the host.
     1726 * Announces new clipboard formats to the X11 clipboard.
    17081727 *
    17091728 * @returns VBox status code.
    1710  * @param   Formats             Clipboard formats offered.
    1711  */
    1712 int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, uint32_t Formats)
     1729 * @param   pCtx                Context data for the clipboard backend.
     1730 * @param   uFormats            Clipboard formats offered.
     1731 */
     1732int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS uFormats)
    17131733{
    17141734    /*
     
    17251745    {
    17261746        pFormats->pCtx    = pCtx;
    1727         pFormats->Formats = Formats;
     1747        pFormats->Formats = uFormats;
    17281748
    17291749        rc = clipQueueToEventThread(pCtx, ShClX11ReportFormatsToX11Worker,
    1730                                     (XtPointer) pFormats);
     1750                                    (XtPointer)pFormats);
    17311751    }
    17321752    else
     
    17431763 * Converts the text obtained UTF-16LE with Windows EOLs.
    17441764 * Converts full BMP data to DIB format.
    1745  *
    1746  * @note  Callback for XtGetSelectionValue, for use when
    1747  *        the X11 clipboard contains a format we understand.
    1748  */
    1749 SHCL_X11_DECL(void) clipConvertDataFromX11CallbackWorker(void *pClient, void *pvSrc, unsigned cbSrc)
     1765 */
     1766SHCL_X11_DECL(void) clipConvertDataFromX11Worker(void *pClient, void *pvSrc, unsigned cbSrc)
    17501767{
    17511768    CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *)pClient;
     
    17701787    pCtx->fXtBusy = false;
    17711788    if (pCtx->fXtNeedsUpdate)
    1772         clipQueryX11FormatsCallback(pCtx);
     1789        clipQueryX11Formats(pCtx);
    17731790
    17741791    if (pvSrc == NULL)
     
    19741991 * Converts the text obtained UTF-16LE with Windows EOLs.
    19751992 * Converts full BMP data to DIB format.
    1976  *
    1977  * @note  Callback for XtGetSelectionValue(), for use when
    1978  *        the X11 clipboard contains a format we understand.
    1979  */
    1980 SHCL_X11_DECL(void) clipConvertDataFromX11Callback(Widget widget, XtPointer pClient,
    1981                                                    Atom * /* selection */, Atom *atomType,
    1982                                                    XtPointer pvSrc, long unsigned int *pcLen,
    1983                                                    int *piFormat)
     1993 */
     1994SHCL_X11_DECL(void) clipConvertDataFromX11(Widget widget, XtPointer pClient,
     1995                                           Atom * /* selection */, Atom *atomType,
     1996                                           XtPointer pvSrc, long unsigned int *pcLen,
     1997                                           int *piFormat)
    19841998{
    19851999    RT_NOREF(widget);
    19862000    if (*atomType == XT_CONVERT_FAIL) /* Xt timeout */
    1987         clipConvertDataFromX11CallbackWorker(pClient, NULL, 0);
     2001        clipConvertDataFromX11Worker(pClient, NULL, 0);
    19882002    else
    1989         clipConvertDataFromX11CallbackWorker(pClient, pvSrc, (*pcLen) * (*piFormat) / 8);
     2003        clipConvertDataFromX11Worker(pClient, pvSrc, (*pcLen) * (*piFormat) / 8);
    19902004
    19912005    XtFree((char *)pvSrc);
     
    19982012    XtGetSelectionValue(pCtx->pWidget, clipGetAtom(pCtx, "CLIPBOARD"),
    19992013                        clipAtomForX11Format(pCtx, idxFmt),
    2000                         clipConvertDataFromX11Callback,
     2014                        clipConvertDataFromX11,
    20012015                        reinterpret_cast<XtPointer>(pReq),
    20022016                        CurrentTime);
     
    20102024/**
    20112025 * Worker function for ShClX11ReadDataFromX11 which runs on the event thread.
     2026 *
     2027 * @param pvUserData            Pointer to a CLIPREADX11CBREQ structure containing
     2028 *                              information about the clipboard read request.
     2029 *                              Must be free'd by the worker.
    20122030 */
    20132031static void ShClX11ReadDataFromX11Worker(void *pvUserData, void * /* interval */)
     
    21012119int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMAT Format, CLIPREADCBREQ *pReq)
    21022120{
     2121    AssertPtrReturn(pReq, VERR_INVALID_POINTER);
     2122
    21032123    /*
    21042124     * Immediately return if we are not connected to the X server.
  • trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11.cpp

    r86538 r86702  
    3636
    3737extern void clipUpdateX11Targets(PSHCLX11CTX pCtx, SHCLX11FMTIDX *pTargets, size_t cTargets);
    38 extern void clipReportEmptyX11CB(PSHCLX11CTX pCtx);
    39 extern void clipConvertDataFromX11CallbackWorker(void *pClient, void *pvSrc, unsigned cbSrc);
     38extern void clipReportEmpty(PSHCLX11CTX pCtx);
     39extern void clipConvertDataFromX11Worker(void *pClient, void *pvSrc, unsigned cbSrc);
    4040extern SHCLX11FMTIDX clipGetTextFormatFromTargets(PSHCLX11CTX pCtx, SHCLX11FMTIDX *pTargets, size_t cTargets);
    4141extern SHCLX11FMT clipRealFormatForX11Format(SHCLX11FMTIDX uFmtIdx);
    4242extern Atom clipGetAtom(PSHCLX11CTX pCtx, const char *pcszName);
     43extern void clipQueryX11Formats(PSHCLX11CTX pCtx);
    4344extern size_t clipReportMaxX11Formats(void);
    4445
     
    6162*   Own callback implementations                                                                                                 *
    6263*********************************************************************************************************************************/
    63 extern DECLCALLBACK(void) clipQueryX11FormatsCallback(PSHCLX11CTX pCtx);
    6464extern DECLCALLBACK(void) clipConvertX11TargetsCallback(Widget widget, XtPointer pClient,
    6565                                                        Atom * /* selection */, Atom *atomType,
     
    224224    if (target != g_tst_aSelTargetsIdx[0])
    225225    {
    226         clipConvertDataFromX11CallbackWorker(closure, NULL, 0); /* Could not convert to target. */
     226        clipConvertDataFromX11Worker(closure, NULL, 0); /* Could not convert to target. */
    227227        return;
    228228    }
     
    236236        format = 0;
    237237    }
    238     clipConvertDataFromX11CallbackWorker(closure, pValue, count * format / 8);
     238    clipConvertDataFromX11Worker(closure, pValue, count * format / 8);
    239239    if (pValue)
    240240        RTMemFree(pValue);
     
    339339static void tstClipSendTargetUpdate(PSHCLX11CTX pCtx)
    340340{
    341     clipQueryX11FormatsCallback(pCtx);
     341    clipQueryX11Formats(pCtx);
    342342}
    343343
     
    772772    RTTestSub(hTest, "notification of switch to X11 clipboard");
    773773    tstClipInvalidateFormats();
    774     clipReportEmptyX11CB(&X11Ctx);
     774    clipReportEmpty(&X11Ctx);
    775775    RTTEST_CHECK_MSG(hTest, tstClipQueryFormats() == 0,
    776776                     (hTest, "Failed to send a format update (release) notification\n"));
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