VirtualBox

Ignore:
Timestamp:
Feb 18, 2014 4:23:28 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92340
Message:

FE/Qt: Mac OS X: 7016: Runtime UI: Native fullscreen feature implementation: Initial commit.

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

Legend:

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

    r50493 r50498  
    506506    {
    507507        case UIVisualStateType_Normal: return Qt::Window;
     508#ifdef Q_WS_MAC
     509        /* We want normal window for native fullscreen mode on ML and next: */
     510        case UIVisualStateType_Fullscreen: return vboxGlobal().osRelease() > MacOSXRelease_Lion ? Qt::Window : Qt::FramelessWindowHint;
     511#else /* !Q_WS_MAC */
    508512        case UIVisualStateType_Fullscreen: return Qt::FramelessWindowHint;
     513#endif /* !Q_WS_MAC */
    509514        case UIVisualStateType_Seamless: return Qt::FramelessWindowHint;
    510515        case UIVisualStateType_Scale: return Qt::Window;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp

    r50490 r50498  
    9797}
    9898
     99#ifdef RT_OS_DARWIN
     100void UIMachineLogicFullscreen::sltHandleNativeFullscreenDidEnter()
     101{
     102    /* Make sure this method is only used for ML and next: */
     103    AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
     104
     105    /* Get sender machine-window: */
     106    UIMachineWindow *pMachineWindow = qobject_cast<UIMachineWindow*>(sender());
     107    AssertReturnVoid(pMachineWindow);
     108
     109    /* Add machine-window to corresponding set: */
     110    m_fullscreenMachineWindows.insert(pMachineWindow);
     111    AssertReturnVoid(m_fullscreenMachineWindows.contains(pMachineWindow));
     112}
     113
     114void UIMachineLogicFullscreen::sltHandleNativeFullscreenDidExit()
     115{
     116    /* Make sure this method is only used for ML and next: */
     117    AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
     118
     119    /* Get sender machine-window: */
     120    UIMachineWindow *pMachineWindow = qobject_cast<UIMachineWindow*>(sender());
     121    AssertReturnVoid(pMachineWindow);
     122
     123    /* Remove machine-window from corresponding set: */
     124    bool fResult = m_fullscreenMachineWindows.remove(pMachineWindow);
     125    AssertReturnVoid(fResult && !m_fullscreenMachineWindows.contains(pMachineWindow));
     126    Q_UNUSED(fResult);
     127
     128    /* Exit fullscreen mode if there is/are no fullscreen window(s) left: */
     129    if (m_fullscreenMachineWindows.isEmpty())
     130    {
     131        /* Change visual-state to requested: */
     132        LogRel(("UIMachineLogicFullscreen::sltHandleNativeFullscreenDidExit: "
     133                "Machine-window(s) exited fullscreen, changing visual-state to requested...\n"));
     134        UIVisualStateType type = uisession()->requestedVisualState();
     135        if (type == UIVisualStateType_Invalid)
     136            type = UIVisualStateType_Normal;
     137        uisession()->setRequestedVisualState(UIVisualStateType_Invalid);
     138        uisession()->changeVisualState(type);
     139    }
     140}
     141
     142void UIMachineLogicFullscreen::sltChangeVisualStateToNormal()
     143{
     144    /* Base-class handling for Lion and previous: */
     145    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     146        UIMachineLogic::sltChangeVisualStateToNormal();
     147    /* Special handling for ML and next: */
     148    else
     149    {
     150        /* Request 'normal' (window) visual-state: */
     151        uisession()->setRequestedVisualState(UIVisualStateType_Normal);
     152        /* Toggle native fullscreen mode for each window: */
     153        foreach (UIMachineWindow *pMachineWindow, machineWindows())
     154            darwinToggleFullscreenMode(pMachineWindow);
     155    }
     156}
     157
     158void UIMachineLogicFullscreen::sltChangeVisualStateToSeamless()
     159{
     160    /* Base-class handling for Lion and previous: */
     161    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     162        UIMachineLogic::sltChangeVisualStateToSeamless();
     163    /* Special handling for ML and next: */
     164    else
     165    {
     166        /* Request 'seamless' visual-state: */
     167        uisession()->setRequestedVisualState(UIVisualStateType_Seamless);
     168        /* Toggle native fullscreen mode for each window: */
     169        foreach (UIMachineWindow *pMachineWindow, machineWindows())
     170            darwinToggleFullscreenMode(pMachineWindow);
     171    }
     172}
     173
     174void UIMachineLogicFullscreen::sltChangeVisualStateToScale()
     175{
     176    /* Base-class handling for Lion and previous: */
     177    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     178        UIMachineLogic::sltChangeVisualStateToScale();
     179    /* Special handling for ML and next: */
     180    else
     181    {
     182        /* Request 'scale' visual-state: */
     183        uisession()->setRequestedVisualState(UIVisualStateType_Scale);
     184        /* Toggle native fullscreen mode for each window: */
     185        foreach (UIMachineWindow *pMachineWindow, machineWindows())
     186            darwinToggleFullscreenMode(pMachineWindow);
     187    }
     188}
     189#endif /* RT_OS_DARWIN */
     190
    99191void UIMachineLogicFullscreen::sltMachineStateChanged()
    100192{
     
    191283void UIMachineLogicFullscreen::prepareOtherConnections()
    192284{
    193     /* Presentation mode connection: */
    194     connect(gEDataEvents, SIGNAL(sigPresentationModeChange(bool)),
    195             this, SLOT(sltChangePresentationMode(bool)));
     285    /* Make sure 'presentation mode' is updated for Lion and previous: */
     286    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     287        connect(gEDataEvents, SIGNAL(sigPresentationModeChange(bool)),
     288                this, SLOT(sltChangePresentationMode(bool)));
    196289}
    197290#endif /* Q_WS_MAC */
     
    222315
    223316#ifdef Q_WS_MAC
    224     /* If the user change the screen, we have to decide again if the
    225      * presentation mode should be changed. */
    226     connect(m_pScreenLayout, SIGNAL(sigScreenLayoutChanged()),
    227             this, SLOT(sltScreenLayoutChanged()));
    228     /* Note: Presentation mode has to be set *after* the windows are created. */
    229     setPresentationModeEnabled(true);
     317    /* Make sure 'presentation mode' is enabled/updated for Lion and previous: */
     318    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     319    {
     320        connect(m_pScreenLayout, SIGNAL(sigScreenLayoutChanged()),
     321                this, SLOT(sltScreenLayoutChanged()));
     322        setPresentationModeEnabled(true);
     323    }
     324#endif /* Q_WS_MAC */
     325
     326#ifdef Q_WS_MAC
     327    /* Keep sync for machine-logic/window(s) in ML and next: */
     328    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
     329    {
     330        foreach (UIMachineWindow *pMachineWindow, machineWindows())
     331        {
     332            connect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenDidEnter()),
     333                    this, SLOT(sltHandleNativeFullscreenDidEnter()));
     334            connect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenDidExit()),
     335                    this, SLOT(sltHandleNativeFullscreenDidExit()));
     336        }
     337    }
    230338#endif /* Q_WS_MAC */
    231339
     
    253361    setMachineWindowsCreated(false);
    254362
     363#ifdef Q_WS_MAC
     364    /* Leave sync for machine-logic/window(s) in ML and next: */
     365    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
     366    {
     367        foreach (UIMachineWindow *pMachineWindow, machineWindows())
     368        {
     369            disconnect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenDidEnter()),
     370                       this, SLOT(sltHandleNativeFullscreenDidEnter()));
     371            disconnect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenDidExit()),
     372                       this, SLOT(sltHandleNativeFullscreenDidExit()));
     373        }
     374    }
     375#endif/* Q_WS_MAC */
     376
    255377    /* Cleanup machine-window(s): */
    256378    foreach (UIMachineWindow *pMachineWindow, machineWindows())
     
    258380
    259381#ifdef Q_WS_MAC
    260     setPresentationModeEnabled(false);
     382    /* Make sure 'presentation mode' is disabled for Lion and previous: */
     383    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     384        setPresentationModeEnabled(false);
    261385#endif/* Q_WS_MAC */
    262386}
     
    298422void UIMachineLogicFullscreen::setPresentationModeEnabled(bool fEnabled)
    299423{
     424    /* Make sure this method is only used for Lion and previous: */
     425    AssertReturnVoid(vboxGlobal().osRelease() <= MacOSXRelease_Lion);
     426
    300427    /* First check if we are on a screen which contains the Dock or the
    301428     * Menubar (which hasn't to be the same), only than the
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h

    r49505 r50498  
    4545private slots:
    4646
     47#ifdef RT_OS_DARWIN
     48    /** Mac OS X: Marks sender() machine-window as 'fullscreen' one. */
     49    void sltHandleNativeFullscreenDidEnter();
     50    /** Mac OS X: Marks sender() machine-window as 'non-fullscreen' one,
     51      * changes visual-state to requested if there is/are no more fullscreen window(s). */
     52    void sltHandleNativeFullscreenDidExit();
     53
     54    /** Mac OS X: Requests visual-state change from 'fullscreen' to 'normal' (window). */
     55    void sltChangeVisualStateToNormal();
     56    /** Mac OS X: Requests visual-state change from 'fullscreen' to 'seamless'. */
     57    void sltChangeVisualStateToSeamless();
     58    /** Mac OS X: Requests visual-state change from 'fullscreen' to 'scale'. */
     59    void sltChangeVisualStateToScale();
     60#endif /* RT_OS_DARWIN */
     61
    4762    /* Handler: Console callback stuff: */
    4863    void sltMachineStateChanged();
     
    8297    UIMultiScreenLayout *m_pScreenLayout;
    8398
     99#ifdef Q_WS_MAC
     100    /** Mac OS X: Contains machine-window(s) marked as 'fullscreen'. */
     101    QSet<UIMachineWindow*> m_fullscreenMachineWindows;
     102#endif /* Q_WS_MAC */
     103
    84104    /* Friend classes: */
    85105    friend class UIMachineLogic;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp

    r49758 r50498  
    3232#include "UIMachineDefs.h"
    3333#include "UIMiniToolBar.h"
     34#ifdef Q_WS_MAC
     35# include "VBoxUtils-darwin.h"
     36# include "UICocoaApplication.h"
     37#endif /* Q_WS_MAC */
    3438
    3539/* COM includes: */
     
    4246{
    4347}
     48
     49#ifdef Q_WS_MAC
     50void UIMachineWindowFullscreen::handleNativeNotification(const QString &strNativeNotificationName)
     51{
     52    /* Make sure this method is only used for ML and next: */
     53    AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
     54
     55    /* Handle arrived notification: */
     56    LogRel(("UIMachineWindowFullscreen::handleNativeNotification: Notification '%s' received.\n",
     57            strNativeNotificationName.toAscii().constData()));
     58    /* Handle 'NSWindowDidEnterFullScreenNotification' notification: */
     59    if (strNativeNotificationName == "NSWindowDidEnterFullScreenNotification")
     60    {
     61        LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
     62                "Native fullscreen mode entered, notifying listener...\n"));
     63        emit sigNotifyAboutNativeFullscreenDidEnter();
     64    }
     65    /* Handle 'NSWindowDidExitFullScreenNotification' notification: */
     66    else if (strNativeNotificationName == "NSWindowDidExitFullScreenNotification")
     67    {
     68        LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
     69                "Native fullscreen mode exited, notifying listener...\n"));
     70        emit sigNotifyAboutNativeFullscreenDidExit();
     71    }
     72}
     73#endif /* Q_WS_MAC */
     74
     75#ifdef RT_OS_DARWIN
     76void UIMachineWindowFullscreen::sltToggleNativeFullscreenMode()
     77{
     78    /* Make sure this method is only used for ML and next: */
     79    AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
     80
     81    /* Toggle native fullscreen mode: */
     82    darwinToggleFullscreenMode(this);
     83}
     84#endif /* RT_OS_DARWIN */
    4485
    4586void UIMachineWindowFullscreen::sltMachineStateChanged()
     
    88129    /* Prepare mini-toolbar: */
    89130    prepareMiniToolbar();
     131
     132#ifdef Q_WS_MAC
     133    /* Native fullscreen stuff on ML and next: */
     134    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
     135    {
     136        /* Enable native fullscreen support: */
     137        darwinEnableFullscreenSupport(this);
     138        /* Register to native fullscreen notifications: */
     139        UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidEnterFullScreenNotification", this,
     140                                                                     UIMachineWindow::handleNativeNotification);
     141        UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidExitFullScreenNotification", this,
     142                                                                     UIMachineWindow::handleNativeNotification);
     143        /* Asynchronously toggle native fullscreen mode: */
     144        QTimer::singleShot(0, this, SLOT(sltToggleNativeFullscreenMode()));
     145    }
     146#endif /* Q_WS_MAC */
    90147}
    91148
     
    140197void UIMachineWindowFullscreen::cleanupVisualState()
    141198{
     199#ifdef Q_WS_MAC
     200    /* Native fullscreen stuff on ML and next: */
     201    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
     202    {
     203        /* Unregister from native fullscreen notifications: */
     204        UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidEnterFullScreenNotification", this);
     205        UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidExitFullScreenNotification", this);
     206    }
     207#endif /* Q_WS_MAC */
     208
    142209    /* Cleanup mini-toolbar: */
    143210    cleanupMiniToolbar();
     
    199266#endif /* Q_WS_WIN */
    200267
     268#ifdef Q_WS_MAC
     269                /* ML and next using native stuff, so we can call for simple show(): */
     270                if (vboxGlobal().osRelease() > MacOSXRelease_Lion) show();
     271                /* Lion and previous still using Qt one, call for showFullScreen(): */
     272                else showFullScreen();
     273#else /* !Q_WS_MAC */
    201274                /* Show in fullscreen mode: */
    202275                showFullScreen();
     276#endif /* !Q_WS_MAC */
    203277
    204278                /* Make sure the window is placed on valid screen again
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.h

    r46244 r50498  
    3131    Q_OBJECT;
    3232
     33#ifdef RT_OS_DARWIN
     34signals:
     35    /** Mac OS X: Notifies listener about native fullscreen entering. */
     36    void sigNotifyAboutNativeFullscreenDidEnter();
     37    /** Mac OS X: Notifies listener about native fullscreen exiting. */
     38    void sigNotifyAboutNativeFullscreenDidExit();
     39#endif /* RT_OS_DARWIN */
     40
    3341protected:
    3442
     
    3644    UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId);
    3745
     46#ifdef Q_WS_MAC
     47    /** Mac OS X: Handles native notifications @a strNativeNotificationName for fullscreen window. */
     48    void handleNativeNotification(const QString &strNativeNotificationName);
     49#endif /* Q_WS_MAC */
     50
    3851private slots:
     52
     53#ifdef RT_OS_DARWIN
     54    /** Mac OS X: Toggles native fullscreen mode. */
     55    void sltToggleNativeFullscreenMode();
     56#endif /* RT_OS_DARWIN */
    3957
    4058    /* Session event-handlers: */
Note: See TracChangeset for help on using the changeset viewer.

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