VirtualBox

Changeset 18398 in vbox for trunk/src


Ignore:
Timestamp:
Mar 27, 2009 2:21:19 PM (16 years ago)
Author:
vboxsync
Message:

HostServices/SharedClipboard: move the first code to the GuestHost directory

Location:
trunk/src/VBox
Files:
1 added
3 edited
1 copied
1 moved

Legend:

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

    r18375 r18398  
    2020 */
    2121
    22 #include "clipboard-helper.h"
    23 #include "VBox/log.h"
    2422#include <iprt/assert.h>
     23#include <VBox/log.h>
     24#include <VBox/GuestHost/clipboard-helper.h>
    2525
    2626/** @todo use const where appropriate; delinuxifiy the code (*Lin* -> *Host*); use AssertLogRel*. */
  • trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp

    r18375 r18398  
    22 *
    33 * Shared Clipboard:
    4  * Linux host.
     4 * X11 back-end.
    55 */
    66
     
    2323#include <vector>
    2424
    25 #include <VBox/HostServices/VBoxClipboardSvc.h>
     25#include <VBox/GuestHost/SharedClipboard.h>
    2626
    2727#include <iprt/alloc.h>
     
    7676    Atom atom;
    7777    g_eClipboardFormats format;
    78     unsigned guestFormat;
     78    unsigned vboxFormat;
    7979} VBOXCLIPBOARDFORMAT;
    8080
     
    126126    std::vector<VBOXCLIPBOARDFORMAT> formatList;
    127127
    128     /** Does the host or the guest currently own the clipboard? */
     128    /** Does X11 or VBox currently own the clipboard? */
    129129    volatile enum g_eOwner eOwner;
    130130
    131     /** What is the best text format the host has to offer?  INVALID for none. */
    132     g_eClipboardFormats hostTextFormat;
    133     /** Atom corresponding to the host text format */
    134     Atom atomHostTextFormat;
    135     /** What is the best bitmap format the host has to offer?  INVALID for none. */
    136     g_eClipboardFormats hostBitmapFormat;
    137     /** Atom corresponding to the host Bitmap format */
    138     Atom atomHostBitmapFormat;
    139     /** What formats does the guest have on offer? */
    140     int guestFormats;
     131    /** What is the best text format that X11 has to offer?  INVALID for none. */
     132    g_eClipboardFormats X11TextFormat;
     133    /** Atom corresponding to the X11 text format */
     134    Atom atomX11TextFormat;
     135    /** What is the best bitmap format that X11 has to offer?  INVALID for none. */
     136    g_eClipboardFormats X11BitmapFormat;
     137    /** Atom corresponding to the X11 Bitmap format */
     138    Atom atomX11BitmapFormat;
     139    /** What formats does VBox have on offer? */
     140    int vboxFormats;
    141141    /** Windows caches the clipboard data it receives.  Since we have no way of knowing whether
    142142        that data is still valid, we always send a "data changed" message after a successful
    143143        transfer to invalidate the cache. */
    144     bool notifyGuest;
     144    bool notifyVBox;
    145145
    146146    /** Since the clipboard data moves asynchronously, we use an event semaphore to wait for
     
    155155    RTSEMMUTEX clipboardMutex;
    156156
    157     /** Format which we are reading from the host clipboard (valid during a request for the
    158         host clipboard) */
    159     g_eClipboardFormats requestHostFormat;
    160     /** The guest buffer to write host clipboard data to (valid during a request for the host
     157    /** Format which we are reading from the X11 clipboard (valid during a request for the
     158        X11 clipboard) */
     159    g_eClipboardFormats requestX11Format;
     160    /** VBox's buffer to write X11 clipboard data to (valid during a request for the X11
    161161        clipboard) */
    162162    void *requestBuffer;
    163     /** The size of the guest buffer to write host clipboard data to (valid during a request for
    164         the host clipboard) */
     163    /** The size of VBox's buffer to write X11 clipboard data to (valid during a request for
     164        the X11 clipboard) */
    165165    unsigned requestBufferSize;
    166     /** The size of the host clipboard data written to the guest buffer (valid during a request
    167         for the host clipboard) */
     166    /** The size of the X11 clipboard data written to VBox's buffer (valid during a request
     167        for the X11 clipboard) */
    168168    uint32_t *requestActualSize;
    169169
     
    175175static VBOXCLIPBOARDCONTEXT g_ctx;
    176176
    177 /* Are we actually connected to the X11 servicer? */
     177/* Are we actually connected to the X server? */
    178178static bool g_fHaveX11;
    179179
    180180/**
    181  * Reset the contents of the buffer used to pass clipboard data from VBox to X11.
    182  * This must be done after every clipboard transfer.
    183  */
    184 static void vboxClipboardEmptyGuestBuffer(void)
    185 {
    186     if (g_ctx.pClient->data.pv != 0)
    187         RTMemFree(g_ctx.pClient->data.pv);
    188     g_ctx.pClient->data.pv = 0;
    189     g_ctx.pClient->data.cb = 0;
    190     g_ctx.pClient->data.u32Format = 0;
    191 }
    192 
    193 /**
    194181 * Send a request to VBox to transfer the contents of its clipboard to X11.
    195182 *
    196  * @param  pCtx      Pointer to the host clipboard structure
     183 * @param  pCtx      Pointer to the X11 clipboard structure
    197184 * @param  u32Format The format in which the data should be transfered
    198185 * @thread clipboard X11 event thread
     
    208195        /* This can legitimately happen if we disconnect during a request for
    209196         * data from X11. */
    210         LogFunc(("host requested guest clipboard data after guest had disconnected.\n"));
    211         pCtx->guestFormats = 0;
     197        LogFunc(("X11 requested VBox clipboard data after VBox had disconnected.\n"));
     198        pCtx->vboxFormats = 0;
    212199        pCtx->waiter = NONE;
    213200        return VERR_TIMEOUT;
     
    229216                              u32Format);
    230217    /* Which will signal us when it is ready.  We use a timeout here because
    231      * we can't be sure that the guest will behave correctly. */
     218     * we can't be sure that the other side will behave correctly. */
    232219    int rc = RTSemEventWait(pCtx->waitForData, CLIPBOARDTIMEOUT);
    233220    if (rc == VERR_TIMEOUT)
     
    247234        /* I believe this should not happen.  Wait until the assertions arrive
    248235         * to prove the contrary. */
    249         vboxClipboardEmptyGuestBuffer();
    250         pCtx->guestFormats = 0;
     236        vboxClipboardEmptyVBoxBuffer();
     237        pCtx->vboxFormats = 0;
    251238        return rc;
    252239    }
     
    259246/**
    260247 * Convert the UTF-16 text returned from the X11 clipboard to UTF-16LE with Windows EOLs
    261  * and place it in the global g_pcClipboardText variable.  We are reading the host clipboard to
    262  * make it available to the guest.
     248 * and place it in the global g_pcClipboardText variable.  We are reading the X11 clipboard to
     249 * make it available to VBox.
    263250 *
    264251 * @param pValue      Source UTF-16 text
     
    284271    {
    285272        /* Not enough buffer space provided - report the amount needed. */
    286         LogFlowFunc (("guest buffer too small: size %d bytes, needed %d.  Returning.\n",
     273        LogFlowFunc (("VBox's buffer too small: size %d bytes, needed %d.  Returning.\n",
    287274                       cb, cwDestLen * 2));
    288275        *pcbActual = cwDestLen * 2;
     
    336323    {
    337324        /* Not enough buffer space provided - report the amount needed. */
    338         LogFlowFunc (("guest buffer too small: size %d bytes, needed %d.  Returning.\n",
     325        LogFlowFunc (("VBox's buffer too small: size %d bytes, needed %d.  Returning.\n",
    339326                       cb, cwDestLen * 2));
    340327        *pcbActual = cwDestLen * 2;
     
    416403    {
    417404        /* Not enough buffer space provided - report the amount needed. */
    418         LogFlowFunc (("guest buffer too small: size %d bytes, needed %d.  Returning.\n",
     405        LogFlowFunc (("VBox's buffer too small: size %d bytes, needed %d.  Returning.\n",
    419406                       cb, cwDestLen * 2));
    420407        *pcbActual = cwDestLen * 2;
     
    467454    {
    468455        /* Not enough buffer space provided - report the amount needed. */
    469         LogFlowFunc (("guest buffer too small: size %d bytes\n", cb));
     456        LogFlowFunc (("VBox's buffer too small: size %d bytes\n", cb));
    470457        *pcbActual = cwDestLen * 2;
    471458        rc = VERR_BUFFER_OVERFLOW;
     
    504491{
    505492    LogFlowFunc(("pClientData=%p, *pcLen=%lu, *piFormat=%d\n", pClientData, *pcLen, *piFormat));
    506     LogFlowFunc(("g_ctx.requestHostFormat=%d, g_ctx.requestBufferSize=%d\n",
    507                  g_ctx.requestHostFormat, g_ctx.requestBufferSize));
     493    LogFlowFunc(("g_ctx.requestX11Format=%d, g_ctx.requestBufferSize=%d\n",
     494                 g_ctx.requestX11Format, g_ctx.requestBufferSize));
    508495    unsigned cTextLen = (*pcLen) * (*piFormat) / 8;
    509496    /* The X Toolkit may have failed to get the clipboard selection for us. */
     
    526513
    527514    /* In which format did we request the clipboard data? */
    528     switch (g_ctx.requestHostFormat)
     515    switch (g_ctx.requestX11Format)
    529516    {
    530517    case UTF16:
     
    542529        char *pu8SourceText = reinterpret_cast<char *>(pValue);
    543530
    544         if ((g_ctx.requestHostFormat == UTF8)
     531        if ((g_ctx.requestX11Format == UTF8)
    545532            && (RTStrUniLenEx(pu8SourceText, *pcLen, &cStringLen) == VINF_SUCCESS))
    546533        {
     
    562549        return;
    563550    }
    564     g_ctx.notifyGuest = true;
     551    g_ctx.notifyVBox = true;
    565552    RTSemMutexRelease(g_ctx.clipboardMutex);
    566553}
     
    587574    if (*atomType == XT_CONVERT_FAIL)
    588575    {
    589         LogFunc (("reading clipboard from host, X toolkit failed to convert the selection\n"));
     576        LogFunc (("reading clipboard from X11, X toolkit failed to convert the selection\n"));
    590577        return;
    591578    }
     
    618605            if (szAtomName != 0)
    619606            {
    620                 Log2 (("%s: the host offers target %s\n", __PRETTY_FUNCTION__,
     607                Log2 (("%s: X11 offers target %s\n", __PRETTY_FUNCTION__,
    621608                       szAtomName));
    622609                XFree(szAtomName);
     
    624611        }
    625612    }
    626     g_ctx.atomHostTextFormat = atomBestTarget;
    627     if ((eBestTarget != g_ctx.hostTextFormat) || (g_ctx.notifyGuest == true))
     613    g_ctx.atomX11TextFormat = atomBestTarget;
     614    if ((eBestTarget != g_ctx.X11TextFormat) || (g_ctx.notifyVBox == true))
    628615    {
    629616        uint32_t u32Formats = 0;
     
    633620            {
    634621                char *szAtomName = XGetAtomName(XtDisplay(g_ctx.widget), atomBestTarget);
    635                 Log2 (("%s: switching to host text target %s.  Available targets are:\n",
     622                Log2 (("%s: switching to X11 text target %s.  Available targets are:\n",
    636623                       __PRETTY_FUNCTION__, szAtomName));
    637624                XFree(szAtomName);
    638625            }
    639626            else
    640                 Log2(("%s: no supported host text target found.  Available targets are:\n",
     627                Log2(("%s: no supported X11 text target found.  Available targets are:\n",
    641628                      __PRETTY_FUNCTION__));
    642629            for (unsigned i = 0; i < cAtoms; ++i)
     
    650637            }
    651638        }
    652         g_ctx.hostTextFormat = eBestTarget;
     639        g_ctx.X11TextFormat = eBestTarget;
    653640        if (eBestTarget != INVALID)
    654641            u32Formats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
    655642        vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS,
    656643                                   u32Formats);
    657         g_ctx.notifyGuest = false;
     644        g_ctx.notifyVBox = false;
    658645    }
    659646    XtFree(reinterpret_cast<char *>(pValue));
     
    673660    if (g_ctx.eOwner == X11 && g_ctx.pClient != 0)
    674661    {
    675         Log3 (("%s: requesting the targets that the host clipboard offers\n",
     662        Log3 (("%s: requesting the targets that the X11 clipboard offers\n",
    676663               __PRETTY_FUNCTION__));
    677664        XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atomTargets,
     
    686673    use. */
    687674static void vboxClipboardAddFormat(const char *pszName, g_eClipboardFormats eFormat,
    688                                    unsigned guestFormat)
     675                                   unsigned vboxFormat)
    689676{
    690677    VBOXCLIPBOARDFORMAT sFormat;
     
    693680    sFormat.atom   = atomFormat;
    694681    sFormat.format = eFormat;
    695     sFormat.guestFormat = guestFormat;
     682    sFormat.vboxFormat = vboxFormat;
    696683    g_ctx.formatList.push_back(sFormat);
    697684    LogFlow (("vboxClipboardAddFormat: added format %s (%d)\n", pszName, eFormat));
     
    704691static int vboxClipboardThread(RTTHREAD self, void * /* pvUser */)
    705692{
    706     LogRel(("Shared clipboard: starting host clipboard thread\n"));
    707 
    708     /* Set up a timer to poll the host clipboard */
     693    LogRel(("Shared clipboard: starting X11 clipboard thread\n"));
     694
     695    /* Set up a timer to poll the X11 clipboard */
    709696    XtAppAddTimeOut(g_ctx.appContext, 200 /* ms */, vboxClipboardPollX11ForTargets, 0);
    710697
    711698    XtAppMainLoop(g_ctx.appContext);
    712699    g_ctx.formatList.clear();
    713     LogRel(("Shared clipboard: host clipboard thread terminated successfully\n"));
     700    LogRel(("Shared clipboard: X11 clipboard thread terminated successfully\n"));
    714701    return VINF_SUCCESS;
    715702}
     
    736723    if (NULL == pDisplay)
    737724    {
    738         LogRel(("Shared clipboard: failed to connect to the host clipboard - the window system may not be running.\n"));
     725        LogRel(("Shared clipboard: failed to connect to the X11 clipboard - the window system may not be running.\n"));
    739726        rc = VERR_NOT_SUPPORTED;
    740727    }
     
    745732        if (NULL == g_ctx.widget)
    746733        {
    747             LogRel(("Shared clipboard: failed to construct the X11 window for the host clipboard manager.\n"));
     734            LogRel(("Shared clipboard: failed to construct the X11 window for the X11 clipboard manager.\n"));
    748735            rc = VERR_NO_MEMORY;
    749736        }
     
    792779
    793780/**
    794  * Initialise the host side of the shared clipboard.
     781 * Initialise the X11 side of the shared clipboard.
    795782 * @note    Called by the HGCM clipboard service
    796783 * @thread  HGCM clipboard service thread
     
    807794         * silently and report success on every call. This is important for VBoxHeadless.
    808795         */
    809         LogRelFunc(("no X11 detected -- host clipboard disabled\n"));
     796        LogRelFunc(("no X11 detected -- X11 clipboard disabled\n"));
    810797        g_fHaveX11 = false;
    811798        return VINF_SUCCESS;
     
    815802    {
    816803        g_testUtf16 = true;
    817         LogRel(("Host clipboard: testing Utf16\n"));
     804        LogRel(("X11 clipboard: testing Utf16\n"));
    818805    }
    819806    else if (RTEnvGet("VBOX_CBTEST_UTF8"))
    820807    {
    821808        g_testUtf8 = true;
    822         LogRel(("Host clipboard: testing Utf8\n"));
     809        LogRel(("X11 clipboard: testing Utf8\n"));
    823810    }
    824811    else if (RTEnvGet("VBOX_CBTEST_CTEXT"))
    825812    {
    826813        g_testCText = true;
    827         LogRel(("Host clipboard: testing compound text\n"));
     814        LogRel(("X11 clipboard: testing compound text\n"));
    828815    }
    829816    else if (RTEnvGet("VBOX_CBDEBUG"))
    830817    {
    831818        g_debugClipboard = true;
    832         LogRel(("Host clipboard: enabling additional debugging output\n"));
     819        LogRel(("X11 clipboard: enabling additional debugging output\n"));
    833820    }
    834821
    835822    g_fHaveX11 = true;
    836823
    837     LogRel(("Initializing host clipboard service\n"));
     824    LogRel(("Initializing X11 clipboard service\n"));
    838825    RTSemEventCreate(&g_ctx.waitForData);
    839826    RTSemMutexCreate(&g_ctx.clipboardMutex);
     
    844831                            RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP");
    845832        if (RT_FAILURE(rc))
    846             LogRel(("Failed to start the host shared clipboard thread.\n"));
     833            LogRel(("Failed to start the X11 shared clipboard thread.\n"));
    847834    }
    848835    if (RT_FAILURE(rc))
     
    855842
    856843/**
    857  * Terminate the host side of the shared clipboard.
     844 * Terminate the X11 side of the shared clipboard.
    858845 * @note    Called by the HGCM clipboard service
    859846 * @thread  HGCM clipboard service thread
     
    866853
    867854    /*
    868      * Immediately return if we are not connected to the host X server.
     855     * Immediately return if we are not connected to the X server.
    869856     */
    870857    if (!g_fHaveX11)
    871858        return;
    872859
    873     LogRel(("vboxClipboardDestroy: shutting down host clipboard\n"));
     860    LogRel(("vboxClipboardDestroy: shutting down X11 clipboard\n"));
    874861
    875862    /* Drop the reference to the client, in case it is still there.  This will
     
    922909
    923910/**
    924  * Connect a guest the shared clipboard.
    925  *
    926  * @param   pClient Structure containing context information about the guest system
     911 * Connect VBox to the shared clipboard.
     912 *
     913 * @param   pClient Structure containing context information from VBox
    927914 * @returns RT status code
    928915 * @note    Called by the HGCM clipboard service
     
    932919{
    933920    /*
    934      * Immediately return if we are not connected to the host X server.
     921     * Immediately return if we are not connected to the X server.
    935922     */
    936923    if (!g_fHaveX11)
     
    945932    pClient->pCtx->pClient = pClient;
    946933    g_ctx.eOwner = X11;
    947     g_ctx.notifyGuest = true;
     934    g_ctx.notifyVBox = true;
    948935    return VINF_SUCCESS;
    949936}
    950937
    951938/**
    952  * Synchronise the contents of the host clipboard with the guest, called
    953  * after a save and restore of the guest.
     939 * Synchronise the contents of the X11 clipboard with VBox, called
     940 * after a save and restore of VBox.
    954941 * @note    Called by the HGCM clipboard service
    955942 * @thread  HGCM clipboard service thread
     
    958945{
    959946    /*
    960      * Immediately return if we are not connected to the host X server.
     947     * Immediately return if we are not connected to the X server.
    961948     */
    962949    if (!g_fHaveX11)
    963950        return VINF_SUCCESS;
    964951
    965     /* On a Linux host, the guest should never synchronise/cache its clipboard contents, as
    966        we have no way of reliably telling when the host clipboard data changes.  So instead
    967        of synchronising, we tell the guest to empty its clipboard, and we set the cached
    968        flag so that we report formats to the guest next time we poll for them. */
     952    /* On X11, VBox should never synchronise/cache its clipboard contents, as
     953       we have no way of reliably telling when the X11 clipboard data changes.  So instead
     954       of synchronising, we tell VBox to empty its clipboard, and we set the cached
     955       flag so that we report formats to VBox next time we poll for them. */
    969956    vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 0);
    970     g_ctx.notifyGuest = true;
     957    g_ctx.notifyVBox = true;
    971958
    972959    return VINF_SUCCESS;
     
    974961
    975962/**
    976  * Shut down the shared clipboard service and "disconnect" the guest.
     963 * Shut down the shared clipboard service and "disconnect" VBox.
    977964 * @note    Called by the HGCM clipboard service
    978965 * @thread  HGCM clipboard service thread
     
    981968{
    982969    /*
    983      * Immediately return if we are not connected to the host X server.
     970     * Immediately return if we are not connected to the X server.
    984971     */
    985972    if (!g_fHaveX11)
     
    991978    g_ctx.pClient = NULL;
    992979    g_ctx.eOwner = NONE;
    993     g_ctx.hostTextFormat = INVALID;
    994     g_ctx.hostBitmapFormat = INVALID;
     980    g_ctx.X11TextFormat = INVALID;
     981    g_ctx.X11BitmapFormat = INVALID;
    995982    RTSemMutexRelease(g_ctx.clipboardMutex);
    996983}
     
    10191006    for (unsigned i = 0; i < uListSize; ++i)
    10201007    {
    1021         if (   ((g_ctx.guestFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0)
    1022             && (g_ctx.formatList[i].guestFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT))
     1008        if (   ((g_ctx.vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0)
     1009            && (g_ctx.formatList[i].vboxFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT))
    10231010        {
    10241011            atomTargets[cTargets] = g_ctx.formatList[i].atom;
     
    10551042
    10561043/**
    1057  * Satisfy a request from the host to convert the clipboard text to Utf16.  We return non-zero
     1044 * Satisfy a request from the X11 to convert the clipboard text to Utf16.  We return non-zero
    10581045 * terminated text.
    10591046 *
     
    10801067        LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc,
    10811068                    RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
    1082         vboxClipboardEmptyGuestBuffer();
     1069        vboxClipboardEmptyVBoxBuffer();
    10831070        return false;
    10841071    }
     
    10901077    {
    10911078        LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
    1092         vboxClipboardEmptyGuestBuffer();
     1079        vboxClipboardEmptyVBoxBuffer();
    10931080        AssertRCReturn(rc, false);
    10941081    }
    10951082    if (cwDestLen == 0)
    10961083    {
    1097         LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));
    1098         vboxClipboardEmptyGuestBuffer();
     1084        LogFlowFunc(("received empty clipboard data from VBox, returning false.\n"));
     1085        vboxClipboardEmptyVBoxBuffer();
    10991086        return false;
    11001087    }
     
    11031090    {
    11041091        LogRel(("vboxClipboardConvertUtf16: failed to allocate %d bytes\n", cwDestLen * 2));
    1105         vboxClipboardEmptyGuestBuffer();
     1092        vboxClipboardEmptyVBoxBuffer();
    11061093        return false;
    11071094    }
     
    11121099        LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed.  vboxClipboardUtf16WinToLin returned %Rrc.  Abandoning.\n", rc));
    11131100        XtFree(reinterpret_cast<char *>(pu16DestText));
    1114         vboxClipboardEmptyGuestBuffer();
     1101        vboxClipboardEmptyVBoxBuffer();
    11151102        return false;
    11161103    }
    11171104    LogFlowFunc (("converted string is %.*ls. Returning.\n", cwDestLen, pu16DestText));
    1118     vboxClipboardEmptyGuestBuffer();
     1105    vboxClipboardEmptyVBoxBuffer();
    11191106    *atomTypeReturn = g_ctx.atomUtf16;
    11201107    *pValReturn = reinterpret_cast<XtPointer>(pu16DestText);
     
    11251112
    11261113/**
    1127  * Satisfy a request from the host to convert the clipboard text to Utf8.
     1114 * Satisfy a request from the X11 to convert the clipboard text to Utf8.
    11281115 *
    11291116 * @returns true if we successfully convert the data to the format requested, false otherwise.
     
    11481135
    11491136    LogFlowFunc (("called\n"));
    1150     /* Read the clipboard data from the guest. */
     1137    /* Read the clipboard data from VBox. */
    11511138    rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    11521139    if ((rc != VINF_SUCCESS) || (g_ctx.pClient->data.cb == 0))
     
    11551142        LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc,
    11561143                     RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
    1157         vboxClipboardEmptyGuestBuffer();
     1144        vboxClipboardEmptyVBoxBuffer();
    11581145        return false;
    11591146    }
     
    11651152    {
    11661153        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
    1167         vboxClipboardEmptyGuestBuffer();
     1154        vboxClipboardEmptyVBoxBuffer();
    11681155        AssertRCReturn(rc, false);
    11691156    }
    11701157    if (cwDestLen == 0)
    11711158    {
    1172         LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));
    1173         vboxClipboardEmptyGuestBuffer();
     1159        LogFlowFunc(("received empty clipboard data from VBox, returning false.\n"));
     1160        vboxClipboardEmptyVBoxBuffer();
    11741161        return false;
    11751162    }
     
    11781165    {
    11791166        LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2));
    1180         vboxClipboardEmptyGuestBuffer();
     1167        vboxClipboardEmptyVBoxBuffer();
    11811168        return false;
    11821169    }
     
    11871174        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
    11881175        RTMemFree(reinterpret_cast<void *>(pu16DestText));
    1189         vboxClipboardEmptyGuestBuffer();
     1176        vboxClipboardEmptyVBoxBuffer();
    11901177        return false;
    11911178    }
     
    11971184        LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 4));
    11981185        RTMemFree(reinterpret_cast<void *>(pu16DestText));
    1199         vboxClipboardEmptyGuestBuffer();
     1186        vboxClipboardEmptyVBoxBuffer();
    12001187        return false;
    12011188    }
     
    12081195        LogRelFunc (("clipboard conversion failed.  RTUtf16ToUtf8Ex() returned %Rrc.  Abandoning.\n", rc));
    12091196        XtFree(pu8DestText);
    1210         vboxClipboardEmptyGuestBuffer();
     1197        vboxClipboardEmptyVBoxBuffer();
    12111198        return false;
    12121199    }
    12131200    LogFlowFunc (("converted string is %.*s. Returning.\n", cbDestLen, pu8DestText));
    1214     vboxClipboardEmptyGuestBuffer();
     1201    vboxClipboardEmptyVBoxBuffer();
    12151202    *atomTypeReturn = g_ctx.atomUtf8;
    12161203    *pValReturn = reinterpret_cast<XtPointer>(pu8DestText);
     
    12211208
    12221209/**
    1223  * Satisfy a request from the host to convert the clipboard text to COMPOUND_TEXT.
     1210 * Satisfy a request from the X11 to convert the clipboard text to COMPOUND_TEXT.
    12241211 *
    12251212 * @returns true if we successfully convert the data to the format requested, false otherwise.
     
    12451232
    12461233    LogFlowFunc (("called\n"));
    1247     /* Read the clipboard data from the guest. */
     1234    /* Read the clipboard data from VBox. */
    12481235    rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    12491236    if ((rc != VINF_SUCCESS) || (g_ctx.pClient->data.cb == 0))
     
    12521239        LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc,
    12531240                      RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
    1254         vboxClipboardEmptyGuestBuffer();
     1241        vboxClipboardEmptyVBoxBuffer();
    12551242        return false;
    12561243    }
     
    12621249    {
    12631250        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
    1264         vboxClipboardEmptyGuestBuffer();
     1251        vboxClipboardEmptyVBoxBuffer();
    12651252        AssertRCReturn(rc, false);
    12661253    }
    12671254    if (cwDestLen == 0)
    12681255    {
    1269         LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));
    1270         vboxClipboardEmptyGuestBuffer();
     1256        LogFlowFunc(("received empty clipboard data from VBox, returning false.\n"));
     1257        vboxClipboardEmptyVBoxBuffer();
    12711258        return false;
    12721259    }
     
    12751262    {
    12761263        LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2));
    1277         vboxClipboardEmptyGuestBuffer();
     1264        vboxClipboardEmptyVBoxBuffer();
    12781265        return false;
    12791266    }
     
    12841271        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
    12851272        RTMemFree(reinterpret_cast<void *>(pu16DestText));
    1286         vboxClipboardEmptyGuestBuffer();
     1273        vboxClipboardEmptyVBoxBuffer();
    12871274        return false;
    12881275    }
     
    12931280    {
    12941281        LogRelFunc (("clipboard conversion failed.  RTUtf16ToUtf8Ex() returned %Rrc.  Abandoning.\n", rc));
    1295         vboxClipboardEmptyGuestBuffer();
     1282        vboxClipboardEmptyVBoxBuffer();
    12961283        return false;
    12971284    }
     
    13241311        LogRelFunc (("Xutf8TextListToTextProperty failed.  Reason: %s\n",
    13251312                pcReason));
    1326         vboxClipboardEmptyGuestBuffer();
     1313        vboxClipboardEmptyVBoxBuffer();
    13271314        return false;
    13281315    }
    13291316    LogFlowFunc (("converted string is %s. Returning.\n", property.value));
    1330     vboxClipboardEmptyGuestBuffer();
     1317    vboxClipboardEmptyVBoxBuffer();
    13311318    *atomTypeReturn = property.encoding;
    13321319    *pValReturn = reinterpret_cast<XtPointer>(property.value);
     
    14201407    LogFlowFunc (("called, giving VBox clipboard ownership\n"));
    14211408    g_ctx.eOwner = X11;
    1422     g_ctx.notifyGuest = true;
     1409    g_ctx.notifyVBox = true;
    14231410}
    14241411
     
    14261413 * VBox is taking possession of the shared clipboard.
    14271414 *
    1428  * @param pClient    Context data for the guest system
    1429  * @param u32Formats Clipboard formats the guest is offering
     1415 * @param pClient    Context data from VBox
     1416 * @param u32Formats Clipboard formats that VBox is offering
    14301417 * @note    Called by the HGCM clipboard service
    14311418 * @thread  HGCM clipboard service thread
     
    14341421{
    14351422    /*
    1436      * Immediately return if we are not connected to the host X server.
     1423     * Immediately return if we are not connected to the X server.
    14371424     */
    14381425    if (!g_fHaveX11)
    14391426        return;
    14401427
    1441     pClient->pCtx->guestFormats = u32Formats;
     1428    pClient->pCtx->vboxFormats = u32Formats;
    14421429    LogFlowFunc (("u32Formats=%d\n", u32Formats));
    14431430    if (u32Formats == 0)
     
    14511438        /* We already own the clipboard, so no need to grab it, especially as that can lead
    14521439           to races due to the asynchronous nature of the X11 clipboard.  This event may also
    1453            have been sent out by the guest to invalidate the Windows clipboard cache. */
     1440           have been sent out by VBox to invalidate the Windows clipboard cache. */
    14541441        LogFlowFunc(("returning\n"));
    14551442        return;
    14561443    }
    1457     Log2 (("%s: giving the guest clipboard ownership\n", __PRETTY_FUNCTION__));
     1444    Log2 (("%s: giving VBox clipboard ownership\n", __PRETTY_FUNCTION__));
    14581445    g_ctx.eOwner = VB;
    1459     g_ctx.hostTextFormat = INVALID;
    1460     g_ctx.hostBitmapFormat = INVALID;
     1446    g_ctx.X11TextFormat = INVALID;
     1447    g_ctx.X11BitmapFormat = INVALID;
    14611448    if (XtOwnSelection(g_ctx.widget, g_ctx.atomClipboard, CurrentTime, vboxClipboardConvertForX11,
    14621449                       vboxClipboardReturnToX11, 0) != True)
    14631450    {
    1464         Log2 (("%s: returning clipboard ownership to the host\n", __PRETTY_FUNCTION__));
    1465         /* We set this so that the guest gets notified when we take the clipboard, even if no
    1466           guest formats are found which we understand. */
    1467         g_ctx.notifyGuest = true;
     1451        Log2 (("%s: returning clipboard ownership to X11\n", __PRETTY_FUNCTION__));
     1452        /* We set this so that VBox gets notified when we take the clipboard, even if no
     1453          VBox formats are found which we understand. */
     1454        g_ctx.notifyVBox = true;
    14681455        g_ctx.eOwner = X11;
    14691456    }
     
    14771464 * Called when VBox wants to read the X11 clipboard.
    14781465 *
    1479  * @param pClient   Context information about the guest VM
    1480  * @param u32Format The format that the guest would like to receive the data in
     1466 * @param pClient   Context information from VBox
     1467 * @param u32Format The format that VBox would like to receive the data in
    14811468 * @param pv        Where to write the data to
    14821469 * @param cb        The size of the buffer to write the data to
     
    14891476{
    14901477    /*
    1491      * Immediately return if we are not connected to the host X server.
     1478     * Immediately return if we are not connected to the X server.
    14921479     */
    14931480    if (!g_fHaveX11)
     
    15011488
    15021489    /*
    1503      * The guest wants to read data in the given format.
     1490     * VBox wants to read data in the given format.
    15041491     */
    15051492    if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    15061493    {
    1507         if (g_ctx.hostTextFormat == INVALID)
     1494        if (g_ctx.X11TextFormat == INVALID)
    15081495        {
    15091496            /* No data available. */
    15101497            *pcbActual = 0;
    1511             return VERR_NO_DATA;  /* The guest thinks we have data and we don't */
     1498            return VERR_NO_DATA;  /* VBox thinks we have data and we don't */
    15121499        }
    15131500        /* No one else (VBox or X11) should currently be waiting.  The first because
     
    15151502         * grabbed the clipboard, so it should not be waiting for data from us. */
    15161503        AssertLogRelReturn (ASMAtomicCmpXchgU32(&g_ctx.waiter, VB, NONE), VERR_DEADLOCK);
    1517         g_ctx.requestHostFormat = g_ctx.hostTextFormat;
     1504        g_ctx.requestX11Format = g_ctx.X11TextFormat;
    15181505        g_ctx.requestBuffer = pv;
    15191506        g_ctx.requestBufferSize = cb;
     
    15231510        *pcbActual = 0;
    15241511        /* Send out a request for the data to the current clipboard owner */
    1525         XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atomHostTextFormat,
     1512        XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atomX11TextFormat,
    15261513                            vboxClipboardGetDataFromX11, reinterpret_cast<XtPointer>(g_ctx.pClient),
    15271514                            CurrentTime);
     
    15471534 * Called when we have requested data from VBox and that data has arrived.
    15481535 *
    1549  * @param pClient   Context information about the guest VM
     1536 * @param pClient   Context information from VBox
    15501537 * @param pv        Buffer to which the data was written
    15511538 * @param cb        The size of the data written
  • trunk/src/VBox/HostServices/SharedClipboard/Makefile.kmk

    r18245 r18398  
    3838VBoxSharedClipboard_SOURCES.darwin = \
    3939        darwin.cpp \
    40         clipboard-helper.cpp \
     40        $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp \
    4141        darwin-pasteboard.cpp
    4242if1of ($(KBUILD_TARGET), linux solaris) ## @todo X11
    4343 ifndef VBOX_HEADLESS
    4444  VBoxSharedClipboard_SOURCES += \
    45         clipboard-helper.cpp \
     45        $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp \
    4646        x11-clipboard.cpp
    4747 else
  • trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp

    r13837 r18398  
    2929#include "VBox/log.h"
    3030#include "VBox/HostServices/VBoxClipboardSvc.h"
    31 #include "clipboard-helper.h"
     31#include "VBox/GuestHost/clipboard-helper.h"
    3232
    3333/* For debugging */
  • trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp

    r18245 r18398  
    2121 */
    2222
     23#include <string.h>
     24#include <stdio.h>
     25#include <stdint.h>
     26
     27#ifdef RT_OS_SOLARIS
     28#include <tsol/label.h>
     29#endif
     30
    2331#include <vector>
    2432
    25 #include <VBox/HostServices/VBoxClipboardSvc.h>
     33#include <X11/Xlib.h>
     34#include <X11/Xatom.h>
     35#include <X11/Intrinsic.h>
     36#include <X11/Shell.h>
     37#include <X11/Xproto.h>
     38#include <X11/StringDefs.h>
    2639
    2740#include <iprt/alloc.h>
     
    3447#include <iprt/process.h>
    3548#include <iprt/semaphore.h>
    36 #include <string.h>
    37 #include <stdio.h>
    38 #include <stdint.h>
     49
     50#include <VBox/GuestHost/clipboard-helper.h>
     51#include <VBox/HostServices/VBoxClipboardSvc.h>
    3952
    4053#include "VBoxClipboard.h"
    41 #include "clipboard-helper.h"
    42 
    43 #include <X11/Xlib.h>
    44 #include <X11/Xatom.h>
    45 #include <X11/Intrinsic.h>
    46 #include <X11/Shell.h>
    47 #include <X11/Xproto.h>
    48 #include <X11/StringDefs.h>
    49 
    50 #ifdef RT_OS_SOLARIS
    51 #include <tsol/label.h>
    52 #endif
    5354
    5455/** Do we want to test Utf16 by disabling other text formats? */
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