void UIMachineWindowFullscreen::prepareVisualState()
{
    /* Call to base-class: */
    UIMachineWindow::prepareVisualState();

    /* The background has to go black: */
    QPalette palette(centralWidget()->palette());
    palette.setColor(centralWidget()->backgroundRole(), Qt::black);
    centralWidget()->setPalette(palette);
    centralWidget()->setAutoFillBackground(true);
    setAutoFillBackground(true);

#ifndef Q_WS_MAC
    /* Prepare mini-toolbar: */
    prepareMiniToolbar();
#endif /* !Q_WS_MAC */

#ifdef Q_WS_MAC
    /* Native fullscreen stuff on ML and next: */
    if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
    {
        /* Make sure this window has fullscreen logic: */
        UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
        AssertPtrReturnVoid(pFullscreenLogic);
        /* Enable fullscreen support for every screen which requires it: */
        if (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
            darwinEnableFullscreenSupport(this);
        /* Enable transience support for other screens: */
        else
            darwinEnableTransienceSupport(this);
        /* Register to native fullscreen notifications: */
        UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowWillEnterFullScreenNotification", this,
                                                                       UIMachineWindow::handleNativeNotification);
        UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidEnterFullScreenNotification", this,
                                                                       UIMachineWindow::handleNativeNotification);
        UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowWillExitFullScreenNotification", this,
                                                                       UIMachineWindow::handleNativeNotification);
        UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidExitFullScreenNotification", this,
                                                                       UIMachineWindow::handleNativeNotification);
        UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidFailToEnterFullScreenNotification", this,
                                                                       UIMachineWindow::handleNativeNotification);
    }
#endif /* Q_WS_MAC */
}
void UIMachineWindowFullscreen::sltExitNativeFullscreen(UIMachineWindow *pMachineWindow)
{
    /* Make sure this slot is called only under ML and next: */
    AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);

    /* Make sure it is NULL or 'this' window passed: */
    if (pMachineWindow && pMachineWindow != this)
        return;

    /* Make sure this window has fullscreen logic: */
    UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
    AssertPtrReturnVoid(pFullscreenLogic);

    /* Mark window 'transitioned from fullscreen': */
    m_fIsInFullscreenTransition = true;

    /* Exit native fullscreen mode if necessary: */
    if (   (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
        && darwinIsInFullscreenMode(this))
        darwinToggleFullscreenMode(this);
}
void UIMachineWindowFullscreen::showInNecessaryMode()
{
    /* Make sure window has fullscreen logic: */
    UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
    AssertPtrReturnVoid(pFullscreenLogic);

    /* Make sure window should be shown and mapped to some host-screen: */
    if (!uisession()->isScreenVisible(m_uScreenId) ||
        !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
    {
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
        /* If there is a mini-toolbar: */
        if (m_pMiniToolBar)
        {
            /* Hide mini-toolbar: */
            m_pMiniToolBar->hide();
        }
#endif /* Q_WS_WIN || Q_WS_X11 */

        /* Hide window: */
        hide();
    }
    else
    {
        /* Ignore if window minimized: */
        if (isMinimized())
            return;

#ifdef Q_WS_X11
        /* If WM doesn't support native stuff, we need to call for placeOnScreen(): */
        const bool fSupportsNativeFullScreen = VBoxGlobal::supportsFullScreenMonitorsProtocolX11() &&
                                               !gEDataManager->legacyFullscreenModeRequested();
        if (!fSupportsNativeFullScreen)
        {
            /* Make sure window have appropriate geometry: */
            placeOnScreen();
        }
#else /* !Q_WS_X11 */
        /* Make sure window have appropriate geometry: */
        placeOnScreen();
#endif /* !Q_WS_X11 */

#if defined(Q_WS_MAC)
        /* ML and next using native stuff, so we can call for simple show(),
         * Lion and previous using Qt stuff, so we should call for showFullScreen(): */
        const bool fSupportsNativeFullScreen = vboxGlobal().osRelease() > MacOSXRelease_Lion;
        if (fSupportsNativeFullScreen)
        {
            /* Show window in normal mode: */
            show();
        }
        else
        {
            /* Show window in fullscreen mode: */
            showFullScreen();
        }
#elif defined(Q_WS_WIN) || defined(Q_WS_X11)
        /* Show window in fullscreen mode: */
        showFullScreen();

        /* If there is a mini-toolbar: */
        if (m_pMiniToolBar)
        {
            /* Show mini-toolbar in full-screen mode: */
            m_pMiniToolBar->showFullScreen();
        }
#endif /* Q_WS_WIN || Q_WS_X11 */

#ifdef Q_WS_X11
        /* If WM supports native stuff, we need to map window to corresponding host-screen. */
        if (fSupportsNativeFullScreen)
        {
            /* Tell recent window managers which host-screen this window should be mapped to: */
            VBoxGlobal::setFullScreenMonitorX11(this, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));

            /* If there is a mini-toolbar: */
            if (m_pMiniToolBar)
            {
                /* Tell recent window managers which host-screen this mini-toolbar should be mapped to: */
                VBoxGlobal::setFullScreenMonitorX11(m_pMiniToolBar, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));
            }
        }
#endif /* Q_WS_X11 */

        /* Adjust machine-view size if necessary: */
        adjustMachineViewSize();

        /* Make sure machine-view have focus: */
        m_pMachineView->setFocus();
    }
}
コード例 #4
0
void UIMachineWindowFullscreen::showInNecessaryMode()
{
    /* Make sure window has fullscreen logic: */
    UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
    AssertPtrReturnVoid(pFullscreenLogic);

#if defined(VBOX_WS_MAC)

    /* If window shouldn't be shown or mapped to some host-screen: */
    if (!uisession()->isScreenVisible(m_uScreenId) ||
        !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
    {
        /* Hide window: */
        hide();
    }
    /* If window should be shown and mapped to some host-screen: */
    else
    {
        /* Make sure window have appropriate geometry: */
        placeOnScreen();

        /* Simple show() for ML and next, showFullScreen() otherwise: */
        if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
            show();
        else
            showFullScreen();

        /* Adjust machine-view size if necessary: */
        adjustMachineViewSize();

        /* Make sure machine-view have focus: */
        m_pMachineView->setFocus();
    }

#elif defined(VBOX_WS_WIN)

    /* If window shouldn't be shown or mapped to some host-screen: */
    if (!uisession()->isScreenVisible(m_uScreenId) ||
        !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
    {
        /* Remember whether the window was minimized: */
        if (isMinimized())
            m_fWasMinimized = true;

        /* Hide window and reset it's state to NONE: */
        setWindowState(Qt::WindowNoState);
        hide();
    }
    /* If window should be shown and mapped to some host-screen: */
    else
    {
        /* Check whether window was minimized: */
        const bool fWasMinimized = isMinimized() && isVisible();
        /* And reset it's state in such case before exposing: */
        if (fWasMinimized)
            setWindowState(Qt::WindowNoState);

        /* Make sure window have appropriate geometry: */
        placeOnScreen();

        /* Show window: */
        showFullScreen();

        /* Restore minimized state if necessary: */
        if (m_fWasMinimized || fWasMinimized)
        {
            m_fWasMinimized = false;
            QMetaObject::invokeMethod(this, "showMinimized", Qt::QueuedConnection);
        }

        /* Adjust machine-view size if necessary: */
        adjustMachineViewSize();

        /* Make sure machine-view have focus: */
        m_pMachineView->setFocus();
    }

#elif defined(VBOX_WS_X11)

    /* If window shouldn't be shown or mapped to some host-screen: */
    if (!uisession()->isScreenVisible(m_uScreenId) ||
        !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
    {
        /* Remember whether the window was minimized: */
        if (isMinimized())
            m_fWasMinimized = true;

        /* Hide window and reset it's state to NONE: */
        setWindowState(Qt::WindowNoState);
        hide();
    }
    /* If window should be shown and mapped to some host-screen: */
    else
    {
        /* Check whether window was minimized: */
        const bool fWasMinimized = isMinimized() && isVisible();
        /* And reset it's state in such case before exposing: */
        if (fWasMinimized)
            setWindowState(Qt::WindowNoState);

        /* Show window: */
        showFullScreen();

        /* Make sure window have appropriate geometry: */
        placeOnScreen();

        /* Restore full-screen state after placeOnScreen() call: */
        setWindowState(Qt::WindowFullScreen);

        /* Restore minimized state if necessary: */
        if (m_fWasMinimized || fWasMinimized)
        {
            m_fWasMinimized = false;
            QMetaObject::invokeMethod(this, "showMinimized", Qt::QueuedConnection);
        }

        /* Adjust machine-view size if necessary: */
        adjustMachineViewSize();

        /* Make sure machine-view have focus: */
        m_pMachineView->setFocus();
    }

#else

# warning "port me"

#endif
}
コード例 #5
0
void UIMachineWindowFullscreen::placeOnScreen()
{
    /* Make sure this window has fullscreen logic: */
    UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
    AssertPtrReturnVoid(pFullscreenLogic);

    /* Get corresponding host-screen: */
    const int iHostScreen = pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId);
    /* And corresponding working area: */
    const QRect workingArea = vboxGlobal().screenGeometry(iHostScreen);
    Q_UNUSED(workingArea);

#if defined(VBOX_WS_MAC)

    /* Move window to the appropriate position: */
    move(workingArea.topLeft());

    /* Resize window to the appropriate size on Lion and previous: */
    if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
        resize(workingArea.size());
    /* Resize window to the appropriate size on ML and next if it's screen has no own user-space: */
    else if (!pFullscreenLogic->screensHaveSeparateSpaces() && m_uScreenId != 0)
        resize(workingArea.size());
    else
    {
        /* Load normal geometry first of all: */
        QRect geo = gEDataManager->machineWindowGeometry(UIVisualStateType_Normal, m_uScreenId, vboxGlobal().managedVMUuid());
        /* If normal geometry is null => use frame-buffer size: */
        if (geo.isNull())
        {
            const UIFrameBuffer *pFrameBuffer = uisession()->frameBuffer(m_uScreenId);
            geo = QRect(QPoint(0, 0), QSize(pFrameBuffer->width(), pFrameBuffer->height()).boundedTo(workingArea.size()));
        }
        /* If normal geometry still null => use default size: */
        if (geo.isNull())
            geo = QRect(QPoint(0, 0), QSize(800, 600).boundedTo(workingArea.size()));
        /* Move window to the center of working-area: */
        geo.moveCenter(workingArea.center());
        setGeometry(geo);
    }

#elif defined(VBOX_WS_WIN)

# if QT_VERSION >= 0x050000
    /* Map window onto required screen: */
    windowHandle()->setScreen(qApp->screens().at(iHostScreen));
# endif /* QT_VERSION >= 0x050000 */
    /* Set appropriate window size: */
    resize(workingArea.size());
# if QT_VERSION < 0x050000
    /* Move window onto required screen: */
    move(workingArea.topLeft());
# endif /* QT_VERSION < 0x050000 */

#elif defined(VBOX_WS_X11)

    /* Determine whether we should use the native full-screen mode: */
    const bool fUseNativeFullScreen = VBoxGlobal::supportsFullScreenMonitorsProtocolX11() &&
                                      !gEDataManager->legacyFullscreenModeRequested();
    if (fUseNativeFullScreen)
    {
        /* Tell recent window managers which host-screen this window should be mapped to: */
        VBoxGlobal::setFullScreenMonitorX11(this, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));
    }

    /* Set appropriate window geometry: */
    resize(workingArea.size());
    move(workingArea.topLeft());

#else

# warning "port me"

#endif
}
void UIMachineWindowFullscreen::showInNecessaryMode()
{
    /* Make sure this window has fullscreen logic: */
    UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
    AssertPtrReturnVoid(pFullscreenLogic);

#ifdef Q_WS_MAC
    /* ML and next using native stuff: */
    const bool fSupportsNativeFullScreen = vboxGlobal().osRelease() > MacOSXRelease_Lion;
#endif /* Q_WS_MAC */

    /* Make sure this window should be shown and mapped to some host-screen: */
    if (!uisession()->isScreenVisible(m_uScreenId) ||
        !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
    {
#ifndef Q_WS_MAC
        /* If there is mini-toolbar: */
        if (m_pMiniToolBar)
        {
            /* Just hide mini-toolbar: */
            m_pMiniToolBar->hide();
        }
#endif /* !Q_WS_MAC */
        /* Hide window: */
        hide();
        return;
    }

    /* Make sure this window is not minimized: */
    if (isMinimized())
        return;

#ifdef Q_WS_X11
    /* On X11 calling placeOnScreen() is only needed for legacy window managers
     * which we do not test, so this is 'best effort' code. With window managers which
     * support the _NET_WM_FULLSCREEN_MONITORS protocol this would interfere unreliable. */
    const bool fSupportsNativeFullScreen = VBoxGlobal::supportsFullScreenMonitorsProtocolX11() &&
                                           !gEDataManager->legacyFullscreenModeRequested();
    if (!fSupportsNativeFullScreen)
        placeOnScreen();
#else /* !Q_WS_X11 */
    /* Make sure this window is maximized and placed on valid screen: */
    placeOnScreen();
#endif /* !Q_WS_X11 */

#ifdef Q_WS_MAC
    /* ML and next using native stuff, so we can call for simple show(),
     * Lion and previous using Qt stuff, so we should call for showFullScreen(): */
    if (fSupportsNativeFullScreen)
        show();
    else
        showFullScreen();
#else /* !Q_WS_MAC */
    /* Show in fullscreen mode: */
    showFullScreen();
#endif /* !Q_WS_MAC */

#ifdef Q_WS_X11
    if (fSupportsNativeFullScreen)
    {
        /* Tell recent window managers which screen this window should be mapped to.
         * Apparently some window managers will not respond to requests for
         * unmapped windows, so do this *after* the call to showFullScreen(). */
        VBoxGlobal::setFullScreenMonitorX11(this, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));
    }
    else
    {
        /* On X11 calling placeOnScreen() is only needed for legacy window managers
         * which we do not test, so this is 'best effort' code. With window managers which
         * support the _NET_WM_FULLSCREEN_MONITORS protocol this would interfere unreliable. */
        placeOnScreen();
    }
#endif /* Q_WS_X11 */

    /* Adjust machine-view size if necessary: */
    adjustMachineViewSize();

#ifndef Q_WS_MAC
    /* If there is mini-toolbar: */
    if (m_pMiniToolBar)
    {
# if   defined(Q_WS_WIN)
        /* Just show mini-toolbar: */
        m_pMiniToolBar->show();
# elif defined(Q_WS_X11)
        /* Allow mini-toolbar to be located on full-screen area: */
        m_pMiniToolBar->showFullScreen();
        /* On modern window managers: */
        if (fSupportsNativeFullScreen)
        {
            /* We also can map mini-toolbar directly on corresponding machine-window: */
            VBoxGlobal::setFullScreenMonitorX11(m_pMiniToolBar, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));
        }
        /* Make sure mini-toolbar is always on top of machine-window: */
        VBoxGlobal::setTransientFor(m_pMiniToolBar, this);
# endif /* Q_WS_X11 */
    }
#endif /* !Q_WS_MAC */

    /* Make sure machine-view have focus: */
    m_pMachineView->setFocus();
}