VBoxDisplay.cpp revision 1ce9b5cdb394313f823577ad75c0bc237b9884b5
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* $Id: $ */
45e9809aff7304721fddb95654901b32195c9c7avboxsync * VBoxSeamless - Display notifications.
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
45e9809aff7304721fddb95654901b32195c9c7avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
45e9809aff7304721fddb95654901b32195c9c7avboxsync * available from http://www.virtualbox.org. This file is free software;
45e9809aff7304721fddb95654901b32195c9c7avboxsync * you can redistribute it and/or modify it under the terms of the GNU
45e9809aff7304721fddb95654901b32195c9c7avboxsync * General Public License (GPL) as published by the Free Software
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
45e9809aff7304721fddb95654901b32195c9c7avboxsync * additional information or have any questions.
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* ChangeDisplaySettingsEx does not exist in NT. ResizeDisplayDevice uses the function. */
45e9809aff7304721fddb95654901b32195c9c7avboxsync LONG (WINAPI * pfnChangeDisplaySettingsEx)(LPCTSTR lpszDeviceName, LPDEVMODE lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam);
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* EnumDisplayDevices does not exist in NT. isVBoxDisplayDriverActive et al. are using these functions. */
45e9809aff7304721fddb95654901b32195c9c7avboxsync BOOL (WINAPI * pfnEnumDisplayDevices)(IN LPCSTR lpDevice, IN DWORD iDevNum, OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags);
45e9809aff7304721fddb95654901b32195c9c7avboxsyncint VBoxDisplayInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
45e9809aff7304721fddb95654901b32195c9c7avboxsync Log(("VBoxTray: Could not get module handle of USER32.DLL!\n"));
45e9809aff7304721fddb95654901b32195c9c7avboxsync else if (OSinfo.dwMajorVersion >= 5) /* APIs available only on W2K and up! */
45e9809aff7304721fddb95654901b32195c9c7avboxsync *(uintptr_t *)&gCtx.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
45e9809aff7304721fddb95654901b32195c9c7avboxsync Log(("VBoxTray: pfnChangeDisplaySettingsEx = %p\n", gCtx.pfnChangeDisplaySettingsEx));
45e9809aff7304721fddb95654901b32195c9c7avboxsync *(uintptr_t *)&gCtx.pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA");
45e9809aff7304721fddb95654901b32195c9c7avboxsync Log(("VBoxTray: pfnEnumDisplayDevices = %p\n", gCtx.pfnEnumDisplayDevices));
45e9809aff7304721fddb95654901b32195c9c7avboxsync else if (OSinfo.dwMajorVersion <= 4) /* Windows NT 4.0 */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* Nothing to do here yet */
45e9809aff7304721fddb95654901b32195c9c7avboxsync else /* Unsupported platform */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Log(("VBoxTray: Warning, display for platform not handled yet!\n"));
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid VBoxDisplayDestroy (const VBOXSERVICEENV *pEnv, void *pInstance)
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstatic bool isVBoxDisplayDriverActive (VBOXDISPLAYCONTEXT *pCtx)
45e9809aff7304721fddb95654901b32195c9c7avboxsync bool result = false;
result = true;
devNum++;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &tempDevMode); /* Get current display device settings */
result = true;
return result;
DWORD i = 0;
NumDevices++;
NumDevices++;
return FALSE;
if (bFetchDevice)
return FALSE;
return FALSE;
DevNum++;
if (Width == 0)
if (Height == 0)
if ( !fModeReset
return FALSE;
#ifdef Log
for (i = 0; i < NumDevices; i++)
for (i = 0; i < NumDevices; i++)
if ( i == Id
&& BitsPerPixel != 0)
return FALSE;
return TRUE;
bool fTerminate = false;
if (DeviceIoControl (gVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED;
if (DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent), &waitEvent, sizeof(waitEvent), &cbReturned, NULL))
BOOL fDisplayChangeQueried = DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevDisplayChangeRequest2)), &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest2),
if (!fDisplayChangeQueried)
fDisplayChangeQueried = DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevDisplayChangeRequest)), &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest),
Log(("VBoxDisplayThread : VMMDevReq_GetDisplayChangeRequest2: %dx%dx%d at %d\n", displayChangeRequest.xres, displayChangeRequest.yres, displayChangeRequest.bpp, displayChangeRequest.display));
Log(("VBoxDisplayThread : Current mode: %dx%dx%d at %d,%d\n", devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmPosition.x, devMode.dmPosition.y));
Log(("VBoxDisplayThread : setting the new mode %dx%dx%d\n", devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel));
fTerminate = true;
fTerminate = true;
fTerminate = true;
} while (!fTerminate);
maskInfo.u32NotMask = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED;
if (DeviceIoControl (gVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))