Index: /trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp	(revision 81284)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp	(revision 81285)
@@ -3520,5 +3520,5 @@
 UISoftKeyboard::UISoftKeyboard(QWidget *pParent,
                                UISession *pSession, QWidget *pCenterWidget, QString strMachineName /* = QString()*/)
-    :QIWithRetranslateUI<QMainWindow>(pParent)
+    : QMainWindowWithRestorableGeometryAndRetranslateUi(pParent)
     , m_pSession(pSession)
     , m_pCenterWidget(pCenterWidget)
@@ -3560,4 +3560,9 @@
 }
 
+bool UISoftKeyboard::shouldBeMaximized() const
+{
+    return gEDataManager->softKeyboardDialogShouldBeMaximized();
+}
+
 void UISoftKeyboard::sltKeyboardLedsChange()
 {
@@ -3827,15 +3832,11 @@
 void UISoftKeyboard::saveSettings()
 {
-    /* Save window geometry to extradata: */
-    const QRect saveGeometry = geometry();
-#ifdef VBOX_WS_MAC
-    /* darwinIsWindowMaximized expects a non-const QWidget*. thus const_cast: */
-    QWidget *pw = const_cast<QWidget*>(qobject_cast<const QWidget*>(this));
-    gEDataManager->setSoftKeyboardDialogGeometry(saveGeometry, ::darwinIsWindowMaximized(pw));
-#else /* !VBOX_WS_MAC */
-    gEDataManager->setSoftKeyboardDialogGeometry(saveGeometry, isMaximized());
-#endif /* !VBOX_WS_MAC */
-    LogRel2(("GUI: Soft Keyboard: Geometry saved as: Origin=%dx%d, Size=%dx%d\n",
-             saveGeometry.x(), saveGeometry.y(), saveGeometry.width(), saveGeometry.height()));
+    /* Save geometry to extradata: */
+    const QRect geo = currentGeometry();
+    LogRel2(("GUI: UISoftKeyboard: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
+             geo.x(), geo.y(), geo.width(), geo.height()));
+    gEDataManager->setSoftKeyboardDialogGeometry(geo, isCurrentlyMaximized());
+
+    /* Save other settings: */
     if (m_pKeyboardWidget)
     {
@@ -3852,23 +3853,24 @@
 void UISoftKeyboard::loadSettings()
 {
+    /* Invent default window geometry: */
     float fKeyboardAspectRatio = 1.0f;
     if (m_pKeyboardWidget)
         fKeyboardAspectRatio = m_pKeyboardWidget->layoutAspectRatio();
-
-    const QRect desktopRect = gpDesktop->availableGeometry(this);
-    int iDefaultWidth = desktopRect.width() / 2;
-    int iDefaultHeight = iDefaultWidth * fKeyboardAspectRatio;
-    QRect defaultGeometry(0, 0, iDefaultWidth, iDefaultHeight);
-
-
+    const QRect availableGeo = gpDesktop->availableGeometry(this);
+    const int iDefaultWidth = availableGeo.width() / 2;
+    const int iDefaultHeight = iDefaultWidth * fKeyboardAspectRatio;
+    QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
     if (m_pCenterWidget)
-        defaultGeometry.moveCenter(m_pCenterWidget->geometry().center());
+        defaultGeo.moveCenter(m_pCenterWidget->geometry().center());
+    else
+        defaultGeo.moveCenter(availableGeo.center());
+
     /* Load geometry from extradata: */
-    QRect geometry = gEDataManager->softKeyboardDialogGeometry(this, defaultGeometry);
-
-    /* Restore geometry: */
-    LogRel2(("GUI: Soft Keyboard: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
-             geometry.x(), geometry.y(), geometry.width(), geometry.height()));
-    setDialogGeometry(geometry);
+    const QRect geo = gEDataManager->softKeyboardDialogGeometry(this, defaultGeo);
+    LogRel2(("GUI: UISoftKeyboard: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
+             geo.x(), geo.y(), geo.width(), geo.height()));
+    restoreGeometry(geo);
+
+    /* Load other settings: */
     if (m_pKeyboardWidget)
     {
@@ -3936,19 +3938,3 @@
 }
 
-void UISoftKeyboard::setDialogGeometry(const QRect &geometry)
-{
-#ifdef VBOX_WS_MAC
-    /* Use the old approach for OSX: */
-    move(geometry.topLeft());
-    resize(geometry.size());
-#else /* VBOX_WS_MAC */
-    /* Use the new approach for Windows/X11: */
-    UICommon::setTopLevelGeometry(this, geometry);
-#endif /* !VBOX_WS_MAC */
-
-    /* Maximize (if necessary): */
-    if (gEDataManager->softKeyboardDialogShouldBeMaximized())
-        showMaximized();
-}
-
 #include "UISoftKeyboard.moc"
Index: /trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h	(revision 81284)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h	(revision 81285)
@@ -29,4 +29,5 @@
 
 /* GUI includes: */
+#include "QIWithRestorableGeometry.h"
 #include "QIWithRetranslateUI.h"
 
@@ -45,5 +46,9 @@
 class QStackedWidget;
 
-class UISoftKeyboard : public QIWithRetranslateUI<QMainWindow>
+/* Type definitions: */
+typedef QIWithRestorableGeometry<QMainWindow> QMainWindowWithRestorableGeometry;
+typedef QIWithRetranslateUI<QMainWindowWithRestorableGeometry> QMainWindowWithRestorableGeometryAndRetranslateUi;
+
+class UISoftKeyboard : public QMainWindowWithRestorableGeometryAndRetranslateUi
 {
     Q_OBJECT;
@@ -58,4 +63,6 @@
 
     virtual void retranslateUi() /* override */;
+
+    virtual bool shouldBeMaximized() const /* override */;
 
 private slots:
@@ -98,5 +105,4 @@
     void updateStatusBarMessage(const QString &strLayoutName);
     void updateLayoutSelectorList();
-    void setDialogGeometry(const QRect &geometry);
     CKeyboard& keyboard() const;
 
