VirtualBox

Changeset 102824 in vbox


Ignore:
Timestamp:
Jan 10, 2024 5:31:25 PM (11 months ago)
Author:
vboxsync
Message:

Shared Clipboard/X11: Implemented ShClX11WriteDataToX11[Async](). bugref:9437

Location:
trunk
Files:
2 edited

Legend:

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

    r102822 r102824  
    177177    SHCLX11EVENTTYPE_REPORT_FORMATS,
    178178    /** Reads clipboard from X11. */
    179     SHCLX11EVENTTYPE_READ
     179    SHCLX11EVENTTYPE_READ,
     180    /** Writes clipboard to X11. */
     181    SHCLX11EVENTTYPE_WRITE
    180182} SHCLX11EVENTTYPE;
    181183/** Pointer to an enumeration for an X11 event type. */
     
    211213            uint32_t         cbMax;
    212214        } Read;
     215        /** Write request. */
     216        struct
     217        {
     218            /** The format of the data to write. */
     219            SHCLFORMAT       uFmtVBox;
     220            /** The format to write to X11. */
     221            SHCLX11FMTIDX    idxFmtX11;
     222            /** Data to write. */
     223            void            *pvData;
     224            /** How much bytes to write. */
     225            uint32_t         cbData;
     226        } Write;
    213227    };
    214228} SHCLX11REQUEST;
     
    232246            uint32_t cbData;
    233247        } Read;
     248        struct
     249        {
     250            const void *pvData;
     251            uint32_t    cbData;
     252        } Write;
    234253    };
    235254} SHCLX11RESPONSE;
     
    248267int ShClX11ReadDataFromX11Async(PSHCLX11CTX pCtx, SHCLFORMAT uFmt, uint32_t cbMax, PSHCLEVENT pEvent);
    249268int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, PSHCLEVENTSOURCE pEventSource, RTMSINTERVAL msTimeout, SHCLFORMAT uFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcbBuf);
     269int ShClX11WriteDataToX11Async(PSHCLX11CTX pCtx, SHCLFORMAT uFmt, const void *pvBuf, uint32_t cbBuf, PSHCLEVENT pEvent);
     270int ShClX11WriteDataToX11(PSHCLX11CTX pCtx, PSHCLEVENTSOURCE pEventSource, RTMSINTERVAL msTimeout, SHCLFORMAT uFmt, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
    250271void ShClX11SetCallbacks(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks);
    251272#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp

    r102823 r102824  
    27272727    return rc;
    27282728}
     2729
     2730/**
     2731 * Writes to the X11 clipboard (asynchronously).
     2732 *
     2733 * @returns VBox status code.
     2734 * @retval  VERR_NOT_AVAILABLE the the X11 clipboard is not available.
     2735 * @retval  VERR_NOT_IMPLEMENTED if the format is not implemented.
     2736 * @param   pCtx                Context data for the clipboard backend.
     2737 * @param   uFmts               The format(s) to write.
     2738 *                              Conversions might be performed, if available.
     2739 * @param   pvBuf               Pointer to data to write.
     2740 * @param   cbBuf               Size (in bytes) of data to write.
     2741 * @param   pEvent              Event to use for waiting for data to get written.
     2742 *                              The event's payload will contain the amount of data written.
     2743 *                              Needs to be free'd with ShClEventRelease().
     2744 */
     2745int ShClX11WriteDataToX11Async(PSHCLX11CTX pCtx, SHCLFORMATS uFmts, const void *pvBuf, uint32_t cbBuf, PSHCLEVENT pEvent)
     2746{
     2747    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     2748    AssertPtrReturn(pvBuf,  VERR_INVALID_POINTER);
     2749    AssertReturn(cbBuf,  VERR_INVALID_PARAMETER);
     2750    /* pEvent not used yet. */ RT_NOREF(pEvent);
     2751
     2752    /*
     2753     * Immediately return if we are not connected to the X server.
     2754     */
     2755    if (!pCtx->fHaveX11)
     2756        return VERR_NOT_AVAILABLE;
     2757
     2758    int rc = ShClCacheSetMultiple(&pCtx->Cache, uFmts, pvBuf, cbBuf);
     2759    if (RT_SUCCESS(rc))
     2760    {
     2761        clipResetX11Formats(pCtx);
     2762        clipGrabX11Clipboard(pCtx, uFmts);
     2763    }
     2764
     2765    return VINF_SUCCESS;
     2766}
     2767
     2768/**
     2769 * Writes to the X11 clipboard.
     2770 *
     2771 * This function currently only is implemented as asynchronous version.
     2772 *
     2773 * @returns VBox status code.
     2774 * @retval  VERR_NOT_AVAILABLE the the X11 clipboard is not available.
     2775 * @retval  VERR_TRY_AGAIN if format is supported but data could not be written.
     2776 * @retval  VERR_NOT_IMPLEMENTED if the format is not implemented.
     2777 * @param   pCtx                Context data for the clipboard backend.
     2778 * @param   uFmt                The format to write.
     2779 * @param   pvBuf               Pointer to data to write. Must match format to write.
     2780 * @param   cbBuf               Size (in bytes) of data to write.
     2781 * @param   pcbWritten          Where to return the written bytes on success. Optional.
     2782 *                              Currently always returns the value of \a cbBuf on success.
     2783 *
     2784 * @note    Text data must be in UTF-8, always.
     2785 */
     2786int ShClX11WriteDataToX11(PSHCLX11CTX pCtx, PSHCLEVENTSOURCE pEventSource, RTMSINTERVAL msTimeout,
     2787                          SHCLFORMAT uFmt, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
     2788{
     2789    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     2790    AssertPtrReturn(pEventSource, VERR_INVALID_POINTER);
     2791    AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
     2792    AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
     2793    /* pcbWritetn is optional. */
     2794
     2795    RT_NOREF(msTimeout); /* Not used yet. */
     2796
     2797    int rc = ShClX11WriteDataToX11Async(pCtx, uFmt, pvBuf, cbBuf, NULL /* pEvent */);
     2798    if (RT_SUCCESS(rc))
     2799    {
     2800        if (pcbWritten)
     2801            *pcbWritten = cbBuf;
     2802    }
     2803
     2804    LogFlowFuncLeaveRC(rc);
     2805    return rc;
     2806}
     2807
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