Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 52511)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 52512)
@@ -32,4 +32,5 @@
 #include "QIMenu.h"
 #ifdef Q_WS_MAC
+# include "UICocoaApplication.h"
 # include "UIExtraDataManager.h"
 # include "VBoxUtils.h"
@@ -511,4 +512,12 @@
 
 #ifdef Q_WS_MAC
+    /* For ML and next: */
+    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
+    {
+        /* Register to native notifications: */
+        UICocoaApplication::instance()->registerToNotificationOfWorkspace("NSWorkspaceDidActivateApplicationNotification", this,
+                                                                          UIMachineLogicFullscreen::nativeHandlerForApplicationActivation);
+    }
+
     /* We have to make sure that we are getting the front most process.
      * This is necessary for Qt versions > 4.3.3: */
@@ -599,4 +608,13 @@
         return;
 
+#ifdef Q_WS_MAC
+    /* For ML and next: */
+    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
+    {
+        /* Unregister from native notifications: */
+        UICocoaApplication::instance()->unregisterFromNotificationOfWorkspace("NSWorkspaceDidActivateApplicationNotification", this);
+    }
+#endif/* Q_WS_MAC */
+
     /* Mark machine-window(s) destroyed: */
     setMachineWindowsCreated(false);
@@ -688,5 +706,5 @@
 
     /* Get screen ID: */
-    ulong uScreenID = pMachineWindow->screenId();
+    const ulong uScreenID = pMachineWindow->screenId();
     LogRel(("UIMachineLogicFullscreen::revalidateNativeFullScreen: For machine-window #%d.\n",
             (int)uScreenID));
@@ -695,6 +713,9 @@
     if (uScreenID != 0 && !screensHaveSeparateSpaces())
     {
-        /* If there is no fullscreen window or it's invalidated: */
-        if (m_fullscreenMachineWindows.isEmpty() || !m_invalidFullscreenMachineWindows.isEmpty())
+        /* We are hiding transient window if:
+         * 1. application is inactive at all or
+         * 2. there is no fullscreen window or it's invalidated. */
+        if (   !UICocoaApplication::instance()->isActive()
+            || m_fullscreenMachineWindows.isEmpty() || !m_invalidFullscreenMachineWindows.isEmpty())
         {
             LogRel(("UIMachineLogicFullscreen::revalidateNativeFullScreen: "
@@ -794,4 +815,52 @@
         revalidateNativeFullScreen(pMachineWindow);
 }
+
+/* static */
+void UIMachineLogicFullscreen::nativeHandlerForApplicationActivation(QObject *pObject, const QMap<QString, QString> &userInfo)
+{
+    /* Handle arrived notification: */
+    UIMachineLogicFullscreen *pLogic = qobject_cast<UIMachineLogicFullscreen*>(pObject);
+    AssertPtrReturnVoid(pLogic);
+    {
+        /* Redirect arrived notification: */
+        pLogic->nativeHandlerForApplicationActivation(userInfo);
+    }
+}
+
+void UIMachineLogicFullscreen::nativeHandlerForApplicationActivation(const QMap<QString, QString> &userInfo)
+{
+    /* Make sure we have BundleIdentifier key: */
+    AssertReturnVoid(userInfo.contains("BundleIdentifier"));
+
+    /* On VirtualBox activation: */
+    if (userInfo.value("BundleIdentifier") == "org.virtualbox.app.VirtualBox")
+    {
+        LogRel(("UIMachineLogicFullscreen::nativeHandlerForApplicationActivation: BundleIdentifier = %s\n",
+                userInfo.value("BundleIdentifier").toAscii().constData()));
+
+        /* Make sure all the transient machine-windows updated: */
+        foreach (UIMachineWindow *pMachineWindow, machineWindows())
+            if (pMachineWindow->screenId() != 0 && !screensHaveSeparateSpaces())
+            {
+                /* If there is no fullscreen window or it's invalidated: */
+                if (m_fullscreenMachineWindows.isEmpty() || !m_invalidFullscreenMachineWindows.isEmpty())
+                {
+                    LogRel(("UIMachineLogicFullscreen::nativeHandlerForApplicationActivation: "
+                            "Ask transient machine-window #%d to hide.\n", (int)pMachineWindow->screenId()));
+
+                    pMachineWindow->hide();
+                }
+                /* If there is valid fullscreen window: */
+                else
+                {
+                    LogRel(("UIMachineLogicFullscreen::nativeHandlerForApplicationActivation: "
+                            "Ask transient machine-window #%d to show/normalize.\n", (int)pMachineWindow->screenId()));
+
+                    /* Make sure window have proper geometry and shown: */
+                    pMachineWindow->showInNecessaryMode();
+                }
+            }
+    }
+}
 #endif /* Q_WS_MAC */
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h	(revision 52511)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h	(revision 52512)
@@ -139,4 +139,9 @@
     /** Mac OS X: Revalidates 'fullscreen' mode for all windows. */
     void revalidateNativeFullScreen();
+
+    /** Mac OS X: Proxies native notification about active space change. */
+    static void nativeHandlerForApplicationActivation(QObject *pObject, const QMap<QString, QString> &userInfo);
+    /** Mac OS X: Handles native notification about active space change. */
+    void nativeHandlerForApplicationActivation(const QMap<QString, QString> &userInfo);
 #endif /* Q_WS_MAC */
 
