VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp@ 52299

Last change on this file since 52299 was 52299, checked in by vboxsync, 10 years ago

FE/Qt: Mac OS X: Runtime UI: Cache 'screens have separate spaces' value in machine-logic.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.5 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 52299 2014-08-06 16:56:26Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UIMachineWindowFullscreen class implementation
6 */
7
8/*
9 * Copyright (C) 2010-2013 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* Qt includes: */
21#include <QDesktopWidget>
22#include <QMenu>
23#include <QTimer>
24
25/* GUI includes: */
26#include "VBoxGlobal.h"
27#include "UIExtraDataManager.h"
28#include "UISession.h"
29#include "UIActionPoolRuntime.h"
30#include "UIMachineLogicFullscreen.h"
31#include "UIMachineWindowFullscreen.h"
32#include "UIMachineView.h"
33#include "UIMachineDefs.h"
34#include "UIMiniToolBar.h"
35#ifdef Q_WS_MAC
36# include "VBoxUtils-darwin.h"
37# include "UICocoaApplication.h"
38#endif /* Q_WS_MAC */
39
40/* COM includes: */
41#include "CSnapshot.h"
42
43UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
44 : UIMachineWindow(pMachineLogic, uScreenId)
45 , m_pMiniToolBar(0)
46#ifdef Q_WS_MAC
47 , m_fIsInFullscreenTransition(false)
48#endif /* Q_WS_MAC */
49{
50}
51
52#ifdef Q_WS_MAC
53void UIMachineWindowFullscreen::handleNativeNotification(const QString &strNativeNotificationName)
54{
55 /* Make sure this method is only used for ML and next: */
56 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
57
58 /* Log all arrived notifications: */
59 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: Notification '%s' received.\n",
60 strNativeNotificationName.toAscii().constData()));
61
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 }
69 /* Handle 'NSWindowDidEnterFullScreenNotification' notification: */
70 else if (strNativeNotificationName == "NSWindowDidEnterFullScreenNotification")
71 {
72 /* Mark window transition complete: */
73 m_fIsInFullscreenTransition = false;
74 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
75 "Native fullscreen mode entered, notifying listener...\n"));
76 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();
84 }
85 /* Handle 'NSWindowDidExitFullScreenNotification' notification: */
86 else if (strNativeNotificationName == "NSWindowDidExitFullScreenNotification")
87 {
88 /* Mark window transition complete: */
89 m_fIsInFullscreenTransition = false;
90 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
91 "Native fullscreen mode exited, notifying listener...\n"));
92 emit sigNotifyAboutNativeFullscreenDidExit();
93 }
94 /* Handle 'NSWindowDidFailToEnterFullScreenNotification' notification: */
95 else if (strNativeNotificationName == "NSWindowDidFailToEnterFullScreenNotification")
96 {
97 /* Mark window transition complete: */
98 m_fIsInFullscreenTransition = false;
99 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
100 "Native fullscreen mode fail to enter, notifying listener...\n"));
101 emit sigNotifyAboutNativeFullscreenFailToEnter();
102 }
103}
104#endif /* Q_WS_MAC */
105
106void UIMachineWindowFullscreen::sltMachineStateChanged()
107{
108 /* Call to base-class: */
109 UIMachineWindow::sltMachineStateChanged();
110
111 /* Update mini-toolbar: */
112 updateAppearanceOf(UIVisualElement_MiniToolBar);
113}
114
115#ifdef Q_WS_MAC
116void UIMachineWindowFullscreen::sltEnterNativeFullscreen(UIMachineWindow *pMachineWindow)
117{
118 /* Make sure this slot is called only under ML and next: */
119 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
120
121 /* Make sure it is NULL or 'this' window passed: */
122 if (pMachineWindow && pMachineWindow != this)
123 return;
124
125 /* Make sure this window should be shown at all: */
126 if (!uisession()->isScreenVisible(m_uScreenId))
127 return;
128
129 /* Make sure this window has fullscreen logic: */
130 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
131 AssertPtrReturnVoid(pFullscreenLogic);
132
133 /* Make sure this window mapped to some host-screen: */
134 if (!pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
135 return;
136
137 /* Mark window 'transitioned to fullscreen': */
138 m_fIsInFullscreenTransition = true;
139
140 /* Enter native fullscreen mode if necessary: */
141 if ( (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
142 && !darwinIsInFullscreenMode(this))
143 darwinToggleFullscreenMode(this);
144}
145
146void UIMachineWindowFullscreen::sltExitNativeFullscreen(UIMachineWindow *pMachineWindow)
147{
148 /* Make sure this slot is called only under ML and next: */
149 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
150
151 /* Make sure it is NULL or 'this' window passed: */
152 if (pMachineWindow && pMachineWindow != this)
153 return;
154
155 /* Make sure this window has fullscreen logic: */
156 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
157 AssertPtrReturnVoid(pFullscreenLogic);
158
159 /* Mark window 'transitioned from fullscreen': */
160 m_fIsInFullscreenTransition = true;
161
162 /* Exit native fullscreen mode if necessary: */
163 if ( (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
164 && darwinIsInFullscreenMode(this))
165 darwinToggleFullscreenMode(this);
166}
167#endif /* Q_WS_MAC */
168
169void UIMachineWindowFullscreen::sltRevokeFocus()
170{
171 /* Revoke stolen focus: */
172 m_pMachineView->setFocus();
173}
174
175void UIMachineWindowFullscreen::prepareVisualState()
176{
177 /* Call to base-class: */
178 UIMachineWindow::prepareVisualState();
179
180 /* The background has to go black: */
181 QPalette palette(centralWidget()->palette());
182 palette.setColor(centralWidget()->backgroundRole(), Qt::black);
183 centralWidget()->setPalette(palette);
184 centralWidget()->setAutoFillBackground(true);
185 setAutoFillBackground(true);
186
187 /* Prepare mini-toolbar: */
188 prepareMiniToolbar();
189
190#ifdef Q_WS_MAC
191 /* Native fullscreen stuff on ML and next: */
192 if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
193 {
194 /* Make sure this window has fullscreen logic: */
195 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
196 AssertPtrReturnVoid(pFullscreenLogic);
197 /* Enable fullscreen support for every screen which requires it: */
198 if (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
199 darwinEnableFullscreenSupport(this);
200 /* Enable transience support for other screens: */
201 else
202 darwinEnableTransienceSupport(this);
203 /* Register to native fullscreen notifications: */
204 UICocoaApplication::instance()->registerToNativeNotification("NSWindowWillEnterFullScreenNotification", this,
205 UIMachineWindow::handleNativeNotification);
206 UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidEnterFullScreenNotification", this,
207 UIMachineWindow::handleNativeNotification);
208 UICocoaApplication::instance()->registerToNativeNotification("NSWindowWillExitFullScreenNotification", this,
209 UIMachineWindow::handleNativeNotification);
210 UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidExitFullScreenNotification", this,
211 UIMachineWindow::handleNativeNotification);
212 UICocoaApplication::instance()->registerToNativeNotification("NSWindowDidFailToEnterFullScreenNotification", this,
213 UIMachineWindow::handleNativeNotification);
214 }
215#endif /* Q_WS_MAC */
216}
217
218void UIMachineWindowFullscreen::prepareMiniToolbar()
219{
220 /* Make sure mini-toolbar is not restricted: */
221 if (!gEDataManager->miniToolbarEnabled(vboxGlobal().managedVMUuid()))
222 return;
223
224 /* Create mini-toolbar: */
225 m_pMiniToolBar = new UIRuntimeMiniToolBar(this,
226 IntegrationMode_Embedded,
227 gEDataManager->miniToolbarAlignment(vboxGlobal().managedVMUuid()),
228 gEDataManager->autoHideMiniToolbar(vboxGlobal().managedVMUuid()));
229 m_pMiniToolBar->addMenus(actionPool()->menus());
230#ifndef RT_OS_DARWIN
231 connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()), this, SLOT(showMinimized()));
232#endif /* !RT_OS_DARWIN */
233 connect(m_pMiniToolBar, SIGNAL(sigExitAction()),
234 actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SLOT(trigger()));
235 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
236 actionPool()->action(UIActionIndexRT_M_Machine_S_Close), SLOT(trigger()));
237 connect(m_pMiniToolBar, SIGNAL(sigNotifyAboutFocusStolen()), this, SLOT(sltRevokeFocus()));
238}
239
240void UIMachineWindowFullscreen::cleanupMiniToolbar()
241{
242 /* Make sure mini-toolbar was created: */
243 if (!m_pMiniToolBar)
244 return;
245
246 /* Save mini-toolbar settings: */
247 gEDataManager->setAutoHideMiniToolbar(m_pMiniToolBar->autoHide(), vboxGlobal().managedVMUuid());
248 /* Delete mini-toolbar: */
249 delete m_pMiniToolBar;
250 m_pMiniToolBar = 0;
251}
252
253void UIMachineWindowFullscreen::cleanupVisualState()
254{
255#ifdef Q_WS_MAC
256 /* Native fullscreen stuff on ML and next: */
257 if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
258 {
259 /* Unregister from native fullscreen notifications: */
260 UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowWillEnterFullScreenNotification", this);
261 UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidEnterFullScreenNotification", this);
262 UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowWillExitFullScreenNotification", this);
263 UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidExitFullScreenNotification", this);
264 UICocoaApplication::instance()->unregisterFromNativeNotification("NSWindowDidFailToEnterFullScreenNotification", this);
265 }
266#endif /* Q_WS_MAC */
267
268 /* Cleanup mini-toolbar: */
269 cleanupMiniToolbar();
270
271 /* Call to base-class: */
272 UIMachineWindow::cleanupVisualState();
273}
274
275void UIMachineWindowFullscreen::placeOnScreen()
276{
277 /* Get corresponding screen: */
278 int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
279 /* Calculate working area: */
280 QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
281 /* Move to the appropriate position: */
282 move(workingArea.topLeft());
283#ifdef Q_WS_MAC
284 /* Make sure this window has fullscreen logic: */
285 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
286 AssertPtrReturnVoid(pFullscreenLogic);
287 /* Resize to the appropriate size on Lion and previous: */
288 if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
289 resize(workingArea.size());
290 /* Resize to the appropriate size on ML and next
291 * only if that screen has no own user-space: */
292 else if (!pFullscreenLogic->screensHaveSeparateSpaces() && m_uScreenId != 0)
293 resize(workingArea.size());
294#else /* !Q_WS_MAC */
295 /* Resize to the appropriate size: */
296 resize(workingArea.size());
297#endif /* !Q_WS_MAC */
298 /* Adjust guest screen size if necessary: */
299 machineView()->maybeAdjustGuestScreenSize();
300 /* Move mini-toolbar into appropriate place: */
301 if (m_pMiniToolBar)
302 m_pMiniToolBar->adjustGeometry();
303}
304
305void UIMachineWindowFullscreen::showInNecessaryMode()
306{
307 /* Make sure this window should be shown at all: */
308 if (!uisession()->isScreenVisible(m_uScreenId))
309 return hide();
310
311 /* Make sure this window has fullscreen logic: */
312 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
313 if (!pFullscreenLogic)
314 return hide();
315
316 /* Make sure this window mapped to some host-screen: */
317 if (!pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
318 return hide();
319
320 /* Make sure this window is not minimized: */
321 if (isMinimized())
322 return;
323
324 /* Make sure this window is maximized and placed on valid screen: */
325 placeOnScreen();
326
327#ifdef Q_WS_MAC
328 /* ML and next using native stuff, so we can call for simple show(): */
329 if (vboxGlobal().osRelease() > MacOSXRelease_Lion) show();
330 /* Lion and previous using Qt stuff, so we should call for showFullScreen(): */
331 else showFullScreen();
332#else /* !Q_WS_MAC */
333 /* Show in fullscreen mode: */
334 showFullScreen();
335#endif /* !Q_WS_MAC */
336
337#ifdef Q_WS_X11
338 /* Make sure the window is placed on valid screen again
339 * after window is shown & window's decorations applied.
340 * That is required (still?) due to X11 Window Geometry Rules. */
341 placeOnScreen();
342#endif /* Q_WS_X11 */
343}
344
345void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
346{
347 /* Call to base-class: */
348 UIMachineWindow::updateAppearanceOf(iElement);
349
350 /* Update mini-toolbar: */
351 if (iElement & UIVisualElement_MiniToolBar)
352 {
353 if (m_pMiniToolBar)
354 {
355 /* Get machine: */
356 const CMachine &m = machine();
357 /* Get snapshot(s): */
358 QString strSnapshotName;
359 if (m.GetSnapshotCount() > 0)
360 {
361 CSnapshot snapshot = m.GetCurrentSnapshot();
362 strSnapshotName = " (" + snapshot.GetName() + ")";
363 }
364 /* Update mini-toolbar text: */
365 m_pMiniToolBar->setText(m.GetName() + strSnapshotName);
366 }
367 }
368}
369
Note: See TracBrowser for help on using the repository browser.

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