[1] | 1 | /** @file
|
---|
| 2 | * VBox frontends: VBoxSDL (simple frontend based on SDL):
|
---|
| 3 | * Main code
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[28800] | 7 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
[1] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 | /*******************************************************************************
|
---|
| 19 | * Header Files *
|
---|
| 20 | *******************************************************************************/
|
---|
| 21 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
| 22 |
|
---|
| 23 | #include <VBox/com/com.h>
|
---|
| 24 | #include <VBox/com/string.h>
|
---|
| 25 | #include <VBox/com/Guid.h>
|
---|
[7379] | 26 | #include <VBox/com/array.h>
|
---|
[1] | 27 | #include <VBox/com/ErrorInfo.h>
|
---|
[20928] | 28 | #include <VBox/com/errorprint.h>
|
---|
[16530] | 29 |
|
---|
[1] | 30 | #include <VBox/com/EventQueue.h>
|
---|
| 31 | #include <VBox/com/VirtualBox.h>
|
---|
| 32 |
|
---|
| 33 | using namespace com;
|
---|
| 34 |
|
---|
[28205] | 35 | #if defined(VBOXSDL_WITH_X11)
|
---|
[29655] | 36 | # include <VBox/VBoxKeyboard.h>
|
---|
| 37 |
|
---|
[4866] | 38 | # include <X11/Xlib.h>
|
---|
| 39 | # include <X11/cursorfont.h> /* for XC_left_ptr */
|
---|
[28205] | 40 | # if !defined(VBOX_WITHOUT_XCURSOR)
|
---|
[4866] | 41 | # include <X11/Xcursor/Xcursor.h>
|
---|
| 42 | # endif
|
---|
[10514] | 43 | # include <unistd.h>
|
---|
[1] | 44 | #endif
|
---|
| 45 |
|
---|
[3667] | 46 | #ifndef RT_OS_DARWIN
|
---|
[2540] | 47 | #include <SDL_syswm.h> /* for SDL_GetWMInfo() */
|
---|
[3667] | 48 | #endif
|
---|
[2540] | 49 |
|
---|
[1] | 50 | #include "VBoxSDL.h"
|
---|
| 51 | #include "Framebuffer.h"
|
---|
| 52 | #include "Helper.h"
|
---|
| 53 |
|
---|
| 54 | #include <VBox/types.h>
|
---|
| 55 | #include <VBox/err.h>
|
---|
| 56 | #include <VBox/param.h>
|
---|
| 57 | #include <VBox/log.h>
|
---|
| 58 | #include <VBox/version.h>
|
---|
[19817] | 59 | #include <VBox/VBoxVideo.h>
|
---|
[33972] | 60 | #include <VBox/com/listeners.h>
|
---|
[11419] | 61 |
|
---|
| 62 | #include <iprt/alloca.h>
|
---|
[14831] | 63 | #include <iprt/asm.h>
|
---|
[11419] | 64 | #include <iprt/assert.h>
|
---|
| 65 | #include <iprt/env.h>
|
---|
[14831] | 66 | #include <iprt/file.h>
|
---|
[11419] | 67 | #include <iprt/ldr.h>
|
---|
[14831] | 68 | #include <iprt/initterm.h>
|
---|
[1] | 69 | #include <iprt/path.h>
|
---|
[14831] | 70 | #include <iprt/process.h>
|
---|
[1] | 71 | #include <iprt/semaphore.h>
|
---|
[11419] | 72 | #include <iprt/string.h>
|
---|
[1] | 73 | #include <iprt/stream.h>
|
---|
| 74 | #include <iprt/uuid.h>
|
---|
| 75 |
|
---|
| 76 | #include <signal.h>
|
---|
| 77 |
|
---|
| 78 | #include <vector>
|
---|
[7379] | 79 | #include <list>
|
---|
[1] | 80 |
|
---|
| 81 | /* Xlib would re-define our enums */
|
---|
| 82 | #undef True
|
---|
| 83 | #undef False
|
---|
| 84 |
|
---|
| 85 | /*******************************************************************************
|
---|
| 86 | * Defined Constants And Macros *
|
---|
| 87 | *******************************************************************************/
|
---|
| 88 | #ifdef VBOX_SECURELABEL
|
---|
| 89 | /** extra data key for the secure label */
|
---|
| 90 | #define VBOXSDL_SECURELABEL_EXTRADATA "VBoxSDL/SecureLabel"
|
---|
| 91 | /** label area height in pixels */
|
---|
| 92 | #define SECURE_LABEL_HEIGHT 20
|
---|
| 93 | #endif
|
---|
| 94 |
|
---|
| 95 | /** Enables the rawr[0|3], patm, and casm options. */
|
---|
| 96 | #define VBOXSDL_ADVANCED_OPTIONS
|
---|
| 97 |
|
---|
| 98 | /*******************************************************************************
|
---|
| 99 | * Structures and Typedefs *
|
---|
| 100 | *******************************************************************************/
|
---|
[33540] | 101 | /** Pointer shape change event data structure */
|
---|
[1] | 102 | struct PointerShapeChangeData
|
---|
| 103 | {
|
---|
[28205] | 104 | PointerShapeChangeData(BOOL aVisible, BOOL aAlpha, ULONG aXHot, ULONG aYHot,
|
---|
[29518] | 105 | ULONG aWidth, ULONG aHeight, ComSafeArrayIn(BYTE,pShape))
|
---|
[28205] | 106 | : visible(aVisible), alpha(aAlpha), xHot(aXHot), yHot(aYHot),
|
---|
[29518] | 107 | width(aWidth), height(aHeight)
|
---|
[1] | 108 | {
|
---|
| 109 | // make a copy of the shape
|
---|
[34645] | 110 | com::SafeArray<BYTE> aShape(ComSafeArrayInArg(pShape));
|
---|
[29518] | 111 | size_t cbShapeSize = aShape.size();
|
---|
[29542] | 112 | if (cbShapeSize > 0)
|
---|
| 113 | {
|
---|
| 114 | shape.resize(cbShapeSize);
|
---|
| 115 | ::memcpy(shape.raw(), aShape.raw(), cbShapeSize);
|
---|
| 116 | }
|
---|
[1] | 117 | }
|
---|
| 118 |
|
---|
| 119 | ~PointerShapeChangeData()
|
---|
| 120 | {
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | const BOOL visible;
|
---|
| 124 | const BOOL alpha;
|
---|
| 125 | const ULONG xHot;
|
---|
| 126 | const ULONG yHot;
|
---|
| 127 | const ULONG width;
|
---|
| 128 | const ULONG height;
|
---|
[29518] | 129 | com::SafeArray<BYTE> shape;
|
---|
[1] | 130 | };
|
---|
| 131 |
|
---|
| 132 | enum TitlebarMode
|
---|
| 133 | {
|
---|
| 134 | TITLEBAR_NORMAL = 1,
|
---|
| 135 | TITLEBAR_STARTUP = 2,
|
---|
| 136 | TITLEBAR_SAVE = 3,
|
---|
| 137 | TITLEBAR_SNAPSHOT = 4
|
---|
| 138 | };
|
---|
| 139 |
|
---|
| 140 | /*******************************************************************************
|
---|
| 141 | * Internal Functions *
|
---|
| 142 | *******************************************************************************/
|
---|
| 143 | static bool UseAbsoluteMouse(void);
|
---|
| 144 | static void ResetKeys(void);
|
---|
| 145 | static void ProcessKey(SDL_KeyboardEvent *ev);
|
---|
| 146 | static void InputGrabStart(void);
|
---|
| 147 | static void InputGrabEnd(void);
|
---|
[20433] | 148 | static void SendMouseEvent(VBoxSDLFB *fb, int dz, int button, int down);
|
---|
[1] | 149 | static void UpdateTitlebar(TitlebarMode mode, uint32_t u32User = 0);
|
---|
| 150 | static void SetPointerShape(const PointerShapeChangeData *data);
|
---|
| 151 | static void HandleGuestCapsChanged(void);
|
---|
| 152 | static int HandleHostKey(const SDL_KeyboardEvent *pEv);
|
---|
| 153 | static Uint32 StartupTimer(Uint32 interval, void *param);
|
---|
[522] | 154 | static Uint32 ResizeTimer(Uint32 interval, void *param);
|
---|
[6852] | 155 | static Uint32 QuitTimer(Uint32 interval, void *param);
|
---|
[3289] | 156 | static int WaitSDLEvent(SDL_Event *event);
|
---|
[10675] | 157 | static void SetFullscreen(bool enable);
|
---|
[20433] | 158 | #ifdef VBOX_WITH_SDL13
|
---|
| 159 | static VBoxSDLFB * getFbFromWinId(SDL_WindowID id);
|
---|
| 160 | #endif
|
---|
[1] | 161 |
|
---|
| 162 |
|
---|
| 163 | /*******************************************************************************
|
---|
| 164 | * Global Variables *
|
---|
| 165 | *******************************************************************************/
|
---|
| 166 | static int gHostKeyMod = KMOD_RCTRL;
|
---|
| 167 | static int gHostKeySym1 = SDLK_RCTRL;
|
---|
| 168 | static int gHostKeySym2 = SDLK_UNKNOWN;
|
---|
[10434] | 169 | static const char *gHostKeyDisabledCombinations = "";
|
---|
[10501] | 170 | static const char *gpszPidFile;
|
---|
[1] | 171 | static BOOL gfGrabbed = FALSE;
|
---|
| 172 | static BOOL gfGrabOnMouseClick = TRUE;
|
---|
[10675] | 173 | static BOOL gfFullscreenResize = FALSE;
|
---|
| 174 | static BOOL gfIgnoreNextResize = FALSE;
|
---|
[1] | 175 | static BOOL gfAllowFullscreenToggle = TRUE;
|
---|
| 176 | static BOOL gfAbsoluteMouseHost = FALSE;
|
---|
| 177 | static BOOL gfAbsoluteMouseGuest = FALSE;
|
---|
[26782] | 178 | static BOOL gfRelativeMouseGuest = TRUE;
|
---|
[1] | 179 | static BOOL gfGuestNeedsHostCursor = FALSE;
|
---|
| 180 | static BOOL gfOffCursorActive = FALSE;
|
---|
| 181 | static BOOL gfGuestNumLockPressed = FALSE;
|
---|
| 182 | static BOOL gfGuestCapsLockPressed = FALSE;
|
---|
| 183 | static BOOL gfGuestScrollLockPressed = FALSE;
|
---|
[6437] | 184 | static BOOL gfACPITerm = FALSE;
|
---|
[20433] | 185 | static BOOL gfXCursorEnabled = FALSE;
|
---|
[315] | 186 | static int gcGuestNumLockAdaptions = 2;
|
---|
| 187 | static int gcGuestCapsLockAdaptions = 2;
|
---|
[10675] | 188 | static uint32_t gmGuestNormalXRes;
|
---|
| 189 | static uint32_t gmGuestNormalYRes;
|
---|
[1] | 190 |
|
---|
| 191 | /** modifier keypress status (scancode as index) */
|
---|
| 192 | static uint8_t gaModifiersState[256];
|
---|
| 193 |
|
---|
[34645] | 194 | static ComPtr<IMachine> gpMachine;
|
---|
| 195 | static ComPtr<IConsole> gpConsole;
|
---|
| 196 | static ComPtr<IMachineDebugger> gpMachineDebugger;
|
---|
| 197 | static ComPtr<IKeyboard> gpKeyboard;
|
---|
| 198 | static ComPtr<IMouse> gpMouse;
|
---|
| 199 | static ComPtr<IDisplay> gpDisplay;
|
---|
| 200 | static ComPtr<IVRDEServer> gpVRDEServer;
|
---|
| 201 | static ComPtr<IProgress> gpProgress;
|
---|
[1] | 202 |
|
---|
[20435] | 203 | static ULONG gcMonitors = 1;
|
---|
[20433] | 204 | static VBoxSDLFB *gpFramebuffer[64];
|
---|
[1] | 205 | static SDL_Cursor *gpDefaultCursor = NULL;
|
---|
[4637] | 206 | #ifdef VBOXSDL_WITH_X11
|
---|
[1] | 207 | static Cursor gpDefaultOrigX11Cursor;
|
---|
| 208 | #endif
|
---|
| 209 | static SDL_Cursor *gpCustomCursor = NULL;
|
---|
[20433] | 210 | #ifndef VBOX_WITH_SDL13
|
---|
[1] | 211 | static WMcursor *gpCustomOrigWMcursor = NULL;
|
---|
[20433] | 212 | #endif
|
---|
[1] | 213 | static SDL_Cursor *gpOffCursor = NULL;
|
---|
[522] | 214 | static SDL_TimerID gSdlResizeTimer = NULL;
|
---|
[6852] | 215 | static SDL_TimerID gSdlQuitTimer = NULL;
|
---|
[1] | 216 |
|
---|
[20433] | 217 | #if defined(VBOXSDL_WITH_X11) && !defined(VBOX_WITH_SDL13)
|
---|
[1] | 218 | static SDL_SysWMinfo gSdlInfo;
|
---|
| 219 | #endif
|
---|
| 220 |
|
---|
| 221 | #ifdef VBOX_SECURELABEL
|
---|
[3669] | 222 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 223 | #define LIBSDL_TTF_NAME "SDL_ttf"
|
---|
| 224 | #else
|
---|
[5815] | 225 | #define LIBSDL_TTF_NAME "libSDL_ttf-2.0.so.0"
|
---|
[1] | 226 | #endif
|
---|
| 227 | RTLDRMOD gLibrarySDL_ttf = NIL_RTLDRMOD;
|
---|
| 228 | #endif
|
---|
| 229 |
|
---|
[3289] | 230 | static RTSEMEVENT g_EventSemSDLEvents;
|
---|
| 231 | static volatile int32_t g_cNotifyUpdateEventsPending;
|
---|
| 232 |
|
---|
[1] | 233 | /**
|
---|
[34646] | 234 | * Event handler for VirtualBoxClient events
|
---|
| 235 | */
|
---|
| 236 | class VBoxSDLClientEventListener
|
---|
| 237 | {
|
---|
| 238 | public:
|
---|
| 239 | VBoxSDLClientEventListener()
|
---|
| 240 | {
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | virtual ~VBoxSDLClientEventListener()
|
---|
| 244 | {
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
|
---|
| 248 | {
|
---|
| 249 | switch (aType)
|
---|
| 250 | {
|
---|
[35172] | 251 | case VBoxEventType_OnVBoxSVCAvailabilityChanged:
|
---|
[34646] | 252 | {
|
---|
[35172] | 253 | ComPtr<IVBoxSVCAvailabilityChangedEvent> pVSACEv = aEvent;
|
---|
| 254 | Assert(pVSACEv);
|
---|
| 255 | BOOL fAvailable = FALSE;
|
---|
| 256 | pVSACEv->COMGETTER(Available)(&fAvailable);
|
---|
| 257 | if (!fAvailable)
|
---|
| 258 | {
|
---|
| 259 | LogRel(("VBoxSDL: VBoxSVC became unavailable, exiting.\n"));
|
---|
| 260 | RTPrintf("VBoxSVC became unavailable, exiting.\n");
|
---|
| 261 | /* Send QUIT event to terminate the VM as cleanly as possible
|
---|
| 262 | * given that VBoxSVC is no longer present. */
|
---|
| 263 | SDL_Event event = {0};
|
---|
| 264 | event.type = SDL_QUIT;
|
---|
| 265 | PushSDLEventForSure(&event);
|
---|
| 266 | }
|
---|
[34646] | 267 | break;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | default:
|
---|
| 271 | AssertFailed();
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | return S_OK;
|
---|
| 275 | }
|
---|
| 276 | };
|
---|
| 277 |
|
---|
| 278 | /**
|
---|
[34645] | 279 | * Event handler for VirtualBox (server) events
|
---|
[1] | 280 | */
|
---|
[33963] | 281 | class VBoxSDLEventListener
|
---|
[1] | 282 | {
|
---|
| 283 | public:
|
---|
[30618] | 284 | VBoxSDLEventListener()
|
---|
[1] | 285 | {
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[30618] | 288 | virtual ~VBoxSDLEventListener()
|
---|
[1] | 289 | {
|
---|
| 290 | }
|
---|
| 291 |
|
---|
[33963] | 292 | STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
|
---|
[1] | 293 | {
|
---|
[30618] | 294 | switch (aType)
|
---|
[1] | 295 | {
|
---|
[30871] | 296 | case VBoxEventType_OnExtraDataChanged:
|
---|
[1] | 297 | {
|
---|
[30618] | 298 | #ifdef VBOX_SECURELABEL
|
---|
[34645] | 299 | ComPtr<IExtraDataChangedEvent> pEDCEv = aEvent;
|
---|
| 300 | Assert(pEDCEv);
|
---|
| 301 | Bstr bstrMachineId;
|
---|
| 302 | pEDCEv->COMGETTER(MachineId)(bstrMachineId.asOutParam());
|
---|
| 303 | if (gpMachine)
|
---|
[2729] | 304 | {
|
---|
| 305 | /*
|
---|
[30618] | 306 | * check if we're interested in the message
|
---|
[2729] | 307 | */
|
---|
[34645] | 308 | Bstr bstrOurId;
|
---|
| 309 | gpMachine->COMGETTER(Id)(bstrOurId.asOutParam());
|
---|
| 310 | if (bstrOurId == bstrMachineId)
|
---|
[30618] | 311 | {
|
---|
[34645] | 312 | Bstr bstrKey;
|
---|
| 313 | pEDCEv->COMGETTER(Key)(bstrKey.asOutParam());
|
---|
| 314 | if (bstrKey == VBOXSDL_SECURELABEL_EXTRADATA)
|
---|
[30618] | 315 | {
|
---|
| 316 | /*
|
---|
| 317 | * Notify SDL thread of the string update
|
---|
| 318 | */
|
---|
| 319 | SDL_Event event = {0};
|
---|
| 320 | event.type = SDL_USEREVENT;
|
---|
| 321 | event.user.type = SDL_USER_EVENT_SECURELABEL_UPDATE;
|
---|
| 322 | PushSDLEventForSure(&event);
|
---|
| 323 | }
|
---|
| 324 | }
|
---|
[2729] | 325 | }
|
---|
[30618] | 326 | #endif
|
---|
| 327 | break;
|
---|
[1] | 328 | }
|
---|
[34645] | 329 |
|
---|
[30618] | 330 | default:
|
---|
| 331 | AssertFailed();
|
---|
[1] | 332 | }
|
---|
[30618] | 333 |
|
---|
[28931] | 334 | return S_OK;
|
---|
[1] | 335 | }
|
---|
| 336 | };
|
---|
| 337 |
|
---|
| 338 | /**
|
---|
[34645] | 339 | * Event handler for Console events
|
---|
[1] | 340 | */
|
---|
[33963] | 341 | class VBoxSDLConsoleEventListener
|
---|
[1] | 342 | {
|
---|
| 343 | public:
|
---|
[30618] | 344 | VBoxSDLConsoleEventListener() : m_fIgnorePowerOffEvents(false)
|
---|
[1] | 345 | {
|
---|
| 346 | }
|
---|
| 347 |
|
---|
[30618] | 348 | virtual ~VBoxSDLConsoleEventListener()
|
---|
[1] | 349 | {
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[33963] | 352 | STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
|
---|
[1] | 353 | {
|
---|
[30618] | 354 | // likely all this double copy is now excessive, and we can just use existing event object
|
---|
| 355 | // @todo: eliminate it
|
---|
| 356 | switch (aType)
|
---|
| 357 | {
|
---|
[30871] | 358 | case VBoxEventType_OnMousePointerShapeChanged:
|
---|
[30618] | 359 | {
|
---|
[34645] | 360 | ComPtr<IMousePointerShapeChangedEvent> pMPSCEv = aEvent;
|
---|
| 361 | Assert(pMPSCEv);
|
---|
[30618] | 362 | PointerShapeChangeData *data;
|
---|
| 363 | BOOL visible, alpha;
|
---|
| 364 | ULONG xHot, yHot, width, height;
|
---|
[34645] | 365 | com::SafeArray<BYTE> shape;
|
---|
[1] | 366 |
|
---|
[34645] | 367 | pMPSCEv->COMGETTER(Visible)(&visible);
|
---|
| 368 | pMPSCEv->COMGETTER(Alpha)(&alpha);
|
---|
| 369 | pMPSCEv->COMGETTER(Xhot)(&xHot);
|
---|
| 370 | pMPSCEv->COMGETTER(Yhot)(&yHot);
|
---|
| 371 | pMPSCEv->COMGETTER(Width)(&width);
|
---|
| 372 | pMPSCEv->COMGETTER(Height)(&height);
|
---|
| 373 | pMPSCEv->COMGETTER(Shape)(ComSafeArrayAsOutParam(shape));
|
---|
[30618] | 374 | data = new PointerShapeChangeData(visible, alpha, xHot, yHot, width, height,
|
---|
| 375 | ComSafeArrayAsInParam(shape));
|
---|
| 376 | Assert(data);
|
---|
| 377 | if (!data)
|
---|
| 378 | break;
|
---|
[1] | 379 |
|
---|
[30618] | 380 | SDL_Event event = {0};
|
---|
| 381 | event.type = SDL_USEREVENT;
|
---|
| 382 | event.user.type = SDL_USER_EVENT_POINTER_CHANGE;
|
---|
| 383 | event.user.data1 = data;
|
---|
[1] | 384 |
|
---|
[30618] | 385 | int rc = PushSDLEventForSure(&event);
|
---|
| 386 | if (rc)
|
---|
| 387 | delete data;
|
---|
[1] | 388 |
|
---|
[30618] | 389 | break;
|
---|
| 390 | }
|
---|
[30871] | 391 | case VBoxEventType_OnMouseCapabilityChanged:
|
---|
[30618] | 392 | {
|
---|
[34645] | 393 | ComPtr<IMouseCapabilityChangedEvent> pMCCEv = aEvent;
|
---|
| 394 | Assert(pMCCEv);
|
---|
| 395 | pMCCEv->COMGETTER(SupportsAbsolute)(&gfAbsoluteMouseGuest);
|
---|
| 396 | pMCCEv->COMGETTER(SupportsRelative)(&gfRelativeMouseGuest);
|
---|
| 397 | pMCCEv->COMGETTER(NeedsHostCursor)(&gfGuestNeedsHostCursor);
|
---|
[30618] | 398 | SDL_Event event = {0};
|
---|
| 399 | event.type = SDL_USEREVENT;
|
---|
| 400 | event.user.type = SDL_USER_EVENT_GUEST_CAP_CHANGED;
|
---|
[1] | 401 |
|
---|
[30618] | 402 | PushSDLEventForSure(&event);
|
---|
| 403 | break;
|
---|
| 404 | }
|
---|
[30871] | 405 | case VBoxEventType_OnKeyboardLedsChanged:
|
---|
[30618] | 406 | {
|
---|
[34645] | 407 | ComPtr<IKeyboardLedsChangedEvent> pCLCEv = aEvent;
|
---|
| 408 | Assert(pCLCEv);
|
---|
[30618] | 409 | BOOL fNumLock, fCapsLock, fScrollLock;
|
---|
[34645] | 410 | pCLCEv->COMGETTER(NumLock)(&fNumLock);
|
---|
| 411 | pCLCEv->COMGETTER(CapsLock)(&fCapsLock);
|
---|
| 412 | pCLCEv->COMGETTER(ScrollLock)(&fScrollLock);
|
---|
[30618] | 413 | /* Don't bother the guest with NumLock scancodes if he doesn't set the NumLock LED */
|
---|
| 414 | if (gfGuestNumLockPressed != fNumLock)
|
---|
| 415 | gcGuestNumLockAdaptions = 2;
|
---|
| 416 | if (gfGuestCapsLockPressed != fCapsLock)
|
---|
| 417 | gcGuestCapsLockAdaptions = 2;
|
---|
| 418 | gfGuestNumLockPressed = fNumLock;
|
---|
| 419 | gfGuestCapsLockPressed = fCapsLock;
|
---|
| 420 | gfGuestScrollLockPressed = fScrollLock;
|
---|
| 421 | break;
|
---|
| 422 | }
|
---|
[1] | 423 |
|
---|
[30871] | 424 | case VBoxEventType_OnStateChanged:
|
---|
[30618] | 425 | {
|
---|
[34645] | 426 | ComPtr<IStateChangedEvent> pSCEv = aEvent;
|
---|
| 427 | Assert(pSCEv);
|
---|
[30618] | 428 | MachineState_T machineState;
|
---|
[34645] | 429 | pSCEv->COMGETTER(State)(&machineState);
|
---|
[30618] | 430 | LogFlow(("OnStateChange: machineState = %d (%s)\n", machineState, GetStateName(machineState)));
|
---|
| 431 | SDL_Event event = {0};
|
---|
[4131] | 432 |
|
---|
[30618] | 433 | if ( machineState == MachineState_Aborted
|
---|
| 434 | || machineState == MachineState_Teleported
|
---|
| 435 | || (machineState == MachineState_Saved && !m_fIgnorePowerOffEvents)
|
---|
| 436 | || (machineState == MachineState_PoweredOff && !m_fIgnorePowerOffEvents)
|
---|
| 437 | )
|
---|
| 438 | {
|
---|
| 439 | /*
|
---|
| 440 | * We have to inform the SDL thread that the application has be terminated
|
---|
| 441 | */
|
---|
| 442 | event.type = SDL_USEREVENT;
|
---|
| 443 | event.user.type = SDL_USER_EVENT_TERMINATE;
|
---|
| 444 | event.user.code = machineState == MachineState_Aborted
|
---|
[24301] | 445 | ? VBOXSDL_TERM_ABEND
|
---|
| 446 | : VBOXSDL_TERM_NORMAL;
|
---|
[30618] | 447 | }
|
---|
| 448 | else
|
---|
| 449 | {
|
---|
| 450 | /*
|
---|
| 451 | * Inform the SDL thread to refresh the titlebar
|
---|
| 452 | */
|
---|
| 453 | event.type = SDL_USEREVENT;
|
---|
| 454 | event.user.type = SDL_USER_EVENT_UPDATE_TITLEBAR;
|
---|
| 455 | }
|
---|
[1] | 456 |
|
---|
[30618] | 457 | PushSDLEventForSure(&event);
|
---|
| 458 | break;
|
---|
| 459 | }
|
---|
[1] | 460 |
|
---|
[30618] | 461 | case VBoxEventType_OnRuntimeError:
|
---|
| 462 | {
|
---|
[34645] | 463 | ComPtr<IRuntimeErrorEvent> pRTEEv = aEvent;
|
---|
| 464 | Assert(pRTEEv);
|
---|
[30618] | 465 | BOOL fFatal;
|
---|
[1] | 466 |
|
---|
[34645] | 467 | pRTEEv->COMGETTER(Fatal)(&fFatal);
|
---|
[30618] | 468 | MachineState_T machineState;
|
---|
[34645] | 469 | gpMachine->COMGETTER(State)(&machineState);
|
---|
[30618] | 470 | const char *pszType;
|
---|
| 471 | bool fPaused = machineState == MachineState_Paused;
|
---|
| 472 | if (fFatal)
|
---|
| 473 | pszType = "FATAL ERROR";
|
---|
| 474 | else if (machineState == MachineState_Paused)
|
---|
| 475 | pszType = "Non-fatal ERROR";
|
---|
| 476 | else
|
---|
| 477 | pszType = "WARNING";
|
---|
[34645] | 478 | Bstr bstrId, bstrMessage;
|
---|
| 479 | pRTEEv->COMGETTER(Id)(bstrId.asOutParam());
|
---|
| 480 | pRTEEv->COMGETTER(Message)(bstrMessage.asOutParam());
|
---|
| 481 | RTPrintf("\n%s: ** %lS **\n%lS\n%s\n", pszType, bstrId.raw(), bstrMessage.raw(),
|
---|
[30618] | 482 | fPaused ? "The VM was paused. Continue with HostKey + P after you solved the problem.\n" : "");
|
---|
| 483 | break;
|
---|
| 484 | }
|
---|
[4131] | 485 |
|
---|
[30618] | 486 | case VBoxEventType_OnCanShowWindow:
|
---|
| 487 | {
|
---|
[34645] | 488 | ComPtr<ICanShowWindowEvent> pCSWEv = aEvent;
|
---|
| 489 | Assert(pCSWEv);
|
---|
[3667] | 490 | #ifdef RT_OS_DARWIN
|
---|
[30618] | 491 | /* SDL feature not available on Quartz */
|
---|
[3667] | 492 | #else
|
---|
[30618] | 493 | SDL_SysWMinfo info;
|
---|
| 494 | SDL_VERSION(&info.version);
|
---|
| 495 | if (!SDL_GetWMInfo(&info))
|
---|
[34645] | 496 | pCSWEv->AddVeto(NULL);
|
---|
[3667] | 497 | #endif
|
---|
[30618] | 498 | break;
|
---|
| 499 | }
|
---|
[2463] | 500 |
|
---|
[30618] | 501 | case VBoxEventType_OnShowWindow:
|
---|
| 502 | {
|
---|
[34645] | 503 | ComPtr<IShowWindowEvent> pSWEv = aEvent;
|
---|
| 504 | Assert(pSWEv);
|
---|
[3667] | 505 | #ifndef RT_OS_DARWIN
|
---|
[30618] | 506 | SDL_SysWMinfo info;
|
---|
| 507 | SDL_VERSION(&info.version);
|
---|
| 508 | if (SDL_GetWMInfo(&info))
|
---|
| 509 | {
|
---|
[28205] | 510 | #if defined(VBOXSDL_WITH_X11)
|
---|
[34645] | 511 | pSWEv->COMSETTER(WinId)((LONG64)info.info.x11.wmwindow);
|
---|
[28205] | 512 | #elif defined(RT_OS_WINDOWS)
|
---|
[34645] | 513 | pSWEv->COMSETTER(WinId)((LONG64)info.window);
|
---|
[2540] | 514 | #else
|
---|
[30618] | 515 | AssertFailed();
|
---|
[2540] | 516 | #endif
|
---|
[30618] | 517 | }
|
---|
| 518 | #endif /* !RT_OS_DARWIN */
|
---|
| 519 | break;
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | default:
|
---|
| 523 | AssertFailed();
|
---|
[2540] | 524 | }
|
---|
[30618] | 525 | return S_OK;
|
---|
[2463] | 526 | }
|
---|
| 527 |
|
---|
[1] | 528 | static const char *GetStateName(MachineState_T machineState)
|
---|
| 529 | {
|
---|
| 530 | switch (machineState)
|
---|
| 531 | {
|
---|
[23879] | 532 | case MachineState_Null: return "<null>";
|
---|
| 533 | case MachineState_PoweredOff: return "PoweredOff";
|
---|
| 534 | case MachineState_Saved: return "Saved";
|
---|
[24301] | 535 | case MachineState_Teleported: return "Teleported";
|
---|
[23879] | 536 | case MachineState_Aborted: return "Aborted";
|
---|
| 537 | case MachineState_Running: return "Running";
|
---|
[24301] | 538 | case MachineState_Teleporting: return "Teleporting";
|
---|
| 539 | case MachineState_LiveSnapshotting: return "LiveSnapshotting";
|
---|
[23879] | 540 | case MachineState_Paused: return "Paused";
|
---|
| 541 | case MachineState_Stuck: return "GuruMeditation";
|
---|
| 542 | case MachineState_Starting: return "Starting";
|
---|
| 543 | case MachineState_Stopping: return "Stopping";
|
---|
| 544 | case MachineState_Saving: return "Saving";
|
---|
| 545 | case MachineState_Restoring: return "Restoring";
|
---|
[24301] | 546 | case MachineState_TeleportingPausedVM: return "TeleportingPausedVM";
|
---|
| 547 | case MachineState_TeleportingIn: return "TeleportingIn";
|
---|
[23879] | 548 | case MachineState_RestoringSnapshot: return "RestoringSnapshot";
|
---|
| 549 | case MachineState_DeletingSnapshot: return "DeletingSnapshot";
|
---|
| 550 | case MachineState_SettingUp: return "SettingUp";
|
---|
| 551 | default: return "no idea";
|
---|
[1] | 552 | }
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | void ignorePowerOffEvents(bool fIgnore)
|
---|
| 556 | {
|
---|
| 557 | m_fIgnorePowerOffEvents = fIgnore;
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | private:
|
---|
| 561 | bool m_fIgnorePowerOffEvents;
|
---|
| 562 | };
|
---|
| 563 |
|
---|
[34646] | 564 | typedef ListenerImpl<VBoxSDLClientEventListener> VBoxSDLClientEventListenerImpl;
|
---|
[33968] | 565 | typedef ListenerImpl<VBoxSDLEventListener> VBoxSDLEventListenerImpl;
|
---|
| 566 | typedef ListenerImpl<VBoxSDLConsoleEventListener> VBoxSDLConsoleEventListenerImpl;
|
---|
[1] | 567 |
|
---|
| 568 | static void show_usage()
|
---|
| 569 | {
|
---|
| 570 | RTPrintf("Usage:\n"
|
---|
[18751] | 571 | " --startvm <uuid|name> Virtual machine to start, either UUID or name\n"
|
---|
| 572 | " --hda <file> Set temporary first hard disk to file\n"
|
---|
| 573 | " --fda <file> Set temporary first floppy disk to file\n"
|
---|
| 574 | " --cdrom <file> Set temporary CDROM/DVD to file/device ('none' to unmount)\n"
|
---|
| 575 | " --boot <a|c|d|n> Set temporary boot device (a = floppy, c = 1st HD, d = DVD, n = network)\n"
|
---|
| 576 | " --memory <size> Set temporary memory size in megabytes\n"
|
---|
| 577 | " --vram <size> Set temporary size of video memory in megabytes\n"
|
---|
| 578 | " --fullscreen Start VM in fullscreen mode\n"
|
---|
| 579 | " --fullscreenresize Resize the guest on fullscreen\n"
|
---|
| 580 | " --fixedmode <w> <h> <bpp> Use a fixed SDL video mode with given width, height and bits per pixel\n"
|
---|
| 581 | " --nofstoggle Forbid switching to/from fullscreen mode\n"
|
---|
| 582 | " --noresize Make the SDL frame non resizable\n"
|
---|
| 583 | " --nohostkey Disable all hostkey combinations\n"
|
---|
| 584 | " --nohostkeys ... Disable specific hostkey combinations, see below for valid keys\n"
|
---|
| 585 | " --nograbonclick Disable mouse/keyboard grabbing on mouse click w/o additions\n"
|
---|
| 586 | " --detecthostkey Get the hostkey identifier and modifier state\n"
|
---|
| 587 | " --hostkey <key> {<key2>} <mod> Set the host key to the values obtained using --detecthostkey\n"
|
---|
| 588 | " --termacpi Send an ACPI power button event when closing the window\n"
|
---|
[23998] | 589 | " --vrdp <ports> Listen for VRDP connections on one of specified ports (default if not specified)\n"
|
---|
[18751] | 590 | " --discardstate Discard saved state (if present) and revert to last snapshot (if present)\n"
|
---|
[1] | 591 | #ifdef VBOX_SECURELABEL
|
---|
[18751] | 592 | " --securelabel Display a secure VM label at the top of the screen\n"
|
---|
| 593 | " --seclabelfnt TrueType (.ttf) font file for secure session label\n"
|
---|
| 594 | " --seclabelsiz Font point size for secure session label (default 12)\n"
|
---|
| 595 | " --seclabelofs Font offset within the secure label (default 0)\n"
|
---|
| 596 | " --seclabelfgcol <rgb> Secure label text color RGB value in 6 digit hexadecimal (eg: FFFF00)\n"
|
---|
| 597 | " --seclabelbgcol <rgb> Secure label background color RGB value in 6 digit hexadecimal (eg: FF0000)\n"
|
---|
[1] | 598 | #endif
|
---|
| 599 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
[18751] | 600 | " --[no]rawr0 Enable or disable raw ring 3\n"
|
---|
| 601 | " --[no]rawr3 Enable or disable raw ring 0\n"
|
---|
| 602 | " --[no]patm Enable or disable PATM\n"
|
---|
| 603 | " --[no]csam Enable or disable CSAM\n"
|
---|
| 604 | " --[no]hwvirtex Permit or deny the usage of VT-x/AMD-V\n"
|
---|
[1] | 605 | #endif
|
---|
[5084] | 606 | "\n"
|
---|
| 607 | "Key bindings:\n"
|
---|
| 608 | " <hostkey> + f Switch to full screen / restore to previous view\n"
|
---|
| 609 | " h Press ACPI power button\n"
|
---|
| 610 | " n Take a snapshot and continue execution\n"
|
---|
| 611 | " p Pause / resume execution\n"
|
---|
| 612 | " q Power off\n"
|
---|
| 613 | " r VM reset\n"
|
---|
| 614 | " s Save state and power off\n"
|
---|
| 615 | " <del> Send <ctrl><alt><del>\n"
|
---|
| 616 | " <F1>...<F12> Send <ctrl><alt><Fx>\n"
|
---|
[8834] | 617 | #if defined(DEBUG) || defined(VBOX_WITH_STATISTICS)
|
---|
| 618 | "\n"
|
---|
| 619 | "Further key bindings useful for debugging:\n"
|
---|
| 620 | " LCtrl + Alt + F12 Reset statistics counter\n"
|
---|
| 621 | " LCtrl + Alt + F11 Dump statistics to logfile\n"
|
---|
| 622 | " Alt + F12 Toggle R0 recompiler\n"
|
---|
| 623 | " Alt + F11 Toggle R3 recompiler\n"
|
---|
| 624 | " Alt + F10 Toggle PATM\n"
|
---|
| 625 | " Alt + F9 Toggle CSAM\n"
|
---|
| 626 | " Alt + F8 Toggle single step mode\n"
|
---|
| 627 | " LCtrl/RCtrl + F12 Toggle logger\n"
|
---|
| 628 | " F12 Write log marker to logfile\n"
|
---|
| 629 | #endif
|
---|
[1] | 630 | "\n");
|
---|
| 631 | }
|
---|
| 632 |
|
---|
[15051] | 633 | static void PrintError(const char *pszName, CBSTR pwszDescr, CBSTR pwszComponent=NULL)
|
---|
[1] | 634 | {
|
---|
| 635 | const char *pszFile, *pszFunc, *pszStat;
|
---|
| 636 | char pszBuffer[1024];
|
---|
| 637 | com::ErrorInfo info;
|
---|
| 638 |
|
---|
| 639 | RTStrPrintf(pszBuffer, sizeof(pszBuffer), "%lS", pwszDescr);
|
---|
| 640 |
|
---|
| 641 | RTPrintf("\n%s! Error info:\n", pszName);
|
---|
| 642 | if ( (pszFile = strstr(pszBuffer, "At '"))
|
---|
| 643 | && (pszFunc = strstr(pszBuffer, ") in "))
|
---|
| 644 | && (pszStat = strstr(pszBuffer, "VBox status code: ")))
|
---|
| 645 | RTPrintf(" %.*s %.*s\n In%.*s %s",
|
---|
| 646 | pszFile-pszBuffer, pszBuffer,
|
---|
| 647 | pszFunc-pszFile+1, pszFile,
|
---|
| 648 | pszStat-pszFunc-4, pszFunc+4,
|
---|
| 649 | pszStat);
|
---|
| 650 | else
|
---|
| 651 | RTPrintf("%s\n", pszBuffer);
|
---|
| 652 |
|
---|
| 653 | if (pwszComponent)
|
---|
| 654 | RTPrintf("(component %lS).\n", pwszComponent);
|
---|
| 655 |
|
---|
| 656 | RTPrintf("\n");
|
---|
| 657 | }
|
---|
| 658 |
|
---|
[4637] | 659 | #ifdef VBOXSDL_WITH_X11
|
---|
[1] | 660 | /**
|
---|
| 661 | * Custom signal handler. Currently it is only used to release modifier
|
---|
| 662 | * keys when receiving the USR1 signal. When switching VTs, we might not
|
---|
| 663 | * get release events for Ctrl-Alt and in case a savestate is performed
|
---|
| 664 | * on the new VT, the VM will be saved with modifier keys stuck. This is
|
---|
| 665 | * annoying enough for introducing this hack.
|
---|
| 666 | */
|
---|
[10501] | 667 | void signal_handler_SIGUSR1(int sig, siginfo_t *info, void *secret)
|
---|
[1] | 668 | {
|
---|
| 669 | /* only SIGUSR1 is interesting */
|
---|
| 670 | if (sig == SIGUSR1)
|
---|
| 671 | {
|
---|
| 672 | /* just release the modifiers */
|
---|
| 673 | ResetKeys();
|
---|
| 674 | }
|
---|
| 675 | }
|
---|
[10501] | 676 |
|
---|
| 677 | /**
|
---|
| 678 | * Custom signal handler for catching exit events.
|
---|
| 679 | */
|
---|
| 680 | void signal_handler_SIGINT(int sig)
|
---|
| 681 | {
|
---|
| 682 | if (gpszPidFile)
|
---|
| 683 | RTFileDelete(gpszPidFile);
|
---|
| 684 | signal(SIGINT, SIG_DFL);
|
---|
| 685 | signal(SIGQUIT, SIG_DFL);
|
---|
| 686 | signal(SIGSEGV, SIG_DFL);
|
---|
| 687 | kill(getpid(), sig);
|
---|
| 688 | }
|
---|
[4637] | 689 | #endif /* VBOXSDL_WITH_X11 */
|
---|
[1] | 690 |
|
---|
| 691 | /** entry point */
|
---|
[11725] | 692 | extern "C"
|
---|
| 693 | DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
|
---|
[1] | 694 | {
|
---|
[4637] | 695 | #ifdef VBOXSDL_WITH_X11
|
---|
[1] | 696 | /*
|
---|
[3098] | 697 | * Lock keys on SDL behave different from normal keys: A KeyPress event is generated
|
---|
[33540] | 698 | * if the lock mode gets active and a keyRelease event is generated if the lock mode
|
---|
[3098] | 699 | * gets inactive, that is KeyPress and KeyRelease are sent when pressing the lock key
|
---|
| 700 | * to change the mode. The current lock mode is reflected in SDL_GetModState().
|
---|
| 701 | *
|
---|
| 702 | * Debian patched libSDL to make the lock keys behave like normal keys generating a
|
---|
| 703 | * KeyPress/KeyRelease event if the lock key was pressed/released. But the lock status
|
---|
| 704 | * is not reflected in the mod status anymore. We disable the Debian-specific extension
|
---|
| 705 | * to ensure a defined environment and work around the missing KeyPress/KeyRelease
|
---|
| 706 | * events in ProcessKeys().
|
---|
| 707 | */
|
---|
[11419] | 708 | RTEnvSet("SDL_DISABLE_LOCK_KEYS", "1");
|
---|
[3098] | 709 | #endif
|
---|
| 710 |
|
---|
| 711 | /*
|
---|
[1] | 712 | * the hostkey detection mode is unrelated to VM processing, so handle it before
|
---|
| 713 | * we initialize anything COM related
|
---|
| 714 | */
|
---|
[18751] | 715 | if (argc == 2 && ( !strcmp(argv[1], "-detecthostkey")
|
---|
| 716 | || !strcmp(argv[1], "--detecthostkey")))
|
---|
[1] | 717 | {
|
---|
| 718 | int rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
|
---|
| 719 | if (rc != 0)
|
---|
| 720 | {
|
---|
| 721 | RTPrintf("Error: SDL_InitSubSystem failed with message '%s'\n", SDL_GetError());
|
---|
| 722 | return 1;
|
---|
| 723 | }
|
---|
| 724 | /* we need a video window for the keyboard stuff to work */
|
---|
| 725 | if (!SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE))
|
---|
| 726 | {
|
---|
| 727 | RTPrintf("Error: could not set SDL video mode\n");
|
---|
| 728 | return 1;
|
---|
| 729 | }
|
---|
| 730 |
|
---|
[18751] | 731 | RTPrintf("Please hit one or two function key(s) to get the --hostkey value...\n");
|
---|
[1] | 732 |
|
---|
| 733 | SDL_Event event1;
|
---|
| 734 | while (SDL_WaitEvent(&event1))
|
---|
| 735 | {
|
---|
| 736 | if (event1.type == SDL_KEYDOWN)
|
---|
| 737 | {
|
---|
| 738 | SDL_Event event2;
|
---|
| 739 | unsigned mod = SDL_GetModState() & ~(KMOD_MODE | KMOD_NUM | KMOD_RESERVED);
|
---|
| 740 | while (SDL_WaitEvent(&event2))
|
---|
| 741 | {
|
---|
| 742 | if (event2.type == SDL_KEYDOWN || event2.type == SDL_KEYUP)
|
---|
| 743 | {
|
---|
| 744 | /* pressed additional host key */
|
---|
[18751] | 745 | RTPrintf("--hostkey %d", event1.key.keysym.sym);
|
---|
[1] | 746 | if (event2.type == SDL_KEYDOWN)
|
---|
| 747 | {
|
---|
| 748 | RTPrintf(" %d", event2.key.keysym.sym);
|
---|
| 749 | RTPrintf(" %d\n", SDL_GetModState() & ~(KMOD_MODE | KMOD_NUM | KMOD_RESERVED));
|
---|
| 750 | }
|
---|
| 751 | else
|
---|
| 752 | {
|
---|
| 753 | RTPrintf(" %d\n", mod);
|
---|
| 754 | }
|
---|
| 755 | /* we're done */
|
---|
| 756 | break;
|
---|
| 757 | }
|
---|
| 758 | }
|
---|
| 759 | /* we're down */
|
---|
| 760 | break;
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
| 763 | SDL_Quit();
|
---|
| 764 | return 1;
|
---|
| 765 | }
|
---|
| 766 |
|
---|
| 767 | HRESULT rc;
|
---|
[22490] | 768 | int vrc;
|
---|
[25013] | 769 | Guid uuidVM;
|
---|
[1] | 770 | char *vmName = NULL;
|
---|
[7207] | 771 | DeviceType_T bootDevice = DeviceType_Null;
|
---|
[1] | 772 | uint32_t memorySize = 0;
|
---|
| 773 | uint32_t vramSize = 0;
|
---|
[34646] | 774 | IEventListener *pVBoxClientListener = NULL;
|
---|
[34645] | 775 | IEventListener *pVBoxListener = NULL;
|
---|
| 776 | VBoxSDLConsoleEventListenerImpl *pConsoleListener = NULL;
|
---|
[22305] | 777 |
|
---|
[1] | 778 | bool fFullscreen = false;
|
---|
| 779 | bool fResizable = true;
|
---|
[967] | 780 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
[1] | 781 | bool fXPCOMEventThreadSignaled = false;
|
---|
[967] | 782 | #endif
|
---|
[1] | 783 | char *hdaFile = NULL;
|
---|
| 784 | char *cdromFile = NULL;
|
---|
| 785 | char *fdaFile = NULL;
|
---|
[23825] | 786 | const char *portVRDP = NULL;
|
---|
[1] | 787 | bool fDiscardState = false;
|
---|
| 788 | #ifdef VBOX_SECURELABEL
|
---|
| 789 | BOOL fSecureLabel = false;
|
---|
| 790 | uint32_t secureLabelPointSize = 12;
|
---|
[8154] | 791 | uint32_t secureLabelFontOffs = 0;
|
---|
[1] | 792 | char *secureLabelFontFile = NULL;
|
---|
| 793 | uint32_t secureLabelColorFG = 0x0000FF00;
|
---|
| 794 | uint32_t secureLabelColorBG = 0x00FFFF00;
|
---|
| 795 | #endif
|
---|
| 796 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
| 797 | unsigned fRawR0 = ~0U;
|
---|
| 798 | unsigned fRawR3 = ~0U;
|
---|
| 799 | unsigned fPATM = ~0U;
|
---|
| 800 | unsigned fCSAM = ~0U;
|
---|
[21446] | 801 | unsigned fHWVirt = ~0U;
|
---|
[445] | 802 | uint32_t u32WarpDrive = 0;
|
---|
[1] | 803 | #endif
|
---|
| 804 | #ifdef VBOX_WIN32_UI
|
---|
[12449] | 805 | bool fWin32UI = true;
|
---|
[31698] | 806 | int64_t winId = 0;
|
---|
[1] | 807 | #endif
|
---|
[516] | 808 | bool fShowSDLConfig = false;
|
---|
| 809 | uint32_t fixedWidth = ~(uint32_t)0;
|
---|
| 810 | uint32_t fixedHeight = ~(uint32_t)0;
|
---|
| 811 | uint32_t fixedBPP = ~(uint32_t)0;
|
---|
| 812 | uint32_t uResizeWidth = ~(uint32_t)0;
|
---|
| 813 | uint32_t uResizeHeight = ~(uint32_t)0;
|
---|
[1] | 814 |
|
---|
| 815 | /* The damned GOTOs forces this to be up here - totally out of place. */
|
---|
| 816 | /*
|
---|
| 817 | * Host key handling.
|
---|
| 818 | *
|
---|
| 819 | * The golden rule is that host-key combinations should not be seen
|
---|
| 820 | * by the guest. For instance a CAD should not have any extra RCtrl down
|
---|
| 821 | * and RCtrl up around itself. Nor should a resume be followed by a Ctrl-P
|
---|
| 822 | * that could encourage applications to start printing.
|
---|
| 823 | *
|
---|
| 824 | * We must not confuse the hostkey processing into any release sequences
|
---|
| 825 | * either, the host key is supposed to be explicitly pressing one key.
|
---|
| 826 | *
|
---|
| 827 | * Quick state diagram:
|
---|
| 828 | *
|
---|
| 829 | * host key down alone
|
---|
| 830 | * (Normal) ---------------
|
---|
| 831 | * ^ ^ |
|
---|
| 832 | * | | v host combination key down
|
---|
| 833 | * | | (Host key down) ----------------
|
---|
| 834 | * | | host key up v | |
|
---|
| 835 | * | |-------------- | other key down v host combination key down
|
---|
| 836 | * | | (host key used) -------------
|
---|
| 837 | * | | | ^ |
|
---|
| 838 | * | (not host key)-- | |---------------
|
---|
| 839 | * | | | | |
|
---|
| 840 | * | | ---- other |
|
---|
| 841 | * | modifiers = 0 v v
|
---|
| 842 | * -----------------------------------------------
|
---|
| 843 | */
|
---|
| 844 | enum HKEYSTATE
|
---|
| 845 | {
|
---|
| 846 | /** The initial and most common state, pass keystrokes to the guest.
|
---|
| 847 | * Next state: HKEYSTATE_DOWN
|
---|
| 848 | * Prev state: Any */
|
---|
| 849 | HKEYSTATE_NORMAL = 1,
|
---|
| 850 | /** The first host key was pressed down
|
---|
| 851 | */
|
---|
| 852 | HKEYSTATE_DOWN_1ST,
|
---|
| 853 | /** The second host key was pressed down (if gHostKeySym2 != SDLK_UNKNOWN)
|
---|
| 854 | */
|
---|
| 855 | HKEYSTATE_DOWN_2ND,
|
---|
| 856 | /** The host key has been pressed down.
|
---|
| 857 | * Prev state: HKEYSTATE_NORMAL
|
---|
| 858 | * Next state: HKEYSTATE_NORMAL - host key up, capture toggle.
|
---|
| 859 | * Next state: HKEYSTATE_USED - host key combination down.
|
---|
| 860 | * Next state: HKEYSTATE_NOT_IT - non-host key combination down.
|
---|
| 861 | */
|
---|
| 862 | HKEYSTATE_DOWN,
|
---|
| 863 | /** A host key combination was pressed.
|
---|
| 864 | * Prev state: HKEYSTATE_DOWN
|
---|
| 865 | * Next state: HKEYSTATE_NORMAL - when modifiers are all 0
|
---|
| 866 | */
|
---|
| 867 | HKEYSTATE_USED,
|
---|
| 868 | /** A non-host key combination was attempted. Send hostkey down to the
|
---|
| 869 | * guest and continue until all modifiers have been released.
|
---|
| 870 | * Prev state: HKEYSTATE_DOWN
|
---|
| 871 | * Next state: HKEYSTATE_NORMAL - when modifiers are all 0
|
---|
| 872 | */
|
---|
| 873 | HKEYSTATE_NOT_IT
|
---|
| 874 | } enmHKeyState = HKEYSTATE_NORMAL;
|
---|
| 875 | /** The host key down event which we have been hiding from the guest.
|
---|
| 876 | * Used when going from HKEYSTATE_DOWN to HKEYSTATE_NOT_IT. */
|
---|
| 877 | SDL_Event EvHKeyDown1;
|
---|
| 878 | SDL_Event EvHKeyDown2;
|
---|
| 879 |
|
---|
| 880 | LogFlow(("SDL GUI started\n"));
|
---|
[26034] | 881 | RTPrintf(VBOX_PRODUCT " SDL GUI version %s\n"
|
---|
[26089] | 882 | "(C) 2005-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
|
---|
[16151] | 883 | "All rights reserved.\n\n",
|
---|
| 884 | VBOX_VERSION_STRING);
|
---|
[1] | 885 |
|
---|
| 886 | // less than one parameter is not possible
|
---|
| 887 | if (argc < 2)
|
---|
| 888 | {
|
---|
| 889 | show_usage();
|
---|
| 890 | return 1;
|
---|
| 891 | }
|
---|
| 892 |
|
---|
| 893 | // command line argument parsing stuff
|
---|
| 894 | for (int curArg = 1; curArg < argc; curArg++)
|
---|
| 895 | {
|
---|
[18751] | 896 | if ( !strcmp(argv[curArg], "--vm")
|
---|
| 897 | || !strcmp(argv[curArg], "-vm")
|
---|
| 898 | || !strcmp(argv[curArg], "--startvm")
|
---|
| 899 | || !strcmp(argv[curArg], "-startvm")
|
---|
| 900 | || !strcmp(argv[curArg], "-s")
|
---|
| 901 | )
|
---|
[1] | 902 | {
|
---|
| 903 | if (++curArg >= argc)
|
---|
| 904 | {
|
---|
| 905 | RTPrintf("Error: VM not specified (UUID or name)!\n");
|
---|
[26322] | 906 | return 1;
|
---|
[1] | 907 | }
|
---|
| 908 | // first check if a UUID was supplied
|
---|
[32780] | 909 | uuidVM = argv[curArg];
|
---|
| 910 | if (uuidVM.isEmpty())
|
---|
[1] | 911 | {
|
---|
| 912 | LogFlow(("invalid UUID format, assuming it's a VM name\n"));
|
---|
| 913 | vmName = argv[curArg];
|
---|
| 914 | }
|
---|
| 915 | }
|
---|
[18751] | 916 | else if ( !strcmp(argv[curArg], "--comment")
|
---|
| 917 | || !strcmp(argv[curArg], "-comment"))
|
---|
[1] | 918 | {
|
---|
| 919 | if (++curArg >= argc)
|
---|
| 920 | {
|
---|
[18751] | 921 | RTPrintf("Error: missing argument for comment!\n");
|
---|
[26322] | 922 | return 1;
|
---|
[18751] | 923 | }
|
---|
| 924 | }
|
---|
| 925 | else if ( !strcmp(argv[curArg], "--boot")
|
---|
| 926 | || !strcmp(argv[curArg], "-boot"))
|
---|
| 927 | {
|
---|
| 928 | if (++curArg >= argc)
|
---|
| 929 | {
|
---|
[1] | 930 | RTPrintf("Error: missing argument for boot drive!\n");
|
---|
[26322] | 931 | return 1;
|
---|
[1] | 932 | }
|
---|
| 933 | switch (argv[curArg][0])
|
---|
| 934 | {
|
---|
| 935 | case 'a':
|
---|
| 936 | {
|
---|
[7207] | 937 | bootDevice = DeviceType_Floppy;
|
---|
[1] | 938 | break;
|
---|
| 939 | }
|
---|
| 940 |
|
---|
| 941 | case 'c':
|
---|
| 942 | {
|
---|
[7207] | 943 | bootDevice = DeviceType_HardDisk;
|
---|
[1] | 944 | break;
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 | case 'd':
|
---|
| 948 | {
|
---|
[7207] | 949 | bootDevice = DeviceType_DVD;
|
---|
[1] | 950 | break;
|
---|
| 951 | }
|
---|
| 952 |
|
---|
[4486] | 953 | case 'n':
|
---|
| 954 | {
|
---|
[7207] | 955 | bootDevice = DeviceType_Network;
|
---|
[4486] | 956 | break;
|
---|
| 957 | }
|
---|
| 958 |
|
---|
[1] | 959 | default:
|
---|
| 960 | {
|
---|
| 961 | RTPrintf("Error: wrong argument for boot drive!\n");
|
---|
[26322] | 962 | return 1;
|
---|
[1] | 963 | }
|
---|
| 964 | }
|
---|
| 965 | }
|
---|
[33916] | 966 | else if ( !strcmp(argv[curArg], "--detecthostkey")
|
---|
| 967 | || !strcmp(argv[curArg], "-detecthostkey"))
|
---|
| 968 | {
|
---|
| 969 | RTPrintf("Error: please specify \"%s\" without any additional parameters!\n",
|
---|
| 970 | argv[curArg]);
|
---|
| 971 | return 1;
|
---|
| 972 | }
|
---|
[18751] | 973 | else if ( !strcmp(argv[curArg], "--memory")
|
---|
| 974 | || !strcmp(argv[curArg], "-memory")
|
---|
| 975 | || !strcmp(argv[curArg], "-m"))
|
---|
[1] | 976 | {
|
---|
| 977 | if (++curArg >= argc)
|
---|
| 978 | {
|
---|
| 979 | RTPrintf("Error: missing argument for memory size!\n");
|
---|
[26322] | 980 | return 1;
|
---|
[1] | 981 | }
|
---|
| 982 | memorySize = atoi(argv[curArg]);
|
---|
| 983 | }
|
---|
[18751] | 984 | else if ( !strcmp(argv[curArg], "--vram")
|
---|
| 985 | || !strcmp(argv[curArg], "-vram"))
|
---|
[1] | 986 | {
|
---|
| 987 | if (++curArg >= argc)
|
---|
| 988 | {
|
---|
| 989 | RTPrintf("Error: missing argument for vram size!\n");
|
---|
[26322] | 990 | return 1;
|
---|
[1] | 991 | }
|
---|
| 992 | vramSize = atoi(argv[curArg]);
|
---|
| 993 | }
|
---|
[18751] | 994 | else if ( !strcmp(argv[curArg], "--fullscreen")
|
---|
| 995 | || !strcmp(argv[curArg], "-fullscreen"))
|
---|
[1] | 996 | {
|
---|
| 997 | fFullscreen = true;
|
---|
| 998 | }
|
---|
[18751] | 999 | else if ( !strcmp(argv[curArg], "--fullscreenresize")
|
---|
| 1000 | || !strcmp(argv[curArg], "-fullscreenresize"))
|
---|
[10675] | 1001 | {
|
---|
| 1002 | gfFullscreenResize = true;
|
---|
[10678] | 1003 | #ifdef VBOXSDL_WITH_X11
|
---|
[11419] | 1004 | RTEnvSet("SDL_VIDEO_X11_VIDMODE", "0");
|
---|
[10678] | 1005 | #endif
|
---|
[10675] | 1006 | }
|
---|
[18751] | 1007 | else if ( !strcmp(argv[curArg], "--fixedmode")
|
---|
| 1008 | || !strcmp(argv[curArg], "-fixedmode"))
|
---|
[1] | 1009 | {
|
---|
| 1010 | /* three parameters follow */
|
---|
| 1011 | if (curArg + 3 >= argc)
|
---|
| 1012 | {
|
---|
| 1013 | RTPrintf("Error: missing arguments for fixed video mode!\n");
|
---|
[26322] | 1014 | return 1;
|
---|
[1] | 1015 | }
|
---|
| 1016 | fixedWidth = atoi(argv[++curArg]);
|
---|
| 1017 | fixedHeight = atoi(argv[++curArg]);
|
---|
| 1018 | fixedBPP = atoi(argv[++curArg]);
|
---|
| 1019 | }
|
---|
[18751] | 1020 | else if ( !strcmp(argv[curArg], "--nofstoggle")
|
---|
| 1021 | || !strcmp(argv[curArg], "-nofstoggle"))
|
---|
[1] | 1022 | {
|
---|
| 1023 | gfAllowFullscreenToggle = FALSE;
|
---|
| 1024 | }
|
---|
[18751] | 1025 | else if ( !strcmp(argv[curArg], "--noresize")
|
---|
| 1026 | || !strcmp(argv[curArg], "-noresize"))
|
---|
[1] | 1027 | {
|
---|
| 1028 | fResizable = false;
|
---|
| 1029 | }
|
---|
[18751] | 1030 | else if ( !strcmp(argv[curArg], "--nohostkey")
|
---|
| 1031 | || !strcmp(argv[curArg], "-nohostkey"))
|
---|
[1] | 1032 | {
|
---|
| 1033 | gHostKeyMod = 0;
|
---|
| 1034 | gHostKeySym1 = 0;
|
---|
| 1035 | }
|
---|
[18751] | 1036 | else if ( !strcmp(argv[curArg], "--nohostkeys")
|
---|
| 1037 | || !strcmp(argv[curArg], "-nohostkeys"))
|
---|
[10430] | 1038 | {
|
---|
| 1039 | if (++curArg >= argc)
|
---|
| 1040 | {
|
---|
| 1041 | RTPrintf("Error: missing a string of disabled hostkey combinations\n");
|
---|
[26322] | 1042 | return 1;
|
---|
[10430] | 1043 | }
|
---|
| 1044 | gHostKeyDisabledCombinations = argv[curArg];
|
---|
[18494] | 1045 | size_t cch = strlen(gHostKeyDisabledCombinations);
|
---|
| 1046 | for (size_t i = 0; i < cch; i++)
|
---|
[10430] | 1047 | {
|
---|
| 1048 | if (!strchr("fhnpqrs", gHostKeyDisabledCombinations[i]))
|
---|
| 1049 | {
|
---|
| 1050 | RTPrintf("Error: <hostkey> + '%c' is not a valid combination\n",
|
---|
[18494] | 1051 | gHostKeyDisabledCombinations[i]);
|
---|
[26322] | 1052 | return 1;
|
---|
[10430] | 1053 | }
|
---|
| 1054 | }
|
---|
| 1055 | }
|
---|
[18751] | 1056 | else if ( !strcmp(argv[curArg], "--nograbonclick")
|
---|
| 1057 | || !strcmp(argv[curArg], "-nograbonclick"))
|
---|
[1] | 1058 | {
|
---|
| 1059 | gfGrabOnMouseClick = FALSE;
|
---|
| 1060 | }
|
---|
[18751] | 1061 | else if ( !strcmp(argv[curArg], "--termacpi")
|
---|
| 1062 | || !strcmp(argv[curArg], "-termacpi"))
|
---|
[6437] | 1063 | {
|
---|
| 1064 | gfACPITerm = TRUE;
|
---|
| 1065 | }
|
---|
[18751] | 1066 | else if ( !strcmp(argv[curArg], "--pidfile")
|
---|
| 1067 | || !strcmp(argv[curArg], "-pidfile"))
|
---|
[10501] | 1068 | {
|
---|
| 1069 | if (++curArg >= argc)
|
---|
| 1070 | {
|
---|
[18751] | 1071 | RTPrintf("Error: missing file name for --pidfile!\n");
|
---|
[26322] | 1072 | return 1;
|
---|
[10501] | 1073 | }
|
---|
| 1074 | gpszPidFile = argv[curArg];
|
---|
| 1075 | }
|
---|
[18751] | 1076 | else if ( !strcmp(argv[curArg], "--hda")
|
---|
| 1077 | || !strcmp(argv[curArg], "-hda"))
|
---|
[1] | 1078 | {
|
---|
| 1079 | if (++curArg >= argc)
|
---|
| 1080 | {
|
---|
| 1081 | RTPrintf("Error: missing file name for first hard disk!\n");
|
---|
[26322] | 1082 | return 1;
|
---|
[1] | 1083 | }
|
---|
| 1084 | /* resolve it. */
|
---|
[2271] | 1085 | if (RTPathExists(argv[curArg]))
|
---|
| 1086 | hdaFile = RTPathRealDup(argv[curArg]);
|
---|
[1] | 1087 | if (!hdaFile)
|
---|
| 1088 | {
|
---|
| 1089 | RTPrintf("Error: The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]);
|
---|
[26322] | 1090 | return 1;
|
---|
[1] | 1091 | }
|
---|
| 1092 | }
|
---|
[18751] | 1093 | else if ( !strcmp(argv[curArg], "--fda")
|
---|
| 1094 | || !strcmp(argv[curArg], "-fda"))
|
---|
[1] | 1095 | {
|
---|
| 1096 | if (++curArg >= argc)
|
---|
| 1097 | {
|
---|
| 1098 | RTPrintf("Error: missing file/device name for first floppy disk!\n");
|
---|
[26322] | 1099 | return 1;
|
---|
[1] | 1100 | }
|
---|
| 1101 | /* resolve it. */
|
---|
[2271] | 1102 | if (RTPathExists(argv[curArg]))
|
---|
| 1103 | fdaFile = RTPathRealDup(argv[curArg]);
|
---|
[1] | 1104 | if (!fdaFile)
|
---|
| 1105 | {
|
---|
| 1106 | RTPrintf("Error: The path to the specified floppy disk, '%s', could not be resolved.\n", argv[curArg]);
|
---|
[26322] | 1107 | return 1;
|
---|
[1] | 1108 | }
|
---|
| 1109 | }
|
---|
[18751] | 1110 | else if ( !strcmp(argv[curArg], "--cdrom")
|
---|
| 1111 | || !strcmp(argv[curArg], "-cdrom"))
|
---|
[1] | 1112 | {
|
---|
| 1113 | if (++curArg >= argc)
|
---|
| 1114 | {
|
---|
[2238] | 1115 | RTPrintf("Error: missing file/device name for cdrom!\n");
|
---|
[26322] | 1116 | return 1;
|
---|
[1] | 1117 | }
|
---|
| 1118 | /* resolve it. */
|
---|
[2271] | 1119 | if (RTPathExists(argv[curArg]))
|
---|
| 1120 | cdromFile = RTPathRealDup(argv[curArg]);
|
---|
[1] | 1121 | if (!cdromFile)
|
---|
| 1122 | {
|
---|
| 1123 | RTPrintf("Error: The path to the specified cdrom, '%s', could not be resolved.\n", argv[curArg]);
|
---|
[26322] | 1124 | return 1;
|
---|
[1] | 1125 | }
|
---|
| 1126 | }
|
---|
[18751] | 1127 | else if ( !strcmp(argv[curArg], "--vrdp")
|
---|
| 1128 | || !strcmp(argv[curArg], "-vrdp"))
|
---|
[1] | 1129 | {
|
---|
| 1130 | // start with the standard VRDP port
|
---|
[23643] | 1131 | portVRDP = "0";
|
---|
[1] | 1132 |
|
---|
| 1133 | // is there another argument
|
---|
| 1134 | if (argc > (curArg + 1))
|
---|
| 1135 | {
|
---|
[23643] | 1136 | curArg++;
|
---|
| 1137 | portVRDP = argv[curArg];
|
---|
| 1138 | LogFlow(("Using non standard VRDP port %s\n", portVRDP));
|
---|
[1] | 1139 | }
|
---|
| 1140 | }
|
---|
[18751] | 1141 | else if ( !strcmp(argv[curArg], "--discardstate")
|
---|
| 1142 | || !strcmp(argv[curArg], "-discardstate"))
|
---|
[1] | 1143 | {
|
---|
| 1144 | fDiscardState = true;
|
---|
| 1145 | }
|
---|
| 1146 | #ifdef VBOX_SECURELABEL
|
---|
[18751] | 1147 | else if ( !strcmp(argv[curArg], "--securelabel")
|
---|
| 1148 | || !strcmp(argv[curArg], "-securelabel"))
|
---|
[1] | 1149 | {
|
---|
| 1150 | fSecureLabel = true;
|
---|
| 1151 | LogFlow(("Secure labelling turned on\n"));
|
---|
| 1152 | }
|
---|
[18751] | 1153 | else if ( !strcmp(argv[curArg], "--seclabelfnt")
|
---|
| 1154 | || !strcmp(argv[curArg], "-seclabelfnt"))
|
---|
[1] | 1155 | {
|
---|
| 1156 | if (++curArg >= argc)
|
---|
| 1157 | {
|
---|
| 1158 | RTPrintf("Error: missing font file name for secure label!\n");
|
---|
[26322] | 1159 | return 1;
|
---|
[1] | 1160 | }
|
---|
| 1161 | secureLabelFontFile = argv[curArg];
|
---|
| 1162 | }
|
---|
[18751] | 1163 | else if ( !strcmp(argv[curArg], "--seclabelsiz")
|
---|
| 1164 | || !strcmp(argv[curArg], "-seclabelsiz"))
|
---|
[1] | 1165 | {
|
---|
| 1166 | if (++curArg >= argc)
|
---|
| 1167 | {
|
---|
| 1168 | RTPrintf("Error: missing font point size for secure label!\n");
|
---|
[26322] | 1169 | return 1;
|
---|
[1] | 1170 | }
|
---|
| 1171 | secureLabelPointSize = atoi(argv[curArg]);
|
---|
| 1172 | }
|
---|
[18751] | 1173 | else if ( !strcmp(argv[curArg], "--seclabelofs")
|
---|
| 1174 | || !strcmp(argv[curArg], "-seclabelofs"))
|
---|
[8154] | 1175 | {
|
---|
| 1176 | if (++curArg >= argc)
|
---|
| 1177 | {
|
---|
| 1178 | RTPrintf("Error: missing font pixel offset for secure label!\n");
|
---|
[26322] | 1179 | return 1;
|
---|
[8154] | 1180 | }
|
---|
| 1181 | secureLabelFontOffs = atoi(argv[curArg]);
|
---|
| 1182 | }
|
---|
[18751] | 1183 | else if ( !strcmp(argv[curArg], "--seclabelfgcol")
|
---|
| 1184 | || !strcmp(argv[curArg], "-seclabelfgcol"))
|
---|
[1] | 1185 | {
|
---|
| 1186 | if (++curArg >= argc)
|
---|
| 1187 | {
|
---|
| 1188 | RTPrintf("Error: missing text color value for secure label!\n");
|
---|
[26322] | 1189 | return 1;
|
---|
[1] | 1190 | }
|
---|
| 1191 | sscanf(argv[curArg], "%X", &secureLabelColorFG);
|
---|
| 1192 | }
|
---|
[18751] | 1193 | else if ( !strcmp(argv[curArg], "--seclabelbgcol")
|
---|
| 1194 | || !strcmp(argv[curArg], "-seclabelbgcol"))
|
---|
[1] | 1195 | {
|
---|
| 1196 | if (++curArg >= argc)
|
---|
| 1197 | {
|
---|
| 1198 | RTPrintf("Error: missing background color value for secure label!\n");
|
---|
[26322] | 1199 | return 1;
|
---|
[1] | 1200 | }
|
---|
| 1201 | sscanf(argv[curArg], "%X", &secureLabelColorBG);
|
---|
| 1202 | }
|
---|
| 1203 | #endif
|
---|
| 1204 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
[18751] | 1205 | else if ( !strcmp(argv[curArg], "--rawr0")
|
---|
| 1206 | || !strcmp(argv[curArg], "-rawr0"))
|
---|
[1] | 1207 | fRawR0 = true;
|
---|
[18751] | 1208 | else if ( !strcmp(argv[curArg], "--norawr0")
|
---|
| 1209 | || !strcmp(argv[curArg], "-norawr0"))
|
---|
[1] | 1210 | fRawR0 = false;
|
---|
[18751] | 1211 | else if ( !strcmp(argv[curArg], "--rawr3")
|
---|
| 1212 | || !strcmp(argv[curArg], "-rawr3"))
|
---|
[1] | 1213 | fRawR3 = true;
|
---|
[18751] | 1214 | else if ( !strcmp(argv[curArg], "--norawr3")
|
---|
| 1215 | || !strcmp(argv[curArg], "-norawr3"))
|
---|
[1] | 1216 | fRawR3 = false;
|
---|
[18751] | 1217 | else if ( !strcmp(argv[curArg], "--patm")
|
---|
| 1218 | || !strcmp(argv[curArg], "-patm"))
|
---|
[1] | 1219 | fPATM = true;
|
---|
[18751] | 1220 | else if ( !strcmp(argv[curArg], "--nopatm")
|
---|
| 1221 | || !strcmp(argv[curArg], "-nopatm"))
|
---|
[1] | 1222 | fPATM = false;
|
---|
[18751] | 1223 | else if ( !strcmp(argv[curArg], "--csam")
|
---|
| 1224 | || !strcmp(argv[curArg], "-csam"))
|
---|
[1] | 1225 | fCSAM = true;
|
---|
[18751] | 1226 | else if ( !strcmp(argv[curArg], "--nocsam")
|
---|
| 1227 | || !strcmp(argv[curArg], "-nocsam"))
|
---|
[1] | 1228 | fCSAM = false;
|
---|
[18751] | 1229 | else if ( !strcmp(argv[curArg], "--hwvirtex")
|
---|
| 1230 | || !strcmp(argv[curArg], "-hwvirtex"))
|
---|
[21446] | 1231 | fHWVirt = true;
|
---|
[18751] | 1232 | else if ( !strcmp(argv[curArg], "--nohwvirtex")
|
---|
| 1233 | || !strcmp(argv[curArg], "-nohwvirtex"))
|
---|
[21446] | 1234 | fHWVirt = false;
|
---|
[18751] | 1235 | else if ( !strcmp(argv[curArg], "--warpdrive")
|
---|
| 1236 | || !strcmp(argv[curArg], "-warpdrive"))
|
---|
[445] | 1237 | {
|
---|
| 1238 | if (++curArg >= argc)
|
---|
| 1239 | {
|
---|
[18751] | 1240 | RTPrintf("Error: missing the rate value for the --warpdrive option!\n");
|
---|
[26322] | 1241 | return 1;
|
---|
[445] | 1242 | }
|
---|
| 1243 | u32WarpDrive = RTStrToUInt32(argv[curArg]);
|
---|
| 1244 | if (u32WarpDrive < 2 || u32WarpDrive > 20000)
|
---|
| 1245 | {
|
---|
| 1246 | RTPrintf("Error: the warp drive rate is restricted to [2..20000]. (%d)\n", u32WarpDrive);
|
---|
[26322] | 1247 | return 1;
|
---|
[445] | 1248 | }
|
---|
| 1249 | }
|
---|
[1] | 1250 | #endif /* VBOXSDL_ADVANCED_OPTIONS */
|
---|
| 1251 | #ifdef VBOX_WIN32_UI
|
---|
[18751] | 1252 | else if ( !strcmp(argv[curArg], "--win32ui")
|
---|
| 1253 | || !strcmp(argv[curArg], "-win32ui"))
|
---|
[1] | 1254 | fWin32UI = true;
|
---|
| 1255 | #endif
|
---|
[18751] | 1256 | else if ( !strcmp(argv[curArg], "--showsdlconfig")
|
---|
| 1257 | || !strcmp(argv[curArg], "-showsdlconfig"))
|
---|
[1] | 1258 | fShowSDLConfig = true;
|
---|
[18751] | 1259 | else if ( !strcmp(argv[curArg], "--hostkey")
|
---|
| 1260 | || !strcmp(argv[curArg], "-hostkey"))
|
---|
[1] | 1261 | {
|
---|
| 1262 | if (++curArg + 1 >= argc)
|
---|
| 1263 | {
|
---|
| 1264 | RTPrintf("Error: not enough arguments for host keys!\n");
|
---|
[26322] | 1265 | return 1;
|
---|
[1] | 1266 | }
|
---|
| 1267 | gHostKeySym1 = atoi(argv[curArg++]);
|
---|
| 1268 | if (curArg + 1 < argc && (argv[curArg+1][0] == '0' || atoi(argv[curArg+1]) > 0))
|
---|
| 1269 | {
|
---|
| 1270 | /* two-key sequence as host key specified */
|
---|
| 1271 | gHostKeySym2 = atoi(argv[curArg++]);
|
---|
| 1272 | }
|
---|
| 1273 | gHostKeyMod = atoi(argv[curArg]);
|
---|
| 1274 | }
|
---|
| 1275 | /* just show the help screen */
|
---|
| 1276 | else
|
---|
| 1277 | {
|
---|
[18751] | 1278 | if ( strcmp(argv[curArg], "-h")
|
---|
| 1279 | && strcmp(argv[curArg], "-help")
|
---|
[5084] | 1280 | && strcmp(argv[curArg], "--help"))
|
---|
| 1281 | RTPrintf("Error: unrecognized switch '%s'\n", argv[curArg]);
|
---|
[1] | 1282 | show_usage();
|
---|
| 1283 | return 1;
|
---|
| 1284 | }
|
---|
| 1285 | }
|
---|
[26322] | 1286 |
|
---|
| 1287 | rc = com::Initialize();
|
---|
[23223] | 1288 | if (FAILED(rc))
|
---|
[26322] | 1289 | {
|
---|
[34645] | 1290 | RTPrintf("Error: COM initialization failed (rc=%Rhrc)!\n", rc);
|
---|
[26322] | 1291 | return 1;
|
---|
| 1292 | }
|
---|
| 1293 |
|
---|
[26439] | 1294 | /* NOTE: do not convert the following scope to a "do {} while (0);", as
|
---|
| 1295 | * this would make it all too tempting to use "break;" incorrectly - it
|
---|
| 1296 | * would skip over the cleanup. */
|
---|
[26322] | 1297 | {
|
---|
| 1298 | // scopes all the stuff till shutdown
|
---|
| 1299 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1300 |
|
---|
[34646] | 1301 | ComPtr<IVirtualBoxClient> pVirtualBoxClient;
|
---|
[34645] | 1302 | ComPtr<IVirtualBox> pVirtualBox;
|
---|
| 1303 | ComPtr<ISession> pSession;
|
---|
[26322] | 1304 | bool sessionOpened = false;
|
---|
[26439] | 1305 | EventQueue* eventQ = com::EventQueue::getMainEventQueue();
|
---|
[26322] | 1306 |
|
---|
[31008] | 1307 | ComPtr<IMachine> pMachine;
|
---|
| 1308 |
|
---|
[34646] | 1309 | rc = pVirtualBoxClient.createInprocObject(CLSID_VirtualBoxClient);
|
---|
[26322] | 1310 | if (FAILED(rc))
|
---|
| 1311 | {
|
---|
| 1312 | com::ErrorInfo info;
|
---|
| 1313 | if (info.isFullAvailable())
|
---|
[34646] | 1314 | PrintError("Failed to create VirtualBoxClient object",
|
---|
[26322] | 1315 | info.getText().raw(), info.getComponent().raw());
|
---|
| 1316 | else
|
---|
[34646] | 1317 | RTPrintf("Failed to create VirtualBoxClient object! No error information available (rc=%Rhrc).\n", rc);
|
---|
[26439] | 1318 | goto leave;
|
---|
[26322] | 1319 | }
|
---|
[34646] | 1320 |
|
---|
| 1321 | rc = pVirtualBoxClient->COMGETTER(VirtualBox)(pVirtualBox.asOutParam());
|
---|
[26322] | 1322 | if (FAILED(rc))
|
---|
| 1323 | {
|
---|
[34646] | 1324 | RTPrintf("Failed to get VirtualBox object (rc=%Rhrc)!\n", rc);
|
---|
[26439] | 1325 | goto leave;
|
---|
[26322] | 1326 | }
|
---|
[34646] | 1327 | rc = pVirtualBoxClient->COMGETTER(Session)(pSession.asOutParam());
|
---|
| 1328 | if (FAILED(rc))
|
---|
| 1329 | {
|
---|
| 1330 | RTPrintf("Failed to get session object (rc=%Rhrc)!\n", rc);
|
---|
| 1331 | goto leave;
|
---|
| 1332 | }
|
---|
[1] | 1333 |
|
---|
| 1334 | /*
|
---|
| 1335 | * Do we have a name but no UUID?
|
---|
| 1336 | */
|
---|
[25013] | 1337 | if (vmName && uuidVM.isEmpty())
|
---|
[1] | 1338 | {
|
---|
[34645] | 1339 | rc = pVirtualBox->FindMachine(Bstr(vmName).raw(), pMachine.asOutParam());
|
---|
[31008] | 1340 | if ((rc == S_OK) && pMachine)
|
---|
[1] | 1341 | {
|
---|
[34645] | 1342 | Bstr bstrId;
|
---|
| 1343 | pMachine->COMGETTER(Id)(bstrId.asOutParam());
|
---|
| 1344 | uuidVM = Guid(bstrId);
|
---|
[1] | 1345 | }
|
---|
| 1346 | else
|
---|
| 1347 | {
|
---|
| 1348 | RTPrintf("Error: machine with the given ID not found!\n");
|
---|
| 1349 | goto leave;
|
---|
| 1350 | }
|
---|
| 1351 | }
|
---|
[25013] | 1352 | else if (uuidVM.isEmpty())
|
---|
[1] | 1353 | {
|
---|
| 1354 | RTPrintf("Error: no machine specified!\n");
|
---|
| 1355 | goto leave;
|
---|
| 1356 | }
|
---|
| 1357 |
|
---|
[3289] | 1358 | /* create SDL event semaphore */
|
---|
[22490] | 1359 | vrc = RTSemEventCreate(&g_EventSemSDLEvents);
|
---|
| 1360 | AssertReleaseRC(vrc);
|
---|
[3289] | 1361 |
|
---|
[34645] | 1362 | rc = pMachine->LockMachine(pSession, LockType_Write);
|
---|
[1] | 1363 | if (FAILED(rc))
|
---|
| 1364 | {
|
---|
| 1365 | com::ErrorInfo info;
|
---|
| 1366 | if (info.isFullAvailable())
|
---|
[26068] | 1367 | PrintError("Could not open VirtualBox session",
|
---|
[34645] | 1368 | info.getText().raw(), info.getComponent().raw());
|
---|
[1] | 1369 | goto leave;
|
---|
| 1370 | }
|
---|
[34645] | 1371 | if (!pSession)
|
---|
[1] | 1372 | {
|
---|
[26068] | 1373 | RTPrintf("Could not open VirtualBox session!\n");
|
---|
[1] | 1374 | goto leave;
|
---|
| 1375 | }
|
---|
| 1376 | sessionOpened = true;
|
---|
[31008] | 1377 | // get the mutable VM we're dealing with
|
---|
[34645] | 1378 | pSession->COMGETTER(Machine)(gpMachine.asOutParam());
|
---|
| 1379 | if (!gpMachine)
|
---|
[1] | 1380 | {
|
---|
| 1381 | com::ErrorInfo info;
|
---|
| 1382 | if (info.isFullAvailable())
|
---|
| 1383 | PrintError("Cannot start VM!",
|
---|
| 1384 | info.getText().raw(), info.getComponent().raw());
|
---|
| 1385 | else
|
---|
| 1386 | RTPrintf("Error: given machine not found!\n");
|
---|
| 1387 | goto leave;
|
---|
| 1388 | }
|
---|
| 1389 | // get the VM console
|
---|
[34645] | 1390 | pSession->COMGETTER(Console)(gpConsole.asOutParam());
|
---|
| 1391 | if (!gpConsole)
|
---|
[1] | 1392 | {
|
---|
| 1393 | RTPrintf("Given console not found!\n");
|
---|
| 1394 | goto leave;
|
---|
| 1395 | }
|
---|
| 1396 |
|
---|
| 1397 | /*
|
---|
| 1398 | * Are we supposed to use a different hard disk file?
|
---|
| 1399 | */
|
---|
| 1400 | if (hdaFile)
|
---|
| 1401 | {
|
---|
[34645] | 1402 | ComPtr<IMedium> pMedium;
|
---|
| 1403 |
|
---|
[1] | 1404 | /*
|
---|
[34645] | 1405 | * Strategy: if any registered hard disk points to the same file,
|
---|
| 1406 | * assign it. If not, register a new image and assign it to the VM.
|
---|
[1] | 1407 | */
|
---|
[34645] | 1408 | Bstr bstrHdaFile(hdaFile);
|
---|
| 1409 | pVirtualBox->FindMedium(bstrHdaFile.raw(), DeviceType_HardDisk,
|
---|
| 1410 | pMedium.asOutParam());
|
---|
| 1411 | if (!pMedium)
|
---|
[1] | 1412 | {
|
---|
| 1413 | /* we've not found the image */
|
---|
[34645] | 1414 | RTPrintf("Adding hard disk '%s'...\n", hdaFile);
|
---|
| 1415 | pVirtualBox->OpenMedium(bstrHdaFile.raw(), DeviceType_HardDisk,
|
---|
| 1416 | AccessMode_ReadWrite, pMedium.asOutParam());
|
---|
[1] | 1417 | }
|
---|
| 1418 | /* do we have the right image now? */
|
---|
[34645] | 1419 | if (pMedium)
|
---|
[1] | 1420 | {
|
---|
[34645] | 1421 | Bstr bstrSCName;
|
---|
[23825] | 1422 |
|
---|
| 1423 | /* get the first IDE controller to attach the harddisk to
|
---|
[34645] | 1424 | * and if there is none, add one temporarily */
|
---|
[23825] | 1425 | {
|
---|
[34645] | 1426 | ComPtr<IStorageController> pStorageCtl;
|
---|
[23825] | 1427 | com::SafeIfaceArray<IStorageController> aStorageControllers;
|
---|
[34645] | 1428 | CHECK_ERROR(gpMachine, COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(aStorageControllers)));
|
---|
[23825] | 1429 | for (size_t i = 0; i < aStorageControllers.size(); ++ i)
|
---|
| 1430 | {
|
---|
| 1431 | StorageBus_T storageBus = StorageBus_Null;
|
---|
| 1432 |
|
---|
[28205] | 1433 | CHECK_ERROR(aStorageControllers[i], COMGETTER(Bus)(&storageBus));
|
---|
[23825] | 1434 | if (storageBus == StorageBus_IDE)
|
---|
| 1435 | {
|
---|
[34645] | 1436 | pStorageCtl = aStorageControllers[i];
|
---|
[23825] | 1437 | break;
|
---|
| 1438 | }
|
---|
| 1439 | }
|
---|
| 1440 |
|
---|
[34645] | 1441 | if (pStorageCtl)
|
---|
[23825] | 1442 | {
|
---|
[34645] | 1443 | CHECK_ERROR(pStorageCtl, COMGETTER(Name)(bstrSCName.asOutParam()));
|
---|
| 1444 | gpMachine->DetachDevice(bstrSCName.raw(), 0, 0);
|
---|
[23825] | 1445 | }
|
---|
| 1446 | else
|
---|
| 1447 | {
|
---|
[34645] | 1448 | bstrSCName = "IDE Controller";
|
---|
| 1449 | CHECK_ERROR(gpMachine, AddStorageController(bstrSCName.raw(),
|
---|
| 1450 | StorageBus_IDE,
|
---|
| 1451 | pStorageCtl.asOutParam()));
|
---|
[23825] | 1452 | }
|
---|
| 1453 | }
|
---|
| 1454 |
|
---|
[34645] | 1455 | CHECK_ERROR(gpMachine, AttachDevice(bstrSCName.raw(), 0, 0,
|
---|
| 1456 | DeviceType_HardDisk, pMedium));
|
---|
[1] | 1457 | /// @todo why is this attachment saved?
|
---|
| 1458 | }
|
---|
| 1459 | else
|
---|
| 1460 | {
|
---|
| 1461 | RTPrintf("Error: failed to mount the specified hard disk image!\n");
|
---|
| 1462 | goto leave;
|
---|
| 1463 | }
|
---|
| 1464 | }
|
---|
| 1465 |
|
---|
[2980] | 1466 | /*
|
---|
[2238] | 1467 | * Mount a floppy if requested.
|
---|
| 1468 | */
|
---|
[1] | 1469 | if (fdaFile)
|
---|
[2238] | 1470 | do
|
---|
[1] | 1471 | {
|
---|
[34645] | 1472 | ComPtr<IMedium> pMedium;
|
---|
[1] | 1473 |
|
---|
[23223] | 1474 | /* unmount? */
|
---|
| 1475 | if (!strcmp(fdaFile, "none"))
|
---|
[1] | 1476 | {
|
---|
[23223] | 1477 | /* nothing to do, NULL object will cause unmount */
|
---|
[1] | 1478 | }
|
---|
[23223] | 1479 | else
|
---|
| 1480 | {
|
---|
[34645] | 1481 | Bstr bstrFdaFile(fdaFile);
|
---|
[2238] | 1482 |
|
---|
[23223] | 1483 | /* Assume it's a host drive name */
|
---|
[34645] | 1484 | ComPtr<IHost> pHost;
|
---|
| 1485 | CHECK_ERROR_BREAK(pVirtualBox, COMGETTER(Host)(pHost.asOutParam()));
|
---|
| 1486 | rc = pHost->FindHostFloppyDrive(bstrFdaFile.raw(),
|
---|
| 1487 | pMedium.asOutParam());
|
---|
[23223] | 1488 | if (FAILED(rc))
|
---|
[2238] | 1489 | {
|
---|
[23223] | 1490 | /* try to find an existing one */
|
---|
[34645] | 1491 | rc = pVirtualBox->FindMedium(bstrFdaFile.raw(), DeviceType_Floppy,
|
---|
| 1492 | pMedium.asOutParam());
|
---|
[23223] | 1493 | if (FAILED(rc))
|
---|
| 1494 | {
|
---|
| 1495 | /* try to add to the list */
|
---|
[34645] | 1496 | RTPrintf("Adding floppy image '%s'...\n", fdaFile);
|
---|
| 1497 | CHECK_ERROR_BREAK(pVirtualBox,
|
---|
| 1498 | OpenMedium(bstrFdaFile.raw(),
|
---|
[32718] | 1499 | DeviceType_Floppy,
|
---|
| 1500 | AccessMode_ReadWrite,
|
---|
[34645] | 1501 | pMedium.asOutParam()));
|
---|
[23223] | 1502 | }
|
---|
[2238] | 1503 | }
|
---|
[1] | 1504 | }
|
---|
[23825] | 1505 |
|
---|
[34645] | 1506 | Bstr bstrSCName;
|
---|
[23825] | 1507 |
|
---|
| 1508 | /* get the first floppy controller to attach the floppy to
|
---|
[34645] | 1509 | * and if there is none, add one temporarily */
|
---|
[23825] | 1510 | {
|
---|
[34645] | 1511 | ComPtr<IStorageController> pStorageCtl;
|
---|
[23825] | 1512 | com::SafeIfaceArray<IStorageController> aStorageControllers;
|
---|
[34645] | 1513 | CHECK_ERROR(gpMachine, COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(aStorageControllers)));
|
---|
[23825] | 1514 | for (size_t i = 0; i < aStorageControllers.size(); ++ i)
|
---|
| 1515 | {
|
---|
| 1516 | StorageBus_T storageBus = StorageBus_Null;
|
---|
| 1517 |
|
---|
[28205] | 1518 | CHECK_ERROR(aStorageControllers[i], COMGETTER(Bus)(&storageBus));
|
---|
[23825] | 1519 | if (storageBus == StorageBus_Floppy)
|
---|
| 1520 | {
|
---|
[34645] | 1521 | pStorageCtl = aStorageControllers[i];
|
---|
[23825] | 1522 | break;
|
---|
| 1523 | }
|
---|
| 1524 | }
|
---|
| 1525 |
|
---|
[34645] | 1526 | if (pStorageCtl)
|
---|
[23825] | 1527 | {
|
---|
[34645] | 1528 | CHECK_ERROR(pStorageCtl, COMGETTER(Name)(bstrSCName.asOutParam()));
|
---|
| 1529 | gpMachine->DetachDevice(bstrSCName.raw(), 0, 0);
|
---|
[23825] | 1530 | }
|
---|
| 1531 | else
|
---|
| 1532 | {
|
---|
[34645] | 1533 | bstrSCName = "Floppy Controller";
|
---|
| 1534 | CHECK_ERROR(gpMachine, AddStorageController(bstrSCName.raw(),
|
---|
| 1535 | StorageBus_Floppy,
|
---|
| 1536 | pStorageCtl.asOutParam()));
|
---|
[23825] | 1537 | }
|
---|
| 1538 | }
|
---|
| 1539 |
|
---|
[34645] | 1540 | CHECK_ERROR(gpMachine, AttachDevice(bstrSCName.raw(), 0, 0,
|
---|
| 1541 | DeviceType_Floppy, pMedium));
|
---|
[1] | 1542 | }
|
---|
[2238] | 1543 | while (0);
|
---|
[23223] | 1544 | if (FAILED(rc))
|
---|
[2238] | 1545 | goto leave;
|
---|
[1] | 1546 |
|
---|
[2980] | 1547 | /*
|
---|
[2238] | 1548 | * Mount a CD-ROM if requested.
|
---|
[1] | 1549 | */
|
---|
| 1550 | if (cdromFile)
|
---|
[2238] | 1551 | do
|
---|
[1] | 1552 | {
|
---|
[34645] | 1553 | ComPtr<IMedium> pMedium;
|
---|
[1] | 1554 |
|
---|
[23223] | 1555 | /* unmount? */
|
---|
| 1556 | if (!strcmp(cdromFile, "none"))
|
---|
[1] | 1557 | {
|
---|
[23223] | 1558 | /* nothing to do, NULL object will cause unmount */
|
---|
[1] | 1559 | }
|
---|
[23223] | 1560 | else
|
---|
| 1561 | {
|
---|
[34645] | 1562 | Bstr bstrCdromFile(cdromFile);
|
---|
[2238] | 1563 |
|
---|
[23223] | 1564 | /* Assume it's a host drive name */
|
---|
[34645] | 1565 | ComPtr<IHost> pHost;
|
---|
| 1566 | CHECK_ERROR_BREAK(pVirtualBox, COMGETTER(Host)(pHost.asOutParam()));
|
---|
| 1567 | rc = pHost->FindHostDVDDrive(bstrCdromFile.raw(), pMedium.asOutParam());
|
---|
[23223] | 1568 | if (FAILED(rc))
|
---|
[1] | 1569 | {
|
---|
[23223] | 1570 | /* try to find an existing one */
|
---|
[34645] | 1571 | rc = pVirtualBox->FindMedium(bstrCdromFile.raw(), DeviceType_DVD,
|
---|
| 1572 | pMedium.asOutParam());
|
---|
[23223] | 1573 | if (FAILED(rc))
|
---|
| 1574 | {
|
---|
| 1575 | /* try to add to the list */
|
---|
[34645] | 1576 | RTPrintf("Adding ISO image '%s'...\n", cdromFile);
|
---|
| 1577 | CHECK_ERROR_BREAK(pVirtualBox,
|
---|
| 1578 | OpenMedium(bstrCdromFile.raw(),
|
---|
| 1579 | DeviceType_DVD,
|
---|
| 1580 | AccessMode_ReadWrite,
|
---|
| 1581 | pMedium.asOutParam()));
|
---|
[23223] | 1582 | }
|
---|
[1] | 1583 | }
|
---|
[2238] | 1584 | }
|
---|
[23825] | 1585 |
|
---|
[34645] | 1586 | Bstr bstrSCName;
|
---|
[23825] | 1587 |
|
---|
[34645] | 1588 | /* get the first IDE controller to attach the DVD drive to
|
---|
| 1589 | * and if there is none, add one temporarily */
|
---|
[23825] | 1590 | {
|
---|
[34645] | 1591 | ComPtr<IStorageController> pStorageCtl;
|
---|
[23825] | 1592 | com::SafeIfaceArray<IStorageController> aStorageControllers;
|
---|
[34645] | 1593 | CHECK_ERROR(gpMachine, COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(aStorageControllers)));
|
---|
[23825] | 1594 | for (size_t i = 0; i < aStorageControllers.size(); ++ i)
|
---|
| 1595 | {
|
---|
| 1596 | StorageBus_T storageBus = StorageBus_Null;
|
---|
| 1597 |
|
---|
[28205] | 1598 | CHECK_ERROR(aStorageControllers[i], COMGETTER(Bus)(&storageBus));
|
---|
[23825] | 1599 | if (storageBus == StorageBus_IDE)
|
---|
| 1600 | {
|
---|
[34645] | 1601 | pStorageCtl = aStorageControllers[i];
|
---|
[23825] | 1602 | break;
|
---|
| 1603 | }
|
---|
| 1604 | }
|
---|
| 1605 |
|
---|
[34645] | 1606 | if (pStorageCtl)
|
---|
[23825] | 1607 | {
|
---|
[34645] | 1608 | CHECK_ERROR(pStorageCtl, COMGETTER(Name)(bstrSCName.asOutParam()));
|
---|
| 1609 | gpMachine->DetachDevice(bstrSCName.raw(), 1, 0);
|
---|
[23825] | 1610 | }
|
---|
| 1611 | else
|
---|
| 1612 | {
|
---|
[34645] | 1613 | bstrSCName = "IDE Controller";
|
---|
| 1614 | CHECK_ERROR(gpMachine, AddStorageController(bstrSCName.raw(),
|
---|
| 1615 | StorageBus_IDE,
|
---|
| 1616 | pStorageCtl.asOutParam()));
|
---|
[23825] | 1617 | }
|
---|
| 1618 | }
|
---|
| 1619 |
|
---|
[34645] | 1620 | CHECK_ERROR(gpMachine, AttachDevice(bstrSCName.raw(), 1, 0,
|
---|
| 1621 | DeviceType_DVD, pMedium));
|
---|
[1] | 1622 | }
|
---|
[2238] | 1623 | while (0);
|
---|
[23223] | 1624 | if (FAILED(rc))
|
---|
[2238] | 1625 | goto leave;
|
---|
[1] | 1626 |
|
---|
| 1627 | if (fDiscardState)
|
---|
| 1628 | {
|
---|
| 1629 | /*
|
---|
| 1630 | * If the machine is currently saved,
|
---|
| 1631 | * discard the saved state first.
|
---|
| 1632 | */
|
---|
| 1633 | MachineState_T machineState;
|
---|
[34645] | 1634 | gpMachine->COMGETTER(State)(&machineState);
|
---|
[1] | 1635 | if (machineState == MachineState_Saved)
|
---|
| 1636 | {
|
---|
[34645] | 1637 | CHECK_ERROR(gpConsole, DiscardSavedState(true /* fDeleteFile */));
|
---|
[1] | 1638 | }
|
---|
| 1639 | /*
|
---|
| 1640 | * If there are snapshots, discard the current state,
|
---|
| 1641 | * i.e. revert to the last snapshot.
|
---|
| 1642 | */
|
---|
| 1643 | ULONG cSnapshots;
|
---|
[34645] | 1644 | gpMachine->COMGETTER(SnapshotCount)(&cSnapshots);
|
---|
[1] | 1645 | if (cSnapshots)
|
---|
| 1646 | {
|
---|
[34645] | 1647 | gpProgress = NULL;
|
---|
[23879] | 1648 |
|
---|
| 1649 | ComPtr<ISnapshot> pCurrentSnapshot;
|
---|
[34645] | 1650 | CHECK_ERROR(gpMachine, COMGETTER(CurrentSnapshot)(pCurrentSnapshot.asOutParam()));
|
---|
[26439] | 1651 | if (FAILED(rc))
|
---|
| 1652 | goto leave;
|
---|
[23879] | 1653 |
|
---|
[34645] | 1654 | CHECK_ERROR(gpConsole, RestoreSnapshot(pCurrentSnapshot, gpProgress.asOutParam()));
|
---|
| 1655 | rc = gpProgress->WaitForCompletion(-1);
|
---|
[1] | 1656 | }
|
---|
| 1657 | }
|
---|
| 1658 |
|
---|
| 1659 | // get the machine debugger (does not have to be there)
|
---|
[34645] | 1660 | gpConsole->COMGETTER(Debugger)(gpMachineDebugger.asOutParam());
|
---|
| 1661 | if (gpMachineDebugger)
|
---|
[1] | 1662 | {
|
---|
| 1663 | Log(("Machine debugger available!\n"));
|
---|
| 1664 | }
|
---|
[34645] | 1665 | gpConsole->COMGETTER(Display)(gpDisplay.asOutParam());
|
---|
| 1666 | if (!gpDisplay)
|
---|
[1] | 1667 | {
|
---|
| 1668 | RTPrintf("Error: could not get display object!\n");
|
---|
| 1669 | goto leave;
|
---|
| 1670 | }
|
---|
| 1671 |
|
---|
| 1672 | // set the boot drive
|
---|
[7207] | 1673 | if (bootDevice != DeviceType_Null)
|
---|
[1] | 1674 | {
|
---|
[34645] | 1675 | rc = gpMachine->SetBootOrder(1, bootDevice);
|
---|
[1] | 1676 | if (rc != S_OK)
|
---|
| 1677 | {
|
---|
| 1678 | RTPrintf("Error: could not set boot device, using default.\n");
|
---|
| 1679 | }
|
---|
| 1680 | }
|
---|
| 1681 |
|
---|
| 1682 | // set the memory size if not default
|
---|
| 1683 | if (memorySize)
|
---|
| 1684 | {
|
---|
[34645] | 1685 | rc = gpMachine->COMSETTER(MemorySize)(memorySize);
|
---|
[1] | 1686 | if (rc != S_OK)
|
---|
| 1687 | {
|
---|
| 1688 | ULONG ramSize = 0;
|
---|
[34645] | 1689 | gpMachine->COMGETTER(MemorySize)(&ramSize);
|
---|
[1] | 1690 | RTPrintf("Error: could not set memory size, using current setting of %d MBytes\n", ramSize);
|
---|
| 1691 | }
|
---|
| 1692 | }
|
---|
| 1693 |
|
---|
| 1694 | if (vramSize)
|
---|
| 1695 | {
|
---|
[34645] | 1696 | rc = gpMachine->COMSETTER(VRAMSize)(vramSize);
|
---|
[1] | 1697 | if (rc != S_OK)
|
---|
| 1698 | {
|
---|
[34645] | 1699 | gpMachine->COMGETTER(VRAMSize)((ULONG*)&vramSize);
|
---|
[1] | 1700 | RTPrintf("Error: could not set VRAM size, using current setting of %d MBytes\n", vramSize);
|
---|
| 1701 | }
|
---|
| 1702 | }
|
---|
| 1703 |
|
---|
| 1704 | // we're always able to process absolute mouse events and we prefer that
|
---|
| 1705 | gfAbsoluteMouseHost = TRUE;
|
---|
| 1706 |
|
---|
| 1707 | #ifdef VBOX_WIN32_UI
|
---|
| 1708 | if (fWin32UI)
|
---|
| 1709 | {
|
---|
| 1710 | /* initialize the Win32 user interface inside which SDL will be embedded */
|
---|
[12449] | 1711 | if (initUI(fResizable, winId))
|
---|
[1] | 1712 | return 1;
|
---|
| 1713 | }
|
---|
| 1714 | #endif
|
---|
| 1715 |
|
---|
[20433] | 1716 | /* static initialization of the SDL stuff */
|
---|
[23170] | 1717 | if (!VBoxSDLFB::init(fShowSDLConfig))
|
---|
| 1718 | goto leave;
|
---|
[1] | 1719 |
|
---|
[34645] | 1720 | gpMachine->COMGETTER(MonitorCount)(&gcMonitors);
|
---|
[20433] | 1721 | if (gcMonitors > 64)
|
---|
| 1722 | gcMonitors = 64;
|
---|
| 1723 |
|
---|
| 1724 | for (unsigned i = 0; i < gcMonitors; i++)
|
---|
[1] | 1725 | {
|
---|
[20433] | 1726 | // create our SDL framebuffer instance
|
---|
| 1727 | gpFramebuffer[i] = new VBoxSDLFB(i, fFullscreen, fResizable, fShowSDLConfig, false,
|
---|
| 1728 | fixedWidth, fixedHeight, fixedBPP);
|
---|
| 1729 |
|
---|
| 1730 | if (!gpFramebuffer[i])
|
---|
| 1731 | {
|
---|
| 1732 | RTPrintf("Error: could not create framebuffer object!\n");
|
---|
| 1733 | goto leave;
|
---|
| 1734 | }
|
---|
[1] | 1735 | }
|
---|
[12449] | 1736 |
|
---|
| 1737 | #ifdef VBOX_WIN32_UI
|
---|
[20433] | 1738 | gpFramebuffer[0]->setWinId(winId);
|
---|
[12449] | 1739 | #endif
|
---|
| 1740 |
|
---|
[20433] | 1741 | for (unsigned i = 0; i < gcMonitors; i++)
|
---|
| 1742 | {
|
---|
| 1743 | if (!gpFramebuffer[i]->initialized())
|
---|
| 1744 | goto leave;
|
---|
| 1745 | gpFramebuffer[i]->AddRef();
|
---|
| 1746 | if (fFullscreen)
|
---|
| 1747 | SetFullscreen(true);
|
---|
| 1748 | }
|
---|
[10501] | 1749 |
|
---|
[1] | 1750 | #ifdef VBOX_SECURELABEL
|
---|
| 1751 | if (fSecureLabel)
|
---|
| 1752 | {
|
---|
| 1753 | if (!secureLabelFontFile)
|
---|
| 1754 | {
|
---|
| 1755 | RTPrintf("Error: no font file specified for secure label!\n");
|
---|
| 1756 | goto leave;
|
---|
| 1757 | }
|
---|
| 1758 | /* load the SDL_ttf library and get the required imports */
|
---|
[22490] | 1759 | vrc = RTLdrLoad(LIBSDL_TTF_NAME, &gLibrarySDL_ttf);
|
---|
| 1760 | if (RT_SUCCESS(vrc))
|
---|
| 1761 | vrc = RTLdrGetSymbol(gLibrarySDL_ttf, "TTF_Init", (void**)&pTTF_Init);
|
---|
| 1762 | if (RT_SUCCESS(vrc))
|
---|
| 1763 | vrc = RTLdrGetSymbol(gLibrarySDL_ttf, "TTF_OpenFont", (void**)&pTTF_OpenFont);
|
---|
| 1764 | if (RT_SUCCESS(vrc))
|
---|
| 1765 | vrc = RTLdrGetSymbol(gLibrarySDL_ttf, "TTF_RenderUTF8_Solid", (void**)&pTTF_RenderUTF8_Solid);
|
---|
| 1766 | if (RT_SUCCESS(vrc))
|
---|
[8144] | 1767 | {
|
---|
| 1768 | /* silently ignore errors here */
|
---|
[22490] | 1769 | vrc = RTLdrGetSymbol(gLibrarySDL_ttf, "TTF_RenderUTF8_Blended", (void**)&pTTF_RenderUTF8_Blended);
|
---|
| 1770 | if (RT_FAILURE(vrc))
|
---|
[8144] | 1771 | pTTF_RenderUTF8_Blended = NULL;
|
---|
[22490] | 1772 | vrc = VINF_SUCCESS;
|
---|
[8144] | 1773 | }
|
---|
[22490] | 1774 | if (RT_SUCCESS(vrc))
|
---|
| 1775 | vrc = RTLdrGetSymbol(gLibrarySDL_ttf, "TTF_CloseFont", (void**)&pTTF_CloseFont);
|
---|
| 1776 | if (RT_SUCCESS(vrc))
|
---|
| 1777 | vrc = RTLdrGetSymbol(gLibrarySDL_ttf, "TTF_Quit", (void**)&pTTF_Quit);
|
---|
| 1778 | if (RT_SUCCESS(vrc))
|
---|
| 1779 | vrc = gpFramebuffer[0]->initSecureLabel(SECURE_LABEL_HEIGHT, secureLabelFontFile, secureLabelPointSize, secureLabelFontOffs);
|
---|
| 1780 | if (RT_FAILURE(vrc))
|
---|
[1] | 1781 | {
|
---|
[22490] | 1782 | RTPrintf("Error: could not initialize secure labeling: rc = %Rrc\n", vrc);
|
---|
[1] | 1783 | goto leave;
|
---|
| 1784 | }
|
---|
[34645] | 1785 | Bstr bstrLabel;
|
---|
| 1786 | gpMachine->GetExtraData(Bstr(VBOXSDL_SECURELABEL_EXTRADATA).raw(), bstrLabel.asOutParam());
|
---|
| 1787 | Utf8Str labelUtf8(bstrLabel);
|
---|
[1] | 1788 | /*
|
---|
| 1789 | * Now update the label
|
---|
| 1790 | */
|
---|
[20433] | 1791 | gpFramebuffer[0]->setSecureLabelColor(secureLabelColorFG, secureLabelColorBG);
|
---|
[31539] | 1792 | gpFramebuffer[0]->setSecureLabelText(labelUtf8.c_str());
|
---|
[1] | 1793 | }
|
---|
| 1794 | #endif
|
---|
| 1795 |
|
---|
[10501] | 1796 | #ifdef VBOXSDL_WITH_X11
|
---|
| 1797 | /* NOTE1: We still want Ctrl-C to work, so we undo the SDL redirections.
|
---|
| 1798 | * NOTE2: We have to remove the PidFile if this file exists. */
|
---|
| 1799 | signal(SIGINT, signal_handler_SIGINT);
|
---|
| 1800 | signal(SIGQUIT, signal_handler_SIGINT);
|
---|
| 1801 | signal(SIGSEGV, signal_handler_SIGINT);
|
---|
| 1802 | #endif
|
---|
| 1803 |
|
---|
[22305] | 1804 |
|
---|
[20435] | 1805 | for (ULONG i = 0; i < gcMonitors; i++)
|
---|
[1] | 1806 | {
|
---|
[20433] | 1807 | // register our framebuffer
|
---|
[34645] | 1808 | rc = gpDisplay->SetFramebuffer(i, gpFramebuffer[i]);
|
---|
[22305] | 1809 | if (FAILED(rc))
|
---|
[20433] | 1810 | {
|
---|
| 1811 | RTPrintf("Error: could not register framebuffer object!\n");
|
---|
| 1812 | goto leave;
|
---|
| 1813 | }
|
---|
| 1814 | IFramebuffer *dummyFb;
|
---|
[20435] | 1815 | LONG xOrigin, yOrigin;
|
---|
[34645] | 1816 | rc = gpDisplay->GetFramebuffer(i, &dummyFb, &xOrigin, &yOrigin);
|
---|
[20433] | 1817 | gpFramebuffer[i]->setOrigin(xOrigin, yOrigin);
|
---|
[1] | 1818 | }
|
---|
| 1819 |
|
---|
[30618] | 1820 | {
|
---|
[34646] | 1821 | // register listener for VirtualBoxClient events
|
---|
| 1822 | ComPtr<IEventSource> pES;
|
---|
| 1823 | CHECK_ERROR(pVirtualBoxClient, COMGETTER(EventSource)(pES.asOutParam()));
|
---|
| 1824 | pVBoxClientListener = new VBoxSDLClientEventListenerImpl();
|
---|
| 1825 | com::SafeArray<VBoxEventType_T> eventTypes;
|
---|
[35172] | 1826 | eventTypes.push_back(VBoxEventType_OnVBoxSVCAvailabilityChanged);
|
---|
[34646] | 1827 | CHECK_ERROR(pES, RegisterListener(pVBoxClientListener, ComSafeArrayAsInParam(eventTypes), true));
|
---|
| 1828 | }
|
---|
| 1829 |
|
---|
| 1830 | {
|
---|
[34645] | 1831 | // register listener for VirtualBox (server) events
|
---|
| 1832 | ComPtr<IEventSource> pES;
|
---|
| 1833 | CHECK_ERROR(pVirtualBox, COMGETTER(EventSource)(pES.asOutParam()));
|
---|
| 1834 | pVBoxListener = new VBoxSDLEventListenerImpl();
|
---|
| 1835 | com::SafeArray<VBoxEventType_T> eventTypes;
|
---|
[30871] | 1836 | eventTypes.push_back(VBoxEventType_OnExtraDataChanged);
|
---|
[34645] | 1837 | CHECK_ERROR(pES, RegisterListener(pVBoxListener, ComSafeArrayAsInParam(eventTypes), true));
|
---|
[30618] | 1838 | }
|
---|
[1] | 1839 |
|
---|
[30618] | 1840 | {
|
---|
[34645] | 1841 | // register listener for Console events
|
---|
| 1842 | ComPtr<IEventSource> pES;
|
---|
| 1843 | CHECK_ERROR(gpConsole, COMGETTER(EventSource)(pES.asOutParam()));
|
---|
| 1844 | pConsoleListener = new VBoxSDLConsoleEventListenerImpl();
|
---|
| 1845 | com::SafeArray<VBoxEventType_T> eventTypes;
|
---|
[30871] | 1846 | eventTypes.push_back(VBoxEventType_OnMousePointerShapeChanged);
|
---|
| 1847 | eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
|
---|
| 1848 | eventTypes.push_back(VBoxEventType_OnKeyboardLedsChanged);
|
---|
| 1849 | eventTypes.push_back(VBoxEventType_OnStateChanged);
|
---|
[30618] | 1850 | eventTypes.push_back(VBoxEventType_OnRuntimeError);
|
---|
| 1851 | eventTypes.push_back(VBoxEventType_OnCanShowWindow);
|
---|
| 1852 | eventTypes.push_back(VBoxEventType_OnShowWindow);
|
---|
[34645] | 1853 | CHECK_ERROR(pES, RegisterListener(pConsoleListener, ComSafeArrayAsInParam(eventTypes), true));
|
---|
[30618] | 1854 | // until we've tried to to start the VM, ignore power off events
|
---|
[34645] | 1855 | pConsoleListener->getWrapped()->ignorePowerOffEvents(true);
|
---|
[30618] | 1856 | }
|
---|
[1] | 1857 |
|
---|
[23643] | 1858 | if (portVRDP)
|
---|
[1] | 1859 | {
|
---|
[34645] | 1860 | rc = gpMachine->COMGETTER(VRDEServer)(gpVRDEServer.asOutParam());
|
---|
| 1861 | AssertMsg((rc == S_OK) && gpVRDEServer, ("Could not get VRDP Server! rc = 0x%x\n", rc));
|
---|
| 1862 | if (gpVRDEServer)
|
---|
[1] | 1863 | {
|
---|
| 1864 | // has a non standard VRDP port been requested?
|
---|
| 1865 | if (portVRDP > 0)
|
---|
| 1866 | {
|
---|
[34645] | 1867 | rc = gpVRDEServer->SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr(portVRDP).raw());
|
---|
[1] | 1868 | if (rc != S_OK)
|
---|
| 1869 | {
|
---|
| 1870 | RTPrintf("Error: could not set VRDP port! rc = 0x%x\n", rc);
|
---|
| 1871 | goto leave;
|
---|
| 1872 | }
|
---|
| 1873 | }
|
---|
| 1874 | // now enable VRDP
|
---|
[34645] | 1875 | rc = gpVRDEServer->COMSETTER(Enabled)(TRUE);
|
---|
[1] | 1876 | if (rc != S_OK)
|
---|
| 1877 | {
|
---|
| 1878 | RTPrintf("Error: could not enable VRDP server! rc = 0x%x\n", rc);
|
---|
| 1879 | goto leave;
|
---|
| 1880 | }
|
---|
| 1881 | }
|
---|
| 1882 | }
|
---|
| 1883 |
|
---|
| 1884 | rc = E_FAIL;
|
---|
| 1885 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
| 1886 | if (fRawR0 != ~0U)
|
---|
| 1887 | {
|
---|
[34645] | 1888 | if (!gpMachineDebugger)
|
---|
[1] | 1889 | {
|
---|
| 1890 | RTPrintf("Error: No debugger object; -%srawr0 cannot be executed!\n", fRawR0 ? "" : "no");
|
---|
| 1891 | goto leave;
|
---|
| 1892 | }
|
---|
[34645] | 1893 | gpMachineDebugger->COMSETTER(RecompileSupervisor)(!fRawR0);
|
---|
[1] | 1894 | }
|
---|
| 1895 | if (fRawR3 != ~0U)
|
---|
| 1896 | {
|
---|
[34645] | 1897 | if (!gpMachineDebugger)
|
---|
[1] | 1898 | {
|
---|
| 1899 | RTPrintf("Error: No debugger object; -%srawr3 cannot be executed!\n", fRawR0 ? "" : "no");
|
---|
| 1900 | goto leave;
|
---|
| 1901 | }
|
---|
[34645] | 1902 | gpMachineDebugger->COMSETTER(RecompileUser)(!fRawR3);
|
---|
[1] | 1903 | }
|
---|
| 1904 | if (fPATM != ~0U)
|
---|
| 1905 | {
|
---|
[34645] | 1906 | if (!gpMachineDebugger)
|
---|
[1] | 1907 | {
|
---|
| 1908 | RTPrintf("Error: No debugger object; -%spatm cannot be executed!\n", fRawR0 ? "" : "no");
|
---|
| 1909 | goto leave;
|
---|
| 1910 | }
|
---|
[34645] | 1911 | gpMachineDebugger->COMSETTER(PATMEnabled)(fPATM);
|
---|
[1] | 1912 | }
|
---|
| 1913 | if (fCSAM != ~0U)
|
---|
| 1914 | {
|
---|
[34645] | 1915 | if (!gpMachineDebugger)
|
---|
[1] | 1916 | {
|
---|
| 1917 | RTPrintf("Error: No debugger object; -%scsam cannot be executed!\n", fRawR0 ? "" : "no");
|
---|
| 1918 | goto leave;
|
---|
| 1919 | }
|
---|
[34645] | 1920 | gpMachineDebugger->COMSETTER(CSAMEnabled)(fCSAM);
|
---|
[1] | 1921 | }
|
---|
[21446] | 1922 | if (fHWVirt != ~0U)
|
---|
[1] | 1923 | {
|
---|
[34645] | 1924 | gpMachine->SetHWVirtExProperty(HWVirtExPropertyType_Enabled, fHWVirt);
|
---|
[1] | 1925 | }
|
---|
[445] | 1926 | if (u32WarpDrive != 0)
|
---|
| 1927 | {
|
---|
[34645] | 1928 | if (!gpMachineDebugger)
|
---|
[445] | 1929 | {
|
---|
[18751] | 1930 | RTPrintf("Error: No debugger object; --warpdrive %d cannot be executed!\n", u32WarpDrive);
|
---|
[445] | 1931 | goto leave;
|
---|
| 1932 | }
|
---|
[34645] | 1933 | gpMachineDebugger->COMSETTER(VirtualTimeRate)(u32WarpDrive);
|
---|
[445] | 1934 | }
|
---|
[1] | 1935 | #endif /* VBOXSDL_ADVANCED_OPTIONS */
|
---|
| 1936 |
|
---|
| 1937 | /* start with something in the titlebar */
|
---|
| 1938 | UpdateTitlebar(TITLEBAR_NORMAL);
|
---|
| 1939 |
|
---|
| 1940 | /* memorize the default cursor */
|
---|
| 1941 | gpDefaultCursor = SDL_GetCursor();
|
---|
| 1942 |
|
---|
[20433] | 1943 | #if !defined(VBOX_WITH_SDL13)
|
---|
| 1944 | # if defined(VBOXSDL_WITH_X11)
|
---|
[1] | 1945 | /* Get Window Manager info. We only need the X11 display. */
|
---|
| 1946 | SDL_VERSION(&gSdlInfo.version);
|
---|
| 1947 | if (!SDL_GetWMInfo(&gSdlInfo))
|
---|
[18793] | 1948 | RTPrintf("Error: could not get SDL Window Manager info -- no Xcursor support!\n");
|
---|
[20433] | 1949 | else
|
---|
| 1950 | gfXCursorEnabled = TRUE;
|
---|
[1] | 1951 |
|
---|
[20433] | 1952 | # if !defined(VBOX_WITHOUT_XCURSOR)
|
---|
[1] | 1953 | /* SDL uses its own (plain) default cursor. Use the left arrow cursor instead which might look
|
---|
| 1954 | * much better if a mouse cursor theme is installed. */
|
---|
[18793] | 1955 | if (gfXCursorEnabled)
|
---|
| 1956 | {
|
---|
| 1957 | gpDefaultOrigX11Cursor = *(Cursor*)gpDefaultCursor->wm_cursor;
|
---|
| 1958 | *(Cursor*)gpDefaultCursor->wm_cursor = XCreateFontCursor(gSdlInfo.info.x11.display, XC_left_ptr);
|
---|
| 1959 | SDL_SetCursor(gpDefaultCursor);
|
---|
| 1960 | }
|
---|
[20433] | 1961 | # endif
|
---|
[29655] | 1962 | /* Initialise the keyboard */
|
---|
[32874] | 1963 | X11DRV_InitKeyboard(gSdlInfo.info.x11.display, NULL, NULL, NULL, NULL);
|
---|
[20433] | 1964 | # endif /* VBOXSDL_WITH_X11 */
|
---|
[1] | 1965 |
|
---|
| 1966 | /* create a fake empty cursor */
|
---|
| 1967 | {
|
---|
| 1968 | uint8_t cursorData[1] = {0};
|
---|
| 1969 | gpCustomCursor = SDL_CreateCursor(cursorData, cursorData, 8, 1, 0, 0);
|
---|
| 1970 | gpCustomOrigWMcursor = gpCustomCursor->wm_cursor;
|
---|
| 1971 | gpCustomCursor->wm_cursor = NULL;
|
---|
| 1972 | }
|
---|
[20433] | 1973 | #endif /* !VBOX_WITH_SDL13 */
|
---|
[1] | 1974 |
|
---|
| 1975 | /*
|
---|
| 1976 | * Register our user signal handler.
|
---|
| 1977 | */
|
---|
[4637] | 1978 | #ifdef VBOXSDL_WITH_X11
|
---|
[1] | 1979 | struct sigaction sa;
|
---|
[10501] | 1980 | sa.sa_sigaction = signal_handler_SIGUSR1;
|
---|
[28205] | 1981 | sigemptyset(&sa.sa_mask);
|
---|
[1] | 1982 | sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
---|
[28205] | 1983 | sigaction(SIGUSR1, &sa, NULL);
|
---|
[4637] | 1984 | #endif /* VBOXSDL_WITH_X11 */
|
---|
[1] | 1985 |
|
---|
| 1986 | /*
|
---|
| 1987 | * Start the VM execution thread. This has to be done
|
---|
| 1988 | * asynchronously as powering up can take some time
|
---|
| 1989 | * (accessing devices such as the host DVD drive). In
|
---|
| 1990 | * the meantime, we have to service the SDL event loop.
|
---|
| 1991 | */
|
---|
| 1992 | SDL_Event event;
|
---|
| 1993 |
|
---|
| 1994 | LogFlow(("Powering up the VM...\n"));
|
---|
[34645] | 1995 | rc = gpConsole->PowerUp(gpProgress.asOutParam());
|
---|
[1] | 1996 | if (rc != S_OK)
|
---|
| 1997 | {
|
---|
[34645] | 1998 | com::ErrorInfo info(gpConsole, COM_IIDOF(IConsole));
|
---|
[1] | 1999 | if (info.isBasicAvailable())
|
---|
| 2000 | PrintError("Failed to power up VM", info.getText().raw());
|
---|
| 2001 | else
|
---|
| 2002 | RTPrintf("Error: failed to power up VM! No error text available.\n");
|
---|
| 2003 | goto leave;
|
---|
| 2004 | }
|
---|
| 2005 |
|
---|
[967] | 2006 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
[1] | 2007 | /*
|
---|
| 2008 | * Before we starting to do stuff, we have to launch the XPCOM
|
---|
| 2009 | * event queue thread. It will wait for events and send messages
|
---|
| 2010 | * to the SDL thread. After having done this, we should fairly
|
---|
| 2011 | * quickly start to process the SDL event queue as an XPCOM
|
---|
| 2012 | * event storm might arrive. Stupid SDL has a ridiculously small
|
---|
| 2013 | * event queue buffer!
|
---|
| 2014 | */
|
---|
[22911] | 2015 | startXPCOMEventQueueThread(eventQ->getSelectFD());
|
---|
[967] | 2016 | #endif /* USE_XPCOM_QUEUE_THREAD */
|
---|
[1] | 2017 |
|
---|
| 2018 | /* termination flag */
|
---|
| 2019 | bool fTerminateDuringStartup;
|
---|
| 2020 | fTerminateDuringStartup = false;
|
---|
| 2021 |
|
---|
[3176] | 2022 | LogRel(("VBoxSDL: NUM lock initially %s, CAPS lock initially %s\n",
|
---|
[34645] | 2023 | !!(SDL_GetModState() & KMOD_NUM) ? "ON" : "OFF",
|
---|
| 2024 | !!(SDL_GetModState() & KMOD_CAPS) ? "ON" : "OFF"));
|
---|
[3176] | 2025 |
|
---|
[1] | 2026 | /* start regular timer so we don't starve in the event loop */
|
---|
| 2027 | SDL_TimerID sdlTimer;
|
---|
| 2028 | sdlTimer = SDL_AddTimer(100, StartupTimer, NULL);
|
---|
| 2029 |
|
---|
| 2030 | /* loop until the powerup processing is done */
|
---|
| 2031 | MachineState_T machineState;
|
---|
| 2032 | do
|
---|
| 2033 | {
|
---|
[34645] | 2034 | rc = gpMachine->COMGETTER(State)(&machineState);
|
---|
[1] | 2035 | if ( rc == S_OK
|
---|
| 2036 | && ( machineState == MachineState_Starting
|
---|
[23703] | 2037 | || machineState == MachineState_Restoring
|
---|
[24301] | 2038 | || machineState == MachineState_TeleportingIn
|
---|
| 2039 | )
|
---|
[23703] | 2040 | )
|
---|
[1] | 2041 | {
|
---|
| 2042 | /*
|
---|
| 2043 | * wait for the next event. This is uncritical as
|
---|
| 2044 | * power up guarantees to change the machine state
|
---|
| 2045 | * to either running or aborted and a machine state
|
---|
| 2046 | * change will send us an event. However, we have to
|
---|
| 2047 | * service the XPCOM event queue!
|
---|
| 2048 | */
|
---|
[967] | 2049 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
[1] | 2050 | if (!fXPCOMEventThreadSignaled)
|
---|
| 2051 | {
|
---|
| 2052 | signalXPCOMEventQueueThread();
|
---|
| 2053 | fXPCOMEventThreadSignaled = true;
|
---|
| 2054 | }
|
---|
| 2055 | #endif
|
---|
| 2056 | /*
|
---|
| 2057 | * Wait for SDL events.
|
---|
| 2058 | */
|
---|
[3289] | 2059 | if (WaitSDLEvent(&event))
|
---|
[1] | 2060 | {
|
---|
| 2061 | switch (event.type)
|
---|
| 2062 | {
|
---|
| 2063 | /*
|
---|
| 2064 | * Timer event. Used to have the titlebar updated.
|
---|
| 2065 | */
|
---|
| 2066 | case SDL_USER_EVENT_TIMER:
|
---|
| 2067 | {
|
---|
| 2068 | /*
|
---|
| 2069 | * Update the title bar.
|
---|
| 2070 | */
|
---|
| 2071 | UpdateTitlebar(TITLEBAR_STARTUP);
|
---|
| 2072 | break;
|
---|
| 2073 | }
|
---|
| 2074 |
|
---|
| 2075 | /*
|
---|
| 2076 | * User specific resize event.
|
---|
| 2077 | */
|
---|
| 2078 | case SDL_USER_EVENT_RESIZE:
|
---|
| 2079 | {
|
---|
| 2080 | LogFlow(("SDL_USER_EVENT_RESIZE\n"));
|
---|
[20433] | 2081 | IFramebuffer *dummyFb;
|
---|
[20436] | 2082 | LONG xOrigin, yOrigin;
|
---|
[20433] | 2083 | gpFramebuffer[event.user.code]->resizeGuest();
|
---|
| 2084 | /* update xOrigin, yOrigin -> mouse */
|
---|
[34645] | 2085 | rc = gpDisplay->GetFramebuffer(event.user.code, &dummyFb, &xOrigin, &yOrigin);
|
---|
[20433] | 2086 | gpFramebuffer[event.user.code]->setOrigin(xOrigin, yOrigin);
|
---|
[1] | 2087 | /* notify the display that the resize has been completed */
|
---|
[34645] | 2088 | gpDisplay->ResizeCompleted(event.user.code);
|
---|
[1] | 2089 | break;
|
---|
| 2090 | }
|
---|
| 2091 |
|
---|
[967] | 2092 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
[1] | 2093 | /*
|
---|
| 2094 | * User specific XPCOM event queue event
|
---|
| 2095 | */
|
---|
| 2096 | case SDL_USER_EVENT_XPCOM_EVENTQUEUE:
|
---|
| 2097 | {
|
---|
| 2098 | LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
|
---|
[22911] | 2099 | eventQ->processEventQueue(0);
|
---|
[1] | 2100 | signalXPCOMEventQueueThread();
|
---|
| 2101 | break;
|
---|
| 2102 | }
|
---|
[967] | 2103 | #endif /* USE_XPCOM_QUEUE_THREAD */
|
---|
[1] | 2104 |
|
---|
| 2105 | /*
|
---|
| 2106 | * Termination event from the on state change callback.
|
---|
| 2107 | */
|
---|
| 2108 | case SDL_USER_EVENT_TERMINATE:
|
---|
| 2109 | {
|
---|
| 2110 | if (event.user.code != VBOXSDL_TERM_NORMAL)
|
---|
| 2111 | {
|
---|
[34645] | 2112 | com::ProgressErrorInfo info(gpProgress);
|
---|
[1] | 2113 | if (info.isBasicAvailable())
|
---|
| 2114 | PrintError("Failed to power up VM", info.getText().raw());
|
---|
| 2115 | else
|
---|
| 2116 | RTPrintf("Error: failed to power up VM! No error text available.\n");
|
---|
| 2117 | }
|
---|
| 2118 | fTerminateDuringStartup = true;
|
---|
| 2119 | break;
|
---|
| 2120 | }
|
---|
| 2121 |
|
---|
| 2122 | default:
|
---|
| 2123 | {
|
---|
| 2124 | LogBird(("VBoxSDL: Unknown SDL event %d (pre)\n", event.type));
|
---|
| 2125 | break;
|
---|
| 2126 | }
|
---|
| 2127 | }
|
---|
| 2128 |
|
---|
| 2129 | }
|
---|
| 2130 | }
|
---|
[22911] | 2131 | eventQ->processEventQueue(0);
|
---|
[1] | 2132 | } while ( rc == S_OK
|
---|
| 2133 | && ( machineState == MachineState_Starting
|
---|
[23703] | 2134 | || machineState == MachineState_Restoring
|
---|
[24301] | 2135 | || machineState == MachineState_TeleportingIn
|
---|
| 2136 | )
|
---|
[23703] | 2137 | );
|
---|
[1] | 2138 |
|
---|
| 2139 | /* kill the timer again */
|
---|
| 2140 | SDL_RemoveTimer(sdlTimer);
|
---|
| 2141 | sdlTimer = 0;
|
---|
| 2142 |
|
---|
| 2143 | /* are we supposed to terminate the process? */
|
---|
| 2144 | if (fTerminateDuringStartup)
|
---|
| 2145 | goto leave;
|
---|
| 2146 |
|
---|
| 2147 | /* did the power up succeed? */
|
---|
| 2148 | if (machineState != MachineState_Running)
|
---|
| 2149 | {
|
---|
[34645] | 2150 | com::ProgressErrorInfo info(gpProgress);
|
---|
[1] | 2151 | if (info.isBasicAvailable())
|
---|
| 2152 | PrintError("Failed to power up VM", info.getText().raw());
|
---|
| 2153 | else
|
---|
| 2154 | RTPrintf("Error: failed to power up VM! No error text available (rc = 0x%x state = %d)\n", rc, machineState);
|
---|
| 2155 | goto leave;
|
---|
| 2156 | }
|
---|
| 2157 |
|
---|
| 2158 | // accept power off events from now on because we're running
|
---|
| 2159 | // note that there's a possible race condition here...
|
---|
[34645] | 2160 | pConsoleListener->getWrapped()->ignorePowerOffEvents(false);
|
---|
[1] | 2161 |
|
---|
[34645] | 2162 | rc = gpConsole->COMGETTER(Keyboard)(gpKeyboard.asOutParam());
|
---|
| 2163 | if (!gpKeyboard)
|
---|
[1] | 2164 | {
|
---|
| 2165 | RTPrintf("Error: could not get keyboard object!\n");
|
---|
| 2166 | goto leave;
|
---|
| 2167 | }
|
---|
[34645] | 2168 | gpConsole->COMGETTER(Mouse)(gpMouse.asOutParam());
|
---|
| 2169 | if (!gpMouse)
|
---|
[1] | 2170 | {
|
---|
| 2171 | RTPrintf("Error: could not get mouse object!\n");
|
---|
| 2172 | goto leave;
|
---|
| 2173 | }
|
---|
| 2174 |
|
---|
| 2175 | UpdateTitlebar(TITLEBAR_NORMAL);
|
---|
| 2176 |
|
---|
| 2177 | /*
|
---|
| 2178 | * Enable keyboard repeats
|
---|
| 2179 | */
|
---|
| 2180 | SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
---|
| 2181 |
|
---|
| 2182 | /*
|
---|
[10501] | 2183 | * Create PID file.
|
---|
| 2184 | */
|
---|
| 2185 | if (gpszPidFile)
|
---|
| 2186 | {
|
---|
| 2187 | char szBuf[32];
|
---|
| 2188 | const char *pcszLf = "\n";
|
---|
| 2189 | RTFILE PidFile;
|
---|
[23973] | 2190 | RTFileOpen(&PidFile, gpszPidFile, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE);
|
---|
[10501] | 2191 | RTStrFormatNumber(szBuf, RTProcSelf(), 10, 0, 0, 0);
|
---|
| 2192 | RTFileWrite(PidFile, szBuf, strlen(szBuf), NULL);
|
---|
| 2193 | RTFileWrite(PidFile, pcszLf, strlen(pcszLf), NULL);
|
---|
| 2194 | RTFileClose(PidFile);
|
---|
| 2195 | }
|
---|
| 2196 |
|
---|
| 2197 | /*
|
---|
[1] | 2198 | * Main event loop
|
---|
| 2199 | */
|
---|
[967] | 2200 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
[1] | 2201 | if (!fXPCOMEventThreadSignaled)
|
---|
| 2202 | {
|
---|
| 2203 | signalXPCOMEventQueueThread();
|
---|
| 2204 | }
|
---|
| 2205 | #endif
|
---|
| 2206 | LogFlow(("VBoxSDL: Entering big event loop\n"));
|
---|
[3289] | 2207 | while (WaitSDLEvent(&event))
|
---|
[1] | 2208 | {
|
---|
| 2209 | switch (event.type)
|
---|
| 2210 | {
|
---|
| 2211 | /*
|
---|
| 2212 | * The screen needs to be repainted.
|
---|
| 2213 | */
|
---|
[20433] | 2214 | #ifdef VBOX_WITH_SDL13
|
---|
| 2215 | case SDL_WINDOWEVENT:
|
---|
| 2216 | {
|
---|
| 2217 | switch (event.window.event)
|
---|
| 2218 | {
|
---|
| 2219 | case SDL_WINDOWEVENT_EXPOSED:
|
---|
| 2220 | {
|
---|
| 2221 | VBoxSDLFB *fb = getFbFromWinId(event.window.windowID);
|
---|
| 2222 | if (fb)
|
---|
| 2223 | fb->repaint();
|
---|
| 2224 | break;
|
---|
| 2225 | }
|
---|
| 2226 | case SDL_WINDOWEVENT_FOCUS_GAINED:
|
---|
| 2227 | {
|
---|
| 2228 | break;
|
---|
| 2229 | }
|
---|
| 2230 | default:
|
---|
| 2231 | break;
|
---|
| 2232 | }
|
---|
| 2233 | }
|
---|
[20842] | 2234 | #else
|
---|
[1] | 2235 | case SDL_VIDEOEXPOSE:
|
---|
| 2236 | {
|
---|
[20433] | 2237 | gpFramebuffer[0]->repaint();
|
---|
[1] | 2238 | break;
|
---|
| 2239 | }
|
---|
[20433] | 2240 | #endif
|
---|
[1] | 2241 |
|
---|
| 2242 | /*
|
---|
| 2243 | * Keyboard events.
|
---|
| 2244 | */
|
---|
| 2245 | case SDL_KEYDOWN:
|
---|
| 2246 | case SDL_KEYUP:
|
---|
| 2247 | {
|
---|
| 2248 | SDLKey ksym = event.key.keysym.sym;
|
---|
| 2249 |
|
---|
| 2250 | switch (enmHKeyState)
|
---|
| 2251 | {
|
---|
| 2252 | case HKEYSTATE_NORMAL:
|
---|
| 2253 | {
|
---|
| 2254 | if ( event.type == SDL_KEYDOWN
|
---|
| 2255 | && ksym != SDLK_UNKNOWN
|
---|
| 2256 | && (ksym == gHostKeySym1 || ksym == gHostKeySym2))
|
---|
| 2257 | {
|
---|
| 2258 | EvHKeyDown1 = event;
|
---|
| 2259 | enmHKeyState = ksym == gHostKeySym1 ? HKEYSTATE_DOWN_1ST
|
---|
| 2260 | : HKEYSTATE_DOWN_2ND;
|
---|
| 2261 | break;
|
---|
| 2262 | }
|
---|
| 2263 | ProcessKey(&event.key);
|
---|
| 2264 | break;
|
---|
| 2265 | }
|
---|
| 2266 |
|
---|
| 2267 | case HKEYSTATE_DOWN_1ST:
|
---|
| 2268 | case HKEYSTATE_DOWN_2ND:
|
---|
| 2269 | {
|
---|
| 2270 | if (gHostKeySym2 != SDLK_UNKNOWN)
|
---|
| 2271 | {
|
---|
| 2272 | if ( event.type == SDL_KEYDOWN
|
---|
| 2273 | && ksym != SDLK_UNKNOWN
|
---|
[5917] | 2274 | && ( (enmHKeyState == HKEYSTATE_DOWN_1ST && ksym == gHostKeySym2)
|
---|
| 2275 | || (enmHKeyState == HKEYSTATE_DOWN_2ND && ksym == gHostKeySym1)))
|
---|
[1] | 2276 | {
|
---|
| 2277 | EvHKeyDown2 = event;
|
---|
| 2278 | enmHKeyState = HKEYSTATE_DOWN;
|
---|
| 2279 | break;
|
---|
| 2280 | }
|
---|
[614] | 2281 | enmHKeyState = event.type == SDL_KEYUP ? HKEYSTATE_NORMAL
|
---|
[1] | 2282 | : HKEYSTATE_NOT_IT;
|
---|
| 2283 | ProcessKey(&EvHKeyDown1.key);
|
---|
[28405] | 2284 | /* ugly hack: Some guests (e.g. mstsc.exe on Windows XP)
|
---|
| 2285 | * expect a small delay between two key events. 5ms work
|
---|
| 2286 | * reliable here so use 10ms to be on the safe side. A
|
---|
| 2287 | * better but more complicated fix would be to introduce
|
---|
| 2288 | * a new state and don't wait here. */
|
---|
| 2289 | RTThreadSleep(10);
|
---|
[1] | 2290 | ProcessKey(&event.key);
|
---|
| 2291 | break;
|
---|
| 2292 | }
|
---|
| 2293 | /* fall through if no two-key sequence is used */
|
---|
| 2294 | }
|
---|
| 2295 |
|
---|
| 2296 | case HKEYSTATE_DOWN:
|
---|
| 2297 | {
|
---|
| 2298 | if (event.type == SDL_KEYDOWN)
|
---|
| 2299 | {
|
---|
| 2300 | /* potential host key combination, try execute it */
|
---|
[25013] | 2301 | int irc = HandleHostKey(&event.key);
|
---|
| 2302 | if (irc == VINF_SUCCESS)
|
---|
[1] | 2303 | {
|
---|
| 2304 | enmHKeyState = HKEYSTATE_USED;
|
---|
| 2305 | break;
|
---|
| 2306 | }
|
---|
[25013] | 2307 | if (RT_SUCCESS(irc))
|
---|
[1] | 2308 | goto leave;
|
---|
| 2309 | }
|
---|
| 2310 | else /* SDL_KEYUP */
|
---|
| 2311 | {
|
---|
| 2312 | if ( ksym != SDLK_UNKNOWN
|
---|
| 2313 | && (ksym == gHostKeySym1 || ksym == gHostKeySym2))
|
---|
| 2314 | {
|
---|
| 2315 | /* toggle grabbing state */
|
---|
| 2316 | if (!gfGrabbed)
|
---|
| 2317 | InputGrabStart();
|
---|
| 2318 | else
|
---|
| 2319 | InputGrabEnd();
|
---|
| 2320 |
|
---|
| 2321 | /* SDL doesn't always reset the keystates, correct it */
|
---|
| 2322 | ResetKeys();
|
---|
| 2323 | enmHKeyState = HKEYSTATE_NORMAL;
|
---|
| 2324 | break;
|
---|
| 2325 | }
|
---|
| 2326 | }
|
---|
| 2327 |
|
---|
| 2328 | /* not host key */
|
---|
| 2329 | enmHKeyState = HKEYSTATE_NOT_IT;
|
---|
| 2330 | ProcessKey(&EvHKeyDown1.key);
|
---|
[28405] | 2331 | /* see the comment for the 2-key case above */
|
---|
| 2332 | RTThreadSleep(10);
|
---|
[1] | 2333 | if (gHostKeySym2 != SDLK_UNKNOWN)
|
---|
[28405] | 2334 | {
|
---|
[1] | 2335 | ProcessKey(&EvHKeyDown2.key);
|
---|
[28405] | 2336 | /* see the comment for the 2-key case above */
|
---|
| 2337 | RTThreadSleep(10);
|
---|
| 2338 | }
|
---|
[1] | 2339 | ProcessKey(&event.key);
|
---|
| 2340 | break;
|
---|
| 2341 | }
|
---|
| 2342 |
|
---|
| 2343 | case HKEYSTATE_USED:
|
---|
| 2344 | {
|
---|
| 2345 | if ((SDL_GetModState() & ~(KMOD_MODE | KMOD_NUM | KMOD_RESERVED)) == 0)
|
---|
| 2346 | enmHKeyState = HKEYSTATE_NORMAL;
|
---|
| 2347 | if (event.type == SDL_KEYDOWN)
|
---|
| 2348 | {
|
---|
[25013] | 2349 | int irc = HandleHostKey(&event.key);
|
---|
| 2350 | if (RT_SUCCESS(irc) && irc != VINF_SUCCESS)
|
---|
[1] | 2351 | goto leave;
|
---|
| 2352 | }
|
---|
| 2353 | break;
|
---|
| 2354 | }
|
---|
| 2355 |
|
---|
| 2356 | default:
|
---|
| 2357 | AssertMsgFailed(("enmHKeyState=%d\n", enmHKeyState));
|
---|
| 2358 | /* fall thru */
|
---|
| 2359 | case HKEYSTATE_NOT_IT:
|
---|
| 2360 | {
|
---|
| 2361 | if ((SDL_GetModState() & ~(KMOD_MODE | KMOD_NUM | KMOD_RESERVED)) == 0)
|
---|
| 2362 | enmHKeyState = HKEYSTATE_NORMAL;
|
---|
| 2363 | ProcessKey(&event.key);
|
---|
| 2364 | break;
|
---|
| 2365 | }
|
---|
| 2366 | } /* state switch */
|
---|
| 2367 | break;
|
---|
| 2368 | }
|
---|
| 2369 |
|
---|
| 2370 | /*
|
---|
| 2371 | * The window was closed.
|
---|
| 2372 | */
|
---|
| 2373 | case SDL_QUIT:
|
---|
| 2374 | {
|
---|
[6852] | 2375 | if (!gfACPITerm || gSdlQuitTimer)
|
---|
[6437] | 2376 | goto leave;
|
---|
[34645] | 2377 | if (gpConsole)
|
---|
| 2378 | gpConsole->PowerButton();
|
---|
[6852] | 2379 | gSdlQuitTimer = SDL_AddTimer(1000, QuitTimer, NULL);
|
---|
[1] | 2380 | break;
|
---|
| 2381 | }
|
---|
| 2382 |
|
---|
| 2383 | /*
|
---|
| 2384 | * The mouse has moved
|
---|
| 2385 | */
|
---|
| 2386 | case SDL_MOUSEMOTION:
|
---|
| 2387 | {
|
---|
| 2388 | if (gfGrabbed || UseAbsoluteMouse())
|
---|
| 2389 | {
|
---|
[20433] | 2390 | VBoxSDLFB *fb;
|
---|
| 2391 | #ifdef VBOX_WITH_SDL13
|
---|
| 2392 | fb = getFbFromWinId(event.motion.windowID);
|
---|
| 2393 | #else
|
---|
[20611] | 2394 | fb = gpFramebuffer[0];
|
---|
[20433] | 2395 | #endif
|
---|
| 2396 | SendMouseEvent(fb, 0, 0, 0);
|
---|
[1] | 2397 | }
|
---|
| 2398 | break;
|
---|
| 2399 | }
|
---|
| 2400 |
|
---|
| 2401 | /*
|
---|
| 2402 | * A mouse button has been clicked or released.
|
---|
| 2403 | */
|
---|
| 2404 | case SDL_MOUSEBUTTONDOWN:
|
---|
| 2405 | case SDL_MOUSEBUTTONUP:
|
---|
| 2406 | {
|
---|
| 2407 | SDL_MouseButtonEvent *bev = &event.button;
|
---|
| 2408 | /* don't grab on mouse click if we have guest additions */
|
---|
| 2409 | if (!gfGrabbed && !UseAbsoluteMouse() && gfGrabOnMouseClick)
|
---|
| 2410 | {
|
---|
| 2411 | if (event.type == SDL_MOUSEBUTTONDOWN && (bev->state & SDL_BUTTON_LMASK))
|
---|
| 2412 | {
|
---|
| 2413 | /* start grabbing all events */
|
---|
| 2414 | InputGrabStart();
|
---|
| 2415 | }
|
---|
| 2416 | }
|
---|
[435] | 2417 | else if (gfGrabbed || UseAbsoluteMouse())
|
---|
[1] | 2418 | {
|
---|
| 2419 | int dz = bev->button == SDL_BUTTON_WHEELUP
|
---|
| 2420 | ? -1
|
---|
| 2421 | : bev->button == SDL_BUTTON_WHEELDOWN
|
---|
| 2422 | ? +1
|
---|
| 2423 | : 0;
|
---|
| 2424 |
|
---|
| 2425 | /* end host key combination (CTRL+MouseButton) */
|
---|
| 2426 | switch (enmHKeyState)
|
---|
| 2427 | {
|
---|
| 2428 | case HKEYSTATE_DOWN_1ST:
|
---|
| 2429 | case HKEYSTATE_DOWN_2ND:
|
---|
| 2430 | enmHKeyState = HKEYSTATE_NOT_IT;
|
---|
| 2431 | ProcessKey(&EvHKeyDown1.key);
|
---|
[19579] | 2432 | /* ugly hack: small delay to ensure that the key event is
|
---|
| 2433 | * actually handled _prior_ to the mouse click event */
|
---|
| 2434 | RTThreadSleep(20);
|
---|
[1] | 2435 | break;
|
---|
| 2436 | case HKEYSTATE_DOWN:
|
---|
| 2437 | enmHKeyState = HKEYSTATE_NOT_IT;
|
---|
| 2438 | ProcessKey(&EvHKeyDown1.key);
|
---|
| 2439 | if (gHostKeySym2 != SDLK_UNKNOWN)
|
---|
| 2440 | ProcessKey(&EvHKeyDown2.key);
|
---|
[19579] | 2441 | /* ugly hack: small delay to ensure that the key event is
|
---|
| 2442 | * actually handled _prior_ to the mouse click event */
|
---|
| 2443 | RTThreadSleep(20);
|
---|
[1] | 2444 | break;
|
---|
| 2445 | default:
|
---|
| 2446 | break;
|
---|
| 2447 | }
|
---|
| 2448 |
|
---|
[20433] | 2449 | VBoxSDLFB *fb;
|
---|
| 2450 | #ifdef VBOX_WITH_SDL13
|
---|
| 2451 | fb = getFbFromWinId(event.button.windowID);
|
---|
| 2452 | #else
|
---|
[20611] | 2453 | fb = gpFramebuffer[0];
|
---|
[20433] | 2454 | #endif
|
---|
| 2455 | SendMouseEvent(fb, dz, event.type == SDL_MOUSEBUTTONDOWN, bev->button);
|
---|
[1] | 2456 | }
|
---|
| 2457 | break;
|
---|
| 2458 | }
|
---|
| 2459 |
|
---|
| 2460 | /*
|
---|
| 2461 | * The window has gained or lost focus.
|
---|
| 2462 | */
|
---|
| 2463 | case SDL_ACTIVEEVENT:
|
---|
| 2464 | {
|
---|
| 2465 | /*
|
---|
| 2466 | * There is a strange behaviour in SDL when running without a window
|
---|
| 2467 | * manager: When SDL_WM_GrabInput(SDL_GRAB_ON) is called we receive two
|
---|
| 2468 | * consecutive events SDL_ACTIVEEVENTs (input lost, input gained).
|
---|
| 2469 | * Asking SDL_GetAppState() seems the better choice.
|
---|
| 2470 | */
|
---|
| 2471 | if (gfGrabbed && (SDL_GetAppState() & SDL_APPINPUTFOCUS) == 0)
|
---|
| 2472 | {
|
---|
| 2473 | /*
|
---|
| 2474 | * another window has stolen the (keyboard) input focus
|
---|
| 2475 | */
|
---|
| 2476 | InputGrabEnd();
|
---|
| 2477 | }
|
---|
| 2478 | break;
|
---|
| 2479 | }
|
---|
| 2480 |
|
---|
| 2481 | /*
|
---|
| 2482 | * The SDL window was resized
|
---|
| 2483 | */
|
---|
| 2484 | case SDL_VIDEORESIZE:
|
---|
| 2485 | {
|
---|
[34645] | 2486 | if (gpDisplay)
|
---|
[1] | 2487 | {
|
---|
[10675] | 2488 | if (gfIgnoreNextResize)
|
---|
| 2489 | {
|
---|
| 2490 | gfIgnoreNextResize = FALSE;
|
---|
| 2491 | break;
|
---|
| 2492 | }
|
---|
[6934] | 2493 | uResizeWidth = event.resize.w;
|
---|
[1] | 2494 | #ifdef VBOX_SECURELABEL
|
---|
[7714] | 2495 | if (fSecureLabel)
|
---|
| 2496 | uResizeHeight = RT_MAX(0, event.resize.h - SECURE_LABEL_HEIGHT);
|
---|
| 2497 | else
|
---|
[1] | 2498 | #endif
|
---|
[7714] | 2499 | uResizeHeight = event.resize.h;
|
---|
[522] | 2500 | if (gSdlResizeTimer)
|
---|
| 2501 | SDL_RemoveTimer(gSdlResizeTimer);
|
---|
| 2502 | gSdlResizeTimer = SDL_AddTimer(300, ResizeTimer, NULL);
|
---|
[1] | 2503 | }
|
---|
| 2504 | break;
|
---|
| 2505 | }
|
---|
| 2506 |
|
---|
| 2507 | /*
|
---|
| 2508 | * User specific update event.
|
---|
| 2509 | */
|
---|
| 2510 | /** @todo use a common user event handler so that SDL_PeepEvents() won't
|
---|
| 2511 | * possibly remove other events in the queue!
|
---|
| 2512 | */
|
---|
| 2513 | case SDL_USER_EVENT_UPDATERECT:
|
---|
| 2514 | {
|
---|
| 2515 | /*
|
---|
| 2516 | * Decode event parameters.
|
---|
| 2517 | */
|
---|
[3289] | 2518 | ASMAtomicDecS32(&g_cNotifyUpdateEventsPending);
|
---|
[18494] | 2519 | #define DECODEX(event) (int)((intptr_t)(event).user.data1 >> 16)
|
---|
| 2520 | #define DECODEY(event) (int)((intptr_t)(event).user.data1 & 0xFFFF)
|
---|
| 2521 | #define DECODEW(event) (int)((intptr_t)(event).user.data2 >> 16)
|
---|
| 2522 | #define DECODEH(event) (int)((intptr_t)(event).user.data2 & 0xFFFF)
|
---|
[1] | 2523 | int x = DECODEX(event);
|
---|
| 2524 | int y = DECODEY(event);
|
---|
| 2525 | int w = DECODEW(event);
|
---|
| 2526 | int h = DECODEH(event);
|
---|
| 2527 | LogFlow(("SDL_USER_EVENT_UPDATERECT: x = %d, y = %d, w = %d, h = %d\n",
|
---|
[34645] | 2528 | x, y, w, h));
|
---|
[1] | 2529 |
|
---|
[20433] | 2530 | Assert(gpFramebuffer[event.user.code]);
|
---|
| 2531 | gpFramebuffer[event.user.code]->update(x, y, w, h, true /* fGuestRelative */);
|
---|
[1] | 2532 |
|
---|
| 2533 | #undef DECODEX
|
---|
| 2534 | #undef DECODEY
|
---|
| 2535 | #undef DECODEW
|
---|
| 2536 | #undef DECODEH
|
---|
| 2537 | break;
|
---|
| 2538 | }
|
---|
| 2539 |
|
---|
| 2540 | /*
|
---|
[522] | 2541 | * User event: Window resize done
|
---|
| 2542 | */
|
---|
| 2543 | case SDL_USER_EVENT_WINDOW_RESIZE_DONE:
|
---|
| 2544 | {
|
---|
| 2545 | /**
|
---|
| 2546 | * @todo This is a workaround for synchronization problems between EMT and the
|
---|
| 2547 | * SDL main thread. It can happen that the SDL thread already starts a
|
---|
| 2548 | * new resize operation while the EMT is still busy with the old one
|
---|
| 2549 | * leading to a deadlock. Therefore we call SetVideoModeHint only once
|
---|
| 2550 | * when the mouse button was released.
|
---|
| 2551 | */
|
---|
| 2552 | /* communicate the resize event to the guest */
|
---|
[34645] | 2553 | gpDisplay->SetVideoModeHint(uResizeWidth, uResizeHeight, 0, 0);
|
---|
[522] | 2554 | break;
|
---|
| 2555 |
|
---|
| 2556 | }
|
---|
| 2557 |
|
---|
| 2558 | /*
|
---|
[1] | 2559 | * User specific resize event.
|
---|
| 2560 | */
|
---|
| 2561 | case SDL_USER_EVENT_RESIZE:
|
---|
| 2562 | {
|
---|
| 2563 | LogFlow(("SDL_USER_EVENT_RESIZE\n"));
|
---|
[20433] | 2564 | IFramebuffer *dummyFb;
|
---|
[20435] | 2565 | LONG xOrigin, yOrigin;
|
---|
[20433] | 2566 | gpFramebuffer[event.user.code]->resizeGuest();
|
---|
| 2567 | /* update xOrigin, yOrigin -> mouse */
|
---|
[34645] | 2568 | rc = gpDisplay->GetFramebuffer(event.user.code, &dummyFb, &xOrigin, &yOrigin);
|
---|
[20433] | 2569 | gpFramebuffer[event.user.code]->setOrigin(xOrigin, yOrigin);
|
---|
[1] | 2570 | /* notify the display that the resize has been completed */
|
---|
[34645] | 2571 | gpDisplay->ResizeCompleted(event.user.code);
|
---|
[1] | 2572 | break;
|
---|
| 2573 | }
|
---|
| 2574 |
|
---|
[967] | 2575 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
[1] | 2576 | /*
|
---|
| 2577 | * User specific XPCOM event queue event
|
---|
| 2578 | */
|
---|
| 2579 | case SDL_USER_EVENT_XPCOM_EVENTQUEUE:
|
---|
| 2580 | {
|
---|
| 2581 | LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
|
---|
[22911] | 2582 | eventQ->processEventQueue(0);
|
---|
[1] | 2583 | signalXPCOMEventQueueThread();
|
---|
| 2584 | break;
|
---|
| 2585 | }
|
---|
[967] | 2586 | #endif /* USE_XPCOM_QUEUE_THREAD */
|
---|
[1] | 2587 |
|
---|
| 2588 | /*
|
---|
| 2589 | * User specific update title bar notification event
|
---|
| 2590 | */
|
---|
| 2591 | case SDL_USER_EVENT_UPDATE_TITLEBAR:
|
---|
| 2592 | {
|
---|
| 2593 | UpdateTitlebar(TITLEBAR_NORMAL);
|
---|
| 2594 | break;
|
---|
| 2595 | }
|
---|
| 2596 |
|
---|
| 2597 | /*
|
---|
| 2598 | * User specific termination event
|
---|
| 2599 | */
|
---|
| 2600 | case SDL_USER_EVENT_TERMINATE:
|
---|
| 2601 | {
|
---|
| 2602 | if (event.user.code != VBOXSDL_TERM_NORMAL)
|
---|
| 2603 | RTPrintf("Error: VM terminated abnormally!\n");
|
---|
| 2604 | goto leave;
|
---|
| 2605 | }
|
---|
| 2606 |
|
---|
| 2607 | #ifdef VBOX_SECURELABEL
|
---|
| 2608 | /*
|
---|
| 2609 | * User specific secure label update event
|
---|
| 2610 | */
|
---|
| 2611 | case SDL_USER_EVENT_SECURELABEL_UPDATE:
|
---|
| 2612 | {
|
---|
| 2613 | /*
|
---|
| 2614 | * Query the new label text
|
---|
| 2615 | */
|
---|
[34645] | 2616 | Bstr bstrLabel;
|
---|
| 2617 | gpMachine->GetExtraData(Bstr(VBOXSDL_SECURELABEL_EXTRADATA).raw(), bstrLabel.asOutParam());
|
---|
| 2618 | Utf8Str labelUtf8(bstrLabel);
|
---|
[1] | 2619 | /*
|
---|
| 2620 | * Now update the label
|
---|
| 2621 | */
|
---|
[31539] | 2622 | gpFramebuffer[0]->setSecureLabelText(labelUtf8.c_str());
|
---|
[1] | 2623 | break;
|
---|
| 2624 | }
|
---|
| 2625 | #endif /* VBOX_SECURELABEL */
|
---|
| 2626 |
|
---|
| 2627 | /*
|
---|
| 2628 | * User specific pointer shape change event
|
---|
| 2629 | */
|
---|
| 2630 | case SDL_USER_EVENT_POINTER_CHANGE:
|
---|
| 2631 | {
|
---|
[28205] | 2632 | PointerShapeChangeData *data = (PointerShapeChangeData *)event.user.data1;
|
---|
[1] | 2633 | SetPointerShape (data);
|
---|
| 2634 | delete data;
|
---|
| 2635 | break;
|
---|
| 2636 | }
|
---|
| 2637 |
|
---|
| 2638 | /*
|
---|
| 2639 | * User specific guest capabilities changed
|
---|
| 2640 | */
|
---|
| 2641 | case SDL_USER_EVENT_GUEST_CAP_CHANGED:
|
---|
| 2642 | {
|
---|
| 2643 | HandleGuestCapsChanged();
|
---|
| 2644 | break;
|
---|
| 2645 | }
|
---|
| 2646 |
|
---|
| 2647 | default:
|
---|
| 2648 | {
|
---|
| 2649 | LogBird(("unknown SDL event %d\n", event.type));
|
---|
| 2650 | break;
|
---|
| 2651 | }
|
---|
| 2652 | }
|
---|
| 2653 | }
|
---|
| 2654 |
|
---|
| 2655 | leave:
|
---|
[10501] | 2656 | if (gpszPidFile)
|
---|
| 2657 | RTFileDelete(gpszPidFile);
|
---|
| 2658 |
|
---|
[1] | 2659 | LogFlow(("leaving...\n"));
|
---|
[3669] | 2660 | #if defined(VBOX_WITH_XPCOM) && !defined(RT_OS_DARWIN) && !defined(RT_OS_OS2)
|
---|
[1] | 2661 | /* make sure the XPCOM event queue thread doesn't do anything harmful */
|
---|
| 2662 | terminateXPCOMQueueThread();
|
---|
[614] | 2663 | #endif /* VBOX_WITH_XPCOM */
|
---|
[1] | 2664 |
|
---|
[34645] | 2665 | if (gpVRDEServer)
|
---|
| 2666 | rc = gpVRDEServer->COMSETTER(Enabled)(FALSE);
|
---|
[1] | 2667 |
|
---|
| 2668 | /*
|
---|
| 2669 | * Get the machine state.
|
---|
| 2670 | */
|
---|
[34645] | 2671 | if (gpMachine)
|
---|
| 2672 | gpMachine->COMGETTER(State)(&machineState);
|
---|
[1] | 2673 | else
|
---|
| 2674 | machineState = MachineState_Aborted;
|
---|
| 2675 |
|
---|
| 2676 | /*
|
---|
| 2677 | * Turn off the VM if it's running
|
---|
| 2678 | */
|
---|
[34645] | 2679 | if ( gpConsole
|
---|
[24301] | 2680 | && ( machineState == MachineState_Running
|
---|
| 2681 | || machineState == MachineState_Teleporting
|
---|
| 2682 | || machineState == MachineState_LiveSnapshotting
|
---|
| 2683 | /** @todo power off paused VMs too? */
|
---|
| 2684 | )
|
---|
| 2685 | )
|
---|
[26439] | 2686 | do
|
---|
[1] | 2687 | {
|
---|
[34645] | 2688 | pConsoleListener->getWrapped()->ignorePowerOffEvents(true);
|
---|
| 2689 | ComPtr<IProgress> pProgress;
|
---|
| 2690 | CHECK_ERROR_BREAK(gpConsole, PowerDown(pProgress.asOutParam()));
|
---|
| 2691 | CHECK_ERROR_BREAK(pProgress, WaitForCompletion(-1));
|
---|
[20928] | 2692 | BOOL completed;
|
---|
[34645] | 2693 | CHECK_ERROR_BREAK(pProgress, COMGETTER(Completed)(&completed));
|
---|
[28205] | 2694 | ASSERT(completed);
|
---|
[20928] | 2695 | LONG hrc;
|
---|
[34645] | 2696 | CHECK_ERROR_BREAK(pProgress, COMGETTER(ResultCode)(&hrc));
|
---|
[20928] | 2697 | if (FAILED(hrc))
|
---|
[1] | 2698 | {
|
---|
| 2699 | com::ErrorInfo info;
|
---|
| 2700 | if (info.isFullAvailable())
|
---|
| 2701 | PrintError("Failed to power down VM",
|
---|
| 2702 | info.getText().raw(), info.getComponent().raw());
|
---|
| 2703 | else
|
---|
[20928] | 2704 | RTPrintf("Failed to power down virtual machine! No error information available (rc = 0x%x).\n", hrc);
|
---|
[1] | 2705 | break;
|
---|
| 2706 | }
|
---|
[26439] | 2707 | } while (0);
|
---|
[1] | 2708 |
|
---|
[34645] | 2709 | /* unregister Console listener */
|
---|
| 2710 | if (pConsoleListener)
|
---|
[30618] | 2711 | {
|
---|
[34645] | 2712 | ComPtr<IEventSource> pES;
|
---|
| 2713 | CHECK_ERROR(gpConsole, COMGETTER(EventSource)(pES.asOutParam()));
|
---|
| 2714 | if (!pES.isNull())
|
---|
| 2715 | CHECK_ERROR(pES, UnregisterListener(pConsoleListener));
|
---|
| 2716 | pConsoleListener->Release();
|
---|
| 2717 | pConsoleListener = NULL;
|
---|
[30618] | 2718 | }
|
---|
| 2719 |
|
---|
[1] | 2720 | /*
|
---|
| 2721 | * Now we discard all settings so that our changes will
|
---|
| 2722 | * not be flushed to the permanent configuration
|
---|
| 2723 | */
|
---|
[34645] | 2724 | if ( gpMachine
|
---|
[1] | 2725 | && machineState != MachineState_Saved)
|
---|
| 2726 | {
|
---|
[34645] | 2727 | rc = gpMachine->DiscardSettings();
|
---|
[1] | 2728 | AssertComRC(rc);
|
---|
| 2729 | }
|
---|
| 2730 |
|
---|
| 2731 | /* close the session */
|
---|
| 2732 | if (sessionOpened)
|
---|
| 2733 | {
|
---|
[34645] | 2734 | rc = pSession->UnlockMachine();
|
---|
[1] | 2735 | AssertComRC(rc);
|
---|
| 2736 | }
|
---|
| 2737 |
|
---|
[20433] | 2738 | #ifndef VBOX_WITH_SDL13
|
---|
[1] | 2739 | /* restore the default cursor and free the custom one if any */
|
---|
| 2740 | if (gpDefaultCursor)
|
---|
| 2741 | {
|
---|
[20433] | 2742 | # ifdef VBOXSDL_WITH_X11
|
---|
[23184] | 2743 | Cursor pDefaultTempX11Cursor = 0;
|
---|
[23170] | 2744 | if (gfXCursorEnabled)
|
---|
| 2745 | {
|
---|
| 2746 | pDefaultTempX11Cursor = *(Cursor*)gpDefaultCursor->wm_cursor;
|
---|
| 2747 | *(Cursor*)gpDefaultCursor->wm_cursor = gpDefaultOrigX11Cursor;
|
---|
| 2748 | }
|
---|
[20433] | 2749 | # endif /* VBOXSDL_WITH_X11 */
|
---|
[1] | 2750 | SDL_SetCursor(gpDefaultCursor);
|
---|
[20433] | 2751 | # if defined(VBOXSDL_WITH_X11) && !defined(VBOX_WITHOUT_XCURSOR)
|
---|
[18793] | 2752 | if (gfXCursorEnabled)
|
---|
| 2753 | XFreeCursor(gSdlInfo.info.x11.display, pDefaultTempX11Cursor);
|
---|
[20433] | 2754 | # endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
|
---|
[1] | 2755 | }
|
---|
| 2756 |
|
---|
| 2757 | if (gpCustomCursor)
|
---|
| 2758 | {
|
---|
| 2759 | WMcursor *pCustomTempWMCursor = gpCustomCursor->wm_cursor;
|
---|
| 2760 | gpCustomCursor->wm_cursor = gpCustomOrigWMcursor;
|
---|
| 2761 | SDL_FreeCursor(gpCustomCursor);
|
---|
| 2762 | if (pCustomTempWMCursor)
|
---|
| 2763 | {
|
---|
[28205] | 2764 | # if defined(RT_OS_WINDOWS)
|
---|
| 2765 | ::DestroyCursor(*(HCURSOR *)pCustomTempWMCursor);
|
---|
| 2766 | # elif defined(VBOXSDL_WITH_X11) && !defined(VBOX_WITHOUT_XCURSOR)
|
---|
[18793] | 2767 | if (gfXCursorEnabled)
|
---|
[28205] | 2768 | XFreeCursor(gSdlInfo.info.x11.display, *(Cursor *)pCustomTempWMCursor);
|
---|
[20433] | 2769 | # endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
|
---|
[1] | 2770 | free(pCustomTempWMCursor);
|
---|
| 2771 | }
|
---|
| 2772 | }
|
---|
[20433] | 2773 | #endif
|
---|
[1] | 2774 |
|
---|
[33386] | 2775 | LogFlow(("Releasing mouse, keyboard, remote desktop server, display, console...\n"));
|
---|
[34645] | 2776 | if (gpDisplay)
|
---|
[20433] | 2777 | {
|
---|
| 2778 | for (unsigned i = 0; i < gcMonitors; i++)
|
---|
[34645] | 2779 | gpDisplay->SetFramebuffer(i, NULL);
|
---|
[30681] | 2780 | }
|
---|
[30618] | 2781 |
|
---|
[34645] | 2782 | gpMouse = NULL;
|
---|
| 2783 | gpKeyboard = NULL;
|
---|
| 2784 | gpVRDEServer = NULL;
|
---|
| 2785 | gpDisplay = NULL;
|
---|
| 2786 | gpConsole = NULL;
|
---|
| 2787 | gpMachineDebugger = NULL;
|
---|
| 2788 | gpProgress = NULL;
|
---|
[1] | 2789 | // we can only uninitialize SDL here because it is not threadsafe
|
---|
[20433] | 2790 |
|
---|
| 2791 | for (unsigned i = 0; i < gcMonitors; i++)
|
---|
[20842] | 2792 | {
|
---|
[20433] | 2793 | if (gpFramebuffer[i])
|
---|
| 2794 | {
|
---|
| 2795 | LogFlow(("Releasing framebuffer...\n"));
|
---|
| 2796 | gpFramebuffer[i]->Release();
|
---|
| 2797 | gpFramebuffer[i] = NULL;
|
---|
| 2798 | }
|
---|
[1] | 2799 | }
|
---|
[20433] | 2800 |
|
---|
| 2801 | VBoxSDLFB::uninit();
|
---|
| 2802 |
|
---|
[1] | 2803 | #ifdef VBOX_SECURELABEL
|
---|
| 2804 | /* must do this after destructing the framebuffer */
|
---|
| 2805 | if (gLibrarySDL_ttf)
|
---|
| 2806 | RTLdrClose(gLibrarySDL_ttf);
|
---|
| 2807 | #endif
|
---|
[26439] | 2808 |
|
---|
[34645] | 2809 | /* VirtualBox (server) listener unregistration. */
|
---|
| 2810 | if (pVBoxListener)
|
---|
[30618] | 2811 | {
|
---|
[34645] | 2812 | ComPtr<IEventSource> pES;
|
---|
| 2813 | CHECK_ERROR(pVirtualBox, COMGETTER(EventSource)(pES.asOutParam()));
|
---|
| 2814 | if (!pES.isNull())
|
---|
| 2815 | CHECK_ERROR(pES, UnregisterListener(pVBoxListener));
|
---|
| 2816 | pVBoxListener->Release();
|
---|
| 2817 | pVBoxListener = NULL;
|
---|
[30618] | 2818 | }
|
---|
[34645] | 2819 |
|
---|
[34646] | 2820 | /* VirtualBoxClient listener unregistration. */
|
---|
| 2821 | if (pVBoxClientListener)
|
---|
| 2822 | {
|
---|
| 2823 | ComPtr<IEventSource> pES;
|
---|
| 2824 | CHECK_ERROR(pVirtualBoxClient, COMGETTER(EventSource)(pES.asOutParam()));
|
---|
| 2825 | if (!pES.isNull())
|
---|
| 2826 | CHECK_ERROR(pES, UnregisterListener(pVBoxClientListener));
|
---|
| 2827 | pVBoxClientListener->Release();
|
---|
| 2828 | pVBoxClientListener = NULL;
|
---|
| 2829 | }
|
---|
| 2830 |
|
---|
[1] | 2831 | LogFlow(("Releasing machine, session...\n"));
|
---|
[34645] | 2832 | gpMachine = NULL;
|
---|
| 2833 | pSession = NULL;
|
---|
[1] | 2834 | LogFlow(("Releasing VirtualBox object...\n"));
|
---|
[34645] | 2835 | pVirtualBox = NULL;
|
---|
[34646] | 2836 | LogFlow(("Releasing VirtualBoxClient object...\n"));
|
---|
| 2837 | pVirtualBoxClient = NULL;
|
---|
[1] | 2838 |
|
---|
| 2839 | // end "all-stuff" scope
|
---|
| 2840 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 2841 | }
|
---|
| 2842 |
|
---|
[25026] | 2843 | /* Must be before com::Shutdown() */
|
---|
[1] | 2844 | LogFlow(("Uninitializing COM...\n"));
|
---|
| 2845 | com::Shutdown();
|
---|
| 2846 |
|
---|
| 2847 | LogFlow(("Returning from main()!\n"));
|
---|
| 2848 | RTLogFlush(NULL);
|
---|
[26322] | 2849 | return FAILED(rc) ? 1 : 0;
|
---|
[1] | 2850 | }
|
---|
| 2851 |
|
---|
[11725] | 2852 |
|
---|
| 2853 | #ifndef VBOX_WITH_HARDENING
|
---|
[1] | 2854 | /**
|
---|
[11725] | 2855 | * Main entry point
|
---|
| 2856 | */
|
---|
| 2857 | int main(int argc, char **argv)
|
---|
| 2858 | {
|
---|
| 2859 | /*
|
---|
| 2860 | * Before we do *anything*, we initialize the runtime.
|
---|
| 2861 | */
|
---|
[11822] | 2862 | int rcRT = RTR3InitAndSUPLib();
|
---|
[13835] | 2863 | if (RT_FAILURE(rcRT))
|
---|
[11725] | 2864 | {
|
---|
| 2865 | RTPrintf("Error: RTR3Init failed rcRC=%d\n", rcRT);
|
---|
| 2866 | return 1;
|
---|
| 2867 | }
|
---|
| 2868 | return TrustedMain(argc, argv, NULL);
|
---|
| 2869 | }
|
---|
| 2870 | #endif /* !VBOX_WITH_HARDENING */
|
---|
| 2871 |
|
---|
| 2872 |
|
---|
| 2873 | /**
|
---|
[1] | 2874 | * Returns whether the absolute mouse is in use, i.e. both host
|
---|
| 2875 | * and guest have opted to enable it.
|
---|
| 2876 | *
|
---|
| 2877 | * @returns bool Flag whether the absolute mouse is in use
|
---|
| 2878 | */
|
---|
| 2879 | static bool UseAbsoluteMouse(void)
|
---|
| 2880 | {
|
---|
| 2881 | return (gfAbsoluteMouseHost && gfAbsoluteMouseGuest);
|
---|
| 2882 | }
|
---|
| 2883 |
|
---|
[6886] | 2884 | #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2)
|
---|
[1] | 2885 | /**
|
---|
[962] | 2886 | * Fallback keycode conversion using SDL symbols.
|
---|
| 2887 | *
|
---|
| 2888 | * This is used to catch keycodes that's missing from the translation table.
|
---|
| 2889 | *
|
---|
| 2890 | * @returns XT scancode
|
---|
| 2891 | * @param ev SDL scancode
|
---|
| 2892 | */
|
---|
[1877] | 2893 | static uint16_t Keyevent2KeycodeFallback(const SDL_KeyboardEvent *ev)
|
---|
[962] | 2894 | {
|
---|
| 2895 | const SDLKey sym = ev->keysym.sym;
|
---|
| 2896 | Log(("SDL key event: sym=%d scancode=%#x unicode=%#x\n",
|
---|
| 2897 | sym, ev->keysym.scancode, ev->keysym.unicode));
|
---|
| 2898 | switch (sym)
|
---|
| 2899 | { /* set 1 scan code */
|
---|
| 2900 | case SDLK_ESCAPE: return 0x01;
|
---|
| 2901 | case SDLK_EXCLAIM:
|
---|
| 2902 | case SDLK_1: return 0x02;
|
---|
| 2903 | case SDLK_AT:
|
---|
| 2904 | case SDLK_2: return 0x03;
|
---|
| 2905 | case SDLK_HASH:
|
---|
| 2906 | case SDLK_3: return 0x04;
|
---|
| 2907 | case SDLK_DOLLAR:
|
---|
| 2908 | case SDLK_4: return 0x05;
|
---|
| 2909 | /* % */
|
---|
| 2910 | case SDLK_5: return 0x06;
|
---|
| 2911 | case SDLK_CARET:
|
---|
| 2912 | case SDLK_6: return 0x07;
|
---|
| 2913 | case SDLK_AMPERSAND:
|
---|
| 2914 | case SDLK_7: return 0x08;
|
---|
| 2915 | case SDLK_ASTERISK:
|
---|
| 2916 | case SDLK_8: return 0x09;
|
---|
| 2917 | case SDLK_LEFTPAREN:
|
---|
| 2918 | case SDLK_9: return 0x0a;
|
---|
| 2919 | case SDLK_RIGHTPAREN:
|
---|
| 2920 | case SDLK_0: return 0x0b;
|
---|
| 2921 | case SDLK_UNDERSCORE:
|
---|
| 2922 | case SDLK_MINUS: return 0x0c;
|
---|
| 2923 | case SDLK_EQUALS:
|
---|
| 2924 | case SDLK_PLUS: return 0x0d;
|
---|
| 2925 | case SDLK_BACKSPACE: return 0x0e;
|
---|
| 2926 | case SDLK_TAB: return 0x0f;
|
---|
| 2927 | case SDLK_q: return 0x10;
|
---|
| 2928 | case SDLK_w: return 0x11;
|
---|
| 2929 | case SDLK_e: return 0x12;
|
---|
| 2930 | case SDLK_r: return 0x13;
|
---|
| 2931 | case SDLK_t: return 0x14;
|
---|
| 2932 | case SDLK_y: return 0x15;
|
---|
| 2933 | case SDLK_u: return 0x16;
|
---|
| 2934 | case SDLK_i: return 0x17;
|
---|
| 2935 | case SDLK_o: return 0x18;
|
---|
| 2936 | case SDLK_p: return 0x19;
|
---|
| 2937 | case SDLK_LEFTBRACKET: return 0x1a;
|
---|
| 2938 | case SDLK_RIGHTBRACKET: return 0x1b;
|
---|
| 2939 | case SDLK_RETURN: return 0x1c;
|
---|
[1877] | 2940 | case SDLK_KP_ENTER: return 0x1c | 0x100;
|
---|
[962] | 2941 | case SDLK_LCTRL: return 0x1d;
|
---|
[1877] | 2942 | case SDLK_RCTRL: return 0x1d | 0x100;
|
---|
[962] | 2943 | case SDLK_a: return 0x1e;
|
---|
| 2944 | case SDLK_s: return 0x1f;
|
---|
| 2945 | case SDLK_d: return 0x20;
|
---|
| 2946 | case SDLK_f: return 0x21;
|
---|
| 2947 | case SDLK_g: return 0x22;
|
---|
| 2948 | case SDLK_h: return 0x23;
|
---|
| 2949 | case SDLK_j: return 0x24;
|
---|
| 2950 | case SDLK_k: return 0x25;
|
---|
| 2951 | case SDLK_l: return 0x26;
|
---|
| 2952 | case SDLK_COLON:
|
---|
| 2953 | case SDLK_SEMICOLON: return 0x27;
|
---|
| 2954 | case SDLK_QUOTEDBL:
|
---|
| 2955 | case SDLK_QUOTE: return 0x28;
|
---|
| 2956 | case SDLK_BACKQUOTE: return 0x29;
|
---|
| 2957 | case SDLK_LSHIFT: return 0x2a;
|
---|
| 2958 | case SDLK_BACKSLASH: return 0x2b;
|
---|
| 2959 | case SDLK_z: return 0x2c;
|
---|
| 2960 | case SDLK_x: return 0x2d;
|
---|
| 2961 | case SDLK_c: return 0x2e;
|
---|
| 2962 | case SDLK_v: return 0x2f;
|
---|
| 2963 | case SDLK_b: return 0x30;
|
---|
| 2964 | case SDLK_n: return 0x31;
|
---|
| 2965 | case SDLK_m: return 0x32;
|
---|
| 2966 | case SDLK_LESS:
|
---|
| 2967 | case SDLK_COMMA: return 0x33;
|
---|
| 2968 | case SDLK_GREATER:
|
---|
| 2969 | case SDLK_PERIOD: return 0x34;
|
---|
| 2970 | case SDLK_KP_DIVIDE: /*??*/
|
---|
| 2971 | case SDLK_QUESTION:
|
---|
| 2972 | case SDLK_SLASH: return 0x35;
|
---|
| 2973 | case SDLK_RSHIFT: return 0x36;
|
---|
| 2974 | case SDLK_KP_MULTIPLY:
|
---|
| 2975 | case SDLK_PRINT: return 0x37; /* fixme */
|
---|
| 2976 | case SDLK_LALT: return 0x38;
|
---|
| 2977 | case SDLK_MODE: /* alt gr*/
|
---|
[1877] | 2978 | case SDLK_RALT: return 0x38 | 0x100;
|
---|
[962] | 2979 | case SDLK_SPACE: return 0x39;
|
---|
| 2980 | case SDLK_CAPSLOCK: return 0x3a;
|
---|
| 2981 | case SDLK_F1: return 0x3b;
|
---|
| 2982 | case SDLK_F2: return 0x3c;
|
---|
| 2983 | case SDLK_F3: return 0x3d;
|
---|
| 2984 | case SDLK_F4: return 0x3e;
|
---|
| 2985 | case SDLK_F5: return 0x3f;
|
---|
| 2986 | case SDLK_F6: return 0x40;
|
---|
| 2987 | case SDLK_F7: return 0x41;
|
---|
| 2988 | case SDLK_F8: return 0x42;
|
---|
| 2989 | case SDLK_F9: return 0x43;
|
---|
| 2990 | case SDLK_F10: return 0x44;
|
---|
| 2991 | case SDLK_PAUSE: return 0x45; /* not right */
|
---|
| 2992 | case SDLK_NUMLOCK: return 0x45;
|
---|
| 2993 | case SDLK_SCROLLOCK: return 0x46;
|
---|
| 2994 | case SDLK_KP7: return 0x47;
|
---|
[1877] | 2995 | case SDLK_HOME: return 0x47 | 0x100;
|
---|
[962] | 2996 | case SDLK_KP8: return 0x48;
|
---|
[1877] | 2997 | case SDLK_UP: return 0x48 | 0x100;
|
---|
[962] | 2998 | case SDLK_KP9: return 0x49;
|
---|
[1877] | 2999 | case SDLK_PAGEUP: return 0x49 | 0x100;
|
---|
[962] | 3000 | case SDLK_KP_MINUS: return 0x4a;
|
---|
| 3001 | case SDLK_KP4: return 0x4b;
|
---|
[1877] | 3002 | case SDLK_LEFT: return 0x4b | 0x100;
|
---|
[962] | 3003 | case SDLK_KP5: return 0x4c;
|
---|
| 3004 | case SDLK_KP6: return 0x4d;
|
---|
[1877] | 3005 | case SDLK_RIGHT: return 0x4d | 0x100;
|
---|
[962] | 3006 | case SDLK_KP_PLUS: return 0x4e;
|
---|
| 3007 | case SDLK_KP1: return 0x4f;
|
---|
[1877] | 3008 | case SDLK_END: return 0x4f | 0x100;
|
---|
[962] | 3009 | case SDLK_KP2: return 0x50;
|
---|
[1877] | 3010 | case SDLK_DOWN: return 0x50 | 0x100;
|
---|
[962] | 3011 | case SDLK_KP3: return 0x51;
|
---|
[1877] | 3012 | case SDLK_PAGEDOWN: return 0x51 | 0x100;
|
---|
[962] | 3013 | case SDLK_KP0: return 0x52;
|
---|
[1877] | 3014 | case SDLK_INSERT: return 0x52 | 0x100;
|
---|
[962] | 3015 | case SDLK_KP_PERIOD: return 0x53;
|
---|
[1877] | 3016 | case SDLK_DELETE: return 0x53 | 0x100;
|
---|
[962] | 3017 | case SDLK_SYSREQ: return 0x54;
|
---|
| 3018 | case SDLK_F11: return 0x57;
|
---|
| 3019 | case SDLK_F12: return 0x58;
|
---|
| 3020 | case SDLK_F13: return 0x5b;
|
---|
| 3021 | case SDLK_LMETA:
|
---|
[1877] | 3022 | case SDLK_LSUPER: return 0x5b | 0x100;
|
---|
[962] | 3023 | case SDLK_F14: return 0x5c;
|
---|
| 3024 | case SDLK_RMETA:
|
---|
[1877] | 3025 | case SDLK_RSUPER: return 0x5c | 0x100;
|
---|
[962] | 3026 | case SDLK_F15: return 0x5d;
|
---|
[1877] | 3027 | case SDLK_MENU: return 0x5d | 0x100;
|
---|
[962] | 3028 | #if 0
|
---|
| 3029 | case SDLK_CLEAR: return 0x;
|
---|
| 3030 | case SDLK_KP_EQUALS: return 0x;
|
---|
[3289] | 3031 | case SDLK_COMPOSE: return 0x;
|
---|
[962] | 3032 | case SDLK_HELP: return 0x;
|
---|
| 3033 | case SDLK_BREAK: return 0x;
|
---|
[3289] | 3034 | case SDLK_POWER: return 0x;
|
---|
| 3035 | case SDLK_EURO: return 0x;
|
---|
| 3036 | case SDLK_UNDO: return 0x;
|
---|
[962] | 3037 | #endif
|
---|
| 3038 | default:
|
---|
| 3039 | Log(("Unhandled sdl key event: sym=%d scancode=%#x unicode=%#x\n",
|
---|
| 3040 | ev->keysym.sym, ev->keysym.scancode, ev->keysym.unicode));
|
---|
| 3041 | return 0;
|
---|
| 3042 | }
|
---|
| 3043 | }
|
---|
[3669] | 3044 | #endif /* RT_OS_DARWIN */
|
---|
[962] | 3045 |
|
---|
| 3046 | /**
|
---|
[1] | 3047 | * Converts an SDL keyboard eventcode to a XT scancode.
|
---|
| 3048 | *
|
---|
| 3049 | * @returns XT scancode
|
---|
| 3050 | * @param ev SDL scancode
|
---|
| 3051 | */
|
---|
[1877] | 3052 | static uint16_t Keyevent2Keycode(const SDL_KeyboardEvent *ev)
|
---|
[1] | 3053 | {
|
---|
| 3054 | // start with the scancode determined by SDL
|
---|
[1877] | 3055 | int keycode = ev->keysym.scancode;
|
---|
[1] | 3056 |
|
---|
[4637] | 3057 | #ifdef VBOXSDL_WITH_X11
|
---|
[20433] | 3058 | # ifdef VBOX_WITH_SDL13
|
---|
| 3059 |
|
---|
| 3060 | switch (ev->keysym.sym)
|
---|
| 3061 | {
|
---|
| 3062 | case SDLK_ESCAPE: return 0x01;
|
---|
| 3063 | case SDLK_EXCLAIM:
|
---|
| 3064 | case SDLK_1: return 0x02;
|
---|
| 3065 | case SDLK_AT:
|
---|
| 3066 | case SDLK_2: return 0x03;
|
---|
| 3067 | case SDLK_HASH:
|
---|
| 3068 | case SDLK_3: return 0x04;
|
---|
| 3069 | case SDLK_DOLLAR:
|
---|
| 3070 | case SDLK_4: return 0x05;
|
---|
| 3071 | /* % */
|
---|
| 3072 | case SDLK_5: return 0x06;
|
---|
| 3073 | case SDLK_CARET:
|
---|
| 3074 | case SDLK_6: return 0x07;
|
---|
| 3075 | case SDLK_AMPERSAND:
|
---|
| 3076 | case SDLK_7: return 0x08;
|
---|
| 3077 | case SDLK_ASTERISK:
|
---|
| 3078 | case SDLK_8: return 0x09;
|
---|
| 3079 | case SDLK_LEFTPAREN:
|
---|
| 3080 | case SDLK_9: return 0x0a;
|
---|
| 3081 | case SDLK_RIGHTPAREN:
|
---|
| 3082 | case SDLK_0: return 0x0b;
|
---|
| 3083 | case SDLK_UNDERSCORE:
|
---|
| 3084 | case SDLK_MINUS: return 0x0c;
|
---|
| 3085 | case SDLK_PLUS: return 0x0d;
|
---|
| 3086 | case SDLK_BACKSPACE: return 0x0e;
|
---|
| 3087 | case SDLK_TAB: return 0x0f;
|
---|
| 3088 | case SDLK_q: return 0x10;
|
---|
| 3089 | case SDLK_w: return 0x11;
|
---|
| 3090 | case SDLK_e: return 0x12;
|
---|
| 3091 | case SDLK_r: return 0x13;
|
---|
| 3092 | case SDLK_t: return 0x14;
|
---|
| 3093 | case SDLK_y: return 0x15;
|
---|
| 3094 | case SDLK_u: return 0x16;
|
---|
| 3095 | case SDLK_i: return 0x17;
|
---|
| 3096 | case SDLK_o: return 0x18;
|
---|
| 3097 | case SDLK_p: return 0x19;
|
---|
| 3098 | case SDLK_RETURN: return 0x1c;
|
---|
| 3099 | case SDLK_KP_ENTER: return 0x1c | 0x100;
|
---|
| 3100 | case SDLK_LCTRL: return 0x1d;
|
---|
| 3101 | case SDLK_RCTRL: return 0x1d | 0x100;
|
---|
| 3102 | case SDLK_a: return 0x1e;
|
---|
| 3103 | case SDLK_s: return 0x1f;
|
---|
| 3104 | case SDLK_d: return 0x20;
|
---|
| 3105 | case SDLK_f: return 0x21;
|
---|
| 3106 | case SDLK_g: return 0x22;
|
---|
| 3107 | case SDLK_h: return 0x23;
|
---|
| 3108 | case SDLK_j: return 0x24;
|
---|
| 3109 | case SDLK_k: return 0x25;
|
---|
| 3110 | case SDLK_l: return 0x26;
|
---|
| 3111 | case SDLK_COLON: return 0x27;
|
---|
| 3112 | case SDLK_QUOTEDBL:
|
---|
| 3113 | case SDLK_QUOTE: return 0x28;
|
---|
| 3114 | case SDLK_BACKQUOTE: return 0x29;
|
---|
| 3115 | case SDLK_LSHIFT: return 0x2a;
|
---|
| 3116 | case SDLK_z: return 0x2c;
|
---|
| 3117 | case SDLK_x: return 0x2d;
|
---|
| 3118 | case SDLK_c: return 0x2e;
|
---|
| 3119 | case SDLK_v: return 0x2f;
|
---|
| 3120 | case SDLK_b: return 0x30;
|
---|
| 3121 | case SDLK_n: return 0x31;
|
---|
| 3122 | case SDLK_m: return 0x32;
|
---|
| 3123 | case SDLK_LESS: return 0x33;
|
---|
| 3124 | case SDLK_GREATER: return 0x34;
|
---|
| 3125 | case SDLK_KP_DIVIDE: /*??*/
|
---|
| 3126 | case SDLK_QUESTION: return 0x35;
|
---|
| 3127 | case SDLK_RSHIFT: return 0x36;
|
---|
| 3128 | case SDLK_KP_MULTIPLY:
|
---|
| 3129 | case SDLK_PRINT: return 0x37; /* fixme */
|
---|
| 3130 | case SDLK_LALT: return 0x38;
|
---|
| 3131 | case SDLK_MODE: /* alt gr*/
|
---|
| 3132 | case SDLK_RALT: return 0x38 | 0x100;
|
---|
| 3133 | case SDLK_SPACE: return 0x39;
|
---|
| 3134 | case SDLK_CAPSLOCK: return 0x3a;
|
---|
| 3135 | case SDLK_F1: return 0x3b;
|
---|
| 3136 | case SDLK_F2: return 0x3c;
|
---|
| 3137 | case SDLK_F3: return 0x3d;
|
---|
| 3138 | case SDLK_F4: return 0x3e;
|
---|
| 3139 | case SDLK_F5: return 0x3f;
|
---|
| 3140 | case SDLK_F6: return 0x40;
|
---|
| 3141 | case SDLK_F7: return 0x41;
|
---|
| 3142 | case SDLK_F8: return 0x42;
|
---|
| 3143 | case SDLK_F9: return 0x43;
|
---|
| 3144 | case SDLK_F10: return 0x44;
|
---|
| 3145 | case SDLK_PAUSE: return 0x45; /* not right */
|
---|
| 3146 | case SDLK_NUMLOCK: return 0x45;
|
---|
| 3147 | case SDLK_SCROLLOCK: return 0x46;
|
---|
| 3148 | case SDLK_KP7: return 0x47;
|
---|
| 3149 | case SDLK_HOME: return 0x47 | 0x100;
|
---|
| 3150 | case SDLK_KP8: return 0x48;
|
---|
| 3151 | case SDLK_UP: return 0x48 | 0x100;
|
---|
| 3152 | case SDLK_KP9: return 0x49;
|
---|
| 3153 | case SDLK_PAGEUP: return 0x49 | 0x100;
|
---|
| 3154 | case SDLK_KP_MINUS: return 0x4a;
|
---|
| 3155 | case SDLK_KP4: return 0x4b;
|
---|
| 3156 | case SDLK_LEFT: return 0x4b | 0x100;
|
---|
| 3157 | case SDLK_KP5: return 0x4c;
|
---|
| 3158 | case SDLK_KP6: return 0x4d;
|
---|
| 3159 | case SDLK_RIGHT: return 0x4d | 0x100;
|
---|
| 3160 | case SDLK_KP_PLUS: return 0x4e;
|
---|
| 3161 | case SDLK_KP1: return 0x4f;
|
---|
| 3162 | case SDLK_END: return 0x4f | 0x100;
|
---|
| 3163 | case SDLK_KP2: return 0x50;
|
---|
| 3164 | case SDLK_DOWN: return 0x50 | 0x100;
|
---|
| 3165 | case SDLK_KP3: return 0x51;
|
---|
| 3166 | case SDLK_PAGEDOWN: return 0x51 | 0x100;
|
---|
| 3167 | case SDLK_KP0: return 0x52;
|
---|
| 3168 | case SDLK_INSERT: return 0x52 | 0x100;
|
---|
| 3169 | case SDLK_KP_PERIOD: return 0x53;
|
---|
| 3170 | case SDLK_DELETE: return 0x53 | 0x100;
|
---|
| 3171 | case SDLK_SYSREQ: return 0x54;
|
---|
| 3172 | case SDLK_F11: return 0x57;
|
---|
| 3173 | case SDLK_F12: return 0x58;
|
---|
| 3174 | case SDLK_F13: return 0x5b;
|
---|
| 3175 | case SDLK_F14: return 0x5c;
|
---|
| 3176 | case SDLK_F15: return 0x5d;
|
---|
| 3177 | case SDLK_MENU: return 0x5d | 0x100;
|
---|
| 3178 | default:
|
---|
| 3179 | return 0;
|
---|
| 3180 | }
|
---|
| 3181 | # else
|
---|
[29655] | 3182 | keycode = X11DRV_KeyEvent(gSdlInfo.info.x11.display, keycode);
|
---|
[20433] | 3183 | # endif
|
---|
[3669] | 3184 | #elif defined(RT_OS_DARWIN)
|
---|
[962] | 3185 | /* This is derived partially from SDL_QuartzKeys.h and partially from testing. */
|
---|
[1877] | 3186 | static const uint16_t s_aMacToSet1[] =
|
---|
[962] | 3187 | {
|
---|
| 3188 | /* set-1 SDL_QuartzKeys.h */
|
---|
| 3189 | 0x1e, /* QZ_a 0x00 */
|
---|
| 3190 | 0x1f, /* QZ_s 0x01 */
|
---|
| 3191 | 0x20, /* QZ_d 0x02 */
|
---|
| 3192 | 0x21, /* QZ_f 0x03 */
|
---|
| 3193 | 0x23, /* QZ_h 0x04 */
|
---|
| 3194 | 0x22, /* QZ_g 0x05 */
|
---|
| 3195 | 0x2c, /* QZ_z 0x06 */
|
---|
| 3196 | 0x2d, /* QZ_x 0x07 */
|
---|
| 3197 | 0x2e, /* QZ_c 0x08 */
|
---|
| 3198 | 0x2f, /* QZ_v 0x09 */
|
---|
| 3199 | 0x56, /* between lshift and z. 'INT 1'? */
|
---|
| 3200 | 0x30, /* QZ_b 0x0B */
|
---|
| 3201 | 0x10, /* QZ_q 0x0C */
|
---|
| 3202 | 0x11, /* QZ_w 0x0D */
|
---|
| 3203 | 0x12, /* QZ_e 0x0E */
|
---|
| 3204 | 0x13, /* QZ_r 0x0F */
|
---|
| 3205 | 0x15, /* QZ_y 0x10 */
|
---|
| 3206 | 0x14, /* QZ_t 0x11 */
|
---|
| 3207 | 0x02, /* QZ_1 0x12 */
|
---|
| 3208 | 0x03, /* QZ_2 0x13 */
|
---|
| 3209 | 0x04, /* QZ_3 0x14 */
|
---|
| 3210 | 0x05, /* QZ_4 0x15 */
|
---|
| 3211 | 0x07, /* QZ_6 0x16 */
|
---|
| 3212 | 0x06, /* QZ_5 0x17 */
|
---|
| 3213 | 0x0d, /* QZ_EQUALS 0x18 */
|
---|
| 3214 | 0x0a, /* QZ_9 0x19 */
|
---|
| 3215 | 0x08, /* QZ_7 0x1A */
|
---|
| 3216 | 0x0c, /* QZ_MINUS 0x1B */
|
---|
| 3217 | 0x09, /* QZ_8 0x1C */
|
---|
| 3218 | 0x0b, /* QZ_0 0x1D */
|
---|
| 3219 | 0x1b, /* QZ_RIGHTBRACKET 0x1E */
|
---|
| 3220 | 0x18, /* QZ_o 0x1F */
|
---|
| 3221 | 0x16, /* QZ_u 0x20 */
|
---|
| 3222 | 0x1a, /* QZ_LEFTBRACKET 0x21 */
|
---|
| 3223 | 0x17, /* QZ_i 0x22 */
|
---|
| 3224 | 0x19, /* QZ_p 0x23 */
|
---|
| 3225 | 0x1c, /* QZ_RETURN 0x24 */
|
---|
| 3226 | 0x26, /* QZ_l 0x25 */
|
---|
| 3227 | 0x24, /* QZ_j 0x26 */
|
---|
| 3228 | 0x28, /* QZ_QUOTE 0x27 */
|
---|
| 3229 | 0x25, /* QZ_k 0x28 */
|
---|
| 3230 | 0x27, /* QZ_SEMICOLON 0x29 */
|
---|
| 3231 | 0x2b, /* QZ_BACKSLASH 0x2A */
|
---|
| 3232 | 0x33, /* QZ_COMMA 0x2B */
|
---|
| 3233 | 0x35, /* QZ_SLASH 0x2C */
|
---|
| 3234 | 0x31, /* QZ_n 0x2D */
|
---|
| 3235 | 0x32, /* QZ_m 0x2E */
|
---|
| 3236 | 0x34, /* QZ_PERIOD 0x2F */
|
---|
| 3237 | 0x0f, /* QZ_TAB 0x30 */
|
---|
| 3238 | 0x39, /* QZ_SPACE 0x31 */
|
---|
| 3239 | 0x29, /* QZ_BACKQUOTE 0x32 */
|
---|
| 3240 | 0x0e, /* QZ_BACKSPACE 0x33 */
|
---|
| 3241 | 0x9c, /* QZ_IBOOK_ENTER 0x34 */
|
---|
| 3242 | 0x01, /* QZ_ESCAPE 0x35 */
|
---|
[1877] | 3243 | 0x5c|0x100, /* QZ_RMETA 0x36 */
|
---|
| 3244 | 0x5b|0x100, /* QZ_LMETA 0x37 */
|
---|
[962] | 3245 | 0x2a, /* QZ_LSHIFT 0x38 */
|
---|
| 3246 | 0x3a, /* QZ_CAPSLOCK 0x39 */
|
---|
| 3247 | 0x38, /* QZ_LALT 0x3A */
|
---|
| 3248 | 0x1d, /* QZ_LCTRL 0x3B */
|
---|
| 3249 | 0x36, /* QZ_RSHIFT 0x3C */
|
---|
[1877] | 3250 | 0x38|0x100, /* QZ_RALT 0x3D */
|
---|
| 3251 | 0x1d|0x100, /* QZ_RCTRL 0x3E */
|
---|
[962] | 3252 | 0, /* */
|
---|
| 3253 | 0, /* */
|
---|
| 3254 | 0x53, /* QZ_KP_PERIOD 0x41 */
|
---|
| 3255 | 0, /* */
|
---|
| 3256 | 0x37, /* QZ_KP_MULTIPLY 0x43 */
|
---|
| 3257 | 0, /* */
|
---|
| 3258 | 0x4e, /* QZ_KP_PLUS 0x45 */
|
---|
| 3259 | 0, /* */
|
---|
| 3260 | 0x45, /* QZ_NUMLOCK 0x47 */
|
---|
| 3261 | 0, /* */
|
---|
| 3262 | 0, /* */
|
---|
| 3263 | 0, /* */
|
---|
[1877] | 3264 | 0x35|0x100, /* QZ_KP_DIVIDE 0x4B */
|
---|
| 3265 | 0x1c|0x100, /* QZ_KP_ENTER 0x4C */
|
---|
[962] | 3266 | 0, /* */
|
---|
| 3267 | 0x4a, /* QZ_KP_MINUS 0x4E */
|
---|
| 3268 | 0, /* */
|
---|
| 3269 | 0, /* */
|
---|
| 3270 | 0x0d/*?*/, /* QZ_KP_EQUALS 0x51 */
|
---|
| 3271 | 0x52, /* QZ_KP0 0x52 */
|
---|
| 3272 | 0x4f, /* QZ_KP1 0x53 */
|
---|
| 3273 | 0x50, /* QZ_KP2 0x54 */
|
---|
| 3274 | 0x51, /* QZ_KP3 0x55 */
|
---|
| 3275 | 0x4b, /* QZ_KP4 0x56 */
|
---|
| 3276 | 0x4c, /* QZ_KP5 0x57 */
|
---|
| 3277 | 0x4d, /* QZ_KP6 0x58 */
|
---|
| 3278 | 0x47, /* QZ_KP7 0x59 */
|
---|
| 3279 | 0, /* */
|
---|
| 3280 | 0x48, /* QZ_KP8 0x5B */
|
---|
| 3281 | 0x49, /* QZ_KP9 0x5C */
|
---|
| 3282 | 0, /* */
|
---|
| 3283 | 0, /* */
|
---|
| 3284 | 0, /* */
|
---|
| 3285 | 0x3f, /* QZ_F5 0x60 */
|
---|
| 3286 | 0x40, /* QZ_F6 0x61 */
|
---|
| 3287 | 0x41, /* QZ_F7 0x62 */
|
---|
| 3288 | 0x3d, /* QZ_F3 0x63 */
|
---|
| 3289 | 0x42, /* QZ_F8 0x64 */
|
---|
| 3290 | 0x43, /* QZ_F9 0x65 */
|
---|
| 3291 | 0, /* */
|
---|
| 3292 | 0x57, /* QZ_F11 0x67 */
|
---|
| 3293 | 0, /* */
|
---|
[1877] | 3294 | 0x37|0x100, /* QZ_PRINT / F13 0x69 */
|
---|
[962] | 3295 | 0x63, /* QZ_F16 0x6A */
|
---|
| 3296 | 0x46, /* QZ_SCROLLOCK 0x6B */
|
---|
| 3297 | 0, /* */
|
---|
| 3298 | 0x44, /* QZ_F10 0x6D */
|
---|
[1877] | 3299 | 0x5d|0x100, /* */
|
---|
[962] | 3300 | 0x58, /* QZ_F12 0x6F */
|
---|
| 3301 | 0, /* */
|
---|
| 3302 | 0/* 0xe1,0x1d,0x45*/, /* QZ_PAUSE 0x71 */
|
---|
[1877] | 3303 | 0x52|0x100, /* QZ_INSERT / HELP 0x72 */
|
---|
| 3304 | 0x47|0x100, /* QZ_HOME 0x73 */
|
---|
| 3305 | 0x49|0x100, /* QZ_PAGEUP 0x74 */
|
---|
| 3306 | 0x53|0x100, /* QZ_DELETE 0x75 */
|
---|
[962] | 3307 | 0x3e, /* QZ_F4 0x76 */
|
---|
[1877] | 3308 | 0x4f|0x100, /* QZ_END 0x77 */
|
---|
[962] | 3309 | 0x3c, /* QZ_F2 0x78 */
|
---|
[1877] | 3310 | 0x51|0x100, /* QZ_PAGEDOWN 0x79 */
|
---|
[962] | 3311 | 0x3b, /* QZ_F1 0x7A */
|
---|
[1877] | 3312 | 0x4b|0x100, /* QZ_LEFT 0x7B */
|
---|
| 3313 | 0x4d|0x100, /* QZ_RIGHT 0x7C */
|
---|
| 3314 | 0x50|0x100, /* QZ_DOWN 0x7D */
|
---|
| 3315 | 0x48|0x100, /* QZ_UP 0x7E */
|
---|
| 3316 | 0x5e|0x100, /* QZ_POWER 0x7F */ /* have different break key! */
|
---|
[962] | 3317 | };
|
---|
| 3318 |
|
---|
| 3319 | if (keycode == 0)
|
---|
| 3320 | {
|
---|
| 3321 | /* This could be a modifier or it could be 'a'. */
|
---|
| 3322 | switch (ev->keysym.sym)
|
---|
| 3323 | {
|
---|
| 3324 | case SDLK_LSHIFT: keycode = 0x2a; break;
|
---|
| 3325 | case SDLK_RSHIFT: keycode = 0x36; break;
|
---|
| 3326 | case SDLK_LCTRL: keycode = 0x1d; break;
|
---|
[1877] | 3327 | case SDLK_RCTRL: keycode = 0x1d | 0x100; break;
|
---|
[962] | 3328 | case SDLK_LALT: keycode = 0x38; break;
|
---|
| 3329 | case SDLK_MODE: /* alt gr */
|
---|
[1877] | 3330 | case SDLK_RALT: keycode = 0x38 | 0x100; break;
|
---|
[962] | 3331 | case SDLK_RMETA:
|
---|
[1877] | 3332 | case SDLK_RSUPER: keycode = 0x5c | 0x100; break;
|
---|
[962] | 3333 | case SDLK_LMETA:
|
---|
[1877] | 3334 | case SDLK_LSUPER: keycode = 0x5b | 0x100; break;
|
---|
[33540] | 3335 | /* Assumes normal key. */
|
---|
[962] | 3336 | default: keycode = s_aMacToSet1[keycode]; break;
|
---|
| 3337 | }
|
---|
| 3338 | }
|
---|
| 3339 | else
|
---|
| 3340 | {
|
---|
| 3341 | if ((unsigned)keycode < RT_ELEMENTS(s_aMacToSet1))
|
---|
| 3342 | keycode = s_aMacToSet1[keycode];
|
---|
| 3343 | else
|
---|
| 3344 | keycode = 0;
|
---|
| 3345 | if (!keycode)
|
---|
| 3346 | {
|
---|
| 3347 | #ifdef DEBUG_bird
|
---|
| 3348 | RTPrintf("Untranslated: keycode=%#x (%d)\n", keycode, keycode);
|
---|
[1] | 3349 | #endif
|
---|
[962] | 3350 | keycode = Keyevent2KeycodeFallback(ev);
|
---|
| 3351 | }
|
---|
| 3352 | }
|
---|
| 3353 | #ifdef DEBUG_bird
|
---|
| 3354 | RTPrintf("scancode=%#x -> %#x\n", ev->keysym.scancode, keycode);
|
---|
| 3355 | #endif
|
---|
| 3356 |
|
---|
[6886] | 3357 | #elif RT_OS_OS2
|
---|
[20433] | 3358 | keycode = Keyevent2KeycodeFallback(ev);
|
---|
[3669] | 3359 | #endif /* RT_OS_DARWIN */
|
---|
[1] | 3360 | return keycode;
|
---|
| 3361 | }
|
---|
| 3362 |
|
---|
| 3363 | /**
|
---|
| 3364 | * Releases any modifier keys that are currently in pressed state.
|
---|
| 3365 | */
|
---|
| 3366 | static void ResetKeys(void)
|
---|
| 3367 | {
|
---|
| 3368 | int i;
|
---|
| 3369 |
|
---|
[34645] | 3370 | if (!gpKeyboard)
|
---|
[1] | 3371 | return;
|
---|
| 3372 |
|
---|
| 3373 | for(i = 0; i < 256; i++)
|
---|
| 3374 | {
|
---|
| 3375 | if (gaModifiersState[i])
|
---|
| 3376 | {
|
---|
| 3377 | if (i & 0x80)
|
---|
[34645] | 3378 | gpKeyboard->PutScancode(0xe0);
|
---|
| 3379 | gpKeyboard->PutScancode(i | 0x80);
|
---|
[1] | 3380 | gaModifiersState[i] = 0;
|
---|
| 3381 | }
|
---|
| 3382 | }
|
---|
| 3383 | }
|
---|
| 3384 |
|
---|
| 3385 | /**
|
---|
| 3386 | * Keyboard event handler.
|
---|
| 3387 | *
|
---|
| 3388 | * @param ev SDL keyboard event.
|
---|
| 3389 | */
|
---|
| 3390 | static void ProcessKey(SDL_KeyboardEvent *ev)
|
---|
| 3391 | {
|
---|
[20433] | 3392 | #if (defined(DEBUG) || defined(VBOX_WITH_STATISTICS)) && !defined(VBOX_WITH_SDL13)
|
---|
[34645] | 3393 | if (gpMachineDebugger && ev->type == SDL_KEYDOWN)
|
---|
[1] | 3394 | {
|
---|
| 3395 | // first handle the debugger hotkeys
|
---|
| 3396 | uint8_t *keystate = SDL_GetKeyState(NULL);
|
---|
[5441] | 3397 | #if 0
|
---|
[1] | 3398 | // CTRL+ALT+Fn is not free on Linux hosts with Xorg ..
|
---|
| 3399 | if (keystate[SDLK_LALT] && !keystate[SDLK_LCTRL])
|
---|
| 3400 | #else
|
---|
| 3401 | if (keystate[SDLK_LALT] && keystate[SDLK_LCTRL])
|
---|
| 3402 | #endif
|
---|
| 3403 | {
|
---|
| 3404 | switch (ev->keysym.sym)
|
---|
| 3405 | {
|
---|
| 3406 | // pressing CTRL+ALT+F11 dumps the statistics counter
|
---|
| 3407 | case SDLK_F12:
|
---|
| 3408 | RTPrintf("ResetStats\n"); /* Visual feedback in console window */
|
---|
[34645] | 3409 | gpMachineDebugger->ResetStats(NULL);
|
---|
[1] | 3410 | break;
|
---|
| 3411 | // pressing CTRL+ALT+F12 resets all statistics counter
|
---|
| 3412 | case SDLK_F11:
|
---|
[34645] | 3413 | gpMachineDebugger->DumpStats(NULL);
|
---|
[1] | 3414 | RTPrintf("DumpStats\n"); /* Vistual feedback in console window */
|
---|
| 3415 | break;
|
---|
| 3416 | default:
|
---|
| 3417 | break;
|
---|
| 3418 | }
|
---|
| 3419 | }
|
---|
| 3420 | #if 1
|
---|
| 3421 | else if (keystate[SDLK_LALT] && !keystate[SDLK_LCTRL])
|
---|
| 3422 | {
|
---|
| 3423 | switch (ev->keysym.sym)
|
---|
| 3424 | {
|
---|
| 3425 | // pressing Alt-F12 toggles the supervisor recompiler
|
---|
| 3426 | case SDLK_F12:
|
---|
| 3427 | {
|
---|
| 3428 | BOOL recompileSupervisor;
|
---|
[34645] | 3429 | gpMachineDebugger->COMGETTER(RecompileSupervisor)(&recompileSupervisor);
|
---|
| 3430 | gpMachineDebugger->COMSETTER(RecompileSupervisor)(!recompileSupervisor);
|
---|
[1] | 3431 | break;
|
---|
| 3432 | }
|
---|
| 3433 | // pressing Alt-F11 toggles the user recompiler
|
---|
| 3434 | case SDLK_F11:
|
---|
| 3435 | {
|
---|
| 3436 | BOOL recompileUser;
|
---|
[34645] | 3437 | gpMachineDebugger->COMGETTER(RecompileUser)(&recompileUser);
|
---|
| 3438 | gpMachineDebugger->COMSETTER(RecompileUser)(!recompileUser);
|
---|
[1] | 3439 | break;
|
---|
| 3440 | }
|
---|
| 3441 | // pressing Alt-F10 toggles the patch manager
|
---|
| 3442 | case SDLK_F10:
|
---|
| 3443 | {
|
---|
| 3444 | BOOL patmEnabled;
|
---|
[34645] | 3445 | gpMachineDebugger->COMGETTER(PATMEnabled)(&patmEnabled);
|
---|
| 3446 | gpMachineDebugger->COMSETTER(PATMEnabled)(!patmEnabled);
|
---|
[1] | 3447 | break;
|
---|
| 3448 | }
|
---|
| 3449 | // pressing Alt-F9 toggles CSAM
|
---|
| 3450 | case SDLK_F9:
|
---|
| 3451 | {
|
---|
| 3452 | BOOL csamEnabled;
|
---|
[34645] | 3453 | gpMachineDebugger->COMGETTER(CSAMEnabled)(&csamEnabled);
|
---|
| 3454 | gpMachineDebugger->COMSETTER(CSAMEnabled)(!csamEnabled);
|
---|
[1] | 3455 | break;
|
---|
| 3456 | }
|
---|
| 3457 | // pressing Alt-F8 toggles singlestepping mode
|
---|
| 3458 | case SDLK_F8:
|
---|
| 3459 | {
|
---|
| 3460 | BOOL singlestepEnabled;
|
---|
[34645] | 3461 | gpMachineDebugger->COMGETTER(Singlestep)(&singlestepEnabled);
|
---|
| 3462 | gpMachineDebugger->COMSETTER(Singlestep)(!singlestepEnabled);
|
---|
[1] | 3463 | break;
|
---|
| 3464 | }
|
---|
| 3465 | default:
|
---|
| 3466 | break;
|
---|
| 3467 | }
|
---|
| 3468 | }
|
---|
| 3469 | #endif
|
---|
| 3470 | // pressing Ctrl-F12 toggles the logger
|
---|
| 3471 | else if ((keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && ev->keysym.sym == SDLK_F12)
|
---|
| 3472 | {
|
---|
| 3473 | BOOL logEnabled = TRUE;
|
---|
[34645] | 3474 | gpMachineDebugger->COMGETTER(LogEnabled)(&logEnabled);
|
---|
| 3475 | gpMachineDebugger->COMSETTER(LogEnabled)(!logEnabled);
|
---|
[1] | 3476 | #ifdef DEBUG_bird
|
---|
| 3477 | return;
|
---|
| 3478 | #endif
|
---|
| 3479 | }
|
---|
| 3480 | // pressing F12 sets a logmark
|
---|
| 3481 | else if (ev->keysym.sym == SDLK_F12)
|
---|
| 3482 | {
|
---|
| 3483 | RTLogPrintf("****** LOGGING MARK ******\n");
|
---|
| 3484 | RTLogFlush(NULL);
|
---|
| 3485 | }
|
---|
| 3486 | // now update the titlebar flags
|
---|
| 3487 | UpdateTitlebar(TITLEBAR_NORMAL);
|
---|
| 3488 | }
|
---|
| 3489 | #endif // DEBUG || VBOX_WITH_STATISTICS
|
---|
| 3490 |
|
---|
| 3491 | // the pause key is the weirdest, needs special handling
|
---|
| 3492 | if (ev->keysym.sym == SDLK_PAUSE)
|
---|
| 3493 | {
|
---|
| 3494 | int v = 0;
|
---|
| 3495 | if (ev->type == SDL_KEYUP)
|
---|
| 3496 | v |= 0x80;
|
---|
[34645] | 3497 | gpKeyboard->PutScancode(0xe1);
|
---|
| 3498 | gpKeyboard->PutScancode(0x1d | v);
|
---|
| 3499 | gpKeyboard->PutScancode(0x45 | v);
|
---|
[1] | 3500 | return;
|
---|
| 3501 | }
|
---|
| 3502 |
|
---|
| 3503 | /*
|
---|
| 3504 | * Perform SDL key event to scancode conversion
|
---|
| 3505 | */
|
---|
| 3506 | int keycode = Keyevent2Keycode(ev);
|
---|
| 3507 |
|
---|
| 3508 | switch(keycode)
|
---|
| 3509 | {
|
---|
| 3510 | case 0x00:
|
---|
| 3511 | {
|
---|
| 3512 | /* sent when leaving window: reset the modifiers state */
|
---|
| 3513 | ResetKeys();
|
---|
| 3514 | return;
|
---|
| 3515 | }
|
---|
| 3516 |
|
---|
[1877] | 3517 | case 0x2a: /* Left Shift */
|
---|
| 3518 | case 0x36: /* Right Shift */
|
---|
| 3519 | case 0x1d: /* Left CTRL */
|
---|
| 3520 | case 0x1d|0x100: /* Right CTRL */
|
---|
| 3521 | case 0x38: /* Left ALT */
|
---|
| 3522 | case 0x38|0x100: /* Right ALT */
|
---|
[1] | 3523 | {
|
---|
| 3524 | if (ev->type == SDL_KEYUP)
|
---|
[10620] | 3525 | gaModifiersState[keycode & ~0x100] = 0;
|
---|
[1] | 3526 | else
|
---|
[10620] | 3527 | gaModifiersState[keycode & ~0x100] = 1;
|
---|
[1] | 3528 | break;
|
---|
| 3529 | }
|
---|
| 3530 |
|
---|
| 3531 | case 0x45: /* Num Lock */
|
---|
| 3532 | case 0x3a: /* Caps Lock */
|
---|
| 3533 | {
|
---|
[3098] | 3534 | /*
|
---|
| 3535 | * SDL generates a KEYDOWN event if the lock key is active and a KEYUP event
|
---|
| 3536 | * if the lock key is inactive. See SDL_DISABLE_LOCK_KEYS.
|
---|
| 3537 | */
|
---|
| 3538 | if (ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP)
|
---|
[1] | 3539 | {
|
---|
[34645] | 3540 | gpKeyboard->PutScancode(keycode);
|
---|
| 3541 | gpKeyboard->PutScancode(keycode | 0x80);
|
---|
[1] | 3542 | }
|
---|
| 3543 | return;
|
---|
| 3544 | }
|
---|
| 3545 | }
|
---|
| 3546 |
|
---|
[255] | 3547 | if (ev->type != SDL_KEYDOWN)
|
---|
[1] | 3548 | {
|
---|
[255] | 3549 | /*
|
---|
| 3550 | * Some keyboards (e.g. the one of mine T60) don't send a NumLock scan code on every
|
---|
| 3551 | * press of the key. Both the guest and the host should agree on the NumLock state.
|
---|
| 3552 | * If they differ, we try to alter the guest NumLock state by sending the NumLock key
|
---|
| 3553 | * scancode. We will get a feedback through the KBD_CMD_SET_LEDS command if the guest
|
---|
| 3554 | * tries to set/clear the NumLock LED. If a (silly) guest doesn't change the LED, don't
|
---|
| 3555 | * bother him with NumLock scancodes. At least our BIOS, Linux and Windows handle the
|
---|
| 3556 | * NumLock LED well.
|
---|
| 3557 | */
|
---|
[315] | 3558 | if ( gcGuestNumLockAdaptions
|
---|
[255] | 3559 | && (gfGuestNumLockPressed ^ !!(SDL_GetModState() & KMOD_NUM)))
|
---|
| 3560 | {
|
---|
[315] | 3561 | gcGuestNumLockAdaptions--;
|
---|
[34645] | 3562 | gpKeyboard->PutScancode(0x45);
|
---|
| 3563 | gpKeyboard->PutScancode(0x45 | 0x80);
|
---|
[255] | 3564 | }
|
---|
[315] | 3565 | if ( gcGuestCapsLockAdaptions
|
---|
[255] | 3566 | && (gfGuestCapsLockPressed ^ !!(SDL_GetModState() & KMOD_CAPS)))
|
---|
| 3567 | {
|
---|
[315] | 3568 | gcGuestCapsLockAdaptions--;
|
---|
[34645] | 3569 | gpKeyboard->PutScancode(0x3a);
|
---|
| 3570 | gpKeyboard->PutScancode(0x3a | 0x80);
|
---|
[255] | 3571 | }
|
---|
[1] | 3572 | }
|
---|
| 3573 |
|
---|
| 3574 | /*
|
---|
| 3575 | * Now we send the event. Apply extended and release prefixes.
|
---|
| 3576 | */
|
---|
[1877] | 3577 | if (keycode & 0x100)
|
---|
[34645] | 3578 | gpKeyboard->PutScancode(0xe0);
|
---|
[1] | 3579 |
|
---|
[34645] | 3580 | gpKeyboard->PutScancode(ev->type == SDL_KEYUP ? (keycode & 0x7f) | 0x80
|
---|
[1877] | 3581 | : (keycode & 0x7f));
|
---|
[1] | 3582 | }
|
---|
| 3583 |
|
---|
[3669] | 3584 | #ifdef RT_OS_DARWIN
|
---|
[965] | 3585 | #include <Carbon/Carbon.h>
|
---|
[20374] | 3586 | RT_C_DECLS_BEGIN
|
---|
[965] | 3587 | /* Private interface in 10.3 and later. */
|
---|
| 3588 | typedef int CGSConnection;
|
---|
| 3589 | typedef enum
|
---|
| 3590 | {
|
---|
| 3591 | kCGSGlobalHotKeyEnable = 0,
|
---|
| 3592 | kCGSGlobalHotKeyDisable,
|
---|
| 3593 | kCGSGlobalHotKeyInvalid = -1 /* bird */
|
---|
| 3594 | } CGSGlobalHotKeyOperatingMode;
|
---|
| 3595 | extern CGSConnection _CGSDefaultConnection(void);
|
---|
| 3596 | extern CGError CGSGetGlobalHotKeyOperatingMode(CGSConnection Connection, CGSGlobalHotKeyOperatingMode *enmMode);
|
---|
| 3597 | extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection Connection, CGSGlobalHotKeyOperatingMode enmMode);
|
---|
[20374] | 3598 | RT_C_DECLS_END
|
---|
[965] | 3599 |
|
---|
| 3600 | /** Keeping track of whether we disabled the hotkeys or not. */
|
---|
| 3601 | static bool g_fHotKeysDisabled = false;
|
---|
| 3602 | /** Whether we've connected or not. */
|
---|
| 3603 | static bool g_fConnectedToCGS = false;
|
---|
| 3604 | /** Cached connection. */
|
---|
| 3605 | static CGSConnection g_CGSConnection;
|
---|
| 3606 |
|
---|
[1] | 3607 | /**
|
---|
[965] | 3608 | * Disables or enabled global hot keys.
|
---|
| 3609 | */
|
---|
| 3610 | static void DisableGlobalHotKeys(bool fDisable)
|
---|
| 3611 | {
|
---|
| 3612 | if (!g_fConnectedToCGS)
|
---|
| 3613 | {
|
---|
| 3614 | g_CGSConnection = _CGSDefaultConnection();
|
---|
| 3615 | g_fConnectedToCGS = true;
|
---|
| 3616 | }
|
---|
| 3617 |
|
---|
| 3618 | /* get current mode. */
|
---|
| 3619 | CGSGlobalHotKeyOperatingMode enmMode = kCGSGlobalHotKeyInvalid;
|
---|
| 3620 | CGSGetGlobalHotKeyOperatingMode(g_CGSConnection, &enmMode);
|
---|
| 3621 |
|
---|
| 3622 | /* calc new mode. */
|
---|
| 3623 | if (fDisable)
|
---|
| 3624 | {
|
---|
| 3625 | if (enmMode != kCGSGlobalHotKeyEnable)
|
---|
| 3626 | return;
|
---|
| 3627 | enmMode = kCGSGlobalHotKeyDisable;
|
---|
| 3628 | }
|
---|
| 3629 | else
|
---|
| 3630 | {
|
---|
| 3631 | if ( enmMode != kCGSGlobalHotKeyDisable
|
---|
| 3632 | /*|| !g_fHotKeysDisabled*/)
|
---|
| 3633 | return;
|
---|
| 3634 | enmMode = kCGSGlobalHotKeyEnable;
|
---|
| 3635 | }
|
---|
| 3636 |
|
---|
| 3637 | /* try set it and check the actual result. */
|
---|
| 3638 | CGSSetGlobalHotKeyOperatingMode(g_CGSConnection, enmMode);
|
---|
| 3639 | CGSGlobalHotKeyOperatingMode enmNewMode = kCGSGlobalHotKeyInvalid;
|
---|
| 3640 | CGSGetGlobalHotKeyOperatingMode(g_CGSConnection, &enmNewMode);
|
---|
| 3641 | if (enmNewMode == enmMode)
|
---|
| 3642 | g_fHotKeysDisabled = enmMode == kCGSGlobalHotKeyDisable;
|
---|
| 3643 | }
|
---|
[3669] | 3644 | #endif /* RT_OS_DARWIN */
|
---|
[965] | 3645 |
|
---|
| 3646 | /**
|
---|
[1] | 3647 | * Start grabbing the mouse.
|
---|
| 3648 | */
|
---|
| 3649 | static void InputGrabStart(void)
|
---|
| 3650 | {
|
---|
[3669] | 3651 | #ifdef RT_OS_DARWIN
|
---|
[965] | 3652 | DisableGlobalHotKeys(true);
|
---|
| 3653 | #endif
|
---|
[26782] | 3654 | if (!gfGuestNeedsHostCursor && gfRelativeMouseGuest)
|
---|
[1] | 3655 | SDL_ShowCursor(SDL_DISABLE);
|
---|
| 3656 | SDL_WM_GrabInput(SDL_GRAB_ON);
|
---|
| 3657 | // dummy read to avoid moving the mouse
|
---|
[20433] | 3658 | SDL_GetRelativeMouseState(
|
---|
| 3659 | #ifdef VBOX_WITH_SDL13
|
---|
| 3660 | 0,
|
---|
| 3661 | #endif
|
---|
| 3662 | NULL, NULL);
|
---|
[1] | 3663 | gfGrabbed = TRUE;
|
---|
| 3664 | UpdateTitlebar(TITLEBAR_NORMAL);
|
---|
| 3665 | }
|
---|
| 3666 |
|
---|
| 3667 | /**
|
---|
| 3668 | * End mouse grabbing.
|
---|
| 3669 | */
|
---|
| 3670 | static void InputGrabEnd(void)
|
---|
| 3671 | {
|
---|
| 3672 | SDL_WM_GrabInput(SDL_GRAB_OFF);
|
---|
[26782] | 3673 | if (!gfGuestNeedsHostCursor && gfRelativeMouseGuest)
|
---|
[1] | 3674 | SDL_ShowCursor(SDL_ENABLE);
|
---|
[3669] | 3675 | #ifdef RT_OS_DARWIN
|
---|
[965] | 3676 | DisableGlobalHotKeys(false);
|
---|
| 3677 | #endif
|
---|
[1] | 3678 | gfGrabbed = FALSE;
|
---|
| 3679 | UpdateTitlebar(TITLEBAR_NORMAL);
|
---|
| 3680 | }
|
---|
| 3681 |
|
---|
| 3682 | /**
|
---|
| 3683 | * Query mouse position and button state from SDL and send to the VM
|
---|
| 3684 | *
|
---|
| 3685 | * @param dz Relative mouse wheel movement
|
---|
| 3686 | */
|
---|
[20433] | 3687 | static void SendMouseEvent(VBoxSDLFB *fb, int dz, int down, int button)
|
---|
[1] | 3688 | {
|
---|
| 3689 | int x, y, state, buttons;
|
---|
| 3690 | bool abs;
|
---|
| 3691 |
|
---|
[20627] | 3692 | #ifdef VBOX_WITH_SDL13
|
---|
[20626] | 3693 | if (!fb)
|
---|
[20433] | 3694 | {
|
---|
| 3695 | SDL_GetMouseState(0, &x, &y);
|
---|
| 3696 | RTPrintf("MouseEvent: Cannot find fb mouse = %d,%d\n", x, y);
|
---|
| 3697 | return;
|
---|
| 3698 | }
|
---|
[20610] | 3699 | #else
|
---|
[20611] | 3700 | AssertRelease(fb != NULL);
|
---|
[20433] | 3701 | #endif
|
---|
| 3702 |
|
---|
[1] | 3703 | /*
|
---|
| 3704 | * If supported and we're not in grabbed mode, we'll use the absolute mouse.
|
---|
| 3705 | * If we are in grabbed mode and the guest is not able to draw the mouse cursor
|
---|
[26782] | 3706 | * itself, or can't handle relative reporting, we have to use absolute
|
---|
| 3707 | * coordinates, otherwise the host cursor and
|
---|
[1] | 3708 | * the coordinates the guest thinks the mouse is at could get out-of-sync. From
|
---|
| 3709 | * the SDL mailing list:
|
---|
| 3710 | *
|
---|
| 3711 | * "The event processing is usually asynchronous and so somewhat delayed, and
|
---|
| 3712 | * SDL_GetMouseState is returning the immediate mouse state. So at the time you
|
---|
| 3713 | * call SDL_GetMouseState, the "button" is already up."
|
---|
| 3714 | */
|
---|
[26782] | 3715 | abs = (UseAbsoluteMouse() && !gfGrabbed)
|
---|
| 3716 | || gfGuestNeedsHostCursor
|
---|
| 3717 | || !gfRelativeMouseGuest;
|
---|
[1] | 3718 |
|
---|
| 3719 | /* only used if abs == TRUE */
|
---|
[20433] | 3720 | int xOrigin = fb->getOriginX();
|
---|
| 3721 | int yOrigin = fb->getOriginY();
|
---|
| 3722 | int xMin = fb->getXOffset() + xOrigin;
|
---|
| 3723 | int yMin = fb->getYOffset() + yOrigin;
|
---|
| 3724 | int xMax = xMin + (int)fb->getGuestXRes();
|
---|
| 3725 | int yMax = yMin + (int)fb->getGuestYRes();
|
---|
[1] | 3726 |
|
---|
[20433] | 3727 | state = abs ? SDL_GetMouseState(
|
---|
| 3728 | #ifdef VBOX_WITH_SDL13
|
---|
| 3729 | 0,
|
---|
| 3730 | #endif
|
---|
| 3731 | &x, &y)
|
---|
| 3732 | : SDL_GetRelativeMouseState(
|
---|
| 3733 | #ifdef VBOX_WITH_SDL13
|
---|
| 3734 | 0,
|
---|
| 3735 | #endif
|
---|
| 3736 | &x, &y);
|
---|
[1] | 3737 |
|
---|
| 3738 | /*
|
---|
| 3739 | * process buttons
|
---|
| 3740 | */
|
---|
| 3741 | buttons = 0;
|
---|
| 3742 | if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
|
---|
| 3743 | buttons |= MouseButtonState_LeftButton;
|
---|
| 3744 | if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))
|
---|
| 3745 | buttons |= MouseButtonState_RightButton;
|
---|
| 3746 | if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE))
|
---|
| 3747 | buttons |= MouseButtonState_MiddleButton;
|
---|
| 3748 |
|
---|
| 3749 | if (abs)
|
---|
| 3750 | {
|
---|
[20433] | 3751 | x += xOrigin;
|
---|
| 3752 | y += yOrigin;
|
---|
| 3753 |
|
---|
[1] | 3754 | /*
|
---|
| 3755 | * Check if the mouse event is inside the guest area. This solves the
|
---|
| 3756 | * following problem: Some guests switch off the VBox hardware mouse
|
---|
| 3757 | * cursor and draw the mouse cursor itself instead. Moving the mouse
|
---|
| 3758 | * outside the guest area then leads to annoying mouse hangs if we
|
---|
| 3759 | * don't pass mouse motion events into the guest.
|
---|
| 3760 | */
|
---|
| 3761 | if (x < xMin || y < yMin || x > xMax || y > yMax)
|
---|
| 3762 | {
|
---|
| 3763 | /*
|
---|
| 3764 | * Cursor outside of valid guest area (outside window or in secure
|
---|
| 3765 | * label area. Don't allow any mouse button press.
|
---|
| 3766 | */
|
---|
| 3767 | button = 0;
|
---|
| 3768 |
|
---|
| 3769 | /*
|
---|
| 3770 | * Release any pressed button.
|
---|
| 3771 | */
|
---|
| 3772 | #if 0
|
---|
| 3773 | /* disabled on customers request */
|
---|
| 3774 | buttons &= ~(MouseButtonState_LeftButton |
|
---|
| 3775 | MouseButtonState_MiddleButton |
|
---|
| 3776 | MouseButtonState_RightButton);
|
---|
| 3777 | #endif
|
---|
| 3778 |
|
---|
| 3779 | /*
|
---|
| 3780 | * Prevent negative coordinates.
|
---|
| 3781 | */
|
---|
| 3782 | if (x < xMin) x = xMin;
|
---|
| 3783 | if (x > xMax) x = xMax;
|
---|
| 3784 | if (y < yMin) y = yMin;
|
---|
| 3785 | if (y > yMax) y = yMax;
|
---|
| 3786 |
|
---|
| 3787 | if (!gpOffCursor)
|
---|
| 3788 | {
|
---|
| 3789 | gpOffCursor = SDL_GetCursor(); /* Cursor image */
|
---|
| 3790 | gfOffCursorActive = SDL_ShowCursor(-1); /* enabled / disabled */
|
---|
| 3791 | SDL_SetCursor(gpDefaultCursor);
|
---|
[28205] | 3792 | SDL_ShowCursor(SDL_ENABLE);
|
---|
[1] | 3793 | }
|
---|
| 3794 | }
|
---|
| 3795 | else
|
---|
| 3796 | {
|
---|
| 3797 | if (gpOffCursor)
|
---|
| 3798 | {
|
---|
| 3799 | /*
|
---|
| 3800 | * We just entered the valid guest area. Restore the guest mouse
|
---|
| 3801 | * cursor.
|
---|
| 3802 | */
|
---|
| 3803 | SDL_SetCursor(gpOffCursor);
|
---|
| 3804 | SDL_ShowCursor(gfOffCursorActive ? SDL_ENABLE : SDL_DISABLE);
|
---|
| 3805 | gpOffCursor = NULL;
|
---|
| 3806 | }
|
---|
| 3807 | }
|
---|
| 3808 | }
|
---|
| 3809 |
|
---|
| 3810 | /*
|
---|
| 3811 | * Button was pressed but that press is not reflected in the button state?
|
---|
| 3812 | */
|
---|
| 3813 | if (down && !(state & SDL_BUTTON(button)))
|
---|
| 3814 | {
|
---|
| 3815 | /*
|
---|
| 3816 | * It can happen that a mouse up event follows a mouse down event immediately
|
---|
| 3817 | * and we see the events when the bit in the button state is already cleared
|
---|
| 3818 | * again. In that case we simulate the mouse down event.
|
---|
| 3819 | */
|
---|
| 3820 | int tmp_button = 0;
|
---|
| 3821 | switch (button)
|
---|
| 3822 | {
|
---|
| 3823 | case SDL_BUTTON_LEFT: tmp_button = MouseButtonState_LeftButton; break;
|
---|
| 3824 | case SDL_BUTTON_MIDDLE: tmp_button = MouseButtonState_MiddleButton; break;
|
---|
| 3825 | case SDL_BUTTON_RIGHT: tmp_button = MouseButtonState_RightButton; break;
|
---|
| 3826 | }
|
---|
| 3827 |
|
---|
| 3828 | if (abs)
|
---|
| 3829 | {
|
---|
| 3830 | /**
|
---|
| 3831 | * @todo
|
---|
| 3832 | * PutMouseEventAbsolute() expects x and y starting from 1,1.
|
---|
| 3833 | * should we do the increment internally in PutMouseEventAbsolute()
|
---|
| 3834 | * or state it in PutMouseEventAbsolute() docs?
|
---|
| 3835 | */
|
---|
[34645] | 3836 | gpMouse->PutMouseEventAbsolute(x + 1 - xMin + xOrigin,
|
---|
| 3837 | y + 1 - yMin + yOrigin,
|
---|
| 3838 | dz, 0 /* horizontal scroll wheel */,
|
---|
| 3839 | buttons | tmp_button);
|
---|
[1] | 3840 | }
|
---|
| 3841 | else
|
---|
| 3842 | {
|
---|
[34645] | 3843 | gpMouse->PutMouseEvent(0, 0, dz,
|
---|
| 3844 | 0 /* horizontal scroll wheel */,
|
---|
| 3845 | buttons | tmp_button);
|
---|
[1] | 3846 | }
|
---|
| 3847 | }
|
---|
| 3848 |
|
---|
| 3849 | // now send the mouse event
|
---|
| 3850 | if (abs)
|
---|
| 3851 | {
|
---|
| 3852 | /**
|
---|
| 3853 | * @todo
|
---|
| 3854 | * PutMouseEventAbsolute() expects x and y starting from 1,1.
|
---|
| 3855 | * should we do the increment internally in PutMouseEventAbsolute()
|
---|
| 3856 | * or state it in PutMouseEventAbsolute() docs?
|
---|
| 3857 | */
|
---|
[34645] | 3858 | gpMouse->PutMouseEventAbsolute(x + 1 - xMin + xOrigin,
|
---|
| 3859 | y + 1 - yMin + yOrigin,
|
---|
| 3860 | dz, 0 /* Horizontal wheel */, buttons);
|
---|
[1] | 3861 | }
|
---|
| 3862 | else
|
---|
| 3863 | {
|
---|
[34645] | 3864 | gpMouse->PutMouseEvent(x, y, dz, 0 /* Horizontal wheel */, buttons);
|
---|
[1] | 3865 | }
|
---|
| 3866 | }
|
---|
| 3867 |
|
---|
| 3868 | /**
|
---|
| 3869 | * Resets the VM
|
---|
| 3870 | */
|
---|
| 3871 | void ResetVM(void)
|
---|
| 3872 | {
|
---|
[34645] | 3873 | if (gpConsole)
|
---|
| 3874 | gpConsole->Reset();
|
---|
[1] | 3875 | }
|
---|
| 3876 |
|
---|
| 3877 | /**
|
---|
| 3878 | * Initiates a saved state and updates the titlebar with progress information
|
---|
| 3879 | */
|
---|
| 3880 | void SaveState(void)
|
---|
| 3881 | {
|
---|
| 3882 | ResetKeys();
|
---|
| 3883 | RTThreadYield();
|
---|
| 3884 | if (gfGrabbed)
|
---|
| 3885 | InputGrabEnd();
|
---|
| 3886 | RTThreadYield();
|
---|
| 3887 | UpdateTitlebar(TITLEBAR_SAVE);
|
---|
[34645] | 3888 | gpProgress = NULL;
|
---|
| 3889 | HRESULT rc = gpConsole->SaveState(gpProgress.asOutParam());
|
---|
[33838] | 3890 | if (FAILED(rc))
|
---|
[1] | 3891 | {
|
---|
| 3892 | RTPrintf("Error saving state! rc = 0x%x\n", rc);
|
---|
| 3893 | return;
|
---|
| 3894 | }
|
---|
[34645] | 3895 | Assert(gpProgress);
|
---|
[1] | 3896 |
|
---|
| 3897 | /*
|
---|
| 3898 | * Wait for the operation to be completed and work
|
---|
| 3899 | * the title bar in the mean while.
|
---|
| 3900 | */
|
---|
[18274] | 3901 | ULONG cPercent = 0;
|
---|
[3669] | 3902 | #ifndef RT_OS_DARWIN /* don't break the other guys yet. */
|
---|
[1] | 3903 | for (;;)
|
---|
| 3904 | {
|
---|
| 3905 | BOOL fCompleted = false;
|
---|
[34645] | 3906 | rc = gpProgress->COMGETTER(Completed)(&fCompleted);
|
---|
[1] | 3907 | if (FAILED(rc) || fCompleted)
|
---|
| 3908 | break;
|
---|
[18274] | 3909 | ULONG cPercentNow;
|
---|
[34645] | 3910 | rc = gpProgress->COMGETTER(Percent)(&cPercentNow);
|
---|
[1] | 3911 | if (FAILED(rc))
|
---|
| 3912 | break;
|
---|
| 3913 | if (cPercentNow != cPercent)
|
---|
| 3914 | {
|
---|
| 3915 | UpdateTitlebar(TITLEBAR_SAVE, cPercent);
|
---|
| 3916 | cPercent = cPercentNow;
|
---|
| 3917 | }
|
---|
| 3918 |
|
---|
| 3919 | /* wait */
|
---|
[34645] | 3920 | rc = gpProgress->WaitForCompletion(100);
|
---|
[1] | 3921 | if (FAILED(rc))
|
---|
| 3922 | break;
|
---|
| 3923 | /// @todo process gui events.
|
---|
| 3924 | }
|
---|
| 3925 |
|
---|
[967] | 3926 | #else /* new loop which processes GUI events while saving. */
|
---|
| 3927 |
|
---|
| 3928 | /* start regular timer so we don't starve in the event loop */
|
---|
| 3929 | SDL_TimerID sdlTimer;
|
---|
| 3930 | sdlTimer = SDL_AddTimer(100, StartupTimer, NULL);
|
---|
| 3931 |
|
---|
| 3932 | for (;;)
|
---|
| 3933 | {
|
---|
| 3934 | /*
|
---|
| 3935 | * Check for completion.
|
---|
| 3936 | */
|
---|
| 3937 | BOOL fCompleted = false;
|
---|
[34645] | 3938 | rc = gpProgress->COMGETTER(Completed)(&fCompleted);
|
---|
[967] | 3939 | if (FAILED(rc) || fCompleted)
|
---|
| 3940 | break;
|
---|
[18274] | 3941 | ULONG cPercentNow;
|
---|
[34645] | 3942 | rc = gpProgress->COMGETTER(Percent)(&cPercentNow);
|
---|
[967] | 3943 | if (FAILED(rc))
|
---|
| 3944 | break;
|
---|
| 3945 | if (cPercentNow != cPercent)
|
---|
| 3946 | {
|
---|
| 3947 | UpdateTitlebar(TITLEBAR_SAVE, cPercent);
|
---|
| 3948 | cPercent = cPercentNow;
|
---|
| 3949 | }
|
---|
| 3950 |
|
---|
| 3951 | /*
|
---|
| 3952 | * Wait for and process GUI a event.
|
---|
| 3953 | * This is necessary for XPCOM IPC and for updating the
|
---|
| 3954 | * title bar on the Mac.
|
---|
| 3955 | */
|
---|
| 3956 | SDL_Event event;
|
---|
[3289] | 3957 | if (WaitSDLEvent(&event))
|
---|
[967] | 3958 | {
|
---|
| 3959 | switch (event.type)
|
---|
| 3960 | {
|
---|
| 3961 | /*
|
---|
| 3962 | * Timer event preventing us from getting stuck.
|
---|
| 3963 | */
|
---|
| 3964 | case SDL_USER_EVENT_TIMER:
|
---|
| 3965 | break;
|
---|
| 3966 |
|
---|
| 3967 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
| 3968 | /*
|
---|
| 3969 | * User specific XPCOM event queue event
|
---|
| 3970 | */
|
---|
| 3971 | case SDL_USER_EVENT_XPCOM_EVENTQUEUE:
|
---|
| 3972 | {
|
---|
| 3973 | LogFlow(("SDL_USER_EVENT_XPCOM_EVENTQUEUE: processing XPCOM event queue...\n"));
|
---|
| 3974 | eventQ->ProcessPendingEvents();
|
---|
| 3975 | signalXPCOMEventQueueThread();
|
---|
| 3976 | break;
|
---|
| 3977 | }
|
---|
| 3978 | #endif /* USE_XPCOM_QUEUE_THREAD */
|
---|
| 3979 |
|
---|
| 3980 |
|
---|
| 3981 | /*
|
---|
| 3982 | * Ignore all other events.
|
---|
| 3983 | */
|
---|
| 3984 | case SDL_USER_EVENT_RESIZE:
|
---|
| 3985 | case SDL_USER_EVENT_TERMINATE:
|
---|
| 3986 | default:
|
---|
| 3987 | break;
|
---|
| 3988 | }
|
---|
| 3989 | }
|
---|
| 3990 | }
|
---|
| 3991 |
|
---|
| 3992 | /* kill the timer */
|
---|
| 3993 | SDL_RemoveTimer(sdlTimer);
|
---|
| 3994 | sdlTimer = 0;
|
---|
| 3995 |
|
---|
[3669] | 3996 | #endif /* RT_OS_DARWIN */
|
---|
[967] | 3997 |
|
---|
[1] | 3998 | /*
|
---|
| 3999 | * What's the result of the operation?
|
---|
| 4000 | */
|
---|
[20267] | 4001 | LONG lrc;
|
---|
[34645] | 4002 | rc = gpProgress->COMGETTER(ResultCode)(&lrc);
|
---|
[1] | 4003 | if (FAILED(rc))
|
---|
| 4004 | lrc = ~0;
|
---|
| 4005 | if (!lrc)
|
---|
| 4006 | {
|
---|
| 4007 | UpdateTitlebar(TITLEBAR_SAVE, 100);
|
---|
| 4008 | RTThreadYield();
|
---|
| 4009 | RTPrintf("Saved the state successfully.\n");
|
---|
| 4010 | }
|
---|
| 4011 | else
|
---|
| 4012 | RTPrintf("Error saving state, lrc=%d (%#x)\n", lrc, lrc);
|
---|
| 4013 | }
|
---|
| 4014 |
|
---|
| 4015 | /**
|
---|
| 4016 | * Build the titlebar string
|
---|
| 4017 | */
|
---|
| 4018 | static void UpdateTitlebar(TitlebarMode mode, uint32_t u32User)
|
---|
| 4019 | {
|
---|
[445] | 4020 | static char szTitle[1024] = {0};
|
---|
[1] | 4021 |
|
---|
| 4022 | /* back up current title */
|
---|
[445] | 4023 | char szPrevTitle[1024];
|
---|
| 4024 | strcpy(szPrevTitle, szTitle);
|
---|
[1] | 4025 |
|
---|
[34645] | 4026 | Bstr bstrName;
|
---|
| 4027 | gpMachine->COMGETTER(Name)(bstrName.asOutParam());
|
---|
[1] | 4028 |
|
---|
[26429] | 4029 | RTStrPrintf(szTitle, sizeof(szTitle), "%s - " VBOX_PRODUCT,
|
---|
[34645] | 4030 | !bstrName.isEmpty() ? Utf8Str(bstrName).c_str() : "<noname>");
|
---|
[1] | 4031 |
|
---|
| 4032 | /* which mode are we in? */
|
---|
| 4033 | switch (mode)
|
---|
| 4034 | {
|
---|
| 4035 | case TITLEBAR_NORMAL:
|
---|
| 4036 | {
|
---|
| 4037 | MachineState_T machineState;
|
---|
[34645] | 4038 | gpMachine->COMGETTER(State)(&machineState);
|
---|
[1] | 4039 | if (machineState == MachineState_Paused)
|
---|
[26429] | 4040 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle), " - [Paused]");
|
---|
[1] | 4041 |
|
---|
| 4042 | if (gfGrabbed)
|
---|
[26429] | 4043 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle), " - [Input captured]");
|
---|
[1] | 4044 |
|
---|
[26429] | 4045 | #if defined(DEBUG) || defined(VBOX_WITH_STATISTICS)
|
---|
[1] | 4046 | // do we have a debugger interface
|
---|
[34645] | 4047 | if (gpMachineDebugger)
|
---|
[1] | 4048 | {
|
---|
| 4049 | // query the machine state
|
---|
| 4050 | BOOL recompileSupervisor = FALSE;
|
---|
| 4051 | BOOL recompileUser = FALSE;
|
---|
| 4052 | BOOL patmEnabled = FALSE;
|
---|
| 4053 | BOOL csamEnabled = FALSE;
|
---|
| 4054 | BOOL singlestepEnabled = FALSE;
|
---|
| 4055 | BOOL logEnabled = FALSE;
|
---|
| 4056 | BOOL hwVirtEnabled = FALSE;
|
---|
[445] | 4057 | ULONG virtualTimeRate = 100;
|
---|
[34645] | 4058 | gpMachineDebugger->COMGETTER(RecompileSupervisor)(&recompileSupervisor);
|
---|
| 4059 | gpMachineDebugger->COMGETTER(RecompileUser)(&recompileUser);
|
---|
| 4060 | gpMachineDebugger->COMGETTER(PATMEnabled)(&patmEnabled);
|
---|
| 4061 | gpMachineDebugger->COMGETTER(CSAMEnabled)(&csamEnabled);
|
---|
| 4062 | gpMachineDebugger->COMGETTER(LogEnabled)(&logEnabled);
|
---|
| 4063 | gpMachineDebugger->COMGETTER(Singlestep)(&singlestepEnabled);
|
---|
| 4064 | gpMachineDebugger->COMGETTER(HWVirtExEnabled)(&hwVirtEnabled);
|
---|
| 4065 | gpMachineDebugger->COMGETTER(VirtualTimeRate)(&virtualTimeRate);
|
---|
[445] | 4066 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
| 4067 | " [STEP=%d CS=%d PAT=%d RR0=%d RR3=%d LOG=%d HWVirt=%d",
|
---|
[1] | 4068 | singlestepEnabled == TRUE, csamEnabled == TRUE, patmEnabled == TRUE,
|
---|
| 4069 | recompileSupervisor == FALSE, recompileUser == FALSE,
|
---|
| 4070 | logEnabled == TRUE, hwVirtEnabled == TRUE);
|
---|
[445] | 4071 | char *psz = strchr(szTitle, '\0');
|
---|
| 4072 | if (virtualTimeRate != 100)
|
---|
| 4073 | RTStrPrintf(psz, &szTitle[sizeof(szTitle)] - psz, " WD=%d%%]", virtualTimeRate);
|
---|
| 4074 | else
|
---|
| 4075 | RTStrPrintf(psz, &szTitle[sizeof(szTitle)] - psz, "]");
|
---|
[1] | 4076 | }
|
---|
[26429] | 4077 | #endif /* DEBUG || VBOX_WITH_STATISTICS */
|
---|
[1] | 4078 | break;
|
---|
| 4079 | }
|
---|
| 4080 |
|
---|
| 4081 | case TITLEBAR_STARTUP:
|
---|
| 4082 | {
|
---|
| 4083 | /*
|
---|
| 4084 | * Format it.
|
---|
| 4085 | */
|
---|
| 4086 | MachineState_T machineState;
|
---|
[34645] | 4087 | gpMachine->COMGETTER(State)(&machineState);
|
---|
[1] | 4088 | if (machineState == MachineState_Starting)
|
---|
[26429] | 4089 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
| 4090 | " - Starting...");
|
---|
[1] | 4091 | else if (machineState == MachineState_Restoring)
|
---|
| 4092 | {
|
---|
[18274] | 4093 | ULONG cPercentNow;
|
---|
[34645] | 4094 | HRESULT rc = gpProgress->COMGETTER(Percent)(&cPercentNow);
|
---|
[1] | 4095 | if (SUCCEEDED(rc))
|
---|
[445] | 4096 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
[1] | 4097 | " - Restoring %d%%...", (int)cPercentNow);
|
---|
| 4098 | else
|
---|
[445] | 4099 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
[1] | 4100 | " - Restoring...");
|
---|
| 4101 | }
|
---|
[24301] | 4102 | else if (machineState == MachineState_TeleportingIn)
|
---|
[23703] | 4103 | {
|
---|
| 4104 | ULONG cPercentNow;
|
---|
[34645] | 4105 | HRESULT rc = gpProgress->COMGETTER(Percent)(&cPercentNow);
|
---|
[23703] | 4106 | if (SUCCEEDED(rc))
|
---|
| 4107 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
[23801] | 4108 | " - Teleporting %d%%...", (int)cPercentNow);
|
---|
[23703] | 4109 | else
|
---|
| 4110 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
[23801] | 4111 | " - Teleporting...");
|
---|
[23703] | 4112 | }
|
---|
[1] | 4113 | /* ignore other states, we could already be in running or aborted state */
|
---|
| 4114 | break;
|
---|
| 4115 | }
|
---|
| 4116 |
|
---|
| 4117 | case TITLEBAR_SAVE:
|
---|
| 4118 | {
|
---|
[13130] | 4119 | AssertMsg(u32User <= 100, ("%d\n", u32User));
|
---|
[445] | 4120 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
[1] | 4121 | " - Saving %d%%...", u32User);
|
---|
| 4122 | break;
|
---|
| 4123 | }
|
---|
| 4124 |
|
---|
| 4125 | case TITLEBAR_SNAPSHOT:
|
---|
| 4126 | {
|
---|
[13130] | 4127 | AssertMsg(u32User <= 100, ("%d\n", u32User));
|
---|
[445] | 4128 | RTStrPrintf(szTitle + strlen(szTitle), sizeof(szTitle) - strlen(szTitle),
|
---|
[1] | 4129 | " - Taking snapshot %d%%...", u32User);
|
---|
| 4130 | break;
|
---|
| 4131 | }
|
---|
| 4132 |
|
---|
| 4133 | default:
|
---|
| 4134 | RTPrintf("Error: Invalid title bar mode %d!\n", mode);
|
---|
| 4135 | return;
|
---|
| 4136 | }
|
---|
| 4137 |
|
---|
| 4138 | /*
|
---|
| 4139 | * Don't update if it didn't change.
|
---|
| 4140 | */
|
---|
[18751] | 4141 | if (!strcmp(szTitle, szPrevTitle))
|
---|
[1] | 4142 | return;
|
---|
| 4143 |
|
---|
| 4144 | /*
|
---|
| 4145 | * Set the new title
|
---|
| 4146 | */
|
---|
| 4147 | #ifdef VBOX_WIN32_UI
|
---|
[445] | 4148 | setUITitle(szTitle);
|
---|
[1] | 4149 | #else
|
---|
[26034] | 4150 | SDL_WM_SetCaption(szTitle, VBOX_PRODUCT);
|
---|
[1] | 4151 | #endif
|
---|
| 4152 | }
|
---|
| 4153 |
|
---|
| 4154 | #if 0
|
---|
[34645] | 4155 | static void vbox_show_shape(unsigned short w, unsigned short h,
|
---|
| 4156 | uint32_t bg, const uint8_t *image)
|
---|
[1] | 4157 | {
|
---|
| 4158 | size_t x, y;
|
---|
| 4159 | unsigned short pitch;
|
---|
| 4160 | const uint32_t *color;
|
---|
| 4161 | const uint8_t *mask;
|
---|
| 4162 | size_t size_mask;
|
---|
| 4163 |
|
---|
| 4164 | mask = image;
|
---|
| 4165 | pitch = (w + 7) / 8;
|
---|
| 4166 | size_mask = (pitch * h + 3) & ~3;
|
---|
| 4167 |
|
---|
[28205] | 4168 | color = (const uint32_t *)(image + size_mask);
|
---|
[1] | 4169 |
|
---|
[28205] | 4170 | printf("show_shape %dx%d pitch %d size mask %d\n",
|
---|
| 4171 | w, h, pitch, size_mask);
|
---|
[1] | 4172 | for (y = 0; y < h; ++y, mask += pitch, color += w)
|
---|
| 4173 | {
|
---|
| 4174 | for (x = 0; x < w; ++x) {
|
---|
| 4175 | if (mask[x / 8] & (1 << (7 - (x % 8))))
|
---|
[28205] | 4176 | printf(" ");
|
---|
[1] | 4177 | else
|
---|
| 4178 | {
|
---|
| 4179 | uint32_t c = color[x];
|
---|
| 4180 | if (c == bg)
|
---|
[28205] | 4181 | printf("Y");
|
---|
[1] | 4182 | else
|
---|
[28205] | 4183 | printf("X");
|
---|
[1] | 4184 | }
|
---|
| 4185 | }
|
---|
[28205] | 4186 | printf("\n");
|
---|
[1] | 4187 | }
|
---|
| 4188 | }
|
---|
| 4189 | #endif
|
---|
| 4190 |
|
---|
| 4191 | /**
|
---|
| 4192 | * Sets the pointer shape according to parameters.
|
---|
| 4193 | * Must be called only from the main SDL thread.
|
---|
| 4194 | */
|
---|
[28205] | 4195 | static void SetPointerShape(const PointerShapeChangeData *data)
|
---|
[1] | 4196 | {
|
---|
| 4197 | /*
|
---|
| 4198 | * don't allow to change the pointer shape if we are outside the valid
|
---|
| 4199 | * guest area. In that case set standard mouse pointer is set and should
|
---|
| 4200 | * not get overridden.
|
---|
| 4201 | */
|
---|
| 4202 | if (gpOffCursor)
|
---|
| 4203 | return;
|
---|
| 4204 |
|
---|
[29518] | 4205 | if (data->shape.size() > 0)
|
---|
[1] | 4206 | {
|
---|
| 4207 | bool ok = false;
|
---|
| 4208 |
|
---|
| 4209 | uint32_t andMaskSize = (data->width + 7) / 8 * data->height;
|
---|
| 4210 | uint32_t srcShapePtrScan = data->width * 4;
|
---|
| 4211 |
|
---|
[29518] | 4212 | const uint8_t* shape = data->shape.raw();
|
---|
| 4213 | const uint8_t *srcAndMaskPtr = shape;
|
---|
| 4214 | const uint8_t *srcShapePtr = shape + ((andMaskSize + 3) & ~3);
|
---|
[1] | 4215 |
|
---|
| 4216 | #if 0
|
---|
| 4217 | /* pointer debugging code */
|
---|
| 4218 | // vbox_show_shape(data->width, data->height, 0, data->shape);
|
---|
| 4219 | uint32_t shapeSize = ((((data->width + 7) / 8) * data->height + 3) & ~3) + data->width * 4 * data->height;
|
---|
| 4220 | printf("visible: %d\n", data->visible);
|
---|
| 4221 | printf("width = %d\n", data->width);
|
---|
| 4222 | printf("height = %d\n", data->height);
|
---|
| 4223 | printf("alpha = %d\n", data->alpha);
|
---|
| 4224 | printf("xhot = %d\n", data->xHot);
|
---|
| 4225 | printf("yhot = %d\n", data->yHot);
|
---|
| 4226 | printf("uint8_t pointerdata[] = { ");
|
---|
| 4227 | for (uint32_t i = 0; i < shapeSize; i++)
|
---|
| 4228 | {
|
---|
| 4229 | printf("0x%x, ", data->shape[i]);
|
---|
| 4230 | }
|
---|
| 4231 | printf("};\n");
|
---|
| 4232 | #endif
|
---|
| 4233 |
|
---|
[28205] | 4234 | #if defined(RT_OS_WINDOWS)
|
---|
[1] | 4235 |
|
---|
| 4236 | BITMAPV5HEADER bi;
|
---|
| 4237 | HBITMAP hBitmap;
|
---|
| 4238 | void *lpBits;
|
---|
| 4239 | HCURSOR hAlphaCursor = NULL;
|
---|
| 4240 |
|
---|
[28205] | 4241 | ::ZeroMemory(&bi, sizeof(BITMAPV5HEADER));
|
---|
| 4242 | bi.bV5Size = sizeof(BITMAPV5HEADER);
|
---|
[1] | 4243 | bi.bV5Width = data->width;
|
---|
[28205] | 4244 | bi.bV5Height = -(LONG)data->height;
|
---|
[1] | 4245 | bi.bV5Planes = 1;
|
---|
| 4246 | bi.bV5BitCount = 32;
|
---|
| 4247 | bi.bV5Compression = BI_BITFIELDS;
|
---|
[33540] | 4248 | // specify a supported 32 BPP alpha format for Windows XP
|
---|
[1] | 4249 | bi.bV5RedMask = 0x00FF0000;
|
---|
| 4250 | bi.bV5GreenMask = 0x0000FF00;
|
---|
| 4251 | bi.bV5BlueMask = 0x000000FF;
|
---|
| 4252 | if (data->alpha)
|
---|
| 4253 | bi.bV5AlphaMask = 0xFF000000;
|
---|
| 4254 | else
|
---|
| 4255 | bi.bV5AlphaMask = 0;
|
---|
| 4256 |
|
---|
[28205] | 4257 | HDC hdc = ::GetDC(NULL);
|
---|
[1] | 4258 |
|
---|
| 4259 | // create the DIB section with an alpha channel
|
---|
[28205] | 4260 | hBitmap = ::CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS,
|
---|
| 4261 | (void **)&lpBits, NULL, (DWORD)0);
|
---|
[1] | 4262 |
|
---|
[28205] | 4263 | ::ReleaseDC(NULL, hdc);
|
---|
[1] | 4264 |
|
---|
| 4265 | HBITMAP hMonoBitmap = NULL;
|
---|
| 4266 | if (data->alpha)
|
---|
| 4267 | {
|
---|
| 4268 | // create an empty mask bitmap
|
---|
[28205] | 4269 | hMonoBitmap = ::CreateBitmap(data->width, data->height, 1, 1, NULL);
|
---|
[1] | 4270 | }
|
---|
| 4271 | else
|
---|
| 4272 | {
|
---|
| 4273 | /* Word aligned AND mask. Will be allocated and created if necessary. */
|
---|
| 4274 | uint8_t *pu8AndMaskWordAligned = NULL;
|
---|
| 4275 |
|
---|
| 4276 | /* Width in bytes of the original AND mask scan line. */
|
---|
| 4277 | uint32_t cbAndMaskScan = (data->width + 7) / 8;
|
---|
| 4278 |
|
---|
| 4279 | if (cbAndMaskScan & 1)
|
---|
| 4280 | {
|
---|
| 4281 | /* Original AND mask is not word aligned. */
|
---|
| 4282 |
|
---|
| 4283 | /* Allocate memory for aligned AND mask. */
|
---|
[28205] | 4284 | pu8AndMaskWordAligned = (uint8_t *)RTMemTmpAllocZ((cbAndMaskScan + 1) * data->height);
|
---|
[1] | 4285 |
|
---|
| 4286 | Assert(pu8AndMaskWordAligned);
|
---|
| 4287 |
|
---|
| 4288 | if (pu8AndMaskWordAligned)
|
---|
| 4289 | {
|
---|
| 4290 | /* According to MSDN the padding bits must be 0.
|
---|
| 4291 | * Compute the bit mask to set padding bits to 0 in the last byte of original AND mask.
|
---|
| 4292 | */
|
---|
| 4293 | uint32_t u32PaddingBits = cbAndMaskScan * 8 - data->width;
|
---|
| 4294 | Assert(u32PaddingBits < 8);
|
---|
| 4295 | uint8_t u8LastBytesPaddingMask = (uint8_t)(0xFF << u32PaddingBits);
|
---|
| 4296 |
|
---|
| 4297 | Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
|
---|
| 4298 | u8LastBytesPaddingMask, (cbAndMaskScan + 1) * 8, data->width, cbAndMaskScan));
|
---|
| 4299 |
|
---|
| 4300 | uint8_t *src = (uint8_t *)srcAndMaskPtr;
|
---|
| 4301 | uint8_t *dst = pu8AndMaskWordAligned;
|
---|
| 4302 |
|
---|
| 4303 | unsigned i;
|
---|
| 4304 | for (i = 0; i < data->height; i++)
|
---|
| 4305 | {
|
---|
[28205] | 4306 | memcpy(dst, src, cbAndMaskScan);
|
---|
[1] | 4307 |
|
---|
| 4308 | dst[cbAndMaskScan - 1] &= u8LastBytesPaddingMask;
|
---|
| 4309 |
|
---|
| 4310 | src += cbAndMaskScan;
|
---|
| 4311 | dst += cbAndMaskScan + 1;
|
---|
| 4312 | }
|
---|
| 4313 | }
|
---|
| 4314 | }
|
---|
| 4315 |
|
---|
| 4316 | // create the AND mask bitmap
|
---|
[28205] | 4317 | hMonoBitmap = ::CreateBitmap(data->width, data->height, 1, 1,
|
---|
| 4318 | pu8AndMaskWordAligned? pu8AndMaskWordAligned: srcAndMaskPtr);
|
---|
[1] | 4319 |
|
---|
| 4320 | if (pu8AndMaskWordAligned)
|
---|
| 4321 | {
|
---|
[28205] | 4322 | RTMemTmpFree(pu8AndMaskWordAligned);
|
---|
[1] | 4323 | }
|
---|
| 4324 | }
|
---|
| 4325 |
|
---|
[28205] | 4326 | Assert(hBitmap);
|
---|
| 4327 | Assert(hMonoBitmap);
|
---|
[1] | 4328 | if (hBitmap && hMonoBitmap)
|
---|
| 4329 | {
|
---|
[28205] | 4330 | DWORD *dstShapePtr = (DWORD *)lpBits;
|
---|
[1] | 4331 |
|
---|
| 4332 | for (uint32_t y = 0; y < data->height; y ++)
|
---|
| 4333 | {
|
---|
[28205] | 4334 | memcpy(dstShapePtr, srcShapePtr, srcShapePtrScan);
|
---|
[1] | 4335 | srcShapePtr += srcShapePtrScan;
|
---|
| 4336 | dstShapePtr += data->width;
|
---|
| 4337 | }
|
---|
| 4338 |
|
---|
| 4339 | ICONINFO ii;
|
---|
| 4340 | ii.fIcon = FALSE;
|
---|
| 4341 | ii.xHotspot = data->xHot;
|
---|
| 4342 | ii.yHotspot = data->yHot;
|
---|
| 4343 | ii.hbmMask = hMonoBitmap;
|
---|
| 4344 | ii.hbmColor = hBitmap;
|
---|
| 4345 |
|
---|
[28205] | 4346 | hAlphaCursor = ::CreateIconIndirect(&ii);
|
---|
| 4347 | Assert(hAlphaCursor);
|
---|
[1] | 4348 | if (hAlphaCursor)
|
---|
| 4349 | {
|
---|
| 4350 | // here we do a dirty trick by substituting a Window Manager's
|
---|
| 4351 | // cursor handle with the handle we created
|
---|
| 4352 |
|
---|
| 4353 | WMcursor *pCustomTempWMCursor = gpCustomCursor->wm_cursor;
|
---|
| 4354 |
|
---|
| 4355 | // see SDL12/src/video/wincommon/SDL_sysmouse.c
|
---|
[28205] | 4356 | void *wm_cursor = malloc(sizeof(HCURSOR) + sizeof(uint8_t *) * 2);
|
---|
| 4357 | *(HCURSOR *)wm_cursor = hAlphaCursor;
|
---|
[1] | 4358 |
|
---|
[28205] | 4359 | gpCustomCursor->wm_cursor = (WMcursor *)wm_cursor;
|
---|
| 4360 | SDL_SetCursor(gpCustomCursor);
|
---|
| 4361 | SDL_ShowCursor(SDL_ENABLE);
|
---|
[1] | 4362 |
|
---|
| 4363 | if (pCustomTempWMCursor)
|
---|
| 4364 | {
|
---|
[28205] | 4365 | ::DestroyCursor(*(HCURSOR *)pCustomTempWMCursor);
|
---|
| 4366 | free(pCustomTempWMCursor);
|
---|
[1] | 4367 | }
|
---|
| 4368 |
|
---|
| 4369 | ok = true;
|
---|
| 4370 | }
|
---|
| 4371 | }
|
---|
| 4372 |
|
---|
| 4373 | if (hMonoBitmap)
|
---|
[28205] | 4374 | ::DeleteObject(hMonoBitmap);
|
---|
[1] | 4375 | if (hBitmap)
|
---|
[28205] | 4376 | ::DeleteObject(hBitmap);
|
---|
[1] | 4377 |
|
---|
[28205] | 4378 | #elif defined(VBOXSDL_WITH_X11) && !defined(VBOX_WITHOUT_XCURSOR)
|
---|
[1] | 4379 |
|
---|
[18793] | 4380 | if (gfXCursorEnabled)
|
---|
[1] | 4381 | {
|
---|
[28205] | 4382 | XcursorImage *img = XcursorImageCreate(data->width, data->height);
|
---|
| 4383 | Assert(img);
|
---|
[18793] | 4384 | if (img)
|
---|
| 4385 | {
|
---|
| 4386 | img->xhot = data->xHot;
|
---|
| 4387 | img->yhot = data->yHot;
|
---|
[1] | 4388 |
|
---|
[18793] | 4389 | XcursorPixel *dstShapePtr = img->pixels;
|
---|
[1] | 4390 |
|
---|
[18793] | 4391 | for (uint32_t y = 0; y < data->height; y ++)
|
---|
| 4392 | {
|
---|
[28205] | 4393 | memcpy(dstShapePtr, srcShapePtr, srcShapePtrScan);
|
---|
[1] | 4394 |
|
---|
[18793] | 4395 | if (!data->alpha)
|
---|
[1] | 4396 | {
|
---|
[18793] | 4397 | // convert AND mask to the alpha channel
|
---|
| 4398 | uint8_t byte = 0;
|
---|
| 4399 | for (uint32_t x = 0; x < data->width; x ++)
|
---|
[1] | 4400 | {
|
---|
[18793] | 4401 | if (!(x % 8))
|
---|
| 4402 | byte = *(srcAndMaskPtr ++);
|
---|
[1] | 4403 | else
|
---|
[18793] | 4404 | byte <<= 1;
|
---|
| 4405 |
|
---|
| 4406 | if (byte & 0x80)
|
---|
| 4407 | {
|
---|
| 4408 | // Linux doesn't support inverted pixels (XOR ops,
|
---|
| 4409 | // to be exact) in cursor shapes, so we detect such
|
---|
| 4410 | // pixels and always replace them with black ones to
|
---|
| 4411 | // make them visible at least over light colors
|
---|
| 4412 | if (dstShapePtr [x] & 0x00FFFFFF)
|
---|
| 4413 | dstShapePtr [x] = 0xFF000000;
|
---|
| 4414 | else
|
---|
| 4415 | dstShapePtr [x] = 0x00000000;
|
---|
| 4416 | }
|
---|
| 4417 | else
|
---|
| 4418 | dstShapePtr [x] |= 0xFF000000;
|
---|
[1] | 4419 | }
|
---|
| 4420 | }
|
---|
[18793] | 4421 |
|
---|
| 4422 | srcShapePtr += srcShapePtrScan;
|
---|
| 4423 | dstShapePtr += data->width;
|
---|
[1] | 4424 | }
|
---|
| 4425 |
|
---|
[20433] | 4426 | #ifndef VBOX_WITH_SDL13
|
---|
[28205] | 4427 | Cursor cur = XcursorImageLoadCursor(gSdlInfo.info.x11.display, img);
|
---|
| 4428 | Assert(cur);
|
---|
[18793] | 4429 | if (cur)
|
---|
| 4430 | {
|
---|
| 4431 | // here we do a dirty trick by substituting a Window Manager's
|
---|
| 4432 | // cursor handle with the handle we created
|
---|
[1] | 4433 |
|
---|
[18793] | 4434 | WMcursor *pCustomTempWMCursor = gpCustomCursor->wm_cursor;
|
---|
[1] | 4435 |
|
---|
[18793] | 4436 | // see SDL12/src/video/x11/SDL_x11mouse.c
|
---|
[28205] | 4437 | void *wm_cursor = malloc(sizeof(Cursor));
|
---|
| 4438 | *(Cursor *)wm_cursor = cur;
|
---|
[1] | 4439 |
|
---|
[28205] | 4440 | gpCustomCursor->wm_cursor = (WMcursor *)wm_cursor;
|
---|
| 4441 | SDL_SetCursor(gpCustomCursor);
|
---|
| 4442 | SDL_ShowCursor(SDL_ENABLE);
|
---|
[1] | 4443 |
|
---|
[18793] | 4444 | if (pCustomTempWMCursor)
|
---|
| 4445 | {
|
---|
[28205] | 4446 | XFreeCursor(gSdlInfo.info.x11.display, *(Cursor *)pCustomTempWMCursor);
|
---|
| 4447 | free(pCustomTempWMCursor);
|
---|
[18793] | 4448 | }
|
---|
[1] | 4449 |
|
---|
[18793] | 4450 | ok = true;
|
---|
[1] | 4451 | }
|
---|
[20433] | 4452 | #endif
|
---|
[1] | 4453 | }
|
---|
[28205] | 4454 | XcursorImageDestroy(img);
|
---|
[1] | 4455 | }
|
---|
| 4456 |
|
---|
[18793] | 4457 | #endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
|
---|
[1] | 4458 |
|
---|
| 4459 | if (!ok)
|
---|
| 4460 | {
|
---|
[28205] | 4461 | SDL_SetCursor(gpDefaultCursor);
|
---|
| 4462 | SDL_ShowCursor(SDL_ENABLE);
|
---|
[1] | 4463 | }
|
---|
| 4464 | }
|
---|
| 4465 | else
|
---|
| 4466 | {
|
---|
| 4467 | if (data->visible)
|
---|
[28205] | 4468 | SDL_ShowCursor(SDL_ENABLE);
|
---|
[1] | 4469 | else if (gfAbsoluteMouseGuest)
|
---|
| 4470 | /* Don't disable the cursor if the guest additions are not active (anymore) */
|
---|
[28205] | 4471 | SDL_ShowCursor(SDL_DISABLE);
|
---|
[1] | 4472 | }
|
---|
| 4473 | }
|
---|
| 4474 |
|
---|
| 4475 | /**
|
---|
| 4476 | * Handle changed mouse capabilities
|
---|
| 4477 | */
|
---|
| 4478 | static void HandleGuestCapsChanged(void)
|
---|
| 4479 | {
|
---|
| 4480 | if (!gfAbsoluteMouseGuest)
|
---|
| 4481 | {
|
---|
| 4482 | // Cursor could be overwritten by the guest tools
|
---|
| 4483 | SDL_SetCursor(gpDefaultCursor);
|
---|
[28205] | 4484 | SDL_ShowCursor(SDL_ENABLE);
|
---|
[1] | 4485 | gpOffCursor = NULL;
|
---|
| 4486 | }
|
---|
[34645] | 4487 | if (gpMouse && UseAbsoluteMouse())
|
---|
[1] | 4488 | {
|
---|
| 4489 | // Actually switch to absolute coordinates
|
---|
| 4490 | if (gfGrabbed)
|
---|
| 4491 | InputGrabEnd();
|
---|
[34645] | 4492 | gpMouse->PutMouseEventAbsolute(-1, -1, 0, 0, 0);
|
---|
[1] | 4493 | }
|
---|
| 4494 | }
|
---|
| 4495 |
|
---|
| 4496 | /**
|
---|
| 4497 | * Handles a host key down event
|
---|
| 4498 | */
|
---|
| 4499 | static int HandleHostKey(const SDL_KeyboardEvent *pEv)
|
---|
| 4500 | {
|
---|
| 4501 | /*
|
---|
| 4502 | * Revalidate the host key modifier
|
---|
| 4503 | */
|
---|
| 4504 | if ((SDL_GetModState() & ~(KMOD_MODE | KMOD_NUM | KMOD_RESERVED)) != gHostKeyMod)
|
---|
| 4505 | return VERR_NOT_SUPPORTED;
|
---|
| 4506 |
|
---|
| 4507 | /*
|
---|
| 4508 | * What was pressed?
|
---|
| 4509 | */
|
---|
| 4510 | switch (pEv->keysym.sym)
|
---|
| 4511 | {
|
---|
| 4512 | /* Control-Alt-Delete */
|
---|
| 4513 | case SDLK_DELETE:
|
---|
| 4514 | {
|
---|
[34645] | 4515 | gpKeyboard->PutCAD();
|
---|
[1] | 4516 | break;
|
---|
| 4517 | }
|
---|
| 4518 |
|
---|
| 4519 | /*
|
---|
| 4520 | * Fullscreen / Windowed toggle.
|
---|
| 4521 | */
|
---|
| 4522 | case SDLK_f:
|
---|
| 4523 | {
|
---|
[10430] | 4524 | if ( strchr(gHostKeyDisabledCombinations, 'f')
|
---|
| 4525 | || !gfAllowFullscreenToggle)
|
---|
| 4526 | return VERR_NOT_SUPPORTED;
|
---|
[1] | 4527 |
|
---|
[10430] | 4528 | /*
|
---|
| 4529 | * We have to pause/resume the machine during this
|
---|
| 4530 | * process because there might be a short moment
|
---|
| 4531 | * without a valid framebuffer
|
---|
| 4532 | */
|
---|
| 4533 | MachineState_T machineState;
|
---|
[34645] | 4534 | gpMachine->COMGETTER(State)(&machineState);
|
---|
[24301] | 4535 | bool fPauseIt = machineState == MachineState_Running
|
---|
| 4536 | || machineState == MachineState_Teleporting
|
---|
| 4537 | || machineState == MachineState_LiveSnapshotting;
|
---|
| 4538 | if (fPauseIt)
|
---|
[34645] | 4539 | gpConsole->Pause();
|
---|
[20433] | 4540 | SetFullscreen(!gpFramebuffer[0]->getFullscreen());
|
---|
[24301] | 4541 | if (fPauseIt)
|
---|
[34645] | 4542 | gpConsole->Resume();
|
---|
[10430] | 4543 |
|
---|
| 4544 | /*
|
---|
| 4545 | * We have switched from/to fullscreen, so request a full
|
---|
| 4546 | * screen repaint, just to be sure.
|
---|
| 4547 | */
|
---|
[34645] | 4548 | gpDisplay->InvalidateAndUpdate();
|
---|
[1] | 4549 | break;
|
---|
| 4550 | }
|
---|
| 4551 |
|
---|
| 4552 | /*
|
---|
| 4553 | * Pause / Resume toggle.
|
---|
| 4554 | */
|
---|
| 4555 | case SDLK_p:
|
---|
| 4556 | {
|
---|
[10430] | 4557 | if (strchr(gHostKeyDisabledCombinations, 'p'))
|
---|
| 4558 | return VERR_NOT_SUPPORTED;
|
---|
| 4559 |
|
---|
[1] | 4560 | MachineState_T machineState;
|
---|
[34645] | 4561 | gpMachine->COMGETTER(State)(&machineState);
|
---|
[24301] | 4562 | if ( machineState == MachineState_Running
|
---|
| 4563 | || machineState == MachineState_Teleporting
|
---|
| 4564 | || machineState == MachineState_LiveSnapshotting
|
---|
| 4565 | )
|
---|
[1] | 4566 | {
|
---|
| 4567 | if (gfGrabbed)
|
---|
| 4568 | InputGrabEnd();
|
---|
[34645] | 4569 | gpConsole->Pause();
|
---|
[1] | 4570 | }
|
---|
| 4571 | else if (machineState == MachineState_Paused)
|
---|
| 4572 | {
|
---|
[34645] | 4573 | gpConsole->Resume();
|
---|
[1] | 4574 | }
|
---|
| 4575 | UpdateTitlebar(TITLEBAR_NORMAL);
|
---|
| 4576 | break;
|
---|
| 4577 | }
|
---|
| 4578 |
|
---|
| 4579 | /*
|
---|
| 4580 | * Reset the VM
|
---|
| 4581 | */
|
---|
| 4582 | case SDLK_r:
|
---|
| 4583 | {
|
---|
[10430] | 4584 | if (strchr(gHostKeyDisabledCombinations, 'r'))
|
---|
| 4585 | return VERR_NOT_SUPPORTED;
|
---|
| 4586 |
|
---|
[1] | 4587 | ResetVM();
|
---|
| 4588 | break;
|
---|
| 4589 | }
|
---|
| 4590 |
|
---|
| 4591 | /*
|
---|
| 4592 | * Terminate the VM
|
---|
| 4593 | */
|
---|
| 4594 | case SDLK_q:
|
---|
| 4595 | {
|
---|
[10430] | 4596 | if (strchr(gHostKeyDisabledCombinations, 'q'))
|
---|
| 4597 | return VERR_NOT_SUPPORTED;
|
---|
| 4598 |
|
---|
[1] | 4599 | return VINF_EM_TERMINATE;
|
---|
| 4600 | }
|
---|
| 4601 |
|
---|
| 4602 | /*
|
---|
| 4603 | * Save the machine's state and exit
|
---|
| 4604 | */
|
---|
| 4605 | case SDLK_s:
|
---|
| 4606 | {
|
---|
[10430] | 4607 | if (strchr(gHostKeyDisabledCombinations, 's'))
|
---|
| 4608 | return VERR_NOT_SUPPORTED;
|
---|
| 4609 |
|
---|
[1] | 4610 | SaveState();
|
---|
| 4611 | return VINF_EM_TERMINATE;
|
---|
| 4612 | }
|
---|
| 4613 |
|
---|
| 4614 | case SDLK_h:
|
---|
| 4615 | {
|
---|
[10430] | 4616 | if (strchr(gHostKeyDisabledCombinations, 'h'))
|
---|
| 4617 | return VERR_NOT_SUPPORTED;
|
---|
| 4618 |
|
---|
[34645] | 4619 | if (gpConsole)
|
---|
| 4620 | gpConsole->PowerButton();
|
---|
[1] | 4621 | break;
|
---|
| 4622 | }
|
---|
| 4623 |
|
---|
| 4624 | /*
|
---|
| 4625 | * Perform an online snapshot. Continue operation.
|
---|
| 4626 | */
|
---|
| 4627 | case SDLK_n:
|
---|
| 4628 | {
|
---|
[10430] | 4629 | if (strchr(gHostKeyDisabledCombinations, 'n'))
|
---|
| 4630 | return VERR_NOT_SUPPORTED;
|
---|
| 4631 |
|
---|
[1] | 4632 | RTThreadYield();
|
---|
| 4633 | ULONG cSnapshots = 0;
|
---|
[34645] | 4634 | gpMachine->COMGETTER(SnapshotCount)(&cSnapshots);
|
---|
[1] | 4635 | char pszSnapshotName[20];
|
---|
| 4636 | RTStrPrintf(pszSnapshotName, sizeof(pszSnapshotName), "Snapshot %d", cSnapshots + 1);
|
---|
[34645] | 4637 | gpProgress = NULL;
|
---|
[1] | 4638 | HRESULT rc;
|
---|
[34645] | 4639 | CHECK_ERROR(gpConsole, TakeSnapshot(Bstr(pszSnapshotName).raw(),
|
---|
| 4640 | Bstr("Taken by VBoxSDL").raw(),
|
---|
| 4641 | gpProgress.asOutParam()));
|
---|
[1] | 4642 | if (FAILED(rc))
|
---|
| 4643 | {
|
---|
| 4644 | RTPrintf("Error taking snapshot! rc = 0x%x\n", rc);
|
---|
| 4645 | /* continue operation */
|
---|
| 4646 | return VINF_SUCCESS;
|
---|
| 4647 | }
|
---|
| 4648 | /*
|
---|
| 4649 | * Wait for the operation to be completed and work
|
---|
| 4650 | * the title bar in the mean while.
|
---|
| 4651 | */
|
---|
[18274] | 4652 | ULONG cPercent = 0;
|
---|
[1] | 4653 | for (;;)
|
---|
| 4654 | {
|
---|
| 4655 | BOOL fCompleted = false;
|
---|
[34645] | 4656 | rc = gpProgress->COMGETTER(Completed)(&fCompleted);
|
---|
[1] | 4657 | if (FAILED(rc) || fCompleted)
|
---|
| 4658 | break;
|
---|
[18274] | 4659 | ULONG cPercentNow;
|
---|
[34645] | 4660 | rc = gpProgress->COMGETTER(Percent)(&cPercentNow);
|
---|
[1] | 4661 | if (FAILED(rc))
|
---|
| 4662 | break;
|
---|
| 4663 | if (cPercentNow != cPercent)
|
---|
| 4664 | {
|
---|
| 4665 | UpdateTitlebar(TITLEBAR_SNAPSHOT, cPercent);
|
---|
| 4666 | cPercent = cPercentNow;
|
---|
| 4667 | }
|
---|
| 4668 |
|
---|
| 4669 | /* wait */
|
---|
[34645] | 4670 | rc = gpProgress->WaitForCompletion(100);
|
---|
[1] | 4671 | if (FAILED(rc))
|
---|
| 4672 | break;
|
---|
| 4673 | /// @todo process gui events.
|
---|
| 4674 | }
|
---|
| 4675 |
|
---|
| 4676 | /* continue operation */
|
---|
| 4677 | return VINF_SUCCESS;
|
---|
| 4678 | }
|
---|
| 4679 |
|
---|
| 4680 | case SDLK_F1: case SDLK_F2: case SDLK_F3:
|
---|
| 4681 | case SDLK_F4: case SDLK_F5: case SDLK_F6:
|
---|
| 4682 | case SDLK_F7: case SDLK_F8: case SDLK_F9:
|
---|
| 4683 | case SDLK_F10: case SDLK_F11: case SDLK_F12:
|
---|
| 4684 | {
|
---|
[11661] | 4685 | // /* send Ctrl-Alt-Fx to guest */
|
---|
| 4686 | com::SafeArray<LONG> keys(6);
|
---|
[11822] | 4687 |
|
---|
[11661] | 4688 | keys[0] = 0x1d; // Ctrl down
|
---|
| 4689 | keys[1] = 0x38; // Alt down
|
---|
| 4690 | keys[2] = Keyevent2Keycode(pEv); // Fx down
|
---|
| 4691 | keys[3] = keys[2] + 0x80; // Fx up
|
---|
| 4692 | keys[4] = 0xb8; // Alt up
|
---|
| 4693 | keys[5] = 0x9d; // Ctrl up
|
---|
[1] | 4694 |
|
---|
[34645] | 4695 | gpKeyboard->PutScancodes(ComSafeArrayAsInParam(keys), NULL);
|
---|
[1] | 4696 | return VINF_SUCCESS;
|
---|
| 4697 | }
|
---|
| 4698 |
|
---|
| 4699 | /*
|
---|
| 4700 | * Not a host key combination.
|
---|
| 4701 | * Indicate this by returning false.
|
---|
| 4702 | */
|
---|
| 4703 | default:
|
---|
| 4704 | return VERR_NOT_SUPPORTED;
|
---|
| 4705 | }
|
---|
| 4706 |
|
---|
| 4707 | return VINF_SUCCESS;
|
---|
| 4708 | }
|
---|
| 4709 |
|
---|
| 4710 | /**
|
---|
| 4711 | * Timer callback function for startup processing
|
---|
| 4712 | */
|
---|
| 4713 | static Uint32 StartupTimer(Uint32 interval, void *param)
|
---|
| 4714 | {
|
---|
| 4715 | /* post message so we can do something in the startup loop */
|
---|
| 4716 | SDL_Event event = {0};
|
---|
| 4717 | event.type = SDL_USEREVENT;
|
---|
| 4718 | event.user.type = SDL_USER_EVENT_TIMER;
|
---|
| 4719 | SDL_PushEvent(&event);
|
---|
[3289] | 4720 | RTSemEventSignal(g_EventSemSDLEvents);
|
---|
[1] | 4721 | return interval;
|
---|
| 4722 | }
|
---|
[522] | 4723 |
|
---|
| 4724 | /**
|
---|
| 4725 | * Timer callback function to check if resizing is finished
|
---|
| 4726 | */
|
---|
| 4727 | static Uint32 ResizeTimer(Uint32 interval, void *param)
|
---|
| 4728 | {
|
---|
| 4729 | /* post message so the window is actually resized */
|
---|
| 4730 | SDL_Event event = {0};
|
---|
| 4731 | event.type = SDL_USEREVENT;
|
---|
| 4732 | event.user.type = SDL_USER_EVENT_WINDOW_RESIZE_DONE;
|
---|
[3289] | 4733 | PushSDLEventForSure(&event);
|
---|
[522] | 4734 | /* one-shot */
|
---|
| 4735 | return 0;
|
---|
| 4736 | }
|
---|
[3289] | 4737 |
|
---|
| 4738 | /**
|
---|
[6852] | 4739 | * Timer callback function to check if an ACPI power button event was handled by the guest.
|
---|
| 4740 | */
|
---|
| 4741 | static Uint32 QuitTimer(Uint32 interval, void *param)
|
---|
| 4742 | {
|
---|
[6853] | 4743 | BOOL fHandled = FALSE;
|
---|
[6852] | 4744 |
|
---|
| 4745 | gSdlQuitTimer = NULL;
|
---|
[34645] | 4746 | if (gpConsole)
|
---|
[6852] | 4747 | {
|
---|
[34645] | 4748 | int rc = gpConsole->GetPowerButtonHandled(&fHandled);
|
---|
[6852] | 4749 | LogRel(("QuitTimer: rc=%d handled=%d\n", rc, fHandled));
|
---|
[13835] | 4750 | if (RT_FAILURE(rc) || !fHandled)
|
---|
[6852] | 4751 | {
|
---|
| 4752 | /* event was not handled, power down the guest */
|
---|
| 4753 | gfACPITerm = FALSE;
|
---|
| 4754 | SDL_Event event = {0};
|
---|
| 4755 | event.type = SDL_QUIT;
|
---|
| 4756 | PushSDLEventForSure(&event);
|
---|
| 4757 | }
|
---|
| 4758 | }
|
---|
| 4759 | /* one-shot */
|
---|
| 4760 | return 0;
|
---|
| 4761 | }
|
---|
| 4762 |
|
---|
| 4763 | /**
|
---|
[3289] | 4764 | * Wait for the next SDL event. Don't use SDL_WaitEvent since this function
|
---|
| 4765 | * calls SDL_Delay(10) if the event queue is empty.
|
---|
| 4766 | */
|
---|
| 4767 | static int WaitSDLEvent(SDL_Event *event)
|
---|
| 4768 | {
|
---|
| 4769 | for (;;)
|
---|
| 4770 | {
|
---|
[28205] | 4771 | int rc = SDL_PollEvent(event);
|
---|
[3289] | 4772 | if (rc == 1)
|
---|
[3300] | 4773 | {
|
---|
| 4774 | #ifdef USE_XPCOM_QUEUE_THREAD
|
---|
| 4775 | if (event->type == SDL_USER_EVENT_XPCOM_EVENTQUEUE)
|
---|
| 4776 | consumedXPCOMUserEvent();
|
---|
| 4777 | #endif
|
---|
[3289] | 4778 | return 1;
|
---|
[3300] | 4779 | }
|
---|
[3289] | 4780 | /* Immediately wake up if new SDL events are available. This does not
|
---|
| 4781 | * work for internal SDL events. Don't wait more than 10ms. */
|
---|
| 4782 | RTSemEventWait(g_EventSemSDLEvents, 10);
|
---|
| 4783 | }
|
---|
| 4784 | }
|
---|
| 4785 |
|
---|
| 4786 | /**
|
---|
| 4787 | * Ensure that an SDL event is really enqueued. Try multiple times if necessary.
|
---|
| 4788 | */
|
---|
| 4789 | int PushSDLEventForSure(SDL_Event *event)
|
---|
| 4790 | {
|
---|
| 4791 | int ntries = 10;
|
---|
| 4792 | for (; ntries > 0; ntries--)
|
---|
| 4793 | {
|
---|
| 4794 | int rc = SDL_PushEvent(event);
|
---|
| 4795 | RTSemEventSignal(g_EventSemSDLEvents);
|
---|
[20433] | 4796 | #ifdef VBOX_WITH_SDL13
|
---|
| 4797 | if (rc == 1)
|
---|
| 4798 | #else
|
---|
[3289] | 4799 | if (rc == 0)
|
---|
[20433] | 4800 | #endif
|
---|
[3289] | 4801 | return 0;
|
---|
[20433] | 4802 | Log(("PushSDLEventForSure: waiting for 2ms (rc = %d)\n", rc));
|
---|
[3289] | 4803 | RTThreadSleep(2);
|
---|
| 4804 | }
|
---|
| 4805 | LogRel(("WARNING: Failed to enqueue SDL event %d.%d!\n",
|
---|
[34645] | 4806 | event->type, event->type == SDL_USEREVENT ? event->user.type : 0));
|
---|
[3289] | 4807 | return -1;
|
---|
| 4808 | }
|
---|
| 4809 |
|
---|
[4637] | 4810 | #ifdef VBOXSDL_WITH_X11
|
---|
[3289] | 4811 | /**
|
---|
| 4812 | * Special SDL_PushEvent function for NotifyUpdate events. These events may occur in bursts
|
---|
| 4813 | * so make sure they don't flood the SDL event queue.
|
---|
| 4814 | */
|
---|
| 4815 | void PushNotifyUpdateEvent(SDL_Event *event)
|
---|
| 4816 | {
|
---|
| 4817 | int rc = SDL_PushEvent(event);
|
---|
[20433] | 4818 | #ifdef VBOX_WITH_SDL13
|
---|
| 4819 | bool fSuccess = (rc == 1);
|
---|
| 4820 | #else
|
---|
| 4821 | bool fSuccess = (rc == 0);
|
---|
| 4822 | #endif
|
---|
| 4823 |
|
---|
[3289] | 4824 | RTSemEventSignal(g_EventSemSDLEvents);
|
---|
[20433] | 4825 | AssertMsg(fSuccess, ("SDL_PushEvent returned SDL error\n"));
|
---|
[3289] | 4826 | /* A global counter is faster than SDL_PeepEvents() */
|
---|
[20433] | 4827 | if (fSuccess)
|
---|
[3289] | 4828 | ASMAtomicIncS32(&g_cNotifyUpdateEventsPending);
|
---|
| 4829 | /* In order to not flood the SDL event queue, yield the CPU or (if there are already many
|
---|
| 4830 | * events queued) even sleep */
|
---|
| 4831 | if (g_cNotifyUpdateEventsPending > 96)
|
---|
| 4832 | {
|
---|
| 4833 | /* Too many NotifyUpdate events, sleep for a small amount to give the main thread time
|
---|
| 4834 | * to handle these events. The SDL queue can hold up to 128 events. */
|
---|
| 4835 | Log(("PushNotifyUpdateEvent: Sleep 1ms\n"));
|
---|
| 4836 | RTThreadSleep(1);
|
---|
| 4837 | }
|
---|
| 4838 | else
|
---|
| 4839 | RTThreadYield();
|
---|
| 4840 | }
|
---|
[4637] | 4841 | #endif /* VBOXSDL_WITH_X11 */
|
---|
[10675] | 4842 |
|
---|
| 4843 | /**
|
---|
| 4844 | *
|
---|
| 4845 | */
|
---|
| 4846 | static void SetFullscreen(bool enable)
|
---|
| 4847 | {
|
---|
[20433] | 4848 | if (enable == gpFramebuffer[0]->getFullscreen())
|
---|
[10675] | 4849 | return;
|
---|
| 4850 |
|
---|
| 4851 | if (!gfFullscreenResize)
|
---|
| 4852 | {
|
---|
| 4853 | /*
|
---|
[11400] | 4854 | * The old/default way: SDL will resize the host to fit the guest screen resolution.
|
---|
[10675] | 4855 | */
|
---|
[20433] | 4856 | gpFramebuffer[0]->setFullscreen(enable);
|
---|
[10675] | 4857 | }
|
---|
| 4858 | else
|
---|
| 4859 | {
|
---|
| 4860 | /*
|
---|
[11400] | 4861 | * The alternate way: Switch to fullscreen with the host screen resolution and adapt
|
---|
| 4862 | * the guest screen resolution to the host window geometry.
|
---|
[10675] | 4863 | */
|
---|
| 4864 | uint32_t NewWidth = 0, NewHeight = 0;
|
---|
[11400] | 4865 | if (enable)
|
---|
[10675] | 4866 | {
|
---|
[11400] | 4867 | /* switch to fullscreen */
|
---|
[20433] | 4868 | gmGuestNormalXRes = gpFramebuffer[0]->getGuestXRes();
|
---|
| 4869 | gmGuestNormalYRes = gpFramebuffer[0]->getGuestYRes();
|
---|
| 4870 | gpFramebuffer[0]->getFullscreenGeometry(&NewWidth, &NewHeight);
|
---|
[10675] | 4871 | }
|
---|
| 4872 | else
|
---|
| 4873 | {
|
---|
[11400] | 4874 | /* switch back to saved geometry */
|
---|
[10675] | 4875 | NewWidth = gmGuestNormalXRes;
|
---|
| 4876 | NewHeight = gmGuestNormalYRes;
|
---|
| 4877 | }
|
---|
| 4878 | if (NewWidth != 0 && NewHeight != 0)
|
---|
| 4879 | {
|
---|
[20433] | 4880 | gpFramebuffer[0]->setFullscreen(enable);
|
---|
[10675] | 4881 | gfIgnoreNextResize = TRUE;
|
---|
[34645] | 4882 | gpDisplay->SetVideoModeHint(NewWidth, NewHeight, 0, 0);
|
---|
[10675] | 4883 | }
|
---|
| 4884 | }
|
---|
| 4885 | }
|
---|
[20433] | 4886 |
|
---|
| 4887 | #ifdef VBOX_WITH_SDL13
|
---|
| 4888 | static VBoxSDLFB * getFbFromWinId(SDL_WindowID id)
|
---|
| 4889 | {
|
---|
| 4890 | for (unsigned i = 0; i < gcMonitors; i++)
|
---|
| 4891 | if (gpFramebuffer[i]->hasWindow(id))
|
---|
| 4892 | return gpFramebuffer[i];
|
---|
| 4893 |
|
---|
| 4894 | return NULL;
|
---|
| 4895 | }
|
---|
| 4896 | #endif
|
---|