Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 45503)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 45504)
@@ -800,15 +800,32 @@
                 break;
             }
-#elif defined(Q_WS_MAC)
-            case QEvent::WindowActivate:
-            {
-                /* If keyboard event handler is NOT currently installed;
-                 * Or installed but NOT for that window: */
+#endif
+            default:
+                break;
+        }
+    }
+
+    else
+
+    /* Check if pWatchedObject object is view: */
+    if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject))
+    {
+        /* Get corresponding screen index: */
+        ulong uScreenId = m_views.key(pWatchedView);
+        NOREF(uScreenId);
+        /* Handle view events: */
+        switch (pEvent->type())
+        {
+            case QEvent::FocusIn:
+            {
+#ifdef Q_WS_MAC
+                /* If keyboard-event handler is NOT currently installed;
+                 * Or installed but NOT for that view: */
                 if (m_iKeyboardGrabViewIndex != (int)uScreenId)
                 {
-                    /* If keyboard event handler is NOT currently installed: */
+                    /* If keyboard-event handler is NOT currently installed: */
                     if (m_iKeyboardGrabViewIndex == -1)
                     {
-                        /* Install the keyboard event handler: */
+                        /* Install the keyboard-event handler: */
                         darwinGrabKeyboardEvents(true);
                     }
@@ -816,36 +833,6 @@
                     m_iKeyboardGrabViewIndex = uScreenId;
                 }
-                break;
-            }
-            case QEvent::WindowDeactivate:
-            {
-                /* If keyboard event handler is installed exactly for that window: */
-                if (m_iKeyboardGrabViewIndex == (int)uScreenId)
-                {
-                    /* Remove the keyboard event handler: */
-                    darwinGrabKeyboardEvents(false);
-                    /* Update the id: */
-                    m_iKeyboardGrabViewIndex = -1;
-                }
-                break;
-            }
-#endif
-            default:
-                break;
-        }
-    }
-
-    else
-
-    /* Check if pWatchedObject object is view: */
-    if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject))
-    {
-        /* Get corresponding screen index: */
-        ulong uScreenId = m_views.key(pWatchedView);
-        NOREF(uScreenId);
-        /* Handle view events: */
-        switch (pEvent->type())
-        {
-            case QEvent::FocusIn:
+#endif /* Q_WS_MAC */
+
                 if (isSessionRunning())
                 {
@@ -863,5 +850,18 @@
                 }
                 break;
+            }
             case QEvent::FocusOut:
+            {
+#ifdef Q_WS_MAC
+                /* If keyboard-event handler is installed for that view: */
+                if (m_iKeyboardGrabViewIndex == (int)uScreenId)
+                {
+                    /* Remove the keyboard-event handler: */
+                    darwinGrabKeyboardEvents(false);
+                    /* Update the id: */
+                    m_iKeyboardGrabViewIndex = -1;
+                }
+#endif /* Q_WS_MAC */
+
                 /* Release keyboard: */
                 if (isSessionRunning())
@@ -870,4 +870,5 @@
                 releaseAllPressedKeys(true);
                 break;
+            }
             case QEvent::KeyPress:
             case QEvent::KeyRelease:
