VirtualBox

Changeset 11382 in vbox for trunk


Ignore:
Timestamp:
Aug 13, 2008 11:56:52 AM (16 years ago)
Author:
vboxsync
Message:

shared clipboard: fail silently if we are not running on an X11 server (test for the DISPLAY variable)

File:
1 edited

Legend:

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

    r10891 r11382  
    3232#include <iprt/asm.h>        /* For atomic operations */
    3333#include <iprt/assert.h>
     34#include <iprt/env.h>
    3435#include <iprt/mem.h>
    3536#include <iprt/string.h>
     
    167168/* Only one client is supported. There seems to be no need for more clients. */
    168169static VBOXCLIPBOARDCONTEXT g_ctx;
     170
     171/* Are we actually connected to the X11 servicer? */
     172static bool g_fHaveX11;
    169173
    170174/**
     
    775779    int rc;
    776780
     781    if (!RTEnvGet("DISPLAY"))
     782    {
     783        /*
     784         * If we don't find the DISPLAY environment variable we assume that we are not
     785         * connected to an X11 server. Don't actually try to do this then, just fail
     786         * silently and report success on every call. This is important for VBoxHeadless.
     787         */
     788        LogRel(("vboxClipboardInit: no X11 detected -- host clipboard disabled\n"));
     789        g_fHaveX11 = false;
     790        return VINF_SUCCESS;
     791    }
     792
     793    g_fHaveX11 = true;
     794
    777795    LogRel(("vboxClipboardInit: initializing host clipboard\n"));
    778796    RTSemEventCreate(&g_ctx.waitForData);
     
    793811void vboxClipboardDestroy (void)
    794812{
    795     LogRel(("vboxClipboardDestroy: shutting down host clipboard\n"));
    796813    int rc, rcThread;
    797814    unsigned count = 0;
    798815    XEvent ev;
     816
     817    /*
     818     * Immetiately return if we are not connected to the host X server.
     819     */
     820    if (!g_fHaveX11)
     821        return;
     822
     823    LogRel(("vboxClipboardDestroy: shutting down host clipboard\n"));
    799824
    800825    /* Set the termination flag. */
     
    828853int vboxClipboardConnect (VBOXCLIPBOARDCLIENTDATA *pClient)
    829854{
     855    /*
     856     * Immetiately return if we are not connected to the host X server.
     857     */
     858    if (!g_fHaveX11)
     859        return VINF_SUCCESS;
     860
    830861    LogFlow(("vboxClipboardConnect\n"));
    831862
     
    850881int vboxClipboardSync (VBOXCLIPBOARDCLIENTDATA *pClient)
    851882{
     883    /*
     884     * Immetiately return if we are not connected to the host X server.
     885     */
     886    if (!g_fHaveX11)
     887        return VINF_SUCCESS;
     888
    852889    /* On a Linux host, the guest should never synchronise/cache its clipboard contents, as
    853890       we have no way of reliably telling when the host clipboard data changes.  So instead
     
    865902void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *pClient)
    866903{
     904    /*
     905     * Immetiately return if we are not connected to the host X server.
     906     */
     907    if (!g_fHaveX11)
     908        return;
     909
    867910    LogFlow(("vboxClipboardDisconnect\n"));
    868911
     
    13061349void vboxClipboardFormatAnnounce (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Formats)
    13071350{
     1351    /*
     1352     * Immetiately return if we are not connected to the host X server.
     1353     */
     1354    if (!g_fHaveX11)
     1355        return;
     1356
    13081357    pClient->pCtx->guestFormats = u32Formats;
    13091358    LogFlowFunc (("u32Formats=%d\n", u32Formats));
     
    13531402                           uint32_t cb, uint32_t *pcbActual)
    13541403{
     1404    /*
     1405     * Immetiately return if we are not connected to the host X server.
     1406     */
     1407    if (!g_fHaveX11)
     1408    {
     1409        /* no data available */
     1410        *pcbActual = 0;
     1411        return VINF_SUCCESS;
     1412    }
     1413
    13551414    LogFlow(("vboxClipboardReadData: u32Format = %d, cb = %d\n", u32Format, cb));
    13561415
     
    14091468void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, uint32_t u32Format)
    14101469{
     1470    if (!g_fHaveX11)
     1471        return;
     1472
    14111473    LogFlow(("vboxClipboardWriteData\n"));
    14121474
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