Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qxcbwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qxcbwindow.h"
6
7#include <QtDebug>
8#include <QMetaEnum>
9#include <QScreen>
10#include <QtCore/QFileInfo>
11#include <QtGui/QIcon>
12#include <QtGui/QRegion>
13#include <QtGui/private/qhighdpiscaling_p.h>
14
16#include "qxcbconnection.h"
17#include "qxcbscreen.h"
18#if QT_CONFIG(draganddrop)
19#include "qxcbdrag.h"
20#endif
21#include "qxcbkeyboard.h"
22#include "qxcbimage.h"
23#include "qxcbwmsupport.h"
24#include "qxcbimage.h"
27
28#include <qpa/qplatformintegration.h>
29#include <qpa/qplatformcursor.h>
30
31#include <algorithm>
32
33#include <xcb/xcb_icccm.h>
34#include <xcb/xfixes.h>
35#include <xcb/shape.h>
36#include <xcb/xinput.h>
37
38#include <private/qguiapplication_p.h>
39#include <private/qwindow_p.h>
40
41#include <qpa/qplatformbackingstore.h>
42#include <qpa/qwindowsysteminterface.h>
43
44#include <stdio.h>
45#include <unistd.h>
46
47#if QT_CONFIG(xcb_xlib)
48#define register /* C++17 deprecated register */
49#include <X11/Xlib.h>
50#include <X11/Xutil.h>
51#undef register
52#endif
53
54#define XCOORD_MAX 32767
55enum {
58};
59
60QT_BEGIN_NAMESPACE
61
62using namespace Qt::StringLiterals;
63
64Q_STATIC_LOGGING_CATEGORY(lcQpaWindow, "qt.qpa.window");
65Q_STATIC_LOGGING_CATEGORY(lcQpaXcbWindow, "qt.qpa.xcb.window");
66
68
69#undef FocusIn
70
76
78 XEMBED_MAPPED = (1 << 0),
79};
80
96
98
99QXcbScreen *QXcbWindow::parentScreen()
100{
101 return QPlatformWindow::parent() ? static_cast<QXcbWindow*>(QPlatformWindow::parent())->parentScreen() : xcbScreen();
102}
103
104QXcbScreen *QXcbWindow::initialScreen() const
105{
106 // Resolve initial screen via QWindowPrivate::screenForGeometry(),
107 // which works in platform independent coordinates, as opposed to
108 // QPlatformWindow::screenForGeometry() that uses native coordinates.
109 QWindowPrivate *windowPrivate = qt_window_private(window());
110 QScreen *screen = windowPrivate->screenForGeometry(window()->geometry());
111 return static_cast<QXcbScreen*>(screen->handle());
112}
113
114// Returns \c true if we should set WM_TRANSIENT_FOR on \a w
115static inline bool isTransient(const QWindow *w)
116{
117 return w->type() == Qt::Dialog
118 || w->type() == Qt::Sheet
119 || w->type() == Qt::Tool
120 || w->type() == Qt::SplashScreen
121 || w->type() == Qt::ToolTip
122 || w->type() == Qt::Drawer
123 || w->type() == Qt::Popup;
124}
125
126void QXcbWindow::setImageFormatForVisual(const xcb_visualtype_t *visual)
127{
128 if (qt_xcb_imageFormatForVisual(connection(), m_depth, visual, &m_imageFormat, &m_imageRgbSwap))
129 return;
130
131 switch (m_depth) {
132 case 32:
133 case 24:
134 qWarning("Using RGB32 fallback, if this works your X11 server is reporting a bad screen format.");
135 m_imageFormat = QImage::Format_RGB32;
136 break;
137 case 16:
138 qWarning("Using RGB16 fallback, if this works your X11 server is reporting a bad screen format.");
139 m_imageFormat = QImage::Format_RGB16;
140 break;
141 default:
142 break;
143 }
144}
145
146#if QT_CONFIG(xcb_xlib)
147static inline XTextProperty* qstringToXTP(Display *dpy, const QString& s)
148{
149 #include <X11/Xatom.h>
150
151 static XTextProperty tp = { nullptr, 0, 0, 0 };
152 static bool free_prop = true; // we can't free tp.value in case it references
153 // the data of the static QByteArray below.
154 if (tp.value) {
155 if (free_prop)
156 XFree(tp.value);
157 tp.value = nullptr;
158 free_prop = true;
159 }
160
161 int errCode = 0;
162 QByteArray mapped = s.toLocal8Bit(); // should always be utf-8
163 char* tl[2];
164 tl[0] = mapped.data();
165 tl[1] = nullptr;
166 errCode = XmbTextListToTextProperty(dpy, tl, 1, XStdICCTextStyle, &tp);
167 if (errCode < 0)
168 qCDebug(lcQpaXcb, "XmbTextListToTextProperty result code %d", errCode);
169
170 if (errCode < 0) {
171 static QByteArray qcs;
172 qcs = s.toLatin1();
173 tp.value = (uchar*)qcs.data();
174 tp.encoding = XA_STRING;
175 tp.format = 8;
176 tp.nitems = qcs.size();
177 free_prop = false;
178 }
179 return &tp;
180}
181#endif // QT_CONFIG(xcb_xlib)
182
183// TODO move this into a utility function in QWindow or QGuiApplication
184static QWindow *childWindowAt(QWindow *win, const QPoint &p)
185{
186 for (QObject *obj : win->children()) {
187 if (obj->isWindowType()) {
188 QWindow *childWin = static_cast<QWindow *>(obj);
189 if (childWin->isVisible()) {
190 if (QWindow *recurse = childWindowAt(childWin, p))
191 return recurse;
192 }
193 }
194 }
195 if (!win->isTopLevel()
196 && !(win->flags() & Qt::WindowTransparentForInput)
197 && win->geometry().contains(win->parent()->mapFromGlobal(p))) {
198 return win;
199 }
200 return nullptr;
201}
202
203static const char *wm_window_type_property_id = "_q_xcb_wm_window_type";
204static const char *wm_window_role_property_id = "_q_xcb_wm_window_role";
205
206QXcbWindow::QXcbWindow(QWindow *window)
207 : QPlatformWindow(window)
208{
209 setConnection(xcbScreen()->connection());
210}
211
212enum : quint32 {
214 = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY
215 | XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_FOCUS_CHANGE,
216
218 | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE
219 | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
220 | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW
221 | XCB_EVENT_MASK_POINTER_MOTION,
222
224 | XCB_EVENT_MASK_VISIBILITY_CHANGE
225 | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
226 | XCB_EVENT_MASK_COLOR_MAP_CHANGE | XCB_EVENT_MASK_OWNER_GRAB_BUTTON
227};
228
229void QXcbWindow::create()
230{
231 xcb_window_t old_m_window = m_window;
232 destroy();
233
234 m_windowState = Qt::WindowNoState;
235 m_trayIconWindow = isTrayIconWindow(window());
236
237 Qt::WindowType type = window()->type();
238
239 QXcbScreen *currentScreen = xcbScreen();
240 QXcbScreen *platformScreen = QPlatformWindow::parent() ? parentScreen() : initialScreen();
241 QRect rect = QPlatformWindow::parent()
242 ? QHighDpi::toNativeLocalPosition(window()->geometry(), platformScreen)
243 : QHighDpi::toNativePixels(window()->geometry(), platformScreen);
244
245 const QSize minimumSize = windowMinimumSize();
246 if (rect.width() > 0 || rect.height() > 0) {
247 rect.setWidth(qBound(1, rect.width(), XCOORD_MAX));
248 rect.setHeight(qBound(1, rect.height(), XCOORD_MAX));
249 } else if (minimumSize.width() > 0 || minimumSize.height() > 0) {
250 rect.setSize(minimumSize);
251 } else {
252 rect.setWidth(QHighDpi::toNativePixels(int(defaultWindowWidth), platformScreen->QPlatformScreen::screen()));
253 rect.setHeight(QHighDpi::toNativePixels(int(defaultWindowHeight), platformScreen->QPlatformScreen::screen()));
254 }
255
256 QPlatformWindow::setGeometry(rect);
257
258 if (platformScreen != currentScreen)
259 QWindowSystemInterface::handleWindowScreenChanged(window(), platformScreen->QPlatformScreen::screen());
260
261 xcb_window_t xcb_parent_id = platformScreen->root();
262 if (QPlatformWindow::parent()) {
263 xcb_parent_id = static_cast<QXcbWindow *>(QPlatformWindow::parent())->xcb_window();
264 m_embedded = QPlatformWindow::parent()->isForeignWindow();
265
266 QSurfaceFormat parentFormat = QPlatformWindow::parent()->window()->requestedFormat();
267 if (window()->surfaceType() != QSurface::OpenGLSurface && parentFormat.hasAlpha()) {
268 window()->setFormat(parentFormat);
269 }
270 }
271
272 resolveFormat(platformScreen->surfaceFormatFor(window()->requestedFormat()));
273
274 const xcb_visualtype_t *visual = nullptr;
275
276 if (m_trayIconWindow && connection()->systemTrayTracker()) {
277 visual = platformScreen->visualForId(connection()->systemTrayTracker()->visualId());
278 } else if (connection()->hasDefaultVisualId()) {
279 visual = platformScreen->visualForId(connection()->defaultVisualId());
280 if (!visual)
281 qWarning() << "Failed to use requested visual id.";
282 }
283
284 if (QPlatformWindow::parent()) {
285 // When using a Vulkan QWindow via QWidget::createWindowContainer() we
286 // must make sure the visuals are compatible. Now, the parent will be
287 // of OpenGLSurface which typically chooses a GLX/EGL compatible
288 // visual which may not be what the Vulkan window would choose.
289 // Therefore, take the parent's visual.
290 if (window()->surfaceType() == QSurface::VulkanSurface
291 && QPlatformWindow::parent()->window()->surfaceType() != QSurface::VulkanSurface)
292 {
293 visual = platformScreen->visualForId(static_cast<QXcbWindow *>(QPlatformWindow::parent())->visualId());
294 }
295 }
296
297 if (!visual)
298 visual = createVisual();
299
300 if (!visual) {
301 qWarning() << "Falling back to using screens root_visual.";
302 visual = platformScreen->visualForId(platformScreen->screen()->root_visual);
303 }
304
305 Q_ASSERT(visual);
306
307 m_visualId = visual->visual_id;
308 m_depth = platformScreen->depthOfVisual(m_visualId);
309 setImageFormatForVisual(visual);
310
311 quint32 mask = XCB_CW_BACK_PIXMAP
312 | XCB_CW_BORDER_PIXEL
313 | XCB_CW_BIT_GRAVITY
314 | XCB_CW_OVERRIDE_REDIRECT
315 | XCB_CW_SAVE_UNDER
316 | XCB_CW_EVENT_MASK
317 | XCB_CW_COLORMAP;
318
319 quint32 values[] = {
320 XCB_BACK_PIXMAP_NONE,
321 platformScreen->screen()->black_pixel,
322 XCB_GRAVITY_NORTH_WEST,
323 type == Qt::Popup || type == Qt::ToolTip || (window()->flags() & Qt::BypassWindowManagerHint),
324 type == Qt::Popup || type == Qt::Tool || type == Qt::SplashScreen || type == Qt::ToolTip || type == Qt::Drawer,
325 defaultEventMask,
326 platformScreen->colormapForVisual(m_visualId)
327 };
328
329 m_window = xcb_generate_id(xcb_connection());
330 xcb_create_window(xcb_connection(),
331 m_depth,
332 m_window, // window id
333 xcb_parent_id, // parent window id
334 rect.x(),
335 rect.y(),
336 rect.width(),
337 rect.height(),
338 0, // border width
339 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
340 m_visualId, // visual
341 mask,
342 values);
343
344 connection()->addWindowEventListener(m_window, this);
345
346 propagateSizeHints();
347
348 xcb_atom_t properties[5];
349 int propertyCount = 0;
350 properties[propertyCount++] = atom(QXcbAtom::AtomWM_DELETE_WINDOW);
351 properties[propertyCount++] = atom(QXcbAtom::AtomWM_TAKE_FOCUS);
352 properties[propertyCount++] = atom(QXcbAtom::Atom_NET_WM_PING);
353
354 if (connection()->hasXSync())
355 properties[propertyCount++] = atom(QXcbAtom::Atom_NET_WM_SYNC_REQUEST);
356
357 if (window()->flags() & Qt::WindowContextHelpButtonHint)
358 properties[propertyCount++] = atom(QXcbAtom::Atom_NET_WM_CONTEXT_HELP);
359
360 xcb_change_property(xcb_connection(),
361 XCB_PROP_MODE_REPLACE,
362 m_window,
363 atom(QXcbAtom::AtomWM_PROTOCOLS),
364 XCB_ATOM_ATOM,
365 32,
366 propertyCount,
367 properties);
368 m_syncValue.hi = 0;
369 m_syncValue.lo = 0;
370
371 const QByteArray wmClass = QXcbIntegration::instance()->wmClass();
372 if (!wmClass.isEmpty()) {
373 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE,
374 m_window, atom(QXcbAtom::AtomWM_CLASS),
375 XCB_ATOM_STRING, 8, wmClass.size(), wmClass.constData());
376 }
377
378 QString desktopFileName = QGuiApplication::desktopFileName();
379 if (QGuiApplication::desktopFileName().isEmpty()) {
380 QFileInfo fi = QFileInfo(QCoreApplication::instance()->applicationFilePath());
381 QStringList domainName =
382 QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
383 Qt::SkipEmptyParts);
384
385 if (domainName.isEmpty()) {
386 desktopFileName = fi.baseName();
387 } else {
388 for (int i = 0; i < domainName.size(); ++i)
389 desktopFileName.prepend(QLatin1Char('.')).prepend(domainName.at(i));
390 desktopFileName.append(fi.baseName());
391 }
392 }
393 if (!desktopFileName.isEmpty()) {
394 const QByteArray dfName = desktopFileName.toUtf8();
395 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE,
396 m_window, atom(QXcbAtom::Atom_KDE_NET_WM_DESKTOP_FILE),
397 atom(QXcbAtom::AtomUTF8_STRING), 8, dfName.size(), dfName.constData());
398 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE,
399 m_window, atom(QXcbAtom::Atom_GTK_APPLICATION_ID),
400 atom(QXcbAtom::AtomUTF8_STRING), 8, dfName.size(), dfName.constData());
401 }
402
403 if (connection()->hasXSync()) {
404 m_syncCounter = xcb_generate_id(xcb_connection());
405 xcb_sync_create_counter(xcb_connection(), m_syncCounter, m_syncValue);
406
407 xcb_change_property(xcb_connection(),
408 XCB_PROP_MODE_REPLACE,
409 m_window,
410 atom(QXcbAtom::Atom_NET_WM_SYNC_REQUEST_COUNTER),
411 XCB_ATOM_CARDINAL,
412 32,
413 1,
414 &m_syncCounter);
415 }
416
417 // set the PID to let the WM kill the application if unresponsive
418 quint32 pid = getpid();
419 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
420 atom(QXcbAtom::Atom_NET_WM_PID), XCB_ATOM_CARDINAL, 32,
421 1, &pid);
422
423 const QByteArray clientMachine = QSysInfo::machineHostName().toLocal8Bit();
424 if (!clientMachine.isEmpty()) {
425 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
426 atom(QXcbAtom::AtomWM_CLIENT_MACHINE), XCB_ATOM_STRING, 8,
427 clientMachine.size(), clientMachine.constData());
428 }
429
430 // Create WM_HINTS property on the window, so we can xcb_icccm_get_wm_hints*()
431 // from various setter functions for adjusting the hints.
432 xcb_icccm_wm_hints_t hints;
433 memset(&hints, 0, sizeof(hints));
434 hints.flags = XCB_ICCCM_WM_HINT_WINDOW_GROUP;
435 hints.window_group = connection()->clientLeader();
436 xcb_icccm_set_wm_hints(xcb_connection(), m_window, &hints);
437
438 xcb_window_t leader = connection()->clientLeader();
439 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
440 atom(QXcbAtom::AtomWM_CLIENT_LEADER), XCB_ATOM_WINDOW, 32,
441 1, &leader);
442
443 /* Add XEMBED info; this operation doesn't initiate the embedding. */
444 quint32 data[] = { XEMBED_VERSION, XEMBED_MAPPED };
445 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
446 atom(QXcbAtom::Atom_XEMBED_INFO),
447 atom(QXcbAtom::Atom_XEMBED_INFO),
448 32, 2, (void *)data);
449
450 if (connection()->hasXInput2())
451 connection()->xi2SelectDeviceEvents(m_window);
452
453 setWindowState(window()->windowStates());
454 setWindowFlags(window()->flags());
455 setWindowTitle(window()->title());
456
457 // force sync to read outstanding requests - see QTBUG-29106
458 connection()->sync();
459
460#if QT_CONFIG(draganddrop)
461 connection()->drag()->dndEnable(this, true);
462#endif
463
464 const qreal opacity = qt_window_private(window())->opacity;
465 if (!qFuzzyCompare(opacity, qreal(1.0)))
466 setOpacity(opacity);
467
468 setMask(QHighDpi::toNativeLocalRegion(window()->mask(), window()));
469
470 if (window()->isTopLevel())
471 setWindowIcon(window()->icon());
472
473 if (window()->dynamicPropertyNames().contains(wm_window_role_property_id)) {
474 QByteArray wmWindowRole = window()->property(wm_window_role_property_id).toByteArray();
475 setWindowRole(QString::fromLatin1(wmWindowRole));
476 }
477
478 if (m_trayIconWindow)
479 m_embedded = requestSystemTrayWindowDock();
480
481 if (m_window != old_m_window) {
482 if (!m_wmTransientForChildren.isEmpty()) {
483 QList<QPointer<QXcbWindow>> transientChildren = m_wmTransientForChildren;
484 m_wmTransientForChildren.clear();
485 for (auto transientChild : transientChildren) {
486 if (transientChild)
487 transientChild->updateWmTransientFor();
488 }
489 }
490 }
491}
492
493QXcbWindow::~QXcbWindow()
494{
495 destroy();
496}
497
498QXcbForeignWindow::QXcbForeignWindow(QWindow *window, WId nativeHandle)
500{
501 m_window = nativeHandle;
502
503 // Reflect the foreign window's geometry as our own
504 if (auto geometry = Q_XCB_REPLY(xcb_get_geometry, xcb_connection(), m_window)) {
505 QRect nativeGeometry(geometry->x, geometry->y, geometry->width, geometry->height);
506 QPlatformWindow::setGeometry(nativeGeometry);
507 }
508
509 // And reparent, if we have a parent already
510 if (QPlatformWindow::parent())
511 setParent(QPlatformWindow::parent());
512}
513
515{
516 if (QPlatformWindow::parent())
517 setParent(nullptr);
518
519 // Clear window so that destroy() does not affect it
520 m_window = 0;
521
522 if (connection()->mouseGrabber() == this)
523 connection()->setMouseGrabber(nullptr);
524 if (connection()->mousePressWindow() == this)
525 connection()->setMousePressWindow(nullptr);
526}
527
528void QXcbWindow::destroy()
529{
530 if (connection()->focusWindow() == this)
531 doFocusOut();
532 if (connection()->mouseGrabber() == this)
533 connection()->setMouseGrabber(nullptr);
534 if (connection()->mousePressWindow() == this)
535 connection()->setMousePressWindow(nullptr);
536
537 if (m_syncCounter && connection()->hasXSync())
538 xcb_sync_destroy_counter(xcb_connection(), m_syncCounter);
539 if (m_window) {
540 if (m_netWmUserTimeWindow) {
541 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_USER_TIME_WINDOW));
542 // Some window managers, like metacity, do XSelectInput on the _NET_WM_USER_TIME_WINDOW window,
543 // without trapping BadWindow (which crashes when the user time window is destroyed).
544 connection()->sync();
545 xcb_destroy_window(xcb_connection(), m_netWmUserTimeWindow);
546 m_netWmUserTimeWindow = XCB_NONE;
547 }
548 connection()->removeWindowEventListener(m_window);
549 xcb_destroy_window(xcb_connection(), m_window);
550 m_window = 0;
551 }
552
553 m_mapped = false;
554 m_recreationReasons = RecreationNotNeeded;
555
556 if (m_pendingSyncRequest)
557 m_pendingSyncRequest->invalidate();
558}
559
560void QXcbWindow::setGeometry(const QRect &rect)
561{
562 QPlatformWindow::setGeometry(rect);
563
564 propagateSizeHints();
565
566 QXcbScreen *currentScreen = xcbScreen();
567 QXcbScreen *newScreen = QPlatformWindow::parent() ? parentScreen() : static_cast<QXcbScreen*>(screenForGeometry(rect));
568
569 if (!newScreen)
570 newScreen = xcbScreen();
571
572 if (newScreen != currentScreen)
573 QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->QPlatformScreen::screen());
574
575 if (qt_window_private(window())->positionAutomatic) {
576 const quint32 mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
577 const qint32 values[] = {
578 qBound<qint32>(1, rect.width(), XCOORD_MAX),
579 qBound<qint32>(1, rect.height(), XCOORD_MAX),
580 };
581 xcb_configure_window(xcb_connection(), m_window, mask, reinterpret_cast<const quint32*>(values));
582 } else {
583 const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
584 const qint32 values[] = {
585 qBound<qint32>(-XCOORD_MAX, rect.x(), XCOORD_MAX),
586 qBound<qint32>(-XCOORD_MAX, rect.y(), XCOORD_MAX),
587 qBound<qint32>(1, rect.width(), XCOORD_MAX),
588 qBound<qint32>(1, rect.height(), XCOORD_MAX),
589 };
590 xcb_configure_window(xcb_connection(), m_window, mask, reinterpret_cast<const quint32*>(values));
591 if (window()->parent() && !window()->transientParent()) {
592 // Wait for server reply for parented windows to ensure that a few window
593 // moves will come as a one event. This is important when native widget is
594 // moved a few times in X and Y directions causing native scroll. Widget
595 // must get single event to not trigger unwanted widget position changes
596 // and then expose events causing backingstore flushes with incorrect
597 // offset causing image crruption.
598 connection()->sync();
599 }
600 }
601
602 xcb_flush(xcb_connection());
603}
604
605QMargins QXcbWindow::frameMargins() const
606{
607 if (m_dirtyFrameMargins) {
608 if (connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::Atom_NET_FRAME_EXTENTS))) {
609 auto reply = Q_XCB_REPLY(xcb_get_property, xcb_connection(), false, m_window,
610 atom(QXcbAtom::Atom_NET_FRAME_EXTENTS), XCB_ATOM_CARDINAL, 0, 4);
611 if (reply && reply->type == XCB_ATOM_CARDINAL && reply->format == 32 && reply->value_len == 4) {
612 quint32 *data = (quint32 *)xcb_get_property_value(reply.get());
613 // _NET_FRAME_EXTENTS format is left, right, top, bottom
614 m_frameMargins = QMargins(data[0], data[2], data[1], data[3]);
615 m_dirtyFrameMargins = false;
616 return m_frameMargins;
617 }
618 }
619
620 // _NET_FRAME_EXTENTS property is not available, so
621 // walk up the window tree to get the frame parent
622 xcb_window_t window = m_window;
623 xcb_window_t parent = m_window;
624
625 bool foundRoot = false;
626
627 const QList<xcb_window_t> &virtualRoots =
628 connection()->wmSupport()->virtualRoots();
629
630 while (!foundRoot) {
631 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_query_tree, xcb_connection(), parent);
632 if (reply) {
633 if (reply->root == reply->parent || virtualRoots.indexOf(reply->parent) != -1 || reply->parent == XCB_WINDOW_NONE) {
634 foundRoot = true;
635 } else {
636 window = parent;
637 parent = reply->parent;
638 }
639 } else {
640 m_dirtyFrameMargins = false;
641 m_frameMargins = QMargins();
642 return m_frameMargins;
643 }
644 }
645
646 QPoint offset;
647
648 auto reply = Q_XCB_REPLY(xcb_translate_coordinates, xcb_connection(), window, parent, 0, 0);
649 if (reply) {
650 offset = QPoint(reply->dst_x, reply->dst_y);
651 }
652
653 auto geom = Q_XCB_REPLY(xcb_get_geometry, xcb_connection(), parent);
654 if (geom) {
655 // --
656 // add the border_width for the window managers frame... some window managers
657 // do not use a border_width of zero for their frames, and if we the left and
658 // top strut, we ensure that pos() is absolutely correct. frameGeometry()
659 // will still be incorrect though... perhaps i should have foffset as well, to
660 // indicate the frame offset (equal to the border_width on X).
661 // - Brad
662 // -- copied from qwidget_x11.cpp
663
664 int left = offset.x() + geom->border_width;
665 int top = offset.y() + geom->border_width;
666 int right = geom->width + geom->border_width - geometry().width() - offset.x();
667 int bottom = geom->height + geom->border_width - geometry().height() - offset.y();
668
669 m_frameMargins = QMargins(left, top, right, bottom);
670 }
671
672 m_dirtyFrameMargins = false;
673 }
674
675 return m_frameMargins;
676}
677
678void QXcbWindow::setVisible(bool visible)
679{
680 if (visible)
681 show();
682 else
683 hide();
684}
685
686void QXcbWindow::updateWmTransientFor()
687{
688 xcb_window_t transientXcbParent = XCB_NONE;
689 if (isTransient(window())) {
690 QWindow *tp = window()->transientParent();
691 if (tp && tp->handle()) {
692 QXcbWindow *handle = static_cast<QXcbWindow *>(tp->handle());
693 transientXcbParent = tp->handle()->winId();
694 if (transientXcbParent) {
695 handle->registerWmTransientForChild(this);
696 qCDebug(lcQpaXcbWindow) << Q_FUNC_INFO << static_cast<QPlatformWindow *>(handle)
697 << " registerWmTransientForChild " << static_cast<QPlatformWindow *>(this);
698 }
699 }
700 // Default to client leader if there is no transient parent, else modal dialogs can
701 // be hidden by their parents.
702 if (!transientXcbParent)
703 transientXcbParent = connection()->clientLeader();
704 if (transientXcbParent) { // ICCCM 4.1.2.6
705 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
706 XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
707 1, &transientXcbParent);
708 qCDebug(lcQpaXcbWindow, "0x%x added XCB_ATOM_WM_TRANSIENT_FOR 0x%x", m_window, transientXcbParent);
709 }
710 }
711 if (!transientXcbParent)
712 xcb_delete_property(xcb_connection(), m_window, XCB_ATOM_WM_TRANSIENT_FOR);
713}
714
715void QXcbWindow::registerWmTransientForChild(QXcbWindow *child)
716{
717 if (!child)
718 return;
719
720 if (!m_wmTransientForChildren.contains(child))
721 m_wmTransientForChildren.append(child);
722}
723
724void QXcbWindow::show()
725{
726 if (window()->isTopLevel()) {
727 if (m_recreationReasons != RecreationNotNeeded) {
728 qCDebug(lcQpaWindow) << "QXcbWindow: need to recreate window" << window() << m_recreationReasons;
729 create();
730 m_recreationReasons = RecreationNotNeeded;
731 }
732
733 // update WM_NORMAL_HINTS
734 propagateSizeHints();
735
736 // update WM_TRANSIENT_FOR
737 updateWmTransientFor();
738
739 // update _NET_WM_STATE
740 setNetWmStateOnUnmappedWindow();
741 }
742
743 // QWidget-attribute Qt::WA_ShowWithoutActivating.
744 const auto showWithoutActivating = window()->property("_q_showWithoutActivating");
745 if (showWithoutActivating.isValid() && showWithoutActivating.toBool())
746 updateNetWmUserTime(0);
747 else if (connection()->time() != XCB_TIME_CURRENT_TIME)
748 updateNetWmUserTime(connection()->time());
749
750 if (m_trayIconWindow)
751 return; // defer showing until XEMBED_EMBEDDED_NOTIFY
752
753 xcb_map_window(xcb_connection(), m_window);
754
755 if (QGuiApplication::modalWindow() == window())
756 requestActivateWindow();
757
758 xcbScreen()->windowShown(this);
759
760 connection()->sync();
761}
762
763void QXcbWindow::hide()
764{
765 xcb_unmap_window(xcb_connection(), m_window);
766
767 // send synthetic UnmapNotify event according to icccm 4.1.4
768 q_padded_xcb_event<xcb_unmap_notify_event_t> event = {};
769 event.response_type = XCB_UNMAP_NOTIFY;
770 event.event = xcbScreen()->root();
771 event.window = m_window;
772 event.from_configure = false;
773 xcb_send_event(xcb_connection(), false, xcbScreen()->root(),
774 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event);
775
776 xcb_flush(xcb_connection());
777
778 if (connection()->mouseGrabber() == this)
779 connection()->setMouseGrabber(nullptr);
780 if (QPlatformWindow *w = connection()->mousePressWindow()) {
781 // Unset mousePressWindow when it (or one of its parents) is unmapped
782 while (w) {
783 if (w == this) {
784 connection()->setMousePressWindow(nullptr);
785 break;
786 }
787 w = w->parent();
788 }
789 }
790
791 // Avoid race with requestActivate()
792 QMutexLocker locker(&m_mappedMutex);
793 m_mapped = false;
794 m_deferredActivation = false;
795
796 // Hiding a modal window doesn't send an enter event to its transient parent when the
797 // mouse is already over the parent window, so the enter event must be emulated.
798 if (window()->isModal()) {
799 // Get the cursor position at modal window screen
800 const QPoint nativePos = xcbScreen()->cursor()->pos();
801 const QPoint cursorPos = QHighDpi::fromNativePixels(nativePos, xcbScreen()->screenForPosition(nativePos)->screen());
802
803 // Find the top level window at cursor position.
804 // Don't use QGuiApplication::topLevelAt(): search only the virtual siblings of this window's screen
805 QWindow *enterWindow = nullptr;
806 const auto screens = xcbScreen()->virtualSiblings();
807 for (QPlatformScreen *screen : screens) {
808 if (screen->geometry().contains(cursorPos)) {
809 const QPoint devicePosition = QHighDpi::toNativePixels(cursorPos, screen->screen());
810 enterWindow = screen->topLevelAt(devicePosition);
811 break;
812 }
813 }
814
815 if (enterWindow && enterWindow != window()) {
816 // Find the child window at cursor position, otherwise use the top level window
817 if (QWindow *childWindow = childWindowAt(enterWindow, cursorPos))
818 enterWindow = childWindow;
819 const QPoint localPos = enterWindow->mapFromGlobal(cursorPos);
820 QWindowSystemInterface::handleEnterEvent(enterWindow,
821 localPos * QHighDpiScaling::factor(enterWindow),
822 nativePos);
823 }
824 }
825}
826
827bool QXcbWindow::relayFocusToModalWindow() const
828{
829 QWindow *w = static_cast<QWindowPrivate *>(QObjectPrivate::get(window()))->eventReceiver();
830 // get top-level window
831 while (w && w->parent())
832 w = w->parent();
833
834 QWindow *modalWindow = nullptr;
835 const bool blocked = QGuiApplicationPrivate::instance()->isWindowBlocked(w, &modalWindow);
836 if (blocked && modalWindow != w) {
837 modalWindow->requestActivate();
838 connection()->flush();
839 return true;
840 }
841
842 return false;
843}
844
845void QXcbWindow::doFocusIn()
846{
847 if (relayFocusToModalWindow())
848 return;
849 QWindow *w = static_cast<QWindowPrivate *>(QObjectPrivate::get(window()))->eventReceiver();
850 connection()->setFocusWindow(w);
851 QWindowSystemInterface::handleFocusWindowChanged(w, Qt::ActiveWindowFocusReason);
852}
853
854void QXcbWindow::doFocusOut()
855{
856 connection()->setFocusWindow(nullptr);
857 relayFocusToModalWindow();
858 // Do not set the active window to nullptr if there is a FocusIn coming.
859 connection()->focusInTimer().start();
860}
861
867
868enum {
870
871 MWM_FUNC_ALL = (1L << 0),
872 MWM_FUNC_RESIZE = (1L << 1),
873 MWM_FUNC_MOVE = (1L << 2),
874 MWM_FUNC_MINIMIZE = (1L << 3),
875 MWM_FUNC_MAXIMIZE = (1L << 4),
876 MWM_FUNC_CLOSE = (1L << 5),
877
879
880 MWM_DECOR_ALL = (1L << 0),
881 MWM_DECOR_BORDER = (1L << 1),
882 MWM_DECOR_RESIZEH = (1L << 2),
883 MWM_DECOR_TITLE = (1L << 3),
884 MWM_DECOR_MENU = (1L << 4),
887};
888
889QXcbWindow::NetWmStates QXcbWindow::netWmStates()
890{
891 NetWmStates result;
892
893 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, xcb_connection(),
894 0, m_window, atom(QXcbAtom::Atom_NET_WM_STATE),
895 XCB_ATOM_ATOM, 0, 1024);
896
897 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) {
898 const xcb_atom_t *states = static_cast<const xcb_atom_t *>(xcb_get_property_value(reply.get()));
899 const xcb_atom_t *statesEnd = states + reply->length;
900 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_ABOVE)))
901 result |= NetWmStateAbove;
902 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_BELOW)))
903 result |= NetWmStateBelow;
904 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN)))
905 result |= NetWmStateFullScreen;
906 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ)))
907 result |= NetWmStateMaximizedHorz;
908 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT)))
909 result |= NetWmStateMaximizedVert;
910 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_MODAL)))
911 result |= NetWmStateModal;
912 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_STAYS_ON_TOP)))
913 result |= NetWmStateStaysOnTop;
914 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_DEMANDS_ATTENTION)))
915 result |= NetWmStateDemandsAttention;
916 if (statesEnd != std::find(states, statesEnd, atom(QXcbAtom::Atom_NET_WM_STATE_HIDDEN)))
917 result |= NetWmStateHidden;
918 } else {
919 qCDebug(lcQpaXcb, "getting net wm state (%x), empty\n", m_window);
920 }
921
922 return result;
923}
924
925void QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
926{
927 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
928
929 if (type == Qt::ToolTip)
930 flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint;
931 if (type == Qt::Popup)
932 flags |= Qt::X11BypassWindowManagerHint;
933
934 Qt::WindowFlags oldflags = window()->flags();
935 if ((oldflags & Qt::WindowStaysOnTopHint) != (flags & Qt::WindowStaysOnTopHint))
936 m_recreationReasons |= WindowStaysOnTopHintChanged;
937 if ((oldflags & Qt::WindowStaysOnBottomHint) != (flags & Qt::WindowStaysOnBottomHint))
938 m_recreationReasons |= WindowStaysOnBottomHintChanged;
939
940 const quint32 mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
941 const quint32 values[] = {
942 // XCB_CW_OVERRIDE_REDIRECT
943 (flags & Qt::BypassWindowManagerHint) ? 1u : 0,
944 // XCB_CW_EVENT_MASK
945 (flags & Qt::WindowTransparentForInput) ? transparentForInputEventMask : defaultEventMask
946 };
947
948 xcb_change_window_attributes(xcb_connection(), xcb_window(), mask, values);
949
950 WindowTypes wmWindowTypes;
951 if (window()->dynamicPropertyNames().contains(wm_window_type_property_id)) {
952 wmWindowTypes = static_cast<WindowTypes>(
953 qvariant_cast<int>(window()->property(wm_window_type_property_id)));
954 }
955
956 setWmWindowType(wmWindowTypes, flags);
957 setNetWmState(flags);
958 setMotifWmHints(flags);
959
960 setTransparentForMouseEvents(flags & Qt::WindowTransparentForInput);
961 updateDoesNotAcceptFocus(flags & Qt::WindowDoesNotAcceptFocus);
962}
963
964void QXcbWindow::setMotifWmHints(Qt::WindowFlags flags)
965{
966 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
967
968 QtMotifWmHints mwmhints;
969 memset(&mwmhints, 0, sizeof(mwmhints));
970
971 if (type != Qt::SplashScreen) {
972 mwmhints.flags |= MWM_HINTS_DECORATIONS;
973
974 bool customize = flags & Qt::CustomizeWindowHint;
975 if (type == Qt::Window && !customize) {
976 const Qt::WindowFlags defaultFlags = Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
977 if (!(flags & defaultFlags))
978 flags |= defaultFlags;
979 }
980 if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
981 mwmhints.decorations |= MWM_DECOR_BORDER;
982 mwmhints.decorations |= MWM_DECOR_RESIZEH;
983 mwmhints.decorations |= MWM_DECOR_TITLE;
984
985 if (flags & Qt::WindowSystemMenuHint)
986 mwmhints.decorations |= MWM_DECOR_MENU;
987
988 if (flags & Qt::WindowMinimizeButtonHint) {
989 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
990 mwmhints.functions |= MWM_FUNC_MINIMIZE;
991 }
992
993 if (flags & Qt::WindowMaximizeButtonHint) {
994 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
995 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
996 }
997
998 if (flags & Qt::WindowCloseButtonHint)
999 mwmhints.functions |= MWM_FUNC_CLOSE;
1000 }
1001 } else {
1002 // if type == Qt::SplashScreen
1003 mwmhints.decorations = MWM_DECOR_ALL;
1004 }
1005
1006 if (mwmhints.functions != 0) {
1007 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
1008 mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
1009 } else {
1010 mwmhints.functions = MWM_FUNC_ALL;
1011 }
1012
1013 if (!(flags & Qt::FramelessWindowHint)
1014 && flags & Qt::CustomizeWindowHint
1015 && flags & Qt::WindowTitleHint
1016 && !(flags &
1017 (Qt::WindowMinimizeButtonHint
1018 | Qt::WindowMaximizeButtonHint
1019 | Qt::WindowCloseButtonHint)))
1020 {
1021 // a special case - only the titlebar without any button
1022 mwmhints.flags = MWM_HINTS_FUNCTIONS;
1023 mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
1024 mwmhints.decorations = 0;
1025 }
1026
1027 if (mwmhints.flags) {
1028 xcb_change_property(xcb_connection(),
1029 XCB_PROP_MODE_REPLACE,
1030 m_window,
1031 atom(QXcbAtom::Atom_MOTIF_WM_HINTS),
1032 atom(QXcbAtom::Atom_MOTIF_WM_HINTS),
1033 32,
1034 5,
1035 &mwmhints);
1036 } else {
1037 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_MOTIF_WM_HINTS));
1038 }
1039}
1040
1041void QXcbWindow::setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two)
1042{
1043 xcb_client_message_event_t event;
1044
1045 event.response_type = XCB_CLIENT_MESSAGE;
1046 event.format = 32;
1047 event.sequence = 0;
1048 event.window = m_window;
1049 event.type = atom(QXcbAtom::Atom_NET_WM_STATE);
1050 event.data.data32[0] = set ? 1 : 0;
1051 event.data.data32[1] = one;
1052 event.data.data32[2] = two;
1053 event.data.data32[3] = 0;
1054 event.data.data32[4] = 0;
1055
1056 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1057 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1058 (const char *)&event);
1059}
1060
1061void QXcbWindow::setNetWmState(Qt::WindowStates state)
1062{
1063 if ((m_windowState ^ state) & Qt::WindowMaximized) {
1064 setNetWmState(state & Qt::WindowMaximized,
1065 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ),
1066 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT));
1067 }
1068
1069 if ((m_windowState ^ state) & Qt::WindowFullScreen)
1070 setNetWmState(state & Qt::WindowFullScreen, atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN));
1071}
1072
1073void QXcbWindow::setNetWmState(Qt::WindowFlags flags)
1074{
1075 setNetWmState(flags & Qt::WindowStaysOnTopHint,
1076 atom(QXcbAtom::Atom_NET_WM_STATE_ABOVE),
1077 atom(QXcbAtom::Atom_NET_WM_STATE_STAYS_ON_TOP));
1078 setNetWmState(flags & Qt::WindowStaysOnBottomHint, atom(QXcbAtom::Atom_NET_WM_STATE_BELOW));
1079}
1080
1081void QXcbWindow::setNetWmStateOnUnmappedWindow()
1082{
1083 QMutexLocker locker(&m_mappedMutex);
1084 if (Q_UNLIKELY(m_mapped))
1085 qCDebug(lcQpaXcb()) << "internal info: " << Q_FUNC_INFO << "called on mapped window";
1086
1087 NetWmStates states;
1088 const Qt::WindowFlags flags = window()->flags();
1089 if (flags & Qt::WindowStaysOnTopHint) {
1090 states |= NetWmStateAbove;
1091 states |= NetWmStateStaysOnTop;
1092 } else if (flags & Qt::WindowStaysOnBottomHint) {
1093 states |= NetWmStateBelow;
1094 }
1095
1096 if (window()->windowStates() & Qt::WindowMinimized)
1097 states |= NetWmStateHidden;
1098
1099 if (window()->windowStates() & Qt::WindowFullScreen)
1100 states |= NetWmStateFullScreen;
1101
1102 if (window()->windowStates() & Qt::WindowMaximized) {
1103 states |= NetWmStateMaximizedHorz;
1104 states |= NetWmStateMaximizedVert;
1105 }
1106
1107 if (window()->modality() != Qt::NonModal)
1108 states |= NetWmStateModal;
1109
1110 // According to EWMH:
1111 // "The Window Manager should remove _NET_WM_STATE whenever a window is withdrawn".
1112 // Which means that we don't have to read this property before changing it on a withdrawn
1113 // window. But there are situations where users want to adjust this property as well
1114 // (e4cea305ed2ba3c9f580bf9d16c59a1048af0e8a), so instead of overwriting the property
1115 // we first read it and then merge our hints with the existing values, allowing a user
1116 // to set custom hints.
1117
1118 QList<xcb_atom_t> atoms;
1119 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, xcb_connection(),
1120 0, m_window, atom(QXcbAtom::Atom_NET_WM_STATE),
1121 XCB_ATOM_ATOM, 0, 1024);
1122 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM && reply->value_len > 0) {
1123 const xcb_atom_t *data = static_cast<const xcb_atom_t *>(xcb_get_property_value(reply.get()));
1124 atoms.resize(reply->value_len);
1125 memcpy((void *)&atoms.first(), (void *)data, reply->value_len * sizeof(xcb_atom_t));
1126 }
1127
1128 if (states & NetWmStateAbove && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_ABOVE)))
1129 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_ABOVE));
1130 if (states & NetWmStateBelow && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_BELOW)))
1131 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_BELOW));
1132 if (states & NetWmStateHidden && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_HIDDEN)))
1133 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_HIDDEN));
1134 if (states & NetWmStateFullScreen && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN)))
1135 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN));
1136 if (states & NetWmStateMaximizedHorz && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ)))
1137 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ));
1138 if (states & NetWmStateMaximizedVert && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT)))
1139 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT));
1140 if (states & NetWmStateModal && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_MODAL)))
1141 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_MODAL));
1142 if (states & NetWmStateStaysOnTop && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_STAYS_ON_TOP)))
1143 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_STAYS_ON_TOP));
1144 if (states & NetWmStateDemandsAttention && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_DEMANDS_ATTENTION)))
1145 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_DEMANDS_ATTENTION));
1146
1147 if (atoms.isEmpty()) {
1148 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_STATE));
1149 } else {
1150 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
1151 atom(QXcbAtom::Atom_NET_WM_STATE), XCB_ATOM_ATOM, 32,
1152 atoms.size(), atoms.constData());
1153 }
1154 xcb_flush(xcb_connection());
1155}
1156
1157void QXcbWindow::setWindowState(Qt::WindowStates state)
1158{
1159 if (state == m_windowState)
1160 return;
1161
1162 Qt::WindowStates unsetState = m_windowState & ~state;
1163 Qt::WindowStates newState = state & ~m_windowState;
1164
1165 // unset old state
1166 if (unsetState & Qt::WindowMinimized)
1167 xcb_map_window(xcb_connection(), m_window);
1168 if (unsetState & Qt::WindowMaximized)
1169 setNetWmState(false,
1170 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ),
1171 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT));
1172 if (unsetState & Qt::WindowFullScreen)
1173 setNetWmState(false, atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN));
1174
1175 // set new state
1176 if (newState & Qt::WindowMinimized) {
1177 {
1178 xcb_client_message_event_t event;
1179
1180 event.response_type = XCB_CLIENT_MESSAGE;
1181 event.format = 32;
1182 event.sequence = 0;
1183 event.window = m_window;
1184 event.type = atom(QXcbAtom::AtomWM_CHANGE_STATE);
1185 event.data.data32[0] = XCB_ICCCM_WM_STATE_ICONIC;
1186 event.data.data32[1] = 0;
1187 event.data.data32[2] = 0;
1188 event.data.data32[3] = 0;
1189 event.data.data32[4] = 0;
1190
1191 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1192 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1193 (const char *)&event);
1194 }
1195 m_minimized = true;
1196 }
1197
1198 // set Maximized && FullScreen state if need
1199 setNetWmState(state);
1200
1201 xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_hints_unchecked(xcb_connection(), m_window);
1202 xcb_icccm_wm_hints_t hints;
1203 if (xcb_icccm_get_wm_hints_reply(xcb_connection(), cookie, &hints, nullptr)) {
1204 if (state & Qt::WindowMinimized)
1205 xcb_icccm_wm_hints_set_iconic(&hints);
1206 else
1207 xcb_icccm_wm_hints_set_normal(&hints);
1208 xcb_icccm_set_wm_hints(xcb_connection(), m_window, &hints);
1209 }
1210
1211 connection()->sync();
1212 m_windowState = state;
1213}
1214
1215void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
1216{
1217 xcb_window_t wid = m_window;
1218 // If timestamp == 0, then it means that the window should not be
1219 // initially activated. Don't update global user time for this
1220 // special case.
1221 if (timestamp != 0)
1222 connection()->setNetWmUserTime(timestamp);
1223
1224 const bool isSupportedByWM = connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::Atom_NET_WM_USER_TIME_WINDOW));
1225 if (m_netWmUserTimeWindow || isSupportedByWM) {
1226 if (!m_netWmUserTimeWindow) {
1227 m_netWmUserTimeWindow = xcb_generate_id(xcb_connection());
1228 xcb_create_window(xcb_connection(),
1229 XCB_COPY_FROM_PARENT, // depth -- same as root
1230 m_netWmUserTimeWindow, // window id
1231 m_window, // parent window id
1232 -1, -1, 1, 1,
1233 0, // border width
1234 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
1235 m_visualId, // visual
1236 0, // value mask
1237 nullptr); // value list
1238 wid = m_netWmUserTimeWindow;
1239 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::Atom_NET_WM_USER_TIME_WINDOW),
1240 XCB_ATOM_WINDOW, 32, 1, &m_netWmUserTimeWindow);
1241 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_USER_TIME));
1242
1243 QXcbWindow::setWindowTitle(connection(), m_netWmUserTimeWindow,
1244 QStringLiteral("Qt NET_WM User Time Window"));
1245
1246 } else if (!isSupportedByWM) {
1247 // WM no longer supports it, then we should remove the
1248 // _NET_WM_USER_TIME_WINDOW atom.
1249 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_USER_TIME_WINDOW));
1250 xcb_destroy_window(xcb_connection(), m_netWmUserTimeWindow);
1251 m_netWmUserTimeWindow = XCB_NONE;
1252 } else {
1253 wid = m_netWmUserTimeWindow;
1254 }
1255 }
1256 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::Atom_NET_WM_USER_TIME),
1257 XCB_ATOM_CARDINAL, 32, 1, &timestamp);
1258}
1259
1260void QXcbWindow::setTransparentForMouseEvents(bool transparent)
1261{
1262 if (!connection()->hasXFixes() || transparent == m_transparent)
1263 return;
1264
1265 xcb_rectangle_t rectangle;
1266
1267 xcb_rectangle_t *rect = nullptr;
1268 int nrect = 0;
1269
1270 if (!transparent) {
1271 rectangle.x = 0;
1272 rectangle.y = 0;
1273 rectangle.width = geometry().width();
1274 rectangle.height = geometry().height();
1275 rect = &rectangle;
1276 nrect = 1;
1277 }
1278
1279 xcb_xfixes_region_t region = xcb_generate_id(xcb_connection());
1280 xcb_xfixes_create_region(xcb_connection(), region, nrect, rect);
1281 xcb_xfixes_set_window_shape_region_checked(xcb_connection(), m_window, XCB_SHAPE_SK_INPUT, 0, 0, region);
1282 xcb_xfixes_destroy_region(xcb_connection(), region);
1283
1284 m_transparent = transparent;
1285}
1286
1287void QXcbWindow::updateDoesNotAcceptFocus(bool doesNotAcceptFocus)
1288{
1289 xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_hints_unchecked(xcb_connection(), m_window);
1290
1291 xcb_icccm_wm_hints_t hints;
1292 if (!xcb_icccm_get_wm_hints_reply(xcb_connection(), cookie, &hints, nullptr))
1293 return;
1294
1295 xcb_icccm_wm_hints_set_input(&hints, !doesNotAcceptFocus);
1296 xcb_icccm_set_wm_hints(xcb_connection(), m_window, &hints);
1297}
1298
1299WId QXcbWindow::winId() const
1300{
1301 return m_window;
1302}
1303
1304void QXcbWindow::setParent(const QPlatformWindow *parent)
1305{
1306 QPoint topLeft = geometry().topLeft();
1307
1308 xcb_window_t xcb_parent_id;
1309 if (parent) {
1310 const QXcbWindow *qXcbParent = static_cast<const QXcbWindow *>(parent);
1311 xcb_parent_id = qXcbParent->xcb_window();
1312 m_embedded = qXcbParent->isForeignWindow();
1313 } else {
1314 xcb_parent_id = xcbScreen()->root();
1315 m_embedded = false;
1316 }
1317 xcb_reparent_window(xcb_connection(), xcb_window(), xcb_parent_id, topLeft.x(), topLeft.y());
1318 connection()->sync();
1319}
1320
1321void QXcbWindow::setWindowTitle(const QString &title)
1322{
1323 setWindowTitle(connection(), m_window, title);
1324}
1325
1326QString QXcbWindow::windowTitle() const
1327{
1328 return windowTitle(connection(), m_window);
1329}
1330
1331void QXcbWindow::setWindowIconText(const QString &title)
1332{
1333 const QByteArray ba = title.toUtf8();
1334 xcb_change_property(xcb_connection(),
1335 XCB_PROP_MODE_REPLACE,
1336 m_window,
1337 atom(QXcbAtom::Atom_NET_WM_ICON_NAME),
1338 atom(QXcbAtom::AtomUTF8_STRING),
1339 8,
1340 ba.size(),
1341 ba.constData());
1342}
1343
1344void QXcbWindow::setWindowIcon(const QIcon &icon)
1345{
1346 QList<quint32> icon_data;
1347 const uint32_t sizeLimit = xcb_get_maximum_request_length(xcb_connection());
1348 if (!icon.isNull()) {
1349 QList<QSize> availableSizes = icon.availableSizes();
1350 if (availableSizes.isEmpty()) {
1351 // try to use default sizes since the icon can be a scalable image like svg.
1352 availableSizes.push_back(QSize(16,16));
1353 availableSizes.push_back(QSize(32,32));
1354 availableSizes.push_back(QSize(64,64));
1355 availableSizes.push_back(QSize(128,128));
1356 }
1357 for (int i = 0; i < availableSizes.size(); ++i) {
1358 QSize size = availableSizes.at(i);
1359 QPixmap pixmap = icon.pixmap(size);
1360 if (!pixmap.isNull()) {
1361 QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
1362 int pos = icon_data.size();
1363 int newSize = pos + 2 + image.width()*image.height();
1364 // In the absence of the BIG-REQUESTS extension, or with too big DPR,
1365 // the size of icon data is too big for the xcb request very easily.
1366 if (quint64(newSize) > quint64(sizeLimit))
1367 break;
1368 icon_data.resize(newSize);
1369 icon_data[pos++] = image.width();
1370 icon_data[pos++] = image.height();
1371 memcpy(icon_data.data() + pos, image.bits(), image.width()*image.height()*4);
1372 }
1373 }
1374 }
1375
1376 if (!icon_data.isEmpty()) {
1377 // Ignore icon exceeding maximum xcb request length
1378 if (quint64(icon_data.size()) > quint64(sizeLimit)) {
1379 qWarning() << "Ignoring window icon" << icon_data.size()
1380 << "exceeds maximum xcb request length"
1381 << sizeLimit;
1382 return;
1383 }
1384 xcb_change_property(xcb_connection(),
1385 XCB_PROP_MODE_REPLACE,
1386 m_window,
1387 atom(QXcbAtom::Atom_NET_WM_ICON),
1388 atom(QXcbAtom::AtomCARDINAL),
1389 32,
1390 icon_data.size(),
1391 (unsigned char *) icon_data.data());
1392 } else {
1393 xcb_delete_property(xcb_connection(),
1394 m_window,
1395 atom(QXcbAtom::Atom_NET_WM_ICON));
1396 }
1397}
1398
1399void QXcbWindow::raise()
1400{
1401 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1402 const quint32 values[] = { XCB_STACK_MODE_ABOVE };
1403 xcb_configure_window(xcb_connection(), m_window, mask, values);
1404}
1405
1406void QXcbWindow::lower()
1407{
1408 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1409 const quint32 values[] = { XCB_STACK_MODE_BELOW };
1410 xcb_configure_window(xcb_connection(), m_window, mask, values);
1411}
1412
1413void QXcbWindow::propagateSizeHints()
1414{
1415 // update WM_NORMAL_HINTS
1416 xcb_size_hints_t hints;
1417 memset(&hints, 0, sizeof(hints));
1418
1419 const QRect rect = geometry();
1420 QWindowPrivate *win = qt_window_private(window());
1421
1422 if (!win->positionAutomatic)
1423 xcb_icccm_size_hints_set_position(&hints, true, rect.x(), rect.y());
1424 if (rect.width() < QWINDOWSIZE_MAX || rect.height() < QWINDOWSIZE_MAX)
1425 xcb_icccm_size_hints_set_size(&hints, true, rect.width(), rect.height());
1426
1427 /* Gravity describes how to interpret x and y values the next time
1428 window needs to be positioned on a screen.
1429 XCB_GRAVITY_STATIC : the left top corner of the client window
1430 XCB_GRAVITY_NORTH_WEST : the left top corner of the frame window */
1431 auto gravity = win->positionPolicy == QWindowPrivate::WindowFrameInclusive
1432 ? XCB_GRAVITY_NORTH_WEST : XCB_GRAVITY_STATIC;
1433
1434 xcb_icccm_size_hints_set_win_gravity(&hints, gravity);
1435
1436 QSize minimumSize = windowMinimumSize();
1437 QSize maximumSize = windowMaximumSize();
1438 QSize baseSize = windowBaseSize();
1439 QSize sizeIncrement = windowSizeIncrement();
1440
1441 if (minimumSize.width() > 0 || minimumSize.height() > 0)
1442 xcb_icccm_size_hints_set_min_size(&hints,
1443 qMin(XCOORD_MAX,minimumSize.width()),
1444 qMin(XCOORD_MAX,minimumSize.height()));
1445
1446 if (maximumSize.width() < QWINDOWSIZE_MAX || maximumSize.height() < QWINDOWSIZE_MAX)
1447 xcb_icccm_size_hints_set_max_size(&hints,
1448 qMin(XCOORD_MAX, maximumSize.width()),
1449 qMin(XCOORD_MAX, maximumSize.height()));
1450
1451 if (sizeIncrement.width() > 0 || sizeIncrement.height() > 0) {
1452 if (!baseSize.isNull() && baseSize.isValid())
1453 xcb_icccm_size_hints_set_base_size(&hints, baseSize.width(), baseSize.height());
1454 xcb_icccm_size_hints_set_resize_inc(&hints, sizeIncrement.width(), sizeIncrement.height());
1455 }
1456
1457 xcb_icccm_set_wm_normal_hints(xcb_connection(), m_window, &hints);
1458
1459 m_sizeHintsScaleFactor = QHighDpiScaling::factor(screen());
1460}
1461
1462void QXcbWindow::requestActivateWindow()
1463{
1464 /* Never activate embedded windows; doing that would prevent the container
1465 * to re-gain the keyboard focus later. */
1466 if (m_embedded) {
1467 QPlatformWindow::requestActivateWindow();
1468 return;
1469 }
1470
1471 {
1472 QMutexLocker locker(&m_mappedMutex);
1473 if (!m_mapped) {
1474 m_deferredActivation = true;
1475 return;
1476 }
1477 m_deferredActivation = false;
1478 }
1479
1480 updateNetWmUserTime(connection()->time());
1481 QWindow *focusWindow = QGuiApplication::focusWindow();
1482 xcb_window_t current = XCB_NONE;
1483 if (focusWindow) {
1484 if (QPlatformWindow *pw = focusWindow->handle())
1485 current = pw->winId();
1486 }
1487
1488 if (window()->isTopLevel()
1489 && !(window()->flags() & Qt::X11BypassWindowManagerHint)
1490 && (!focusWindow || !window()->isAncestorOf(focusWindow))
1491 && connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::Atom_NET_ACTIVE_WINDOW))) {
1492 xcb_client_message_event_t event;
1493
1494 event.response_type = XCB_CLIENT_MESSAGE;
1495 event.format = 32;
1496 event.sequence = 0;
1497 event.window = m_window;
1498 event.type = atom(QXcbAtom::Atom_NET_ACTIVE_WINDOW);
1499 event.data.data32[0] = 1;
1500 event.data.data32[1] = connection()->time();
1501 event.data.data32[2] = current;
1502 event.data.data32[3] = 0;
1503 event.data.data32[4] = 0;
1504
1505 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1506 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1507 (const char *)&event);
1508 } else {
1509 xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, connection()->time());
1510 }
1511
1512 connection()->sync();
1513}
1514
1515QSurfaceFormat QXcbWindow::format() const
1516{
1517 return m_format;
1518}
1519
1520QXcbWindow::WindowTypes QXcbWindow::wmWindowTypes() const
1521{
1522 WindowTypes result;
1523
1524 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, xcb_connection(),
1525 0, m_window, atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE),
1526 XCB_ATOM_ATOM, 0, 1024);
1527 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) {
1528 const xcb_atom_t *types = static_cast<const xcb_atom_t *>(xcb_get_property_value(reply.get()));
1529 const xcb_atom_t *types_end = types + reply->length;
1530 for (; types != types_end; types++) {
1531 QXcbAtom::Atom type = connection()->qatom(*types);
1532 switch (type) {
1533 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL:
1534 result |= WindowType::Normal;
1535 break;
1536 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DESKTOP:
1537 result |= WindowType::Desktop;
1538 break;
1539 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DOCK:
1540 result |= WindowType::Dock;
1541 break;
1542 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLBAR:
1543 result |= WindowType::Toolbar;
1544 break;
1545 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_MENU:
1546 result |= WindowType::Menu;
1547 break;
1548 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_UTILITY:
1549 result |= WindowType::Utility;
1550 break;
1551 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_SPLASH:
1552 result |= WindowType::Splash;
1553 break;
1554 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DIALOG:
1555 result |= WindowType::Dialog;
1556 break;
1557 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DROPDOWN_MENU:
1558 result |= WindowType::DropDownMenu;
1559 break;
1560 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_POPUP_MENU:
1561 result |= WindowType::PopupMenu;
1562 break;
1563 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLTIP:
1564 result |= WindowType::Tooltip;
1565 break;
1566 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NOTIFICATION:
1567 result |= WindowType::Notification;
1568 break;
1569 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_COMBO:
1570 result |= WindowType::Combo;
1571 break;
1572 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DND:
1573 result |= WindowType::Dnd;
1574 break;
1575 case QXcbAtom::Atom_KDE_NET_WM_WINDOW_TYPE_OVERRIDE:
1576 result |= WindowType::KdeOverride;
1577 break;
1578 default:
1579 break;
1580 }
1581 }
1582 }
1583 return result;
1584}
1585
1586void QXcbWindow::setWmWindowType(WindowTypes types, Qt::WindowFlags flags)
1587{
1588 QList<xcb_atom_t> atoms;
1589
1590 // manual selection 1 (these are never set by Qt and take precedence)
1591 if (types & WindowType::Normal)
1592 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL));
1593 if (types & WindowType::Desktop)
1594 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DESKTOP));
1595 if (types & WindowType::Dock)
1596 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DOCK));
1597 if (types & WindowType::Notification)
1598 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NOTIFICATION));
1599
1600 // manual selection 2 (Qt uses these during auto selection);
1601 if (types & WindowType::Utility)
1602 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_UTILITY));
1603 if (types & WindowType::Splash)
1604 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_SPLASH));
1605 if (types & WindowType::Dialog)
1606 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DIALOG));
1607 if (types & WindowType::Tooltip)
1608 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLTIP));
1609 if (types & WindowType::KdeOverride)
1610 atoms.append(atom(QXcbAtom::Atom_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
1611
1612 // manual selection 3 (these can be set by Qt, but don't have a
1613 // corresponding Qt::WindowType). note that order of the *MENU
1614 // atoms is important
1615 if (types & WindowType::Menu)
1616 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_MENU));
1617 if (types & WindowType::DropDownMenu)
1618 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DROPDOWN_MENU));
1619 if (types & WindowType::PopupMenu)
1620 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_POPUP_MENU));
1621 if (types & WindowType::Toolbar)
1622 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLBAR));
1623 if (types & WindowType::Combo)
1624 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_COMBO));
1625 if (types & WindowType::Dnd)
1626 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DND));
1627
1628 // automatic selection
1629 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
1630 switch (type) {
1631 case Qt::Dialog:
1632 case Qt::Sheet:
1633 if (!(types & WindowType::Dialog))
1634 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DIALOG));
1635 break;
1636 case Qt::Tool:
1637 case Qt::Drawer:
1638 if (!(types & WindowType::Utility))
1639 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_UTILITY));
1640 break;
1641 case Qt::ToolTip:
1642 if (!(types & WindowType::Tooltip))
1643 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLTIP));
1644 break;
1645 case Qt::SplashScreen:
1646 if (!(types & WindowType::Splash))
1647 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_SPLASH));
1648 break;
1649 default:
1650 break;
1651 }
1652
1653 if ((flags & Qt::FramelessWindowHint) && !(types & WindowType::KdeOverride)) {
1654 // override netwm type - quick and easy for KDE noborder
1655 atoms.append(atom(QXcbAtom::Atom_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
1656 }
1657
1658 if (atoms.size() == 1 && atoms.first() == atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL))
1659 atoms.clear();
1660 else
1661 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL));
1662
1663 if (atoms.isEmpty()) {
1664 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE));
1665 } else {
1666 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
1667 atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE), XCB_ATOM_ATOM, 32,
1668 atoms.size(), atoms.constData());
1669 }
1670 xcb_flush(xcb_connection());
1671}
1672
1673void QXcbWindow::setWindowRole(const QString &role)
1674{
1675 QByteArray roleData = role.toLatin1();
1676 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
1677 atom(QXcbAtom::AtomWM_WINDOW_ROLE), XCB_ATOM_STRING, 8,
1678 roleData.size(), roleData.constData());
1679}
1680
1681void QXcbWindow::setParentRelativeBackPixmap()
1682{
1683 const quint32 mask = XCB_CW_BACK_PIXMAP;
1684 const quint32 values[] = { XCB_BACK_PIXMAP_PARENT_RELATIVE };
1685 xcb_change_window_attributes(xcb_connection(), m_window, mask, values);
1686}
1687
1688bool QXcbWindow::requestSystemTrayWindowDock()
1689{
1690 if (!connection()->systemTrayTracker())
1691 return false;
1692 connection()->systemTrayTracker()->requestSystemTrayWindowDock(m_window);
1693 return true;
1694}
1695
1696bool QXcbWindow::handleNativeEvent(xcb_generic_event_t *event)
1697{
1698 auto eventType = connection()->nativeInterface()->nativeEventType();
1699 qintptr result = 0; // Used only by MS Windows
1700 return QWindowSystemInterface::handleNativeEvent(window(), eventType, event, &result);
1701}
1702
1703void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
1704{
1705 QRect rect(event->x, event->y, event->width, event->height);
1706 m_exposeRegion |= rect;
1707
1708 bool pending = true;
1709
1710 connection()->eventQueue()->peek(QXcbEventQueue::PeekConsumeMatchAndContinue,
1711 [this, &pending](xcb_generic_event_t *event, int type) {
1712 if (type != XCB_EXPOSE)
1713 return false;
1714 auto expose = reinterpret_cast<xcb_expose_event_t *>(event);
1715 if (expose->window != m_window)
1716 return false;
1717 if (expose->count == 0)
1718 pending = false;
1719 m_exposeRegion |= QRect(expose->x, expose->y, expose->width, expose->height);
1720 free(expose);
1721 return true;
1722 });
1723
1724 // if count is non-zero there are more expose events pending
1725 if (event->count == 0 || !pending) {
1726 QWindowSystemInterface::handleExposeEvent(window(), m_exposeRegion);
1727 m_exposeRegion = QRegion();
1728 }
1729}
1730
1731void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event)
1732{
1733 if (event->format != 32)
1734 return;
1735
1736 if (event->type == atom(QXcbAtom::AtomWM_PROTOCOLS)) {
1737 xcb_atom_t protocolAtom = event->data.data32[0];
1738 if (protocolAtom == atom(QXcbAtom::AtomWM_DELETE_WINDOW)) {
1739 QWindowSystemInterface::handleCloseEvent(window());
1740 } else if (protocolAtom == atom(QXcbAtom::AtomWM_TAKE_FOCUS)) {
1741 connection()->setTime(event->data.data32[1]);
1742 relayFocusToModalWindow();
1743 return;
1744 } else if (protocolAtom == atom(QXcbAtom::Atom_NET_WM_PING)) {
1745 if (event->window == xcbScreen()->root())
1746 return;
1747
1748 xcb_client_message_event_t reply = *event;
1749
1750 reply.response_type = XCB_CLIENT_MESSAGE;
1751 reply.window = xcbScreen()->root();
1752
1753 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1754 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1755 (const char *)&reply);
1756 xcb_flush(xcb_connection());
1757 } else if (protocolAtom == atom(QXcbAtom::Atom_NET_WM_SYNC_REQUEST)) {
1758 connection()->setTime(event->data.data32[1]);
1759 m_syncValue.lo = event->data.data32[2];
1760 m_syncValue.hi = event->data.data32[3];
1761 if (connection()->hasXSync())
1762 m_syncState = SyncReceived;
1763#ifndef QT_NO_WHATSTHIS
1764 } else if (protocolAtom == atom(QXcbAtom::Atom_NET_WM_CONTEXT_HELP)) {
1765 QWindowSystemInterface::handleEnterWhatsThisEvent();
1766#endif
1767 } else {
1768 qCWarning(lcQpaXcb, "Unhandled WM_PROTOCOLS (%s)",
1769 connection()->atomName(protocolAtom).constData());
1770 }
1771#if QT_CONFIG(draganddrop)
1772 } else if (event->type == atom(QXcbAtom::AtomXdndEnter)) {
1773 connection()->drag()->handleEnter(this, event);
1774 } else if (event->type == atom(QXcbAtom::AtomXdndPosition)) {
1775 connection()->drag()->handlePosition(this, event);
1776 } else if (event->type == atom(QXcbAtom::AtomXdndLeave)) {
1777 connection()->drag()->handleLeave(this, event);
1778 } else if (event->type == atom(QXcbAtom::AtomXdndDrop)) {
1779 connection()->drag()->handleDrop(this, event);
1780#endif
1781 } else if (event->type == atom(QXcbAtom::Atom_XEMBED)) {
1782 handleXEmbedMessage(event);
1783 } else if (event->type == atom(QXcbAtom::Atom_NET_ACTIVE_WINDOW)) {
1784 doFocusIn();
1785 } else if (event->type == atom(QXcbAtom::AtomMANAGER)
1786 || event->type == atom(QXcbAtom::Atom_NET_WM_STATE)
1787 || event->type == atom(QXcbAtom::AtomWM_CHANGE_STATE)) {
1788 // Ignore _NET_WM_STATE, MANAGER which are relate to tray icons
1789 // and other messages.
1790 } else if (event->type == atom(QXcbAtom::Atom_COMPIZ_DECOR_PENDING)
1791 || event->type == atom(QXcbAtom::Atom_COMPIZ_DECOR_REQUEST)
1792 || event->type == atom(QXcbAtom::Atom_COMPIZ_DECOR_DELETE_PIXMAP)
1793 || event->type == atom(QXcbAtom::Atom_COMPIZ_TOOLKIT_ACTION)
1794 || event->type == atom(QXcbAtom::Atom_GTK_LOAD_ICONTHEMES)) {
1795 //silence the _COMPIZ and _GTK messages for now
1796 } else {
1797 qCWarning(lcQpaXcb) << "Unhandled client message: " << connection()->atomName(event->type);
1798 }
1799}
1800
1801void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event)
1802{
1803 bool fromSendEvent = (event->response_type & 0x80);
1804 QPoint pos(event->x, event->y);
1805 if (!QPlatformWindow::parent() && !fromSendEvent) {
1806 // Do not trust the position, query it instead.
1807 auto reply = Q_XCB_REPLY(xcb_translate_coordinates, xcb_connection(),
1808 xcb_window(), xcbScreen()->root(), 0, 0);
1809 if (reply) {
1810 pos.setX(reply->dst_x);
1811 pos.setY(reply->dst_y);
1812 }
1813 }
1814
1815 const QRect actualGeometry = QRect(pos, QSize(event->width, event->height));
1816 QPlatformScreen *newScreen = QPlatformWindow::parent() ? QPlatformWindow::parent()->screen() : screenForGeometry(actualGeometry);
1817 if (!newScreen)
1818 return;
1819
1820 QWindowSystemInterface::handleGeometryChange(window(), actualGeometry);
1821
1822 // QPlatformScreen::screen() is updated asynchronously, so we can't compare it
1823 // with the newScreen. Just send the WindowScreenChanged event and QGuiApplication
1824 // will make the comparison later.
1825 QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen());
1826
1827 if (!qFuzzyCompare(QHighDpiScaling::factor(newScreen), m_sizeHintsScaleFactor))
1828 propagateSizeHints();
1829
1830 // Send the synthetic expose event on resize only when the window is shrunk,
1831 // because the "XCB_GRAVITY_NORTH_WEST" flag doesn't send it automatically.
1832 if (!m_oldWindowSize.isEmpty()
1833 && (actualGeometry.width() < m_oldWindowSize.width()
1834 || actualGeometry.height() < m_oldWindowSize.height())) {
1835 QWindowSystemInterface::handleExposeEvent(window(), QRegion(0, 0, actualGeometry.width(), actualGeometry.height()));
1836 }
1837 m_oldWindowSize = actualGeometry.size();
1838
1839 if (connection()->hasXSync() && m_syncState == SyncReceived)
1840 m_syncState = SyncAndConfigureReceived;
1841
1842 m_dirtyFrameMargins = true;
1843}
1844
1845bool QXcbWindow::isExposed() const
1846{
1847 return m_mapped;
1848}
1849
1850bool QXcbWindow::isEmbedded() const
1851{
1852 return m_embedded;
1853}
1854
1855QPoint QXcbWindow::mapToGlobal(const QPoint &pos) const
1856{
1857 if (!m_embedded)
1858 return QPlatformWindow::mapToGlobal(pos);
1859
1860 QPoint ret;
1861 auto reply = Q_XCB_REPLY(xcb_translate_coordinates, xcb_connection(),
1862 xcb_window(), xcbScreen()->root(),
1863 pos.x(), pos.y());
1864 if (reply) {
1865 ret.setX(reply->dst_x);
1866 ret.setY(reply->dst_y);
1867 }
1868
1869 return ret;
1870}
1871
1872QPoint QXcbWindow::mapFromGlobal(const QPoint &pos) const
1873{
1874 if (!m_embedded)
1875 return QPlatformWindow::mapFromGlobal(pos);
1876
1877 QPoint ret;
1878 auto reply = Q_XCB_REPLY(xcb_translate_coordinates, xcb_connection(),
1879 xcbScreen()->root(), xcb_window(),
1880 pos.x(), pos.y());
1881 if (reply) {
1882 ret.setX(reply->dst_x);
1883 ret.setY(reply->dst_y);
1884 }
1885
1886 return ret;
1887}
1888
1889void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event)
1890{
1891 if (event->window == m_window) {
1892 m_mappedMutex.lock();
1893 m_mapped = true;
1894 const bool deferredActivation = m_deferredActivation;
1895 m_mappedMutex.unlock();
1896 if (deferredActivation)
1897 requestActivateWindow();
1898
1899 QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size()));
1900 }
1901}
1902
1903void QXcbWindow::handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event)
1904{
1905 if (event->window == m_window) {
1906 m_mappedMutex.lock();
1907 m_mapped = false;
1908 m_mappedMutex.unlock();
1909 QWindowSystemInterface::handleExposeEvent(window(), QRegion());
1910 }
1911}
1912
1913void QXcbWindow::handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y,
1914 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
1915 QEvent::Type type, Qt::MouseEventSource source)
1916{
1917 const bool isWheel = detail >= 4 && detail <= 7;
1918 if (!isWheel && window() != QGuiApplication::focusWindow()) {
1919 QWindow *w = static_cast<QWindowPrivate *>(QObjectPrivate::get(window()))->eventReceiver();
1920 if (!(w->flags() & (Qt::WindowDoesNotAcceptFocus | Qt::BypassWindowManagerHint))
1921 && w->type() != Qt::ToolTip
1922 && w->type() != Qt::Popup) {
1923 w->requestActivate();
1924 }
1925 }
1926
1927 updateNetWmUserTime(timestamp);
1928
1929 if (m_embedded && !m_trayIconWindow) {
1930 if (window() != QGuiApplication::focusWindow()) {
1931 const QXcbWindow *container = static_cast<const QXcbWindow *>(QPlatformWindow::parent());
1932 Q_ASSERT(container != nullptr);
1933
1934 sendXEmbedMessage(container->xcb_window(), XEMBED_REQUEST_FOCUS);
1935 }
1936 }
1937 QPoint local(event_x, event_y);
1938 QPoint global(root_x, root_y);
1939
1940 if (isWheel) {
1941 if (!connection()->isAtLeastXI21()) {
1942 QPoint angleDelta;
1943 if (detail == 4)
1944 angleDelta.setY(120);
1945 else if (detail == 5)
1946 angleDelta.setY(-120);
1947 else if (detail == 6)
1948 angleDelta.setX(120);
1949 else if (detail == 7)
1950 angleDelta.setX(-120);
1951 if (modifiers & Qt::AltModifier)
1952 angleDelta = angleDelta.transposed();
1953 QWindowSystemInterface::handleWheelEvent(window(), timestamp, local, global, QPoint(), angleDelta, modifiers);
1954 }
1955 return;
1956 }
1957
1958 connection()->setMousePressWindow(this);
1959
1960 handleMouseEvent(timestamp, local, global, modifiers, type, source);
1961}
1962
1963void QXcbWindow::handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
1964 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
1965 QEvent::Type type, Qt::MouseEventSource source)
1966{
1967 QPoint local(event_x, event_y);
1968 QPoint global(root_x, root_y);
1969
1970 if (detail >= 4 && detail <= 7) {
1971 // mouse wheel, handled in handleButtonPressEvent()
1972 return;
1973 }
1974
1975 if (connection()->buttonState() == Qt::NoButton) {
1976 connection()->setMousePressWindow(nullptr);
1977 m_ignorePressedWindowOnMouseLeave = false;
1978 }
1979
1980 handleMouseEvent(timestamp, local, global, modifiers, type, source);
1981}
1982
1983static inline bool doCheckUnGrabAncestor(QXcbConnection *conn)
1984{
1985 /* Checking for XCB_NOTIFY_MODE_GRAB and XCB_NOTIFY_DETAIL_ANCESTOR prevents unwanted
1986 * enter/leave events on AwesomeWM on mouse button press. It also ignores duplicated
1987 * enter/leave events on Alt+Tab switching on some WMs with XInput2 events.
1988 * Without XInput2 events the (Un)grabAncestor cannot be checked when mouse button is
1989 * not pressed, otherwise (e.g. on Alt+Tab) it can igonre important enter/leave events.
1990 */
1991 if (conn) {
1992 const bool mouseButtonsPressed = (conn->buttonState() != Qt::NoButton);
1993 return mouseButtonsPressed || conn->hasXInput2();
1994 }
1995 return true;
1996}
1997
1998static bool ignoreLeaveEvent(quint8 mode, quint8 detail, QXcbConnection *conn)
1999{
2000 return ((doCheckUnGrabAncestor(conn)
2001 && mode == XCB_NOTIFY_MODE_GRAB && detail == XCB_NOTIFY_DETAIL_ANCESTOR)
2002 || (mode == XCB_NOTIFY_MODE_UNGRAB && detail == XCB_NOTIFY_DETAIL_INFERIOR)
2003 || detail == XCB_NOTIFY_DETAIL_VIRTUAL
2004 || detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL);
2005}
2006
2007static bool ignoreEnterEvent(quint8 mode, quint8 detail, QXcbConnection *conn = nullptr)
2008{
2009 return ((doCheckUnGrabAncestor(conn)
2010 && mode == XCB_NOTIFY_MODE_UNGRAB && detail == XCB_NOTIFY_DETAIL_ANCESTOR)
2011 || (mode != XCB_NOTIFY_MODE_NORMAL && mode != XCB_NOTIFY_MODE_UNGRAB)
2012 || detail == XCB_NOTIFY_DETAIL_VIRTUAL
2013 || detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL);
2014}
2015
2016void QXcbWindow::handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y,
2017 quint8 mode, quint8 detail, xcb_timestamp_t timestamp)
2018{
2019 connection()->setTime(timestamp);
2020
2021 if (ignoreEnterEvent(mode, detail, connection())
2022 || (connection()->mousePressWindow() && !m_ignorePressedWindowOnMouseLeave)) {
2023 return;
2024 }
2025
2026 // Updates scroll valuators, as user might have done some scrolling outside our X client.
2027 connection()->xi2UpdateScrollingDevices();
2028
2029 if (mode == XCB_NOTIFY_MODE_UNGRAB && connection()->queryMouseButtons() != Qt::NoButton)
2030 m_ignorePressedWindowOnMouseLeave = true;
2031
2032 const QPoint global = QPoint(root_x, root_y);
2033 const QPoint local(event_x, event_y);
2034 QWindowSystemInterface::handleEnterEvent(window(), local, global);
2035}
2036
2037void QXcbWindow::handleLeaveNotifyEvent(int root_x, int root_y,
2038 quint8 mode, quint8 detail, xcb_timestamp_t timestamp)
2039{
2040 connection()->setTime(timestamp);
2041
2042 QXcbWindow *mousePressWindow = connection()->mousePressWindow();
2043 if (ignoreLeaveEvent(mode, detail, connection())
2044 || (mousePressWindow && !m_ignorePressedWindowOnMouseLeave)) {
2045 return;
2046 }
2047
2048 // check if enter event is buffered
2049 auto event = connection()->eventQueue()->peek([](xcb_generic_event_t *event, int type) {
2050 if (type != XCB_ENTER_NOTIFY)
2051 return false;
2052 auto enter = reinterpret_cast<xcb_enter_notify_event_t *>(event);
2053 return !ignoreEnterEvent(enter->mode, enter->detail);
2054 });
2055 auto enter = reinterpret_cast<xcb_enter_notify_event_t *>(event);
2056 QXcbWindow *enterWindow = enter ? connection()->platformWindowFromId(enter->event) : nullptr;
2057
2058 if (enterWindow) {
2059 QPoint local(enter->event_x, enter->event_y);
2060 QPoint global = QPoint(root_x, root_y);
2061 QWindowSystemInterface::handleEnterLeaveEvent(enterWindow->window(), window(), local, global);
2062 } else {
2063 QWindowSystemInterface::handleLeaveEvent(window());
2064 if (m_ignorePressedWindowOnMouseLeave)
2065 connection()->setMousePressWindow(nullptr);
2066 }
2067
2068 free(enter);
2069}
2070
2071void QXcbWindow::handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
2072 Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
2073 QEvent::Type type, Qt::MouseEventSource source)
2074{
2075 QPoint local(event_x, event_y);
2076 QPoint global(root_x, root_y);
2077
2078 // "mousePressWindow" can be NULL i.e. if a window will be grabbed or unmapped, so set it again here.
2079 // Unset "mousePressWindow" when mouse button isn't pressed - in some cases the release event won't arrive.
2080 const bool isMouseButtonPressed = (connection()->buttonState() != Qt::NoButton);
2081 const bool hasMousePressWindow = (connection()->mousePressWindow() != nullptr);
2082 if (isMouseButtonPressed && !hasMousePressWindow)
2083 connection()->setMousePressWindow(this);
2084 else if (hasMousePressWindow && !isMouseButtonPressed)
2085 connection()->setMousePressWindow(nullptr);
2086
2087 handleMouseEvent(timestamp, local, global, modifiers, type, source);
2088}
2089
2090void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
2091{
2092 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
2093 handleButtonPressEvent(event->event_x, event->event_y, event->root_x, event->root_y, event->detail,
2094 modifiers, event->time, QEvent::MouseButtonPress);
2095}
2096
2097void QXcbWindow::handleButtonReleaseEvent(const xcb_button_release_event_t *event)
2098{
2099 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
2100 handleButtonReleaseEvent(event->event_x, event->event_y, event->root_x, event->root_y, event->detail,
2101 modifiers, event->time, QEvent::MouseButtonRelease);
2102}
2103
2104void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
2105{
2106 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
2107 handleMotionNotifyEvent(event->event_x, event->event_y, event->root_x, event->root_y, modifiers,
2108 event->time, QEvent::MouseMove);
2109}
2110
2111static inline int fixed1616ToInt(xcb_input_fp1616_t val)
2112{
2113 return int(qreal(val) / 0x10000);
2114}
2115
2116#define qt_xcb_mask_is_set(ptr, event) (((unsigned char*)(ptr))[(event)>>3] & (1 << ((event) & 7)))
2117
2118void QXcbWindow::handleXIMouseEvent(xcb_ge_event_t *event, Qt::MouseEventSource source)
2119{
2120 QXcbConnection *conn = connection();
2121 auto *ev = reinterpret_cast<xcb_input_button_press_event_t *>(event);
2122
2123 if (ev->buttons_len > 0) {
2124 unsigned char *buttonMask = (unsigned char *) &ev[1];
2125 // There is a bug in the evdev driver which leads to receiving mouse events without
2126 // XIPointerEmulated being set: https://bugs.freedesktop.org/show_bug.cgi?id=98188
2127 // Filter them out by other attributes: when their source device is a touch screen
2128 // and the LMB is pressed.
2129 if (qt_xcb_mask_is_set(buttonMask, 1) && conn->isTouchScreen(ev->sourceid)) {
2130 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2131 qCDebug(lcQpaXInput, "XI2 mouse event from touch device %d was ignored", ev->sourceid);
2132 return;
2133 }
2134 for (int i = 1; i <= 15; ++i)
2135 conn->setButtonState(conn->translateMouseButton(i), qt_xcb_mask_is_set(buttonMask, i));
2136 }
2137
2138 const Qt::KeyboardModifiers modifiers = conn->keyboard()->translateModifiers(ev->mods.effective);
2139 const int event_x = fixed1616ToInt(ev->event_x);
2140 const int event_y = fixed1616ToInt(ev->event_y);
2141 const int root_x = fixed1616ToInt(ev->root_x);
2142 const int root_y = fixed1616ToInt(ev->root_y);
2143
2144 conn->keyboard()->updateXKBStateFromXI(&ev->mods, &ev->group);
2145
2146 const Qt::MouseButton button = conn->xiToQtMouseButton(ev->detail);
2147
2148 const char *sourceName = nullptr;
2149 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled())) {
2150 const QMetaObject *metaObject = qt_getEnumMetaObject(source);
2151 const QMetaEnum me = metaObject->enumerator(metaObject->indexOfEnumerator(qt_getEnumName(source)));
2152 sourceName = me.valueToKey(source);
2153 }
2154
2155 switch (ev->event_type) {
2156 case XCB_INPUT_BUTTON_PRESS:
2157 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2158 qCDebug(lcQpaXInputEvents, "XI2 mouse press, button %d, time %d, source %s", button, ev->time, sourceName);
2159 conn->setButtonState(button, true);
2160 handleButtonPressEvent(event_x, event_y, root_x, root_y, ev->detail, modifiers, ev->time, QEvent::MouseButtonPress, source);
2161 break;
2162 case XCB_INPUT_BUTTON_RELEASE:
2163 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2164 qCDebug(lcQpaXInputEvents, "XI2 mouse release, button %d, time %d, source %s", button, ev->time, sourceName);
2165 conn->setButtonState(button, false);
2166 handleButtonReleaseEvent(event_x, event_y, root_x, root_y, ev->detail, modifiers, ev->time, QEvent::MouseButtonRelease, source);
2167 break;
2168 case XCB_INPUT_MOTION:
2169 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2170 qCDebug(lcQpaXInputEvents, "XI2 mouse motion %d,%d, time %d, source %s", event_x, event_y, ev->time, sourceName);
2171 handleMotionNotifyEvent(event_x, event_y, root_x, root_y, modifiers, ev->time, QEvent::MouseMove, source);
2172 break;
2173 default:
2174 qWarning() << "Unrecognized XI2 mouse event" << ev->event_type;
2175 break;
2176 }
2177}
2178
2179void QXcbWindow::handleXIEnterLeave(xcb_ge_event_t *event)
2180{
2181 auto *ev = reinterpret_cast<xcb_input_enter_event_t *>(event);
2182
2183 // Compare the window with current mouse grabber to prevent deliver events to any other windows.
2184 // If leave event occurs and the window is under mouse - allow to deliver the leave event.
2185 QXcbWindow *mouseGrabber = connection()->mouseGrabber();
2186 if (mouseGrabber && mouseGrabber != this
2187 && (ev->event_type != XCB_INPUT_LEAVE || QGuiApplicationPrivate::currentMouseWindow != window())) {
2188 return;
2189 }
2190
2191 const int root_x = fixed1616ToInt(ev->root_x);
2192 const int root_y = fixed1616ToInt(ev->root_y);
2193
2194 switch (ev->event_type) {
2195 case XCB_INPUT_ENTER: {
2196 const int event_x = fixed1616ToInt(ev->event_x);
2197 const int event_y = fixed1616ToInt(ev->event_y);
2198 qCDebug(lcQpaXInputEvents, "XI2 mouse enter %d,%d, mode %d, detail %d, time %d",
2199 event_x, event_y, ev->mode, ev->detail, ev->time);
2200 handleEnterNotifyEvent(event_x, event_y, root_x, root_y, ev->mode, ev->detail, ev->time);
2201 break;
2202 }
2203 case XCB_INPUT_LEAVE:
2204 qCDebug(lcQpaXInputEvents, "XI2 mouse leave, mode %d, detail %d, time %d",
2205 ev->mode, ev->detail, ev->time);
2206 connection()->keyboard()->updateXKBStateFromXI(&ev->mods, &ev->group);
2207 handleLeaveNotifyEvent(root_x, root_y, ev->mode, ev->detail, ev->time);
2208 break;
2209 }
2210}
2211
2212QXcbWindow *QXcbWindow::toWindow() { return this; }
2213
2214void QXcbWindow::handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global,
2215 Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source)
2216{
2217 m_lastPointerPosition = local;
2218 m_lastPointerGlobalPosition = global;
2219 connection()->setTime(time);
2220 Qt::MouseButton button = type == QEvent::MouseMove ? Qt::NoButton : connection()->button();
2221 QWindowSystemInterface::handleMouseEvent(window(), time, local, global,
2222 connection()->buttonState(), button,
2223 type, modifiers, source);
2224}
2225
2226void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
2227{
2228 handleEnterNotifyEvent(event->event_x, event->event_y, event->root_x, event->root_y, event->mode, event->detail, event->time);
2229}
2230
2231void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
2232{
2233 handleLeaveNotifyEvent(event->root_x, event->root_y, event->mode, event->detail, event->time);
2234}
2235
2236void QXcbWindow::handlePropertyNotifyEvent(const xcb_property_notify_event_t *event)
2237{
2238 connection()->setTime(event->time);
2239
2240 const bool propertyDeleted = event->state == XCB_PROPERTY_DELETE;
2241
2242 if (event->atom == atom(QXcbAtom::Atom_NET_WM_STATE) || event->atom == atom(QXcbAtom::AtomWM_STATE)) {
2243 if (propertyDeleted)
2244 return;
2245
2246 Qt::WindowStates newState = Qt::WindowNoState;
2247
2248 if (event->atom == atom(QXcbAtom::AtomWM_STATE)) { // WM_STATE: Quick check for 'Minimize'.
2249 auto reply = Q_XCB_REPLY(xcb_get_property, xcb_connection(),
2250 0, m_window, atom(QXcbAtom::AtomWM_STATE),
2251 XCB_ATOM_ANY, 0, 1024);
2252 if (reply && reply->format == 32 && reply->type == atom(QXcbAtom::AtomWM_STATE)) {
2253 const quint32 *data = (const quint32 *)xcb_get_property_value(reply.get());
2254 if (reply->length != 0)
2255 m_minimized = (data[0] == XCB_ICCCM_WM_STATE_ICONIC
2256 || (data[0] == XCB_ICCCM_WM_STATE_WITHDRAWN && m_minimized));
2257 }
2258 }
2259
2260 const NetWmStates states = netWmStates();
2261 // _NET_WM_STATE_HIDDEN should be set by the Window Manager to indicate that a window would
2262 // not be visible on the screen if its desktop/viewport were active and its coordinates were
2263 // within the screen bounds. The canonical example is that minimized windows should be in
2264 // the _NET_WM_STATE_HIDDEN state.
2265 if (m_minimized && (!connection()->wmSupport()->isSupportedByWM(NetWmStateHidden)
2266 || states.testFlag(NetWmStateHidden)))
2267 newState = Qt::WindowMinimized;
2268
2269 if (states & NetWmStateFullScreen)
2270 newState |= Qt::WindowFullScreen;
2271 if ((states & NetWmStateMaximizedHorz) && (states & NetWmStateMaximizedVert))
2272 newState |= Qt::WindowMaximized;
2273 // Send Window state, compress events in case other flags (modality, etc) are changed.
2274 if (m_lastWindowStateEvent != newState) {
2275 QWindowSystemInterface::handleWindowStateChanged(window(), newState);
2276 m_lastWindowStateEvent = newState;
2277 m_windowState = newState;
2278 if ((m_windowState & Qt::WindowMinimized) && connection()->mouseGrabber() == this)
2279 connection()->setMouseGrabber(nullptr);
2280 }
2281 return;
2282 } else if (event->atom == atom(QXcbAtom::Atom_NET_FRAME_EXTENTS)) {
2283 m_dirtyFrameMargins = true;
2284 }
2285}
2286
2287void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *event)
2288{
2289 // Ignore focus events that are being sent only because the pointer is over
2290 // our window, even if the input focus is in a different window.
2291 if (event->detail == XCB_NOTIFY_DETAIL_POINTER)
2292 return;
2293
2294 connection()->focusInTimer().stop();
2295 doFocusIn();
2296}
2297
2298
2299void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *event)
2300{
2301 // Ignore focus events that are being sent only because the pointer is over
2302 // our window, even if the input focus is in a different window.
2303 if (event->detail == XCB_NOTIFY_DETAIL_POINTER)
2304 return;
2305 doFocusOut();
2306}
2307
2308void QXcbWindow::updateSyncRequestCounter()
2309{
2310 if (m_syncState != SyncAndConfigureReceived) {
2311 // window manager does not expect a sync event yet.
2312 return;
2313 }
2314 if (connection()->hasXSync() && (m_syncValue.lo != 0 || m_syncValue.hi != 0)) {
2315 xcb_sync_set_counter(xcb_connection(), m_syncCounter, m_syncValue);
2316 xcb_flush(xcb_connection());
2317
2318 m_syncValue.lo = 0;
2319 m_syncValue.hi = 0;
2320 m_syncState = NoSyncNeeded;
2321 }
2322}
2323
2324const xcb_visualtype_t *QXcbWindow::createVisual()
2325{
2326 return xcbScreen() ? xcbScreen()->visualForFormat(m_format)
2327 : nullptr;
2328}
2329
2330bool QXcbWindow::setKeyboardGrabEnabled(bool grab)
2331{
2332 if (grab && !connection()->canGrab())
2333 return false;
2334
2335 if (!grab) {
2336 xcb_ungrab_keyboard(xcb_connection(), XCB_TIME_CURRENT_TIME);
2337 return true;
2338 }
2339
2340 auto reply = Q_XCB_REPLY(xcb_grab_keyboard, xcb_connection(), false,
2341 m_window, XCB_TIME_CURRENT_TIME,
2342 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
2343 return reply && reply->status == XCB_GRAB_STATUS_SUCCESS;
2344}
2345
2346bool QXcbWindow::setMouseGrabEnabled(bool grab)
2347{
2348 if (!grab && connection()->mouseGrabber() == this)
2349 connection()->setMouseGrabber(nullptr);
2350
2351 if (grab && !connection()->canGrab())
2352 return false;
2353
2354 if (connection()->hasXInput2()) {
2355 bool result = connection()->xi2SetMouseGrabEnabled(m_window, grab);
2356 if (grab && result)
2357 connection()->setMouseGrabber(this);
2358 return result;
2359 }
2360
2361 if (!grab) {
2362 xcb_ungrab_pointer(xcb_connection(), XCB_TIME_CURRENT_TIME);
2363 return true;
2364 }
2365
2366 auto reply = Q_XCB_REPLY(xcb_grab_pointer, xcb_connection(),
2367 false, m_window,
2368 (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
2369 | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_ENTER_WINDOW
2370 | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION),
2371 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
2372 XCB_WINDOW_NONE, XCB_CURSOR_NONE,
2373 XCB_TIME_CURRENT_TIME);
2374 bool result = reply && reply->status == XCB_GRAB_STATUS_SUCCESS;
2375 if (result)
2376 connection()->setMouseGrabber(this);
2377 return result;
2378}
2379
2380bool QXcbWindow::windowEvent(QEvent *event)
2381{
2382 switch (event->type()) {
2383 case QEvent::FocusIn:
2384 if (m_embedded && !m_trayIconWindow && !event->spontaneous()) {
2385 QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event);
2386 switch (focusEvent->reason()) {
2387 case Qt::TabFocusReason:
2388 case Qt::BacktabFocusReason:
2389 {
2390 const QXcbWindow *container =
2391 static_cast<const QXcbWindow *>(QPlatformWindow::parent());
2392 sendXEmbedMessage(container->xcb_window(),
2393 focusEvent->reason() == Qt::TabFocusReason ?
2394 XEMBED_FOCUS_NEXT : XEMBED_FOCUS_PREV);
2395 event->accept();
2396 }
2397 break;
2398 default:
2399 break;
2400 }
2401 }
2402 break;
2403 default:
2404 break;
2405 }
2406 return QPlatformWindow::windowEvent(event);
2407}
2408
2409bool QXcbWindow::startSystemResize(Qt::Edges edges)
2410{
2411 return startSystemMoveResize(m_lastPointerPosition, edges);
2412}
2413
2414bool QXcbWindow::startSystemMove()
2415{
2416 return startSystemMoveResize(m_lastPointerPosition, 16);
2417}
2418
2419bool QXcbWindow::startSystemMoveResize(const QPoint &pos, int edges)
2420{
2421 const xcb_atom_t moveResize = connection()->atom(QXcbAtom::Atom_NET_WM_MOVERESIZE);
2422 if (!connection()->wmSupport()->isSupportedByWM(moveResize))
2423 return false;
2424
2425 // ### FIXME QTBUG-53389
2426 bool startedByTouch = connection()->startSystemMoveResizeForTouch(m_window, edges);
2427 if (startedByTouch) {
2428 const QString wmname = connection()->windowManagerName();
2429 if (wmname != "kwin"_L1 && wmname != "openbox"_L1) {
2430 qCDebug(lcQpaInputDevices) << "only KDE and OpenBox support startSystemMove/Resize which is triggered from touch events: XDG_CURRENT_DESKTOP="
2431 << qgetenv("XDG_CURRENT_DESKTOP");
2432 connection()->abortSystemMoveResize(m_window);
2433 return false;
2434 }
2435 // KWin, Openbox, AwesomeWM and Gnome have been tested to work with _NET_WM_MOVERESIZE.
2436 } else { // Started by mouse press.
2437 doStartSystemMoveResize(mapToGlobal(pos), edges);
2438 }
2439
2440 return true;
2441}
2442
2443static uint qtEdgesToXcbMoveResizeDirection(Qt::Edges edges)
2444{
2445 if (edges == (Qt::TopEdge | Qt::LeftEdge))
2446 return 0;
2447 if (edges == Qt::TopEdge)
2448 return 1;
2449 if (edges == (Qt::TopEdge | Qt::RightEdge))
2450 return 2;
2451 if (edges == Qt::RightEdge)
2452 return 3;
2453 if (edges == (Qt::RightEdge | Qt::BottomEdge))
2454 return 4;
2455 if (edges == Qt::BottomEdge)
2456 return 5;
2457 if (edges == (Qt::BottomEdge | Qt::LeftEdge))
2458 return 6;
2459 if (edges == Qt::LeftEdge)
2460 return 7;
2461
2462 qWarning() << "Cannot convert " << edges << "to _NET_WM_MOVERESIZE direction.";
2463 return 0;
2464}
2465
2466void QXcbWindow::doStartSystemMoveResize(const QPoint &globalPos, int edges)
2467{
2468 qCDebug(lcQpaInputDevices) << "triggered system move or resize via sending _NET_WM_MOVERESIZE client message";
2469 const xcb_atom_t moveResize = connection()->atom(QXcbAtom::Atom_NET_WM_MOVERESIZE);
2470 xcb_client_message_event_t xev;
2471 xev.response_type = XCB_CLIENT_MESSAGE;
2472 xev.type = moveResize;
2473 xev.sequence = 0;
2474 xev.window = xcb_window();
2475 xev.format = 32;
2476 xev.data.data32[0] = globalPos.x();
2477 xev.data.data32[1] = globalPos.y();
2478 if (edges == 16)
2479 xev.data.data32[2] = 8; // move
2480 else
2481 xev.data.data32[2] = qtEdgesToXcbMoveResizeDirection(Qt::Edges(edges));
2482 xev.data.data32[3] = XCB_BUTTON_INDEX_1;
2483 xev.data.data32[4] = 0;
2484 xcb_ungrab_pointer(connection()->xcb_connection(), XCB_CURRENT_TIME);
2485 xcb_send_event(connection()->xcb_connection(), false, xcbScreen()->root(),
2486 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
2487 (const char *)&xev);
2488
2489 connection()->setDuringSystemMoveResize(true);
2490}
2491
2492// Sends an XEmbed message.
2493void QXcbWindow::sendXEmbedMessage(xcb_window_t window, quint32 message,
2494 quint32 detail, quint32 data1, quint32 data2)
2495{
2496 xcb_client_message_event_t event;
2497
2498 event.response_type = XCB_CLIENT_MESSAGE;
2499 event.format = 32;
2500 event.sequence = 0;
2501 event.window = window;
2502 event.type = atom(QXcbAtom::Atom_XEMBED);
2503 event.data.data32[0] = connection()->time();
2504 event.data.data32[1] = message;
2505 event.data.data32[2] = detail;
2506 event.data.data32[3] = data1;
2507 event.data.data32[4] = data2;
2508 xcb_send_event(xcb_connection(), false, window, XCB_EVENT_MASK_NO_EVENT, (const char *)&event);
2509}
2510
2511static bool focusWindowChangeQueued(const QWindow *window)
2512{
2513 /* Check from window system event queue if the next queued activation
2514 * targets a window other than @window.
2515 */
2516 QWindowSystemInterfacePrivate::FocusWindowEvent *systemEvent =
2517 static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>
2518 (QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::FocusWindow));
2519 return systemEvent && systemEvent->focused != window;
2520}
2521
2522void QXcbWindow::handleXEmbedMessage(const xcb_client_message_event_t *event)
2523{
2524 connection()->setTime(event->data.data32[0]);
2525 switch (event->data.data32[1]) {
2526 case XEMBED_WINDOW_ACTIVATE:
2527 case XEMBED_WINDOW_DEACTIVATE:
2528 break;
2529 case XEMBED_EMBEDDED_NOTIFY:
2530 xcb_map_window(xcb_connection(), m_window);
2531 xcbScreen()->windowShown(this);
2532 break;
2533 case XEMBED_FOCUS_IN:
2534 connection()->focusInTimer().stop();
2535 Qt::FocusReason reason;
2536 switch (event->data.data32[2]) {
2537 case XEMBED_FOCUS_FIRST:
2538 reason = Qt::TabFocusReason;
2539 break;
2540 case XEMBED_FOCUS_LAST:
2541 reason = Qt::BacktabFocusReason;
2542 break;
2543 case XEMBED_FOCUS_CURRENT:
2544 default:
2545 reason = Qt::OtherFocusReason;
2546 break;
2547 }
2548 connection()->setFocusWindow(window());
2549 QWindowSystemInterface::handleFocusWindowChanged(window(), reason);
2550 break;
2551 case XEMBED_FOCUS_OUT:
2552 if (window() == QGuiApplication::focusWindow()
2553 && !focusWindowChangeQueued(window())) {
2554 connection()->setFocusWindow(nullptr);
2555 QWindowSystemInterface::handleFocusWindowChanged(nullptr);
2556 }
2557 break;
2558 }
2559}
2560
2561static inline xcb_rectangle_t qRectToXCBRectangle(const QRect &r)
2562{
2563 xcb_rectangle_t result;
2564 result.x = qMax(SHRT_MIN, r.x());
2565 result.y = qMax(SHRT_MIN, r.y());
2566 result.width = qMin((int)USHRT_MAX, r.width());
2567 result.height = qMin((int)USHRT_MAX, r.height());
2568 return result;
2569}
2570
2571void QXcbWindow::setOpacity(qreal level)
2572{
2573 if (!m_window)
2574 return;
2575
2576 quint32 value = qRound64(qBound(qreal(0), level, qreal(1)) * 0xffffffff);
2577
2578 xcb_change_property(xcb_connection(),
2579 XCB_PROP_MODE_REPLACE,
2580 m_window,
2581 atom(QXcbAtom::Atom_NET_WM_WINDOW_OPACITY),
2582 XCB_ATOM_CARDINAL,
2583 32,
2584 1,
2585 (uchar *)&value);
2586}
2587
2588QList<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion &region)
2589{
2590 QList<xcb_rectangle_t> rects;
2591 rects.reserve(region.rectCount());
2592 for (const QRect &r : region)
2593 rects.push_back(qRectToXCBRectangle(r));
2594 return rects;
2595}
2596
2597void QXcbWindow::setMask(const QRegion &region)
2598{
2599 if (!connection()->hasXShape())
2600 return;
2601 if (region.isEmpty()) {
2602 xcb_shape_mask(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
2603 XCB_SHAPE_SK_BOUNDING, xcb_window(), 0, 0, XCB_NONE);
2604 } else {
2605 const auto rects = qRegionToXcbRectangleList(region);
2606 xcb_shape_rectangles(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
2607 XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
2608 xcb_window(), 0, 0, rects.size(), &rects[0]);
2609 }
2610}
2611
2612void QXcbWindow::setAlertState(bool enabled)
2613{
2614 if (m_alertState == enabled)
2615 return;
2616
2617 m_alertState = enabled;
2618
2619 setNetWmState(enabled, atom(QXcbAtom::Atom_NET_WM_STATE_DEMANDS_ATTENTION));
2620}
2621
2622uint QXcbWindow::visualId() const
2623{
2624 return m_visualId;
2625}
2626
2627bool QXcbWindow::needsSync() const
2628{
2629 return m_syncState == SyncAndConfigureReceived;
2630}
2631
2632void QXcbWindow::postSyncWindowRequest()
2633{
2634 if (!m_pendingSyncRequest) {
2635 QXcbSyncWindowRequest *e = new QXcbSyncWindowRequest(this);
2636 m_pendingSyncRequest = e;
2637 QCoreApplication::postEvent(xcbScreen()->connection(), e);
2638 }
2639}
2640
2641QXcbScreen *QXcbWindow::xcbScreen() const
2642{
2643 return static_cast<QXcbScreen *>(screen());
2644}
2645
2646void QXcbWindow::setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title)
2647{
2648 QString fullTitle = formatWindowTitle(title, QString::fromUtf8(" \xe2\x80\x94 ")); // unicode character U+2014, EM DASH
2649 const QByteArray ba = std::move(fullTitle).toUtf8();
2650 xcb_change_property(conn->xcb_connection(),
2651 XCB_PROP_MODE_REPLACE,
2652 window,
2653 conn->atom(QXcbAtom::Atom_NET_WM_NAME),
2654 conn->atom(QXcbAtom::AtomUTF8_STRING),
2655 8,
2656 ba.size(),
2657 ba.constData());
2658
2659#if QT_CONFIG(xcb_xlib)
2660 Display *dpy = static_cast<Display *>(conn->xlib_display());
2661 XTextProperty *text = qstringToXTP(dpy, title);
2662 if (text)
2663 XSetWMName(dpy, window, text);
2664#endif
2665 xcb_flush(conn->xcb_connection());
2666}
2667
2668QString QXcbWindow::windowTitle(const QXcbConnection *conn, xcb_window_t window)
2669{
2670 const xcb_atom_t utf8Atom = conn->atom(QXcbAtom::AtomUTF8_STRING);
2671 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, conn->xcb_connection(),
2672 false, window, conn->atom(QXcbAtom::Atom_NET_WM_NAME),
2673 utf8Atom, 0, 1024);
2674 if (reply && reply->format == 8 && reply->type == utf8Atom) {
2675 const char *name = reinterpret_cast<const char *>(xcb_get_property_value(reply.get()));
2676 return QString::fromUtf8(name, xcb_get_property_value_length(reply.get()));
2677 }
2678
2679 reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, conn->xcb_connection(),
2680 false, window, conn->atom(QXcbAtom::AtomWM_NAME),
2681 XCB_ATOM_STRING, 0, 1024);
2682 if (reply && reply->format == 8 && reply->type == XCB_ATOM_STRING) {
2683 const char *name = reinterpret_cast<const char *>(xcb_get_property_value(reply.get()));
2684 return QString::fromLatin1(name, xcb_get_property_value_length(reply.get()));
2685 }
2686
2687 return QString();
2688}
2689
2690QT_END_NAMESPACE
Definition qlist.h:80
QXcbForeignWindow(QWindow *window, WId nativeHandle)
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
@ defaultWindowHeight
Definition qioswindow.mm:35
@ defaultWindowWidth
Definition qioswindow.mm:34
#define Q_XCB_REPLY(call,...)
#define Q_XCB_REPLY_UNCHECKED(call,...)
static uint qtEdgesToXcbMoveResizeDirection(Qt::Edges edges)
#define XCOORD_MAX
static bool doCheckUnGrabAncestor(QXcbConnection *conn)
@ baseEventMask
@ defaultEventMask
@ transparentForInputEventMask
@ MWM_DECOR_MAXIMIZE
@ MWM_DECOR_MENU
@ MWM_DECOR_TITLE
@ MWM_FUNC_MINIMIZE
@ MWM_FUNC_ALL
@ MWM_FUNC_CLOSE
@ MWM_FUNC_MOVE
@ MWM_DECOR_ALL
@ MWM_DECOR_BORDER
@ MWM_HINTS_DECORATIONS
@ MWM_HINTS_FUNCTIONS
@ MWM_DECOR_RESIZEH
@ MWM_DECOR_MINIMIZE
@ MWM_FUNC_MAXIMIZE
@ MWM_FUNC_RESIZE
static bool isTransient(const QWindow *w)
#define qt_xcb_mask_is_set(ptr, event)
static bool ignoreEnterEvent(quint8 mode, quint8 detail, QXcbConnection *conn=nullptr)
static bool focusWindowChangeQueued(const QWindow *window)
static const char * wm_window_role_property_id
static xcb_rectangle_t qRectToXCBRectangle(const QRect &r)
Q_DECLARE_TYPEINFO(xcb_rectangle_t, Q_PRIMITIVE_TYPE)
const quint32 XEMBED_VERSION
QX11EmbedInfoFlags
@ XEMBED_MAPPED
static int fixed1616ToInt(xcb_input_fp1616_t val)
static bool ignoreLeaveEvent(quint8 mode, quint8 detail, QXcbConnection *conn)
static const char * wm_window_type_property_id
QX11EmbedMessageType
@ XEMBED_REGISTER_ACCELERATOR
@ XEMBED_UNREGISTER_ACCELERATOR
@ XEMBED_WINDOW_ACTIVATE
@ XEMBED_ACTIVATE_ACCELERATOR
@ XEMBED_WINDOW_DEACTIVATE
@ XEMBED_FOCUS_OUT
@ XEMBED_EMBEDDED_NOTIFY
@ XEMBED_FOCUS_IN
@ XEMBED_FOCUS_NEXT
@ XEMBED_MODALITY_OFF
@ XEMBED_REQUEST_FOCUS
@ XEMBED_FOCUS_PREV
@ XEMBED_MODALITY_ON
QX11EmbedFocusInDetail
@ XEMBED_FOCUS_CURRENT
@ XEMBED_FOCUS_FIRST
@ XEMBED_FOCUS_LAST
static QWindow * childWindowAt(QWindow *win, const QPoint &p)
QList< xcb_rectangle_t > qRegionToXcbRectangleList(const QRegion &region)
quint32 decorations