Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qdesktopwidget.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | QDesktopScreenWidget::QDesktopScreenWidget(QScreen *screen, const QRect &geometry) | - | ||||||||||||
6 | : QWidget(nullptr, Qt::Desktop), m_screen(screen) | - | ||||||||||||
7 | { | - | ||||||||||||
8 | setVisible(false); | - | ||||||||||||
9 | if (QWindow *winHandle = windowHandle()
| 0 | ||||||||||||
10 | winHandle->setScreen(screen); never executed: winHandle->setScreen(screen); | 0 | ||||||||||||
11 | setScreenGeometry(geometry); | - | ||||||||||||
12 | } never executed: end of block | 0 | ||||||||||||
13 | - | |||||||||||||
14 | void QDesktopScreenWidget::setScreenGeometry(const QRect &geometry) | - | ||||||||||||
15 | { | - | ||||||||||||
16 | m_geometry = geometry; | - | ||||||||||||
17 | setGeometry(geometry); | - | ||||||||||||
18 | } never executed: end of block | 0 | ||||||||||||
19 | - | |||||||||||||
20 | int QDesktopScreenWidget::screenNumber() const | - | ||||||||||||
21 | { | - | ||||||||||||
22 | const QDesktopWidgetPrivate *desktopWidgetP | - | ||||||||||||
23 | = static_cast<const QDesktopWidgetPrivate *>(qt_widget_private(QApplication::desktop())); | - | ||||||||||||
24 | return never executed: desktopWidgetP->screens.indexOf(const_cast<QDesktopScreenWidget *>(this));return desktopWidgetP->screens.indexOf(const_cast<QDesktopScreenWidget *>(this)); never executed: return desktopWidgetP->screens.indexOf(const_cast<QDesktopScreenWidget *>(this)); | 0 | ||||||||||||
25 | } | - | ||||||||||||
26 | - | |||||||||||||
27 | const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const | - | ||||||||||||
28 | { | - | ||||||||||||
29 | if (__builtin_expect(!!(!widget), false)
| 0 | ||||||||||||
30 | QMessageLogger(__FILE__, 77, __PRETTY_FUNCTION__).warning("QDesktopWidget::screenGeometry(): Attempt " | - | ||||||||||||
31 | "to get the screen geometry of a null widget"); | - | ||||||||||||
32 | return never executed: QRect();return QRect(); never executed: return QRect(); | 0 | ||||||||||||
33 | } | - | ||||||||||||
34 | QRect rect = QWidgetPrivate::screenGeometry(widget); | - | ||||||||||||
35 | if (rect.isNull()
| 0 | ||||||||||||
36 | return never executed: screenGeometry(screenNumber(widget));return screenGeometry(screenNumber(widget)); never executed: return screenGeometry(screenNumber(widget)); | 0 | ||||||||||||
37 | else return never executed: rect;return rect; never executed: return rect; | 0 | ||||||||||||
38 | } | - | ||||||||||||
39 | - | |||||||||||||
40 | const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const | - | ||||||||||||
41 | { | - | ||||||||||||
42 | if (__builtin_expect(!!(!widget), false)
| 0 | ||||||||||||
43 | QMessageLogger(__FILE__, 90, __PRETTY_FUNCTION__).warning("QDesktopWidget::availableGeometry(): Attempt " | - | ||||||||||||
44 | "to get the available geometry of a null widget"); | - | ||||||||||||
45 | return never executed: QRect();return QRect(); never executed: return QRect(); | 0 | ||||||||||||
46 | } | - | ||||||||||||
47 | QRect rect = QWidgetPrivate::screenGeometry(widget); | - | ||||||||||||
48 | if (rect.isNull()
| 0 | ||||||||||||
49 | return never executed: availableGeometry(screenNumber(widget));return availableGeometry(screenNumber(widget)); never executed: return availableGeometry(screenNumber(widget)); | 0 | ||||||||||||
50 | else | - | ||||||||||||
51 | return never executed: rect;return rect; never executed: return rect; | 0 | ||||||||||||
52 | } | - | ||||||||||||
53 | - | |||||||||||||
54 | QDesktopScreenWidget *QDesktopWidgetPrivate::widgetForScreen(QScreen *qScreen) const | - | ||||||||||||
55 | { | - | ||||||||||||
56 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(screens)>::type> _container_((screens)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QDesktopScreenWidget *widget = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
57 | if (widget->screen() == qScreen
| 0 | ||||||||||||
58 | return never executed: widget;return widget; never executed: return widget; | 0 | ||||||||||||
59 | } never executed: end of block | 0 | ||||||||||||
60 | return never executed: nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||
61 | } | - | ||||||||||||
62 | - | |||||||||||||
63 | void QDesktopWidgetPrivate::_q_updateScreens() | - | ||||||||||||
64 | { | - | ||||||||||||
65 | QDesktopWidget * const q = q_func(); | - | ||||||||||||
66 | const QList<QScreen *> screenList = QGuiApplication::screens(); | - | ||||||||||||
67 | const int targetLength = screenList.length(); | - | ||||||||||||
68 | bool screenCountChanged = false; | - | ||||||||||||
69 | - | |||||||||||||
70 | - | |||||||||||||
71 | - | |||||||||||||
72 | - | |||||||||||||
73 | - | |||||||||||||
74 | QList<QDesktopScreenWidget *> newScreens; | - | ||||||||||||
75 | QList<int> changedScreens; | - | ||||||||||||
76 | QRegion virtualGeometry; | - | ||||||||||||
77 | - | |||||||||||||
78 | for (int i = 0; i < targetLength
| 0 | ||||||||||||
79 | QScreen *qScreen = screenList.at(i); | - | ||||||||||||
80 | const QRect screenGeometry = qScreen->geometry(); | - | ||||||||||||
81 | QDesktopScreenWidget *screenWidget = widgetForScreen(qScreen); | - | ||||||||||||
82 | if (screenWidget
| 0 | ||||||||||||
83 | - | |||||||||||||
84 | if (screenGeometry != screenWidget->screenGeometry()
| 0 | ||||||||||||
85 | screenWidget->setScreenGeometry(screenGeometry); | - | ||||||||||||
86 | changedScreens.push_back(i); | - | ||||||||||||
87 | } never executed: end of block | 0 | ||||||||||||
88 | } never executed: else {end of block | 0 | ||||||||||||
89 | - | |||||||||||||
90 | screenWidget = new QDesktopScreenWidget(qScreen, screenGeometry); | - | ||||||||||||
91 | QObject::connect(qScreen, qFlagLocation("2""geometryChanged(QRect)" "\0" __FILE__ ":" "138"), | - | ||||||||||||
92 | q, qFlagLocation("1""_q_updateScreens()" "\0" __FILE__ ":" "139"), Qt::QueuedConnection); | - | ||||||||||||
93 | QObject::connect(qScreen, qFlagLocation("2""availableGeometryChanged(QRect)" "\0" __FILE__ ":" "140"), | - | ||||||||||||
94 | q, qFlagLocation("1""_q_availableGeometryChanged()" "\0" __FILE__ ":" "141"), Qt::QueuedConnection); | - | ||||||||||||
95 | QObject::connect(qScreen, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "142"), | - | ||||||||||||
96 | q, qFlagLocation("1""_q_updateScreens()" "\0" __FILE__ ":" "143"), Qt::QueuedConnection); | - | ||||||||||||
97 | screenCountChanged = true; | - | ||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||
99 | - | |||||||||||||
100 | newScreens.push_back(screenWidget); | - | ||||||||||||
101 | virtualGeometry += screenGeometry; | - | ||||||||||||
102 | } never executed: end of block | 0 | ||||||||||||
103 | - | |||||||||||||
104 | - | |||||||||||||
105 | screens.swap(newScreens); | - | ||||||||||||
106 | ((!(screens.size() == targetLength)) ? qt_assert("screens.size() == targetLength",__FILE__,153) : qt_noop()); | - | ||||||||||||
107 | q->setGeometry(virtualGeometry.boundingRect()); | - | ||||||||||||
108 | - | |||||||||||||
109 | - | |||||||||||||
110 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(newScreens)>::type> _container_((newScreens)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QDesktopScreenWidget *screen = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
111 | if (!screens.contains(screen)
| 0 | ||||||||||||
112 | delete screen; | - | ||||||||||||
113 | screenCountChanged = true; | - | ||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||
115 | } never executed: end of block | 0 | ||||||||||||
116 | - | |||||||||||||
117 | - | |||||||||||||
118 | if (screenCountChanged
| 0 | ||||||||||||
119 | - | |||||||||||||
120 | - | |||||||||||||
121 | - | |||||||||||||
122 | q->screenCountChanged(targetLength); | - | ||||||||||||
123 | } never executed: end of block | 0 | ||||||||||||
124 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(changedScreens)>::type> _container_((changedScreens)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (int changedScreen = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||
125 | q->resized(changedScreen); never executed: q->resized(changedScreen); | 0 | ||||||||||||
126 | } never executed: end of block | 0 | ||||||||||||
127 | - | |||||||||||||
128 | void QDesktopWidgetPrivate::_q_availableGeometryChanged() | - | ||||||||||||
129 | { | - | ||||||||||||
130 | QDesktopWidget * const q = q_func(); | - | ||||||||||||
131 | if (QScreen *screen = qobject_cast<QScreen *>(q->sender())
| 0 | ||||||||||||
132 | q->workAreaResized(QGuiApplication::screens().indexOf(screen)); never executed: q->workAreaResized(QGuiApplication::screens().indexOf(screen)); | 0 | ||||||||||||
133 | } never executed: end of block | 0 | ||||||||||||
134 | - | |||||||||||||
135 | QDesktopWidget::QDesktopWidget() | - | ||||||||||||
136 | : QWidget(*new QDesktopWidgetPrivate, 0, Qt::Desktop) | - | ||||||||||||
137 | { | - | ||||||||||||
138 | QDesktopWidgetPrivate * const d = d_func(); | - | ||||||||||||
139 | setObjectName(QLatin1String("desktop")); | - | ||||||||||||
140 | d->_q_updateScreens(); | - | ||||||||||||
141 | connect((static_cast<QApplication *>(QCoreApplication::instance())), qFlagLocation("2""screenAdded(QScreen*)" "\0" __FILE__ ":" "188"), this, qFlagLocation("1""_q_updateScreens()" "\0" __FILE__ ":" "188")); | - | ||||||||||||
142 | connect((static_cast<QApplication *>(QCoreApplication::instance())), qFlagLocation("2""primaryScreenChanged(QScreen*)" "\0" __FILE__ ":" "189"), this, qFlagLocation("2""primaryScreenChanged()" "\0" __FILE__ ":" "189")); | - | ||||||||||||
143 | } never executed: end of block | 0 | ||||||||||||
144 | - | |||||||||||||
145 | QDesktopWidget::~QDesktopWidget() | - | ||||||||||||
146 | { | - | ||||||||||||
147 | } | - | ||||||||||||
148 | - | |||||||||||||
149 | bool QDesktopWidget::isVirtualDesktop() const | - | ||||||||||||
150 | { | - | ||||||||||||
151 | return never executed: QGuiApplication::primaryScreen()->virtualSiblings().size() > 1;return QGuiApplication::primaryScreen()->virtualSiblings().size() > 1; never executed: return QGuiApplication::primaryScreen()->virtualSiblings().size() > 1; | 0 | ||||||||||||
152 | } | - | ||||||||||||
153 | - | |||||||||||||
154 | int QDesktopWidget::primaryScreen() const | - | ||||||||||||
155 | { | - | ||||||||||||
156 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
157 | } | - | ||||||||||||
158 | - | |||||||||||||
159 | int QDesktopWidget::numScreens() const | - | ||||||||||||
160 | { | - | ||||||||||||
161 | return never executed: qMax(QGuiApplication::screens().size(), 1);return qMax(QGuiApplication::screens().size(), 1); never executed: return qMax(QGuiApplication::screens().size(), 1); | 0 | ||||||||||||
162 | } | - | ||||||||||||
163 | - | |||||||||||||
164 | QWidget *QDesktopWidget::screen(int screen) | - | ||||||||||||
165 | { | - | ||||||||||||
166 | QDesktopWidgetPrivate * const d = d_func(); | - | ||||||||||||
167 | if (screen < 0
| 0 | ||||||||||||
168 | return never executed: d->screens.at(0);return d->screens.at(0); never executed: return d->screens.at(0); | 0 | ||||||||||||
169 | return never executed: d->screens.at(screen);return d->screens.at(screen); never executed: return d->screens.at(screen); | 0 | ||||||||||||
170 | } | - | ||||||||||||
171 | - | |||||||||||||
172 | const QRect QDesktopWidget::availableGeometry(int screenNo) const | - | ||||||||||||
173 | { | - | ||||||||||||
174 | QList<QScreen *> screens = QGuiApplication::screens(); | - | ||||||||||||
175 | if (screenNo == -1
| 0 | ||||||||||||
176 | screenNo = 0; never executed: screenNo = 0; | 0 | ||||||||||||
177 | if (screenNo < 0
| 0 | ||||||||||||
178 | return never executed: QRect();return QRect(); never executed: return QRect(); | 0 | ||||||||||||
179 | else | - | ||||||||||||
180 | return never executed: screens.at(screenNo)->availableGeometry();return screens.at(screenNo)->availableGeometry(); never executed: return screens.at(screenNo)->availableGeometry(); | 0 | ||||||||||||
181 | } | - | ||||||||||||
182 | - | |||||||||||||
183 | const QRect QDesktopWidget::screenGeometry(int screenNo) const | - | ||||||||||||
184 | { | - | ||||||||||||
185 | QList<QScreen *> screens = QGuiApplication::screens(); | - | ||||||||||||
186 | if (screenNo == -1
| 0 | ||||||||||||
187 | screenNo = 0; never executed: screenNo = 0; | 0 | ||||||||||||
188 | if (screenNo < 0
| 0 | ||||||||||||
189 | return never executed: QRect();return QRect(); never executed: return QRect(); | 0 | ||||||||||||
190 | else | - | ||||||||||||
191 | return never executed: screens.at(screenNo)->geometry();return screens.at(screenNo)->geometry(); never executed: return screens.at(screenNo)->geometry(); | 0 | ||||||||||||
192 | } | - | ||||||||||||
193 | - | |||||||||||||
194 | int QDesktopWidget::screenNumber(const QWidget *w) const | - | ||||||||||||
195 | { | - | ||||||||||||
196 | if (!w
| 0 | ||||||||||||
197 | return never executed: primaryScreen();return primaryScreen(); never executed: return primaryScreen(); | 0 | ||||||||||||
198 | - | |||||||||||||
199 | const QList<QScreen *> allScreens = QGuiApplication::screens(); | - | ||||||||||||
200 | QList<QScreen *> screens = allScreens; | - | ||||||||||||
201 | if (screens.isEmpty()
| 0 | ||||||||||||
202 | return never executed: primaryScreen();return primaryScreen(); never executed: return primaryScreen(); | 0 | ||||||||||||
203 | - | |||||||||||||
204 | const QWindow *winHandle = w->windowHandle(); | - | ||||||||||||
205 | if (!winHandle
| 0 | ||||||||||||
206 | if (const
| 0 | ||||||||||||
207 | winHandle = nativeParent->windowHandle(); never executed: winHandle = nativeParent->windowHandle(); | 0 | ||||||||||||
208 | } never executed: end of block | 0 | ||||||||||||
209 | - | |||||||||||||
210 | - | |||||||||||||
211 | if (screens.count() != screens.constFirst()->virtualSiblings().count()
| 0 | ||||||||||||
212 | - | |||||||||||||
213 | - | |||||||||||||
214 | if (winHandle
| 0 | ||||||||||||
215 | if (const
| 0 | ||||||||||||
216 | screens = winScreen->virtualSiblings(); never executed: screens = winScreen->virtualSiblings(); | 0 | ||||||||||||
217 | } never executed: end of block | 0 | ||||||||||||
218 | } never executed: end of block | 0 | ||||||||||||
219 | - | |||||||||||||
220 | - | |||||||||||||
221 | - | |||||||||||||
222 | QRect frame = w->frameGeometry(); | - | ||||||||||||
223 | if (!w->isWindow()
| 0 | ||||||||||||
224 | frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0))); never executed: frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0))); | 0 | ||||||||||||
225 | const QRect nativeFrame = QHighDpi::toNativePixels(frame, winHandle); | - | ||||||||||||
226 | - | |||||||||||||
227 | QScreen *widgetScreen = nullptr; | - | ||||||||||||
228 | int largestArea = 0; | - | ||||||||||||
229 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(screens)>::type> _container_((screens)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QScreen *screen = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
230 | const QRect intersected = screen->handle()->geometry().intersected(nativeFrame); | - | ||||||||||||
231 | int area = intersected.width() * intersected.height(); | - | ||||||||||||
232 | if (largestArea < area
| 0 | ||||||||||||
233 | widgetScreen = screen; | - | ||||||||||||
234 | largestArea = area; | - | ||||||||||||
235 | } never executed: end of block | 0 | ||||||||||||
236 | } never executed: end of block | 0 | ||||||||||||
237 | return never executed: allScreens.indexOf(widgetScreen);return allScreens.indexOf(widgetScreen); never executed: return allScreens.indexOf(widgetScreen); | 0 | ||||||||||||
238 | } | - | ||||||||||||
239 | - | |||||||||||||
240 | int QDesktopWidget::screenNumber(const QPoint &p) const | - | ||||||||||||
241 | { | - | ||||||||||||
242 | const QList<QScreen *> screens = QGuiApplication::screens(); | - | ||||||||||||
243 | if (!screens.isEmpty()
| 0 | ||||||||||||
244 | const QList<QScreen *> primaryScreens = screens.first()->virtualSiblings(); | - | ||||||||||||
245 | - | |||||||||||||
246 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(primaryScreens)>::type> _container_((primaryScreens)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QScreen *screen = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
247 | if (screen->geometry().contains(p)
| 0 | ||||||||||||
248 | return never executed: screens.indexOf(screen);return screens.indexOf(screen); never executed: return screens.indexOf(screen); | 0 | ||||||||||||
249 | } never executed: end of block | 0 | ||||||||||||
250 | - | |||||||||||||
251 | - | |||||||||||||
252 | - | |||||||||||||
253 | - | |||||||||||||
254 | if (screens.count() != primaryScreens.count()
| 0 | ||||||||||||
255 | for (int i = 1; i < screens.size()
| 0 | ||||||||||||
256 | if (screens[i]->geometry().contains(p)
| 0 | ||||||||||||
257 | return never executed: i;return i; never executed: return i; | 0 | ||||||||||||
258 | } never executed: end of block | 0 | ||||||||||||
259 | } never executed: end of block | 0 | ||||||||||||
260 | } never executed: end of block | 0 | ||||||||||||
261 | return never executed: primaryScreen();return primaryScreen(); never executed: return primaryScreen(); | 0 | ||||||||||||
262 | } | - | ||||||||||||
263 | - | |||||||||||||
264 | void QDesktopWidget::resizeEvent(QResizeEvent *) | - | ||||||||||||
265 | { | - | ||||||||||||
266 | } | - | ||||||||||||
267 | - | |||||||||||||
268 | - | |||||||||||||
269 | - | |||||||||||||
Switch to Source code | Preprocessed file |