Index: trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h	(revision 6173)
+++ trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h	(revision 6184)
@@ -81,5 +81,5 @@
     void setMouseIntegrationEnabled (bool enabled);
 
-    bool isMouseAbsolute() const { return mouse_absolute; }
+    bool isMouseAbsolute() const { return mMouseAbsolute; }
 
     void setAutoresizeGuest (bool on);
@@ -146,12 +146,12 @@
     {
         emit keyboardStateChanged (
-            (kbd_captured ? KeyboardCaptured : 0) |
+            (mKbdCaptured ? KeyboardCaptured : 0) |
             (mIsHostkeyPressed ? HostKeyPressed : 0));
     }
 
     void emitMouseStateChanged() {
-        emit mouseStateChanged ((mouse_captured ? MouseCaptured : 0) |
-                                (mouse_absolute ? MouseAbsolute : 0) |
-                                (!mouse_integration ? MouseAbsoluteDisabled : 0));
+        emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
+                                (mMouseAbsolute ? MouseAbsolute : 0) |
+                                (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
     }
 
@@ -166,6 +166,6 @@
 #endif
 
-    void captureKbd (bool capture, bool emit_signal = true);
-    void captureMouse (bool capture, bool emit_signal = true);
+    void captureKbd (bool aCapture, bool aEmitSignal = true);
+    void captureMouse (bool aCapture, bool aEmitSignal = true);
 
     bool processHotKey (const QKeySequence &key, QMenuData *data);
@@ -179,6 +179,6 @@
     void setPointerShape (MousePointerChangeEvent *me);
 
-    bool isPaused() { return last_state == CEnums::Paused; }
-    bool isRunning() { return last_state == CEnums::Running; }
+    bool isPaused() { return mLastState == CEnums::Paused; }
+    bool isRunning() { return mLastState == CEnums::Running; }
 
     static void dimImage (QImage &img);
@@ -198,13 +198,13 @@
     const VBoxGlobalSettings &gs;
 
-    CEnums::MachineState last_state;
-
-    bool attached : 1;
-    bool kbd_captured : 1;
-    bool mouse_captured : 1;
-    bool mouse_absolute : 1;
-    bool mouse_integration : 1;
-    QPoint last_pos;
-    QPoint captured_pos;
+    CEnums::MachineState mLastState;
+
+    bool mAttached : 1;
+    bool mKbdCaptured : 1;
+    bool mMouseCaptured : 1;
+    bool mMouseAbsolute : 1;
+    bool mMouseIntegration : 1;
+    QPoint mLastPos;
+    QPoint mCapturedPos;
 
 	bool mDisableAutoCapture : 1;
@@ -217,5 +217,5 @@
     bool mIsHostkeyAlone : 1;
 
-    /** kbd_captured value during the the last host key press or release */
+    /** mKbdCaptured value during the the last host key press or release */
     bool hostkey_in_capture : 1;
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 6173)
+++ trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 6184)
@@ -137,5 +137,5 @@
     else if (EventClass == kEventClassCommand)
     {
-        if (view->kbd_captured)
+        if (view->mKbdCaptured)
             return 0;
     }
@@ -599,9 +599,9 @@
     , mConsole (console)
     , gs (vboxGlobal().settings())
-    , attached (false)
-    , kbd_captured (false)
-    , mouse_captured (false)
-    , mouse_absolute (false)
-    , mouse_integration (true)
+    , mAttached (false)
+    , mKbdCaptured (false)
+    , mMouseCaptured (false)
+    , mMouseAbsolute (false)
+    , mMouseIntegration (true)
     , mDisableAutoCapture (false)
     , mIsHostkeyPressed (false)
@@ -814,7 +814,7 @@
 void VBoxConsoleView::attach()
 {
-    if (!attached)
-    {
-        attached = true;
+    if (!mAttached)
+    {
+        mAttached = true;
     }
 }
@@ -833,9 +833,9 @@
 void VBoxConsoleView::detach()
 {
-    if (attached)
+    if (mAttached)
     {
         /* reuse the focus event handler to uncapture everything */
         focusEvent (false);
-        attached = false;
+        mAttached = false;
     }
 }
@@ -922,8 +922,8 @@
 void VBoxConsoleView::setMouseIntegrationEnabled (bool enabled)
 {
-    if (mouse_integration == enabled)
+    if (mMouseIntegration == enabled)
         return;
 
-    if (mouse_absolute)
+    if (mMouseAbsolute)
         captureMouse (!enabled, false);
 
@@ -945,5 +945,5 @@
         viewport()->setCursor (QCursor (BlankCursor));
 
-    mouse_integration = enabled;
+    mMouseIntegration = enabled;
 
     emitMouseStateChanged();
@@ -991,5 +991,5 @@
 bool VBoxConsoleView::event (QEvent *e)
 {
-    if (attached)
+    if (mAttached)
     {
         switch (e->type())
@@ -1037,5 +1037,5 @@
                  * So it is necessary to perform updateMouseClipping() for
                  * the guest resize event if the mouse cursor was captured. */
-                if (mouse_captured)
+                if (mMouseCaptured)
                     updateMouseClipping();
 
@@ -1101,5 +1101,5 @@
                  * supported (change mouse shape type event may arrive after
                  * mouse capability change that disables integration */
-                if (mouse_absolute)
+                if (mMouseAbsolute)
                     setPointerShape (me);
                 return true;
@@ -1108,10 +1108,10 @@
             {
                 MouseCapabilityEvent *me = (MouseCapabilityEvent *) e;
-                if (mouse_absolute != me->supportsAbsolute())
+                if (mMouseAbsolute != me->supportsAbsolute())
                 {
-                    mouse_absolute = me->supportsAbsolute();
+                    mMouseAbsolute = me->supportsAbsolute();
                     /* correct the mouse capture state and reset the cursor
                      * to the default shape if necessary */
-                    if (mouse_absolute)
+                    if (mMouseAbsolute)
                     {
                         CMouse mouse = mConsole.GetMouse();
@@ -1122,5 +1122,5 @@
                         viewport()->unsetCursor();
                     emitMouseStateChanged();
-                    vboxProblem().remindAboutMouseIntegration (mouse_absolute);
+                    vboxProblem().remindAboutMouseIntegration (mMouseAbsolute);
                 }
                 if (me->needsHostCursor())
@@ -1281,5 +1281,5 @@
                         /* activate the main menu */
                         if (mMainWnd->isTrueSeamless() || mMainWnd->isTrueFullscreen())
-                            mMainWnd->popupMainMenu (mouse_captured);
+                            mMainWnd->popupMainMenu (mMouseCaptured);
                         else
                             mMainWnd->menuBar()->setFocus();
@@ -1336,5 +1336,5 @@
 bool VBoxConsoleView::eventFilter (QObject *watched, QEvent *e)
 {
-    if (attached && watched == viewport())
+    if (mAttached && watched == viewport())
     {
         switch (e->type())
@@ -1363,5 +1363,5 @@
             case QEvent::Resize:
             {
-                if (mouse_captured)
+                if (mMouseCaptured)
                     updateMouseClipping();
             }
@@ -1475,6 +1475,6 @@
 {
 #if 0
-    LogFlow (("### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X (kbd_captured=%d)\n",
-              event.vkCode, event.scanCode, event.flags, event.dwExtraInfo, kbd_captured));
+    LogFlow (("### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X (mKbdCaptured=%d)\n",
+              event.vkCode, event.scanCode, event.flags, event.dwExtraInfo, mKbdCaptured));
     char buf [256];
     sprintf (buf, "### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X",
@@ -1491,5 +1491,5 @@
         return true;
 
-    if (!kbd_captured)
+    if (!mKbdCaptured)
         return false;
 
@@ -1531,5 +1531,5 @@
 bool VBoxConsoleView::winEvent (MSG *msg)
 {
-    if (!attached || ! (
+    if (!mAttached || ! (
         msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
         msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP
@@ -1611,5 +1611,5 @@
 
     bool result = keyEvent (vkey, scan, flags);
-    if (!result && kbd_captured)
+    if (!result && mKbdCaptured)
     {
         /* keyEvent() returned that it didn't process the message, but since the
@@ -1640,5 +1640,5 @@
 bool VBoxConsoleView::pmEvent (QMSG *aMsg)
 {
-    if (!attached || aMsg->msg != WM_CHAR)
+    if (!mAttached || aMsg->msg != WM_CHAR)
         return false;
 
@@ -1714,5 +1714,5 @@
 
     bool result = keyEvent (vkey, scan, flags);
-    if (!result && kbd_captured)
+    if (!result && mKbdCaptured)
     {
         /* keyEvent() returned that it didn't process the message, but since the
@@ -1745,5 +1745,5 @@
         case XKeyPress:
         case XKeyRelease:
-            if (attached)
+            if (mAttached)
                 break;
             /*  else fall through */
@@ -1982,5 +1982,5 @@
 //      released after we got focus, and grab the mouse only after then.
 //      btw, the similar would be good the for keyboard auto-capture, too.
-//            if (!(mouse_absolute && mouse_integration))
+//            if (!(mMouseAbsolute && mMouseIntegration))
 //                captureMouse (true);
         }
@@ -2102,8 +2102,8 @@
  *  Called on every key press and release (while in focus).
  *
- *  @key        virtual scan code (virtual key on Win32 and KeySym on X11)
- *  @scan       hardware scan code
- *  @flags      flags, a combination of Key* constants
- *  @aUniKey    Unicode translation of the key. Optional.
+ *  @param aKey        virtual scan code (virtual key on Win32 and KeySym on X11)
+ *  @param aScan       hardware scan code
+ *  @param aFlags      flags, a combination of Key* constants
+ *  @param aUniKey     Unicode translation of the key. Optional.
  *
  *  @return     true to consume the event and false to pass it to Qt
@@ -2167,4 +2167,29 @@
                  * to synchronize the state. */
                 fixModifierState (codes, &count);
+            }
+
+            /* Check if it's C-A-D */
+            if (aScan == 0x53 /* Del */ &&
+                ((mPressedKeys [0x38] & IsKeyPressed) /* Alt */ ||
+                 (mPressedKeys [0x38] & IsExtKeyPressed)) &&
+                ((mPressedKeys [0x1d] & IsKeyPressed) /* Ctrl */ ||
+                 (mPressedKeys [0x1d] & IsExtKeyPressed)))
+            {
+                /* Use the C-A-D combination as a last resort to get the
+                 * keyboard and mouse back to the host when the user forgets
+                 * the Host Key. Note that it's always possible to send C-A-D
+                 * to the guest using the Host+Del combination. BTW, it would
+                 * be preferrable to completely ignore C-A-D in guests, but
+                 * that's not possible because we cannot predict what other
+                 * keys will be pressed next when one of C, A, D is held. */
+
+                if (isRunning() && mKbdCaptured)
+                {
+                    captureKbd (false);
+                    if (!(mMouseAbsolute && mMouseIntegration))
+                        captureMouse (false);
+                }
+
+                return true;
             }
 
@@ -2193,5 +2218,5 @@
             }
 
-            if (kbd_captured)
+            if (mKbdCaptured)
                 mPressedKeys [aScan] |= IsKbdCaptured;
             else
@@ -2202,5 +2227,5 @@
     {
         /* currently this is used in winLowKeyboardEvent() only */
-        hostkey_in_capture = kbd_captured;
+        hostkey_in_capture = mKbdCaptured;
     }
 
@@ -2250,5 +2275,5 @@
                     if (isRunning())
                     {
-                        bool captured = kbd_captured;
+                        bool captured = mKbdCaptured;
                         bool ok = true;
                         if (!captured)
@@ -2272,6 +2297,6 @@
                         {
                             captureKbd (!captured, false);
-                            if (!(mouse_absolute && mouse_integration))
-                                captureMouse (kbd_captured);
+                            if (!(mMouseAbsolute && mMouseIntegration))
+                                captureMouse (mKbdCaptured);
                         }
                     }
@@ -2428,5 +2453,5 @@
     }
 
-    if (mouse_captured)
+    if (mMouseCaptured)
     {
 #ifdef Q_WS_WIN32
@@ -2436,6 +2461,6 @@
 
         CMouse mouse = mConsole.GetMouse();
-        mouse.PutMouseEvent (aGlobalPos.x() - last_pos.x(),
-                             aGlobalPos.y() - last_pos.y(),
+        mouse.PutMouseEvent (aGlobalPos.x() - mLastPos.x(),
+                             aGlobalPos.y() - mLastPos.y(),
                              wheel, state);
 
@@ -2469,9 +2494,9 @@
 
         if (rect.contains (aGlobalPos, true))
-            last_pos = aGlobalPos;
+            mLastPos = aGlobalPos;
         else
         {
-            last_pos = rect.center();
-            QCursor::setPos (last_pos);
+            mLastPos = rect.center();
+            QCursor::setPos (mLastPos);
         }
 
@@ -2496,10 +2521,10 @@
         if (p != aPos)
         {
-            last_pos = viewport()->mapToGlobal (p);
-            QCursor::setPos (last_pos);
+            mLastPos = viewport()->mapToGlobal (p);
+            QCursor::setPos (mLastPos);
         }
         else
         {
-            last_pos = aGlobalPos;
+            mLastPos = aGlobalPos;
         }
 #else
@@ -2518,10 +2543,10 @@
         if (p != aGlobalPos)
         {
-            last_pos =  p;
-            QCursor::setPos (last_pos);
+            mLastPos =  p;
+            QCursor::setPos (mLastPos);
         }
         else
         {
-            last_pos = aGlobalPos;
+            mLastPos = aGlobalPos;
         }
 #endif
@@ -2529,5 +2554,5 @@
         return true; /* stop further event handling */
     }
-    else /* !mouse_captured */
+    else /* !mMouseCaptured */
     {
 #ifdef Q_WS_MAC
@@ -2560,5 +2585,5 @@
         }
 
-        if (mouse_absolute && mouse_integration)
+        if (mMouseAbsolute && mMouseIntegration)
         {
             int cw = contentsWidth(), ch = contentsHeight();
@@ -2668,5 +2693,5 @@
         case CEnums::Running:
         {
-            if (last_state == CEnums::Paused)
+            if (mLastState == CEnums::Paused)
             {
                 if (mode != VBoxDefs::TimerMode && mFrameBuf)
@@ -2691,5 +2716,5 @@
     }
 
-    last_state = state;
+    mLastState = state;
 }
 
@@ -2779,12 +2804,12 @@
  *  system (including most system combinations like Alt-Tab).
  *
- *  @capture        true to capture, false to uncapture
- *  @emit_signal    whether to emit keyboardStateChanged() or not
+ *  @param aCapture     true to capture, false to uncapture.
+ *  @param aEmitSignal  Whether to emit keyboardStateChanged() or not.
  */
-void VBoxConsoleView::captureKbd (bool capture, bool emit_signal)
-{
-    AssertMsg (attached, ("Console must be attached"));
-
-    if (kbd_captured == capture)
+void VBoxConsoleView::captureKbd (bool aCapture, bool aEmitSignal /* = true */)
+{
+    AssertMsg (mAttached, ("Console must be attached"));
+
+    if (mKbdCaptured == aCapture)
         return;
 
@@ -2799,5 +2824,5 @@
     /**/
 #elif defined (Q_WS_X11)
-	if (capture)
+	if (aCapture)
 		XGrabKey (x11Display(), AnyKey, AnyModifier,
                   topLevelWidget()->winId(), False,
@@ -2807,5 +2832,5 @@
                     topLevelWidget()->winId());
 #elif defined (Q_WS_MAC)
-    if (capture)
+    if (aCapture)
     {
         ::DarwinDisableGlobalHotKeys (true);
@@ -2818,5 +2843,5 @@
     }
 #else
-    if (capture)
+    if (aCapture)
         grabKeyboard();
     else
@@ -2824,7 +2849,7 @@
 #endif
 
-    kbd_captured = capture;
-
-    if (emit_signal)
+    mKbdCaptured = aCapture;
+
+    if (aEmitSignal)
         emitKeyboardStateChanged ();
 }
@@ -2834,31 +2859,32 @@
  *  unavailable to the host applications.
  *
- *  @capture    true to capture, false to uncapture
+ *  @param aCapture     true to capture, false to uncapture.
+ *  @param aEmitSignal  Whether to emit mouseStateChanged() or not.
  */
-void VBoxConsoleView::captureMouse (bool capture, bool emit_signal)
-{
-    AssertMsg (attached, ("Console must be attached"));
-
-    if (mouse_captured == capture)
+void VBoxConsoleView::captureMouse (bool aCapture, bool aEmitSignal /* = true */)
+{
+    AssertMsg (mAttached, ("Console must be attached"));
+
+    if (mMouseCaptured == aCapture)
         return;
 
-    if (capture)
+    if (aCapture)
     {
         /* memorize the host position where the cursor was captured */
-        captured_pos = QCursor::pos();
+        mCapturedPos = QCursor::pos();
 #ifdef Q_WS_WIN32
         viewport()->setCursor (QCursor (BlankCursor));
         /* move the mouse to the center of the visible area */
         QCursor::setPos (mapToGlobal (visibleRect().center()));
-        last_pos = QCursor::pos();
+        mLastPos = QCursor::pos();
 #elif defined (Q_WS_MAC)
         /* move the mouse to the center of the visible area */
-        last_pos = mapToGlobal (visibleRect().center());
-        QCursor::setPos (last_pos);
+        mLastPos = mapToGlobal (visibleRect().center());
+        QCursor::setPos (mLastPos);
         /* grab all mouse events. */
         viewport()->grabMouse();
 #else
         viewport()->grabMouse();
-        last_pos = QCursor::pos();
+        mLastPos = QCursor::pos();
 #endif
     }
@@ -2873,9 +2899,9 @@
     }
 
-    mouse_captured = capture;
+    mMouseCaptured = aCapture;
 
     updateMouseClipping();
 
-    if (emit_signal)
+    if (aEmitSignal)
         emitMouseStateChanged ();
 }
@@ -2941,5 +2967,5 @@
 void VBoxConsoleView::releaseAllPressedKeys (bool aReleaseHostKey)
 {
-    AssertMsg (attached, ("Console must be attached"));
+    AssertMsg (mAttached, ("Console must be attached"));
 
     CKeyboard keyboard = mConsole.GetKeyboard();
@@ -3008,5 +3034,5 @@
 void VBoxConsoleView::sendChangedKeyStates()
 {
-    AssertMsg (attached, ("Console must be attached"));
+    AssertMsg (mAttached, ("Console must be attached"));
 
     LONG codes [2];
@@ -3036,20 +3062,23 @@
 void VBoxConsoleView::updateMouseClipping()
 {
-    AssertMsg (attached, ("Console must be attached"));
-
-    if ( mouse_captured ) {
-        viewport()->setCursor( QCursor( BlankCursor ) );
+    AssertMsg (mAttached, ("Console must be attached"));
+
+    if (mMouseCaptured)
+    {
+        viewport()->setCursor (QCursor (BlankCursor));
 #ifdef Q_WS_WIN32
         QRect r = viewport()->rect();
-        r.moveTopLeft( viewport()->mapToGlobal( QPoint( 0, 0 ) ) );
+        r.moveTopLeft (viewport()->mapToGlobal (QPoint (0, 0)));
         RECT rect = { r.left(), r.top(), r.right() + 1, r.bottom() + 1 };
-        ::ClipCursor( &rect );
-#endif
-    } else {
+        ::ClipCursor (&rect);
+#endif
+    }
+    else
+    {
 #ifdef Q_WS_WIN32
-        ::ClipCursor( NULL );
+        ::ClipCursor (NULL);
 #endif
         /* return the cursor to where it was when we captured it and show it */
-        QCursor::setPos( captured_pos );
+        QCursor::setPos (mCapturedPos);
         viewport()->unsetCursor();
     }
