Index: /trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleWnd.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleWnd.h	(revision 6440)
+++ /trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleWnd.h	(revision 6441)
@@ -182,4 +182,6 @@
     void onExitFullscreen();
 
+    void setViewInSeamlessMode(const QRect& targetRect);
+
 private:
 
@@ -248,5 +250,8 @@
     bool statusBarChangedInside;
 
-    QSpacerItem *mShiftingSpacer;
+    QSpacerItem *mShiftingSpacerLeft;
+    QSpacerItem *mShiftingSpacerTop;
+    QSpacerItem *mShiftingSpacerRight;
+    QSpacerItem *mShiftingSpacerBottom;
 
 #ifdef VBOX_WITH_DEBUGGER_GUI
Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 6440)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 6441)
@@ -1057,11 +1057,14 @@
                 mIgnoreMainwndResize = oldIgnoreMainwndResize;
 
-                /* emit a signal about guest was resized */
-                emit resizeHintDone();
-
                 /* update geometry after entering fullscreen | seamless */
                 if (mMainWnd->isTrueFullscreen() || mMainWnd->isTrueSeamless())
                     updateGeometry();
 
+                /* make sure that all posted signals are processed */
+                qApp->processEvents();
+
+                /* emit a signal about guest was resized */
+                emit resizeHintDone();
+              
                 return true;
             }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp	(revision 6440)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp	(revision 6441)
@@ -631,5 +631,21 @@
     {
         setCentralWidget (new QWidget (this, "centralWidget"));
-        new QBoxLayout (centralWidget(), QBoxLayout::Down);
+        QGridLayout *pMainLayout = new QGridLayout(centralWidget(), 3, 3, 0, 0);
+        mShiftingSpacerLeft = new QSpacerItem (0, 0, 
+                                               QSizePolicy::Fixed,
+                                               QSizePolicy::Fixed);
+        mShiftingSpacerTop = new QSpacerItem (0, 0, 
+                                              QSizePolicy::Fixed,
+                                              QSizePolicy::Fixed);
+        mShiftingSpacerRight = new QSpacerItem (0, 0, 
+                                                QSizePolicy::Fixed,
+                                                QSizePolicy::Fixed);
+        mShiftingSpacerBottom = new QSpacerItem (0, 0, 
+                                                 QSizePolicy::Fixed,
+                                                 QSizePolicy::Fixed);
+        pMainLayout->addItem(mShiftingSpacerLeft, 1, 0);
+        pMainLayout->addMultiCell(mShiftingSpacerTop, 0, 0, 0, 2);
+        pMainLayout->addItem(mShiftingSpacerRight, 1, 2);
+        pMainLayout->addMultiCell(mShiftingSpacerBottom, 2, 2, 0, 2);
     }
 
@@ -646,11 +662,6 @@
     activateUICustomizations();
 
-    ((QBoxLayout*) centralWidget()->layout())->addWidget (
-        console, 0, AlignVCenter | AlignHCenter);
-
-    mShiftingSpacer = new QSpacerItem (0, 0, QSizePolicy::Expanding,
-                                             QSizePolicy::Fixed);
-    ((QBoxLayout*) centralWidget()->layout())->addItem (mShiftingSpacer);
-
+    static_cast<QGridLayout*>(centralWidget()->layout())->addWidget(console, 1, 1, AlignVCenter | AlignHCenter);
+    
     CMachine cmachine = csession.GetMachine();
 
@@ -996,4 +1007,10 @@
 {
     disconnect (console, SIGNAL (resizeHintDone()), 0, 0);
+#ifndef Q_WS_MAC 
+    /* It isn't guaranteed that the guest os set the video mode that
+     * we requested. So after all the resizing stuff set the clipping 
+     * mask and the spacing shifter to the corresponding values. */
+    setViewInSeamlessMode(QRect(console->mapToGlobal(QPoint(0, 0)), console->size()));
+#endif
 
     vmSeamlessAction->setEnabled (mIsSeamless);
@@ -1895,4 +1912,5 @@
 bool VBoxConsoleWnd::toggleFullscreenMode (bool aOn, bool aSeamless)
 {
+
     if (aSeamless)
     {
@@ -1995,18 +2013,8 @@
             dtw->availableGeometry (this) : dtw->screenGeometry (this);
 
-        /* Calculate the difference region between current mode
-         * (fullscreen or seamless) and the screen geometry. */
-        mStrictedRegion =
-            QRegion (dtw->screenGeometry (this)) - scrGeo;
-
-        /* Setup the shifting spacer to make the console to be aligned on top
-         * in the seamless mode. */
-#ifdef Q_WS_MAC 
-        mShiftingSpacer->changeSize (0,  dtw->screenGeometry(this).bottom() - scrGeo.bottom(),
-                                     QSizePolicy::Preferred, QSizePolicy::Fixed);
-#else
-        mShiftingSpacer->changeSize (0, mStrictedRegion.boundingRect().height(),
-                                     QSizePolicy::Preferred, QSizePolicy::Fixed);
-#endif
+        /* It isn't guaranteed that the guest os set the video mode that
+         * we requested. So after all the resizing stuff set the clipping 
+         * mask and the spacing shifter to the corresponding values. */
+        setViewInSeamlessMode(dtw->availableGeometry(this));
 
 #ifdef Q_WS_WIN32
@@ -2052,10 +2060,11 @@
         setWindowState (windowState() ^ WindowFullScreen);
 #ifdef Q_WS_MAC /* setMask seems to not include the far border pixels. */
-        QRect maskRect = dtw->screenGeometry (this);
-        maskRect.setRight (maskRect.right() + 1);
-        maskRect.setBottom (maskRect.bottom() + 1);
-        setMask (maskRect);
+//        QRect maskRect = dtw->screenGeometry (this);
+//        maskRect.setRight (maskRect.right() + 1);
+//        maskRect.setBottom (maskRect.bottom() + 1);
+//        setMask (maskRect);
+
 #else
-        setMask (dtw->screenGeometry (this));
+//        setMask (dtw->screenGeometry (this));
 #endif
 
@@ -2073,6 +2082,8 @@
 
         /* Reset the shifting spacer. */
-        mShiftingSpacer->changeSize (0, 0, QSizePolicy::Preferred,
-                                           QSizePolicy::Fixed);
+        mShiftingSpacerLeft->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
+        mShiftingSpacerTop->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
+        mShiftingSpacerRight->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
+        mShiftingSpacerBottom->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
 
         /* Restore the previous scroll-view minimum size before the exiting
@@ -2121,4 +2132,34 @@
 // Private slots
 /////////////////////////////////////////////////////////////////////////////
+void VBoxConsoleWnd::setViewInSeamlessMode(const QRect& targetRect)
+{
+    if (mIsSeamless)
+    {
+        /* It isn't guaranteed that the guest os set the video mode that
+         * we requested. So after all the resizing stuff set the clipping 
+         * mask and the spacing shifter to the corresponding values. */
+        QDesktopWidget *dtw = QApplication::desktop();
+        QRect sRect = dtw->screenGeometry (this);
+        QRect aRect(targetRect);
+        QRect a1Rect(targetRect);
+#ifdef Q_WS_MAC
+        /* On mac os x this isn't necessary cause the screen starts
+         * by y=0 always regardless if there is the global menubar or not. */
+        aRect.setRect(aRect.left(), 0, aRect.width(), aRect.height()+aRect.top());
+        a1Rect.setRect(a1Rect.left(), 0, a1Rect.width(), a1Rect.height());
+#endif // Q_WS_MAC
+        /* Set the clipping mask */
+        mStrictedRegion = QRegion(sRect) - a1Rect;
+        /* Set the shifting spacer */
+        mShiftingSpacerLeft->changeSize(RT_ABS(sRect.left() - aRect.left()), 0,
+                                        QSizePolicy::Fixed, QSizePolicy::Preferred);
+        mShiftingSpacerTop->changeSize(0, RT_ABS(sRect.top() - aRect.top()),
+                                       QSizePolicy::Preferred, QSizePolicy::Fixed);
+        mShiftingSpacerRight->changeSize(RT_ABS(sRect.right() - aRect.right()), 0,
+                                         QSizePolicy::Fixed, QSizePolicy::Preferred);
+        mShiftingSpacerBottom->changeSize(0, RT_ABS(sRect.bottom() - aRect.bottom()),
+                                          QSizePolicy::Preferred, QSizePolicy::Fixed);
+    }
+}
 
 void VBoxConsoleWnd::vmFullscreen (bool aOn)
@@ -2513,5 +2554,17 @@
 void VBoxConsoleWnd::setMask (const QRegion &aRegion)
 {
-    QRegion region = aRegion - mStrictedRegion;
+    QRegion region = aRegion;
+    region.translate(mShiftingSpacerLeft->sizeHint().width(), mShiftingSpacerTop->sizeHint().height());
+    region -= mStrictedRegion;
+
+#ifdef Q_WS_MAC
+    /* This is necessary to avoid the flicker by
+     * an mask update. 
+     * See http://lists.apple.com/archives/Carbon-development/2001/Apr/msg01651.html
+     * for the hint.
+     * There *must* be a better solution. */
+    if(!region.isEmpty())
+      region |= QRect(0, 0, 1, 1);
+#endif 
 
 #ifdef Q_WS_WIN
@@ -2520,9 +2573,11 @@
     /* Region offset calculation */
     int fleft = 0, ftop = 0;
-    if (isTopLevel())
-    {
-        ftop = topData()->ftop;
-        fleft = topData()->fleft;
-    }
+    /* I think this isn't necessary anymore because the 4 shifting spacer.
+     * Has to be verified. */
+//    if (isTopLevel())
+//    {
+//        ftop = topData()->ftop;
+//        fleft = topData()->fleft;
+//    }
 
     /* Visible region calculation */
@@ -3035,7 +3090,7 @@
     vmAutoresizeGuestAction->setEnabled (aActive);
     vmSeamlessAction->setEnabled (aSeamlessSupported);
-#ifndef Q_WS_MAC /** @todo fix seamless mode on Mac OS X. It is temporarily disabled to prevent bogus bugreports for the beta 3 / beta 2 leopard update. */
+//#ifndef Q_WS_MAC /** @todo fix seamless mode on Mac OS X. It is temporarily disabled to prevent bogus bugreports for the beta 3 / beta 2 leopard update. */
     mIsSeamlessSupported = aSeamlessSupported;
-#endif
+//#endif
     /* If seamless mode should be enabled then check if it is enabled
      * currently and re-enable it if open-view procedure is finished */
