VirtualBox

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

Last change on this file since 102493 was 100064, checked in by vboxsync, 16 months ago

FE/Qt: bugref:10421. Replacing VBOX_WS_X11 with VBOX_WS_NIX.

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