VirtualBox

Changeset 18551 in vbox


Ignore:
Timestamp:
Mar 30, 2009 2:37:40 PM (15 years ago)
Author:
vboxsync
Message:

HostServices/SharedClipboard/x11: removed an unneeded mutex, remove some dependencies on globals and add comments and todos

File:
1 edited

Legend:

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

    r18417 r18551  
    9595} VBOXBITMAPFILEHEADER;
    9696
    97 /** Global context information used by the host clipboard subsystem */
     97/** Global context information used by the host glue for the X11 clipboard
     98 * backend */
    9899struct _VBOXCLIPBOARDCONTEXT
    99100{
     
    108109    /** This mutex is grabbed during any critical operations on the clipboard
    109110     * which might clash with others. */
    110     /** @todo this is still used in X11 backend parts, disentangle it. */
    111111    RTSEMMUTEX clipboardMutex;
    112 
    113     /** @todo both the VBox subsystem and the X11 backend need the following
    114      * members, so we need to transfer them between the two contexts at
    115      * an appropriate time */
    116     /** Format which we are reading from the X11 clipboard (valid during a
    117      * request for its contents) */
    118     g_eClipboardFormats requestX11Format;
    119     /** The buffer to write X11 clipboard data to (valid during a request
    120      * for the clipboard contents) */
    121     void *requestBuffer;
    122     /** The size of the buffer to write X11 clipboard data to (valid during
    123      * a request for the clipboard contents) */
    124     unsigned requestBufferSize;
    125     /** The size of the X11 clipboard data written to the buffer (valid
    126      * during a request for the clipboard contents) */
    127     uint32_t *requestActualSize;
    128112
    129113    /** Pointer to the client data structure */
     
    187171     * when the data arrives. */
    188172    RTSEMEVENT waitForData;
    189 
    190     /** Format which we are reading from the X11 clipboard (valid during a
    191      * request for its contents) */
    192     g_eClipboardFormats requestX11Format;
     173};
     174
     175typedef struct _VBOXCLIPBOARDCONTEXTX11 VBOXCLIPBOARDCONTEXTX11;
     176
     177/** A structure containing information about where to store a request
     178 * for the X11 clipboard contents. */
     179struct _VBOXCLIPBOARDREQUEST
     180{
    193181    /** The buffer to write X11 clipboard data to (valid during a request
    194182     * for the clipboard contents) */
    195     void *requestBuffer;
     183    void *pv;
    196184    /** The size of the buffer to write X11 clipboard data to (valid during
    197185     * a request for the clipboard contents) */
    198     unsigned requestBufferSize;
     186    unsigned cb;
    199187    /** The size of the X11 clipboard data written to the buffer (valid
    200188     * during a request for the clipboard contents) */
    201     uint32_t *requestActualSize;
     189    uint32_t *pcbActual;
    202190};
    203191
    204 typedef struct _VBOXCLIPBOARDCONTEXTX11 VBOXCLIPBOARDCONTEXTX11;
     192typedef struct _VBOXCLIPBOARDREQUEST VBOXCLIPBOARDREQUEST;
    205193
    206194/* Only one client is supported. There seems to be no need for more clients.
     
    222210 * @param  pcb       On success, this contains the number of bytes of data
    223211 *                   returned
     212 * @note   Host glue code.
    224213 */
    225214static int vboxClipboardReadDataFromVBox (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, void **ppv, uint32_t *pcb)
     
    290279
    291280/**
    292  * Convert the UTF-16 text returned from the X11 clipboard to UTF-16LE with Windows EOLs
    293  * and place it in the global g_pcClipboardText variable.  We are reading the host clipboard to
    294  * make it available to the guest.
     281 * Convert the UTF-16 text obtained from the X11 clipboard to UTF-16LE with
     282 * Windows EOLs, place it in the buffer supplied and signal that data has
     283 * arrived.
    295284 *
    296285 * @param pValue      Source UTF-16 text
     
    300289 * @param pcbActual   Where to store the size of the converted data
    301290 * @param pClient     Pointer to the client context structure
    302  */
    303 static void vboxClipboardGetUtf16(XtPointer pValue, unsigned cwSrcLen, void *pv, unsigned cb,
     291 * @note  X11 backend code, called from the Xt callback when we wish to read
     292 *        the X11 clipboard.
     293 */
     294static void vboxClipboardGetUtf16(XtPointer pValue, unsigned cwSrcLen,
     295                                  void *pv, unsigned cb,
    304296                                  uint32_t *pcbActual)
    305297{
     
    336328
    337329/**
    338  * Convert the UTF-8 text returned from the X11 clipboard to UTF-16LE with Windows EOLS.
    339  * We are reading the X11 clipboard to make it available to VBox.
     330 * Convert the UTF-8 text obtained from the X11 clipboard to UTF-16LE with
     331 * Windows EOLs, place it in the buffer supplied and signal that data has
     332 * arrived.
    340333 *
    341334 * @param pValue      Source UTF-8 text
     
    345338 * @param pcbActual   Where to store the size of the converted data
    346339 * @param pClient     Pointer to the client context structure
    347  * @thread clipboard X11 event thread
    348  * @note   called by vboxClipboardGetDataFromX11
     340 * @note  X11 backend code, called from the Xt callback when we wish to read
     341 *        the X11 clipboard.
    349342 */
    350343static void vboxClipboardGetUtf8FromX11(XtPointer pValue, unsigned cbSrcLen,
     
    388381
    389382/**
    390  * Convert the COMPOUND_TEXT text returned from the X11 clipboard to UTF-16LE with Windows
    391  * EOLS.  We are reading the X11 clipboard to make it available to VBox.
    392  *
    393  * @param pValue      Source COMPOUND_TEXT text
     383 * Convert the COMPOUND_TEXT obtained from the X11 clipboard to UTF-16LE with
     384 * Windows EOLs, place it in the buffer supplied and signal that data has
     385 * arrived.
     386 *
     387 * @param pValue      Source COMPOUND_TEXT
    394388 * @param cbSourceLen Length in 8-bit bytes of the source text
    395389 * @param pv          Where to store the converted data
     
    397391 * @param pcbActual   Where to store the size of the converted data
    398392 * @param pClient     Pointer to the client context structure
    399  * @thread clipboard X11 event thread
    400  * @note   called by vboxClipboardGetDataFromX11
     393 * @note  X11 backend code, called from the Xt callback when we wish to read
     394 *        the X11 clipboard.
    401395 */
    402396static void vboxClipboardGetCTextFromX11(XtPointer pValue, unsigned cbSrcLen,
     
    469463
    470464/**
    471  * Convert the Latin1 text returned from the X11 clipboard to UTF-16LE with Windows EOLS
    472  * and place it in the global g_pcClipboardText variable.  We are reading the X11 clipboard to
    473  * make it available to VBox.
     465 * Convert the Latin1 text obtained from the X11 clipboard to UTF-16LE with
     466 * Windows EOLs, place it in the buffer supplied and signal that data has
     467 * arrived.
    474468 *
    475469 * @param pValue      Source Latin1 text
     
    479473 * @param pcbActual   Where to store the size of the converted data
    480474 * @param pClient     Pointer to the client context structure
    481  * @thread clipboard X11 event thread
    482  * @note   called by vboxClipboardGetDataFromX11
    483  */
    484 static void vboxClipboardGetLatin1FromX11(XtPointer pValue, unsigned cbSourceLen, void *pv, unsigned cb,
    485                                    uint32_t *pcbActual)
     475 * @note  X11 backend code, called from the Xt callback when we wish to read
     476 *        the X11 clipboard.
     477 */
     478static void vboxClipboardGetLatin1FromX11(XtPointer pValue,
     479                                          unsigned cbSourceLen, void *pv,
     480                                          unsigned cb, uint32_t *pcbActual)
    486481{
    487482    unsigned cwDestLen = cbSourceLen + 1;
     
    524519
    525520/**
    526  * Convert the clipboard text from the current format to Utf-16 with Windows line breaks.
    527  * We are reading the X11 clipboard to make it available to VBox.
    528  * @thread  clipboard X11 event thread
    529  * @note    Callback for XtGetSelectionValue, called from vboxClipboardReadData
     521 * Convert the text obtained from the X11 clipboard to UTF-16LE with Windows
     522 * EOLs, place it in the buffer supplied and signal that data has arrived.
     523 * @note  X11 backend code, callback for XtGetSelectionValue, for use when
     524 *        the X11 clipboard contains a text format we understand.
    530525 */
    531526static void vboxClipboardGetDataFromX11(Widget, XtPointer pClientData,
    532                                         Atom * /* selection */, Atom *atomType,
     527                                        Atom * /* selection */,
     528                                        Atom *atomType,
    533529                                        XtPointer pValue,
    534530                                        long unsigned int *pcLen,
    535531                                        int *piFormat)
    536532{
    537     LogFlowFunc(("pClientData=%p, *pcLen=%lu, *piFormat=%d\n", pClientData, *pcLen, *piFormat));
    538     LogFlowFunc(("g_ctxHost.requestX11Format=%d, g_ctxHost.requestBufferSize=%d\n",
    539                  g_ctxHost.requestX11Format, g_ctxHost.requestBufferSize));
     533    VBOXCLIPBOARDREQUEST *pRequest
     534        = reinterpret_cast<VBOXCLIPBOARDREQUEST *>(pClientData);
     535    LogFlowFunc(("pClientData=%p, *pcLen=%lu, *piFormat=%d\n", pClientData,
     536                 *pcLen, *piFormat));
     537    LogFlowFunc(("g_ctxX11.X11TextFormat=%d, pRequest->cb=%d\n",
     538                 g_ctxX11.X11TextFormat, pRequest->cb));
    540539    unsigned cTextLen = (*pcLen) * (*piFormat) / 8;
    541540    /* The X Toolkit may have failed to get the clipboard selection for us. */
     
    545544    if (NULL == pValue)
    546545        return;
    547     /* We grab this mutex whenever an asynchronous clipboard operation completes and while
    548        disconnecting a client from the clipboard to stop these operations colliding. */
    549     RTSemMutexRequest(g_ctxHost.clipboardMutex, RT_INDEFINITE_WAIT);
    550     if (reinterpret_cast<VBOXCLIPBOARDCLIENTDATA *>(pClientData) != g_ctxHost.pClient)
    551     {
    552         /* If the client is no longer connected, just return. */
    553         XtFree(reinterpret_cast<char *>(pValue));
    554         LogFlowFunc(("client is no longer connected, returning\n"));
    555         RTSemMutexRelease(g_ctxHost.clipboardMutex);
    556         return;
    557     }
    558 
    559     /* In which format did we request the clipboard data? */
    560     switch (g_ctxHost.requestX11Format)
     546    /* In which format is the clipboard data? */
     547    switch (g_ctxX11.X11TextFormat)
    561548    {
    562549    case UTF16:
    563         vboxClipboardGetUtf16(pValue, cTextLen / 2, g_ctxHost.requestBuffer, g_ctxHost.requestBufferSize,
    564                               g_ctxHost.requestActualSize);
     550        vboxClipboardGetUtf16(pValue, cTextLen / 2, pRequest->pv,
     551                              pRequest->cb, pRequest->pcbActual);
    565552        break;
    566553    case CTEXT:
    567         vboxClipboardGetCTextFromX11(pValue, cTextLen, g_ctxHost.requestBuffer, g_ctxHost.requestBufferSize,
    568                               g_ctxHost.requestActualSize);
     554        vboxClipboardGetCTextFromX11(pValue, cTextLen, pRequest->pv,
     555                                     pRequest->cb, pRequest->pcbActual);
    569556        break;
    570557    case UTF8:
     
    574561        char *pu8SourceText = reinterpret_cast<char *>(pValue);
    575562
    576         if ((g_ctxHost.requestX11Format == UTF8)
     563        if ((g_ctxX11.X11TextFormat == UTF8)
    577564            && (RTStrUniLenEx(pu8SourceText, *pcLen, &cStringLen) == VINF_SUCCESS))
    578565        {
    579             vboxClipboardGetUtf8FromX11(pValue, cTextLen, g_ctxHost.requestBuffer, g_ctxHost.requestBufferSize,
    580                                  g_ctxHost.requestActualSize);
     566            vboxClipboardGetUtf8FromX11(pValue, cTextLen, pRequest->pv,
     567                                     pRequest->cb, pRequest->pcbActual);
    581568            break;
    582569        }
    583570        else
    584571        {
    585             vboxClipboardGetLatin1FromX11(pValue, cTextLen, g_ctxHost.requestBuffer, g_ctxHost.requestBufferSize,
    586                                    g_ctxHost.requestActualSize);
     572            vboxClipboardGetLatin1FromX11(pValue, cTextLen, pRequest->pv,
     573                                     pRequest->cb, pRequest->pcbActual);
    587574            break;
    588575        }
     
    591578        LogFunc (("bad target format\n"));
    592579        XtFree(reinterpret_cast<char *>(pValue));
    593         RTSemMutexRelease(g_ctxHost.clipboardMutex);
    594580        return;
    595581    }
    596582    g_ctxX11.notifyVBox = true;
    597     RTSemMutexRelease(g_ctxHost.clipboardMutex);
    598 }
    599 
    600 /**
    601  * Find out what targets the current X11 clipboard holder can handle.  We are
    602  * reading the X11 clipboard to make it available to VBox.
    603  * @thread  clipboard X11 event thread
    604  * @note    Callback for XtGetSelectionValue, called from vboxClipboardPollX11ForTargets
    605  */
    606 static void vboxClipboardGetTargetsFromX11(Widget, XtPointer pClientData,
     583}
     584
     585/**
     586 * Notify the host clipboard about the data formats we support, based on the
     587 * "targets" (available data formats) information obtained from the X11
     588 * clipboard.
     589 * @note  X11 backend code, callback for XtGetSelectionValue, called when we
     590 *        poll for available targets.
     591 * @todo  This function still references host-specific data and calls host
     592 *        frontend APIs.  Fix.
     593 */
     594static void vboxClipboardGetTargetsFromX11(Widget,
     595                                           XtPointer /* pClientData */,
    607596                                           Atom * /* selection */,
    608597                                           Atom *atomType,
     
    620609    {
    621610        LogFunc (("reading clipboard from host, X toolkit failed to convert the selection\n"));
    622         return;
    623     }
    624     /* We grab this mutex whenever an asynchronous clipboard operation completes and while
    625        disconnecting a client from the clipboard to stop these operations colliding. */
    626     RTSemMutexRequest(g_ctxHost.clipboardMutex, RT_INDEFINITE_WAIT);
    627     if (reinterpret_cast<VBOXCLIPBOARDCLIENTDATA *>(pClientData) != g_ctxHost.pClient)
    628     {
    629         /* If the client is no longer connected, just return. */
    630         LogFlowFunc(("client is no longer connected, returning\n"));
    631         RTSemMutexRelease(g_ctxHost.clipboardMutex);
    632611        return;
    633612    }
     
    690669    }
    691670    XtFree(reinterpret_cast<char *>(pValue));
    692     RTSemMutexRelease(g_ctxHost.clipboardMutex);
    693 }
    694 
    695 /**
    696  * This callback is called every 200ms to check the contents of the X11 clipboard.
    697  * @thread  clipboard X11 event thread
    698  * @note    Callback for XtAppAddTimeOut, called from vboxClipboardThread and
    699  *          recursively retriggered
     671}
     672
     673/**
     674 * This timer callback is called every 200ms to check the contents of the X11
     675 * clipboard.
     676 * @note  X11 backend code, callback for XtAppAddTimeOut, recursively
     677 *        re-armed.
     678 * @todo  This function still references host-specific data.  Fix.
     679 * @todo  Use the XFIXES extension to check for new clipboard data when
     680 *        available.
    700681 */
    701682static void vboxClipboardPollX11ForTargets(XtPointer /* pUserData */, XtIntervalId * /* hTimerId */)
     
    715696}
    716697
    717 /** We store information about the target formats we can handle in a global vector for internal
    718     use. */
     698/** We store information about the target formats we can handle in a global
     699 * vector for internal use.
     700 * @note  X11 backend code.
     701 */
    719702static void vboxClipboardAddFormat(const char *pszName, g_eClipboardFormats eFormat,
    720703                                   unsigned guestFormat)
     
    732715/**
    733716 * The main loop of our clipboard reader.
    734  * @thread  clipboard X11 event thread
     717 * @note  X11 backend code.
    735718 */
    736719static int vboxClipboardThread(RTTHREAD self, void * /* pvUser */)
     
    747730}
    748731
    749 /** X11 specific initialisation for the shared clipboard. */
     732/** X11 specific initialisation for the shared clipboard.
     733 * @note  X11 backend code.
     734 */
    750735int vboxClipboardInitX11 (void)
    751736{
     
    825810/**
    826811 * Initialise the host side of the shared clipboard.
    827  * @note    Called by the HGCM clipboard service
    828  * @thread  HGCM clipboard service thread
     812 * @todo  This mixes host glue and X11 backend code, separate into two
     813 *        functions.
    829814 */
    830815int vboxClipboardInit (void)
     
    890875/**
    891876 * Terminate the host side of the shared clipboard.
    892  * @note    Called by the HGCM clipboard service
    893  * @thread  HGCM clipboard service thread
     877 * @todo  This mixes host glue and X11 backend code, separate into two
     878 *        functions.
    894879 */
    895880void vboxClipboardDestroy (void)
     
    958943/**
    959944 * Connect a guest the shared clipboard.
    960  *
    961  * @param   pClient Structure containing context information about the guest system
    962  * @returns RT status code
    963  * @note    Called by the HGCM clipboard service
    964  * @thread  HGCM clipboard service thread
     945 * @todo  This mixes host glue and X11 backend code, separate into two
     946 *        functions.
    965947 */
    966948int vboxClipboardConnect (VBOXCLIPBOARDCLIENTDATA *pClient)
     
    987969 * Synchronise the contents of the host clipboard with the guest, called
    988970 * after a save and restore of the guest.
    989  * @note    Called by the HGCM clipboard service
    990  * @thread  HGCM clipboard service thread
     971 * @todo  This mixes host glue and X11 backend code and calls host frontend
     972 *        APIs.  Separate into two functions.
    991973 */
    992974int vboxClipboardSync (VBOXCLIPBOARDCLIENTDATA *pClient)
     
    1010992/**
    1011993 * Shut down the shared clipboard service and "disconnect" the guest.
    1012  * @note    Called by the HGCM clipboard service
    1013  * @thread  HGCM clipboard service thread
     994 * @todo  This mixes host glue and X11 backend code, separate into two
     995 *        functions.
    1014996 */
    1015997void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *)
     
    10341016 * Satisfy a request from X11 for clipboard targets supported by VBox.
    10351017 *
    1036  * @returns true if we successfully convert the data to the format requested, false otherwise.
     1018 * @returns true if we successfully convert the data to the format
     1019 *          requested, false otherwise.
    10371020 *
    10381021 * @param  atomTypeReturn The type of the data we are returning
    1039  * @param  pValReturn     A pointer to the data we are returning.  This should be to memory
    1040  *                        allocated by XtMalloc, which will be freed by the toolkit later
     1022 * @param  pValReturn     A pointer to the data we are returning.  This
     1023 *                        should be set to memory allocated by XtMalloc,
     1024 *                        which will be freed later by the Xt toolkit.
    10411025 * @param  pcLenReturn    The length of the data we are returning
    1042  * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    1043  * @thread  clipboard X11 event thread
    1044  * @note    called by vboxClipboardConvertForX11
    1045  */
    1046 static Boolean vboxClipboardConvertTargetsForX11(Atom *atomTypeReturn, XtPointer *pValReturn,
    1047                                                  unsigned long *pcLenReturn, int *piFormatReturn)
     1026 * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are
     1027 *                        returning
     1028 * @note  X11 backend code, called by the XtOwnSelection callback.
     1029 */
     1030static Boolean vboxClipboardConvertTargetsForX11(Atom *atomTypeReturn,
     1031                                                 XtPointer *pValReturn,
     1032                                                 unsigned long *pcLenReturn,
     1033                                                 int *piFormatReturn)
    10481034{
    10491035    unsigned uListSize = g_ctxX11.formatList.size();
     
    10901076
    10911077/**
    1092  * Satisfy a request from X11 to convert the clipboard text to Utf16.  We return non-zero
    1093  * terminated text.
    1094  *
    1095  * @returns true if we successfully convert the data to the format requested, false otherwise.
    1096  *
    1097  * @retval atomTypeReturn The type of the data we are returning
    1098  * @retval pValReturn     A pointer to the data we are returning.  This should be to memory
    1099  *                       allocated by XtMalloc, which will be freed by the toolkit later
    1100  * @retval pcLenReturn    The length of the data we are returning
    1101  * @retval piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    1102  */
    1103 static Boolean vboxClipboardConvertUtf16(Atom *atomTypeReturn, XtPointer *pValReturn,
    1104                                          unsigned long *pcLenReturn, int *piFormatReturn)
     1078 * Satisfy a request from X11 to convert the clipboard text to Utf16.  We
     1079 * return non-zero terminated text.
     1080 * @todo that works, but it is bad.  Change it to return zero-terminated
     1081 *       text.
     1082 *
     1083 * @returns true if we successfully convert the data to the format
     1084 * requested, false otherwise.
     1085 *
     1086 * @param  atomTypeReturn  Where to store the atom for the type of the data
     1087 *                         we are returning
     1088 * @param  pValReturn      Where to store the pointer to the data we are
     1089 *                         returning.  This should be to memory allocated by
     1090 *                         XtMalloc, which will be freed by the Xt toolkit
     1091 *                         later.
     1092 * @param  pcLenReturn     Where to store the length of the data we are
     1093 *                         returning
     1094 * @param  piFormatReturn  Where to store the bit width (8, 16, 32) of the
     1095 *                         data we are returning
     1096 * @note  X11 backend code, called by the callback for XtOwnSelection.
     1097 * @todo  this function uses host-specific data and APIs.  Fix.
     1098 */
     1099static Boolean vboxClipboardConvertUtf16(Atom *atomTypeReturn,
     1100                                         XtPointer *pValReturn,
     1101                                         unsigned long *pcLenReturn,
     1102                                         int *piFormatReturn)
    11051103{
    11061104    PRTUTF16 pu16SrcText, pu16DestText;
     
    11621160
    11631161/**
    1164  * Satisfy a request from X11 to convert the clipboard text to Utf8.
    1165  *
    1166  * @returns true if we successfully convert the data to the format requested, false otherwise.
    1167  *
    1168  * @param  atomTypeReturn The type of the data we are returning
    1169  * @param  pValReturn     A pointer to the data we are returning.  This should be to memory
    1170  *                        allocated by XtMalloc, which will be freed by the toolkit later
    1171  * @param  pcLenReturn    The length of the data we are returning
    1172  * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    1173  * @thread  clipboard X11 event thread
    1174  * @note    called by vboxClipboardConvertForX11
     1162 * Satisfy a request from X11 to convert the clipboard text to Utf8.  We
     1163 * return non-zero terminated text.
     1164 * @todo that works, but it is bad.  Change it to return zero-terminated
     1165 *       text.
     1166 *
     1167 * @returns true if we successfully convert the data to the format
     1168 * requested, false otherwise.
     1169 *
     1170 * @param  atomTypeReturn  Where to store the atom for the type of the data
     1171 *                         we are returning
     1172 * @param  pValReturn      Where to store the pointer to the data we are
     1173 *                         returning.  This should be to memory allocated by
     1174 *                         XtMalloc, which will be freed by the Xt toolkit
     1175 *                         later.
     1176 * @param  pcLenReturn     Where to store the length of the data we are
     1177 *                         returning
     1178 * @param  piFormatReturn  Where to store the bit width (8, 16, 32) of the
     1179 *                         data we are returning
     1180 * @note  X11 backend code, called by the callback for XtOwnSelection.
     1181 * @todo  this function uses host-specific data and APIs.  Fix.
    11751182 */
    11761183static Boolean vboxClipboardConvertToUtf8ForX11(Atom *atomTypeReturn,
     
    12601267
    12611268/**
    1262  * Satisfy a request from X11 to convert the clipboard text to COMPOUND_TEXT.
    1263  *
    1264  * @returns true if we successfully convert the data to the format requested, false otherwise.
    1265  *
    1266  * @param  atomTypeReturn The type of the data we are returning
    1267  * @param  pValReturn     A pointer to the data we are returning.  This should be to memory
    1268  *                        allocated by XtMalloc, which will be freed by the toolkit later
    1269  * @param  pcLenReturn    The length of the data we are returning
    1270  * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    1271  * @thread  clipboard X11 event thread
    1272  * @note    called by vboxClipboardConvertForX11
     1269 * Satisfy a request from X11 to convert the clipboard text to
     1270 * COMPOUND_TEXT.  We return non-zero terminated text.
     1271 * @todo that works, but it is bad.  Change it to return zero-terminated
     1272 *       text.
     1273 *
     1274 * @returns true if we successfully convert the data to the format
     1275 * requested, false otherwise.
     1276 *
     1277 * @param  atomTypeReturn  Where to store the atom for the type of the data
     1278 *                         we are returning
     1279 * @param  pValReturn      Where to store the pointer to the data we are
     1280 *                         returning.  This should be to memory allocated by
     1281 *                         XtMalloc, which will be freed by the Xt toolkit
     1282 *                         later.
     1283 * @param  pcLenReturn     Where to store the length of the data we are
     1284 *                         returning
     1285 * @param  piFormatReturn  Where to store the bit width (8, 16, 32) of the
     1286 *                         data we are returning
     1287 * @note  X11 backend code, called by the callback for XtOwnSelection.
     1288 * @todo  this function uses host-specific data and APIs.  Fix.
    12731289 */
    12741290static Boolean vboxClipboardConvertToCTextForX11(Atom *atomTypeReturn,
     
    13781394
    13791395/**
    1380  * Callback to request VBox's clipboard data for an X11 client.  Called by the
    1381  * X Toolkit.
    1382  * @thread  clipboard X11 event thread
    1383  * @note    callback for XtOwnSelection, called by vboxClipboardFormatAnnounce
     1396 * Return VBox's clipboard data for an X11 client.
     1397 * @note  X11 backend code, callback for XtOwnSelection
    13841398 */
    13851399static Boolean vboxClipboardConvertForX11(Widget, Atom *atomSelection,
     
    14531467/**
    14541468 * This is called by the X toolkit intrinsics to let us know that another
    1455  * X11 client has taken the clipboard.
    1456  * @note    callback for XtOwnSelection, called from vboxClipboardFormatAnnounce
    1457  * @thread  clipboard X11 event thread
     1469 * X11 client has taken the clipboard.  In this case we notify VBox that
     1470 * we want ownership of the clipboard.
     1471 * @note  X11 backend code, callback for XtOwnSelection
    14581472 */
    14591473static void vboxClipboardReturnToX11(Widget, Atom *)
     
    15181532 * Called when VBox wants to read the X11 clipboard.
    15191533 *
    1520  * @param pClient   Context information about the guest VM
    1521  * @param u32Format The format that the guest would like to receive the data in
    1522  * @param pv        Where to write the data to
    1523  * @param cb        The size of the buffer to write the data to
    1524  * @param pcbActual Where to write the actual size of the written data
    1525  * @note    Called by the HGCM clipboard service
    1526  * @thread  HGCM clipboard service thread
    1527  */
    1528 int vboxClipboardReadData (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format, void *pv,
    1529                            uint32_t cb, uint32_t *pcbActual)
    1530 {
     1534 * @param  pClient   Context information about the guest VM
     1535 * @param  u32Format The format that the guest would like to receive the data in
     1536 * @param  pv        Where to write the data to
     1537 * @param  cb        The size of the buffer to write the data to
     1538 * @param  pcbActual Where to write the actual size of the written data
     1539 * @note   Host glue code
     1540 * @todo   Separate this into a host and an X11-specific function
     1541 */
     1542int vboxClipboardReadData (VBOXCLIPBOARDCLIENTDATA *pClient,
     1543                           uint32_t u32Format, void *pv, uint32_t cb,
     1544                           uint32_t *pcbActual)
     1545{
     1546    VBOXCLIPBOARDREQUEST request;
    15311547    /*
    15321548     * Immediately return if we are not connected to the host X server.
     
    15561572         * grabbed the clipboard, so it should not be waiting for data from us. */
    15571573        AssertLogRelReturn (ASMAtomicCmpXchgU32(&g_ctxHost.waiter, VB, NONE), VERR_DEADLOCK);
    1558         g_ctxHost.requestX11Format = g_ctxX11.X11TextFormat;
    1559         g_ctxHost.requestBuffer = pv;
    1560         g_ctxHost.requestBufferSize = cb;
    1561         g_ctxHost.requestActualSize = pcbActual;
     1574        request.pv = pv;
     1575        request.cb = cb;
     1576        request.pcbActual = pcbActual;
    15621577        /* Initially set the size of the data read to zero in case we fail
    15631578         * somewhere. */
    15641579        *pcbActual = 0;
    15651580        /* Send out a request for the data to the current clipboard owner */
    1566         XtGetSelectionValue(g_ctxX11.widget, g_ctxX11.atomClipboard, g_ctxX11.atomX11TextFormat,
    1567                             vboxClipboardGetDataFromX11, reinterpret_cast<XtPointer>(g_ctxHost.pClient),
     1581        XtGetSelectionValue(g_ctxX11.widget, g_ctxX11.atomClipboard,
     1582                            g_ctxX11.atomX11TextFormat,
     1583                            vboxClipboardGetDataFromX11,
     1584                            reinterpret_cast<XtPointer>(&request),
    15681585                            CurrentTime);
    15691586        /* When the data arrives, the vboxClipboardGetDataFromX11 callback will be called.  The
     
    15881605 * Called when we have requested data from VBox and that data has arrived.
    15891606 *
    1590  * @param pClient   Context information about the guest VM
    1591  * @param pv        Buffer to which the data was written
    1592  * @param cb        The size of the data written
    1593  * @param u32Format The format of the data written
    1594  * @note    Called by the HGCM clipboard service
    1595  * @thread  HGCM clipboard service thread
     1607 * @param  pClient   Context information about the guest VM
     1608 * @param  pv        Buffer to which the data was written
     1609 * @param  cb        The size of the data written
     1610 * @param  u32Format The format of the data written
     1611 * @note   Host glue code
    15961612 */
    15971613void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, uint32_t u32Format)
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