Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/xcb/qxcbscreen.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | QXcbVirtualDesktop::QXcbVirtualDesktop(QXcbConnection *connection, xcb_screen_t *screen, int number) | - | ||||||||||||
9 | : QXcbObject(connection) | - | ||||||||||||
10 | , m_screen(screen) | - | ||||||||||||
11 | , m_number(number) | - | ||||||||||||
12 | , m_xSettings(nullptr) | - | ||||||||||||
13 | { | - | ||||||||||||
14 | QByteArray cmAtomName("_NET_WM_CM_S"); | - | ||||||||||||
15 | cmAtomName += QByteArray::number(m_number); | - | ||||||||||||
16 | m_net_wm_cm_atom = connection->internAtom(cmAtomName.constData()); | - | ||||||||||||
17 | m_compositingActive = connection->getSelectionOwner(m_net_wm_cm_atom); | - | ||||||||||||
18 | - | |||||||||||||
19 | m_workArea = getWorkArea(); | - | ||||||||||||
20 | } | - | ||||||||||||
21 | - | |||||||||||||
22 | QXcbVirtualDesktop::~QXcbVirtualDesktop() | - | ||||||||||||
23 | { | - | ||||||||||||
24 | delete m_xSettings; | - | ||||||||||||
25 | } | - | ||||||||||||
26 | - | |||||||||||||
27 | QXcbScreen *QXcbVirtualDesktop::screenAt(const QPoint &pos) const | - | ||||||||||||
28 | { | - | ||||||||||||
29 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(connection()->const auto screens ())>::type> _container_((= connection()->screens())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)(); | - | ||||||||||||
30 | for (QXcbScreen *screen = *_container_.i; _container_.control; _container_.control = 0: screens) { | - | ||||||||||||
31 | if (screen->virtualDesktop() == this
| 0 | ||||||||||||
32 | return never executed: screen;return screen; never executed: return screen; | 0 | ||||||||||||
33 | } never executed: end of block | 0 | ||||||||||||
34 | return never executed: nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||
35 | } | - | ||||||||||||
36 | - | |||||||||||||
37 | void QXcbVirtualDesktop::addScreen(QPlatformScreen *s) | - | ||||||||||||
38 | { | - | ||||||||||||
39 | ((QXcbScreen *) s)->isPrimary() ? m_screens.prepend(s) : m_screens.append(s); | - | ||||||||||||
40 | } | - | ||||||||||||
41 | - | |||||||||||||
42 | void QXcbVirtualDesktop::setPrimaryScreen(QPlatformScreen *s) | - | ||||||||||||
43 | { | - | ||||||||||||
44 | const int idx = m_screens.indexOf(s); | - | ||||||||||||
45 | ((!(idx > -1)) ? qt_assert("idx > -1",__FILE__,8795) : qt_noop()); | - | ||||||||||||
46 | m_screens.swap(0, idx); | - | ||||||||||||
47 | } | - | ||||||||||||
48 | - | |||||||||||||
49 | QXcbXSettings *QXcbVirtualDesktop::xSettings() const | - | ||||||||||||
50 | { | - | ||||||||||||
51 | if (!m_xSettings) { | - | ||||||||||||
52 | QXcbVirtualDesktop *self = const_cast<QXcbVirtualDesktop *>(this); | - | ||||||||||||
53 | self->m_xSettings = new QXcbXSettings(self); | - | ||||||||||||
54 | } | - | ||||||||||||
55 | return m_xSettings; | - | ||||||||||||
56 | } | - | ||||||||||||
57 | - | |||||||||||||
58 | bool QXcbVirtualDesktop::compositingActive() const | - | ||||||||||||
59 | { | - | ||||||||||||
60 | if (connection()->hasXFixes()) | - | ||||||||||||
61 | return m_compositingActive; | - | ||||||||||||
62 | else | - | ||||||||||||
63 | return connection()->getSelectionOwner(m_net_wm_cm_atom); | - | ||||||||||||
64 | } | - | ||||||||||||
65 | - | |||||||||||||
66 | void QXcbVirtualDesktop::handleXFixesSelectionNotify(xcb_xfixes_selection_notify_event_t *notify_event) | - | ||||||||||||
67 | { | - | ||||||||||||
68 | if (notify_event->selection == m_net_wm_cm_atom) | - | ||||||||||||
69 | m_compositingActive = notify_event->owner; | - | ||||||||||||
70 | } | - | ||||||||||||
71 | - | |||||||||||||
72 | void QXcbVirtualDesktop::subscribeToXFixesSelectionNotify() | - | ||||||||||||
73 | { | - | ||||||||||||
74 | if (connection()->hasXFixes()) { | - | ||||||||||||
75 | const uint32_t mask = XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER | | - | ||||||||||||
76 | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY | | - | ||||||||||||
77 | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE; | - | ||||||||||||
78 | xcb_xfixes_select_selection_input_checked(xcb_connection(), connection()->getQtSelectionOwner(), m_net_wm_cm_atom, mask); | - | ||||||||||||
79 | } | - | ||||||||||||
80 | } | - | ||||||||||||
81 | - | |||||||||||||
82 | QRect QXcbVirtualDesktop::getWorkArea() const | - | ||||||||||||
83 | { | - | ||||||||||||
84 | QRect r; | - | ||||||||||||
85 | xcb_get_property_reply_t * workArea = | - | ||||||||||||
86 | xcb_get_property_reply(xcb_connection(), | - | ||||||||||||
87 | xcb_get_property_unchecked(xcb_connection(), false, screen()->root, | - | ||||||||||||
88 | atom(QXcbAtom::_NET_WORKAREA), | - | ||||||||||||
89 | XCB_ATOM_CARDINAL, 0, 1024), __null); | - | ||||||||||||
90 | if (workArea && workArea->type == XCB_ATOM_CARDINAL && workArea->format == 32 && workArea->value_len >= 4) { | - | ||||||||||||
91 | - | |||||||||||||
92 | - | |||||||||||||
93 | - | |||||||||||||
94 | - | |||||||||||||
95 | - | |||||||||||||
96 | - | |||||||||||||
97 | uint32_t *geom = (uint32_t*)xcb_get_property_value(workArea); | - | ||||||||||||
98 | r = QRect(geom[0], geom[1], geom[2], geom[3]); | - | ||||||||||||
99 | } else { | - | ||||||||||||
100 | r = QRect(QPoint(), size()); | - | ||||||||||||
101 | } | - | ||||||||||||
102 | free(workArea); | - | ||||||||||||
103 | return r; | - | ||||||||||||
104 | } | - | ||||||||||||
105 | - | |||||||||||||
106 | void QXcbVirtualDesktop::updateWorkArea() | - | ||||||||||||
107 | { | - | ||||||||||||
108 | QRect workArea = getWorkArea(); | - | ||||||||||||
109 | if (m_workArea != workArea
| 0 | ||||||||||||
110 | m_workArea = workArea; | - | ||||||||||||
for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_screens)>::type> _container_((m_screens)); _container_.control && _container_.i != _container_.e; | ||||||||||||||
111 | ++_container_.i, _container_.control ^= 1)for (QPlatformScreen *screen = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_screens)) | - | ||||||||||||
112 | (( never executed: QXcbScreen *)screen)->updateAvailableGeometry();((QXcbScreen *)screen)->updateAvailableGeometry(); never executed: ((QXcbScreen *)screen)->updateAvailableGeometry(); | 0 | ||||||||||||
113 | } never executed: end of block | 0 | ||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||
115 | - | |||||||||||||
116 | static inline QSizeF sizeInMillimeters(const QSize &size, const QDpi &dpi) | - | ||||||||||||
117 | { | - | ||||||||||||
118 | return QSizeF(Q_MM_PER_INCH * size.width() / dpi.first, | - | ||||||||||||
119 | Q_MM_PER_INCH * size.height() / dpi.second); | - | ||||||||||||
120 | } | - | ||||||||||||
121 | - | |||||||||||||
122 | QXcbScreen::QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDesktop, | - | ||||||||||||
123 | xcb_randr_output_t outputId, xcb_randr_get_output_info_reply_t *output, | - | ||||||||||||
124 | const xcb_xinerama_screen_info_t *xineramaScreenInfo, int xineramaScreenIdx) | - | ||||||||||||
125 | : QXcbObject(connection) | - | ||||||||||||
126 | , m_virtualDesktop(virtualDesktop) | - | ||||||||||||
127 | , m_output(outputId) | - | ||||||||||||
128 | , m_crtc(output ? output->crtc : 0L) | - | ||||||||||||
129 | , m_mode(0L) | - | ||||||||||||
130 | , m_primary(false) | - | ||||||||||||
131 | , m_rotation(XCB_RANDR_ROTATION_ROTATE_0) | - | ||||||||||||
132 | , m_outputName(getOutputName(output)) | - | ||||||||||||
133 | , m_outputSizeMillimeters(output ? QSize(output->mm_width, output->mm_height) : QSize()) | - | ||||||||||||
134 | , m_virtualSize(virtualDesktop->size()) | - | ||||||||||||
135 | , m_virtualSizeMillimeters(virtualDesktop->physicalSize()) | - | ||||||||||||
136 | , m_orientation(Qt::PrimaryOrientation) | - | ||||||||||||
137 | , m_refreshRate(60) | - | ||||||||||||
138 | , m_forcedDpi(-1) | - | ||||||||||||
139 | , m_pixelDensity(1) | - | ||||||||||||
140 | , m_hintStyle(QFontEngine::HintStyle(-1)) | - | ||||||||||||
141 | , m_noFontHinting(false) | - | ||||||||||||
142 | , m_subpixelType(QFontEngine::SubpixelAntialiasingType(-1)) | - | ||||||||||||
143 | , m_antialiasingEnabled(-1) | - | ||||||||||||
144 | { | - | ||||||||||||
145 | if (connection->hasXRandr()) { | - | ||||||||||||
146 | xcb_randr_select_input(xcb_connection(), screen()->root, true); | - | ||||||||||||
147 | xcb_randr_get_crtc_info_cookie_t crtcCookie = | - | ||||||||||||
148 | xcb_randr_get_crtc_info_unchecked(xcb_connection(), m_crtc, output ? output->timestamp : 0); | - | ||||||||||||
149 | xcb_randr_get_crtc_info_reply_t *crtc = | - | ||||||||||||
150 | xcb_randr_get_crtc_info_reply(xcb_connection(), crtcCookie, __null); | - | ||||||||||||
151 | if (crtc) { | - | ||||||||||||
152 | updateGeometry(QRect(crtc->x, crtc->y, crtc->width, crtc->height), crtc->rotation); | - | ||||||||||||
153 | updateRefreshRate(crtc->mode); | - | ||||||||||||
154 | free(crtc); | - | ||||||||||||
155 | } | - | ||||||||||||
156 | } else if (xineramaScreenInfo) { | - | ||||||||||||
157 | m_geometry = QRect(xineramaScreenInfo->x_org, xineramaScreenInfo->y_org, | - | ||||||||||||
158 | xineramaScreenInfo->width, xineramaScreenInfo->height); | - | ||||||||||||
159 | m_availableGeometry = m_geometry & m_virtualDesktop->workArea(); | - | ||||||||||||
160 | m_sizeMillimeters = sizeInMillimeters(m_geometry.size(), virtualDpi()); | - | ||||||||||||
161 | if (xineramaScreenIdx > -1) | - | ||||||||||||
162 | m_outputName += QLatin1Char('-') + QString::number(xineramaScreenIdx); | - | ||||||||||||
163 | } | - | ||||||||||||
164 | - | |||||||||||||
165 | if (m_geometry.isEmpty()) | - | ||||||||||||
166 | m_geometry = QRect(QPoint(), m_virtualSize); | - | ||||||||||||
167 | - | |||||||||||||
168 | if (m_availableGeometry.isEmpty()) | - | ||||||||||||
169 | m_availableGeometry = m_geometry & m_virtualDesktop->workArea(); | - | ||||||||||||
170 | - | |||||||||||||
171 | if (m_sizeMillimeters.isEmpty()) | - | ||||||||||||
172 | m_sizeMillimeters = m_virtualSizeMillimeters; | - | ||||||||||||
173 | - | |||||||||||||
174 | readXResources(); | - | ||||||||||||
175 | - | |||||||||||||
176 | QScopedPointer<xcb_get_window_attributes_reply_t, QScopedPointerPodDeleter> rootAttribs( | - | ||||||||||||
177 | xcb_get_window_attributes_reply(xcb_connection(), | - | ||||||||||||
178 | xcb_get_window_attributes_unchecked(xcb_connection(), screen()->root), __null)); | - | ||||||||||||
179 | const quint32 existingEventMask = rootAttribs.isNull() ? 0 : rootAttribs->your_event_mask; | - | ||||||||||||
180 | - | |||||||||||||
181 | const quint32 mask = XCB_CW_EVENT_MASK; | - | ||||||||||||
182 | const quint32 values[] = { | - | ||||||||||||
183 | - | |||||||||||||
184 | XCB_EVENT_MASK_ENTER_WINDOW | - | ||||||||||||
185 | | XCB_EVENT_MASK_LEAVE_WINDOW | - | ||||||||||||
186 | | XCB_EVENT_MASK_PROPERTY_CHANGE | - | ||||||||||||
187 | | XCB_EVENT_MASK_STRUCTURE_NOTIFY | - | ||||||||||||
188 | | existingEventMask | - | ||||||||||||
189 | }; | - | ||||||||||||
190 | - | |||||||||||||
191 | xcb_change_window_attributes(xcb_connection(), screen()->root, mask, values); | - | ||||||||||||
192 | - | |||||||||||||
193 | xcb_get_property_reply_t *reply = | - | ||||||||||||
194 | xcb_get_property_reply(xcb_connection(), | - | ||||||||||||
195 | xcb_get_property_unchecked(xcb_connection(), false, screen()->root, | - | ||||||||||||
196 | atom(QXcbAtom::_NET_SUPPORTING_WM_CHECK), | - | ||||||||||||
197 | XCB_ATOM_WINDOW, 0, 1024), __null); | - | ||||||||||||
198 | - | |||||||||||||
199 | if (reply && reply->format == 32 && reply->type == XCB_ATOM_WINDOW) { | - | ||||||||||||
200 | xcb_window_t windowManager = *((xcb_window_t *)xcb_get_property_value(reply)); | - | ||||||||||||
201 | - | |||||||||||||
202 | if (windowManager != XCB_WINDOW_NONE) { | - | ||||||||||||
203 | xcb_get_property_reply_t *windowManagerReply = | - | ||||||||||||
204 | xcb_get_property_reply(xcb_connection(), | - | ||||||||||||
205 | xcb_get_property_unchecked(xcb_connection(), false, windowManager, | - | ||||||||||||
206 | atom(QXcbAtom::_NET_WM_NAME), | - | ||||||||||||
207 | atom(QXcbAtom::UTF8_STRING), 0, 1024), __null); | - | ||||||||||||
208 | if (windowManagerReply && windowManagerReply->format == 8 && windowManagerReply->type == atom(QXcbAtom::UTF8_STRING)) { | - | ||||||||||||
209 | m_windowManagerName = QString::fromUtf8((const char *)xcb_get_property_value(windowManagerReply), xcb_get_property_value_length(windowManagerReply)); | - | ||||||||||||
210 | } | - | ||||||||||||
211 | - | |||||||||||||
212 | free(windowManagerReply); | - | ||||||||||||
213 | } | - | ||||||||||||
214 | } | - | ||||||||||||
215 | free(reply); | - | ||||||||||||
216 | - | |||||||||||||
217 | const xcb_query_extension_reply_t *sync_reply = xcb_get_extension_data(xcb_connection(), &xcb_sync_id); | - | ||||||||||||
218 | if (!sync_reply || !sync_reply->present) | - | ||||||||||||
219 | m_syncRequestSupported = false; | - | ||||||||||||
220 | else | - | ||||||||||||
221 | m_syncRequestSupported = true; | - | ||||||||||||
222 | - | |||||||||||||
223 | xcb_depth_iterator_t depth_iterator = | - | ||||||||||||
224 | xcb_screen_allowed_depths_iterator(screen()); | - | ||||||||||||
225 | - | |||||||||||||
226 | while (depth_iterator.rem) { | - | ||||||||||||
227 | xcb_depth_t *depth = depth_iterator.data; | - | ||||||||||||
228 | xcb_visualtype_iterator_t visualtype_iterator = | - | ||||||||||||
229 | xcb_depth_visuals_iterator(depth); | - | ||||||||||||
230 | - | |||||||||||||
231 | while (visualtype_iterator.rem) { | - | ||||||||||||
232 | xcb_visualtype_t *visualtype = visualtype_iterator.data; | - | ||||||||||||
233 | m_visuals.insert(visualtype->visual_id, *visualtype); | - | ||||||||||||
234 | m_visualDepths.insert(visualtype->visual_id, depth->depth); | - | ||||||||||||
235 | xcb_visualtype_next(&visualtype_iterator); | - | ||||||||||||
236 | } | - | ||||||||||||
237 | - | |||||||||||||
238 | xcb_depth_next(&depth_iterator); | - | ||||||||||||
239 | } | - | ||||||||||||
240 | - | |||||||||||||
241 | m_cursor = new QXcbCursor(connection, this); | - | ||||||||||||
242 | } | - | ||||||||||||
243 | - | |||||||||||||
244 | QXcbScreen::~QXcbScreen() | - | ||||||||||||
245 | { | - | ||||||||||||
246 | delete m_cursor; | - | ||||||||||||
247 | } | - | ||||||||||||
248 | - | |||||||||||||
249 | QString QXcbScreen::getOutputName(xcb_randr_get_output_info_reply_t *outputInfo) | - | ||||||||||||
250 | { | - | ||||||||||||
251 | QString name; | - | ||||||||||||
252 | if (outputInfo) { | - | ||||||||||||
253 | name = QString::fromUtf8((const char*)xcb_randr_get_output_info_name(outputInfo), | - | ||||||||||||
254 | xcb_randr_get_output_info_name_length(outputInfo)); | - | ||||||||||||
255 | } else { | - | ||||||||||||
256 | QByteArray displayName = connection()->displayName(); | - | ||||||||||||
257 | int dotPos = displayName.lastIndexOf('.'); | - | ||||||||||||
258 | if (dotPos != -1) | - | ||||||||||||
259 | displayName.truncate(dotPos); | - | ||||||||||||
260 | name = QString::fromLocal8Bit(displayName) + QLatin1Char('.') | - | ||||||||||||
261 | + QString::number(m_virtualDesktop->number()); | - | ||||||||||||
262 | } | - | ||||||||||||
263 | return name; | - | ||||||||||||
264 | } | - | ||||||||||||
265 | - | |||||||||||||
266 | QWindow *QXcbScreen::topLevelAt(const QPoint &p) const | - | ||||||||||||
267 | { | - | ||||||||||||
268 | xcb_window_t root = screen()->root; | - | ||||||||||||
269 | - | |||||||||||||
270 | int x = p.x(); | - | ||||||||||||
271 | int y = p.y(); | - | ||||||||||||
272 | - | |||||||||||||
273 | xcb_window_t parent = root; | - | ||||||||||||
274 | xcb_window_t child = root; | - | ||||||||||||
275 | - | |||||||||||||
276 | do { | - | ||||||||||||
277 | xcb_translate_coordinates_cookie_t translate_cookie = | - | ||||||||||||
278 | xcb_translate_coordinates_unchecked(xcb_connection(), parent, child, x, y); | - | ||||||||||||
279 | - | |||||||||||||
280 | xcb_translate_coordinates_reply_t *translate_reply = | - | ||||||||||||
281 | xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, __null); | - | ||||||||||||
282 | - | |||||||||||||
283 | if (!translate_reply) { | - | ||||||||||||
284 | return 0; | - | ||||||||||||
285 | } | - | ||||||||||||
286 | - | |||||||||||||
287 | parent = child; | - | ||||||||||||
288 | child = translate_reply->child; | - | ||||||||||||
289 | x = translate_reply->dst_x; | - | ||||||||||||
290 | y = translate_reply->dst_y; | - | ||||||||||||
291 | - | |||||||||||||
292 | free(translate_reply); | - | ||||||||||||
293 | - | |||||||||||||
294 | if (!child || child == root) | - | ||||||||||||
295 | return 0; | - | ||||||||||||
296 | - | |||||||||||||
297 | QPlatformWindow *platformWindow = connection()->platformWindowFromId(child); | - | ||||||||||||
298 | if (platformWindow) | - | ||||||||||||
299 | return platformWindow->window(); | - | ||||||||||||
300 | } while (parent != child); | - | ||||||||||||
301 | - | |||||||||||||
302 | return 0; | - | ||||||||||||
303 | } | - | ||||||||||||
304 | - | |||||||||||||
305 | void QXcbScreen::windowShown(QXcbWindow *window) | - | ||||||||||||
306 | { | - | ||||||||||||
307 | - | |||||||||||||
308 | if (!connection()->startupId().isEmpty() && window->window()->isTopLevel()) { | - | ||||||||||||
309 | sendStartupMessage(([]() -> QByteArray { enum { Size = sizeof("remove: ID=") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "remove: ID=" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()) + connection()->startupId()); | - | ||||||||||||
310 | connection()->clearStartupId(); | - | ||||||||||||
311 | } | - | ||||||||||||
312 | } | - | ||||||||||||
313 | - | |||||||||||||
314 | QSurfaceFormat QXcbScreen::surfaceFormatFor(const QSurfaceFormat &format) const | - | ||||||||||||
315 | { | - | ||||||||||||
316 | const xcb_visualid_t xcb_visualid = connection()->hasDefaultVisualId()
| 0-4190 | ||||||||||||
317 | : screen()->root_visual; | - | ||||||||||||
318 | const xcb_visualtype_t *xcb_visualtype = visualForId(xcb_visualid); | - | ||||||||||||
319 | - | |||||||||||||
320 | const int redSize = qPopulationCount(xcb_visualtype->red_mask); | - | ||||||||||||
321 | const int greenSize = qPopulationCount(xcb_visualtype->green_mask); | - | ||||||||||||
322 | const int blueSize = qPopulationCount(xcb_visualtype->blue_mask); | - | ||||||||||||
323 | - | |||||||||||||
324 | QSurfaceFormat result = format; | - | ||||||||||||
325 | - | |||||||||||||
326 | if (result.redBufferSize() < 0
| 40-4150 | ||||||||||||
327 | result.setRedBufferSize(redSize); executed 4150 times by 126 tests: result.setRedBufferSize(redSize); Executed by:
| 4150 | ||||||||||||
328 | - | |||||||||||||
329 | if (result.greenBufferSize() < 0
| 40-4150 | ||||||||||||
330 | result.setGreenBufferSize(greenSize); executed 4150 times by 126 tests: result.setGreenBufferSize(greenSize); Executed by:
| 4150 | ||||||||||||
331 | - | |||||||||||||
332 | if (result.blueBufferSize() < 0
| 40-4150 | ||||||||||||
333 | result.setBlueBufferSize(blueSize); executed 4150 times by 126 tests: result.setBlueBufferSize(blueSize); Executed by:
| 4150 | ||||||||||||
334 | - | |||||||||||||
335 | return executed 4190 times by 126 tests: result;return result; Executed by:
executed 4190 times by 126 tests: return result; Executed by:
| 4190 | ||||||||||||
336 | } | - | ||||||||||||
337 | - | |||||||||||||
338 | const xcb_visualtype_t *QXcbScreen::visualForFormat(const QSurfaceFormat &format) const | - | ||||||||||||
339 | { | - | ||||||||||||
340 | const xcb_visualtype_t *candidate = nullptr; | - | ||||||||||||
341 | - | |||||||||||||
342 | for (const xcb_visualtype_t &xcb_visualtype : m_visuals) { | - | ||||||||||||
343 | - | |||||||||||||
344 | const int redSize = qPopulationCount(xcb_visualtype.red_mask); | - | ||||||||||||
345 | const int greenSize = qPopulationCount(xcb_visualtype.green_mask); | - | ||||||||||||
346 | const int blueSize = qPopulationCount(xcb_visualtype.blue_mask); | - | ||||||||||||
347 | const int alphaSize = depthOfVisual(xcb_visualtype.visual_id) - redSize - greenSize - blueSize; | - | ||||||||||||
348 | - | |||||||||||||
349 | if (format.redBufferSize() != -1
| 0-133 | ||||||||||||
350 | continue; never executed: continue; | 0 | ||||||||||||
351 | - | |||||||||||||
352 | if (format.greenBufferSize() != -1
| 0-133 | ||||||||||||
353 | continue; never executed: continue; | 0 | ||||||||||||
354 | - | |||||||||||||
355 | if (format.blueBufferSize() != -1
| 0-133 | ||||||||||||
356 | continue; never executed: continue; | 0 | ||||||||||||
357 | - | |||||||||||||
358 | if (format.alphaBufferSize() != -1
| 0-133 | ||||||||||||
359 | continue; never executed: continue; | 0 | ||||||||||||
360 | - | |||||||||||||
361 | - | |||||||||||||
362 | if (qCountTrailingZeroBits(xcb_visualtype.blue_mask) == 0
| 0-133 | ||||||||||||
363 | return executed 133 times by 12 tests: &xcb_visualtype;return &xcb_visualtype; Executed by:
executed 133 times by 12 tests: return &xcb_visualtype; Executed by:
| 133 | ||||||||||||
364 | - | |||||||||||||
365 | - | |||||||||||||
366 | - | |||||||||||||
367 | if (!candidate
| 0 | ||||||||||||
368 | candidate = &xcb_visualtype; never executed: candidate = &xcb_visualtype; | 0 | ||||||||||||
369 | } never executed: end of block | 0 | ||||||||||||
370 | - | |||||||||||||
371 | return never executed: return candidate; never executed: candidate;return candidate; never executed: return candidate; | 0 | ||||||||||||
372 | } | - | ||||||||||||
373 | - | |||||||||||||
374 | void QXcbScreen::sendStartupMessage(const QByteArray &message) const | - | ||||||||||||
375 | { | - | ||||||||||||
376 | xcb_window_t rootWindow = root(); | - | ||||||||||||
377 | - | |||||||||||||
378 | xcb_client_message_event_t ev; | - | ||||||||||||
379 | ev.response_type = 33; | - | ||||||||||||
380 | ev.format = 8; | - | ||||||||||||
381 | ev.type = connection()->atom(QXcbAtom::_NET_STARTUP_INFO_BEGIN); | - | ||||||||||||
382 | ev.sequence = 0; | - | ||||||||||||
383 | ev.window = rootWindow; | - | ||||||||||||
384 | int sent = 0; | - | ||||||||||||
385 | int length = message.length() + 1; | - | ||||||||||||
386 | const char *data = message.constData(); | - | ||||||||||||
387 | do { | - | ||||||||||||
388 | if (sent == 20) | - | ||||||||||||
389 | ev.type = connection()->atom(QXcbAtom::_NET_STARTUP_INFO); | - | ||||||||||||
390 | - | |||||||||||||
391 | const int start = sent; | - | ||||||||||||
392 | const int numBytes = qMin(length - start, 20); | - | ||||||||||||
393 | memcpy(ev.data.data8, data + start, numBytes); | - | ||||||||||||
394 | xcb_send_event(connection()->xcb_connection(), false, rootWindow, XCB_EVENT_MASK_PROPERTY_CHANGE, (const char *) &ev); | - | ||||||||||||
395 | - | |||||||||||||
396 | sent += numBytes; | - | ||||||||||||
397 | } while (sent < length); | - | ||||||||||||
398 | } | - | ||||||||||||
399 | - | |||||||||||||
400 | const xcb_visualtype_t *QXcbScreen::visualForId(xcb_visualid_t visualid) const | - | ||||||||||||
401 | { | - | ||||||||||||
402 | QMap<xcb_visualid_t, xcb_visualtype_t>::const_iterator it = m_visuals.find(visualid); | - | ||||||||||||
403 | if (it == m_visuals.constEnd()) | - | ||||||||||||
404 | return 0; | - | ||||||||||||
405 | return &*it; | - | ||||||||||||
406 | } | - | ||||||||||||
407 | - | |||||||||||||
408 | quint8 QXcbScreen::depthOfVisual(xcb_visualid_t visualid) const | - | ||||||||||||
409 | { | - | ||||||||||||
410 | QMap<xcb_visualid_t, quint8>::const_iterator it = m_visualDepths.find(visualid); | - | ||||||||||||
411 | if (it == m_visualDepths.constEnd()) | - | ||||||||||||
412 | return 0; | - | ||||||||||||
413 | return *it; | - | ||||||||||||
414 | } | - | ||||||||||||
415 | - | |||||||||||||
416 | QImage::Format QXcbScreen::format() const | - | ||||||||||||
417 | { | - | ||||||||||||
418 | return executed 72809 times by 105 tests: QImage::Format_RGB32;qt_xcb_imageFormatForVisual(connection(), screen()->root_depth, visualForId(screen()->root_visual));return qt_xcb_imageFormatForVisual(connection(), screen()->root_depth, visualForId(screen()->root_visual)); Executed by:
executed 72809 times by 105 tests: return qt_xcb_imageFormatForVisual(connection(), screen()->root_depth, visualForId(screen()->root_visual)); Executed by:
| 72809 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | QDpi QXcbScreen::virtualDpi() const | - | ||||||||||||
422 | { | - | ||||||||||||
423 | return QDpi(Q_MM_PER_INCH * m_virtualSize.width() / m_virtualSizeMillimeters.width(), | - | ||||||||||||
424 | Q_MM_PER_INCH * m_virtualSize.height() / m_virtualSizeMillimeters.height()); | - | ||||||||||||
425 | } | - | ||||||||||||
426 | - | |||||||||||||
427 | - | |||||||||||||
428 | QDpi QXcbScreen::logicalDpi() const | - | ||||||||||||
429 | { | - | ||||||||||||
430 | static const int overrideDpi = qEnvironmentVariableIntValue("QT_FONT_DPI"); | - | ||||||||||||
431 | if (overrideDpi) | - | ||||||||||||
432 | return QDpi(overrideDpi, overrideDpi); | - | ||||||||||||
433 | - | |||||||||||||
434 | if (m_forcedDpi > 0) { | - | ||||||||||||
435 | return QDpi(m_forcedDpi, m_forcedDpi); | - | ||||||||||||
436 | } | - | ||||||||||||
437 | return virtualDpi(); | - | ||||||||||||
438 | } | - | ||||||||||||
439 | - | |||||||||||||
440 | qreal QXcbScreen::pixelDensity() const | - | ||||||||||||
441 | { | - | ||||||||||||
442 | return m_pixelDensity; | - | ||||||||||||
443 | } | - | ||||||||||||
444 | - | |||||||||||||
445 | QPlatformCursor *QXcbScreen::cursor() const | - | ||||||||||||
446 | { | - | ||||||||||||
447 | return m_cursor; | - | ||||||||||||
448 | } | - | ||||||||||||
449 | - | |||||||||||||
450 | void QXcbScreen::setOutput(xcb_randr_output_t outputId, | - | ||||||||||||
451 | xcb_randr_get_output_info_reply_t *outputInfo) | - | ||||||||||||
452 | { | - | ||||||||||||
453 | m_output = outputId; | - | ||||||||||||
454 | m_crtc = outputInfo ? outputInfo->crtc : 0L; | - | ||||||||||||
455 | m_mode = 0L; | - | ||||||||||||
456 | m_outputName = getOutputName(outputInfo); | - | ||||||||||||
457 | - | |||||||||||||
458 | } | - | ||||||||||||
459 | - | |||||||||||||
460 | int QXcbScreen::virtualDesktopNumberStatic(const QScreen *screen) | - | ||||||||||||
461 | { | - | ||||||||||||
462 | if (screen && screen->handle()) | - | ||||||||||||
463 | return static_cast<const QXcbScreen *>(screen->handle())->screenNumber(); | - | ||||||||||||
464 | - | |||||||||||||
465 | return 0; | - | ||||||||||||
466 | } | - | ||||||||||||
467 | void QXcbScreen::handleScreenChange(xcb_randr_screen_change_notify_event_t *change_event) | - | ||||||||||||
468 | { | - | ||||||||||||
469 | - | |||||||||||||
470 | - | |||||||||||||
471 | - | |||||||||||||
472 | if (change_event->rotation == m_rotation) | - | ||||||||||||
473 | return; | - | ||||||||||||
474 | - | |||||||||||||
475 | m_rotation = change_event->rotation; | - | ||||||||||||
476 | switch (m_rotation) { | - | ||||||||||||
477 | case XCB_RANDR_ROTATION_ROTATE_0: | - | ||||||||||||
478 | m_orientation = Qt::LandscapeOrientation; | - | ||||||||||||
479 | m_virtualSize.setWidth(change_event->width); | - | ||||||||||||
480 | m_virtualSize.setHeight(change_event->height); | - | ||||||||||||
481 | m_virtualSizeMillimeters.setWidth(change_event->mwidth); | - | ||||||||||||
482 | m_virtualSizeMillimeters.setHeight(change_event->mheight); | - | ||||||||||||
483 | break; | - | ||||||||||||
484 | case XCB_RANDR_ROTATION_ROTATE_90: | - | ||||||||||||
485 | m_orientation = Qt::PortraitOrientation; | - | ||||||||||||
486 | m_virtualSize.setWidth(change_event->height); | - | ||||||||||||
487 | m_virtualSize.setHeight(change_event->width); | - | ||||||||||||
488 | m_virtualSizeMillimeters.setWidth(change_event->mheight); | - | ||||||||||||
489 | m_virtualSizeMillimeters.setHeight(change_event->mwidth); | - | ||||||||||||
490 | break; | - | ||||||||||||
491 | case XCB_RANDR_ROTATION_ROTATE_180: | - | ||||||||||||
492 | m_orientation = Qt::InvertedLandscapeOrientation; | - | ||||||||||||
493 | m_virtualSize.setWidth(change_event->width); | - | ||||||||||||
494 | m_virtualSize.setHeight(change_event->height); | - | ||||||||||||
495 | m_virtualSizeMillimeters.setWidth(change_event->mwidth); | - | ||||||||||||
496 | m_virtualSizeMillimeters.setHeight(change_event->mheight); | - | ||||||||||||
497 | break; | - | ||||||||||||
498 | case XCB_RANDR_ROTATION_ROTATE_270: | - | ||||||||||||
499 | m_orientation = Qt::InvertedPortraitOrientation; | - | ||||||||||||
500 | m_virtualSize.setWidth(change_event->height); | - | ||||||||||||
501 | m_virtualSize.setHeight(change_event->width); | - | ||||||||||||
502 | m_virtualSizeMillimeters.setWidth(change_event->mheight); | - | ||||||||||||
503 | m_virtualSizeMillimeters.setHeight(change_event->mwidth); | - | ||||||||||||
504 | break; | - | ||||||||||||
505 | - | |||||||||||||
506 | - | |||||||||||||
507 | case XCB_RANDR_ROTATION_REFLECT_X: break; | - | ||||||||||||
508 | case XCB_RANDR_ROTATION_REFLECT_Y: break; | - | ||||||||||||
509 | } | - | ||||||||||||
510 | - | |||||||||||||
511 | updateGeometry(change_event->timestamp); | - | ||||||||||||
512 | - | |||||||||||||
513 | QWindowSystemInterface::handleScreenOrientationChange(QPlatformScreen::screen(), m_orientation); | - | ||||||||||||
514 | - | |||||||||||||
515 | QDpi ldpi = logicalDpi(); | - | ||||||||||||
516 | QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QPlatformScreen::screen(), ldpi.first, ldpi.second); | - | ||||||||||||
517 | } | - | ||||||||||||
518 | - | |||||||||||||
519 | void QXcbScreen::updateGeometry(xcb_timestamp_t timestamp) | - | ||||||||||||
520 | { | - | ||||||||||||
521 | if (!connection()->hasXRandr()) | - | ||||||||||||
522 | return; | - | ||||||||||||
523 | - | |||||||||||||
524 | xcb_randr_get_crtc_info_cookie_t crtcCookie = | - | ||||||||||||
525 | xcb_randr_get_crtc_info_unchecked(xcb_connection(), m_crtc, timestamp); | - | ||||||||||||
526 | xcb_randr_get_crtc_info_reply_t *crtc = | - | ||||||||||||
527 | xcb_randr_get_crtc_info_reply(xcb_connection(), crtcCookie, __null); | - | ||||||||||||
528 | if (crtc) { | - | ||||||||||||
529 | updateGeometry(QRect(crtc->x, crtc->y, crtc->width, crtc->height), crtc->rotation); | - | ||||||||||||
530 | free(crtc); | - | ||||||||||||
531 | } | - | ||||||||||||
532 | } | - | ||||||||||||
533 | - | |||||||||||||
534 | void QXcbScreen::updateGeometry(const QRect &geom, uint8_t rotation) | - | ||||||||||||
535 | { | - | ||||||||||||
536 | QRect xGeometry = geom; | - | ||||||||||||
537 | switch (rotation) { | - | ||||||||||||
538 | case XCB_RANDR_ROTATION_ROTATE_0: | - | ||||||||||||
539 | m_orientation = Qt::LandscapeOrientation; | - | ||||||||||||
540 | m_sizeMillimeters = m_outputSizeMillimeters; | - | ||||||||||||
541 | break; | - | ||||||||||||
542 | case XCB_RANDR_ROTATION_ROTATE_90: | - | ||||||||||||
543 | m_orientation = Qt::PortraitOrientation; | - | ||||||||||||
544 | m_sizeMillimeters = m_outputSizeMillimeters.transposed(); | - | ||||||||||||
545 | break; | - | ||||||||||||
546 | case XCB_RANDR_ROTATION_ROTATE_180: | - | ||||||||||||
547 | m_orientation = Qt::InvertedLandscapeOrientation; | - | ||||||||||||
548 | m_sizeMillimeters = m_outputSizeMillimeters; | - | ||||||||||||
549 | break; | - | ||||||||||||
550 | case XCB_RANDR_ROTATION_ROTATE_270: | - | ||||||||||||
551 | m_orientation = Qt::InvertedPortraitOrientation; | - | ||||||||||||
552 | m_sizeMillimeters = m_outputSizeMillimeters.transposed(); | - | ||||||||||||
553 | break; | - | ||||||||||||
554 | } | - | ||||||||||||
555 | - | |||||||||||||
556 | - | |||||||||||||
557 | - | |||||||||||||
558 | - | |||||||||||||
559 | if (m_sizeMillimeters.isEmpty()) | - | ||||||||||||
560 | m_sizeMillimeters = sizeInMillimeters(xGeometry.size(), virtualDpi()); | - | ||||||||||||
561 | - | |||||||||||||
562 | qreal dpi = xGeometry.width() / physicalSize().width() * qreal(25.4); | - | ||||||||||||
563 | m_pixelDensity = qRound(dpi/96); | - | ||||||||||||
564 | m_geometry = QRect(xGeometry.topLeft(), xGeometry.size()); | - | ||||||||||||
565 | m_availableGeometry = xGeometry & m_virtualDesktop->workArea(); | - | ||||||||||||
566 | QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), m_geometry, m_availableGeometry); | - | ||||||||||||
567 | } | - | ||||||||||||
568 | - | |||||||||||||
569 | void QXcbScreen::updateAvailableGeometry() | - | ||||||||||||
570 | { | - | ||||||||||||
571 | QRect availableGeometry = m_geometry & m_virtualDesktop->workArea(); | - | ||||||||||||
572 | if (m_availableGeometry != availableGeometry) { | - | ||||||||||||
573 | m_availableGeometry = availableGeometry; | - | ||||||||||||
574 | QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), m_geometry, m_availableGeometry); | - | ||||||||||||
575 | } | - | ||||||||||||
576 | } | - | ||||||||||||
577 | - | |||||||||||||
578 | void QXcbScreen::updateRefreshRate(xcb_randr_mode_t mode) | - | ||||||||||||
579 | { | - | ||||||||||||
580 | if (!connection()->hasXRandr()) | - | ||||||||||||
581 | return; | - | ||||||||||||
582 | - | |||||||||||||
583 | if (m_mode == mode) | - | ||||||||||||
584 | return; | - | ||||||||||||
585 | - | |||||||||||||
586 | - | |||||||||||||
587 | - | |||||||||||||
588 | xcb_randr_get_screen_resources_current_cookie_t resourcesCookie = | - | ||||||||||||
589 | xcb_randr_get_screen_resources_current_unchecked(xcb_connection(), screen()->root); | - | ||||||||||||
590 | xcb_randr_get_screen_resources_current_reply_t *resources = | - | ||||||||||||
591 | xcb_randr_get_screen_resources_current_reply(xcb_connection(), resourcesCookie, __null); | - | ||||||||||||
592 | if (resources) { | - | ||||||||||||
593 | xcb_randr_mode_info_iterator_t modesIter = | - | ||||||||||||
594 | xcb_randr_get_screen_resources_current_modes_iterator(resources); | - | ||||||||||||
595 | for (; modesIter.rem; xcb_randr_mode_info_next(&modesIter)) { | - | ||||||||||||
596 | xcb_randr_mode_info_t *modeInfo = modesIter.data; | - | ||||||||||||
597 | if (modeInfo->id == mode) { | - | ||||||||||||
598 | const uint32_t dotCount = modeInfo->htotal * modeInfo->vtotal; | - | ||||||||||||
599 | m_refreshRate = (dotCount != 0) ? modeInfo->dot_clock / dotCount : 0; | - | ||||||||||||
600 | m_mode = mode; | - | ||||||||||||
601 | break; | - | ||||||||||||
602 | } | - | ||||||||||||
603 | } | - | ||||||||||||
604 | - | |||||||||||||
605 | free(resources); | - | ||||||||||||
606 | QWindowSystemInterface::handleScreenRefreshRateChange(QPlatformScreen::screen(), m_refreshRate); | - | ||||||||||||
607 | } | - | ||||||||||||
608 | } | - | ||||||||||||
609 | - | |||||||||||||
610 | QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) const | - | ||||||||||||
611 | { | - | ||||||||||||
612 | if (width == 0 || height == 0) | - | ||||||||||||
613 | return QPixmap(); | - | ||||||||||||
614 | - | |||||||||||||
615 | - | |||||||||||||
616 | QXcbScreen *screen = const_cast<QXcbScreen *>(this); | - | ||||||||||||
617 | xcb_window_t root = screen->root(); | - | ||||||||||||
618 | - | |||||||||||||
619 | if (window == 0) | - | ||||||||||||
620 | window = root; | - | ||||||||||||
621 | - | |||||||||||||
622 | xcb_get_geometry_cookie_t geometry_cookie = xcb_get_geometry_unchecked(xcb_connection(), window); | - | ||||||||||||
623 | - | |||||||||||||
624 | xcb_get_geometry_reply_t *reply = | - | ||||||||||||
625 | xcb_get_geometry_reply(xcb_connection(), geometry_cookie, __null); | - | ||||||||||||
626 | - | |||||||||||||
627 | if (!reply) { | - | ||||||||||||
628 | return QPixmap(); | - | ||||||||||||
629 | } | - | ||||||||||||
630 | - | |||||||||||||
631 | if (width < 0) | - | ||||||||||||
632 | width = reply->width - x; | - | ||||||||||||
633 | if (height < 0) | - | ||||||||||||
634 | height = reply->height - y; | - | ||||||||||||
635 | - | |||||||||||||
636 | geometry_cookie = xcb_get_geometry_unchecked(xcb_connection(), root); | - | ||||||||||||
637 | xcb_get_geometry_reply_t *root_reply = | - | ||||||||||||
638 | xcb_get_geometry_reply(xcb_connection(), geometry_cookie, __null); | - | ||||||||||||
639 | - | |||||||||||||
640 | if (!root_reply) { | - | ||||||||||||
641 | free(reply); | - | ||||||||||||
642 | return QPixmap(); | - | ||||||||||||
643 | } | - | ||||||||||||
644 | - | |||||||||||||
645 | if (reply->depth == root_reply->depth) { | - | ||||||||||||
646 | - | |||||||||||||
647 | - | |||||||||||||
648 | - | |||||||||||||
649 | - | |||||||||||||
650 | - | |||||||||||||
651 | xcb_translate_coordinates_cookie_t translate_cookie = | - | ||||||||||||
652 | xcb_translate_coordinates_unchecked(xcb_connection(), window, root, x, y); | - | ||||||||||||
653 | - | |||||||||||||
654 | xcb_translate_coordinates_reply_t *translate_reply = | - | ||||||||||||
655 | xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, __null); | - | ||||||||||||
656 | - | |||||||||||||
657 | if (!translate_reply) { | - | ||||||||||||
658 | free(reply); | - | ||||||||||||
659 | free(root_reply); | - | ||||||||||||
660 | return QPixmap(); | - | ||||||||||||
661 | } | - | ||||||||||||
662 | - | |||||||||||||
663 | x = translate_reply->dst_x; | - | ||||||||||||
664 | y = translate_reply->dst_y; | - | ||||||||||||
665 | - | |||||||||||||
666 | window = root; | - | ||||||||||||
667 | - | |||||||||||||
668 | free(translate_reply); | - | ||||||||||||
669 | free(reply); | - | ||||||||||||
670 | reply = root_reply; | - | ||||||||||||
671 | } else { | - | ||||||||||||
672 | free(root_reply); | - | ||||||||||||
673 | root_reply = 0; | - | ||||||||||||
674 | } | - | ||||||||||||
675 | - | |||||||||||||
676 | xcb_get_window_attributes_reply_t *attributes_reply = | - | ||||||||||||
677 | xcb_get_window_attributes_reply(xcb_connection(), xcb_get_window_attributes_unchecked(xcb_connection(), window), __null); | - | ||||||||||||
678 | - | |||||||||||||
679 | if (!attributes_reply) { | - | ||||||||||||
680 | free(reply); | - | ||||||||||||
681 | return QPixmap(); | - | ||||||||||||
682 | } | - | ||||||||||||
683 | - | |||||||||||||
684 | const xcb_visualtype_t *visual = screen->visualForId(attributes_reply->visual); | - | ||||||||||||
685 | free(attributes_reply); | - | ||||||||||||
686 | - | |||||||||||||
687 | xcb_pixmap_t pixmap = xcb_generate_id(xcb_connection()); | - | ||||||||||||
688 | xcb_create_pixmap(xcb_connection(), reply->depth, pixmap, window, width, height); | - | ||||||||||||
689 | - | |||||||||||||
690 | uint32_t gc_value_mask = XCB_GC_SUBWINDOW_MODE; | - | ||||||||||||
691 | uint32_t gc_value_list[] = { XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS }; | - | ||||||||||||
692 | - | |||||||||||||
693 | xcb_gcontext_t gc = xcb_generate_id(xcb_connection()); | - | ||||||||||||
694 | xcb_create_gc(xcb_connection(), gc, pixmap, gc_value_mask, gc_value_list); | - | ||||||||||||
695 | - | |||||||||||||
696 | xcb_copy_area(xcb_connection(), window, pixmap, gc, x, y, 0, 0, width, height); | - | ||||||||||||
697 | - | |||||||||||||
698 | QPixmap result = qt_xcb_pixmapFromXPixmap(connection(), pixmap, width, height, reply->depth, visual); | - | ||||||||||||
699 | - | |||||||||||||
700 | free(reply); | - | ||||||||||||
701 | xcb_free_gc(xcb_connection(), gc); | - | ||||||||||||
702 | xcb_free_pixmap(xcb_connection(), pixmap); | - | ||||||||||||
703 | - | |||||||||||||
704 | return result; | - | ||||||||||||
705 | } | - | ||||||||||||
706 | - | |||||||||||||
707 | static bool parseXftInt(const QByteArray& stringValue, int *value) | - | ||||||||||||
708 | { | - | ||||||||||||
709 | ((!(value != 0)) ? qt_assert("value != 0",__FILE__,714782) : qt_noop()); | - | ||||||||||||
710 | bool ok; | - | ||||||||||||
711 | *value = stringValue.toInt(&ok); | - | ||||||||||||
712 | return ok; | - | ||||||||||||
713 | } | - | ||||||||||||
714 | - | |||||||||||||
715 | static QFontEngine::HintStyle parseXftHintStyle(const QByteArray& stringValue) | - | ||||||||||||
716 | { | - | ||||||||||||
717 | if (stringValue == "hintfull") | - | ||||||||||||
718 | return QFontEngine::HintFull; | - | ||||||||||||
719 | else if (stringValue == "hintnone") | - | ||||||||||||
720 | return QFontEngine::HintNone; | - | ||||||||||||
721 | else if (stringValue == "hintmedium") | - | ||||||||||||
722 | return QFontEngine::HintMedium; | - | ||||||||||||
723 | else if (stringValue == "hintslight") | - | ||||||||||||
724 | return QFontEngine::HintLight; | - | ||||||||||||
725 | - | |||||||||||||
726 | return QFontEngine::HintStyle(-1); | - | ||||||||||||
727 | } | - | ||||||||||||
728 | - | |||||||||||||
729 | static QFontEngine::SubpixelAntialiasingType parseXftRgba(const QByteArray& stringValue) | - | ||||||||||||
730 | { | - | ||||||||||||
731 | if (stringValue == "none") | - | ||||||||||||
732 | return QFontEngine::Subpixel_None; | - | ||||||||||||
733 | else if (stringValue == "rgb") | - | ||||||||||||
734 | return QFontEngine::Subpixel_RGB; | - | ||||||||||||
735 | else if (stringValue == "bgr") | - | ||||||||||||
736 | return QFontEngine::Subpixel_BGR; | - | ||||||||||||
737 | else if (stringValue == "vrgb") | - | ||||||||||||
738 | return QFontEngine::Subpixel_VRGB; | - | ||||||||||||
739 | else if (stringValue == "vbgr") | - | ||||||||||||
740 | return QFontEngine::Subpixel_VBGR; | - | ||||||||||||
741 | - | |||||||||||||
742 | return QFontEngine::SubpixelAntialiasingType(-1); | - | ||||||||||||
743 | } | - | ||||||||||||
744 | - | |||||||||||||
745 | bool QXcbScreen::xResource(const QByteArray &identifier, | - | ||||||||||||
746 | const QByteArray &expectedIdentifier, | - | ||||||||||||
747 | QByteArray& stringValue) | - | ||||||||||||
748 | { | - | ||||||||||||
749 | if (identifier.startsWith(expectedIdentifier)) { | - | ||||||||||||
750 | stringValue = identifier.mid(expectedIdentifier.size()); | - | ||||||||||||
751 | return true; | - | ||||||||||||
752 | } | - | ||||||||||||
753 | return false; | - | ||||||||||||
754 | } | - | ||||||||||||
755 | - | |||||||||||||
756 | void QXcbScreen::readXResources() | - | ||||||||||||
757 | { | - | ||||||||||||
758 | int offset = 0; | - | ||||||||||||
759 | QByteArray resources; | - | ||||||||||||
760 | while(1) { | - | ||||||||||||
761 | xcb_get_property_reply_t *reply = | - | ||||||||||||
762 | xcb_get_property_reply(xcb_connection(), | - | ||||||||||||
763 | xcb_get_property_unchecked(xcb_connection(), false, screen()->root, | - | ||||||||||||
764 | XCB_ATOM_RESOURCE_MANAGER, | - | ||||||||||||
765 | XCB_ATOM_STRING, offset/4, 8192), __null); | - | ||||||||||||
766 | bool more = false; | - | ||||||||||||
767 | if (reply && reply->format == 8 && reply->type == XCB_ATOM_STRING) { | - | ||||||||||||
768 | resources += QByteArray((const char *)xcb_get_property_value(reply), xcb_get_property_value_length(reply)); | - | ||||||||||||
769 | offset += xcb_get_property_value_length(reply); | - | ||||||||||||
770 | more = reply->bytes_after != 0; | - | ||||||||||||
771 | } | - | ||||||||||||
772 | - | |||||||||||||
773 | if (reply) | - | ||||||||||||
774 | free(reply); | - | ||||||||||||
775 | - | |||||||||||||
776 | if (!more) | - | ||||||||||||
777 | break; | - | ||||||||||||
778 | } | - | ||||||||||||
779 | - | |||||||||||||
780 | QList<QByteArray> split = resources.split('\n'); | - | ||||||||||||
781 | for (int i = 0; i < split.size(); ++i) { | - | ||||||||||||
782 | const QByteArray &r = split.at(i); | - | ||||||||||||
783 | int value; | - | ||||||||||||
784 | QByteArray stringValue; | - | ||||||||||||
785 | if (xResource(r, "Xft.dpi:\t", stringValue)) { | - | ||||||||||||
786 | if (parseXftInt(stringValue, &value)) | - | ||||||||||||
787 | m_forcedDpi = value; | - | ||||||||||||
788 | } else if (xResource(r, "Xft.hintstyle:\t", stringValue)) { | - | ||||||||||||
789 | m_hintStyle = parseXftHintStyle(stringValue); | - | ||||||||||||
790 | } else if (xResource(r, "Xft.antialias:\t", stringValue)) { | - | ||||||||||||
791 | if (parseXftInt(stringValue, &value)) | - | ||||||||||||
792 | m_antialiasingEnabled = value; | - | ||||||||||||
793 | } else if (xResource(r, "Xft.rgba:\t", stringValue)) { | - | ||||||||||||
794 | m_subpixelType = parseXftRgba(stringValue); | - | ||||||||||||
795 | } | - | ||||||||||||
796 | } | - | ||||||||||||
797 | } | - | ||||||||||||
798 | - | |||||||||||||
799 | QXcbXSettings *QXcbScreen::xSettings() const | - | ||||||||||||
800 | { | - | ||||||||||||
801 | return m_virtualDesktop->xSettings(); | - | ||||||||||||
802 | } | - | ||||||||||||
803 | - | |||||||||||||
804 | static inline void formatRect(QDebug &debug, const QRect r) | - | ||||||||||||
805 | { | - | ||||||||||||
806 | debug << r.width() << 'x' << r.height() | - | ||||||||||||
807 | << forcesign << r.x() << r.y() << noforcesign; | - | ||||||||||||
808 | } | - | ||||||||||||
809 | - | |||||||||||||
810 | static inline void formatSizeF(QDebug &debug, const QSizeF s) | - | ||||||||||||
811 | { | - | ||||||||||||
812 | debug << s.width() << 'x' << s.height() << "mm"; | - | ||||||||||||
813 | } | - | ||||||||||||
814 | - | |||||||||||||
815 | QDebug operator<<(QDebug debug, const QXcbScreen *screen) | - | ||||||||||||
816 | { | - | ||||||||||||
817 | const QDebugStateSaver saver(debug); | - | ||||||||||||
818 | debug.nospace(); | - | ||||||||||||
819 | debug << "QXcbScreen(" << (const void *)screen; | - | ||||||||||||
820 | if (screen) { | - | ||||||||||||
821 | debug << fixed << qSetRealNumberPrecision(1); | - | ||||||||||||
822 | debug << ", name=" << screen->name(); | - | ||||||||||||
823 | debug << ", geometry="; | - | ||||||||||||
824 | formatRect(debug, screen->geometry()); | - | ||||||||||||
825 | debug << ", availableGeometry="; | - | ||||||||||||
826 | formatRect(debug, screen->availableGeometry()); | - | ||||||||||||
827 | debug << ", devicePixelRatio=" << screen->devicePixelRatio(); | - | ||||||||||||
828 | debug << ", logicalDpi=" << screen->logicalDpi(); | - | ||||||||||||
829 | debug << ", physicalSize="; | - | ||||||||||||
830 | formatSizeF(debug, screen->physicalSize()); | - | ||||||||||||
831 | - | |||||||||||||
832 | debug << ", screenNumber=" << screen->screenNumber(); | - | ||||||||||||
833 | debug << ", virtualSize=" << screen->virtualSize().width() << 'x' << screen->virtualSize().height() << " ("; | - | ||||||||||||
834 | formatSizeF(debug, screen->virtualSize()); | - | ||||||||||||
835 | debug << "), orientation=" << screen->orientation(); | - | ||||||||||||
836 | debug << ", depth=" << screen->depth(); | - | ||||||||||||
837 | debug << ", refreshRate=" << screen->refreshRate(); | - | ||||||||||||
838 | debug << ", root=" << hex << screen->root(); | - | ||||||||||||
839 | debug << ", windowManagerName=" << screen->windowManagerName(); | - | ||||||||||||
840 | } | - | ||||||||||||
841 | debug << ')'; | - | ||||||||||||
842 | return debug; | - | ||||||||||||
843 | } | - | ||||||||||||
844 | - | |||||||||||||
845 | - | |||||||||||||
Switch to Source code | Preprocessed file |