display.cpp revision 23ff0a80f28ba27da3cb458face82665fe65e96c
/* $Id$ */
/** @file
* X11 guest client - display management.
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/** @todo this should probably be replaced by something IPRT */
/* For system() and WEXITSTATUS() */
#include <stdlib.h>
#include <errno.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxClient.h"
/* TESTING: Dynamic resizing and mouse integration toggling should work
* correctly with a range of X servers (pre-1.3, 1.3 and later under Linux, 1.3
* and later under Solaris) with Guest Additions installed. Switching to a
* virtual terminal while a user session is in place should disable dynamic
* resizing and cursor integration, switching back should re-enable them. */
/** Most recent information received for a particular screen. */
struct screenInformation
{
unsigned cx;
unsigned cy;
unsigned cBPP;
unsigned x;
unsigned y;
bool fEnabled;
bool fUpdateSize;
bool fUpdatePosition;
};
/** Display magic number, start of a UUID. */
/** State information needed for the service. The main VBoxClient code provides
* the daemon logic needed by all services. */
struct DISPLAYSTATE
{
/** The service interface. */
struct VBCLSERVICE *pInterface;
/** Magic number for sanity checks. */
/** Are we initialised yet? */
bool mfInit;
/** The connection to the server. */
/** Can we use version 1.2 or later of the RandR protocol here? */
bool fHaveRandR12;
/** The command argument to use for the xrandr binary. Currently only
* used to support the non-standard location on some Solaris systems -
* would it make sense to use absolute paths on all systems? */
const char *pcszXrandr;
/** The number of screens we are currently aware of. */
unsigned cScreensTracked;
/** Array of information about different screens. */
struct screenInformation *paScreenInformation;
};
/** Tell the VBoxGuest driver we no longer want any events and tell the host
* we no longer support any capabilities. */
static int disableEventsAndCaps(bool fDisableEvents)
{
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
if (fDisableEvents)
rc = VbglR3CtlFilterMask(0, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED | VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
if (RT_FAILURE(rc))
return VINF_SUCCESS;
}
/** Tell the VBoxGuest driver which events we want and tell the host which
* capabilities we support. */
static int enableEventsAndCaps()
{
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
rc = VbglR3SetMouseStatus(0);
if (RT_FAILURE(rc))
return VINF_SUCCESS;
}
{
char szCommand[256];
int status;
/* Initialise the guest library. */
int rc = VbglR3InitUser();
if (RT_FAILURE(rc))
return VERR_NOT_FOUND;
pState->fHaveRandR12 = false;
if (RTFileExists("/usr/X11/bin/xrandr"))
VBClFatalError(("Failed to execute the xrandr utility.\n"));
if (WEXITSTATUS(status) == 0)
pState->fHaveRandR12 = true;
pState->cScreensTracked = 0;
return VINF_SUCCESS;
}
static void updateScreenInformation(struct DISPLAYSTATE *pState, unsigned cx, unsigned cy, unsigned cBPP, unsigned iDisplay,
unsigned x, unsigned y, bool fEnabled, bool fUpdatePosition)
{
uint32_t i;
{
if (!pState->paScreenInformation)
VBClFatalError(("Failed to re-allocate screen information.\n"));
}
}
{
unsigned i;
if (paSizeHints == NULL)
VBClFatalError(("Failed to allocate size hint property memory.\n"));
for (i = 0; i < pState->cScreensTracked; ++i)
{
paSizeHints[i] = (pState->paScreenInformation[i].cx & 0x8fff) << 16 | (pState->paScreenInformation[i].cy & 0x8fff);
paSizeHints[i] = -1;
}
XChangeProperty(pState->pDisplay, DefaultRootWindow(pState->pDisplay), XInternAtom(pState->pDisplay, "VBOX_SIZE_HINTS", 0),
}
{
char szCommand[256];
unsigned i;
bool fUpdateInformation = false;
/** @note The xrandr command can fail if something else accesses RandR at
* the same time. We just ignore failure for now and let the user try
* again as we do not know what someone else is doing. */
for (i = 0; i < pState->cScreensTracked; ++i)
fUpdateInformation = true;
{
}
for (i = 0; i < pState->cScreensTracked; ++i)
{
{
}
{
}
pState->paScreenInformation[i].fUpdateSize = pState->paScreenInformation[i].fUpdatePosition = false;
}
else
{
}
}
{
int rc;
unsigned i;
if (rc != VINF_SUCCESS)
(unsigned char *)&fFeatures, 1);
if (pState->fHaveRandR12)
for (i = 0; i < pState->cScreensTracked; ++i)
else
}
/**
* Display change request monitor thread function.
*/
{
unsigned i, cScreensTracked;
char szCommand[256];
LogRelFlowFunc(("\n"));
/* Make sure that we have an entry for screen 1 at least. */
if (rc == VINF_SUCCESS)
{
/* The "8" is for the sanity test below. */
{
bool fEnabled = true;
&fEnabled);
/* Sanity test for VbglR3VideoModeGetHighestSavedScreen(). */
VBClFatalError(("Internal error retrieving the number of saved screen modes.\n"));
if (rc == VINF_SUCCESS)
}
}
while (true)
{
do
while(rc == VERR_INTERRUPTED);
/* If it is a size hint, set the new size. */
{
bool fEnabled = true, fUpdatePosition = true;
&x, &y, &fEnabled,
&fUpdatePosition, true);
if (rc != VINF_SUCCESS)
VBClFatalError(("Failed to get display change request, rc=%Rrc\n",
rc));
else
LogRelFlowFunc(("Got size hint from host cx=%d, cy=%d, bpp=%d, iDisplay=%d, x=%d, y=%d fEnabled=%d\n",
VBClFatalError(("Received a size hint for too high display number %u\n",
(unsigned) iDisplay));
if (RT_FAILURE(rc))
if (Mode == VMMDev_Seamless_Disabled)
{
fEnabled);
}
}
}
}
static const char *getPidFilePath()
{
return ".vboxclient-display.pid";
}
{
VBClFatalError(("Bad display service object!\n"));
return pSelf;
}
{
int rc;
return VERR_WRONG_ORDER;
if (RT_FAILURE(rc))
return rc;
rc = enableEventsAndCaps();
if (RT_SUCCESS(rc))
return rc;
}
{
int rc;
return VERR_WRONG_ORDER;
rc = VBClStartVTMonitor();
if (RT_FAILURE(rc))
return VERR_INTERNAL_ERROR; /* "Should never reach here." */
}
{
return VERR_WRONG_ORDER;
return disableEventsAndCaps(false);
}
{
return VERR_WRONG_ORDER;
return enableEventsAndCaps();
}
{
disableEventsAndCaps(true);
VbglR3Term();
}
struct VBCLSERVICE vbclDisplayInterface =
{
init,
run,
};
struct VBCLSERVICE **VBClGetDisplayService()
{
if (!pService)
VBClFatalError(("Out of memory\n"));
return &pService->pInterface;
}