UIMachineWindowFullscreen.cpp revision 7012be689cdcb57abe9a8dbb5ebedd56d67c5b96
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIMachineWindowFullscreen class implementation
*/
/*
* Copyright (C) 2010-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/* Qt includes: */
#include <QDesktopWidget>
#include <QMenu>
#include <QTimer>
/* GUI includes: */
#include "VBoxGlobal.h"
#include "UIExtraDataManager.h"
#include "UISession.h"
#include "UIActionPoolRuntime.h"
#include "UIMachineLogicFullscreen.h"
#include "UIMachineWindowFullscreen.h"
#include "UIMachineView.h"
#include "UIMachineDefs.h"
#include "UIMiniToolBar.h"
#ifdef Q_WS_MAC
# include "VBoxUtils-darwin.h"
# include "UICocoaApplication.h"
#endif /* Q_WS_MAC */
/* COM includes: */
#include "CSnapshot.h"
UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
, m_pMiniToolBar(0)
#ifdef Q_WS_MAC
, m_fIsInFullscreenTransition(false)
#endif /* Q_WS_MAC */
{
}
#ifdef Q_WS_MAC
{
/* Make sure this method is only used for ML and next: */
/* Log all arrived notifications: */
LogRel(("UIMachineWindowFullscreen::handleNativeNotification: Notification '%s' received.\n",
/* Handle 'NSWindowWillEnterFullScreenNotification' notification: */
if (strNativeNotificationName == "NSWindowWillEnterFullScreenNotification")
{
LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
"Native fullscreen mode about to enter, notifying listener...\n"));
}
/* Handle 'NSWindowDidEnterFullScreenNotification' notification: */
else if (strNativeNotificationName == "NSWindowDidEnterFullScreenNotification")
{
/* Mark window transition complete: */
m_fIsInFullscreenTransition = false;
LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
"Native fullscreen mode entered, notifying listener...\n"));
}
/* Handle 'NSWindowWillExitFullScreenNotification' notification: */
else if (strNativeNotificationName == "NSWindowWillExitFullScreenNotification")
{
LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
"Native fullscreen mode about to exit, notifying listener...\n"));
}
/* Handle 'NSWindowDidExitFullScreenNotification' notification: */
else if (strNativeNotificationName == "NSWindowDidExitFullScreenNotification")
{
/* Mark window transition complete: */
m_fIsInFullscreenTransition = false;
LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
"Native fullscreen mode exited, notifying listener...\n"));
}
/* Handle 'NSWindowDidFailToEnterFullScreenNotification' notification: */
else if (strNativeNotificationName == "NSWindowDidFailToEnterFullScreenNotification")
{
/* Mark window transition complete: */
m_fIsInFullscreenTransition = false;
LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
"Native fullscreen mode fail to enter, notifying listener...\n"));
}
}
#endif /* Q_WS_MAC */
{
/* Call to base-class: */
/* Update mini-toolbar: */
}
#ifdef Q_WS_MAC
{
/* Make sure this slot is called only under ML and next: */
/* 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());
/* Make sure this window should be shown and mapped to host-screen: */
return;
/* Mark window 'transitioned to fullscreen': */
m_fIsInFullscreenTransition = true;
/* Enter native fullscreen mode if necessary: */
&& !darwinIsInFullscreenMode(this))
darwinToggleFullscreenMode(this);
}
{
/* Make sure this slot is called only under ML and next: */
/* 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());
/* Mark window 'transitioned from fullscreen': */
m_fIsInFullscreenTransition = true;
/* Exit native fullscreen mode if necessary: */
&& darwinIsInFullscreenMode(this))
darwinToggleFullscreenMode(this);
}
#endif /* Q_WS_MAC */
{
/* Revoke stolen focus: */
}
{
/* Call to base-class: */
/* The background has to go black: */
centralWidget()->setAutoFillBackground(true);
setAutoFillBackground(true);
/* Prepare mini-toolbar: */
#ifdef Q_WS_MAC
/* Native fullscreen stuff on ML and next: */
{
/* Make sure this window has fullscreen logic: */
UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
/* Enable fullscreen support for every screen which requires it: */
/* Enable transience support for other screens: */
else
/* Register to native fullscreen notifications: */
UICocoaApplication::instance()->registerToNativeNotification("NSWindowWillEnterFullScreenNotification", this,
UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidEnterFullScreenNotification", this,
UICocoaApplication::instance()->registerToNativeNotification("NSWindowWillExitFullScreenNotification", this,
UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidExitFullScreenNotification", this,
UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidFailToEnterFullScreenNotification", this,
}
#endif /* Q_WS_MAC */
}
{
/* Make sure mini-toolbar is not restricted: */
return;
/* Create mini-toolbar: */
m_pMiniToolBar = new UIRuntimeMiniToolBar(this,
#ifndef RT_OS_DARWIN
#endif /* !RT_OS_DARWIN */
}
{
/* Make sure mini-toolbar was created: */
if (!m_pMiniToolBar)
return;
/* Save mini-toolbar settings: */
/* Delete mini-toolbar: */
delete m_pMiniToolBar;
m_pMiniToolBar = 0;
}
{
#ifdef Q_WS_MAC
/* Native fullscreen stuff on ML and next: */
{
/* Unregister from native fullscreen notifications: */
UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowWillEnterFullScreenNotification", this);
UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidEnterFullScreenNotification", this);
UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowWillExitFullScreenNotification", this);
UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidExitFullScreenNotification", this);
UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidFailToEnterFullScreenNotification", this);
}
#endif /* Q_WS_MAC */
/* Cleanup mini-toolbar: */
/* Call to base-class: */
}
{
/* Get corresponding screen: */
int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
/* Calculate working area: */
/* Move to the appropriate position: */
#ifdef Q_WS_MAC
/* Make sure this window has fullscreen logic: */
UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
/* Resize to the appropriate size on Lion and previous: */
/* Resize to the appropriate size on ML and next
* only if that screen has no own user-space: */
else
{
/* Move window to the center of working-area: */
QRect geo = gEDataManager->machineWindowGeometry(UIVisualStateType_Normal, m_uScreenId, vboxGlobal().managedVMUuid());
}
#else /* !Q_WS_MAC */
/* Resize to the appropriate size: */
#endif /* !Q_WS_MAC */
/* Adjust guest screen size if necessary: */
/* Move mini-toolbar into appropriate place: */
if (m_pMiniToolBar)
}
{
/* Make sure this window should be shown at all: */
return hide();
/* Make sure this window has fullscreen logic: */
UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
if (!pFullscreenLogic)
return hide();
/* Make sure this window mapped to some host-screen: */
return hide();
/* Make sure this window is not minimized: */
if (isMinimized())
return;
/* Make sure this window is maximized and placed on valid screen: */
#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(): */
else showFullScreen();
#else /* !Q_WS_MAC */
/* Show in fullscreen mode: */
#endif /* !Q_WS_MAC */
#ifdef Q_WS_X11
/* Make sure the window is placed on valid screen again
* after window is shown & window's decorations applied.
* That is required (still?) due to X11 Window Geometry Rules. */
#endif /* Q_WS_X11 */
}
{
/* Call to base-class: */
/* Update mini-toolbar: */
{
if (m_pMiniToolBar)
{
/* Get machine: */
/* Get snapshot(s): */
if (m.GetSnapshotCount() > 0)
{
}
/* Update mini-toolbar text: */
}
}
}