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