1 | /* $Id: UIDesktopWidgetWatchdog.h 76581 2019-01-01 06:24:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIDesktopWidgetWatchdog class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2015-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_globals_UIDesktopWidgetWatchdog_h
|
---|
19 | #define FEQT_INCLUDED_SRC_globals_UIDesktopWidgetWatchdog_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QObject>
|
---|
26 | #ifdef VBOX_WS_X11
|
---|
27 | # include <QVector>
|
---|
28 | # include <QRect>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | /* GUI includes: */
|
---|
32 | #include "UILibraryDefs.h"
|
---|
33 |
|
---|
34 | /* Forward declarations: */
|
---|
35 | class QScreen;
|
---|
36 |
|
---|
37 | /** Singleton QObject extension used as desktop-widget
|
---|
38 | * watchdog aware of the host-screen geometry changes. */
|
---|
39 | class SHARED_LIBRARY_STUFF UIDesktopWidgetWatchdog : public QObject
|
---|
40 | {
|
---|
41 | Q_OBJECT;
|
---|
42 |
|
---|
43 | /** Constructs desktop-widget watchdog. */
|
---|
44 | UIDesktopWidgetWatchdog();
|
---|
45 | /** Destructs desktop-widget watchdog. */
|
---|
46 | ~UIDesktopWidgetWatchdog();
|
---|
47 |
|
---|
48 | signals:
|
---|
49 |
|
---|
50 | /** Notifies about host-screen count change to @a cHostScreenCount. */
|
---|
51 | void sigHostScreenCountChanged(int cHostScreenCount);
|
---|
52 |
|
---|
53 | /** Notifies about resize for the host-screen with @a iHostScreenIndex. */
|
---|
54 | void sigHostScreenResized(int iHostScreenIndex);
|
---|
55 |
|
---|
56 | /** Notifies about work-area resize for the host-screen with @a iHostScreenIndex. */
|
---|
57 | void sigHostScreenWorkAreaResized(int iHostScreenIndex);
|
---|
58 |
|
---|
59 | #ifdef VBOX_WS_X11
|
---|
60 | /** Notifies about work-area recalculated for the host-screen with @a iHostScreenIndex. */
|
---|
61 | void sigHostScreenWorkAreaRecalculated(int iHostScreenIndex);
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | public:
|
---|
65 |
|
---|
66 | /** Returns the static instance of the desktop-widget watchdog. */
|
---|
67 | static UIDesktopWidgetWatchdog *instance() { return s_pInstance; }
|
---|
68 |
|
---|
69 | /** Creates the static instance of the desktop-widget watchdog. */
|
---|
70 | static void create();
|
---|
71 | /** Destroys the static instance of the desktop-widget watchdog. */
|
---|
72 | static void destroy();
|
---|
73 |
|
---|
74 | /** Returns overall desktop width. */
|
---|
75 | int overallDesktopWidth() const;
|
---|
76 | /** Returns overall desktop height. */
|
---|
77 | int overallDesktopHeight() const;
|
---|
78 |
|
---|
79 | /** Returns the number of host-screens currently available on the system. */
|
---|
80 | int screenCount() const;
|
---|
81 |
|
---|
82 | /** Returns primary screen index. */
|
---|
83 | int primaryScreen() const;
|
---|
84 |
|
---|
85 | /** Returns the index of the screen which contains contains @a pWidget. */
|
---|
86 | int screenNumber(const QWidget *pWidget) const;
|
---|
87 | /** Returns the index of the screen which contains contains @a point. */
|
---|
88 | int screenNumber(const QPoint &point) const;
|
---|
89 |
|
---|
90 | /** Returns the geometry of the host-screen with @a iHostScreenIndex.
|
---|
91 | * @note The default screen is used if @a iHostScreenIndex is -1. */
|
---|
92 | const QRect screenGeometry(int iHostScreenIndex = -1) const;
|
---|
93 | /** Returns the geometry of the host-screen which contains @a pWidget. */
|
---|
94 | const QRect screenGeometry(const QWidget *pWidget) const;
|
---|
95 | /** Returns the geometry of the host-screen which contains @a point. */
|
---|
96 | const QRect screenGeometry(const QPoint &point) const;
|
---|
97 |
|
---|
98 | /** Returns the available-geometry of the host-screen with @a iHostScreenIndex.
|
---|
99 | * @note The default screen is used if @a iHostScreenIndex is -1. */
|
---|
100 | const QRect availableGeometry(int iHostScreenIndex = -1) const;
|
---|
101 | /** Returns the available-geometry of the host-screen which contains @a pWidget. */
|
---|
102 | const QRect availableGeometry(const QWidget *pWidget) const;
|
---|
103 | /** Returns the available-geometry of the host-screen which contains @a point. */
|
---|
104 | const QRect availableGeometry(const QPoint &point) const;
|
---|
105 |
|
---|
106 | /** Returns overall region unifying all the host-screen geometries. */
|
---|
107 | const QRegion overallScreenRegion() const;
|
---|
108 | /** Returns overall region unifying all the host-screen available-geometries. */
|
---|
109 | const QRegion overallAvailableRegion() const;
|
---|
110 |
|
---|
111 | #ifdef VBOX_WS_X11
|
---|
112 | /** Qt5: X11: Returns whether no or fake screen detected. */
|
---|
113 | bool isFakeScreenDetected() const;
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | /** Returns device-pixel-ratio of the host-screen with @a iHostScreenIndex. */
|
---|
117 | double devicePixelRatio(int iHostScreenIndex = -1);
|
---|
118 | /** Returns device-pixel-ratio of the host-screen which contains @a pWidget. */
|
---|
119 | double devicePixelRatio(QWidget *pWidget);
|
---|
120 |
|
---|
121 | /** Returns actual device-pixel-ratio of the host-screen with @a iHostScreenIndex. */
|
---|
122 | double devicePixelRatioActual(int iHostScreenIndex = -1);
|
---|
123 | /** Returns actual device-pixel-ratio of the host-screen which contains @a pWidget. */
|
---|
124 | double devicePixelRatioActual(QWidget *pWidget);
|
---|
125 |
|
---|
126 | private slots:
|
---|
127 |
|
---|
128 | #if QT_VERSION == 0
|
---|
129 | /** Stupid moc does not warn if it cannot find headers! */
|
---|
130 | void QT_VERSION_NOT_DEFINED
|
---|
131 | #else /* QT_VERSION != 0 */
|
---|
132 | /** Handles @a pHostScreen adding. */
|
---|
133 | void sltHostScreenAdded(QScreen *pHostScreen);
|
---|
134 | /** Handles @a pHostScreen removing. */
|
---|
135 | void sltHostScreenRemoved(QScreen *pHostScreen);
|
---|
136 | /** Handles host-screen resize to passed @a geometry. */
|
---|
137 | void sltHandleHostScreenResized(const QRect &geometry);
|
---|
138 | /** Handles host-screen work-area resize to passed @a availableGeometry. */
|
---|
139 | void sltHandleHostScreenWorkAreaResized(const QRect &availableGeometry);
|
---|
140 | #endif /* QT_VERSION != 0 */
|
---|
141 |
|
---|
142 | #ifdef VBOX_WS_X11
|
---|
143 | /** Handles @a availableGeometry calculation result for the host-screen with @a iHostScreenIndex. */
|
---|
144 | void sltHandleHostScreenAvailableGeometryCalculated(int iHostScreenIndex, QRect availableGeometry);
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | private:
|
---|
148 |
|
---|
149 | /** Prepare routine. */
|
---|
150 | void prepare();
|
---|
151 | /** Cleanup routine. */
|
---|
152 | void cleanup();
|
---|
153 |
|
---|
154 | /** Holds the static instance of the desktop-widget watchdog. */
|
---|
155 | static UIDesktopWidgetWatchdog *s_pInstance;
|
---|
156 |
|
---|
157 | #ifdef VBOX_WS_X11
|
---|
158 | /** Updates host-screen configuration according to new @a cHostScreenCount.
|
---|
159 | * @note If cHostScreenCount is equal to -1 we have to acquire it ourselves. */
|
---|
160 | void updateHostScreenConfiguration(int cHostScreenCount = -1);
|
---|
161 |
|
---|
162 | /** Update available-geometry for the host-screen with @a iHostScreenIndex. */
|
---|
163 | void updateHostScreenAvailableGeometry(int iHostScreenIndex);
|
---|
164 |
|
---|
165 | /** Cleanups existing workers. */
|
---|
166 | void cleanupExistingWorkers();
|
---|
167 |
|
---|
168 | /** Holds current host-screen available-geometries. */
|
---|
169 | QVector<QRect> m_availableGeometryData;
|
---|
170 | /** Holds current workers determining host-screen available-geometries. */
|
---|
171 | QVector<QWidget*> m_availableGeometryWorkers;
|
---|
172 | #endif /* VBOX_WS_X11 */
|
---|
173 | };
|
---|
174 |
|
---|
175 | /** 'Official' name for the desktop-widget watchdog singleton. */
|
---|
176 | #define gpDesktop UIDesktopWidgetWatchdog::instance()
|
---|
177 |
|
---|
178 | #endif /* !FEQT_INCLUDED_SRC_globals_UIDesktopWidgetWatchdog_h */
|
---|
179 |
|
---|