VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.h

Last change on this file was 106061, checked in by vboxsync, 7 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
1/* $Id: UIDesktopWidgetWatchdog.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDesktopWidgetWatchdog class declaration.
4 */
5
6/*
7 * Copyright (C) 2015-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#ifndef FEQT_INCLUDED_SRC_globals_UIDesktopWidgetWatchdog_h
29#define FEQT_INCLUDED_SRC_globals_UIDesktopWidgetWatchdog_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QObject>
36#include <QWindow>
37#ifdef VBOX_WS_NIX
38# include <QRect>
39# include <QVector>
40#endif
41
42/* GUI includes: */
43#include "UILibraryDefs.h"
44
45/* Forward declarations: */
46class QScreen;
47
48#if defined(VBOX_WS_NIX) && !defined(VBOX_GUI_WITH_CUSTOMIZATIONS1)
49/** Desktop Watchdog / Synthetic Test policy type. */
50enum DesktopWatchdogPolicy_SynthTest
51{
52 DesktopWatchdogPolicy_SynthTest_Disabled,
53 DesktopWatchdogPolicy_SynthTest_ManagerOnly,
54 DesktopWatchdogPolicy_SynthTest_MachineOnly,
55 DesktopWatchdogPolicy_SynthTest_Both
56};
57Q_DECLARE_METATYPE(DesktopWatchdogPolicy_SynthTest);
58#endif /* VBOX_WS_NIX && !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
59
60/** Singleton QObject extension used as desktop-widget
61 * watchdog aware of the host-screen geometry changes. */
62class SHARED_LIBRARY_STUFF UIDesktopWidgetWatchdog : public QObject
63{
64 Q_OBJECT;
65
66 /** Constructs desktop-widget watchdog. */
67 UIDesktopWidgetWatchdog();
68 /** Destructs desktop-widget watchdog. */
69 virtual ~UIDesktopWidgetWatchdog() /* override final */;
70
71signals:
72
73 /** Notifies about host-screen count change to @a cHostScreenCount. */
74 void sigHostScreenCountChanged(int cHostScreenCount);
75
76 /** Notifies about resize for the host-screen with @a iHostScreenIndex. */
77 void sigHostScreenResized(int iHostScreenIndex);
78
79 /** Notifies about work-area resize for the host-screen with @a iHostScreenIndex. */
80 void sigHostScreenWorkAreaResized(int iHostScreenIndex);
81
82#if defined(VBOX_WS_NIX) && !defined(VBOX_GUI_WITH_CUSTOMIZATIONS1)
83 /** Notifies about work-area recalculated for the host-screen with @a iHostScreenIndex. */
84 void sigHostScreenWorkAreaRecalculated(int iHostScreenIndex);
85#endif
86
87public:
88
89 /** Returns the static instance of the desktop-widget watchdog. */
90 static UIDesktopWidgetWatchdog *instance() { return s_pInstance; }
91
92 /** Creates the static instance of the desktop-widget watchdog. */
93 static void create();
94 /** Destroys the static instance of the desktop-widget watchdog. */
95 static void destroy();
96
97 /** Returns the number of host-screens currently available on the system. */
98 static int screenCount();
99
100 /** Returns primary screen index. */
101 static int primaryScreenNumber();
102 /** Returns the index of the screen which contains contains @a pWidget. */
103 static int screenNumber(const QWidget *pWidget);
104 /** Returns the index of the screen which contains contains @a point. */
105 static int screenNumber(const QPoint &point);
106
107 /** Returns the geometry of the host @a pScreen. */
108 QRect screenGeometry(QScreen *pScreen) const;
109 /** Returns the geometry of the host-screen with @a iHostScreenIndex.
110 * @note The default screen is used if @a iHostScreenIndex is -1. */
111 QRect screenGeometry(int iHostScreenIndex = -1) const;
112 /** Returns the geometry of the host-screen which contains @a pWidget. */
113 QRect screenGeometry(const QWidget *pWidget) const;
114 /** Returns the geometry of the host-screen which contains @a point. */
115 QRect screenGeometry(const QPoint &point) const;
116
117 /** Returns the available-geometry of the host @a pScreen. */
118 QRect availableGeometry(QScreen *pScreen) const;
119 /** Returns the available-geometry of the host-screen with @a iHostScreenIndex.
120 * @note The default screen is used if @a iHostScreenIndex is -1. */
121 QRect availableGeometry(int iHostScreenIndex = -1) const;
122 /** Returns the available-geometry of the host-screen which contains @a pWidget. */
123 QRect availableGeometry(const QWidget *pWidget) const;
124 /** Returns the available-geometry of the host-screen which contains @a point. */
125 QRect availableGeometry(const QPoint &point) const;
126
127 /** Returns overall region unifying all the host-screen geometries. */
128 static QRegion overallScreenRegion();
129 /** Returns overall region unifying all the host-screen available-geometries. */
130 static QRegion overallAvailableRegion();
131
132#ifdef VBOX_WS_NIX
133 /** Qt5: X11: Returns whether no or fake screen detected. */
134 static bool isFakeScreenDetected();
135#endif
136
137 /** Returns device-pixel-ratio of the host-screen with @a iHostScreenIndex. */
138 static double devicePixelRatio(int iHostScreenIndex = -1);
139 /** Returns device-pixel-ratio of the host-screen which contains @a pWidget. */
140 static double devicePixelRatio(QWidget *pWidget);
141
142 /** Returns actual device-pixel-ratio of the host-screen with @a iHostScreenIndex. */
143 static double devicePixelRatioActual(int iHostScreenIndex = -1);
144 /** Returns actual device-pixel-ratio of the host-screen which contains @a pWidget. */
145 static double devicePixelRatioActual(QWidget *pWidget);
146
147 /** Search position for @a rectangle to make sure it is fully
148 * contained within @a boundRegion, performing resize if allowed. */
149 static QRect normalizeGeometry(const QRect &rectangle,
150 const QRegion &boundRegion,
151 bool fCanResize = true);
152 /** Ensures that the given rectangle @a rectangle is fully
153 * contained within the region @a boundRegion, performing resize if allowed. */
154 static QRect getNormalized(const QRect &rectangle,
155 const QRegion &boundRegion,
156 bool fCanResize = true);
157 /** Aligns the center of @a pWidget with the center
158 * of @a pRelative, performing resize if allowed. */
159 void centerWidget(QWidget *pWidget,
160 QWidget *pRelative,
161 bool fCanResize = true) const;
162 /** Restores and exposes the @a pWidget on desktop. */
163 static void restoreWidget(QWidget *pWidget);
164
165 /** Assigns top-level @a pWidget geometry passed as QRect coordinates.
166 * @note Take into account that this request may fail on X11. */
167 static void setTopLevelGeometry(QWidget *pWidget, int x, int y, int w, int h);
168 /** Assigns top-level @a pWidget geometry passed as @a rect.
169 * @note Take into account that this request may fail on X11. */
170 static void setTopLevelGeometry(QWidget *pWidget, const QRect &rect);
171
172 /** Activates the specified window with given @a wId. Can @a fSwitchDesktop if requested. */
173 static bool activateWindow(WId wId, bool fSwitchDesktop = true);
174
175private slots:
176
177 /** Handles @a pHostScreen adding. */
178 void sltHostScreenAdded(QScreen *pHostScreen);
179 /** Handles @a pHostScreen removing. */
180 void sltHostScreenRemoved(QScreen *pHostScreen);
181 /** Handles host-screen resize to passed @a geometry. */
182 void sltHandleHostScreenResized(const QRect &geometry);
183 /** Handles host-screen work-area resize to passed @a availableGeometry. */
184 void sltHandleHostScreenWorkAreaResized(const QRect &availableGeometry);
185
186#if defined(VBOX_WS_NIX) && !defined(VBOX_GUI_WITH_CUSTOMIZATIONS1)
187 /** Handles @a availableGeometry calculation result for the host-screen with @a iHostScreenIndex. */
188 void sltHandleHostScreenAvailableGeometryCalculated(int iHostScreenIndex, QRect availableGeometry);
189#endif
190
191private:
192
193 /** Prepare routine. */
194 void prepare();
195 /** Cleanup routine. */
196 void cleanup();
197
198 /** Returns index of passed @a pScreen. */
199 static int screenToIndex(QScreen *pScreen);
200
201 /** Returns the flipped (transposed) @a region. */
202 static QRegion flip(const QRegion &region);
203
204 /** Holds the static instance of the desktop-widget watchdog. */
205 static UIDesktopWidgetWatchdog *s_pInstance;
206
207#if defined(VBOX_WS_NIX) && !defined(VBOX_GUI_WITH_CUSTOMIZATIONS1)
208 /** Returns whether Synthetic Test is restricted according to cached policy. */
209 bool isSynchTestRestricted() const;
210
211 /** Updates host-screen configuration according to new @a cHostScreenCount.
212 * @note If cHostScreenCount is equal to -1 we have to acquire it ourselves. */
213 void updateHostScreenConfiguration(int cHostScreenCount = -1);
214
215 /** Update available-geometry for the host-screen with @a iHostScreenIndex. */
216 void updateHostScreenAvailableGeometry(int iHostScreenIndex);
217
218 /** Cleanups existing workers. */
219 void cleanupExistingWorkers();
220
221 /** Holds environment variable name for Desktop Watchdog / Synthetic Test policy type. */
222 static const QString s_strVBoxDesktopWatchdogPolicySynthTest;
223
224 /** Holds the cached Synthetic Test policy. */
225 DesktopWatchdogPolicy_SynthTest m_enmSynthTestPolicy;
226
227 /** Holds current host-screen available-geometries. */
228 QVector<QRect> m_availableGeometryData;
229 /** Holds current workers determining host-screen available-geometries. */
230 QVector<QWidget*> m_availableGeometryWorkers;
231#endif /* VBOX_WS_NIX && !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
232};
233
234/** 'Official' name for the desktop-widget watchdog singleton. */
235#define gpDesktop UIDesktopWidgetWatchdog::instance()
236
237#endif /* !FEQT_INCLUDED_SRC_globals_UIDesktopWidgetWatchdog_h */
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