1 | /* $Id: UIMachineViewFullscreen.cpp 107169 2024-11-27 17:53:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMachineViewFullscreen class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QResizeEvent>
|
---|
31 | #include <QMainWindow>
|
---|
32 | #include <QTimer>
|
---|
33 | #ifdef VBOX_WS_MAC
|
---|
34 | # include <QMenuBar>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UIActionPoolRuntime.h"
|
---|
39 | #include "UIDesktopWidgetWatchdog.h"
|
---|
40 | #include "UIExtraDataManager.h"
|
---|
41 | #include "UIFrameBuffer.h"
|
---|
42 | #include "UILoggingDefs.h"
|
---|
43 | #include "UIMachine.h"
|
---|
44 | #include "UIMachineLogicFullscreen.h"
|
---|
45 | #include "UIMachineViewFullscreen.h"
|
---|
46 | #include "UIMachineWindow.h"
|
---|
47 |
|
---|
48 | /* External includes: */
|
---|
49 | #ifdef VBOX_WS_NIX
|
---|
50 | # include <limits.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 |
|
---|
54 | UIMachineViewFullscreen::UIMachineViewFullscreen(UIMachineWindow *pMachineWindow, ulong uScreenId)
|
---|
55 | : UIMachineView(pMachineWindow, uScreenId)
|
---|
56 | , m_fGuestAutoresizeEnabled(actionPool()->action(UIActionIndexRT_M_View_T_GuestAutoresize)->isChecked())
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | void UIMachineViewFullscreen::sltAdditionsStateChanged()
|
---|
61 | {
|
---|
62 | adjustGuestScreenSize();
|
---|
63 | }
|
---|
64 |
|
---|
65 | bool UIMachineViewFullscreen::eventFilter(QObject *pWatched, QEvent *pEvent)
|
---|
66 | {
|
---|
67 | if (pWatched != 0 && pWatched == machineWindow())
|
---|
68 | {
|
---|
69 | switch (pEvent->type())
|
---|
70 | {
|
---|
71 | case QEvent::Resize:
|
---|
72 | {
|
---|
73 | /* Send guest-resize hint only if top window resizing to required dimension: */
|
---|
74 | QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
|
---|
75 | if (pResizeEvent->size() != calculateMaxGuestSize())
|
---|
76 | break;
|
---|
77 |
|
---|
78 | /* Recalculate maximum guest size: */
|
---|
79 | setMaximumGuestSize();
|
---|
80 |
|
---|
81 | break;
|
---|
82 | }
|
---|
83 | default:
|
---|
84 | break;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | return UIMachineView::eventFilter(pWatched, pEvent);
|
---|
89 | }
|
---|
90 |
|
---|
91 | void UIMachineViewFullscreen::prepareCommon()
|
---|
92 | {
|
---|
93 | /* Base class common settings: */
|
---|
94 | UIMachineView::prepareCommon();
|
---|
95 |
|
---|
96 | /* Setup size-policy: */
|
---|
97 | setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
|
---|
98 | /* Maximum size to sizehint: */
|
---|
99 | setMaximumSize(sizeHint());
|
---|
100 | /* Minimum size is ignored: */
|
---|
101 | setMinimumSize(0, 0);
|
---|
102 | /* No scrollbars: */
|
---|
103 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
104 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
105 | }
|
---|
106 |
|
---|
107 | void UIMachineViewFullscreen::prepareFilters()
|
---|
108 | {
|
---|
109 | /* Base class filters: */
|
---|
110 | UIMachineView::prepareFilters();
|
---|
111 | }
|
---|
112 |
|
---|
113 | void UIMachineViewFullscreen::prepareConsoleConnections()
|
---|
114 | {
|
---|
115 | /* Base class connections: */
|
---|
116 | UIMachineView::prepareConsoleConnections();
|
---|
117 |
|
---|
118 | /* Guest additions state-change updater: */
|
---|
119 | connect(uimachine(), &UIMachine::sigAdditionsStateActualChange, this, &UIMachineViewFullscreen::sltAdditionsStateChanged);
|
---|
120 | }
|
---|
121 |
|
---|
122 | void UIMachineViewFullscreen::setGuestAutoresizeEnabled(bool fEnabled)
|
---|
123 | {
|
---|
124 | if (m_fGuestAutoresizeEnabled != fEnabled)
|
---|
125 | {
|
---|
126 | m_fGuestAutoresizeEnabled = fEnabled;
|
---|
127 |
|
---|
128 | if (m_fGuestAutoresizeEnabled && uimachine()->isGuestSupportsGraphics())
|
---|
129 | sltPerformGuestResize();
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | void UIMachineViewFullscreen::adjustGuestScreenSize()
|
---|
134 | {
|
---|
135 | /* Step 0: Is machine running or paused? */
|
---|
136 | if (!uimachine()->isRunning() && !uimachine()->isPaused())
|
---|
137 | {
|
---|
138 | LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
|
---|
139 | "Guest-screen #%d display is not initialized, adjustment is not possible.\n",
|
---|
140 | screenId()));
|
---|
141 | return;
|
---|
142 | }
|
---|
143 | /* Step 1: Is guest-screen visible? */
|
---|
144 | if (!uimachine()->isScreenVisible(screenId()))
|
---|
145 | {
|
---|
146 | LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
|
---|
147 | "Guest-screen #%d is not visible, adjustment is not required.\n",
|
---|
148 | screenId()));
|
---|
149 | return;
|
---|
150 | }
|
---|
151 | /* Step 2: Is guest-screen auto-resize enabled? */
|
---|
152 | if (!isGuestAutoresizeEnabled())
|
---|
153 | {
|
---|
154 | LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
|
---|
155 | "Guest-screen #%d auto-resize is disabled, adjustment is not required.\n",
|
---|
156 | screenId()));
|
---|
157 | return;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /* What are the desired and requested hints? */
|
---|
161 | const QSize sizeToApply = calculateMaxGuestSize();
|
---|
162 | const QSize desiredSizeHint = scaledBackward(sizeToApply);
|
---|
163 | const QSize requestedSizeHint = requestedGuestScreenSizeHint();
|
---|
164 |
|
---|
165 | /* Step 3: Is the guest-screen of another size than necessary? */
|
---|
166 | if (desiredSizeHint == requestedSizeHint)
|
---|
167 | {
|
---|
168 | LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
|
---|
169 | "Desired hint %dx%d for guest-screen #%d is already in IDisplay, adjustment is not required.\n",
|
---|
170 | desiredSizeHint.width(), desiredSizeHint.height(), screenId()));
|
---|
171 | return;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /* Final step: Adjust .. */
|
---|
175 | LogRel(("GUI: UIMachineViewFullscreen::adjustGuestScreenSize: "
|
---|
176 | "Desired hint %dx%d for guest-screen #%d differs from the one in IDisplay, adjustment is required.\n",
|
---|
177 | desiredSizeHint.width(), desiredSizeHint.height(), screenId()));
|
---|
178 | sltPerformGuestResize(sizeToApply);
|
---|
179 | /* And remember the size to know what we are resizing out of when we exit: */
|
---|
180 | uimachine()->setLastFullScreenSize(screenId(), scaledForward(desiredSizeHint));
|
---|
181 | }
|
---|
182 |
|
---|
183 | QRect UIMachineViewFullscreen::workingArea() const
|
---|
184 | {
|
---|
185 | /* Get corresponding screen: */
|
---|
186 | int iScreen = static_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(screenId());
|
---|
187 | /* Return available geometry for that screen: */
|
---|
188 | return gpDesktop->screenGeometry(iScreen);
|
---|
189 | }
|
---|
190 |
|
---|
191 | QSize UIMachineViewFullscreen::calculateMaxGuestSize() const
|
---|
192 | {
|
---|
193 | return workingArea().size();
|
---|
194 | }
|
---|