VirtualBox

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

Last change on this file since 61967 was 61967, checked in by vboxsync, 9 years ago

FE/Qt: bugref:8422: X11: Runtime UI: Restore full-screen window state after placeOnScreen() call.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 KB
Line 
1/* $Id: UIMachineWindowFullscreen.cpp 61967 2016-06-30 17:40:58Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMachineWindowFullscreen class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2015 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 <QMenu>
24# include <QTimer>
25# ifdef VBOX_WS_WIN
26# if QT_VERSION >= 0x050000
27# include <QWindow>
28# endif /* QT_VERSION >= 0x050000 */
29# endif /* VBOX_WS_WIN */
30
31/* GUI includes: */
32# include "VBoxGlobal.h"
33# include "UIExtraDataManager.h"
34# include "UISession.h"
35# include "UIActionPoolRuntime.h"
36# include "UIMachineLogicFullscreen.h"
37# include "UIMachineWindowFullscreen.h"
38# include "UIMachineView.h"
39# if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
40# include "UIMachineDefs.h"
41# include "UIMiniToolBar.h"
42# elif defined(VBOX_WS_MAC)
43# include "UIFrameBuffer.h"
44# include "VBoxUtils-darwin.h"
45# include "UICocoaApplication.h"
46# endif /* VBOX_WS_MAC */
47
48/* COM includes: */
49# include "CSnapshot.h"
50
51#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
52
53
54UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId)
55 : UIMachineWindow(pMachineLogic, uScreenId)
56#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
57 , m_pMiniToolBar(0)
58#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
59#ifdef VBOX_WS_MAC
60 , m_fIsInFullscreenTransition(false)
61#endif /* VBOX_WS_MAC */
62 , m_fWasMinimized(false)
63{
64}
65
66#ifdef VBOX_WS_MAC
67void UIMachineWindowFullscreen::handleNativeNotification(const QString &strNativeNotificationName)
68{
69 /* Make sure this method is only used for ML and next: */
70 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
71
72 /* Log all arrived notifications: */
73 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: Notification '%s' received.\n",
74 strNativeNotificationName.toLatin1().constData()));
75
76 /* Handle 'NSWindowWillEnterFullScreenNotification' notification: */
77 if (strNativeNotificationName == "NSWindowWillEnterFullScreenNotification")
78 {
79 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
80 "Native fullscreen mode about to enter, notifying listener...\n"));
81 emit sigNotifyAboutNativeFullscreenWillEnter();
82 }
83 /* Handle 'NSWindowDidEnterFullScreenNotification' notification: */
84 else if (strNativeNotificationName == "NSWindowDidEnterFullScreenNotification")
85 {
86 /* Mark window transition complete: */
87 m_fIsInFullscreenTransition = false;
88 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
89 "Native fullscreen mode entered, notifying listener...\n"));
90 /* Update console's display viewport and 3D overlay: */
91 machineView()->updateViewport();
92 emit sigNotifyAboutNativeFullscreenDidEnter();
93 }
94 /* Handle 'NSWindowWillExitFullScreenNotification' notification: */
95 else if (strNativeNotificationName == "NSWindowWillExitFullScreenNotification")
96 {
97 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
98 "Native fullscreen mode about to exit, notifying listener...\n"));
99 emit sigNotifyAboutNativeFullscreenWillExit();
100 }
101 /* Handle 'NSWindowDidExitFullScreenNotification' notification: */
102 else if (strNativeNotificationName == "NSWindowDidExitFullScreenNotification")
103 {
104 /* Mark window transition complete: */
105 m_fIsInFullscreenTransition = false;
106 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
107 "Native fullscreen mode exited, notifying listener...\n"));
108 /* Update console's display viewport and 3D overlay: */
109 machineView()->updateViewport();
110 emit sigNotifyAboutNativeFullscreenDidExit();
111 }
112 /* Handle 'NSWindowDidFailToEnterFullScreenNotification' notification: */
113 else if (strNativeNotificationName == "NSWindowDidFailToEnterFullScreenNotification")
114 {
115 /* Mark window transition complete: */
116 m_fIsInFullscreenTransition = false;
117 LogRel(("UIMachineWindowFullscreen::handleNativeNotification: "
118 "Native fullscreen mode fail to enter, notifying listener...\n"));
119 emit sigNotifyAboutNativeFullscreenFailToEnter();
120 }
121}
122#endif /* VBOX_WS_MAC */
123
124#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
125void UIMachineWindowFullscreen::sltMachineStateChanged()
126{
127 /* Call to base-class: */
128 UIMachineWindow::sltMachineStateChanged();
129
130 /* Update mini-toolbar: */
131 updateAppearanceOf(UIVisualElement_MiniToolBar);
132}
133
134void UIMachineWindowFullscreen::sltRevokeWindowActivation()
135{
136 /* Make sure window is visible: */
137 if (!isVisible() || isMinimized())
138 return;
139
140 /* Revoke stolen activation: */
141#ifdef VBOX_WS_X11
142 raise();
143#endif /* VBOX_WS_X11 */
144 activateWindow();
145}
146#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
147
148#ifdef VBOX_WS_MAC
149void UIMachineWindowFullscreen::sltEnterNativeFullscreen(UIMachineWindow *pMachineWindow)
150{
151 /* Make sure this slot is called only under ML and next: */
152 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
153
154 /* Make sure it is NULL or 'this' window passed: */
155 if (pMachineWindow && pMachineWindow != this)
156 return;
157
158 /* Make sure this window has fullscreen logic: */
159 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
160 AssertPtrReturnVoid(pFullscreenLogic);
161
162 /* Make sure this window should be shown and mapped to host-screen: */
163 if (!uisession()->isScreenVisible(m_uScreenId) ||
164 !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
165 return;
166
167 /* Mark window 'transitioned to fullscreen': */
168 m_fIsInFullscreenTransition = true;
169
170 /* Enter native fullscreen mode if necessary: */
171 if ( (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
172 && !darwinIsInFullscreenMode(this))
173 darwinToggleFullscreenMode(this);
174}
175
176void UIMachineWindowFullscreen::sltExitNativeFullscreen(UIMachineWindow *pMachineWindow)
177{
178 /* Make sure this slot is called only under ML and next: */
179 AssertReturnVoid(vboxGlobal().osRelease() > MacOSXRelease_Lion);
180
181 /* Make sure it is NULL or 'this' window passed: */
182 if (pMachineWindow && pMachineWindow != this)
183 return;
184
185 /* Make sure this window has fullscreen logic: */
186 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
187 AssertPtrReturnVoid(pFullscreenLogic);
188
189 /* Mark window 'transitioned from fullscreen': */
190 m_fIsInFullscreenTransition = true;
191
192 /* Exit native fullscreen mode if necessary: */
193 if ( (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
194 && darwinIsInFullscreenMode(this))
195 darwinToggleFullscreenMode(this);
196}
197#endif /* VBOX_WS_MAC */
198
199void UIMachineWindowFullscreen::prepareVisualState()
200{
201 /* Call to base-class: */
202 UIMachineWindow::prepareVisualState();
203
204 /* The background has to go black: */
205 QPalette palette(centralWidget()->palette());
206 palette.setColor(centralWidget()->backgroundRole(), Qt::black);
207 centralWidget()->setPalette(palette);
208 centralWidget()->setAutoFillBackground(true);
209 setAutoFillBackground(true);
210
211#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
212 /* Prepare mini-toolbar: */
213 prepareMiniToolbar();
214#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
215
216#ifdef VBOX_WS_MAC
217 /* Native fullscreen stuff on ML and next: */
218 if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
219 {
220 /* Make sure this window has fullscreen logic: */
221 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
222 AssertPtrReturnVoid(pFullscreenLogic);
223 /* Enable fullscreen support for every screen which requires it: */
224 if (pFullscreenLogic->screensHaveSeparateSpaces() || m_uScreenId == 0)
225 darwinEnableFullscreenSupport(this);
226 /* Enable transience support for other screens: */
227 else
228 darwinEnableTransienceSupport(this);
229 /* Register to native fullscreen notifications: */
230 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowWillEnterFullScreenNotification", this,
231 UIMachineWindow::handleNativeNotification);
232 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidEnterFullScreenNotification", this,
233 UIMachineWindow::handleNativeNotification);
234 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowWillExitFullScreenNotification", this,
235 UIMachineWindow::handleNativeNotification);
236 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidExitFullScreenNotification", this,
237 UIMachineWindow::handleNativeNotification);
238 UICocoaApplication::instance()->registerToNotificationOfWindow("NSWindowDidFailToEnterFullScreenNotification", this,
239 UIMachineWindow::handleNativeNotification);
240}
241#endif /* VBOX_WS_MAC */
242}
243
244#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
245void UIMachineWindowFullscreen::prepareMiniToolbar()
246{
247 /* Make sure mini-toolbar is not restricted: */
248 if (!gEDataManager->miniToolbarEnabled(vboxGlobal().managedVMUuid()))
249 return;
250
251 /* Create mini-toolbar: */
252 m_pMiniToolBar = new UIMiniToolBar(this,
253 GeometryType_Full,
254 gEDataManager->miniToolbarAlignment(vboxGlobal().managedVMUuid()),
255 gEDataManager->autoHideMiniToolbar(vboxGlobal().managedVMUuid()));
256 AssertPtrReturnVoid(m_pMiniToolBar);
257 {
258 /* Configure mini-toolbar: */
259 m_pMiniToolBar->addMenus(actionPool()->menus());
260 connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()),
261 this, SLOT(showMinimized()), Qt::QueuedConnection);
262 connect(m_pMiniToolBar, SIGNAL(sigExitAction()),
263 actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SLOT(trigger()));
264 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
265 actionPool()->action(UIActionIndex_M_Application_S_Close), SLOT(trigger()));
266 connect(m_pMiniToolBar, SIGNAL(sigNotifyAboutWindowActivationStolen()),
267 this, SLOT(sltRevokeWindowActivation()), Qt::QueuedConnection);
268 }
269}
270#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
271
272#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
273void UIMachineWindowFullscreen::cleanupMiniToolbar()
274{
275 /* Make sure mini-toolbar was created: */
276 if (!m_pMiniToolBar)
277 return;
278
279 /* Save mini-toolbar settings: */
280 gEDataManager->setAutoHideMiniToolbar(m_pMiniToolBar->autoHide(), vboxGlobal().managedVMUuid());
281 /* Delete mini-toolbar: */
282 delete m_pMiniToolBar;
283 m_pMiniToolBar = 0;
284}
285#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
286
287void UIMachineWindowFullscreen::cleanupVisualState()
288{
289#ifdef VBOX_WS_MAC
290 /* Native fullscreen stuff on ML and next: */
291 if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
292 {
293 /* Unregister from native fullscreen notifications: */
294 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowWillEnterFullScreenNotification", this);
295 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowDidEnterFullScreenNotification", this);
296 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowWillExitFullScreenNotification", this);
297 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowDidExitFullScreenNotification", this);
298 UICocoaApplication::instance()->unregisterFromNotificationOfWindow("NSWindowDidFailToEnterFullScreenNotification", this);
299 }
300#endif /* VBOX_WS_MAC */
301
302#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
303 /* Cleanup mini-toolbar: */
304 cleanupMiniToolbar();
305#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
306
307 /* Call to base-class: */
308 UIMachineWindow::cleanupVisualState();
309}
310
311void UIMachineWindowFullscreen::placeOnScreen()
312{
313 /* Make sure this window has fullscreen logic: */
314 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
315 AssertPtrReturnVoid(pFullscreenLogic);
316
317 /* Get corresponding host-screen: */
318 const int iHostScreen = pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId);
319 /* And corresponding working area: */
320 const QRect workingArea = vboxGlobal().screenGeometry(iHostScreen);
321 Q_UNUSED(workingArea);
322
323#if defined(VBOX_WS_MAC)
324
325 /* Move window to the appropriate position: */
326 move(workingArea.topLeft());
327
328 /* Resize window to the appropriate size on Lion and previous: */
329 if (vboxGlobal().osRelease() <= MacOSXRelease_Lion)
330 resize(workingArea.size());
331 /* Resize window to the appropriate size on ML and next if it's screen has no own user-space: */
332 else if (!pFullscreenLogic->screensHaveSeparateSpaces() && m_uScreenId != 0)
333 resize(workingArea.size());
334 else
335 {
336 /* Load normal geometry first of all: */
337 QRect geo = gEDataManager->machineWindowGeometry(UIVisualStateType_Normal, m_uScreenId, vboxGlobal().managedVMUuid());
338 /* If normal geometry is null => use frame-buffer size: */
339 if (geo.isNull())
340 {
341 const UIFrameBuffer *pFrameBuffer = uisession()->frameBuffer(m_uScreenId);
342 geo = QRect(QPoint(0, 0), QSize(pFrameBuffer->width(), pFrameBuffer->height()).boundedTo(workingArea.size()));
343 }
344 /* If normal geometry still null => use default size: */
345 if (geo.isNull())
346 geo = QRect(QPoint(0, 0), QSize(800, 600).boundedTo(workingArea.size()));
347 /* Move window to the center of working-area: */
348 geo.moveCenter(workingArea.center());
349 setGeometry(geo);
350 }
351
352#elif defined(VBOX_WS_WIN)
353
354# if QT_VERSION >= 0x050000
355 /* Map window onto required screen: */
356 windowHandle()->setScreen(qApp->screens().at(iHostScreen));
357# endif /* QT_VERSION >= 0x050000 */
358 /* Set appropriate window size: */
359 resize(workingArea.size());
360# if QT_VERSION < 0x050000
361 /* Move window onto required screen: */
362 move(workingArea.topLeft());
363# endif /* QT_VERSION < 0x050000 */
364
365#elif defined(VBOX_WS_X11)
366
367 /* Determine whether we should use the native full-screen mode: */
368 const bool fUseNativeFullScreen = VBoxGlobal::supportsFullScreenMonitorsProtocolX11() &&
369 !gEDataManager->legacyFullscreenModeRequested();
370 if (fUseNativeFullScreen)
371 {
372 /* Tell recent window managers which host-screen this window should be mapped to: */
373 VBoxGlobal::setFullScreenMonitorX11(this, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));
374 }
375
376 /* Set appropriate window geometry: */
377 resize(workingArea.size());
378 move(workingArea.topLeft());
379
380#else
381
382# warning "port me"
383
384#endif
385}
386
387void UIMachineWindowFullscreen::showInNecessaryMode()
388{
389 /* Make sure window has fullscreen logic: */
390 UIMachineLogicFullscreen *pFullscreenLogic = qobject_cast<UIMachineLogicFullscreen*>(machineLogic());
391 AssertPtrReturnVoid(pFullscreenLogic);
392
393#if defined(VBOX_WS_MAC)
394
395 /* If window shouldn't be shown or mapped to some host-screen: */
396 if (!uisession()->isScreenVisible(m_uScreenId) ||
397 !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
398 {
399 /* Hide window: */
400 hide();
401 }
402 /* If window should be shown and mapped to some host-screen: */
403 else
404 {
405 /* Make sure window have appropriate geometry: */
406 placeOnScreen();
407
408 /* Simple show() for ML and next, showFullScreen() otherwise: */
409 if (vboxGlobal().osRelease() > MacOSXRelease_Lion)
410 show();
411 else
412 showFullScreen();
413
414 /* Adjust machine-view size if necessary: */
415 adjustMachineViewSize();
416
417 /* Make sure machine-view have focus: */
418 m_pMachineView->setFocus();
419 }
420
421#elif defined(VBOX_WS_WIN)
422
423 /* If window shouldn't be shown or mapped to some host-screen: */
424 if (!uisession()->isScreenVisible(m_uScreenId) ||
425 !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
426 {
427 /* Remember whether the window was minimized: */
428 if (isMinimized())
429 m_fWasMinimized = true;
430
431 /* Hide window and reset it's state to NONE: */
432 setWindowState(Qt::WindowNoState);
433 hide();
434 }
435 /* If window should be shown and mapped to some host-screen: */
436 else
437 {
438 /* Ignore if window is minimized and visible: */
439 if (isMinimized() && isVisible())
440 return;
441
442 /* Make sure window have appropriate geometry: */
443 placeOnScreen();
444
445 /* Show window: */
446 showFullScreen();
447
448 /* Restore minimized state if necessary: */
449 if (m_fWasMinimized)
450 {
451 m_fWasMinimized = false;
452 showMinimized();
453 }
454
455 /* Adjust machine-view size if necessary: */
456 adjustMachineViewSize();
457
458 /* Make sure machine-view have focus: */
459 m_pMachineView->setFocus();
460 }
461
462#elif defined(VBOX_WS_X11)
463
464 /* If window shouldn't be shown or mapped to some host-screen: */
465 if (!uisession()->isScreenVisible(m_uScreenId) ||
466 !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
467 {
468 /* Remember whether the window was minimized: */
469 if (isMinimized())
470 m_fWasMinimized = true;
471
472 /* Hide window and reset it's state to NONE: */
473 setWindowState(Qt::WindowNoState);
474 hide();
475 }
476 /* If window should be shown and mapped to some host-screen: */
477 else
478 {
479 /* Ignore if window is minimized and visible: */
480 if (isMinimized() && isVisible())
481 return;
482
483 /* Show window: */
484 showFullScreen();
485
486 /* Make sure window have appropriate geometry: */
487 placeOnScreen();
488
489 /* Restore full-screen state after placeOnScreen() call: */
490 setWindowState(Qt::WindowFullScreen);
491
492 /* Restore minimized state if necessary: */
493 if (m_fWasMinimized)
494 {
495 m_fWasMinimized = false;
496 showMinimized();
497 }
498
499 /* Adjust machine-view size if necessary: */
500 adjustMachineViewSize();
501
502 /* Make sure machine-view have focus: */
503 m_pMachineView->setFocus();
504 }
505
506#else
507
508# warning "port me"
509
510#endif
511}
512
513#if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
514void UIMachineWindowFullscreen::updateAppearanceOf(int iElement)
515{
516 /* Call to base-class: */
517 UIMachineWindow::updateAppearanceOf(iElement);
518
519 /* Update mini-toolbar: */
520 if (iElement & UIVisualElement_MiniToolBar)
521 {
522 /* If there is a mini-toolbar: */
523 if (m_pMiniToolBar)
524 {
525 /* Get snapshot(s): */
526 QString strSnapshotName;
527 if (machine().GetSnapshotCount() > 0)
528 {
529 CSnapshot snapshot = machine().GetCurrentSnapshot();
530 strSnapshotName = " (" + snapshot.GetName() + ")";
531 }
532 /* Update mini-toolbar text: */
533 m_pMiniToolBar->setText(machineName() + strSnapshotName);
534 }
535 }
536}
537#endif /* VBOX_WS_WIN || VBOX_WS_X11 */
538
539#ifdef VBOX_WS_WIN
540# if QT_VERSION >= 0x050000
541void UIMachineWindowFullscreen::showEvent(QShowEvent *pEvent)
542{
543 /* Expose workaround again,
544 * Qt devs will never fix that it seems.
545 * This time they forget to set 'Mapped'
546 * attribute for initially frame-less window. */
547 setAttribute(Qt::WA_Mapped);
548
549 /* Call to base-class: */
550 UIMachineWindow::showEvent(pEvent);
551}
552# endif /* QT_VERSION >= 0x050000 */
553#endif /* VBOX_WS_WIN */
554
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