VirtualBox

Changeset 49177 in vbox


Ignore:
Timestamp:
Oct 18, 2013 11:48:13 AM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI: Guest screen size adjustment mechanism.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r49048 r49177  
    271271}
    272272
     273/** Adjusts guest screen size for each the machine-window we have. */
     274void UIMachineLogic::maybeAdjustGuestScreenSize()
     275{
     276    foreach(UIMachineWindow *pMachineWindow, machineWindows())
     277        pMachineWindow->machineView()->maybeAdjustGuestScreenSize();
     278}
     279
    273280#ifdef Q_WS_MAC
    274281void UIMachineLogic::updateDockIcon()
     
    11201127            pMachineWindow->showNormal();
    11211128
    1122         /* Normalize view's geometry: */
    1123         pMachineWindow->machineView()->normalizeGeometry(true);
     1129        /* Normalize window geometry: */
     1130        pMachineWindow->normalizeGeometry(true);
    11241131    }
    11251132}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r49025 r49177  
    7979    bool isPreventAutoClose() const { return m_fIsPreventAutoClose; }
    8080    void setPreventAutoClose(bool fIsPreventAutoClose) { m_fIsPreventAutoClose = fIsPreventAutoClose; }
     81
     82    /* API: Guest screen size stuff: */
     83    void maybeAdjustGuestScreenSize();
    8184
    8285    /* Wrapper to open Machine settings / Network page: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r49167 r49177  
    275275            /* Normalize machine-window geometry: */
    276276            if (visualStateType() == UIVisualStateType_Normal)
    277                 normalizeGeometry(true /* Adjust Position? */);
     277                machineWindow()->normalizeGeometry(true /* adjust position */);
    278278        }
    279279    }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r47493 r49177  
    7676    virtual void setGuestAutoresizeEnabled(bool /* fEnabled */) {}
    7777
    78     /* Public members: */
    79     virtual void normalizeGeometry(bool /* bAdjustPosition = false */) = 0;
     78    /** Adjusts guest screen size to correspond current machine-window size.
     79      * @note Reimplemented in sub-classes. Base implementation does nothing. */
     80    virtual void maybeAdjustGuestScreenSize() {}
    8081
    8182    /* Framebuffer aspect ratio: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h

    r49013 r49177  
    6161    CSession& session() const;
    6262    CMachine machine() const;
     63
     64    /** Adjusts machine-window size to correspond current guest screen size.
     65      * @param fAdjustPosition determines whether is it necessary to adjust position too.
     66      * @note  Reimplemented in sub-classes. Base implementation does nothing. */
     67    virtual void normalizeGeometry(bool fAdjustPosition) { Q_UNUSED(fAdjustPosition); }
    6368
    6469#ifndef VBOX_WITH_TRANSLUCENT_SEAMLESS
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r49167 r49177  
    206206}
    207207
    208 void UISession::adjustGuestView()
    209 {
    210     foreach(UIMachineWindow *pMachineWindow, machineLogic()->machineWindows())
    211     {
    212         bool fAdjustPosition = false;
    213         UIVisualStateType visualStateType = machineLogic()->visualStateType();
    214 
    215         if (visualStateType == UIVisualStateType_Normal ||
    216             visualStateType == UIVisualStateType_Scale)
    217             fAdjustPosition = true;
    218 
    219         /* Normalize view's geometry: */
    220         pMachineWindow->machineView()->normalizeGeometry(fAdjustPosition);
    221     }
    222 }
    223 
    224208void UISession::powerUp()
    225209{
     
    276260    {
    277261        msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_state_restore_90px.png", 0, 0);
    278         /* If restoring from saved state, guest MachineView
    279            should be notified about host MachineWindow geometry change */
    280         adjustGuestView();
     262        /* After restoring from 'saved' state, guest screen size should be adjusted: */
     263        machineLogic()->maybeAdjustGuestScreenSize();
    281264    }
    282265    else
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r49121 r49177  
    271271    void reinitMenuPool();
    272272    bool preparePowerUp();
    273     void adjustGuestView();
    274273    int countOfVisibleWindows();
    275274
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp

    r49009 r49177  
    6363void UIMachineViewFullscreen::sltAdditionsStateChanged()
    6464{
    65     normalizeGeometry(false);
     65    maybeAdjustGuestScreenSize();
    6666}
    6767
     
    136136}
    137137
    138 void UIMachineViewFullscreen::normalizeGeometry(bool /* fAdjustPosition */)
     138/** Adjusts guest screen size to correspond current <i>working area</i> size. */
     139void UIMachineViewFullscreen::maybeAdjustGuestScreenSize()
    139140{
    140141    /* Check if we should adjust guest to new size: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.h

    r49009 r49177  
    6262    void setGuestAutoresizeEnabled(bool bEnabled);
    6363
    64     /* Private helpers: */
    65     void normalizeGeometry(bool fAdjustPosition);
     64    /* Helpers: Geometry stuff: */
     65    void maybeAdjustGuestScreenSize();
    6666    QRect workingArea() const;
    6767    QSize calculateMaxGuestSize() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp

    r49013 r49177  
    165165    /* Resize to the appropriate size: */
    166166    resize(workingArea.size());
    167     /* Adjust guest if necessary: */
    168     machineView()->normalizeGeometry(false);
     167    /* Adjust guest screen size if necessary: */
     168    machineView()->maybeAdjustGuestScreenSize();
    169169    /* Move mini-toolbar into appropriate place: */
    170170    if (m_pMiniToolBar)
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp

    r49176 r49177  
    4949    , m_bIsGuestAutoresizeEnabled(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->isChecked())
    5050{
    51 
    52     /* Initialization: */
    53     sltAdditionsStateChanged();
     51    /* Resend the last resize hint if there was a fullscreen or
     52     * seamless transition previously. If we were not in graphical
     53     * mode initially after the transition this happens when we switch. */
     54    maybeResendResizeHint();
    5455}
    5556
     
    6566void UIMachineViewNormal::sltAdditionsStateChanged()
    6667{
    67     /* Resend the last resize hint if there was a fullscreen or
    68      * seamless transition previously.  If we were not in graphical
    69      * mode initially after the transition this happens when we
    70      * switch. */
    71     maybeResendResizeHint();
     68    maybeAdjustGuestScreenSize();
    7269}
    7370
     
    194191}
    195192
    196 void UIMachineViewNormal::normalizeGeometry(bool bAdjustPosition)
    197 {
    198 #ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1
    199     QWidget *pTopLevelWidget = window();
    200 
    201     /* Calculate client window offsets: */
    202     QRect frameGeo = pTopLevelWidget->frameGeometry();
    203     QRect geo = pTopLevelWidget->geometry();
    204     int dl = geo.left() - frameGeo.left();
    205     int dt = geo.top() - frameGeo.top();
    206     int dr = frameGeo.right() - geo.right();
    207     int db = frameGeo.bottom() - geo.bottom();
    208 
    209     /* Get the best size w/o scroll bars: */
    210     QSize s = pTopLevelWidget->sizeHint();
    211 
    212     /* Resize the frame to fit the contents: */
    213     s -= pTopLevelWidget->size();
    214     frameGeo.setRight(frameGeo.right() + s.width());
    215     frameGeo.setBottom(frameGeo.bottom() + s.height());
    216 
    217     if (bAdjustPosition)
    218     {
    219         QRegion availableGeo;
    220         QDesktopWidget *dwt = QApplication::desktop();
    221         if (dwt->isVirtualDesktop())
    222             /* Compose complex available region */
    223             for (int i = 0; i < dwt->numScreens(); ++ i)
    224                 availableGeo += dwt->availableGeometry(i);
    225         else
    226             /* Get just a simple available rectangle */
    227             availableGeo = dwt->availableGeometry(pTopLevelWidget->pos());
    228 
    229         frameGeo = VBoxGlobal::normalizeGeometry(frameGeo, availableGeo);
    230     }
    231 
    232 #if 0
    233     /* Center the frame on the desktop: */
    234     frameGeo.moveCenter(availableGeo.center());
    235 #endif
    236 
    237     /* Finally, set the frame geometry */
    238     pTopLevelWidget->setGeometry(frameGeo.left() + dl, frameGeo.top() + dt, frameGeo.width() - dl - dr, frameGeo.height() - dt - db);
    239 
    240 #else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
    241     Q_UNUSED(bAdjustPosition);
    242 #endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
     193/** Adjusts guest screen size to correspond current machine-window size. */
     194void UIMachineViewNormal::maybeAdjustGuestScreenSize()
     195{
     196    /* Check if we should adjust guest to new size: */
     197    QSize centralWidgetSize = machineWindow()->centralWidget()->size();
     198    if ((int)frameBuffer()->width() != centralWidgetSize.width() ||
     199        (int)frameBuffer()->height() != centralWidgetSize.height())
     200        if (m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics())
     201            sltPerformGuestResize(centralWidgetSize);
    243202}
    244203
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h

    r49176 r49177  
    4444    void sltAdditionsStateChanged();
    4545
    46 #ifdef Q_WS_X11
    47     /* Slot to perform synchronized geometry normalization.
    48      * Currently its only required under X11 as of its async nature: */
    49     virtual void sltNormalizeGeometry() { normalizeGeometry(true); }
    50 #endif /* Q_WS_X11 */
    51 
    5246private:
    5347
     
    7266    /* Private helpers: */
    7367    void maybeResendResizeHint();
    74     void normalizeGeometry(bool fAdjustPosition);
     68    void maybeAdjustGuestScreenSize();
    7569    QRect workingArea() const;
    7670    QSize calculateMaxGuestSize() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp

    r47401 r49177  
    457457                m_normalGeometry = QRect(x, y, width(), height());
    458458                setGeometry(m_normalGeometry);
    459                 if (machineView())
    460                     machineView()->normalizeGeometry(false);
     459                /* Normalize to the optimal size: */
     460                normalizeGeometry(false);
    461461            }
    462462            /* Maximize if needed: */
     
    466466        else
    467467        {
    468             /* Normalize view early to the optimal size: */
    469             if (machineView())
    470                 machineView()->normalizeGeometry(true);
     468            /* Normalize to the optimal size: */
     469            normalizeGeometry(true);
    471470            /* Move newly created window to the screen center: */
    472471            m_normalGeometry = geometry();
     
    475474        }
    476475
    477         /* Normalize view to the optimal size: */
    478         if (machineView())
     476        /* Normalize to the optimal size: */
    479477#ifdef Q_WS_X11
    480             QTimer::singleShot(0, machineView(), SLOT(sltNormalizeGeometry()));
    481 #else /* Q_WS_X11 */
    482             machineView()->normalizeGeometry(true);
    483 #endif
     478        QTimer::singleShot(0, this, SLOT(sltNormalizeGeometry()));
     479#else /* !Q_WS_X11 */
     480        normalizeGeometry(true);
     481#endif /* !Q_WS_X11 */
    484482    }
    485483
     
    611609}
    612610
     611/**
     612 * Adjusts machine-window size to correspond current guest screen size.
     613 * @param fAdjustPosition determines whether is it necessary to adjust position too.
     614 */
     615void UIMachineWindowNormal::normalizeGeometry(bool fAdjustPosition)
     616{
     617#ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1
     618    /* Skip if maximized: */
     619    if (isMaximized())
     620        return;
     621
     622    /* Calculate client window offsets: */
     623    QRect frameGeo = frameGeometry();
     624    QRect geo = geometry();
     625    int dl = geo.left() - frameGeo.left();
     626    int dt = geo.top() - frameGeo.top();
     627    int dr = frameGeo.right() - geo.right();
     628    int db = frameGeo.bottom() - geo.bottom();
     629
     630    /* Get the best size w/o scroll-bars: */
     631    QSize s = sizeHint();
     632
     633    /* Resize the frame to fit the contents: */
     634    s -= size();
     635    frameGeo.setRight(frameGeo.right() + s.width());
     636    frameGeo.setBottom(frameGeo.bottom() + s.height());
     637
     638    /* Adjust position if necessary: */
     639    if (fAdjustPosition)
     640    {
     641        QRegion availableGeo;
     642        QDesktopWidget *dwt = QApplication::desktop();
     643        if (dwt->isVirtualDesktop())
     644            /* Compose complex available region: */
     645            for (int i = 0; i < dwt->numScreens(); ++i)
     646                availableGeo += dwt->availableGeometry(i);
     647        else
     648            /* Get just a simple available rectangle */
     649            availableGeo = dwt->availableGeometry(pos());
     650
     651        frameGeo = VBoxGlobal::normalizeGeometry(frameGeo, availableGeo);
     652    }
     653
     654    /* Finally, set the frame geometry: */
     655    setGeometry(frameGeo.left() + dl, frameGeo.top() + dt,
     656                frameGeo.width() - dl - dr, frameGeo.height() - dt - db);
     657
     658#else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
     659    Q_UNUSED(fAdjustPosition);
     660#endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
     661}
     662
    613663void UIMachineWindowNormal::updateAppearanceOf(int iElement)
    614664{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.h

    r46686 r49177  
    4343private slots:
    4444
     45#ifdef Q_WS_X11
     46    /** X11: Performs machine-window async geometry normalization. */
     47    void sltNormalizeGeometry() { normalizeGeometry(true); }
     48#endif /* Q_WS_X11 */
     49
    4550    /* Session event-handlers: */
    4651    void sltMachineStateChanged();
     
    8287    void showInNecessaryMode();
    8388
     89    /* Helper: Machine-window geometry stuff: */
     90    void normalizeGeometry(bool fAdjustPosition);
     91
    8492    /* Update stuff: */
    8593    void updateAppearanceOf(int aElement);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h

    r49176 r49177  
    6565    /* Private helpers: */
    6666    QSize sizeHint() const;
    67     void normalizeGeometry(bool /* fAdjustPosition */) {}
    6867    QRect workingArea() const;
    6968    QSize calculateMaxGuestSize() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp

    r49009 r49177  
    7272void UIMachineViewSeamless::sltAdditionsStateChanged()
    7373{
    74     normalizeGeometry(false);
     74    maybeAdjustGuestScreenSize();
    7575}
    7676
     
    154154}
    155155
    156 void UIMachineViewSeamless::normalizeGeometry(bool /* fAdjustPosition */)
     156/** Adjusts guest screen size to correspond current <i>working area</i> size. */
     157void UIMachineViewSeamless::maybeAdjustGuestScreenSize()
    157158{
    158159    /* Check if we should adjust guest to new size: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.h

    r49009 r49177  
    6464    //void cleanupCommon() {}
    6565
    66     /* Private helpers: */
    67     void normalizeGeometry(bool fAdjustPosition);
     66    /* Helpers: Geometry stuff: */
     67    void maybeAdjustGuestScreenSize();
    6868    QRect workingArea() const;
    6969    QSize calculateMaxGuestSize() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineWindowSeamless.cpp

    r49013 r49177  
    197197    /* Resize to the appropriate size: */
    198198    resize(workingArea.size());
    199     /* Adjust guest if necessary: */
    200     machineView()->normalizeGeometry(false);
     199    /* Adjust guest screen size if necessary: */
     200    machineView()->maybeAdjustGuestScreenSize();
    201201#ifndef Q_WS_MAC
    202202    /* Move mini-toolbar into appropriate place: */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette