VBoxSDL.cpp revision 2162ed290319349d7c9548c189f1730e594e1a2c
/** @file
* VBox frontends: VBoxSDL (simple frontend based on SDL):
* Main code
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_GUI
using namespace com;
#if defined (__LINUX__)
#include <SDL_syswm.h> /* for SDL_GetWMInfo() */
#endif
#include "VBoxSDL.h"
#include "Framebuffer.h"
#include "Helper.h"
#include <iprt/semaphore.h>
#include <stdlib.h> /* for alloca */
#include <malloc.h> /* for alloca */
#include <signal.h>
#include <vector>
/* 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 (aShape)
{
if (shape)
}
}
{
}
};
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);
/*******************************************************************************
* Global Variables *
*******************************************************************************/
#if defined (DEBUG_dmik)
// my mini kbd doesn't have RCTRL...
static int gHostKeyMod = KMOD_RSHIFT;
static int gHostKeySym1 = SDLK_RSHIFT;
static int gHostKeySym2 = SDLK_UNKNOWN;
#else
static int gHostKeyMod = KMOD_RCTRL;
static int gHostKeySym1 = SDLK_RCTRL;
static int gHostKeySym2 = SDLK_UNKNOWN;
#endif
static int guGuestNumLockAdaptionCnt = 2;
/** modifier keypress status (scancode as index) */
#ifdef __LINUX__
static Cursor gpDefaultOrigX11Cursor;
#endif
#ifdef __LINUX__
static SDL_SysWMinfo gSdlInfo;
#endif
#ifdef VBOX_SECURELABEL
#ifdef __WIN__
#define LIBSDL_TTF_NAME "SDL_ttf"
#else
#define LIBSDL_TTF_NAME "libSDL_ttf"
#endif
#endif
/**
* Callback handler for VirtualBox events
*/
class VBoxSDLCallback :
public IVirtualBoxCallback
{
public:
{
#if defined (__WIN__)
refcnt = 0;
#endif
}
virtual ~VBoxSDLCallback()
{
}
#ifdef __WIN__
{
return ::InterlockedIncrement(&refcnt);
}
{
if (cnt == 0)
delete this;
return cnt;
}
{
if (riid == IID_IUnknown)
{
*ppObj = this;
AddRef();
return S_OK;
}
if (riid == IID_IVirtualBoxCallback)
{
*ppObj = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
#endif
{
return S_OK;
}
{
return S_OK;
}
{
/* we never disagree */
if (!changeAllowed)
return E_INVALIDARG;
*changeAllowed = true;
return S_OK;
}
{
#ifdef VBOX_SECURELABEL
/*
* check if we're interested in the message
*/
if (ourGuid == messageGuid)
{
{
/*
* Notify SDL thread of the string update
*/
}
}
#endif /* VBOX_SECURELABEL */
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
private:
#ifdef __WIN__
long refcnt;
#endif
};
/**
* Callback handler for machine events
*/
class VBoxSDLConsoleCallback :
public IConsoleCallback
{
public:
VBoxSDLConsoleCallback() : m_fIgnorePowerOffEvents(false)
{
#if defined (__WIN__)
refcnt = 0;
#endif
}
virtual ~VBoxSDLConsoleCallback()
{
}
#ifdef __WIN__
{
return ::InterlockedIncrement(&refcnt);
}
{
if (cnt == 0)
delete this;
return cnt;
}
{
if (riid == IID_IUnknown)
{
*ppObj = this;
AddRef();
return S_OK;
}
if (riid == IID_IConsoleCallback)
{
*ppObj = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
#endif
{
if (!data)
return E_FAIL;
if (rc)
delete data;
return S_OK;
}
{
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 S_OK;
}
{
/* Don't bother the guest with NumLock scancodes if he doesn't set the NumLock LED */
if (gfGuestNumLockPressed != fNumLock)
return S_OK;
}
{
return S_OK;
}
{
switch (machineState)
{
case MachineState_InvalidMachineState: return "InvalidMachineState";
case MachineState_Running: return "Running";
case MachineState_Restoring: return "Restoring";
case MachineState_Starting: return "Starting";
case MachineState_PoweredOff: return "PoweredOff";
case MachineState_Saved: return "Saved";
case MachineState_Aborted: return "Aborted";
case MachineState_Stopping: return "Stopping";
default: return "no idea";
}
}
void ignorePowerOffEvents(bool fIgnore)
{
}
private:
#ifdef __WIN__
long refcnt;
#endif
bool m_fIgnorePowerOffEvents;
};
#ifdef __LINUX__
#endif /* __LINUX__ */
static void show_usage()
{
RTPrintf("Usage:\n"
" -list List all registered virtual machines and exit\n"
" -vm <id|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> Set temporary boot device (a = floppy, c = first hard disk, d = DVD)\n"
" -m <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"
" -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 hostkey\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"
#ifdef __LINUX__
" -tapdev<1-N> <dev> Use existing persistent TAP device with the given name\n"
" -tapfd<1-N> <fd> Use existing TAP device, don't allocate\n"
#endif
#ifdef VBOX_VRDP
" -vrdp <port> Listen for VRDP connections on port (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"
" -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");
}
{
char pszBuffer[1024];
RTPrintf(" %.*s %.*s\n In%.*s %s",
pszStat);
else
if (pwszComponent)
RTPrintf("\n");
}
#ifdef __LINUX__
/**
* 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();
}
}
#endif /* __LINUX__ */
/** entry point */
{
/*
* Before we do *anything*, we initialize the runtime.
*/
if (VBOX_FAILURE(rcRT))
{
return 1;
}
/*
* 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;
}
uint32_t memorySize = 0;
bool fFullscreen = false;
bool fResizable = true;
bool fXPCOMEventThreadSignaled = false;
bool fListVMs = false;
#ifdef VBOX_VRDP
int portVRDP = ~0;
#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;
#endif
#ifdef VBOX_WIN32_UI
bool fWin32UI = false;
#endif
bool fShowSDLConfig = false;
int fixedWidth = ~0;
int fixedHeight = ~0;
int fixedBPP = ~0;
/* 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"));
RTPrintf("VirtualBox SDL GUI %d.%d.%d built %s %s\n",
// less than one parameter is not possible
if (argc < 2)
{
show_usage();
return 1;
}
{
return 1;
}
do
{
// scopes all the stuff till shutdown
////////////////////////////////////////////////////////////////////////////
bool sessionOpened = false;
"VirtualBoxServer");
{
if (info.isFullAvailable())
PrintError("Failed to create VirtualBox object",
else
break;
}
{
break;
}
// create the event queue
// after the session is closed)
/// @todo
// EventQueue eventQ;
#ifdef __LINUX__
#endif /* __LINUX__ */
/* Get the number of network adapters */
ULONG NetworkAdapterCount = 0;
#ifdef __LINUX__
#endif
// command line argument parsing stuff
{
{
fListVMs = true;
}
{
{
RTPrintf("Error: VM not specified (UUID or name)!\n");
break;
}
// first check if a UUID was supplied
{
LogFlow(("invalid UUID format, assuming it's a VM name\n"));
}
}
{
{
RTPrintf("Error: missing argument for boot drive!\n");
break;
}
{
case 'a':
{
break;
}
case 'c':
{
break;
}
case 'd':
{
break;
}
default:
{
RTPrintf("Error: wrong argument for boot drive!\n");
break;
}
}
break;
}
{
{
RTPrintf("Error: missing argument for memory size!\n");
break;
}
}
{
{
RTPrintf("Error: missing argument for vram size!\n");
break;
}
}
{
fFullscreen = true;
}
{
/* three parameters follow */
{
RTPrintf("Error: missing arguments for fixed video mode!\n");
break;
}
}
{
}
{
fResizable = false;
}
{
gHostKeyMod = 0;
gHostKeySym1 = 0;
}
{
}
{
{
RTPrintf("Error: missing file name for first hard disk!\n");
break;
}
/* resolve it. */
if (!hdaFile)
{
RTPrintf("Error: The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]);
break;
}
}
{
{
break;
}
/* resolve it. */
if (!fdaFile)
{
RTPrintf("Error: The path to the specified floppy disk, '%s', could not be resolved.\n", argv[curArg]);
break;
}
}
{
{
break;
}
/* resolve it. */
if (!cdromFile)
{
break;
}
}
#ifdef __LINUX__
{
ULONG n = 0;
{
RTPrintf("Error: invalid TAP device option!\n");
break;
}
curArg++;
}
{
ULONG n = 0;
{
RTPrintf("Error: invalid TAP file descriptor option!\n");
break;
}
curArg++;
}
#endif /* __LINUX__ */
#ifdef VBOX_VRDP
{
// start with the standard VRDP port
portVRDP = 0;
// is there another argument
{
// check if the next argument is a number
if (port > 0)
{
curArg++;
}
}
}
#endif /* VBOX_VRDP */
{
fDiscardState = true;
}
#ifdef VBOX_SECURELABEL
{
fSecureLabel = true;
LogFlow(("Secure labelling turned on\n"));
}
{
{
RTPrintf("Error: missing font file name for secure label!\n");
break;
}
}
{
{
RTPrintf("Error: missing font point size for secure label!\n");
break;
}
}
{
{
RTPrintf("Error: missing text color value for secure label!\n");
break;
}
}
{
{
RTPrintf("Error: missing background color value for secure label!\n");
break;
}
}
#endif
#ifdef VBOXSDL_ADVANCED_OPTIONS
fRawR0 = true;
fRawR0 = false;
fRawR3 = true;
fRawR3 = false;
fPATM = true;
fPATM = false;
fCSAM = true;
fCSAM = false;
#endif /* VBOXSDL_ADVANCED_OPTIONS */
#ifdef VBOX_WIN32_UI
fWin32UI = true;
#endif
fShowSDLConfig = true;
{
{
RTPrintf("Error: not enough arguments for host keys!\n");
break;
}
{
/* two-key sequence as host key specified */
}
}
/* just show the help screen */
else
{
show_usage();
return 1;
}
}
break;
/*
* Are we supposed to display the list of registered VMs?
*/
if (fListVMs)
{
RTPrintf("\nList of registered VMs:\n");
/*
* Get the list of all registered VMs
*/
{
/*
* Iterate through the collection
*/
{
{
}
}
}
/* terminate application */
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;
}
{
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 assing
* it to the VM.
*/
if (vdi)
{
}
else
{
/* we've not found the image */
if (vdi)
{
}
}
/* do we have the right image now? */
if (hardDisk)
{
/*
* Go and attach it!
*/
/// @todo why is this attachment saved?
}
else
{
RTPrintf("Error: failed to mount the specified hard disk image!\n");
goto leave;
}
}
if (fdaFile)
{
{
/// @todo this will not work on case insensitive systems if the casing does not match the registration!!!
break;
else
floppyImage = NULL;
}
/* we've not found the image? */
if (!floppyImage)
{
}
/* do we have the right image now? */
if (floppyImage)
{
/*
* Go and attach it!
*/
}
else
{
RTPrintf("Error: failed to mount the specified floppy disk image!\n");
goto leave;
}
}
/*
* Are we supposed to use a different CDROM image?
*/
if (cdromFile)
{
/*
* First special case 'none' to unmount
*/
{
}
else
{
/*
* Determine if it's a host device or ISO image
*/
bool fHostDrive = false;
#ifdef __WIN__
/* two characters with the 2nd being a colon */
{
fHostDrive = true;
}
#else /* !__WIN__ */
/* it has to start with /dev/ */
fHostDrive = true;
#endif /* !__WIN__ */
if (fHostDrive)
{
{
{
{
}
break;
}
}
if (!hasMore)
}
else
{
/*
* Same strategy as with the HDD images: check if already registered,
* if not, register on the fly.
*/
{
/// @todo not correct for case insensitive platforms (win32)
/// See comment on hdaFile.
if (dvdImageFile == cdromFile)
break;
else
}
/* we've not found the image? */
if (!dvdImage)
{
{
}
}
/* do we have the right image now? */
if (dvdImage)
{
/* attach */
}
else
{
RTPrintf("Error: failed to mount the specified ISO image!\n");
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)
{
}
}
// 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_NoDevice)
{
{
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 */
if (initUI(fResizable))
return 1;
}
#endif
// create our SDL framebuffer instance
if (!gpFrameBuffer)
{
RTPrintf("Error: could not create framebuffer object!\n");
goto leave;
}
if (!gpFrameBuffer->initialized())
goto leave;
gpFrameBuffer->AddRef();
if (fFullscreen)
{
gpFrameBuffer->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 */
int rcVBox;
if (VBOX_SUCCESS(rcVBox))
if (VBOX_SUCCESS(rcVBox))
if (VBOX_SUCCESS(rcVBox))
if (VBOX_SUCCESS(rcVBox))
if (VBOX_SUCCESS(rcVBox))
if (VBOX_SUCCESS(rcVBox))
rcVBox = gpFrameBuffer->initSecureLabel(SECURE_LABEL_HEIGHT, secureLabelFontFile, secureLabelPointSize);
if (VBOX_FAILURE(rcVBox))
{
goto leave;
}
/*
* Now update the label
*/
}
#endif
// register our framebuffer
{
RTPrintf("Error: could not register framebuffer object!\n");
goto leave;
}
// register a callback for global events
callback = new VBoxSDLCallback();
// register a callback for machine events
consoleCallback = new VBoxSDLConsoleCallback();
// until we've tried to to start the VM, ignore power off events
consoleCallback->ignorePowerOffEvents(true);
#ifdef __LINUX__
/*
* Do we have a TAP device name or file descriptor? If so, communicate
* it to the network adapter so that it doesn't allocate a new one
* in case TAP is already configured.
*/
{
for (ULONG i = 0; i < NetworkAdapterCount; i++)
{
{
if (networkAdapter)
{
{
if (tapdev[i])
else
}
else
{
}
}
else
{
/* warning */
}
}
}
}
#endif /* __LINUX__ */
#ifdef VBOX_VRDP
if (portVRDP != ~0)
{
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 != TriStateBool_Default)
{
}
#endif /* VBOXSDL_ADVANCED_OPTIONS */
/* start with something in the titlebar */
/* memorize the default cursor */
#ifdef __LINUX__
/* Get Window Manager info. We only need the X11 display. */
if (!SDL_GetWMInfo(&gSdlInfo))
{
RTPrintf("Error: could not get SDL Window Manager info!\n");
goto leave;
}
/* 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. */
#endif /* __LINUX__ */
/* create a fake empty cursor */
{
}
/*
* Register our user signal handler.
*/
#ifdef __LINUX__
#endif /* __LINUX__ */
/*
* 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 __LINUX__
/*
* 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 /** __LINUX__ */
/* termination flag */
bool fTerminateDuringStartup;
fTerminateDuringStartup = false;
/* start regular timer so we don't starve in the event loop */
/* loop until the powerup processing is done */
do
{
&& ( machineState == MachineState_Starting
|| machineState == MachineState_Restoring))
{
/*
* 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 __LINUX__
{
fXPCOMEventThreadSignaled = true;
}
#endif
/*
* Wait for SDL events.
*/
if (SDL_WaitEvent(&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"));
/* notify the display that the resize has been completed */
break;
}
#ifdef __LINUX__
/*
* User specific XPCOM event queue event
*/
{
LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
break;
}
#endif /* __LINUX__ */
/*
* 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;
}
}
}
}
&& ( machineState == MachineState_Starting
|| machineState == MachineState_Restoring));
/* 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...
consoleCallback->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
*/
/*
* Main event loop
*/
#ifdef __LINUX__
{
}
#endif
LogFlow(("VBoxSDL: Entering big event loop\n"));
while (SDL_WaitEvent(&event))
{
{
/*
* The screen needs to be repainted.
*/
case SDL_VIDEOEXPOSE:
{
/// @todo that somehow doesn't seem to work!
gpFrameBuffer->repaint();
break;
}
/*
* 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;
}
break;
}
/* fall through if no two-key sequence is used */
}
case HKEYSTATE_DOWN:
{
{
/* potential host key combination, try execute it */
if (rc == VINF_SUCCESS)
{
break;
}
if (VBOX_SUCCESS(rc))
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 */
if (gHostKeySym2 != SDLK_UNKNOWN)
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:
{
goto leave;
break;
}
/*
* The mouse has moved
*/
case SDL_MOUSEMOTION:
{
if (gfGrabbed || UseAbsoluteMouse())
{
SendMouseEvent(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
{
? -1
? +1
: 0;
/* end host key combination (CTRL+MouseButton) */
switch (enmHKeyState)
{
case HKEYSTATE_DOWN_1ST:
case HKEYSTATE_DOWN_2ND:
break;
case HKEYSTATE_DOWN:
if (gHostKeySym2 != SDLK_UNKNOWN)
break;
default:
break;
}
}
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)
{
#ifdef VBOX_SECURELABEL
/* communicate the resize event to the guest */
#else
/* communicate the resize event to the guest */
#endif
}
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));
/*
* Lock the framebuffer, perform the update and lock again
*/
gpFrameBuffer->Lock();
gpFrameBuffer->Unlock();
break;
}
/*
* User specific resize event.
*/
case SDL_USER_EVENT_RESIZE:
{
LogFlow(("SDL_USER_EVENT_RESIZE\n"));
/* notify the display that the resize has been completed */
break;
}
#ifdef __LINUX__
/*
* User specific XPCOM event queue event
*/
{
LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
break;
}
#endif /* __LINUX__ */
/*
* 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;
}
}
}
LogFlow(("leaving...\n"));
#ifdef __LINUX__
/* make sure the XPCOM event queue thread doesn't do anything harmful */
#endif /* __LINUX__ */
#ifdef VBOX_VRDP
if (gVrdpServer)
#endif
/*
* Get the machine state.
*/
if (gMachine)
else
/*
* Turn off the VM if it's running
*/
if ( gConsole
&& machineState == MachineState_Running)
{
consoleCallback->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", rc);
break;
}
}
/*
* 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)
{
}
/* restore the default cursor and free the custom one if any */
if (gpDefaultCursor)
{
#ifdef __LINUX__
#endif /* __LNUX__ */
#ifdef __LINUX__
#endif /* __LINUX__ */
}
if (gpCustomCursor)
{
if (pCustomTempWMCursor)
{
#if defined (__WIN__)
#endif
}
}
LogFlow(("Releasing mouse, keyboard, vrdpserver, display, console...\n"));
gVrdpServer = NULL;
// we can only uninitialize SDL here because it is not threadsafe
if (gpFrameBuffer)
{
LogFlow(("Releasing framebuffer...\n"));
gpFrameBuffer->uninit();
gpFrameBuffer->Release();
}
#ifdef VBOX_SECURELABEL
/* must do this after destructing the framebuffer */
if (gLibrarySDL_ttf)
#endif
LogFlow(("Releasing machine, session...\n"));
LogFlow(("Releasing callback handlers...\n"));
if (callback)
if (consoleCallback)
LogFlow(("Releasing VirtualBox object...\n"));
virtualBox = NULL;
// end "all-stuff" scope
////////////////////////////////////////////////////////////////////////////
}
while (0);
LogFlow(("Uninitializing COM...\n"));
LogFlow(("Returning from main()!\n"));
}
/**
* 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);
}
/**
* Converts an SDL keyboard eventcode to a XT scancode.
*
* @returns XT scancode
* @param ev SDL scancode
*/
{
int keycode;
// start with the scancode determined by SDL
#ifdef __LINUX__
// workaround for SDL keyboard translation issues on Linux
// keycodes > 0x80 are sent as 0xe0 keycode
{
0xc7, /* 97 Home */
0xc8, /* 98 Up */
0xc9, /* 99 PgUp */
0xcb, /* 100 Left */
0x4c, /* 101 KP-5 */
0xcd, /* 102 Right */
0xcf, /* 103 End */
0xd0, /* 104 Down */
0xd1, /* 105 PgDn */
0xd2, /* 106 Ins */
0xd3, /* 107 Del */
0x9c, /* 108 Enter */
0x9d, /* 109 Ctrl-R */
0x0, /* 110 Pause */
0xb7, /* 111 Print */
0xb5, /* 112 Divide */
0xb8, /* 113 Alt-R */
0xc6, /* 114 Break */
0xdb, /* 115 Win Left */
0xdc, /* 116 Win Right */
0xdd, /* 117 Win Menu */
0x0, /* 118 */
0x0, /* 119 */
0x70, /* 120 Hiragana_Katakana */
0x0, /* 121 */
0x0, /* 122 */
0x73, /* 123 backslash */
0x0, /* 124 */
0x0, /* 125 */
0x0, /* 126 */
0x0, /* 127 */
0x0, /* 128 */
0x79, /* 129 Henkan */
0x0, /* 130 */
0x7b, /* 131 Muhenkan */
0x0, /* 132 */
0x7d, /* 133 Yen */
0x0, /* 134 */
0x0, /* 135 */
0x47, /* 136 KP_7 */
0x48, /* 137 KP_8 */
0x49, /* 138 KP_9 */
0x4b, /* 139 KP_4 */
0x4c, /* 140 KP_5 */
0x4d, /* 141 KP_6 */
0x4f, /* 142 KP_1 */
0x50, /* 143 KP_2 */
0x51, /* 144 KP_3 */
0x52, /* 145 KP_0 */
0x53, /* 146 KP_. */
0x47, /* 147 KP_HOME */
0x48, /* 148 KP_UP */
0x49, /* 149 KP_PgUp */
0x4b, /* 150 KP_Left */
0x4c, /* 151 KP_ */
0x4d, /* 152 KP_Right */
0x4f, /* 153 KP_End */
0x50, /* 154 KP_Down */
0x51, /* 155 KP_PgDn */
0x52, /* 156 KP_Ins */
0x53, /* 157 KP_Del */
};
if (keycode < 9)
{
keycode = 0;
}
else if (keycode < 97)
{
// just an offset (Xorg MIN_KEYCODE)
keycode -= 8;
}
else if (keycode < 158)
{
// apply conversion table
}
else
{
keycode = 0;
}
#endif
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.
*/
{
#if defined(DEBUG) || defined(VBOX_WITH_STATISTICS)
{
// 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 0x9d: /* Right CTRL */
case 0x38: /* Left ALT */
case 0xb8: /* Right ALT */
{
gaModifiersState[keycode] = 0;
else
break;
}
case 0x45: /* Num Lock */
case 0x3a: /* Caps Lock */
{
/* SDL does not send the key up event, so we generate it.
* r=frank: This is not true for never SDL versions. */
{
}
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 & 0x80)
: keycode & 0x7f);
}
/**
* Start grabbing the mouse.
*/
static void InputGrabStart(void)
{
if (!gfGuestNeedsHostCursor)
// dummy read to avoid moving the mouse
}
/**
* End mouse grabbing.
*/
static void InputGrabEnd(void)
{
if (!gfGuestNeedsHostCursor)
}
/**
* Query mouse position and button state from SDL and send to the VM
*
* @param dz Relative mouse wheel movement
*/
{
bool abs;
/*
* 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, 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."
*/
/* only used if abs == TRUE */
/*
* process buttons
*/
buttons = 0;
if (abs)
{
/*
* 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?
*/
y + 1 - yMin,
}
else
{
}
}
// 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?
*/
y + 1 - yMin,
}
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.
*/
for (;;)
{
BOOL fCompleted = false;
break;
break;
if (cPercentNow != cPercent)
{
}
/* wait */
break;
/// @todo process gui events.
}
/*
* What's the result of the operation?
*/
lrc = ~0;
if (!lrc)
{
RTPrintf("Saved the state successfully.\n");
}
else
}
/**
* Build the titlebar string
*/
{
static char pszTitle[1024] = {0};
/* back up current title */
char pszPrevTitle[1024];
if (name)
else
/* which mode are we in? */
switch (mode)
{
case TITLEBAR_NORMAL:
{
if (machineState == MachineState_Paused)
if (gfGrabbed)
// do we have a debugger interface
if (gMachineDebugger)
{
#if defined(DEBUG) || defined(VBOX_WITH_STATISTICS)
// query the machine state
" [STEP=%d CS=%d PAT=%d RR0=%d RR3=%d LOG=%d HWVirt=%d]",
#else
#endif /* DEBUG */
}
break;
}
case TITLEBAR_STARTUP:
{
/*
* Format it.
*/
if (machineState == MachineState_Starting)
else if (machineState == MachineState_Restoring)
{
" - Restoring %d%%...", (int)cPercentNow);
else
" - Restoring...");
}
/* 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 (__WIN__)
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)
::DeleteObject (hMonoBitmap);
if (hBitmap)
::DeleteObject (hBitmap);
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;
}
}
}
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
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:
{
{
/*
* process because there might be a short moment
* without a valid framebuffer
*/
if (machineState == MachineState_Running)
if (machineState == MachineState_Running)
/*
* screen repaint, just to be sure.
*/
}
break;
}
/*
* Pause / Resume toggle.
*/
case SDLK_p:
{
if (machineState == MachineState_Running)
{
if (gfGrabbed)
InputGrabEnd();
}
else if (machineState == MachineState_Paused)
{
}
break;
}
/*
* Reset the VM
*/
case SDLK_r:
{
ResetVM();
break;
}
/*
* Terminate the VM
*/
case SDLK_q:
{
return VINF_EM_TERMINATE;
break;
}
/*
* Save the machine's state and exit
*/
case SDLK_s:
{
SaveState();
return VINF_EM_TERMINATE;
}
case SDLK_h:
{
if (gConsole)
gConsole->PowerButton();
break;
}
/*
* Perform an online snapshot. Continue operation.
*/
case SDLK_n:
{
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 */
static LONG keySequence[] = {
0x1d, // Ctrl down
0x38, // Alt down
0x00, // Fx down (placeholder)
0x00, // Fx up (placeholder)
0xb8, // Alt up
0x9d // Ctrl up
};
/* put in the right Fx key */
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;
}