VBoxSDL.cpp revision 77db051750d055a815f6cbaddbb2e2c9b857bf7e
/** @file
* VBox frontends: VBoxSDL (simple frontend based on SDL):
* Main code
*/
/*
* Copyright (C) 2006-2010 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_GUI
using namespace com;
#if defined(VBOXSDL_WITH_X11)
# include <VBox/VBoxKeyboard.h>
# if !defined(VBOX_WITHOUT_XCURSOR)
# endif
# include <unistd.h>
#endif
#ifndef RT_OS_DARWIN
#include <SDL_syswm.h> /* for SDL_GetWMInfo() */
#endif
#include "VBoxSDL.h"
#include "Framebuffer.h"
#include "Helper.h"
#include <VBox/VBoxVideo.h>
#include <iprt/initterm.h>
#include <iprt/semaphore.h>
#include <signal.h>
#include <vector>
#include <list>
/* Xlib would re-define our enums */
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#ifdef VBOX_SECURELABEL
/** extra data key for the secure label */
#define VBOXSDL_SECURELABEL_EXTRADATA "VBoxSDL/SecureLabel"
/** label area height in pixels */
#define SECURE_LABEL_HEIGHT 20
#endif
/** Enables the rawr[0|3], patm, and casm options. */
#define VBOXSDL_ADVANCED_OPTIONS
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** Pointer shape change event data strucure */
struct PointerShapeChangeData
{
{
// make a copy of the shape
if (cbShapeSize > 0)
{
}
}
{
}
};
enum TitlebarMode
{
TITLEBAR_NORMAL = 1,
TITLEBAR_STARTUP = 2,
TITLEBAR_SAVE = 3,
};
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static bool UseAbsoluteMouse(void);
static void ResetKeys(void);
static void InputGrabStart(void);
static void InputGrabEnd(void);
static void HandleGuestCapsChanged(void);
static void SetFullscreen(bool enable);
#ifdef VBOX_WITH_SDL13
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static int gHostKeyMod = KMOD_RCTRL;
static int gHostKeySym1 = SDLK_RCTRL;
static int gHostKeySym2 = SDLK_UNKNOWN;
static const char *gHostKeyDisabledCombinations = "";
static const char *gpszPidFile;
static int gcGuestNumLockAdaptions = 2;
static int gcGuestCapsLockAdaptions = 2;
static uint32_t gmGuestNormalXRes;
static uint32_t gmGuestNormalYRes;
/** modifier keypress status (scancode as index) */
#ifdef VBOXSDL_WITH_X11
static Cursor gpDefaultOrigX11Cursor;
#endif
#ifndef VBOX_WITH_SDL13
#endif
#if defined(VBOXSDL_WITH_X11) && !defined(VBOX_WITH_SDL13)
static SDL_SysWMinfo gSdlInfo;
#endif
#ifdef VBOX_SECURELABEL
#ifdef RT_OS_WINDOWS
#define LIBSDL_TTF_NAME "SDL_ttf"
#else
#define LIBSDL_TTF_NAME "libSDL_ttf-2.0.so.0"
#endif
#endif
static RTSEMEVENT g_EventSemSDLEvents;
static volatile int32_t g_cNotifyUpdateEventsPending;
/**
* Callback handler for VirtualBox events
*/
class VBoxSDLCallback :
{
public:
{
#if defined(RT_OS_WINDOWS)
refcnt = 0;
#endif
}
virtual ~VBoxSDLCallback()
{
}
#ifdef RT_OS_WINDOWS
{
return ::InterlockedIncrement(&refcnt);
}
{
if (cnt == 0)
delete this;
return cnt;
}
#endif
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
/* we never disagree */
if (!changeAllowed)
return E_INVALIDARG;
*changeAllowed = TRUE;
return VBOX_E_DONT_CALL_AGAIN;
}
{
#ifdef VBOX_SECURELABEL
if (gMachine)
{
/*
* check if we're interested in the message
*/
{
{
/*
* Notify SDL thread of the string update
*/
}
}
}
return S_OK;
#else
return VBOX_E_DONT_CALL_AGAIN;
#endif /* VBOX_SECURELABEL */
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
private:
#ifdef RT_OS_WINDOWS
long refcnt;
#endif
};
/**
* Callback handler for machine events
*/
class VBoxSDLConsoleCallback :
{
public:
VBoxSDLConsoleCallback() : m_fIgnorePowerOffEvents(false)
{
#if defined(RT_OS_WINDOWS)
refcnt = 0;
#endif
}
virtual ~VBoxSDLConsoleCallback()
{
}
#ifdef RT_OS_WINDOWS
{
return ::InterlockedIncrement(&refcnt);
}
{
if (cnt == 0)
delete this;
return cnt;
}
#endif
{
if (!data)
return E_FAIL;
if (rc)
delete data;
return S_OK;
}
STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor)
{
LogFlow(("OnMouseCapabilityChange: supportsAbsolute = %d, supportsRelative = %d, needsHostCursor = %d\n",
return S_OK;
}
{
/* Don't bother the guest with NumLock scancodes if he doesn't set the NumLock LED */
if (gfGuestNumLockPressed != fNumLock)
if (gfGuestCapsLockPressed != fCapsLock)
return S_OK;
}
{
if ( machineState == MachineState_Aborted
)
{
/*
* We have to inform the SDL thread that the application has be terminated
*/
}
else
{
/*
* Inform the SDL thread to refresh the titlebar
*/
}
return S_OK;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
return VBOX_E_DONT_CALL_AGAIN;
}
{
const char *pszType;
if (fFatal)
pszType = "FATAL ERROR";
else if (machineState == MachineState_Paused)
pszType = "Non-fatal ERROR";
else
pszType = "WARNING";
return S_OK;
}
{
if (!canShow)
return E_POINTER;
#ifdef RT_OS_DARWIN
/* SDL feature not available on Quartz */
#else
#endif
return S_OK;
}
{
#ifndef RT_OS_DARWIN
if (SDL_GetWMInfo(&info))
{
#if defined(VBOXSDL_WITH_X11)
#elif defined(RT_OS_WINDOWS)
#else
AssertFailed();
return E_FAIL;
#endif
return S_OK;
}
#endif /* !RT_OS_DARWIN */
AssertFailed();
return E_FAIL;
}
{
switch (machineState)
{
case MachineState_Null: return "<null>";
case MachineState_PoweredOff: return "PoweredOff";
case MachineState_Saved: return "Saved";
case MachineState_Teleported: return "Teleported";
case MachineState_Aborted: return "Aborted";
case MachineState_Running: return "Running";
case MachineState_Teleporting: return "Teleporting";
case MachineState_LiveSnapshotting: return "LiveSnapshotting";
case MachineState_Paused: return "Paused";
case MachineState_Stuck: return "GuruMeditation";
case MachineState_Starting: return "Starting";
case MachineState_Stopping: return "Stopping";
case MachineState_Saving: return "Saving";
case MachineState_Restoring: return "Restoring";
case MachineState_TeleportingPausedVM: return "TeleportingPausedVM";
case MachineState_TeleportingIn: return "TeleportingIn";
case MachineState_RestoringSnapshot: return "RestoringSnapshot";
case MachineState_DeletingSnapshot: return "DeletingSnapshot";
case MachineState_SettingUp: return "SettingUp";
default: return "no idea";
}
}
void ignorePowerOffEvents(bool fIgnore)
{
}
private:
#ifdef RT_OS_WINDOWS
long refcnt;
#endif
bool m_fIgnorePowerOffEvents;
};
#ifdef VBOX_WITH_XPCOM
#endif /* VBOX_WITH_XPCOM */
static void show_usage()
{
RTPrintf("Usage:\n"
" --startvm <uuid|name> Virtual machine to start, either UUID or name\n"
" --hda <file> Set temporary first hard disk to file\n"
" --fda <file> Set temporary first floppy disk to file\n"
" --boot <a|c|d|n> Set temporary boot device (a = floppy, c = 1st HD, d = DVD, n = network)\n"
" --memory <size> Set temporary memory size in megabytes\n"
" --vram <size> Set temporary size of video memory in megabytes\n"
" --fullscreen Start VM in fullscreen mode\n"
" --fullscreenresize Resize the guest on fullscreen\n"
" --fixedmode <w> <h> <bpp> Use a fixed SDL video mode with given width, height and bits per pixel\n"
" --noresize Make the SDL frame non resizable\n"
" --nohostkey Disable all hostkey combinations\n"
" --nohostkeys ... Disable specific hostkey combinations, see below for valid keys\n"
" --detecthostkey Get the hostkey identifier and modifier state\n"
" --hostkey <key> {<key2>} <mod> Set the host key to the values obtained using --detecthostkey\n"
" --termacpi Send an ACPI power button event when closing the window\n"
#ifdef VBOX_WITH_VRDP
" --vrdp <ports> Listen for VRDP connections on one of specified ports (default if not specified)\n"
#endif
" --discardstate Discard saved state (if present) and revert to last snapshot (if present)\n"
#ifdef VBOX_SECURELABEL
" --securelabel Display a secure VM label at the top of the screen\n"
" --seclabelfnt TrueType (.ttf) font file for secure session label\n"
" --seclabelsiz Font point size for secure session label (default 12)\n"
" --seclabelofs Font offset within the secure label (default 0)\n"
" --seclabelfgcol <rgb> Secure label text color RGB value in 6 digit hexadecimal (eg: FFFF00)\n"
" --seclabelbgcol <rgb> Secure label background color RGB value in 6 digit hexadecimal (eg: FF0000)\n"
#endif
#ifdef VBOXSDL_ADVANCED_OPTIONS
" --[no]rawr0 Enable or disable raw ring 3\n"
" --[no]rawr3 Enable or disable raw ring 0\n"
" --[no]patm Enable or disable PATM\n"
" --[no]csam Enable or disable CSAM\n"
#endif
"\n"
"Key bindings:\n"
" <hostkey> + f Switch to full screen / restore to previous view\n"
" h Press ACPI power button\n"
" n Take a snapshot and continue execution\n"
" p Pause / resume execution\n"
" q Power off\n"
" r VM reset\n"
" s Save state and power off\n"
" <del> Send <ctrl><alt><del>\n"
" <F1>...<F12> Send <ctrl><alt><Fx>\n"
#if defined(DEBUG) || defined(VBOX_WITH_STATISTICS)
"\n"
"Further key bindings useful for debugging:\n"
" LCtrl + Alt + F12 Reset statistics counter\n"
" LCtrl + Alt + F11 Dump statistics to logfile\n"
" Alt + F12 Toggle R0 recompiler\n"
" Alt + F11 Toggle R3 recompiler\n"
" Alt + F10 Toggle PATM\n"
" Alt + F9 Toggle CSAM\n"
" Alt + F8 Toggle single step mode\n"
" F12 Write log marker to logfile\n"
#endif
"\n");
}
{
char pszBuffer[1024];
RTPrintf(" %.*s %.*s\n In%.*s %s",
pszStat);
else
if (pwszComponent)
RTPrintf("\n");
}
#ifdef VBOXSDL_WITH_X11
/**
* Custom signal handler. Currently it is only used to release modifier
* keys when receiving the USR1 signal. When switching VTs, we might not
* get release events for Ctrl-Alt and in case a savestate is performed
* on the new VT, the VM will be saved with modifier keys stuck. This is
* annoying enough for introducing this hack.
*/
{
/* only SIGUSR1 is interesting */
{
/* just release the modifiers */
ResetKeys();
}
}
/**
* Custom signal handler for catching exit events.
*/
void signal_handler_SIGINT(int sig)
{
if (gpszPidFile)
}
#endif /* VBOXSDL_WITH_X11 */
/** entry point */
extern "C"
{
#ifdef VBOXSDL_WITH_X11
/*
* Lock keys on SDL behave different from normal keys: A KeyPress event is generated
* if the lock mode gets active and a keyRelease event is genereated if the lock mode
* gets inactive, that is KeyPress and KeyRelease are sent when pressing the lock key
* to change the mode. The current lock mode is reflected in SDL_GetModState().
*
* Debian patched libSDL to make the lock keys behave like normal keys generating a
* KeyPress/KeyRelease event if the lock key was pressed/released. But the lock status
* is not reflected in the mod status anymore. We disable the Debian-specific extension
* to ensure a defined environment and work around the missing KeyPress/KeyRelease
* events in ProcessKeys().
*/
#endif
/*
* the hostkey detection mode is unrelated to VM processing, so handle it before
* we initialize anything COM related
*/
{
if (rc != 0)
{
return 1;
}
/* we need a video window for the keyboard stuff to work */
{
RTPrintf("Error: could not set SDL video mode\n");
return 1;
}
RTPrintf("Please hit one or two function key(s) to get the --hostkey value...\n");
while (SDL_WaitEvent(&event1))
{
{
while (SDL_WaitEvent(&event2))
{
{
/* pressed additional host key */
{
}
else
{
}
/* we're done */
break;
}
}
/* we're down */
break;
}
}
SDL_Quit();
return 1;
}
int vrc;
uint32_t memorySize = 0;
/* wrapper around above object */
bool fFullscreen = false;
bool fResizable = true;
#ifdef USE_XPCOM_QUEUE_THREAD
bool fXPCOMEventThreadSignaled = false;
#endif
#ifdef VBOX_WITH_VRDP
#endif
bool fDiscardState = false;
#ifdef VBOX_SECURELABEL
BOOL fSecureLabel = false;
char *secureLabelFontFile = NULL;
#endif
#ifdef VBOXSDL_ADVANCED_OPTIONS
unsigned fRawR0 = ~0U;
unsigned fRawR3 = ~0U;
unsigned fPATM = ~0U;
unsigned fCSAM = ~0U;
unsigned fHWVirt = ~0U;
uint32_t u32WarpDrive = 0;
#endif
#ifdef VBOX_WIN32_UI
bool fWin32UI = true;
#endif
bool fShowSDLConfig = false;
/* The damned GOTOs forces this to be up here - totally out of place. */
/*
* Host key handling.
*
* The golden rule is that host-key combinations should not be seen
* by the guest. For instance a CAD should not have any extra RCtrl down
* and RCtrl up around itself. Nor should a resume be followed by a Ctrl-P
* that could encourage applications to start printing.
*
* We must not confuse the hostkey processing into any release sequences
* either, the host key is supposed to be explicitly pressing one key.
*
* Quick state diagram:
*
* host key down alone
* (Normal) ---------------
* ^ ^ |
* | | v host combination key down
* | | (Host key down) ----------------
* | | host key up v | |
* | |-------------- | other key down v host combination key down
* | | (host key used) -------------
* | | | ^ |
* | (not host key)-- | |---------------
* | | | | |
* | | ---- other |
* | modifiers = 0 v v
* -----------------------------------------------
*/
enum HKEYSTATE
{
/** The initial and most common state, pass keystrokes to the guest.
* Next state: HKEYSTATE_DOWN
* Prev state: Any */
HKEYSTATE_NORMAL = 1,
/** The first host key was pressed down
*/
/** The second host key was pressed down (if gHostKeySym2 != SDLK_UNKNOWN)
*/
/** The host key has been pressed down.
* Prev state: HKEYSTATE_NORMAL
* Next state: HKEYSTATE_NORMAL - host key up, capture toggle.
* Next state: HKEYSTATE_USED - host key combination down.
* Next state: HKEYSTATE_NOT_IT - non-host key combination down.
*/
/** A host key combination was pressed.
* Prev state: HKEYSTATE_DOWN
* Next state: HKEYSTATE_NORMAL - when modifiers are all 0
*/
/** A non-host key combination was attempted. Send hostkey down to the
* guest and continue until all modifiers have been released.
* Prev state: HKEYSTATE_DOWN
* Next state: HKEYSTATE_NORMAL - when modifiers are all 0
*/
/** The host key down event which we have been hiding from the guest.
* Used when going from HKEYSTATE_DOWN to HKEYSTATE_NOT_IT. */
LogFlow(("SDL GUI started\n"));
"All rights reserved.\n\n",
// less than one parameter is not possible
if (argc < 2)
{
show_usage();
return 1;
}
// command line argument parsing stuff
{
)
{
{
RTPrintf("Error: VM not specified (UUID or name)!\n");
return 1;
}
// first check if a UUID was supplied
{
LogFlow(("invalid UUID format, assuming it's a VM name\n"));
}
}
{
{
RTPrintf("Error: missing argument for comment!\n");
return 1;
}
}
{
{
RTPrintf("Error: missing argument for boot drive!\n");
return 1;
}
{
case 'a':
{
break;
}
case 'c':
{
break;
}
case 'd':
{
break;
}
case 'n':
{
break;
}
default:
{
RTPrintf("Error: wrong argument for boot drive!\n");
return 1;
}
}
}
{
{
RTPrintf("Error: missing argument for memory size!\n");
return 1;
}
}
{
{
RTPrintf("Error: missing argument for vram size!\n");
return 1;
}
}
{
fFullscreen = true;
}
{
gfFullscreenResize = true;
#ifdef VBOXSDL_WITH_X11
#endif
}
{
/* three parameters follow */
{
RTPrintf("Error: missing arguments for fixed video mode!\n");
return 1;
}
}
{
}
{
fResizable = false;
}
{
gHostKeyMod = 0;
gHostKeySym1 = 0;
}
{
{
RTPrintf("Error: missing a string of disabled hostkey combinations\n");
return 1;
}
{
{
RTPrintf("Error: <hostkey> + '%c' is not a valid combination\n",
return 1;
}
}
}
{
}
{
gfACPITerm = TRUE;
}
{
{
RTPrintf("Error: missing file name for --pidfile!\n");
return 1;
}
}
{
{
RTPrintf("Error: missing file name for first hard disk!\n");
return 1;
}
/* resolve it. */
if (!hdaFile)
{
RTPrintf("Error: The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]);
return 1;
}
}
{
{
return 1;
}
/* resolve it. */
if (!fdaFile)
{
RTPrintf("Error: The path to the specified floppy disk, '%s', could not be resolved.\n", argv[curArg]);
return 1;
}
}
{
{
return 1;
}
/* resolve it. */
if (!cdromFile)
{
return 1;
}
}
#ifdef VBOX_WITH_VRDP
{
// start with the standard VRDP port
portVRDP = "0";
// is there another argument
{
curArg++;
}
}
#endif /* VBOX_WITH_VRDP */
{
fDiscardState = true;
}
#ifdef VBOX_SECURELABEL
{
fSecureLabel = true;
LogFlow(("Secure labelling turned on\n"));
}
{
{
RTPrintf("Error: missing font file name for secure label!\n");
return 1;
}
}
{
{
RTPrintf("Error: missing font point size for secure label!\n");
return 1;
}
}
{
{
RTPrintf("Error: missing font pixel offset for secure label!\n");
return 1;
}
}
{
{
RTPrintf("Error: missing text color value for secure label!\n");
return 1;
}
}
{
{
RTPrintf("Error: missing background color value for secure label!\n");
return 1;
}
}
#endif
#ifdef VBOXSDL_ADVANCED_OPTIONS
fRawR0 = true;
fRawR0 = false;
fRawR3 = true;
fRawR3 = false;
fPATM = true;
fPATM = false;
fCSAM = true;
fCSAM = false;
fHWVirt = true;
fHWVirt = false;
{
{
RTPrintf("Error: missing the rate value for the --warpdrive option!\n");
return 1;
}
{
return 1;
}
}
#endif /* VBOXSDL_ADVANCED_OPTIONS */
#ifdef VBOX_WIN32_UI
fWin32UI = true;
#endif
fShowSDLConfig = true;
{
{
RTPrintf("Error: not enough arguments for host keys!\n");
return 1;
}
{
/* two-key sequence as host key specified */
}
}
/* just show the help screen */
else
{
show_usage();
return 1;
}
}
{
return 1;
}
/* NOTE: do not convert the following scope to a "do {} while (0);", as
* this would make it all too tempting to use "break;" incorrectly - it
* would skip over the cleanup. */
{
// scopes all the stuff till shutdown
////////////////////////////////////////////////////////////////////////////
bool sessionOpened = false;
{
if (info.isFullAvailable())
PrintError("Failed to create VirtualBox object",
else
goto leave;
}
{
goto leave;
}
/*
* Do we have a name but no UUID?
*/
{
{
}
else
{
RTPrintf("Error: machine with the given ID not found!\n");
goto leave;
}
}
{
RTPrintf("Error: no machine specified!\n");
goto leave;
}
/* create SDL event semaphore */
{
if (info.isFullAvailable())
PrintError("Could not open VirtualBox session",
goto leave;
}
if (!session)
{
RTPrintf("Could not open VirtualBox session!\n");
goto leave;
}
sessionOpened = true;
// get the VM we're dealing with
if (!gMachine)
{
if (info.isFullAvailable())
PrintError("Cannot start VM!",
else
RTPrintf("Error: given machine not found!\n");
goto leave;
}
// get the VM console
if (!gConsole)
{
RTPrintf("Given console not found!\n");
goto leave;
}
/*
* Are we supposed to use a different hard disk file?
*/
if (hdaFile)
{
/*
* Strategy: iterate through all registered hard disk
* and see if one of them points to the same file. If
* so, assign it. If not, register a new image and assign
* it to the VM.
*/
if (!hardDisk)
{
/* we've not found the image */
virtualBox->OpenHardDisk(hdaFileBstr, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam());
}
/* do we have the right image now? */
if (hardDisk)
{
/*
* Go and attach it!
*/
/* get the first IDE controller to attach the harddisk to
* and if there is none, add one temporarily
*/
{
{
if (storageBus == StorageBus_IDE)
{
break;
}
}
if (storageCtl)
{
}
else
{
storageCtlName = "IDE Controller";
storageCtl.asOutParam()));
}
}
/// @todo why is this attachment saved?
}
else
{
RTPrintf("Error: failed to mount the specified hard disk image!\n");
goto leave;
}
}
/*
* Mount a floppy if requested.
*/
if (fdaFile)
do
{
/* unmount? */
{
/* nothing to do, NULL object will cause unmount */
}
else
{
/* Assume it's a host drive name */
{
/* try to find an existing one */
{
/* try to add to the list */
floppyMedium.asOutParam()));
}
}
}
/* get the first floppy controller to attach the floppy to
* and if there is none, add one temporarily
*/
{
{
if (storageBus == StorageBus_Floppy)
{
break;
}
}
if (storageCtl)
{
}
else
{
storageCtlName = "Floppy Controller";
storageCtl.asOutParam()));
}
}
}
while (0);
goto leave;
/*
* Mount a CD-ROM if requested.
*/
if (cdromFile)
do
{
/* unmount? */
{
/* nothing to do, NULL object will cause unmount */
}
else
{
/* Assume it's a host drive name */
{
/* try to find an existing one */
{
/* try to add to the list */
dvdMedium.asOutParam()));
}
}
}
/* get the first IDE controller to attach the DVD Drive to
* and if there is none, add one temporarily
*/
{
{
if (storageBus == StorageBus_IDE)
{
break;
}
}
if (storageCtl)
{
DeviceType_DVD, NULL));
}
else
{
storageCtlName = "IDE Controller";
storageCtl.asOutParam()));
DeviceType_DVD, NULL));
}
}
}
while (0);
goto leave;
if (fDiscardState)
{
/*
* If the machine is currently saved,
* discard the saved state first.
*/
if (machineState == MachineState_Saved)
{
}
/*
* If there are snapshots, discard the current state,
* i.e. revert to the last snapshot.
*/
if (cSnapshots)
{
goto leave;
}
}
// get the machine debugger (does not have to be there)
if (gMachineDebugger)
{
Log(("Machine debugger available!\n"));
}
if (!gDisplay)
{
RTPrintf("Error: could not get display object!\n");
goto leave;
}
// set the boot drive
if (bootDevice != DeviceType_Null)
{
{
RTPrintf("Error: could not set boot device, using default.\n");
}
}
// set the memory size if not default
if (memorySize)
{
{
}
}
if (vramSize)
{
{
}
}
// we're always able to process absolute mouse events and we prefer that
#ifdef VBOX_WIN32_UI
if (fWin32UI)
{
/* initialize the Win32 user interface inside which SDL will be embedded */
return 1;
}
#endif
/* static initialization of the SDL stuff */
goto leave;
if (gcMonitors > 64)
gcMonitors = 64;
for (unsigned i = 0; i < gcMonitors; i++)
{
// create our SDL framebuffer instance
if (!gpFramebuffer[i])
{
RTPrintf("Error: could not create framebuffer object!\n");
goto leave;
}
}
#ifdef VBOX_WIN32_UI
#endif
for (unsigned i = 0; i < gcMonitors; i++)
{
if (!gpFramebuffer[i]->initialized())
goto leave;
gpFramebuffer[i]->AddRef();
if (fFullscreen)
SetFullscreen(true);
}
#ifdef VBOX_SECURELABEL
if (fSecureLabel)
{
if (!secureLabelFontFile)
{
RTPrintf("Error: no font file specified for secure label!\n");
goto leave;
}
/* load the SDL_ttf library and get the required imports */
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
/* silently ignore errors here */
if (RT_FAILURE(vrc))
vrc = VINF_SUCCESS;
}
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
vrc = gpFramebuffer[0]->initSecureLabel(SECURE_LABEL_HEIGHT, secureLabelFontFile, secureLabelPointSize, secureLabelFontOffs);
if (RT_FAILURE(vrc))
{
goto leave;
}
/*
* Now update the label
*/
}
#endif
#ifdef VBOXSDL_WITH_X11
/* NOTE1: We still want Ctrl-C to work, so we undo the SDL redirections.
* NOTE2: We have to remove the PidFile if this file exists. */
#endif
for (ULONG i = 0; i < gcMonitors; i++)
{
// register our framebuffer
{
RTPrintf("Error: could not register framebuffer object!\n");
goto leave;
}
}
// register a callback for global events
cbVBoxImpl = new VBoxSDLCallback();
goto leave;
// register a callback for machine events
cbConsoleImpl = new VBoxSDLConsoleCallback();
goto leave;
// until we've tried to to start the VM, ignore power off events
cbConsoleImpl->ignorePowerOffEvents(true);
#ifdef VBOX_WITH_VRDP
if (portVRDP)
{
if (gVrdpServer)
{
// has a non standard VRDP port been requested?
if (portVRDP > 0)
{
{
goto leave;
}
}
// now enable VRDP
{
goto leave;
}
}
}
#endif
#ifdef VBOXSDL_ADVANCED_OPTIONS
if (fRawR0 != ~0U)
{
if (!gMachineDebugger)
{
goto leave;
}
}
if (fRawR3 != ~0U)
{
if (!gMachineDebugger)
{
goto leave;
}
}
if (fPATM != ~0U)
{
if (!gMachineDebugger)
{
goto leave;
}
}
if (fCSAM != ~0U)
{
if (!gMachineDebugger)
{
goto leave;
}
}
if (fHWVirt != ~0U)
{
}
if (u32WarpDrive != 0)
{
if (!gMachineDebugger)
{
goto leave;
}
}
#endif /* VBOXSDL_ADVANCED_OPTIONS */
/* start with something in the titlebar */
/* memorize the default cursor */
#if !defined(VBOX_WITH_SDL13)
# if defined(VBOXSDL_WITH_X11)
/* Get Window Manager info. We only need the X11 display. */
if (!SDL_GetWMInfo(&gSdlInfo))
RTPrintf("Error: could not get SDL Window Manager info -- no Xcursor support!\n");
else
# if !defined(VBOX_WITHOUT_XCURSOR)
/* SDL uses its own (plain) default cursor. Use the left arrow cursor instead which might look
* much better if a mouse cursor theme is installed. */
if (gfXCursorEnabled)
{
}
# endif
/* Initialise the keyboard */
# endif /* VBOXSDL_WITH_X11 */
/* create a fake empty cursor */
{
}
#endif /* !VBOX_WITH_SDL13 */
/*
* Register our user signal handler.
*/
#ifdef VBOXSDL_WITH_X11
#endif /* VBOXSDL_WITH_X11 */
/*
* Start the VM execution thread. This has to be done
* asynchronously as powering up can take some time
* (accessing devices such as the host DVD drive). In
* the meantime, we have to service the SDL event loop.
*/
LogFlow(("Powering up the VM...\n"));
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to power up VM! No error text available.\n");
goto leave;
}
#ifdef USE_XPCOM_QUEUE_THREAD
/*
* Before we starting to do stuff, we have to launch the XPCOM
* event queue thread. It will wait for events and send messages
* to the SDL thread. After having done this, we should fairly
* quickly start to process the SDL event queue as an XPCOM
* event storm might arrive. Stupid SDL has a ridiculously small
* event queue buffer!
*/
#endif /* USE_XPCOM_QUEUE_THREAD */
/* termination flag */
bool fTerminateDuringStartup;
fTerminateDuringStartup = false;
LogRel(("VBoxSDL: NUM lock initially %s, CAPS lock initially %s\n",
/* start regular timer so we don't starve in the event loop */
/* loop until the powerup processing is done */
do
{
&& ( machineState == MachineState_Starting
)
)
{
/*
* wait for the next event. This is uncritical as
* power up guarantees to change the machine state
* to either running or aborted and a machine state
* change will send us an event. However, we have to
* service the XPCOM event queue!
*/
#ifdef USE_XPCOM_QUEUE_THREAD
{
fXPCOMEventThreadSignaled = true;
}
#endif
/*
* Wait for SDL events.
*/
if (WaitSDLEvent(&event))
{
{
/*
* Timer event. Used to have the titlebar updated.
*/
case SDL_USER_EVENT_TIMER:
{
/*
* Update the title bar.
*/
break;
}
/*
* User specific resize event.
*/
case SDL_USER_EVENT_RESIZE:
{
LogFlow(("SDL_USER_EVENT_RESIZE\n"));
/* update xOrigin, yOrigin -> mouse */
/* notify the display that the resize has been completed */
break;
}
#ifdef USE_XPCOM_QUEUE_THREAD
/*
* User specific XPCOM event queue event
*/
{
LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
eventQ->processEventQueue(0);
break;
}
#endif /* USE_XPCOM_QUEUE_THREAD */
/*
* Termination event from the on state change callback.
*/
case SDL_USER_EVENT_TERMINATE:
{
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to power up VM! No error text available.\n");
}
fTerminateDuringStartup = true;
break;
}
default:
{
break;
}
}
}
}
eventQ->processEventQueue(0);
&& ( machineState == MachineState_Starting
)
);
/* kill the timer again */
sdlTimer = 0;
/* are we supposed to terminate the process? */
goto leave;
/* did the power up succeed? */
if (machineState != MachineState_Running)
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to power up VM! No error text available (rc = 0x%x state = %d)\n", rc, machineState);
goto leave;
}
// accept power off events from now on because we're running
// note that there's a possible race condition here...
cbConsoleImpl->ignorePowerOffEvents(false);
if (!gKeyboard)
{
RTPrintf("Error: could not get keyboard object!\n");
goto leave;
}
if (!gMouse)
{
RTPrintf("Error: could not get mouse object!\n");
goto leave;
}
/*
* Enable keyboard repeats
*/
/*
* Create PID file.
*/
if (gpszPidFile)
{
char szBuf[32];
const char *pcszLf = "\n";
}
/*
* Main event loop
*/
#ifdef USE_XPCOM_QUEUE_THREAD
{
}
#endif
LogFlow(("VBoxSDL: Entering big event loop\n"));
while (WaitSDLEvent(&event))
{
{
/*
* The screen needs to be repainted.
*/
#ifdef VBOX_WITH_SDL13
case SDL_WINDOWEVENT:
{
{
case SDL_WINDOWEVENT_EXPOSED:
{
if (fb)
break;
}
{
break;
}
default:
break;
}
}
#else
case SDL_VIDEOEXPOSE:
{
gpFramebuffer[0]->repaint();
break;
}
#endif
/*
* Keyboard events.
*/
case SDL_KEYDOWN:
case SDL_KEYUP:
{
switch (enmHKeyState)
{
case HKEYSTATE_NORMAL:
{
&& ksym != SDLK_UNKNOWN
{
EvHKeyDown1 = event;
break;
}
break;
}
case HKEYSTATE_DOWN_1ST:
case HKEYSTATE_DOWN_2ND:
{
if (gHostKeySym2 != SDLK_UNKNOWN)
{
&& ksym != SDLK_UNKNOWN
{
EvHKeyDown2 = event;
break;
}
/* ugly hack: Some guests (e.g. mstsc.exe on Windows XP)
* expect a small delay between two key events. 5ms work
* reliable here so use 10ms to be on the safe side. A
* better but more complicated fix would be to introduce
* a new state and don't wait here. */
RTThreadSleep(10);
break;
}
/* fall through if no two-key sequence is used */
}
case HKEYSTATE_DOWN:
{
{
/* potential host key combination, try execute it */
if (irc == VINF_SUCCESS)
{
break;
}
if (RT_SUCCESS(irc))
goto leave;
}
else /* SDL_KEYUP */
{
if ( ksym != SDLK_UNKNOWN
{
/* toggle grabbing state */
if (!gfGrabbed)
else
InputGrabEnd();
/* SDL doesn't always reset the keystates, correct it */
ResetKeys();
break;
}
}
/* not host key */
/* see the comment for the 2-key case above */
RTThreadSleep(10);
if (gHostKeySym2 != SDLK_UNKNOWN)
{
/* see the comment for the 2-key case above */
RTThreadSleep(10);
}
break;
}
case HKEYSTATE_USED:
{
{
goto leave;
}
break;
}
default:
/* fall thru */
case HKEYSTATE_NOT_IT:
{
break;
}
} /* state switch */
break;
}
/*
* The window was closed.
*/
case SDL_QUIT:
{
if (!gfACPITerm || gSdlQuitTimer)
goto leave;
if (gConsole)
gConsole->PowerButton();
break;
}
/*
* The mouse has moved
*/
case SDL_MOUSEMOTION:
{
if (gfGrabbed || UseAbsoluteMouse())
{
#ifdef VBOX_WITH_SDL13
#else
fb = gpFramebuffer[0];
#endif
SendMouseEvent(fb, 0, 0, 0);
}
break;
}
/*
* A mouse button has been clicked or released.
*/
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
/* don't grab on mouse click if we have guest additions */
{
{
/* start grabbing all events */
}
}
else if (gfGrabbed || UseAbsoluteMouse())
{
? -1
? +1
: 0;
/* end host key combination (CTRL+MouseButton) */
switch (enmHKeyState)
{
case HKEYSTATE_DOWN_1ST:
case HKEYSTATE_DOWN_2ND:
/* ugly hack: small delay to ensure that the key event is
* actually handled _prior_ to the mouse click event */
RTThreadSleep(20);
break;
case HKEYSTATE_DOWN:
if (gHostKeySym2 != SDLK_UNKNOWN)
/* ugly hack: small delay to ensure that the key event is
* actually handled _prior_ to the mouse click event */
RTThreadSleep(20);
break;
default:
break;
}
#ifdef VBOX_WITH_SDL13
#else
fb = gpFramebuffer[0];
#endif
}
break;
}
/*
* The window has gained or lost focus.
*/
case SDL_ACTIVEEVENT:
{
/*
* There is a strange behaviour in SDL when running without a window
* manager: When SDL_WM_GrabInput(SDL_GRAB_ON) is called we receive two
* consecutive events SDL_ACTIVEEVENTs (input lost, input gained).
* Asking SDL_GetAppState() seems the better choice.
*/
{
/*
* another window has stolen the (keyboard) input focus
*/
InputGrabEnd();
}
break;
}
/*
* The SDL window was resized
*/
case SDL_VIDEORESIZE:
{
if (gDisplay)
{
if (gfIgnoreNextResize)
{
break;
}
#ifdef VBOX_SECURELABEL
if (fSecureLabel)
else
#endif
if (gSdlResizeTimer)
}
break;
}
/*
* User specific update event.
*/
/** @todo use a common user event handler so that SDL_PeepEvents() won't
* possibly remove other events in the queue!
*/
{
/*
* Decode event parameters.
*/
LogFlow(("SDL_USER_EVENT_UPDATERECT: x = %d, y = %d, w = %d, h = %d\n",
x, y, w, h));
break;
}
/*
* User event: Window resize done
*/
{
/**
* @todo This is a workaround for synchronization problems between EMT and the
* SDL main thread. It can happen that the SDL thread already starts a
* new resize operation while the EMT is still busy with the old one
* leading to a deadlock. Therefore we call SetVideoModeHint only once
* when the mouse button was released.
*/
/* communicate the resize event to the guest */
break;
}
/*
* User specific resize event.
*/
case SDL_USER_EVENT_RESIZE:
{
LogFlow(("SDL_USER_EVENT_RESIZE\n"));
/* update xOrigin, yOrigin -> mouse */
/* notify the display that the resize has been completed */
break;
}
#ifdef USE_XPCOM_QUEUE_THREAD
/*
* User specific XPCOM event queue event
*/
{
LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
eventQ->processEventQueue(0);
break;
}
#endif /* USE_XPCOM_QUEUE_THREAD */
/*
* User specific update title bar notification event
*/
{
break;
}
/*
* User specific termination event
*/
case SDL_USER_EVENT_TERMINATE:
{
RTPrintf("Error: VM terminated abnormally!\n");
goto leave;
}
#ifdef VBOX_SECURELABEL
/*
* User specific secure label update event
*/
{
/*
* Query the new label text
*/
/*
* Now update the label
*/
break;
}
#endif /* VBOX_SECURELABEL */
/*
* User specific pointer shape change event
*/
{
delete data;
break;
}
/*
* User specific guest capabilities changed
*/
{
break;
}
default:
{
break;
}
}
}
if (gpszPidFile)
LogFlow(("leaving...\n"));
/* make sure the XPCOM event queue thread doesn't do anything harmful */
#endif /* VBOX_WITH_XPCOM */
#ifdef VBOX_WITH_VRDP
if (gVrdpServer)
#endif
/*
* Get the machine state.
*/
if (gMachine)
else
/*
* Turn off the VM if it's running
*/
if ( gConsole
&& ( machineState == MachineState_Running
/** @todo power off paused VMs too? */
)
)
do
{
cbConsoleImpl->ignorePowerOffEvents(true);
{
if (info.isFullAvailable())
PrintError("Failed to power down VM",
else
RTPrintf("Failed to power down virtual machine! No error information available (rc = 0x%x).\n", hrc);
break;
}
} while (0);
/*
* Now we discard all settings so that our changes will
* not be flushed to the permanent configuration
*/
if ( gMachine
&& machineState != MachineState_Saved)
{
}
/* close the session */
if (sessionOpened)
{
}
#ifndef VBOX_WITH_SDL13
/* restore the default cursor and free the custom one if any */
if (gpDefaultCursor)
{
# ifdef VBOXSDL_WITH_X11
if (gfXCursorEnabled)
{
}
# endif /* VBOXSDL_WITH_X11 */
# if defined(VBOXSDL_WITH_X11) && !defined(VBOX_WITHOUT_XCURSOR)
if (gfXCursorEnabled)
# endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
}
if (gpCustomCursor)
{
if (pCustomTempWMCursor)
{
# if defined(RT_OS_WINDOWS)
if (gfXCursorEnabled)
# endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
}
}
#endif
LogFlow(("Releasing mouse, keyboard, vrdpserver, display, console...\n"));
if (gDisplay)
{
for (unsigned i = 0; i < gcMonitors; i++)
}
gVrdpServer = NULL;
// we can only uninitialize SDL here because it is not threadsafe
for (unsigned i = 0; i < gcMonitors; i++)
{
if (gpFramebuffer[i])
{
LogFlow(("Releasing framebuffer...\n"));
gpFramebuffer[i]->Release();
gpFramebuffer[i] = NULL;
}
}
#ifdef VBOX_SECURELABEL
/* must do this after destructing the framebuffer */
if (gLibrarySDL_ttf)
#endif
/* VirtualBox callback unregistration. */
LogFlow(("Releasing machine, session...\n"));
LogFlow(("Releasing VirtualBox object...\n"));
virtualBox = NULL;
// end "all-stuff" scope
////////////////////////////////////////////////////////////////////////////
}
/* Must be before com::Shutdown() */
LogFlow(("Uninitializing COM...\n"));
LogFlow(("Returning from main()!\n"));
}
#ifndef VBOX_WITH_HARDENING
/**
* Main entry point
*/
{
/*
* Before we do *anything*, we initialize the runtime.
*/
int rcRT = RTR3InitAndSUPLib();
if (RT_FAILURE(rcRT))
{
return 1;
}
}
#endif /* !VBOX_WITH_HARDENING */
/**
* Returns whether the absolute mouse is in use, i.e. both host
* and guest have opted to enable it.
*
* @returns bool Flag whether the absolute mouse is in use
*/
static bool UseAbsoluteMouse(void)
{
return (gfAbsoluteMouseHost && gfAbsoluteMouseGuest);
}
#if defined(RT_OS_DARWIN) || defined(RT_OS_OS2)
/**
* Fallback keycode conversion using SDL symbols.
*
* This is used to catch keycodes that's missing from the translation table.
*
* @returns XT scancode
* @param ev SDL scancode
*/
{
Log(("SDL key event: sym=%d scancode=%#x unicode=%#x\n",
switch (sym)
{ /* set 1 scan code */
case SDLK_ESCAPE: return 0x01;
case SDLK_EXCLAIM:
case SDLK_1: return 0x02;
case SDLK_AT:
case SDLK_2: return 0x03;
case SDLK_HASH:
case SDLK_3: return 0x04;
case SDLK_DOLLAR:
case SDLK_4: return 0x05;
/* % */
case SDLK_5: return 0x06;
case SDLK_CARET:
case SDLK_6: return 0x07;
case SDLK_AMPERSAND:
case SDLK_7: return 0x08;
case SDLK_ASTERISK:
case SDLK_8: return 0x09;
case SDLK_LEFTPAREN:
case SDLK_9: return 0x0a;
case SDLK_RIGHTPAREN:
case SDLK_0: return 0x0b;
case SDLK_UNDERSCORE:
case SDLK_MINUS: return 0x0c;
case SDLK_EQUALS:
case SDLK_PLUS: return 0x0d;
case SDLK_BACKSPACE: return 0x0e;
case SDLK_TAB: return 0x0f;
case SDLK_q: return 0x10;
case SDLK_w: return 0x11;
case SDLK_e: return 0x12;
case SDLK_r: return 0x13;
case SDLK_t: return 0x14;
case SDLK_y: return 0x15;
case SDLK_u: return 0x16;
case SDLK_i: return 0x17;
case SDLK_o: return 0x18;
case SDLK_p: return 0x19;
case SDLK_LEFTBRACKET: return 0x1a;
case SDLK_RIGHTBRACKET: return 0x1b;
case SDLK_RETURN: return 0x1c;
case SDLK_LCTRL: return 0x1d;
case SDLK_a: return 0x1e;
case SDLK_s: return 0x1f;
case SDLK_d: return 0x20;
case SDLK_f: return 0x21;
case SDLK_g: return 0x22;
case SDLK_h: return 0x23;
case SDLK_j: return 0x24;
case SDLK_k: return 0x25;
case SDLK_l: return 0x26;
case SDLK_COLON:
case SDLK_SEMICOLON: return 0x27;
case SDLK_QUOTEDBL:
case SDLK_QUOTE: return 0x28;
case SDLK_BACKQUOTE: return 0x29;
case SDLK_LSHIFT: return 0x2a;
case SDLK_BACKSLASH: return 0x2b;
case SDLK_z: return 0x2c;
case SDLK_x: return 0x2d;
case SDLK_c: return 0x2e;
case SDLK_v: return 0x2f;
case SDLK_b: return 0x30;
case SDLK_n: return 0x31;
case SDLK_m: return 0x32;
case SDLK_LESS:
case SDLK_COMMA: return 0x33;
case SDLK_GREATER:
case SDLK_PERIOD: return 0x34;
case SDLK_KP_DIVIDE: /*??*/
case SDLK_QUESTION:
case SDLK_SLASH: return 0x35;
case SDLK_RSHIFT: return 0x36;
case SDLK_KP_MULTIPLY:
case SDLK_LALT: return 0x38;
case SDLK_MODE: /* alt gr*/
case SDLK_SPACE: return 0x39;
case SDLK_CAPSLOCK: return 0x3a;
case SDLK_F1: return 0x3b;
case SDLK_F2: return 0x3c;
case SDLK_F3: return 0x3d;
case SDLK_F4: return 0x3e;
case SDLK_F5: return 0x3f;
case SDLK_F6: return 0x40;
case SDLK_F7: return 0x41;
case SDLK_F8: return 0x42;
case SDLK_F9: return 0x43;
case SDLK_F10: return 0x44;
case SDLK_NUMLOCK: return 0x45;
case SDLK_SCROLLOCK: return 0x46;
case SDLK_KP7: return 0x47;
case SDLK_KP8: return 0x48;
case SDLK_KP9: return 0x49;
case SDLK_KP_MINUS: return 0x4a;
case SDLK_KP4: return 0x4b;
case SDLK_KP5: return 0x4c;
case SDLK_KP6: return 0x4d;
case SDLK_KP_PLUS: return 0x4e;
case SDLK_KP1: return 0x4f;
case SDLK_KP2: return 0x50;
case SDLK_KP3: return 0x51;
case SDLK_KP0: return 0x52;
case SDLK_KP_PERIOD: return 0x53;
case SDLK_SYSREQ: return 0x54;
case SDLK_F11: return 0x57;
case SDLK_F12: return 0x58;
case SDLK_F13: return 0x5b;
case SDLK_LMETA:
case SDLK_F14: return 0x5c;
case SDLK_RMETA:
case SDLK_F15: return 0x5d;
#if 0
case SDLK_CLEAR: return 0x;
case SDLK_KP_EQUALS: return 0x;
case SDLK_COMPOSE: return 0x;
case SDLK_HELP: return 0x;
case SDLK_BREAK: return 0x;
case SDLK_POWER: return 0x;
case SDLK_EURO: return 0x;
case SDLK_UNDO: return 0x;
#endif
default:
Log(("Unhandled sdl key event: sym=%d scancode=%#x unicode=%#x\n",
return 0;
}
}
#endif /* RT_OS_DARWIN */
/**
* Converts an SDL keyboard eventcode to a XT scancode.
*
* @returns XT scancode
* @param ev SDL scancode
*/
{
// start with the scancode determined by SDL
#ifdef VBOXSDL_WITH_X11
# ifdef VBOX_WITH_SDL13
{
case SDLK_ESCAPE: return 0x01;
case SDLK_EXCLAIM:
case SDLK_1: return 0x02;
case SDLK_AT:
case SDLK_2: return 0x03;
case SDLK_HASH:
case SDLK_3: return 0x04;
case SDLK_DOLLAR:
case SDLK_4: return 0x05;
/* % */
case SDLK_5: return 0x06;
case SDLK_CARET:
case SDLK_6: return 0x07;
case SDLK_AMPERSAND:
case SDLK_7: return 0x08;
case SDLK_ASTERISK:
case SDLK_8: return 0x09;
case SDLK_LEFTPAREN:
case SDLK_9: return 0x0a;
case SDLK_RIGHTPAREN:
case SDLK_0: return 0x0b;
case SDLK_UNDERSCORE:
case SDLK_MINUS: return 0x0c;
case SDLK_PLUS: return 0x0d;
case SDLK_BACKSPACE: return 0x0e;
case SDLK_TAB: return 0x0f;
case SDLK_q: return 0x10;
case SDLK_w: return 0x11;
case SDLK_e: return 0x12;
case SDLK_r: return 0x13;
case SDLK_t: return 0x14;
case SDLK_y: return 0x15;
case SDLK_u: return 0x16;
case SDLK_i: return 0x17;
case SDLK_o: return 0x18;
case SDLK_p: return 0x19;
case SDLK_RETURN: return 0x1c;
case SDLK_LCTRL: return 0x1d;
case SDLK_a: return 0x1e;
case SDLK_s: return 0x1f;
case SDLK_d: return 0x20;
case SDLK_f: return 0x21;
case SDLK_g: return 0x22;
case SDLK_h: return 0x23;
case SDLK_j: return 0x24;
case SDLK_k: return 0x25;
case SDLK_l: return 0x26;
case SDLK_COLON: return 0x27;
case SDLK_QUOTEDBL:
case SDLK_QUOTE: return 0x28;
case SDLK_BACKQUOTE: return 0x29;
case SDLK_LSHIFT: return 0x2a;
case SDLK_z: return 0x2c;
case SDLK_x: return 0x2d;
case SDLK_c: return 0x2e;
case SDLK_v: return 0x2f;
case SDLK_b: return 0x30;
case SDLK_n: return 0x31;
case SDLK_m: return 0x32;
case SDLK_LESS: return 0x33;
case SDLK_GREATER: return 0x34;
case SDLK_KP_DIVIDE: /*??*/
case SDLK_QUESTION: return 0x35;
case SDLK_RSHIFT: return 0x36;
case SDLK_KP_MULTIPLY:
case SDLK_LALT: return 0x38;
case SDLK_MODE: /* alt gr*/
case SDLK_SPACE: return 0x39;
case SDLK_CAPSLOCK: return 0x3a;
case SDLK_F1: return 0x3b;
case SDLK_F2: return 0x3c;
case SDLK_F3: return 0x3d;
case SDLK_F4: return 0x3e;
case SDLK_F5: return 0x3f;
case SDLK_F6: return 0x40;
case SDLK_F7: return 0x41;
case SDLK_F8: return 0x42;
case SDLK_F9: return 0x43;
case SDLK_F10: return 0x44;
case SDLK_NUMLOCK: return 0x45;
case SDLK_SCROLLOCK: return 0x46;
case SDLK_KP7: return 0x47;
case SDLK_KP8: return 0x48;
case SDLK_KP9: return 0x49;
case SDLK_KP_MINUS: return 0x4a;
case SDLK_KP4: return 0x4b;
case SDLK_KP5: return 0x4c;
case SDLK_KP6: return 0x4d;
case SDLK_KP_PLUS: return 0x4e;
case SDLK_KP1: return 0x4f;
case SDLK_KP2: return 0x50;
case SDLK_KP3: return 0x51;
case SDLK_KP0: return 0x52;
case SDLK_KP_PERIOD: return 0x53;
case SDLK_SYSREQ: return 0x54;
case SDLK_F11: return 0x57;
case SDLK_F12: return 0x58;
case SDLK_F13: return 0x5b;
case SDLK_F14: return 0x5c;
case SDLK_F15: return 0x5d;
default:
return 0;
}
# else
# endif
#elif defined(RT_OS_DARWIN)
/* This is derived partially from SDL_QuartzKeys.h and partially from testing. */
static const uint16_t s_aMacToSet1[] =
{
/* set-1 SDL_QuartzKeys.h */
0x1e, /* QZ_a 0x00 */
0x1f, /* QZ_s 0x01 */
0x20, /* QZ_d 0x02 */
0x21, /* QZ_f 0x03 */
0x23, /* QZ_h 0x04 */
0x22, /* QZ_g 0x05 */
0x2c, /* QZ_z 0x06 */
0x2d, /* QZ_x 0x07 */
0x2e, /* QZ_c 0x08 */
0x2f, /* QZ_v 0x09 */
0x56, /* between lshift and z. 'INT 1'? */
0x30, /* QZ_b 0x0B */
0x10, /* QZ_q 0x0C */
0x11, /* QZ_w 0x0D */
0x12, /* QZ_e 0x0E */
0x13, /* QZ_r 0x0F */
0x15, /* QZ_y 0x10 */
0x14, /* QZ_t 0x11 */
0x02, /* QZ_1 0x12 */
0x03, /* QZ_2 0x13 */
0x04, /* QZ_3 0x14 */
0x05, /* QZ_4 0x15 */
0x07, /* QZ_6 0x16 */
0x06, /* QZ_5 0x17 */
0x0d, /* QZ_EQUALS 0x18 */
0x0a, /* QZ_9 0x19 */
0x08, /* QZ_7 0x1A */
0x0c, /* QZ_MINUS 0x1B */
0x09, /* QZ_8 0x1C */
0x0b, /* QZ_0 0x1D */
0x1b, /* QZ_RIGHTBRACKET 0x1E */
0x18, /* QZ_o 0x1F */
0x16, /* QZ_u 0x20 */
0x1a, /* QZ_LEFTBRACKET 0x21 */
0x17, /* QZ_i 0x22 */
0x19, /* QZ_p 0x23 */
0x1c, /* QZ_RETURN 0x24 */
0x26, /* QZ_l 0x25 */
0x24, /* QZ_j 0x26 */
0x28, /* QZ_QUOTE 0x27 */
0x25, /* QZ_k 0x28 */
0x27, /* QZ_SEMICOLON 0x29 */
0x2b, /* QZ_BACKSLASH 0x2A */
0x33, /* QZ_COMMA 0x2B */
0x35, /* QZ_SLASH 0x2C */
0x31, /* QZ_n 0x2D */
0x32, /* QZ_m 0x2E */
0x34, /* QZ_PERIOD 0x2F */
0x0f, /* QZ_TAB 0x30 */
0x39, /* QZ_SPACE 0x31 */
0x29, /* QZ_BACKQUOTE 0x32 */
0x0e, /* QZ_BACKSPACE 0x33 */
0x9c, /* QZ_IBOOK_ENTER 0x34 */
0x01, /* QZ_ESCAPE 0x35 */
0x5c|0x100, /* QZ_RMETA 0x36 */
0x5b|0x100, /* QZ_LMETA 0x37 */
0x2a, /* QZ_LSHIFT 0x38 */
0x3a, /* QZ_CAPSLOCK 0x39 */
0x38, /* QZ_LALT 0x3A */
0x1d, /* QZ_LCTRL 0x3B */
0x36, /* QZ_RSHIFT 0x3C */
0x38|0x100, /* QZ_RALT 0x3D */
0x1d|0x100, /* QZ_RCTRL 0x3E */
0, /* */
0, /* */
0x53, /* QZ_KP_PERIOD 0x41 */
0, /* */
0x37, /* QZ_KP_MULTIPLY 0x43 */
0, /* */
0x4e, /* QZ_KP_PLUS 0x45 */
0, /* */
0x45, /* QZ_NUMLOCK 0x47 */
0, /* */
0, /* */
0, /* */
0x35|0x100, /* QZ_KP_DIVIDE 0x4B */
0x1c|0x100, /* QZ_KP_ENTER 0x4C */
0, /* */
0x4a, /* QZ_KP_MINUS 0x4E */
0, /* */
0, /* */
0x0d/*?*/, /* QZ_KP_EQUALS 0x51 */
0x52, /* QZ_KP0 0x52 */
0x4f, /* QZ_KP1 0x53 */
0x50, /* QZ_KP2 0x54 */
0x51, /* QZ_KP3 0x55 */
0x4b, /* QZ_KP4 0x56 */
0x4c, /* QZ_KP5 0x57 */
0x4d, /* QZ_KP6 0x58 */
0x47, /* QZ_KP7 0x59 */
0, /* */
0x48, /* QZ_KP8 0x5B */
0x49, /* QZ_KP9 0x5C */
0, /* */
0, /* */
0, /* */
0x3f, /* QZ_F5 0x60 */
0x40, /* QZ_F6 0x61 */
0x41, /* QZ_F7 0x62 */
0x3d, /* QZ_F3 0x63 */
0x42, /* QZ_F8 0x64 */
0x43, /* QZ_F9 0x65 */
0, /* */
0x57, /* QZ_F11 0x67 */
0, /* */
0x37|0x100, /* QZ_PRINT / F13 0x69 */
0x63, /* QZ_F16 0x6A */
0x46, /* QZ_SCROLLOCK 0x6B */
0, /* */
0x44, /* QZ_F10 0x6D */
0x5d|0x100, /* */
0x58, /* QZ_F12 0x6F */
0, /* */
0/* 0xe1,0x1d,0x45*/, /* QZ_PAUSE 0x71 */
0x52|0x100, /* QZ_INSERT / HELP 0x72 */
0x47|0x100, /* QZ_HOME 0x73 */
0x49|0x100, /* QZ_PAGEUP 0x74 */
0x53|0x100, /* QZ_DELETE 0x75 */
0x3e, /* QZ_F4 0x76 */
0x4f|0x100, /* QZ_END 0x77 */
0x3c, /* QZ_F2 0x78 */
0x51|0x100, /* QZ_PAGEDOWN 0x79 */
0x3b, /* QZ_F1 0x7A */
0x4b|0x100, /* QZ_LEFT 0x7B */
0x4d|0x100, /* QZ_RIGHT 0x7C */
0x50|0x100, /* QZ_DOWN 0x7D */
0x48|0x100, /* QZ_UP 0x7E */
0x5e|0x100, /* QZ_POWER 0x7F */ /* have different break key! */
};
if (keycode == 0)
{
/* This could be a modifier or it could be 'a'. */
{
case SDLK_MODE: /* alt gr */
case SDLK_RMETA:
case SDLK_LMETA:
/* Sssumes normal key. */
}
}
else
{
else
keycode = 0;
if (!keycode)
{
#ifdef DEBUG_bird
#endif
}
}
#ifdef DEBUG_bird
#endif
#endif /* RT_OS_DARWIN */
return keycode;
}
/**
* Releases any modifier keys that are currently in pressed state.
*/
static void ResetKeys(void)
{
int i;
if (!gKeyboard)
return;
for(i = 0; i < 256; i++)
{
if (gaModifiersState[i])
{
if (i & 0x80)
gaModifiersState[i] = 0;
}
}
}
/**
* Keyboard event handler.
*
* @param ev SDL keyboard event.
*/
{
{
// first handle the debugger hotkeys
#if 0
// CTRL+ALT+Fn is not free on Linux hosts with Xorg ..
#else
#endif
{
{
// pressing CTRL+ALT+F11 dumps the statistics counter
case SDLK_F12:
break;
// pressing CTRL+ALT+F12 resets all statistics counter
case SDLK_F11:
break;
default:
break;
}
}
#if 1
{
{
// pressing Alt-F12 toggles the supervisor recompiler
case SDLK_F12:
{
break;
}
// pressing Alt-F11 toggles the user recompiler
case SDLK_F11:
{
break;
}
// pressing Alt-F10 toggles the patch manager
case SDLK_F10:
{
break;
}
// pressing Alt-F9 toggles CSAM
case SDLK_F9:
{
break;
}
// pressing Alt-F8 toggles singlestepping mode
case SDLK_F8:
{
break;
}
default:
break;
}
}
#endif
// pressing Ctrl-F12 toggles the logger
{
#ifdef DEBUG_bird
return;
#endif
}
// pressing F12 sets a logmark
{
RTLogPrintf("****** LOGGING MARK ******\n");
}
// now update the titlebar flags
}
#endif // DEBUG || VBOX_WITH_STATISTICS
// the pause key is the weirdest, needs special handling
{
int v = 0;
v |= 0x80;
return;
}
/*
* Perform SDL key event to scancode conversion
*/
switch(keycode)
{
case 0x00:
{
/* sent when leaving window: reset the modifiers state */
ResetKeys();
return;
}
case 0x2a: /* Left Shift */
case 0x36: /* Right Shift */
case 0x1d: /* Left CTRL */
case 0x1d|0x100: /* Right CTRL */
case 0x38: /* Left ALT */
case 0x38|0x100: /* Right ALT */
{
else
break;
}
case 0x45: /* Num Lock */
case 0x3a: /* Caps Lock */
{
/*
* SDL generates a KEYDOWN event if the lock key is active and a KEYUP event
* if the lock key is inactive. See SDL_DISABLE_LOCK_KEYS.
*/
{
}
return;
}
}
{
/*
* Some keyboards (e.g. the one of mine T60) don't send a NumLock scan code on every
* press of the key. Both the guest and the host should agree on the NumLock state.
* If they differ, we try to alter the guest NumLock state by sending the NumLock key
* scancode. We will get a feedback through the KBD_CMD_SET_LEDS command if the guest
* bother him with NumLock scancodes. At least our BIOS, Linux and Windows handle the
* NumLock LED well.
*/
{
}
{
}
}
/*
* Now we send the event. Apply extended and release prefixes.
*/
if (keycode & 0x100)
: (keycode & 0x7f));
}
#ifdef RT_OS_DARWIN
/* Private interface in 10.3 and later. */
typedef int CGSConnection;
typedef enum
{
extern CGSConnection _CGSDefaultConnection(void);
extern CGError CGSGetGlobalHotKeyOperatingMode(CGSConnection Connection, CGSGlobalHotKeyOperatingMode *enmMode);
extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection Connection, CGSGlobalHotKeyOperatingMode enmMode);
/** Keeping track of whether we disabled the hotkeys or not. */
static bool g_fHotKeysDisabled = false;
/** Whether we've connected or not. */
static bool g_fConnectedToCGS = false;
/** Cached connection. */
static CGSConnection g_CGSConnection;
/**
* Disables or enabled global hot keys.
*/
static void DisableGlobalHotKeys(bool fDisable)
{
if (!g_fConnectedToCGS)
{
g_fConnectedToCGS = true;
}
/* get current mode. */
/* calc new mode. */
if (fDisable)
{
if (enmMode != kCGSGlobalHotKeyEnable)
return;
}
else
{
if ( enmMode != kCGSGlobalHotKeyDisable
/*|| !g_fHotKeysDisabled*/)
return;
}
/* try set it and check the actual result. */
if (enmNewMode == enmMode)
}
#endif /* RT_OS_DARWIN */
/**
* Start grabbing the mouse.
*/
static void InputGrabStart(void)
{
#ifdef RT_OS_DARWIN
DisableGlobalHotKeys(true);
#endif
// dummy read to avoid moving the mouse
#ifdef VBOX_WITH_SDL13
0,
#endif
}
/**
* End mouse grabbing.
*/
static void InputGrabEnd(void)
{
#ifdef RT_OS_DARWIN
DisableGlobalHotKeys(false);
#endif
}
/**
* Query mouse position and button state from SDL and send to the VM
*
* @param dz Relative mouse wheel movement
*/
{
bool abs;
#ifdef VBOX_WITH_SDL13
if (!fb)
{
SDL_GetMouseState(0, &x, &y);
RTPrintf("MouseEvent: Cannot find fb mouse = %d,%d\n", x, y);
return;
}
#else
#endif
/*
* If supported and we're not in grabbed mode, we'll use the absolute mouse.
* If we are in grabbed mode and the guest is not able to draw the mouse cursor
* itself, or can't handle relative reporting, we have to use absolute
* coordinates, otherwise the host cursor and
* the coordinates the guest thinks the mouse is at could get out-of-sync. From
* the SDL mailing list:
*
* "The event processing is usually asynchronous and so somewhat delayed, and
* SDL_GetMouseState is returning the immediate mouse state. So at the time you
* call SDL_GetMouseState, the "button" is already up."
*/
|| !gfRelativeMouseGuest;
/* only used if abs == TRUE */
#ifdef VBOX_WITH_SDL13
0,
#endif
&x, &y)
#ifdef VBOX_WITH_SDL13
0,
#endif
&x, &y);
/*
* process buttons
*/
buttons = 0;
if (abs)
{
x += xOrigin;
y += yOrigin;
/*
* Check if the mouse event is inside the guest area. This solves the
* following problem: Some guests switch off the VBox hardware mouse
* cursor and draw the mouse cursor itself instead. Moving the mouse
* outside the guest area then leads to annoying mouse hangs if we
* don't pass mouse motion events into the guest.
*/
{
/*
* Cursor outside of valid guest area (outside window or in secure
* label area. Don't allow any mouse button press.
*/
button = 0;
/*
* Release any pressed button.
*/
#if 0
/* disabled on customers request */
#endif
/*
* Prevent negative coordinates.
*/
if (!gpOffCursor)
{
}
}
else
{
if (gpOffCursor)
{
/*
* We just entered the valid guest area. Restore the guest mouse
* cursor.
*/
gpOffCursor = NULL;
}
}
}
/*
* Button was pressed but that press is not reflected in the button state?
*/
{
/*
* It can happen that a mouse up event follows a mouse down event immediately
* and we see the events when the bit in the button state is already cleared
* again. In that case we simulate the mouse down event.
*/
int tmp_button = 0;
switch (button)
{
}
if (abs)
{
/**
* @todo
* PutMouseEventAbsolute() expects x and y starting from 1,1.
* should we do the increment internally in PutMouseEventAbsolute()
* or state it in PutMouseEventAbsolute() docs?
*/
dz, 0 /* horizontal scroll wheel */,
buttons | tmp_button);
}
else
{
0 /* horizontal scroll wheel */,
buttons | tmp_button);
}
}
// now send the mouse event
if (abs)
{
/**
* @todo
* PutMouseEventAbsolute() expects x and y starting from 1,1.
* should we do the increment internally in PutMouseEventAbsolute()
* or state it in PutMouseEventAbsolute() docs?
*/
}
else
{
}
}
/**
* Resets the VM
*/
void ResetVM(void)
{
if (gConsole)
}
/**
* Initiates a saved state and updates the titlebar with progress information
*/
void SaveState(void)
{
ResetKeys();
if (gfGrabbed)
InputGrabEnd();
{
return;
}
/*
* Wait for the operation to be completed and work
* the title bar in the mean while.
*/
#ifndef RT_OS_DARWIN /* don't break the other guys yet. */
for (;;)
{
BOOL fCompleted = false;
break;
break;
if (cPercentNow != cPercent)
{
}
/* wait */
break;
/// @todo process gui events.
}
#else /* new loop which processes GUI events while saving. */
/* start regular timer so we don't starve in the event loop */
for (;;)
{
/*
* Check for completion.
*/
BOOL fCompleted = false;
break;
break;
if (cPercentNow != cPercent)
{
}
/*
* Wait for and process GUI a event.
* This is necessary for XPCOM IPC and for updating the
* title bar on the Mac.
*/
if (WaitSDLEvent(&event))
{
{
/*
* Timer event preventing us from getting stuck.
*/
case SDL_USER_EVENT_TIMER:
break;
#ifdef USE_XPCOM_QUEUE_THREAD
/*
* User specific XPCOM event queue event
*/
{
LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
break;
}
#endif /* USE_XPCOM_QUEUE_THREAD */
/*
* Ignore all other events.
*/
case SDL_USER_EVENT_RESIZE:
case SDL_USER_EVENT_TERMINATE:
default:
break;
}
}
}
/* kill the timer */
sdlTimer = 0;
#endif /* RT_OS_DARWIN */
/*
* What's the result of the operation?
*/
lrc = ~0;
if (!lrc)
{
RTPrintf("Saved the state successfully.\n");
}
else
}
/**
* Build the titlebar string
*/
{
static char szTitle[1024] = {0};
/* back up current title */
char szPrevTitle[1024];
/* which mode are we in? */
switch (mode)
{
case TITLEBAR_NORMAL:
{
if (machineState == MachineState_Paused)
if (gfGrabbed)
#if defined(DEBUG) || defined(VBOX_WITH_STATISTICS)
// do we have a debugger interface
if (gMachineDebugger)
{
// query the machine state
" [STEP=%d CS=%d PAT=%d RR0=%d RR3=%d LOG=%d HWVirt=%d",
if (virtualTimeRate != 100)
else
}
#endif /* DEBUG || VBOX_WITH_STATISTICS */
break;
}
case TITLEBAR_STARTUP:
{
/*
* Format it.
*/
if (machineState == MachineState_Starting)
" - Starting...");
else if (machineState == MachineState_Restoring)
{
" - Restoring %d%%...", (int)cPercentNow);
else
" - Restoring...");
}
else if (machineState == MachineState_TeleportingIn)
{
" - Teleporting %d%%...", (int)cPercentNow);
else
" - Teleporting...");
}
/* ignore other states, we could already be in running or aborted state */
break;
}
case TITLEBAR_SAVE:
{
" - Saving %d%%...", u32User);
break;
}
case TITLEBAR_SNAPSHOT:
{
" - Taking snapshot %d%%...", u32User);
break;
}
default:
return;
}
/*
* Don't update if it didn't change.
*/
return;
/*
* Set the new title
*/
#ifdef VBOX_WIN32_UI
#else
#endif
}
#if 0
static void vbox_show_shape (unsigned short w, unsigned short h,
{
size_t x, y;
unsigned short pitch;
printf("show_shape %dx%d pitch %d size mask %d\n",
{
for (x = 0; x < w; ++x) {
printf(" ");
else
{
if (c == bg)
printf("Y");
else
printf("X");
}
}
printf("\n");
}
}
#endif
/**
* Sets the pointer shape according to parameters.
* Must be called only from the main SDL thread.
*/
{
/*
* don't allow to change the pointer shape if we are outside the valid
* guest area. In that case set standard mouse pointer is set and should
* not get overridden.
*/
if (gpOffCursor)
return;
{
bool ok = false;
#if 0
/* pointer debugging code */
// vbox_show_shape(data->width, data->height, 0, data->shape);
uint32_t shapeSize = ((((data->width + 7) / 8) * data->height + 3) & ~3) + data->width * 4 * data->height;
printf("uint8_t pointerdata[] = { ");
{
}
printf("};\n");
#endif
#if defined(RT_OS_WINDOWS)
void *lpBits;
// specifiy a supported 32 BPP alpha format for Windows XP
else
bi.bV5AlphaMask = 0;
// create the DIB section with an alpha channel
{
// create an empty mask bitmap
}
else
{
/* Word aligned AND mask. Will be allocated and created if necessary. */
/* Width in bytes of the original AND mask scan line. */
if (cbAndMaskScan & 1)
{
/* Original AND mask is not word aligned. */
/* Allocate memory for aligned AND mask. */
{
/* According to MSDN the padding bits must be 0.
* Compute the bit mask to set padding bits to 0 in the last byte of original AND mask.
*/
Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
unsigned i;
{
src += cbAndMaskScan;
}
}
}
// create the AND mask bitmap
{
}
}
if (hBitmap && hMonoBitmap)
{
{
}
if (hAlphaCursor)
{
// here we do a dirty trick by substituting a Window Manager's
// cursor handle with the handle we created
// see SDL12/src/video/wincommon/SDL_sysmouse.c
if (pCustomTempWMCursor)
{
}
ok = true;
}
}
if (hMonoBitmap)
if (hBitmap)
::DeleteObject(hBitmap);
if (gfXCursorEnabled)
{
if (img)
{
{
{
// convert AND mask to the alpha channel
{
if (!(x % 8))
byte = *(srcAndMaskPtr ++);
else
byte <<= 1;
if (byte & 0x80)
{
// Linux doesn't support inverted pixels (XOR ops,
// to be exact) in cursor shapes, so we detect such
// pixels and always replace them with black ones to
// make them visible at least over light colors
if (dstShapePtr [x] & 0x00FFFFFF)
dstShapePtr [x] = 0xFF000000;
else
dstShapePtr [x] = 0x00000000;
}
else
dstShapePtr [x] |= 0xFF000000;
}
}
}
#ifndef VBOX_WITH_SDL13
if (cur)
{
// here we do a dirty trick by substituting a Window Manager's
// cursor handle with the handle we created
// see SDL12/src/video/x11/SDL_x11mouse.c
if (pCustomTempWMCursor)
{
}
ok = true;
}
#endif
}
}
#endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
if (!ok)
{
}
}
else
{
else if (gfAbsoluteMouseGuest)
/* Don't disable the cursor if the guest additions are not active (anymore) */
}
}
/**
* Handle changed mouse capabilities
*/
static void HandleGuestCapsChanged(void)
{
if (!gfAbsoluteMouseGuest)
{
// Cursor could be overwritten by the guest tools
gpOffCursor = NULL;
}
if (gMouse && UseAbsoluteMouse())
{
// Actually switch to absolute coordinates
if (gfGrabbed)
InputGrabEnd();
}
}
/**
* Handles a host key down event
*/
{
/*
* Revalidate the host key modifier
*/
return VERR_NOT_SUPPORTED;
/*
* What was pressed?
*/
{
/* Control-Alt-Delete */
case SDLK_DELETE:
{
break;
}
/*
* Fullscreen / Windowed toggle.
*/
case SDLK_f:
{
return VERR_NOT_SUPPORTED;
/*
* process because there might be a short moment
* without a valid framebuffer
*/
if (fPauseIt)
if (fPauseIt)
/*
* screen repaint, just to be sure.
*/
break;
}
/*
* Pause / Resume toggle.
*/
case SDLK_p:
{
return VERR_NOT_SUPPORTED;
if ( machineState == MachineState_Running
)
{
if (gfGrabbed)
InputGrabEnd();
}
else if (machineState == MachineState_Paused)
{
}
break;
}
/*
* Reset the VM
*/
case SDLK_r:
{
return VERR_NOT_SUPPORTED;
ResetVM();
break;
}
/*
* Terminate the VM
*/
case SDLK_q:
{
return VERR_NOT_SUPPORTED;
return VINF_EM_TERMINATE;
}
/*
* Save the machine's state and exit
*/
case SDLK_s:
{
return VERR_NOT_SUPPORTED;
SaveState();
return VINF_EM_TERMINATE;
}
case SDLK_h:
{
return VERR_NOT_SUPPORTED;
if (gConsole)
gConsole->PowerButton();
break;
}
/*
* Perform an online snapshot. Continue operation.
*/
case SDLK_n:
{
return VERR_NOT_SUPPORTED;
ULONG cSnapshots = 0;
char pszSnapshotName[20];
gProgress.asOutParam()));
{
/* continue operation */
return VINF_SUCCESS;
}
/*
* Wait for the operation to be completed and work
* the title bar in the mean while.
*/
for (;;)
{
BOOL fCompleted = false;
break;
break;
if (cPercentNow != cPercent)
{
}
/* wait */
break;
/// @todo process gui events.
}
/* continue operation */
return VINF_SUCCESS;
}
{
// /* send Ctrl-Alt-Fx to guest */
return VINF_SUCCESS;
}
/*
* Not a host key combination.
* Indicate this by returning false.
*/
default:
return VERR_NOT_SUPPORTED;
}
return VINF_SUCCESS;
}
/**
* Timer callback function for startup processing
*/
{
/* post message so we can do something in the startup loop */
return interval;
}
/**
* Timer callback function to check if resizing is finished
*/
{
/* post message so the window is actually resized */
/* one-shot */
return 0;
}
/**
* Timer callback function to check if an ACPI power button event was handled by the guest.
*/
{
if (gConsole)
{
{
/* event was not handled, power down the guest */
gfACPITerm = FALSE;
}
}
/* one-shot */
return 0;
}
/**
* Wait for the next SDL event. Don't use SDL_WaitEvent since this function
* calls SDL_Delay(10) if the event queue is empty.
*/
{
for (;;)
{
if (rc == 1)
{
#ifdef USE_XPCOM_QUEUE_THREAD
#endif
return 1;
}
/* Immediately wake up if new SDL events are available. This does not
* work for internal SDL events. Don't wait more than 10ms. */
}
}
/**
* Ensure that an SDL event is really enqueued. Try multiple times if necessary.
*/
{
int ntries = 10;
{
#ifdef VBOX_WITH_SDL13
if (rc == 1)
#else
if (rc == 0)
#endif
return 0;
RTThreadSleep(2);
}
LogRel(("WARNING: Failed to enqueue SDL event %d.%d!\n",
return -1;
}
#ifdef VBOXSDL_WITH_X11
/**
* Special SDL_PushEvent function for NotifyUpdate events. These events may occur in bursts
* so make sure they don't flood the SDL event queue.
*/
{
#ifdef VBOX_WITH_SDL13
#else
#endif
/* A global counter is faster than SDL_PeepEvents() */
if (fSuccess)
/* In order to not flood the SDL event queue, yield the CPU or (if there are already many
* events queued) even sleep */
if (g_cNotifyUpdateEventsPending > 96)
{
/* Too many NotifyUpdate events, sleep for a small amount to give the main thread time
* to handle these events. The SDL queue can hold up to 128 events. */
Log(("PushNotifyUpdateEvent: Sleep 1ms\n"));
RTThreadSleep(1);
}
else
}
#endif /* VBOXSDL_WITH_X11 */
/**
*
*/
static void SetFullscreen(bool enable)
{
return;
if (!gfFullscreenResize)
{
/*
*/
}
else
{
/*
* The alternate way: Switch to fullscreen with the host screen resolution and adapt
* the guest screen resolution to the host window geometry.
*/
if (enable)
{
/* switch to fullscreen */
}
else
{
/* switch back to saved geometry */
}
{
}
}
}
#ifdef VBOX_WITH_SDL13
{
for (unsigned i = 0; i < gcMonitors; i++)
return gpFramebuffer[i];
return NULL;
}
#endif