1 | /* $Id: UIMachineViewSeamless.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMachineViewSeamless 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 <QMainWindow>
|
---|
31 | #include <QResizeEvent>
|
---|
32 | #include <QTimer>
|
---|
33 | #ifdef VBOX_WS_MAC
|
---|
34 | # include <QMenuBar>
|
---|
35 | #endif /* VBOX_WS_MAC */
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UIDesktopWidgetWatchdog.h"
|
---|
39 | #include "UIExtraDataManager.h"
|
---|
40 | #include "UIFrameBuffer.h"
|
---|
41 | #include "UILoggingDefs.h"
|
---|
42 | #include "UIMachine.h"
|
---|
43 | #include "UIMachineLogicSeamless.h"
|
---|
44 | #include "UIMachineViewSeamless.h"
|
---|
45 | #include "UIMachineWindow.h"
|
---|
46 |
|
---|
47 | /* COM includes: */
|
---|
48 | #include "CConsole.h"
|
---|
49 |
|
---|
50 | /* External includes: */
|
---|
51 | #ifdef VBOX_WS_NIX
|
---|
52 | # include <limits.h>
|
---|
53 | #endif
|
---|
54 |
|
---|
55 |
|
---|
56 | UIMachineViewSeamless::UIMachineViewSeamless(UIMachineWindow *pMachineWindow, ulong uScreenId)
|
---|
57 | : UIMachineView(pMachineWindow, uScreenId)
|
---|
58 | {
|
---|
59 | /* Prepare seamless view: */
|
---|
60 | prepareSeamless();
|
---|
61 | }
|
---|
62 |
|
---|
63 | void UIMachineViewSeamless::sltAdditionsStateChanged()
|
---|
64 | {
|
---|
65 | adjustGuestScreenSize();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void UIMachineViewSeamless::sltHandleSetVisibleRegion(QRegion region)
|
---|
69 | {
|
---|
70 | /* Apply new seamless-region: */
|
---|
71 | frameBuffer()->handleSetVisibleRegion(region);
|
---|
72 | }
|
---|
73 |
|
---|
74 | bool UIMachineViewSeamless::eventFilter(QObject *pWatched, QEvent *pEvent)
|
---|
75 | {
|
---|
76 | if (pWatched != 0 && pWatched == machineWindow())
|
---|
77 | {
|
---|
78 | switch (pEvent->type())
|
---|
79 | {
|
---|
80 | case QEvent::Resize:
|
---|
81 | {
|
---|
82 | /* Send guest-resize hint only if top window resizing to required dimension: */
|
---|
83 | QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
|
---|
84 | if (pResizeEvent->size() != calculateMaxGuestSize())
|
---|
85 | break;
|
---|
86 |
|
---|
87 | /* Recalculate maximum guest size: */
|
---|
88 | setMaximumGuestSize();
|
---|
89 |
|
---|
90 | break;
|
---|
91 | }
|
---|
92 | default:
|
---|
93 | break;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | return UIMachineView::eventFilter(pWatched, pEvent);
|
---|
98 | }
|
---|
99 |
|
---|
100 | void UIMachineViewSeamless::prepareCommon()
|
---|
101 | {
|
---|
102 | /* Base class common settings: */
|
---|
103 | UIMachineView::prepareCommon();
|
---|
104 |
|
---|
105 | /* Setup size-policy: */
|
---|
106 | setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
|
---|
107 | /* Maximum size to sizehint: */
|
---|
108 | setMaximumSize(sizeHint());
|
---|
109 | /* Minimum size is ignored: */
|
---|
110 | setMinimumSize(0, 0);
|
---|
111 | /* No scrollbars: */
|
---|
112 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
113 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
114 | }
|
---|
115 |
|
---|
116 | void UIMachineViewSeamless::prepareFilters()
|
---|
117 | {
|
---|
118 | /* Base class filters: */
|
---|
119 | UIMachineView::prepareFilters();
|
---|
120 | }
|
---|
121 |
|
---|
122 | void UIMachineViewSeamless::prepareConsoleConnections()
|
---|
123 | {
|
---|
124 | /* Base class connections: */
|
---|
125 | UIMachineView::prepareConsoleConnections();
|
---|
126 |
|
---|
127 | /* Guest additions state-change updater: */
|
---|
128 | connect(uimachine(), &UIMachine::sigAdditionsStateActualChange, this, &UIMachineViewSeamless::sltAdditionsStateChanged);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void UIMachineViewSeamless::prepareSeamless()
|
---|
132 | {
|
---|
133 | /* Set seamless feature flag to the guest: */
|
---|
134 | uimachine()->setSeamlessMode(true);
|
---|
135 | }
|
---|
136 |
|
---|
137 | void UIMachineViewSeamless::cleanupSeamless()
|
---|
138 | {
|
---|
139 | /* Reset seamless feature flag if possible: */
|
---|
140 | if (uimachine()->isRunning())
|
---|
141 | uimachine()->setSeamlessMode(false);
|
---|
142 | }
|
---|
143 |
|
---|
144 | void UIMachineViewSeamless::adjustGuestScreenSize()
|
---|
145 | {
|
---|
146 | /* Step 1: Is guest-screen visible? */
|
---|
147 | if (!uimachine()->isScreenVisible(screenId()))
|
---|
148 | {
|
---|
149 | LogRel(("GUI: UIMachineViewSeamless::adjustGuestScreenSize: "
|
---|
150 | "Guest-screen #%d is not visible, adjustment is not required.\n",
|
---|
151 | screenId()));
|
---|
152 | return;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /* What are the desired and requested hints? */
|
---|
156 | const QSize sizeToApply = calculateMaxGuestSize();
|
---|
157 | const QSize desiredSizeHint = scaledBackward(sizeToApply);
|
---|
158 | const QSize requestedSizeHint = requestedGuestScreenSizeHint();
|
---|
159 |
|
---|
160 | /* Step 2: Is the guest-screen of another size than necessary? */
|
---|
161 | if (desiredSizeHint == requestedSizeHint)
|
---|
162 | {
|
---|
163 | LogRel(("GUI: UIMachineViewSeamless::adjustGuestScreenSize: "
|
---|
164 | "Desired hint %dx%d for guest-screen #%d is already in IDisplay, adjustment is not required.\n",
|
---|
165 | desiredSizeHint.width(), desiredSizeHint.height(), screenId()));
|
---|
166 | return;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /* Final step: Adjust .. */
|
---|
170 | LogRel(("GUI: UIMachineViewSeamless::adjustGuestScreenSize: "
|
---|
171 | "Desired hint %dx%d for guest-screen #%d differs from the one in IDisplay, adjustment is required.\n",
|
---|
172 | desiredSizeHint.width(), desiredSizeHint.height(), screenId()));
|
---|
173 | sltPerformGuestResize(sizeToApply);
|
---|
174 | /* And remember the size to know what we are resizing out of when we exit: */
|
---|
175 | uimachine()->setLastFullScreenSize(screenId(), scaledForward(desiredSizeHint));
|
---|
176 | }
|
---|
177 |
|
---|
178 | QRect UIMachineViewSeamless::workingArea() const
|
---|
179 | {
|
---|
180 | /* Get corresponding screen: */
|
---|
181 | int iScreen = static_cast<UIMachineLogicSeamless*>(machineLogic())->hostScreenForGuestScreen(screenId());
|
---|
182 | /* Return available geometry for that screen: */
|
---|
183 | return gpDesktop->availableGeometry(iScreen);
|
---|
184 | }
|
---|
185 |
|
---|
186 | QSize UIMachineViewSeamless::calculateMaxGuestSize() const
|
---|
187 | {
|
---|
188 | return workingArea().size();
|
---|
189 | }
|
---|