VirtualBox

Changeset 18633 in vbox


Ignore:
Timestamp:
Apr 2, 2009 12:46:58 PM (15 years ago)
Author:
vboxsync
Message:

GuestHost/SharedClipboard: pass pointers instead of using globals whereever possible

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/SharedClipboard.h

    r18586 r18633  
    5555     * during a request for the clipboard contents) */
    5656    uint32_t *pcbActual;
     57    /** The clipboard context this request is associated with */
     58    VBOXCLIPBOARDCONTEXTX11 *pCtx;
    5759};
    5860
     
    6062
    6163/* APIs exported by the X11 backend */
    62 extern void VBoxX11ClipboardAnnounceVBoxFormat(uint32_t u32Formats);
    6364extern int VBoxX11ClipboardInitX11(VBOXCLIPBOARDCONTEXT *pFrontend,
    6465                                   VBOXCLIPBOARDCONTEXTX11 **ppBackend);
  • trunk/include/VBox/log.h

    r18189 r18633  
    278278    /** SELM group. */
    279279    LOG_GROUP_SELM,
     280    /** Shared clipboard host service group. */
     281    LOG_GROUP_SHARED_CLIPBOARD,
    280282    /** Chromium OpenGL host service group. */
    281283    LOG_GROUP_SHARED_CROPENGL,
     
    448450    "REM_RUN",      \
    449451    "SELM",         \
     452    "SHARED_CLIPBOARD",\
    450453    "SHARED_CROPENGL",\
    451454    "SHARED_FOLDERS",\
  • trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp

    r18613 r18633  
    2121 */
    2222
    23 /** @todo create a clipboard log group */
    24 #define LOG_GROUP LOG_GROUP_HGCM
     23#define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
    2524
    2625#include <vector>
     
    138137 */
    139138static VBOXCLIPBOARDCONTEXTX11 g_ctxX11;
     139static VBOXCLIPBOARDCONTEXTX11 *g_pCtx;
    140140
    141141/* Are we actually connected to the X server? */
     
    156156 *        the X11 clipboard.
    157157 */
    158 static void vboxClipboardGetUtf16(XtPointer pValue, unsigned cwSrcLen,
     158static void vboxClipboardGetUtf16(VBOXCLIPBOARDCONTEXTX11 *pCtx,
     159                                  XtPointer pValue, unsigned cwSrcLen,
    159160                                  void *pv, unsigned cb,
    160161                                  uint32_t *pcbActual)
     
    187188    /* We need to do this whether we succeed or fail. */
    188189    XtFree(reinterpret_cast<char *>(pValue));
    189     RTSemEventSignal(g_ctxX11.waitForData);
     190    RTSemEventSignal(pCtx->waitForData);
    190191    LogFlowFunc(("Returning.  Status is %Rrc\n", rc));
    191192}
     
    205206 *        the X11 clipboard.
    206207 */
    207 static void vboxClipboardGetUtf8FromX11(XtPointer pValue, unsigned cbSrcLen,
     208static void vboxClipboardGetUtf8FromX11(VBOXCLIPBOARDCONTEXTX11 *pCtx,
     209                                        XtPointer pValue, unsigned cbSrcLen,
    208210                                        void *pv, unsigned cb,
    209211                                        uint32_t *pcbActual)
     
    240242    XtFree(reinterpret_cast<char *>(pValue));
    241243    RTUtf16Free(pu16SrcText);
    242     RTSemEventSignal(g_ctxX11.waitForData);
     244    RTSemEventSignal(pCtx->waitForData);
    243245    LogFlowFunc(("Returning.  Status is %Rrc", rc));
    244246}
     
    258260 *        the X11 clipboard.
    259261 */
    260 static void vboxClipboardGetCTextFromX11(XtPointer pValue, unsigned cbSrcLen,
     262static void vboxClipboardGetCTextFromX11(VBOXCLIPBOARDCONTEXTX11 *pCtx,
     263                                         XtPointer pValue, unsigned cbSrcLen,
    261264                                         void *pv, unsigned cb,
    262265                                         uint32_t *pcbActual)
     
    275278    /* First convert the compound text to Utf8 */
    276279    property.value = reinterpret_cast<unsigned char *>(pValue);
    277     property.encoding = g_ctxX11.atomCText;
     280    property.encoding = pCtx->atomCText;
    278281    property.format = 8;
    279282    property.nitems = cbSrcLen;
    280283#ifdef RT_OS_SOLARIS
    281     int xrc = XmbTextPropertyToTextList(XtDisplay(g_ctxX11.widget), &property, &ppu8SrcText, &cProps);
     284    int xrc = XmbTextPropertyToTextList(XtDisplay(pCtx->widget), &property,
     285                                        &ppu8SrcText, &cProps);
    282286#else
    283     int xrc = Xutf8TextPropertyToTextList(XtDisplay(g_ctxX11.widget), &property, &ppu8SrcText, &cProps);
     287    int xrc = Xutf8TextPropertyToTextList(XtDisplay(pCtx->widget),
     288                                          &property, &ppu8SrcText, &cProps);
    284289#endif
    285290    XtFree(reinterpret_cast<char *>(pValue));
     
    323328    RTUtf16Free(pu16SrcText);
    324329    LogFlowFunc(("Returning.  Status is %Rrc\n", rc));
    325     RTSemEventSignal(g_ctxX11.waitForData);
     330    RTSemEventSignal(pCtx->waitForData);
    326331}
    327332
     
    340345 *        the X11 clipboard.
    341346 */
    342 static void vboxClipboardGetLatin1FromX11(XtPointer pValue,
     347static void vboxClipboardGetLatin1FromX11(VBOXCLIPBOARDCONTEXTX11 *pCtx,
     348                                          XtPointer pValue,
    343349                                          unsigned cbSourceLen, void *pv,
    344350                                          unsigned cb, uint32_t *pcbActual)
     
    378384    }
    379385    XtFree(reinterpret_cast<char *>(pValue));
    380     RTSemEventSignal(g_ctxX11.waitForData);
     386    RTSemEventSignal(pCtx->waitForData);
    381387    LogFlowFunc(("Returning.  Status is %Rrc\n", rc));
    382388}
     
    397403    VBOXCLIPBOARDREQUEST *pRequest
    398404        = reinterpret_cast<VBOXCLIPBOARDREQUEST *>(pClientData);
     405    VBOXCLIPBOARDCONTEXTX11 *pCtx = pRequest->pCtx;
    399406    LogFlowFunc(("pClientData=%p, *pcLen=%lu, *piFormat=%d\n", pClientData,
    400407                 *pcLen, *piFormat));
    401     LogFlowFunc(("g_ctxX11.X11TextFormat=%d, pRequest->cb=%d\n",
    402                  g_ctxX11.X11TextFormat, pRequest->cb));
     408    LogFlowFunc(("pCtx->X11TextFormat=%d, pRequest->cb=%d\n",
     409                 pCtx->X11TextFormat, pRequest->cb));
    403410    unsigned cTextLen = (*pcLen) * (*piFormat) / 8;
    404411    /* The X Toolkit may have failed to get the clipboard selection for us. */
     
    409416        return;
    410417    /* In which format is the clipboard data? */
    411     switch (g_ctxX11.X11TextFormat)
     418    switch (pCtx->X11TextFormat)
    412419    {
    413420    case UTF16:
    414         vboxClipboardGetUtf16(pValue, cTextLen / 2, pRequest->pv,
     421        vboxClipboardGetUtf16(pCtx, pValue, cTextLen / 2, pRequest->pv,
    415422                              pRequest->cb, pRequest->pcbActual);
    416423        break;
    417424    case CTEXT:
    418         vboxClipboardGetCTextFromX11(pValue, cTextLen, pRequest->pv,
     425        vboxClipboardGetCTextFromX11(pCtx, pValue, cTextLen, pRequest->pv,
    419426                                     pRequest->cb, pRequest->pcbActual);
    420427        break;
     
    425432        char *pu8SourceText = reinterpret_cast<char *>(pValue);
    426433
    427         if ((g_ctxX11.X11TextFormat == UTF8)
     434        if ((pCtx->X11TextFormat == UTF8)
    428435            && (RTStrUniLenEx(pu8SourceText, *pcLen, &cStringLen) == VINF_SUCCESS))
    429436        {
    430             vboxClipboardGetUtf8FromX11(pValue, cTextLen, pRequest->pv,
     437            vboxClipboardGetUtf8FromX11(pCtx, pValue, cTextLen, pRequest->pv,
    431438                                     pRequest->cb, pRequest->pcbActual);
    432439            break;
     
    434441        else
    435442        {
    436             vboxClipboardGetLatin1FromX11(pValue, cTextLen, pRequest->pv,
    437                                      pRequest->cb, pRequest->pcbActual);
     443            vboxClipboardGetLatin1FromX11(pCtx, pValue, cTextLen,
     444                                          pRequest->pv, pRequest->cb,
     445                                          pRequest->pcbActual);
    438446            break;
    439447        }
     
    444452        return;
    445453    }
    446     g_ctxX11.notifyVBox = true;
     454    pCtx->notifyVBox = true;
    447455}
    448456
     
    455463 */
    456464static void vboxClipboardGetTargetsFromX11(Widget,
    457                                            XtPointer /* pClientData */,
     465                                           XtPointer pClientData,
    458466                                           Atom * /* selection */,
    459467                                           Atom *atomType,
     
    462470                                           int *piFormat)
    463471{
     472    VBOXCLIPBOARDCONTEXTX11 *pCtx =
     473            reinterpret_cast<VBOXCLIPBOARDCONTEXTX11 *>(pClientData);
    464474    Atom *atomTargets = reinterpret_cast<Atom *>(pValue);
    465475    unsigned cAtoms = *pcLen;
     
    476486    for (unsigned i = 0; i < cAtoms; ++i)
    477487    {
    478         for (unsigned j = 0; j != g_ctxX11.formatList.size(); ++j)
    479             if (g_ctxX11.formatList[j].atom == atomTargets[i])
     488        for (unsigned j = 0; j != pCtx->formatList.size(); ++j)
     489            if (pCtx->formatList[j].atom == atomTargets[i])
    480490            {
    481                 if (eBestTarget < g_ctxX11.formatList[j].format)
     491                if (eBestTarget < pCtx->formatList[j].format)
    482492                {
    483                     eBestTarget = g_ctxX11.formatList[j].format;
    484                     atomBestTarget = g_ctxX11.formatList[j].atom;
     493                    eBestTarget = pCtx->formatList[j].format;
     494                    atomBestTarget = pCtx->formatList[j].atom;
    485495                }
    486496                break;
     
    488498        if (g_debugClipboard)
    489499        {
    490             char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), atomTargets[i]);
     500            char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget),
     501                                            atomTargets[i]);
    491502            if (szAtomName != 0)
    492503            {
     
    497508        }
    498509    }
    499     g_ctxX11.atomX11TextFormat = atomBestTarget;
    500     if ((eBestTarget != g_ctxX11.X11TextFormat) || (g_ctxX11.notifyVBox == true))
     510    pCtx->atomX11TextFormat = atomBestTarget;
     511    if ((eBestTarget != pCtx->X11TextFormat) || (pCtx->notifyVBox == true))
    501512    {
    502513        uint32_t u32Formats = 0;
     
    505516            if (atomBestTarget != None)
    506517            {
    507                 char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), atomBestTarget);
     518                char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget),
     519                                                atomBestTarget);
    508520                Log2 (("%s: switching to host text target %s.  Available targets are:\n",
    509521                       __PRETTY_FUNCTION__, szAtomName));
     
    515527            for (unsigned i = 0; i < cAtoms; ++i)
    516528            {
    517                 char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), atomTargets[i]);
     529                char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget),
     530                                                atomTargets[i]);
    518531                if (szAtomName != 0)
    519532                {
     
    523536            }
    524537        }
    525         g_ctxX11.X11TextFormat = eBestTarget;
     538        pCtx->X11TextFormat = eBestTarget;
    526539        if (eBestTarget != INVALID)
    527540            u32Formats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
    528         VBoxX11ClipboardReportX11Formats(g_ctxX11.pFrontend, u32Formats);
    529         g_ctxX11.notifyVBox = false;
     541        VBoxX11ClipboardReportX11Formats(pCtx->pFrontend, u32Formats);
     542        pCtx->notifyVBox = false;
    530543    }
    531544    XtFree(reinterpret_cast<char *>(pValue));
     
    540553 *        available.
    541554 */
    542 static void vboxClipboardPollX11ForTargets(XtPointer /* pUserData */, XtIntervalId * /* hTimerId */)
    543 {
     555static void vboxClipboardPollX11ForTargets(XtPointer pUserData,
     556                                           XtIntervalId * /* hTimerId */)
     557{
     558    VBOXCLIPBOARDCONTEXTX11 *pCtx =
     559            reinterpret_cast<VBOXCLIPBOARDCONTEXTX11 *>(pUserData);
    544560    Log3 (("%s: called\n", __PRETTY_FUNCTION__));
    545561    /* Get the current clipboard contents */
    546     if (g_ctxX11.eOwner == X11)
     562    if (pCtx->eOwner == X11)
    547563    {
    548564        Log3 (("%s: requesting the targets that the host clipboard offers\n",
    549565               __PRETTY_FUNCTION__));
    550         XtGetSelectionValue(g_ctxX11.widget, g_ctxX11.atomClipboard,
    551                             g_ctxX11.atomTargets,
    552                             vboxClipboardGetTargetsFromX11, NULL,
     566        XtGetSelectionValue(pCtx->widget, pCtx->atomClipboard,
     567                            pCtx->atomTargets,
     568                            vboxClipboardGetTargetsFromX11, pCtx,
    553569                            CurrentTime);
    554570    }
    555571    /* Re-arm our timer */
    556     XtAppAddTimeOut(g_ctxX11.appContext, 200 /* ms */,
    557                     vboxClipboardPollX11ForTargets, 0);
     572    XtAppAddTimeOut(pCtx->appContext, 200 /* ms */,
     573                    vboxClipboardPollX11ForTargets, pCtx);
    558574}
    559575
     
    562578 * @note  X11 backend code.
    563579 */
    564 static void vboxClipboardAddFormat(const char *pszName, g_eClipboardFormats eFormat,
     580static void vboxClipboardAddFormat(VBOXCLIPBOARDCONTEXTX11 *pCtx,
     581                                   const char *pszName,
     582                                   g_eClipboardFormats eFormat,
    565583                                   unsigned guestFormat)
    566584{
    567585    VBOXCLIPBOARDFORMAT sFormat;
    568586    /* Get an atom from the X server for that target format */
    569     Atom atomFormat = XInternAtom(XtDisplay(g_ctxX11.widget), pszName, false);
     587    Atom atomFormat = XInternAtom(XtDisplay(pCtx->widget), pszName, false);
    570588    sFormat.atom   = atomFormat;
    571589    sFormat.format = eFormat;
    572590    sFormat.guestFormat = guestFormat;
    573     g_ctxX11.formatList.push_back(sFormat);
     591    pCtx->formatList.push_back(sFormat);
    574592    LogFlow (("vboxClipboardAddFormat: added format %s (%d)\n", pszName, eFormat));
    575593}
     
    579597 * @note  X11 backend code.
    580598 */
    581 static int vboxClipboardThread(RTTHREAD self, void * /* pvUser */)
     599static int vboxClipboardThread(RTTHREAD self, void *pvUser)
    582600{
    583601    LogRel(("Shared clipboard: starting host clipboard thread\n"));
    584602
     603    VBOXCLIPBOARDCONTEXTX11 *pCtx =
     604            reinterpret_cast<VBOXCLIPBOARDCONTEXTX11 *>(pvUser);
    585605    /* Set up a timer to poll the host clipboard */
    586     XtAppAddTimeOut(g_ctxX11.appContext, 200 /* ms */, vboxClipboardPollX11ForTargets, 0);
    587 
    588     XtAppMainLoop(g_ctxX11.appContext);
    589     g_ctxX11.formatList.clear();
     606    XtAppAddTimeOut(pCtx->appContext, 200 /* ms */,
     607                    vboxClipboardPollX11ForTargets, pCtx);
     608
     609    XtAppMainLoop(pCtx->appContext);
     610    pCtx->formatList.clear();
    590611    LogRel(("Shared clipboard: host clipboard thread terminated successfully\n"));
    591612    return VINF_SUCCESS;
     
    595616 * @note  X11 backend code.
    596617 */
    597 static int vboxClipboardInitX11 (void)
     618static int vboxClipboardInitX11 (VBOXCLIPBOARDCONTEXTX11 *pCtx)
    598619{
    599620    /* Create a window and make it a clipboard viewer. */
     
    610631       can't get an X11 display. */
    611632    XtToolkitInitialize();
    612     g_ctxX11.appContext = XtCreateApplicationContext();
    613     // XtAppSetFallbackResources(g_ctxX11.appContext, szFallbackResources);
    614     pDisplay = XtOpenDisplay(g_ctxX11.appContext, 0, 0, "VBoxClipboard", 0, 0, &cArgc, &pcArgv);
     633    pCtx->appContext = XtCreateApplicationContext();
     634    // XtAppSetFallbackResources(pCtx->appContext, szFallbackResources);
     635    pDisplay = XtOpenDisplay(pCtx->appContext, 0, 0, "VBoxClipboard", 0, 0, &cArgc, &pcArgv);
    615636    if (NULL == pDisplay)
    616637    {
     
    620641    if (RT_SUCCESS(rc))
    621642    {
    622         g_ctxX11.widget = XtVaAppCreateShell(0, "VBoxClipboard", applicationShellWidgetClass, pDisplay,
     643        pCtx->widget = XtVaAppCreateShell(0, "VBoxClipboard", applicationShellWidgetClass, pDisplay,
    623644                                          XtNwidth, 1, XtNheight, 1, NULL);
    624         if (NULL == g_ctxX11.widget)
     645        if (NULL == pCtx->widget)
    625646        {
    626647            LogRel(("Shared clipboard: failed to construct the X11 window for the host clipboard manager.\n"));
     
    630651    if (RT_SUCCESS(rc))
    631652    {
    632         XtSetMappedWhenManaged(g_ctxX11.widget, false);
    633         XtRealizeWidget(g_ctxX11.widget);
     653        XtSetMappedWhenManaged(pCtx->widget, false);
     654        XtRealizeWidget(pCtx->widget);
    634655
    635656        /* Get hold of the atoms which we need */
    636         g_ctxX11.atomClipboard = XInternAtom(XtDisplay(g_ctxX11.widget), "CLIPBOARD", false /* only_if_exists */);
    637         g_ctxX11.atomPrimary   = XInternAtom(XtDisplay(g_ctxX11.widget), "PRIMARY",   false);
    638         g_ctxX11.atomTargets   = XInternAtom(XtDisplay(g_ctxX11.widget), "TARGETS",   false);
    639         g_ctxX11.atomMultiple  = XInternAtom(XtDisplay(g_ctxX11.widget), "MULTIPLE",  false);
    640         g_ctxX11.atomTimestamp = XInternAtom(XtDisplay(g_ctxX11.widget), "TIMESTAMP", false);
    641         g_ctxX11.atomUtf16     = XInternAtom(XtDisplay(g_ctxX11.widget),
     657        pCtx->atomClipboard = XInternAtom(XtDisplay(pCtx->widget), "CLIPBOARD", false /* only_if_exists */);
     658        pCtx->atomPrimary   = XInternAtom(XtDisplay(pCtx->widget), "PRIMARY",   false);
     659        pCtx->atomTargets   = XInternAtom(XtDisplay(pCtx->widget), "TARGETS",   false);
     660        pCtx->atomMultiple  = XInternAtom(XtDisplay(pCtx->widget), "MULTIPLE",  false);
     661        pCtx->atomTimestamp = XInternAtom(XtDisplay(pCtx->widget), "TIMESTAMP", false);
     662        pCtx->atomUtf16     = XInternAtom(XtDisplay(pCtx->widget),
    642663                                          "text/plain;charset=ISO-10646-UCS-2", false);
    643         g_ctxX11.atomUtf8      = XInternAtom(XtDisplay(g_ctxX11.widget), "UTF_STRING", false);
     664        pCtx->atomUtf8      = XInternAtom(XtDisplay(pCtx->widget), "UTF_STRING", false);
    644665        /* And build up the vector of supported formats */
    645         g_ctxX11.atomCText     = XInternAtom(XtDisplay(g_ctxX11.widget), "COMPOUND_TEXT", false);
     666        pCtx->atomCText     = XInternAtom(XtDisplay(pCtx->widget), "COMPOUND_TEXT", false);
    646667        /* And build up the vector of supported formats */
    647668        if (!g_testUtf8 && !g_testCText)
    648             vboxClipboardAddFormat("text/plain;charset=ISO-10646-UCS-2", UTF16,
     669            vboxClipboardAddFormat(pCtx,
     670                                   "text/plain;charset=ISO-10646-UCS-2",
     671                                   UTF16,
    649672                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    650673        if (!g_testUtf16 && !g_testCText)
    651674        {
    652             vboxClipboardAddFormat("UTF8_STRING", UTF8,
     675            vboxClipboardAddFormat(pCtx, "UTF8_STRING", UTF8,
    653676                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    654             vboxClipboardAddFormat("text/plain;charset=UTF-8", UTF8,
     677            vboxClipboardAddFormat(pCtx, "text/plain;charset=UTF-8", UTF8,
    655678                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    656             vboxClipboardAddFormat("text/plain;charset=utf-8", UTF8,
     679            vboxClipboardAddFormat(pCtx, "text/plain;charset=utf-8", UTF8,
    657680                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    658             vboxClipboardAddFormat("STRING", UTF8,
     681            vboxClipboardAddFormat(pCtx, "STRING", UTF8,
    659682                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    660             vboxClipboardAddFormat("TEXT", UTF8,
     683            vboxClipboardAddFormat(pCtx, "TEXT", UTF8,
    661684                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    662             vboxClipboardAddFormat("text/plain", UTF8,
     685            vboxClipboardAddFormat(pCtx, "text/plain", UTF8,
    663686                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    664687}
    665688        if (!g_testUtf16 && !g_testUtf8)
    666             vboxClipboardAddFormat("COMPOUND_TEXT", CTEXT,
     689            vboxClipboardAddFormat(pCtx, "COMPOUND_TEXT", CTEXT,
    667690                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    668691    }
     
    679702    int rc;
    680703
     704    VBOXCLIPBOARDCONTEXTX11 *pCtx = &g_ctxX11;
     705    /** @todo we still only support one backend at a time, because the X
     706     * toolkit intrinsics don't support user data in XtOwnSelection.  Not
     707     * a big problem, but not clean either. */
     708    AssertReturn(g_pCtx == NULL, VERR_NOT_SUPPORTED);
     709    g_pCtx = &g_ctxX11;
    681710    if (!RTEnvGet("DISPLAY"))
    682711    {
     
    715744
    716745    LogRel(("Initializing X11 clipboard backend\n"));
    717     g_ctxX11.pFrontend = pFrontend;
    718     RTSemEventCreate(&g_ctxX11.waitForData);
    719     rc = vboxClipboardInitX11();
     746    pCtx->pFrontend = pFrontend;
     747    RTSemEventCreate(&pCtx->waitForData);
     748    rc = vboxClipboardInitX11(pCtx);
    720749    if (RT_SUCCESS(rc))
    721750    {
    722         rc = RTThreadCreate(&g_ctxX11.thread, vboxClipboardThread, 0, 0,
     751        rc = RTThreadCreate(&pCtx->thread, vboxClipboardThread, pCtx, 0,
    723752                            RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP");
    724753        if (RT_FAILURE(rc))
     
    726755    }
    727756    if (RT_FAILURE(rc))
    728         RTSemEventDestroy(g_ctxX11.waitForData);
     757        RTSemEventDestroy(pCtx->waitForData);
     758    *ppBackend = pCtx;
    729759    return rc;
    730760}
     
    734764 * @note  X11 backend code
    735765 */
    736 int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *pBackend)
     766int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
    737767{
    738768    int rc, rcThread;
     
    751781     * during a request for clipboard data coming from X11, so only we do it
    752782     * after releasing any such requests. */
    753     XtAppSetExitFlag(g_ctxX11.appContext);
     783    XtAppSetExitFlag(pCtx->appContext);
    754784    /* Wake up the event loop */
    755785    memset(&ev, 0, sizeof(ev));
    756786    ev.xclient.type = ClientMessage;
    757787    ev.xclient.format = 8;
    758     XSendEvent(XtDisplay(g_ctxX11.widget), XtWindow(g_ctxX11.widget), false, 0, &ev);
    759     XFlush(XtDisplay(g_ctxX11.widget));
     788    XSendEvent(XtDisplay(pCtx->widget), XtWindow(pCtx->widget), false, 0, &ev);
     789    XFlush(XtDisplay(pCtx->widget));
    760790    do
    761791    {
    762         rc = RTThreadWait(g_ctxX11.thread, 1000, &rcThread);
     792        rc = RTThreadWait(pCtx->thread, 1000, &rcThread);
    763793        ++count;
    764794        Assert(RT_SUCCESS(rc) || ((VERR_TIMEOUT == rc) && (count != 5)));
     
    768798        /* We can safely destroy this now, as only this thread ever waits
    769799         * for it. */
    770         RTSemEventDestroy(g_ctxX11.waitForData);
     800        RTSemEventDestroy(pCtx->waitForData);
    771801        AssertRC(rcThread);
    772802    }
    773803    else
    774804        LogRel(("vboxClipboardDestroy: rc=%Rrc\n", rc));
    775     XtCloseDisplay(XtDisplay(g_ctxX11.widget));
     805    XtCloseDisplay(XtDisplay(pCtx->widget));
    776806    LogFlowFunc(("returning %Rrc.\n", rc));
    777807    return rc;
     
    782812 * @param  owner who is the initial clipboard owner
    783813 */
    784 int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pBackend,
     814int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pCtx,
    785815                             enum g_eOwner owner)
    786816{
     
    792822        return VINF_SUCCESS;
    793823
    794     g_ctxX11.eOwner = owner;
     824    pCtx->eOwner = owner;
    795825    if (owner == X11)
    796         g_ctxX11.notifyVBox = true;
     826        pCtx->notifyVBox = true;
    797827    else
    798828    {
    799829        /** @todo Check whether the guest gets a format announcement at
    800830          *       startup. */
    801         VBoxX11ClipboardAnnounceVBoxFormat(pBackend, 0);
     831        VBoxX11ClipboardAnnounceVBoxFormat(pCtx, 0);
    802832    }
    803833    return VINF_SUCCESS;
     
    808838 * @note  X11 backend code
    809839 */
    810 void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pBackend)
     840void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
    811841{
    812842    /*
     
    815845    if (!g_fHaveX11)
    816846        return;
    817     g_ctxX11.notifyVBox = true;
     847    pCtx->notifyVBox = true;
    818848}
    819849
     
    822852 * @note  X11 backend code
    823853 */
    824 void VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pBackend)
     854void VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
    825855{
    826856    /*
     
    830860        return;
    831861
    832     g_ctxX11.eOwner = NONE;
    833     g_ctxX11.X11TextFormat = INVALID;
    834     g_ctxX11.X11BitmapFormat = INVALID;
     862    pCtx->eOwner = NONE;
     863    pCtx->X11TextFormat = INVALID;
     864    pCtx->X11BitmapFormat = INVALID;
    835865}
    836866
     
    850880 * @note  X11 backend code, called by the XtOwnSelection callback.
    851881 */
    852 static Boolean vboxClipboardConvertTargetsForX11(Atom *atomTypeReturn,
     882static Boolean vboxClipboardConvertTargetsForX11(VBOXCLIPBOARDCONTEXTX11
     883                                                                      *pCtx,
     884                                                 Atom *atomTypeReturn,
    853885                                                 XtPointer *pValReturn,
    854886                                                 unsigned long *pcLenReturn,
    855887                                                 int *piFormatReturn)
    856888{
    857     unsigned uListSize = g_ctxX11.formatList.size();
     889    unsigned uListSize = pCtx->formatList.size();
    858890    Atom *atomTargets = reinterpret_cast<Atom *>(XtMalloc((uListSize + 3) * sizeof(Atom)));
    859891    unsigned cTargets = 0;
     
    862894    for (unsigned i = 0; i < uListSize; ++i)
    863895    {
    864         if (   ((g_ctxX11.vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0)
    865             && (g_ctxX11.formatList[i].guestFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT))
     896        if (   ((pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0)
     897            && (   pCtx->formatList[i].guestFormat
     898                == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT))
    866899        {
    867             atomTargets[cTargets] = g_ctxX11.formatList[i].atom;
     900            atomTargets[cTargets] = pCtx->formatList[i].atom;
    868901            ++cTargets;
    869902        }
    870903    }
    871     atomTargets[cTargets] = g_ctxX11.atomTargets;
    872     atomTargets[cTargets + 1] = g_ctxX11.atomMultiple;
    873     atomTargets[cTargets + 2] = g_ctxX11.atomTimestamp;
     904    atomTargets[cTargets] = pCtx->atomTargets;
     905    atomTargets[cTargets + 1] = pCtx->atomMultiple;
     906    atomTargets[cTargets + 2] = pCtx->atomTimestamp;
    874907    if (g_debugClipboard)
    875908    {
    876909        for (unsigned i = 0; i < cTargets + 3; i++)
    877910        {
    878             char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), atomTargets[i]);
     911            char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget), atomTargets[i]);
    879912            if (szAtomName != 0)
    880913            {
     
    918951 * @note  X11 backend code, called by the callback for XtOwnSelection.
    919952 */
    920 static Boolean vboxClipboardConvertUtf16(Atom *atomTypeReturn,
     953static Boolean vboxClipboardConvertUtf16(VBOXCLIPBOARDCONTEXTX11 *pCtx,
     954                                         Atom *atomTypeReturn,
    921955                                         XtPointer *pValReturn,
    922956                                         unsigned long *pcLenReturn,
     
    930964
    931965    LogFlowFunc (("called\n"));
    932     rc = VBoxX11ClipboardReadVBoxData(g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
     966    rc = VBoxX11ClipboardReadVBoxData(pCtx->pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
    933967    if ((RT_FAILURE(rc)) || (cbVBox == 0))
    934968    {
     
    9731007    LogFlowFunc (("converted string is %.*ls. Returning.\n", cwDestLen, pu16DestText));
    9741008    RTMemFree(pvVBox);
    975     *atomTypeReturn = g_ctxX11.atomUtf16;
     1009    *atomTypeReturn = pCtx->atomUtf16;
    9761010    *pValReturn = reinterpret_cast<XtPointer>(pu16DestText);
    9771011    *pcLenReturn = cwDestLen;
     
    10011035 * @note  X11 backend code, called by the callback for XtOwnSelection.
    10021036 */
    1003 static Boolean vboxClipboardConvertToUtf8ForX11(Atom *atomTypeReturn,
     1037static Boolean vboxClipboardConvertToUtf8ForX11(VBOXCLIPBOARDCONTEXTX11
     1038                                                                      *pCtx,
     1039                                                Atom *atomTypeReturn,
    10041040                                                XtPointer *pValReturn,
    10051041                                                unsigned long *pcLenReturn,
     
    10151051    LogFlowFunc (("called\n"));
    10161052    /* Read the clipboard data from the guest. */
    1017     rc = VBoxX11ClipboardReadVBoxData(g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
     1053    rc = VBoxX11ClipboardReadVBoxData(pCtx->pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
    10181054    if ((rc != VINF_SUCCESS) || (cbVBox == 0))
    10191055    {
     
    10791115    LogFlowFunc (("converted string is %.*s. Returning.\n", cbDestLen, pu8DestText));
    10801116    RTMemFree(pvVBox);
    1081     *atomTypeReturn = g_ctxX11.atomUtf8;
     1117    *atomTypeReturn = pCtx->atomUtf8;
    10821118    *pValReturn = reinterpret_cast<XtPointer>(pu8DestText);
    10831119    *pcLenReturn = cbDestLen;
     
    11071143 * @note  X11 backend code, called by the callback for XtOwnSelection.
    11081144 */
    1109 static Boolean vboxClipboardConvertToCTextForX11(Atom *atomTypeReturn,
     1145static Boolean vboxClipboardConvertToCTextForX11(VBOXCLIPBOARDCONTEXTX11
     1146                                                                      *pCtx,
     1147                                                 Atom *atomTypeReturn,
    11101148                                                 XtPointer *pValReturn,
    11111149                                                 unsigned long *pcLenReturn,
     
    11221160    LogFlowFunc (("called\n"));
    11231161    /* Read the clipboard data from the guest. */
    1124     rc = VBoxX11ClipboardReadVBoxData(g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
     1162    rc = VBoxX11ClipboardReadVBoxData(pCtx->pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
    11251163    if ((rc != VINF_SUCCESS) || (cbVBox == 0))
    11261164    {
     
    11741212    /* And finally (!) convert the Utf8 text to compound text. */
    11751213#ifdef RT_OS_SOLARIS
    1176     rc = XmbTextListToTextProperty(XtDisplay(g_ctxX11.widget), &pu8DestText, 1,
     1214    rc = XmbTextListToTextProperty(XtDisplay(pCtx->widget), &pu8DestText, 1,
    11771215                                     XCompoundTextStyle, &property);
    11781216#else
    1179     rc = Xutf8TextListToTextProperty(XtDisplay(g_ctxX11.widget), &pu8DestText, 1,
     1217    rc = Xutf8TextListToTextProperty(XtDisplay(pCtx->widget), &pu8DestText, 1,
    11801218                                     XCompoundTextStyle, &property);
    11811219#endif
     
    12241262{
    12251263    g_eClipboardFormats eFormat = INVALID;
     1264    /** @todo find a better way around the lack of user data. */
     1265    VBOXCLIPBOARDCONTEXTX11 *pCtx = g_pCtx;
    12261266
    12271267    LogFlowFunc(("\n"));
    12281268    /* Drop requests that we receive too late. */
    1229     if (g_ctxX11.eOwner != VB)
    1230         return false;
    1231     if (   (*atomSelection != g_ctxX11.atomClipboard)
    1232         && (*atomSelection != g_ctxX11.atomPrimary)
     1269    if (pCtx->eOwner != VB)
     1270        return false;
     1271    if (   (*atomSelection != pCtx->atomClipboard)
     1272        && (*atomSelection != pCtx->atomPrimary)
    12331273       )
    12341274    {
     
    12381278    if (g_debugClipboard)
    12391279    {
    1240         char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), *atomTarget);
     1280        char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget), *atomTarget);
    12411281        if (szAtomName != 0)
    12421282        {
     
    12491289        }
    12501290    }
    1251     if (*atomTarget == g_ctxX11.atomTargets)
     1291    if (*atomTarget == pCtx->atomTargets)
    12521292    {
    12531293        eFormat = TARGETS;
     
    12551295    else
    12561296    {
    1257         for (unsigned i = 0; i != g_ctxX11.formatList.size(); ++i)
     1297        for (unsigned i = 0; i != pCtx->formatList.size(); ++i)
    12581298        {
    1259             if (g_ctxX11.formatList[i].atom == *atomTarget)
     1299            if (pCtx->formatList[i].atom == *atomTarget)
    12601300            {
    1261                 eFormat = g_ctxX11.formatList[i].format;
     1301                eFormat = pCtx->formatList[i].format;
    12621302                break;
    12631303            }
     
    12671307    {
    12681308    case TARGETS:
    1269         return vboxClipboardConvertTargetsForX11(atomTypeReturn, pValReturn,
    1270                                                  pcLenReturn, piFormatReturn);
     1309        return vboxClipboardConvertTargetsForX11(pCtx, atomTypeReturn,
     1310                                                 pValReturn, pcLenReturn,
     1311                                                 piFormatReturn);
    12711312    case UTF16:
    1272         return vboxClipboardConvertUtf16(atomTypeReturn, pValReturn, pcLenReturn,
    1273                                          piFormatReturn);
     1313        return vboxClipboardConvertUtf16(pCtx, atomTypeReturn, pValReturn,
     1314                                         pcLenReturn, piFormatReturn);
    12741315    case UTF8:
    1275         return vboxClipboardConvertToUtf8ForX11(atomTypeReturn, pValReturn,
    1276                                                 pcLenReturn, piFormatReturn);
     1316        return vboxClipboardConvertToUtf8ForX11(pCtx, atomTypeReturn,
     1317                                                pValReturn, pcLenReturn,
     1318                                                piFormatReturn);
    12771319    case CTEXT:
    1278         return vboxClipboardConvertToCTextForX11(atomTypeReturn, pValReturn,
    1279                                                  pcLenReturn, piFormatReturn);
     1320        return vboxClipboardConvertToCTextForX11(pCtx, atomTypeReturn,
     1321                                                 pValReturn, pcLenReturn,
     1322                                                 piFormatReturn);
    12801323    default:
    12811324        LogFunc (("bad format\n"));
     
    12921335static void vboxClipboardReturnToX11(Widget, Atom *)
    12931336{
     1337    /** @todo find a better way around the lack of user data */
     1338    VBOXCLIPBOARDCONTEXTX11 *pCtx = g_pCtx;
    12941339    LogFlowFunc (("called, giving VBox clipboard ownership\n"));
    1295     g_ctxX11.eOwner = X11;
    1296     g_ctxX11.notifyVBox = true;
     1340    pCtx->eOwner = X11;
     1341    pCtx->notifyVBox = true;
    12971342}
    12981343
     
    13031348 * @note  X11 backend code
    13041349 */
    1305 void VBoxX11ClipboardAnnounceVBoxFormat(VBOXCLIPBOARDCONTEXTX11 *pBackend,
     1350void VBoxX11ClipboardAnnounceVBoxFormat(VBOXCLIPBOARDCONTEXTX11 *pCtx,
    13061351                                        uint32_t u32Formats)
    13071352{
     
    13121357        return;
    13131358
    1314     g_ctxX11.vboxFormats = u32Formats;
     1359    pCtx->vboxFormats = u32Formats;
    13151360    LogFlowFunc (("u32Formats=%d\n", u32Formats));
    13161361    if (u32Formats == 0)
     
    13201365        return;
    13211366    }
    1322     if (g_ctxX11.eOwner == VB)
     1367    if (pCtx->eOwner == VB)
    13231368    {
    13241369        /* We already own the clipboard, so no need to grab it, especially as that can lead
     
    13291374    }
    13301375    Log2 (("%s: giving the guest clipboard ownership\n", __PRETTY_FUNCTION__));
    1331     g_ctxX11.eOwner = VB;
    1332     g_ctxX11.X11TextFormat = INVALID;
    1333     g_ctxX11.X11BitmapFormat = INVALID;
    1334     if (XtOwnSelection(g_ctxX11.widget, g_ctxX11.atomClipboard, CurrentTime, vboxClipboardConvertForX11,
    1335                        vboxClipboardReturnToX11, 0) != True)
     1376    pCtx->eOwner = VB;
     1377    pCtx->X11TextFormat = INVALID;
     1378    pCtx->X11BitmapFormat = INVALID;
     1379    if (XtOwnSelection(pCtx->widget, pCtx->atomClipboard, CurrentTime,
     1380                       vboxClipboardConvertForX11, vboxClipboardReturnToX11,
     1381                       0) != True)
    13361382    {
    13371383        Log2 (("%s: returning clipboard ownership to the host\n", __PRETTY_FUNCTION__));
    13381384        /* We set this so that the guest gets notified when we take the clipboard, even if no
    13391385          guest formats are found which we understand. */
    1340         g_ctxX11.notifyVBox = true;
    1341         g_ctxX11.eOwner = X11;
    1342     }
    1343     XtOwnSelection(g_ctxX11.widget, g_ctxX11.atomPrimary, CurrentTime, vboxClipboardConvertForX11,
     1386        pCtx->notifyVBox = true;
     1387        pCtx->eOwner = X11;
     1388    }
     1389    XtOwnSelection(pCtx->widget, pCtx->atomPrimary, CurrentTime, vboxClipboardConvertForX11,
    13441390                   NULL, 0);
    13451391    LogFlowFunc(("returning\n"));
     
    13571403 * @note   X11 backend code
    13581404 */
    1359 int VBoxX11ClipboardReadX11Data(VBOXCLIPBOARDCONTEXTX11 *pBackend,
     1405int VBoxX11ClipboardReadX11Data(VBOXCLIPBOARDCONTEXTX11 *pCtx,
    13601406                                uint32_t u32Format,
    13611407                                VBOXCLIPBOARDREQUEST *pRequest)
     
    13781424    if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    13791425    {
    1380         if (g_ctxX11.X11TextFormat == INVALID)
     1426        if (pCtx->X11TextFormat == INVALID)
    13811427        {
    13821428            /* No data available. */
     
    13881434        *pRequest->pcbActual = 0;
    13891435        /* Send out a request for the data to the current clipboard owner */
    1390         XtGetSelectionValue(g_ctxX11.widget, g_ctxX11.atomClipboard,
    1391                             g_ctxX11.atomX11TextFormat,
     1436        XtGetSelectionValue(pCtx->widget, pCtx->atomClipboard,
     1437                            pCtx->atomX11TextFormat,
    13921438                            vboxClipboardGetDataFromX11,
    13931439                            reinterpret_cast<XtPointer>(pRequest),
     
    13961442           callback will signal the event semaphore when it has processed the data for us. */
    13971443
    1398         int rc = RTSemEventWait(g_ctxX11.waitForData, RT_INDEFINITE_WAIT);
     1444        int rc = RTSemEventWait(pCtx->waitForData, RT_INDEFINITE_WAIT);
    13991445        if (RT_FAILURE(rc))
    14001446            return rc;
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard.h

    r18585 r18633  
    2323#define __VBOXCLIPBOARD__H
    2424
    25 #define LOG_GROUP LOG_GROUP_HGCM
     25#define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
    2626#include <VBox/log.h>
    2727
  • trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp

    r18586 r18633  
    2121 */
    2222
    23 /** @todo create a clipboard log group */
    24 #define LOG_GROUP LOG_GROUP_HGCM
    25 
    2623#include <string.h>
    2724
     
    3027#include <iprt/mem.h>
    3128#include <iprt/semaphore.h>
    32 
    33 #include <VBox/log.h>
    3429
    3530#include <VBox/GuestHost/SharedClipboard.h>
     
    309304    request.cb = cb;
    310305    request.pcbActual = pcbActual;
     306    request.pCtx = g_ctxHost.pBackend;
    311307    rc = VBoxX11ClipboardReadX11Data(g_ctxHost.pBackend, u32Format, &request);
    312308    g_ctxHost.waiter = NONE;
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