VirtualBox

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

Last change on this file since 52730 was 52730, checked in by vboxsync, 11 years ago

FE/Qt: Precompiled header hacking (work in progress).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.0 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 52730 2014-09-12 16:19:53Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMachineWindowFullscreen class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21
22/* Qt includes: */
23# include <QDesktopWidget>
24# include <QMenu>
25# include <QTimer>
26
27/* GUI includes: */
28# include "VBoxGlobal.h"
29# include "UIExtraDataManager.h"
30# include "UISession.h"
31# include "UIActionPoolRuntime.h"
32# include "UIMachineLogicFullscreen.h"
33# include "UIMachineWindowFullscreen.h"
34# include "UIMachineView.h"
35# include "UIFrameBuffer.h"
36# include "UIMachineDefs.h"
37# include "UIMiniToolBar.h"
38# ifdef Q_WS_MAC
39# include "VBoxUtils-darwin.h"
40# include "UICocoaApplication.h"
41# endif /* Q_WS_MAC */
42
43/* COM includes: */
44# include "CSnapshot.h"
45
46#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
47
48
49UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
50 : UIMachineWindow(pMachineLogic, uScreenId)
51 , m_pMiniToolBar(0)
52#ifdef Q_WS_MAC
53 , m_fIsInFullscreenTransition(false)
54#endif /* Q_WS_MAC */
55{
56}
57
58#ifdef Q_WS_MAC
59void UIMachineWindowFullscreen::handleNativeNotification(const QString &strNativeNotificationName)
60{
61 /* Make sure this method is only used for ML and next: */
62 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
63
64 /* Log all arrived notifications: */
65 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: Notification '%s' received.\n",
66 strNativeNotificationName.toAscii().constData()));
67
68 /* Handle 'NSWindowWillEnterFullScreenNotification' notification: */
69 if (strNativeNotificationName == "NSWindowWillEnterFullScreenNotification")
70 {
71 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
72 "Native fullscreen mode about to enter, notifying listener...\n"));
73 emit sigNotifyAboutNativeFullscreenWillEnter();
74 }
75 /* Handle 'NSWindowDidEnterFullScreenNotification' notification: */
76 else if (strNativeNotificationName == "NSWindowDidEnterFullScreenNotification")
77 {
78 /* Mark window transition complete: */
79 m_fIsInFullscreenTransition = false;
80 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
81 "Native fullscreen mode entered, notifying listener...\n"));
82 emit sigNotifyAboutNativeFullscreenDidEnter();
83 }
84 /* Handle 'NSWindowWillExitFullScreenNotification' notification: */
85 else if (strNativeNotificationName == "NSWindowWillExitFullScreenNotification")
86 {
87 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
88 "Native fullscreen mode about to exit, notifying listener...\n"));
89 emit sigNotifyAboutNativeFullscreenWillExit();
90 }
91 /* Handle 'NSWindowDidExitFullScreenNotification' notification: */
92 else if (strNativeNotificationName == "NSWindowDidExitFullScreenNotification")
93 {
94 /* Mark window transition complete: */
95 m_fIsInFullscreenTransition = false;
96 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
97 "Native fullscreen mode exited, notifying listener...\n"));
98 emit sigNotifyAboutNativeFullscreenDidExit();
99 }
100 /* Handle 'NSWindowDidFailToEnterFullScreenNotification' notification: */
101 else if (strNativeNotificationName == "NSWindowDidFailToEnterFullScreenNotification")
102 {
103 /* Mark window transition complete: */
104 m_fIsInFullscreenTransition = false;
105 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
106 "Native fullscreen mode fail to enter, notifying listener...\n"));
107 emit sigNotifyAboutNativeFullscreenFailToEnter();
108 }
109}
110
111void UIMachineWindowFullscreen::setMiniToolbarVisible(bool fVisible)
112{
113 /* Make sure mini-toolbar exists: */
114 if (!m_pMiniToolBar)
115 return;
116 /* Set mini-toolbar visibility to passed one: */
117 m_pMiniToolBar->setVisible(fVisible);
118}
119#endif /* Q_WS_MAC */
120
121void UIMachineWindowFullscreen::sltMachineStateChanged()
122{
123 /* Call to base-class: */
124 UIMachineWindow::sltMachineStateChanged();
125
126 /* Update mini-toolbar: */
127 updateAppearanceOf(UIVisualElement_MiniToolBar);
128}
129
130#ifdef Q_WS_MAC
131void UIMachineWindowFullscreen::sltEnterNativeFullscreen(UIMachineWindow *pMachineWindow)
132{
133 /* Make sure this slot is called only under ML and next: */
134 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
135
136 /* Make sure it is NULL or 'this' window passed: */
137 if (pMachineWindow && pMachineWindow != this)
138 return;
139
140 /* Make sure this window has fullscreen logic: */
141 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
142 AssertPtrReturnVoid(pFullscreenLogic);
143
144 /* Make sure this window should be shown and mapped to host-screen: */
145 if (!uisession()->isScreenVisible(m_uScreenId) ||
146 !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
147 return;
148
149 /* Mark window 'transitioned to fullscreen': */
150 m_fIsInFullscreenTransition = true;
151
152 /* Enter native fullscreen mode if necessary: */
153 if ( (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
154 && !darwinIsInFullscreenMode(this))
155 darwinToggleFullscreenMode(this);
156}
157
158void UIMachineWindowFullscreen::sltExitNativeFullscreen(UIMachineWindow *pMachineWindow)
159{
160 /* Make sure this slot is called only under ML and next: */
161 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
162
163 /* Make sure it is NULL or 'this' window passed: */
164 if (pMachineWindow && pMachineWindow != this)
165 return;
166
167 /* Make sure this window has fullscreen logic: */
168 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
169 AssertPtrReturnVoid(pFullscreenLogic);
170
171 /* Mark window 'transitioned from fullscreen': */
172 m_fIsInFullscreenTransition = true;
173
174 /* Exit native fullscreen mode if necessary: */
175 if ( (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
176 && darwinIsInFullscreenMode(this))
177 darwinToggleFullscreenMode(this);
178}
179#endif /* Q_WS_MAC */
180
181void UIMachineWindowFullscreen::sltRevokeFocus()
182{
183 /* Make sure window is visible: */
184 if (!isVisible())
185 return;
186
187 /* Revoke stolen focus: */
188 m_pMachineView->setFocus();
189}
190
191void UIMachineWindowFullscreen::prepareVisualState()
192{
193 /* Call to base-class: */
194 UIMachineWindow::prepareVisualState();
195
196 /* The background has to go black: */
197 QPalette palette(centralWidget()->palette());
198 palette.setColor(centralWidget()->backgroundRole(), Qt::black);
199 centralWidget()->setPalette(palette);
200 centralWidget()->setAutoFillBackground(true);
201 setAutoFillBackground(true);
202
203 /* Prepare mini-toolbar: */
204 prepareMiniToolbar();
205
206#ifdef Q_WS_MAC
207 /* Native fullscreen stuff on ML and next: */
208 if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
209 {
210 /* Make sure this window has fullscreen logic: */
211 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
212 AssertPtrReturnVoid(pFullscreenLogic);
213 /* Enable fullscreen support for every screen which requires it: */
214 if (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
215 darwinEnableFullscreenSupport(this);
216 /* Enable transience support for other screens: */
217 else
218 darwinEnableTransienceSupport(this);
219 /* Register to native fullscreen notifications: */
220 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowWillEnterFullScreenNotification", this,
221 UIMachineWindow::handleNativeNotification);
222 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidEnterFullScreenNotification", this,
223 UIMachineWindow::handleNativeNotification);
224 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowWillExitFullScreenNotification", this,
225 UIMachineWindow::handleNativeNotification);
226 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidExitFullScreenNotification", this,
227 UIMachineWindow::handleNativeNotification);
228 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidFailToEnterFullScreenNotification", this,
229 UIMachineWindow::handleNativeNotification);
230 }
231#endif /* Q_WS_MAC */
232}
233
234void UIMachineWindowFullscreen::prepareMiniToolbar()
235{
236 /* Make sure mini-toolbar is not restricted: */
237 if (!gEDataManager->miniToolbarEnabled(vboxGlobal().managedVMUuid()))
238 return;
239
240 /* Create mini-toolbar: */
241 m_pMiniToolBar = new UIRuntimeMiniToolBar(this,
242 GeometryType_Full,
243 gEDataManager->miniToolbarAlignment(vboxGlobal().managedVMUuid()),
244 gEDataManager->autoHideMiniToolbar(vboxGlobal().managedVMUuid()));
245 m_pMiniToolBar->addMenus(actionPool()->menus());
246#ifndef RT_OS_DARWIN
247 connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()), this, SLOT(showMinimized()));
248#endif /* !RT_OS_DARWIN */
249 connect(m_pMiniToolBar, SIGNAL(sigExitAction()),
250 actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SLOT(trigger()));
251#ifdef RT_OS_DARWIN
252 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
253 actionPool()->action(UIActionIndex_M_Application_S_Close), SLOT(trigger()));
254#else /* !RT_OS_DARWIN */
255 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
256 actionPool()->action(UIActionIndexRT_M_Machine_S_Close), SLOT(trigger()));
257#endif /* !RT_OS_DARWIN */
258 connect(m_pMiniToolBar, SIGNAL(sigNotifyAboutFocusStolen()), this, SLOT(sltRevokeFocus()));
259}
260
261void UIMachineWindowFullscreen::cleanupMiniToolbar()
262{
263 /* Make sure mini-toolbar was created: */
264 if (!m_pMiniToolBar)
265 return;
266
267 /* Save mini-toolbar settings: */
268 gEDataManager->setAutoHideMiniToolbar(m_pMiniToolBar->autoHide(), vboxGlobal().managedVMUuid());
269 /* Delete mini-toolbar: */
270 delete m_pMiniToolBar;
271 m_pMiniToolBar = 0;
272}
273
274void UIMachineWindowFullscreen::cleanupVisualState()
275{
276#ifdef Q_WS_MAC
277 /* Native fullscreen stuff on ML and next: */
278 if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
279 {
280 /* Unregister from native fullscreen notifications: */
281 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowWillEnterFullScreenNotification", this);
282 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowDidEnterFullScreenNotification", this);
283 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowWillExitFullScreenNotification", this);
284 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowDidExitFullScreenNotification", this);
285 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowDidFailToEnterFullScreenNotification", this);
286 }
287#endif /* Q_WS_MAC */
288
289 /* Cleanup mini-toolbar: */
290 cleanupMiniToolbar();
291
292 /* Call to base-class: */
293 UIMachineWindow::cleanupVisualState();
294}
295
296void UIMachineWindowFullscreen::placeOnScreen()
297{
298 /* Get corresponding screen: */
299 const int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);
300 /* And corresponding working area: */
301 const QRect workingArea = QApplication::desktop()->screenGeometry(iScreen);
302
303 /* Move to the appropriate position: */
304 move(workingArea.topLeft());
305
306#ifdef Q_WS_MAC
307 /* Make sure this window has fullscreen logic: */
308 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
309 AssertPtrReturnVoid(pFullscreenLogic);
310
311 /* Resize to the appropriate size on Lion and previous: */
312 if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
313 resize(workingArea.size());
314 /* Resize to the appropriate size on ML and next
315 * only if that screen has no own user-space: */
316 else if (!pFullscreenLogic->screensHaveSeparateSpaces() && m_uScreenId != 0)
317 resize(workingArea.size());
318 else
319 {
320 /* Load normal geometry first of all: */
321 QRect geo = gEDataManager->machineWindowGeometry(UIVisualStateType_Normal, m_uScreenId, vboxGlobal().managedVMUuid());
322 /* If normal geometry is null => use frame-buffer size: */
323 if (geo.isNull())
324 {
325 const UIFrameBuffer *pFrameBuffer = uisession()->frameBuffer(m_uScreenId);
326 geo = QRect(QPoint(0, 0), QSize(pFrameBuffer->width(), pFrameBuffer->height()).boundedTo(workingArea.size()));
327 }
328 /* If frame-buffer size is null => use default size: */
329 if (geo.isNull())
330 geo = QRect(QPoint(0, 0), QSize(800, 600).boundedTo(workingArea.size()));
331 /* Move window to the center of working-area: */
332 geo.moveCenter(workingArea.center());
333 setGeometry(geo);
334 }
335#else /* !Q_WS_MAC */
336 /* Resize to the appropriate size: */
337 resize(workingArea.size());
338#endif /* !Q_WS_MAC */
339}
340
341void UIMachineWindowFullscreen::showInNecessaryMode()
342{
343 /* Make sure this window has fullscreen logic: */
344 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
345 AssertPtrReturnVoid(pFullscreenLogic);
346
347#ifdef Q_WS_MAC
348 /* ML and next using native stuff: */
349 const bool fSupportsNativeFullScreen = vboxGlobal().osRelease() > MacOSXRelease_Lion;
350#endif /* Q_WS_MAC */
351
352 /* Make sure this window should be shown and mapped to some host-screen: */
353 if (!uisession()->isScreenVisible(m_uScreenId) ||
354 !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
355 {
356 /* Hide mini-toolbar: */
357 if ( m_pMiniToolBar
358#ifdef Q_WS_MAC
359 && !fSupportsNativeFullScreen
360#endif /* Q_WS_MAC */
361 )
362 m_pMiniToolBar->hide();
363 /* Hide window: */
364 hide();
365 return;
366 }
367
368 /* Make sure this window is not minimized: */
369 if (isMinimized())
370 return;
371
372#ifdef Q_WS_X11
373 /* On X11 calling placeOnScreen() is only needed for legacy window managers
374 * which we do not test, so this is 'best effort' code. With window managers which
375 * support the _NET_WM_FULLSCREEN_MONITORS protocol this would interfere unreliable. */
376 const bool fSupportsNativeFullScreen = VBoxGlobal::supportsFullScreenMonitorsProtocolX11();
377 if (!fSupportsNativeFullScreen)
378 placeOnScreen();
379#else /* !Q_WS_X11 */
380 /* Make sure this window is maximized and placed on valid screen: */
381 placeOnScreen();
382#endif /* !Q_WS_X11 */
383
384#ifdef Q_WS_MAC
385 /* ML and next using native stuff, so we can call for simple show(),
386 * Lion and previous using Qt stuff, so we should call for showFullScreen(): */
387 if (fSupportsNativeFullScreen)
388 show();
389 else
390 showFullScreen();
391#else /* !Q_WS_MAC */
392 /* Show in fullscreen mode: */
393 showFullScreen();
394#endif /* !Q_WS_MAC */
395
396#ifdef Q_WS_X11
397 if (fSupportsNativeFullScreen)
398 {
399 /* Tell recent window managers which screen this window should be mapped to.
400 * Apparently some window managers will not respond to requests for
401 * unmapped windows, so do this *after* the call to showFullScreen(). */
402 VBoxGlobal::setFullScreenMonitorX11(this, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));
403 }
404 else
405 {
406 /* On X11 calling placeOnScreen() is only needed for legacy window managers
407 * which we do not test, so this is 'best effort' code. With window managers which
408 * support the _NET_WM_FULLSCREEN_MONITORS protocol this would interfere unreliable. */
409 placeOnScreen();
410 }
411#endif /* Q_WS_X11 */
412
413 /* Adjust machine-view size if necessary: */
414 adjustMachineViewSize();
415
416 /* Show mini-toolbar: */
417 if ( m_pMiniToolBar
418#ifdef Q_WS_MAC
419 && !fSupportsNativeFullScreen
420#endif /* Q_WS_MAC */
421 )
422 m_pMiniToolBar->show();
423
424 /* Make sure machine-view have focus: */
425 m_pMachineView->setFocus();
426}
427
428void UIMachineWindowFullscreen::adjustMachineViewSize()
429{
430 /* Call to base-class: */
431 UIMachineWindow::adjustMachineViewSize();
432
433 /* If mini-toolbar present: */
434 if (m_pMiniToolBar)
435 {
436 /* Make sure this window has fullscreen logic: */
437 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
438 AssertPtrReturnVoid(pFullscreenLogic);
439
440 /* Which host-screen should that machine-window located on? */
441 const int iHostScreen = pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId);
442
443 /* Move mini-toolbar into appropriate place: */
444 m_pMiniToolBar->adjustGeometry(iHostScreen);
445 }
446}
447
448void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
449{
450 /* Call to base-class: */
451 UIMachineWindow::updateAppearanceOf(iElement);
452
453 /* Update mini-toolbar: */
454 if (iElement & UIVisualElement_MiniToolBar)
455 {
456 if (m_pMiniToolBar)
457 {
458 /* Get machine: */
459 const CMachine &m = machine();
460 /* Get snapshot(s): */
461 QString strSnapshotName;
462 if (m.GetSnapshotCount() > 0)
463 {
464 CSnapshot snapshot = m.GetCurrentSnapshot();
465 strSnapshotName = " (" + snapshot.GetName() + ")";
466 }
467 /* Update mini-toolbar text: */
468 m_pMiniToolBar->setText(m.GetName() + strSnapshotName);
469 }
470 }
471}
472
Note: See TracBrowser for help on using the repository browser.

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