Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 59346)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 59347)
@@ -138,44 +138,44 @@
 
 /* Prepare listened objects: */
-void UIKeyboardHandler::prepareListener(ulong uIndex, UIMachineWindow *pMachineWindow)
+void UIKeyboardHandler::prepareListener(ulong uScreenId, UIMachineWindow *pMachineWindow)
 {
     /* If that window is NOT registered yet: */
-    if (!m_windows.contains(uIndex))
+    if (!m_windows.contains(uScreenId))
     {
         /* Add window: */
-        m_windows.insert(uIndex, pMachineWindow);
+        m_windows.insert(uScreenId, pMachineWindow);
         /* Install event-filter for window: */
-        m_windows[uIndex]->installEventFilter(this);
+        m_windows[uScreenId]->installEventFilter(this);
     }
 
     /* If that view is NOT registered yet: */
-    if (!m_views.contains(uIndex))
+    if (!m_views.contains(uScreenId))
     {
         /* Add view: */
-        m_views.insert(uIndex, pMachineWindow->machineView());
+        m_views.insert(uScreenId, pMachineWindow->machineView());
         /* Install event-filter for view: */
-        m_views[uIndex]->installEventFilter(this);
+        m_views[uScreenId]->installEventFilter(this);
     }
 }
 
 /* Cleanup listened objects: */
-void UIKeyboardHandler::cleanupListener(ulong uIndex)
+void UIKeyboardHandler::cleanupListener(ulong uScreenId)
 {
     /* Check if we should release keyboard first: */
-    if ((int)uIndex == m_iKeyboardCaptureViewIndex)
+    if ((int)uScreenId == m_iKeyboardCaptureViewIndex)
         releaseKeyboard();
 
     /* If window still registered: */
-    if (m_windows.contains(uIndex))
+    if (m_windows.contains(uScreenId))
     {
         /* Remove window: */
-        m_windows.remove(uIndex);
+        m_windows.remove(uScreenId);
     }
 
     /* If view still registered: */
-    if (m_views.contains(uIndex))
+    if (m_views.contains(uScreenId))
     {
         /* Remove view: */
-        m_views.remove(uIndex);
+        m_views.remove(uScreenId);
     }
 }
@@ -406,5 +406,5 @@
         hostComboModifierMask |= ::DarwinKeyCodeToDarwinModifierMask(hostCombo.at(i));
     /* Clear most of the modifiers: */
-    m_darwinKeyModifiers &=
+    m_uDarwinKeyModifiers &=
         alphaLock | kEventKeyModifierNumLockMask |
         (aReleaseHostKey ? 0 : hostComboModifierMask);
@@ -889,11 +889,11 @@
     , m_fDebuggerActive(false)
 #if defined(Q_WS_MAC)
-    , m_darwinKeyModifiers(0)
-    , m_fKeyboardGrabbed(false)
-    , m_iKeyboardGrabViewIndex(-1)
+    , m_iKeyboardHookViewIndex(-1)
+    , m_uDarwinKeyModifiers(0)
 #elif defined(Q_WS_WIN)
-    , m_bIsHostkeyInCapture(false)
     , m_iKeyboardHookViewIndex(-1)
+    , m_fIsHostkeyInCapture(false)
     , m_fSkipKeyboardEvents(false)
+    , m_keyboardHook(NULL)
     , m_pAltGrMonitor(0)
 #endif /* Q_WS_WIN */
@@ -964,5 +964,5 @@
     /* We have to make sure the callback for the keyboard events
      * is released when closing this view. */
-    if (m_fKeyboardGrabbed)
+    if (m_iKeyboardHookViewIndex != -1)
         darwinGrabKeyboardEvents(false);
 #endif /* Q_WS_MAC */
@@ -1022,5 +1022,5 @@
                     }
                     /* Register new keyboard-hook: */
-                    m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, lowLevelKeyboardProc, GetModuleHandle(NULL), 0);
+                    m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, UIKeyboardHandler::winKeyboardProc, GetModuleHandle(NULL), 0);
                     AssertMsg(m_keyboardHook, ("SetWindowsHookEx(): err=%d", GetLastError()));
                     /* Remember which view had captured keyboard: */
@@ -1064,8 +1064,8 @@
                 /* If keyboard-event handler is NOT currently installed;
                  * Or installed but NOT for that view: */
-                if (m_iKeyboardGrabViewIndex != (int)uScreenId)
+                if (m_iKeyboardHookViewIndex != (int)uScreenId)
                 {
                     /* If keyboard-event handler is NOT currently installed: */
-                    if (m_iKeyboardGrabViewIndex == -1)
+                    if (m_iKeyboardHookViewIndex == -1)
                     {
                         /* Install the keyboard-event handler: */
@@ -1073,5 +1073,5 @@
                     }
                     /* Update the id: */
-                    m_iKeyboardGrabViewIndex = uScreenId;
+                    m_iKeyboardHookViewIndex = uScreenId;
                 }
 #endif /* Q_WS_MAC */
@@ -1097,10 +1097,10 @@
 #ifdef Q_WS_MAC
                 /* If keyboard-event handler is installed for that view: */
-                if (m_iKeyboardGrabViewIndex == (int)uScreenId)
+                if (m_iKeyboardHookViewIndex == (int)uScreenId)
                 {
                     /* Remove the keyboard-event handler: */
                     darwinGrabKeyboardEvents(false);
                     /* Update the id: */
-                    m_iKeyboardGrabViewIndex = -1;
+                    m_iKeyboardHookViewIndex = -1;
                 }
 #endif /* Q_WS_MAC */
@@ -1165,5 +1165,4 @@
 void UIKeyboardHandler::darwinGrabKeyboardEvents(bool fGrab)
 {
-    m_fKeyboardGrabbed = fGrab;
     if (fGrab)
     {
@@ -1174,11 +1173,11 @@
         /* Bring the caps lock state up to date, otherwise e.g. a later Shift
          * key press will accidentally inject a CapsLock key press and release,
-         * see UIKeyboardHandler::darwinKeyboardEvent for the code handling
+         * see UIKeyboardHandler::macKeyboardEvent for the code handling
          * modifier key state changes */
-        m_darwinKeyModifiers ^= (m_darwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock;
+        m_uDarwinKeyModifiers ^= (m_uDarwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock;
 
         /* Register the event callback/hook and grab the keyboard. */
         UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */,
-                                                                UIKeyboardHandler::darwinEventHandlerProc, this);
+                                                                UIKeyboardHandler::macKeyboardProc, this);
 
         ::DarwinGrabKeyboard (false);
@@ -1188,9 +1187,9 @@
         ::DarwinReleaseKeyboard();
         UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */,
-                                                                  UIKeyboardHandler::darwinEventHandlerProc, this);
-    }
-}
-
-bool UIKeyboardHandler::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
+                                                                  UIKeyboardHandler::macKeyboardProc, this);
+    }
+}
+
+bool UIKeyboardHandler::macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
 {
     UIKeyboardHandler *pKeyboardHandler = (UIKeyboardHandler*)pvUser;
@@ -1206,5 +1205,5 @@
     if (eventClass == kEventClassKeyboard)
     {
-        if (pKeyboardHandler->darwinKeyboardEvent (pvCocoaEvent, inEvent))
+        if (pKeyboardHandler->macKeyboardEvent(pvCocoaEvent, inEvent))
             return true;
     }
@@ -1213,5 +1212,5 @@
 }
 
-bool UIKeyboardHandler::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
+bool UIKeyboardHandler::macKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
 {
     bool ret = false;
@@ -1256,5 +1255,5 @@
             ucs[cbWritten / sizeof(wchar_t)] = 0; /* The api doesn't terminate it. */
 
-            ret = keyEvent(keyCode, scanCode, flags, m_iKeyboardGrabViewIndex, ucs[0] ? ucs : NULL);
+            ret = keyEvent(keyCode, scanCode, flags, m_iKeyboardHookViewIndex, ucs[0] ? ucs : NULL);
         }
     }
@@ -1266,5 +1265,5 @@
                             sizeof(newMask), NULL, &newMask);
         newMask = ::DarwinAdjustModifierMask(newMask, pvCocoaEvent);
-        UInt32 changed = newMask ^ m_darwinKeyModifiers;
+        UInt32 changed = newMask ^ m_uDarwinKeyModifiers;
         if (changed)
         {
@@ -1285,5 +1284,5 @@
                         flags |= KeyExtended;
                     scanCode &= VBOXKEY_SCANCODE_MASK;
-                    ret |= keyEvent(keyCode, scanCode & 0xff, flags, m_iKeyboardGrabViewIndex);
+                    ret |= keyEvent(keyCode, scanCode & 0xff, flags, m_iKeyboardHookViewIndex);
                 }
                 else
@@ -1293,11 +1292,11 @@
                         flags |= KeyExtended;
                     scanCode &= VBOXKEY_SCANCODE_MASK;
-                    keyEvent(keyCode, scanCode, flags | KeyPressed, m_iKeyboardGrabViewIndex);
-                    keyEvent(keyCode, scanCode, flags, m_iKeyboardGrabViewIndex);
+                    keyEvent(keyCode, scanCode, flags | KeyPressed, m_iKeyboardHookViewIndex);
+                    keyEvent(keyCode, scanCode, flags, m_iKeyboardHookViewIndex);
                 }
             }
         }
 
-        m_darwinKeyModifiers = newMask;
+        m_uDarwinKeyModifiers = newMask;
 
         /* Always return true here because we'll otherwise getting a Qt event
@@ -1311,7 +1310,7 @@
 #elif defined(Q_WS_WIN)
 
-LRESULT CALLBACK UIKeyboardHandler::lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
-{
-    if (nCode == HC_ACTION && m_spKeyboardHandler && m_spKeyboardHandler->winLowKeyboardEvent(wParam, *(KBDLLHOOKSTRUCT*)lParam))
+LRESULT CALLBACK UIKeyboardHandler::winKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
+{
+    if (nCode == HC_ACTION && m_spKeyboardHandler && m_spKeyboardHandler->winKeyboardEvent(wParam, *(KBDLLHOOKSTRUCT*)lParam))
         return 1;
 
@@ -1319,5 +1318,5 @@
 }
 
-bool UIKeyboardHandler::winLowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event)
+bool UIKeyboardHandler::winKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event)
 {
     /* Check what related machine-view was NOT unregistered yet: */
@@ -1333,5 +1332,5 @@
     if (   (event.flags & 0x80) /* released */
         && (   (   UIHostCombo::toKeyCodeList(m_globalSettings.hostCombo()).contains(event.vkCode)
-                && !m_bIsHostkeyInCapture)
+                && !m_fIsHostkeyInCapture)
             ||    (  m_pressedKeys[event.scanCode & 0x7F]
                    & (IsKbdCaptured | what_pressed))
@@ -1601,6 +1600,6 @@
     if (m_bIsHostComboPressed || isHostComboStateChanged)
     {
-        /* Currently this is used in winLowKeyboardEvent() only: */
-        m_bIsHostkeyInCapture = m_fIsKeyboardCaptured;
+        /* Currently this is used in winKeyboardEvent() only: */
+        m_fIsHostkeyInCapture = m_fIsKeyboardCaptured;
     }
 #endif /* Q_WS_WIN */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h	(revision 59346)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h	(revision 59347)
@@ -71,6 +71,6 @@
 
     /* Prepare/cleanup listeners: */
-    void prepareListener(ulong uIndex, UIMachineWindow *pMachineWindow);
-    void cleanupListener(ulong uIndex);
+    void prepareListener(ulong uScreenId, UIMachineWindow *pMachineWindow);
+    void cleanupListener(ulong uScreenId);
 
     /* Commands to capture/release keyboard: */
@@ -91,5 +91,5 @@
 #ifdef Q_WS_MAC
     bool isHostKeyAlone() const { return m_bIsHostComboAlone; }
-    bool isKeyboardGrabbed() const { return m_fKeyboardGrabbed; }
+    bool isKeyboardGrabbed() const { return m_iKeyboardHookViewIndex != -1; }
 #endif /* Q_WS_MAC */
 
@@ -153,12 +153,12 @@
     void darwinGrabKeyboardEvents(bool fGrab);
     /** Mac: Performs initial pre-processing of all the native keyboard events. */
-    static bool darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
+    static bool macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
     /** Mac: Performs initial pre-processing of all the native keyboard events. */
-    bool darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
+    bool macKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
 #elif defined(Q_WS_WIN)
     /** Win: Performs initial pre-processing of all the native keyboard events. */
-    static LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
+    static LRESULT CALLBACK winKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
     /** Win: Performs initial pre-processing of all the native keyboard events. */
-    bool winLowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event);
+    bool winKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event);
 #endif /* Q_WS_WIN */
 
@@ -212,23 +212,21 @@
 
 #if defined(Q_WS_MAC)
+    /** Holds the keyboard hook view index. */
+    int m_iKeyboardHookViewIndex;
     /** Holds the current modifiers key mask. */
-    UInt32 m_darwinKeyModifiers;
-    /** Holds whether the keyboard is grabbed. */
-    bool m_fKeyboardGrabbed;
+    UInt32 m_uDarwinKeyModifiers;
+#elif defined(Q_WS_WIN)
     /** Holds the keyboard hook view index. */
-    int m_iKeyboardGrabViewIndex;
-#elif defined(Q_WS_WIN)
-    /* Currently this is used in winLowKeyboardEvent() only: */
-    bool m_bIsHostkeyInCapture;
+    int m_iKeyboardHookViewIndex;
+    /* Currently this is used in winKeyboardEvent() only: */
+    bool m_fIsHostkeyInCapture;
+    /** Holds whether the keyboard event filter should ignore keyboard events. */
+    bool m_fSkipKeyboardEvents;
+    /** Holds the keyboard hook instance. */
+    HHOOK m_keyboardHook;
+    /** Holds the object monitoring key event stream for problematic AltGr events. */
+    WinAltGrMonitor *m_pAltGrMonitor;
     /** Holds the keyboard handler reference to be accessible from the keyboard hook. */
     static UIKeyboardHandler *m_spKeyboardHandler;
-    /** Holds the keyboard hook instance. */
-    HHOOK m_keyboardHook;
-    /** Holds the keyboard hook view index. */
-    int m_iKeyboardHookViewIndex;
-    /** Holds whether the keyboard event filter should ignore keyboard events. */
-    bool m_fSkipKeyboardEvents;
-    /** Holds the object monitoring key event stream for problematic AltGr events. */
-    WinAltGrMonitor *m_pAltGrMonitor;
 #endif /* Q_WS_WIN */
 
