Index: /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h	(revision 14396)
+++ /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h	(revision 14397)
@@ -302,4 +302,5 @@
                                                   WPARAM wParam, LPARAM lParam);
 #elif defined (Q_WS_MAC)
+    EventHandlerRef mDarwinWindowOverlayHandlerRef;
 # ifndef VBOX_WITH_HACKED_QT
     static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
Index: /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h	(revision 14396)
+++ /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h	(revision 14397)
@@ -220,4 +220,16 @@
 OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
 
+/* Handler for the OpenGL overlay window stuff & the possible messages. */
+enum
+{
+    /* Event classes */
+    kEventClassVBox        = 'vbox',
+    /* Event kinds */
+    kEventVBoxShowWindow   = 'swin',
+    kEventVBoxMoveWindow   = 'mwin',
+    kEventVBoxResizeWindow = 'rwin',
+};
+OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
+
 # ifdef DEBUG
 void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent);
Index: /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp	(revision 14396)
+++ /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp	(revision 14397)
@@ -680,4 +680,18 @@
     /* Overlay logo for the dock icon */
     mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_cube_42px.png");
+
+    /* Install the event handler which will proceed external window handling */
+    EventHandlerUPP eventHandler = ::NewEventHandlerUPP (::darwinOverlayWindowHandler);
+    EventTypeSpec eventTypes[] =
+    {
+        { kEventClassVBox, kEventVBoxShowWindow },
+        { kEventClassVBox, kEventVBoxMoveWindow },
+        { kEventClassVBox, kEventVBoxResizeWindow }
+    };
+
+    mDarwinWindowOverlayHandlerRef = NULL;
+    ::InstallApplicationEventHandler (eventHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
+                                      this, &mDarwinWindowOverlayHandlerRef);
+    ::DisposeEventHandlerUPP (eventHandler);
 #endif
 
@@ -855,4 +869,9 @@
 
 #ifdef Q_WS_MAC
+    if (mDarwinWindowOverlayHandlerRef)
+    {
+        ::RemoveEventHandler (mDarwinWindowOverlayHandlerRef);
+        mDarwinWindowOverlayHandlerRef = NULL;
+    }
     CGImageRelease (mVirtualBoxLogo);
 #endif
Index: /trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp	(revision 14396)
+++ /trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp	(revision 14397)
@@ -373,4 +373,64 @@
     return status;
 }
+
+OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)
+{
+    if (aInUserData)
+        return ::CallNextEventHandler (aInHandlerCallRef, aInEvent);
+
+    UInt32 eventClass = ::GetEventClass (aInEvent);
+    UInt32 eventKind = ::GetEventKind (aInEvent);
+    /* For debugging events */
+    /*
+    if (!(eventClass == 'cute'))
+        ::darwinDebugPrintEvent ("view: ", aInEvent);
+    */
+    QWidget *view = static_cast<QWidget *> (aInUserData);
+
+    if (eventClass == kEventClassVBox)
+    {
+        if (eventKind == kEventVBoxShowWindow)
+        {
+//            printf ("ShowWindow requested\n");
+            WindowRef w;
+            if (GetEventParameter (aInEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof (w), NULL, &w) != noErr)
+                return noErr;
+            ShowWindow (w);
+            SelectWindow (w);
+            return noErr;
+        }
+        if (eventKind == kEventVBoxMoveWindow)
+        {
+//            printf ("MoveWindow requested\n");
+            WindowPtr w;
+            if (GetEventParameter (aInEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof (w), NULL, &w) != noErr)
+                return noErr;
+            HIPoint p;
+            if (GetEventParameter (aInEvent, kEventParamOrigin, typeHIPoint, NULL, sizeof (p), NULL, &p) != noErr)
+                return noErr;
+            ChangeWindowGroupAttributes (GetWindowGroup (w), 0, kWindowGroupAttrMoveTogether);
+            QPoint p1 = view->mapToGlobal (QPoint (p.x, p.y));
+            MoveWindow (w, p1.x(), p1.y(), true);
+            ChangeWindowGroupAttributes (GetWindowGroup (w), kWindowGroupAttrMoveTogether, 0);
+            return noErr;
+        }
+        if (eventKind == kEventVBoxResizeWindow)
+        {
+//            printf ("ResizeWindow requested\n");
+            WindowPtr w;
+            if (GetEventParameter (aInEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof (w), NULL, &w) != noErr)
+                return noErr;
+            HISize s;
+            if (GetEventParameter (aInEvent, kEventParamDimensions, typeHISize, NULL, sizeof (s), NULL, &s) != noErr)
+                return noErr;
+            SizeWindow (w, s.width, s.height, true);
+            return noErr;
+        }
+    }
+
+    return ::CallNextEventHandler (aInHandlerCallRef, aInEvent);
+}
+
+
 
 /* Event debugging stuff. Borrowed from the Knuts Qt patch. */
