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