VirtualBox

Ignore:
Timestamp:
Mar 4, 2014 4:47:28 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Mac OS X: 7016: Native fullscreen: Reworking blackout fade effects.

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

Legend:

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

    r49506 r50681  
    2323#include "UIMachineLogic.h"
    2424#include "UIMachineWindow.h"
    25 #ifdef Q_WS_MAC
    26 # include <ApplicationServices/ApplicationServices.h>
    27 #endif /* Q_WS_MAC */
    2825
    2926/* Visual state interface: */
     
    4037        , m_pSession(pSession)
    4138        , m_pMachineLogic(0)
    42 #ifdef Q_WS_MAC
    43         , m_fadeToken(kCGDisplayFadeReservationInvalidToken)
    44 #endif /* Q_WS_MAC */
    4539    {
    4640    }
     
    6660
    6761    /* Method to prepare change one visual state to another: */
    68     bool prepareChange(UIVisualStateType previousVisualStateType)
     62    bool prepareChange()
    6963    {
    7064        m_pMachineLogic = UIMachineLogic::create(this, m_pSession, visualStateType());
    71         bool fResult = m_pMachineLogic->checkAvailability();
    72 #ifdef Q_WS_MAC
    73         /* If the new is or the old type was fullscreen we add the blending
    74          * transition between the mode switches.
    75          * TODO: make this more general. */
    76         if (   fResult
    77             && (   visualStateType() == UIVisualStateType_Fullscreen
    78                 || previousVisualStateType == UIVisualStateType_Fullscreen))
    79         {
    80             /* Fade to black */
    81             CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &m_fadeToken);
    82             CGDisplayFade(m_fadeToken, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, true);
    83         }
    84 #else /* Q_WS_MAC */
    85         Q_UNUSED(previousVisualStateType);
    86 #endif /* !Q_WS_MAC */
    87         return fResult;
     65        return m_pMachineLogic->checkAvailability();
    8866    }
    8967
     
    9371        /* Prepare the logic object: */
    9472        m_pMachineLogic->prepare();
    95     }
    96 
    97     /* Method to finish change one visual state to another: */
    98     void finishChange()
    99     {
    100 #ifdef Q_WS_MAC
    101         /* If there is a valid fade token, fade back to normal color in any
    102          * case. */
    103         if (m_fadeToken != kCGDisplayFadeReservationInvalidToken)
    104         {
    105             /* Fade back to the normal gamma */
    106             CGDisplayFade(m_fadeToken, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, false);
    107             CGReleaseDisplayFadeReservation(m_fadeToken);
    108             m_fadeToken = kCGDisplayFadeReservationInvalidToken;
    109         }
    110 #endif /* Q_WS_MAC */
    11173    }
    11274
     
    11779    UISession *m_pSession;
    11880    UIMachineLogic *m_pMachineLogic;
    119 #ifdef Q_WS_MAC
    120     CGDisplayFadeReservationToken m_fadeToken;
    121 #endif /* Q_WS_MAC */
    12281};
    12382
     
    200159    UIVisualState *pNewVisualState = new UIVisualState(this, m_pSession, newVisualStateType);
    201160
    202     /* Get previous visual state type: */
    203     UIVisualStateType previousVisualStateType = m_pVisualState ? m_pVisualState->visualStateType() : UIVisualStateType_Normal;
    204 
    205161    /* First we have to check if the selected mode is available at all.
    206162     * Only then we delete the old mode and switch to the new mode. */
    207     if (pNewVisualState->prepareChange(previousVisualStateType))
     163    if (pNewVisualState->prepareChange())
    208164    {
    209165        /* Delete previous state: */
     
    213169        m_pVisualState = pNewVisualState;
    214170        m_pVisualState->change();
    215 
    216         /* Finish any setup: */
    217         m_pVisualState->finishChange();
    218171    }
    219172    else
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp

    r50679 r50681  
    3636UIMachineLogicFullscreen::UIMachineLogicFullscreen(QObject *pParent, UISession *pSession)
    3737    : UIMachineLogic(pParent, pSession, UIVisualStateType_Fullscreen)
     38#ifdef Q_WS_MAC
     39    , m_fadeToken(kCGDisplayFadeReservationInvalidToken)
     40#endif /* Q_WS_MAC */
    3841{
    3942    /* Create multiscreen layout: */
     
    99102
    100103#ifdef RT_OS_DARWIN
    101 void UIMachineLogicFullscreen::sltHandleNativeFullscreenDidEnter()
     104void UIMachineLogicFullscreen::sltHandleNativeFullscreenWillEnter()
    102105{
    103106    /* Make sure this method is only used for ML and next: */
     
    108111    AssertReturnVoid(pMachineWindow);
    109112
     113    /* Fade to black: */
     114    fadeToBlack();
     115}
     116
     117void UIMachineLogicFullscreen::sltHandleNativeFullscreenDidEnter()
     118{
     119    /* Make sure this method is only used for ML and next: */
     120    AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
     121
     122    /* Get sender machine-window: */
     123    UIMachineWindow *pMachineWindow = qobject_cast<UIMachineWindow*>(sender());
     124    AssertReturnVoid(pMachineWindow);
     125
    110126    /* Add machine-window to corresponding set: */
    111127    m_fullscreenMachineWindows.insert(pMachineWindow);
    112128    AssertReturnVoid(m_fullscreenMachineWindows.contains(pMachineWindow));
     129
     130    /* Fade to normal if necessary: */
     131    QSet<UIMachineWindow*> visibleMachineWindows;
     132    foreach (UIMachineWindow *pMachineWindow, machineWindows())
     133        if (uisession()->isScreenVisible(pMachineWindow->screenId()))
     134            visibleMachineWindows << pMachineWindow;
     135    if (   !darwinScreensHaveSeparateSpaces()
     136        || m_fullscreenMachineWindows == visibleMachineWindows)
     137        fadeToNormal();
     138}
     139
     140void UIMachineLogicFullscreen::sltHandleNativeFullscreenWillExit()
     141{
     142    /* Make sure this method is only used for ML and next: */
     143    AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
     144
     145    /* Get sender machine-window: */
     146    UIMachineWindow *pMachineWindow = qobject_cast<UIMachineWindow*>(sender());
     147    AssertReturnVoid(pMachineWindow);
     148
     149    /* Fade to black: */
     150    fadeToBlack();
    113151}
    114152
     
    164202            uisession()->setRequestedVisualState(UIVisualStateType_Invalid);
    165203            uisession()->changeVisualState(type);
     204
     205            /* Fade to normal: */
     206            fadeToNormal();
    166207        }
    167208    }
     
    360401     * This is necessary for Qt versions > 4.3.3: */
    361402    darwinSetFrontMostProcess();
     403
     404    /* Fade to black: */
     405    fadeToBlack();
    362406#endif /* Q_WS_MAC */
    363407
     
    376420    /* Activate 'presentation mode': */
    377421    setPresentationModeEnabled(true);
     422
     423    /* For Lion and previous fade to normal: */
     424    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     425        fadeToNormal();
     426
    378427    /* For ML and next: */
    379428    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
     
    388437                    pMachineWindow, SLOT(sltExitNativeFullscreen(UIMachineWindow*)));
    389438            /* Window => logic signals: */
     439            connect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenWillEnter()),
     440                    this, SLOT(sltHandleNativeFullscreenWillEnter()));
    390441            connect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenDidEnter()),
    391442                    this, SLOT(sltHandleNativeFullscreenDidEnter()));
     443            connect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenWillExit()),
     444                    this, SLOT(sltHandleNativeFullscreenWillExit()));
    392445            connect(pMachineWindow, SIGNAL(sigNotifyAboutNativeFullscreenDidExit()),
    393446                    this, SLOT(sltHandleNativeFullscreenDidExit()));
     
    418471        return;
    419472
     473#ifdef Q_WS_MAC
     474    /* For Lion and previous fade to black: */
     475    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
     476        fadeToBlack();
     477#endif/* Q_WS_MAC */
     478
    420479    /* Mark machine-window(s) destroyed: */
    421480    setMachineWindowsCreated(false);
     
    428487    /* Deactivate 'presentation mode': */
    429488    setPresentationModeEnabled(false);
     489
     490    /* Fade to normal: */
     491    fadeToNormal();
    430492#endif/* Q_WS_MAC */
    431493}
     
    499561}
    500562
     563void UIMachineLogicFullscreen::fadeToBlack()
     564{
     565    /* Make sure fade-token invalid: */
     566    if (m_fadeToken != kCGDisplayFadeReservationInvalidToken)
     567        return;
     568
     569    /* Acquire fade-token: */
     570    CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &m_fadeToken);
     571    CGDisplayFade(m_fadeToken, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, true);
     572}
     573
     574void UIMachineLogicFullscreen::fadeToNormal()
     575{
     576    /* Make sure fade-token valid: */
     577    if (m_fadeToken == kCGDisplayFadeReservationInvalidToken)
     578        return;
     579
     580    /* Release fade-token: */
     581    CGDisplayFade(m_fadeToken, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, false);
     582    CGReleaseDisplayFadeReservation(m_fadeToken);
     583    m_fadeToken = kCGDisplayFadeReservationInvalidToken;
     584}
     585
    501586void UIMachineLogicFullscreen::revalidateFullscreenWindow(UIMachineWindow *pMachineWindow)
    502587{
     
    534619                LogRel(("UIMachineLogicFullscreen::revalidateFullscreenWindow: "
    535620                        "Ask machine-window #%d to enter fullscreen.\n", (int)uScreenID));
     621
     622                /* Fade to black: */
     623                fadeToBlack();
    536624
    537625                /* Update 'presentation mode': */
     
    569657                        "Ask machine-window #%d to exit fullscreen.\n", (int)uScreenID));
    570658
     659                /* Fade to black: */
     660                fadeToBlack();
     661
    571662                /* Mark window as invalidated: */
    572663                m_invalidFullscreenMachineWindows << pMachineWindow;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h

    r50679 r50681  
    1818#define ___UIMachineLogicFullscreen_h___
    1919
    20 /* Local includes: */
     20/* GUI includes: */
    2121#include "UIMachineLogic.h"
     22
     23/* Other includes: */
     24#ifdef Q_WS_MAC
     25# include <ApplicationServices/ApplicationServices.h>
     26#endif /* Q_WS_MAC */
    2227
    2328/* Forward declarations: */
     
    5459
    5560#ifdef RT_OS_DARWIN
    56     /** Mac OS X: Marks sender() machine-window as 'fullscreen' one. */
     61    /** Mac OS X: Handles native notification about 'fullscreen' will be entered. */
     62    void sltHandleNativeFullscreenWillEnter();
     63    /** Mac OS X: Handles native notification about 'fullscreen' entered. */
    5764    void sltHandleNativeFullscreenDidEnter();
    58     /** Mac OS X: Marks sender() machine-window as 'non-fullscreen' one,
    59       * changes visual-state to requested if there is/are no more fullscreen window(s). */
     65    /** Mac OS X: Handles native notification about 'fullscreen' will be exited. */
     66    void sltHandleNativeFullscreenWillExit();
     67    /** Mac OS X: Handles native notification about 'fullscreen' exited. */
    6068    void sltHandleNativeFullscreenDidExit();
    6169
     
    104112    void setPresentationModeEnabled(bool fEnabled);
    105113
     114    /** Mac OS X: Performs fade to black if possible. */
     115    void fadeToBlack();
     116    /** Mac OS X: Performs fade to normal if possible. */
     117    void fadeToNormal();
     118
    106119    /** Mac OS X: Revalidates 'fullscreen' mode for @a pMachineWindow. */
    107120    void revalidateFullscreenWindow(UIMachineWindow *pMachineWindow);
     
    114127
    115128#ifdef Q_WS_MAC
     129    /** Mac OS X: Fade token. */
     130    CGDisplayFadeReservationToken m_fadeToken;
     131
    116132    /** Mac OS X: Contains machine-window(s) marked as 'fullscreen'. */
    117133    QSet<UIMachineWindow*> m_fullscreenMachineWindows;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp

    r50679 r50681  
    6060            strNativeNotificationName.toAscii().constData()));
    6161
     62    /* Handle 'NSWindowWillEnterFullScreenNotification' notification: */
     63    if (strNativeNotificationName == "NSWindowWillEnterFullScreenNotification")
     64    {
     65        LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
     66                "Native fullscreen mode about to enter, notifying listener...\n"));
     67        emit sigNotifyAboutNativeFullscreenWillEnter();
     68    }
    6269    /* Handle 'NSWindowDidEnterFullScreenNotification' notification: */
    63     if (strNativeNotificationName == "NSWindowDidEnterFullScreenNotification")
     70    else if (strNativeNotificationName == "NSWindowDidEnterFullScreenNotification")
    6471    {
    6572        /* Mark window transition complete: */
     
    6875                "Native fullscreen mode entered, notifying listener...\n"));
    6976        emit sigNotifyAboutNativeFullscreenDidEnter();
     77    }
     78    /* Handle 'NSWindowWillExitFullScreenNotification' notification: */
     79    else if (strNativeNotificationName == "NSWindowWillExitFullScreenNotification")
     80    {
     81        LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
     82                "Native fullscreen mode about to exit, notifying listener...\n"));
     83        emit sigNotifyAboutNativeFullscreenWillExit();
    7084    }
    7185    /* Handle 'NSWindowDidExitFullScreenNotification' notification: */
     
    189203            darwinEnableTransienceSupport(this);
    190204        /* Register to native fullscreen notifications: */
     205        UICocoaApplication::instance()->registerToNativeNotification("NSWindowWillEnterFullScreenNotification", this,
     206                                                                     UIMachineWindow::handleNativeNotification);
    191207        UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidEnterFullScreenNotification", this,
     208                                                                     UIMachineWindow::handleNativeNotification);
     209        UICocoaApplication::instance()->registerToNativeNotification("NSWindowWillExitFullScreenNotification", this,
    192210                                                                     UIMachineWindow::handleNativeNotification);
    193211        UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidExitFullScreenNotification", this,
     
    252270    {
    253271        /* Unregister from native fullscreen notifications: */
     272        UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowWillEnterFullScreenNotification", this);
    254273        UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidEnterFullScreenNotification", this);
     274        UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowWillExitFullScreenNotification", this);
    255275        UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidExitFullScreenNotification", this);
    256276    }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.h

    r50679 r50681  
    3333#ifdef RT_OS_DARWIN
    3434signals:
     35    /** Mac OS X: Notifies listener about native 'fullscreen' will be entered. */
     36    void sigNotifyAboutNativeFullscreenWillEnter();
    3537    /** Mac OS X: Notifies listener about native 'fullscreen' entered. */
    3638    void sigNotifyAboutNativeFullscreenDidEnter();
     39    /** Mac OS X: Notifies listener about native 'fullscreen' will be exited. */
     40    void sigNotifyAboutNativeFullscreenWillExit();
    3741    /** Mac OS X: Notifies listener about native 'fullscreen' exited. */
    3842    void sigNotifyAboutNativeFullscreenDidExit();
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