VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp@ 103977

Last change on this file since 103977 was 103538, checked in by vboxsync, 11 months ago

FE/Qt: Moving out logging stuff from UIDefs.h to separate UILoggingDefs.h; This breaks dependency of UIDefs/UICommon headers from VBox/log.h

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette