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
925static inline Qt::WindowFlags x11AdjustedWindowFlags(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 return flags;
934}
935
936void QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
937{
938 flags = x11AdjustedWindowFlags(flags);
939 Qt::WindowFlags oldflags = x11AdjustedWindowFlags(window()->flags());
940 if ((oldflags & Qt::WindowStaysOnTopHint) != (flags & Qt::WindowStaysOnTopHint))
941 m_recreationReasons |= WindowStaysOnTopHintChanged;
942 if ((oldflags & Qt::WindowStaysOnBottomHint) != (flags & Qt::WindowStaysOnBottomHint))
943 m_recreationReasons |= WindowStaysOnBottomHintChanged;
944
945 const quint32 mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
946 const quint32 values[] = {
947 // XCB_CW_OVERRIDE_REDIRECT
948 (flags & Qt::BypassWindowManagerHint) ? 1u : 0,
949 // XCB_CW_EVENT_MASK
950 (flags & Qt::WindowTransparentForInput) ? transparentForInputEventMask : defaultEventMask
951 };
952
953 xcb_change_window_attributes(xcb_connection(), xcb_window(), mask, values);
954
955 WindowTypes wmWindowTypes;
956 if (window()->dynamicPropertyNames().contains(wm_window_type_property_id)) {
957 wmWindowTypes = static_cast<WindowTypes>(
958 qvariant_cast<int>(window()->property(wm_window_type_property_id)));
959 }
960
961 setWmWindowType(wmWindowTypes, flags);
962 setNetWmState(flags);
963 setMotifWmHints(flags);
964
965 setTransparentForMouseEvents(flags & Qt::WindowTransparentForInput);
966 updateDoesNotAcceptFocus(flags & Qt::WindowDoesNotAcceptFocus);
967}
968
969void QXcbWindow::setMotifWmHints(Qt::WindowFlags flags)
970{
971 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
972
973 QtMotifWmHints mwmhints;
974 memset(&mwmhints, 0, sizeof(mwmhints));
975
976 if (type != Qt::SplashScreen) {
977 mwmhints.flags |= MWM_HINTS_DECORATIONS;
978
979 bool customize = flags & Qt::CustomizeWindowHint;
980 if (type == Qt::Window && !customize) {
981 const Qt::WindowFlags defaultFlags = Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
982 if (!(flags & defaultFlags))
983 flags |= defaultFlags;
984 }
985 if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
986 mwmhints.decorations |= MWM_DECOR_BORDER;
987 mwmhints.decorations |= MWM_DECOR_RESIZEH;
988 mwmhints.decorations |= MWM_DECOR_TITLE;
989
990 if (flags & Qt::WindowSystemMenuHint)
991 mwmhints.decorations |= MWM_DECOR_MENU;
992
993 if (flags & Qt::WindowMinimizeButtonHint) {
994 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
995 mwmhints.functions |= MWM_FUNC_MINIMIZE;
996 }
997
998 if (flags & Qt::WindowMaximizeButtonHint) {
999 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
1000 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
1001 }
1002
1003 if (flags & Qt::WindowCloseButtonHint)
1004 mwmhints.functions |= MWM_FUNC_CLOSE;
1005 }
1006 } else {
1007 // if type == Qt::SplashScreen
1008 mwmhints.decorations = MWM_DECOR_ALL;
1009 }
1010
1011 if (mwmhints.functions != 0) {
1012 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
1013 mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
1014 } else {
1015 mwmhints.functions = MWM_FUNC_ALL;
1016 }
1017
1018 if (!(flags & Qt::FramelessWindowHint)
1019 && flags & Qt::CustomizeWindowHint
1020 && flags & Qt::WindowTitleHint
1021 && !(flags &
1022 (Qt::WindowMinimizeButtonHint
1023 | Qt::WindowMaximizeButtonHint
1024 | Qt::WindowCloseButtonHint)))
1025 {
1026 // a special case - only the titlebar without any button
1027 mwmhints.flags = MWM_HINTS_FUNCTIONS;
1028 mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
1029 mwmhints.decorations = 0;
1030 }
1031
1032 if (mwmhints.flags) {
1033 xcb_change_property(xcb_connection(),
1034 XCB_PROP_MODE_REPLACE,
1035 m_window,
1036 atom(QXcbAtom::Atom_MOTIF_WM_HINTS),
1037 atom(QXcbAtom::Atom_MOTIF_WM_HINTS),
1038 32,
1039 5,
1040 &mwmhints);
1041 } else {
1042 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_MOTIF_WM_HINTS));
1043 }
1044}
1045
1046void QXcbWindow::setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two)
1047{
1048 xcb_client_message_event_t event;
1049
1050 event.response_type = XCB_CLIENT_MESSAGE;
1051 event.format = 32;
1052 event.sequence = 0;
1053 event.window = m_window;
1054 event.type = atom(QXcbAtom::Atom_NET_WM_STATE);
1055 event.data.data32[0] = set ? 1 : 0;
1056 event.data.data32[1] = one;
1057 event.data.data32[2] = two;
1058 event.data.data32[3] = 0;
1059 event.data.data32[4] = 0;
1060
1061 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1062 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1063 (const char *)&event);
1064}
1065
1066void QXcbWindow::setNetWmState(Qt::WindowStates state)
1067{
1068 if ((m_windowState ^ state) & Qt::WindowMaximized) {
1069 setNetWmState(state & Qt::WindowMaximized,
1070 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ),
1071 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT));
1072 }
1073
1074 if ((m_windowState ^ state) & Qt::WindowFullScreen)
1075 setNetWmState(state & Qt::WindowFullScreen, atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN));
1076}
1077
1078void QXcbWindow::setNetWmState(Qt::WindowFlags flags)
1079{
1080 setNetWmState(flags & Qt::WindowStaysOnTopHint,
1081 atom(QXcbAtom::Atom_NET_WM_STATE_ABOVE),
1082 atom(QXcbAtom::Atom_NET_WM_STATE_STAYS_ON_TOP));
1083 setNetWmState(flags & Qt::WindowStaysOnBottomHint, atom(QXcbAtom::Atom_NET_WM_STATE_BELOW));
1084}
1085
1086void QXcbWindow::setNetWmStateOnUnmappedWindow()
1087{
1088 QMutexLocker locker(&m_mappedMutex);
1089 if (Q_UNLIKELY(m_mapped))
1090 qCDebug(lcQpaXcb()) << "internal info: " << Q_FUNC_INFO << "called on mapped window";
1091
1092 NetWmStates states;
1093 const Qt::WindowFlags flags = window()->flags();
1094 if (flags & Qt::WindowStaysOnTopHint) {
1095 states |= NetWmStateAbove;
1096 states |= NetWmStateStaysOnTop;
1097 } else if (flags & Qt::WindowStaysOnBottomHint) {
1098 states |= NetWmStateBelow;
1099 }
1100
1101 if (window()->windowStates() & Qt::WindowMinimized)
1102 states |= NetWmStateHidden;
1103
1104 if (window()->windowStates() & Qt::WindowFullScreen)
1105 states |= NetWmStateFullScreen;
1106
1107 if (window()->windowStates() & Qt::WindowMaximized) {
1108 states |= NetWmStateMaximizedHorz;
1109 states |= NetWmStateMaximizedVert;
1110 }
1111
1112 if (window()->modality() != Qt::NonModal)
1113 states |= NetWmStateModal;
1114
1115 // According to EWMH:
1116 // "The Window Manager should remove _NET_WM_STATE whenever a window is withdrawn".
1117 // Which means that we don't have to read this property before changing it on a withdrawn
1118 // window. But there are situations where users want to adjust this property as well
1119 // (e4cea305ed2ba3c9f580bf9d16c59a1048af0e8a), so instead of overwriting the property
1120 // we first read it and then merge our hints with the existing values, allowing a user
1121 // to set custom hints.
1122
1123 QList<xcb_atom_t> atoms;
1124 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, xcb_connection(),
1125 0, m_window, atom(QXcbAtom::Atom_NET_WM_STATE),
1126 XCB_ATOM_ATOM, 0, 1024);
1127 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM && reply->value_len > 0) {
1128 const xcb_atom_t *data = static_cast<const xcb_atom_t *>(xcb_get_property_value(reply.get()));
1129 atoms.resize(reply->value_len);
1130 memcpy((void *)&atoms.first(), (void *)data, reply->value_len * sizeof(xcb_atom_t));
1131 }
1132
1133 if (states & NetWmStateAbove && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_ABOVE)))
1134 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_ABOVE));
1135 if (states & NetWmStateBelow && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_BELOW)))
1136 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_BELOW));
1137 if (states & NetWmStateHidden && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_HIDDEN)))
1138 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_HIDDEN));
1139 if (states & NetWmStateFullScreen && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN)))
1140 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN));
1141 if (states & NetWmStateMaximizedHorz && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ)))
1142 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ));
1143 if (states & NetWmStateMaximizedVert && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT)))
1144 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT));
1145 if (states & NetWmStateModal && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_MODAL)))
1146 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_MODAL));
1147 if (states & NetWmStateStaysOnTop && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_STAYS_ON_TOP)))
1148 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_STAYS_ON_TOP));
1149 if (states & NetWmStateDemandsAttention && !atoms.contains(atom(QXcbAtom::Atom_NET_WM_STATE_DEMANDS_ATTENTION)))
1150 atoms.push_back(atom(QXcbAtom::Atom_NET_WM_STATE_DEMANDS_ATTENTION));
1151
1152 if (atoms.isEmpty()) {
1153 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_STATE));
1154 } else {
1155 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
1156 atom(QXcbAtom::Atom_NET_WM_STATE), XCB_ATOM_ATOM, 32,
1157 atoms.size(), atoms.constData());
1158 }
1159 xcb_flush(xcb_connection());
1160}
1161
1162void QXcbWindow::setWindowState(Qt::WindowStates state)
1163{
1164 if (state == m_windowState)
1165 return;
1166
1167 Qt::WindowStates unsetState = m_windowState & ~state;
1168 Qt::WindowStates newState = state & ~m_windowState;
1169
1170 // unset old state
1171 if (unsetState & Qt::WindowMinimized)
1172 xcb_map_window(xcb_connection(), m_window);
1173 if (unsetState & Qt::WindowMaximized)
1174 setNetWmState(false,
1175 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_HORZ),
1176 atom(QXcbAtom::Atom_NET_WM_STATE_MAXIMIZED_VERT));
1177 if (unsetState & Qt::WindowFullScreen)
1178 setNetWmState(false, atom(QXcbAtom::Atom_NET_WM_STATE_FULLSCREEN));
1179
1180 // set new state
1181 if (newState & Qt::WindowMinimized) {
1182 {
1183 xcb_client_message_event_t event;
1184
1185 event.response_type = XCB_CLIENT_MESSAGE;
1186 event.format = 32;
1187 event.sequence = 0;
1188 event.window = m_window;
1189 event.type = atom(QXcbAtom::AtomWM_CHANGE_STATE);
1190 event.data.data32[0] = XCB_ICCCM_WM_STATE_ICONIC;
1191 event.data.data32[1] = 0;
1192 event.data.data32[2] = 0;
1193 event.data.data32[3] = 0;
1194 event.data.data32[4] = 0;
1195
1196 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1197 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1198 (const char *)&event);
1199 }
1200 m_minimized = true;
1201 }
1202
1203 // set Maximized && FullScreen state if need
1204 setNetWmState(state);
1205
1206 xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_hints_unchecked(xcb_connection(), m_window);
1207 xcb_icccm_wm_hints_t hints;
1208 if (xcb_icccm_get_wm_hints_reply(xcb_connection(), cookie, &hints, nullptr)) {
1209 if (state & Qt::WindowMinimized)
1210 xcb_icccm_wm_hints_set_iconic(&hints);
1211 else
1212 xcb_icccm_wm_hints_set_normal(&hints);
1213 xcb_icccm_set_wm_hints(xcb_connection(), m_window, &hints);
1214 }
1215
1216 connection()->sync();
1217 m_windowState = state;
1218}
1219
1220void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
1221{
1222 xcb_window_t wid = m_window;
1223 // If timestamp == 0, then it means that the window should not be
1224 // initially activated. Don't update global user time for this
1225 // special case.
1226 if (timestamp != 0)
1227 connection()->setNetWmUserTime(timestamp);
1228
1229 const bool isSupportedByWM = connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::Atom_NET_WM_USER_TIME_WINDOW));
1230 if (m_netWmUserTimeWindow || isSupportedByWM) {
1231 if (!m_netWmUserTimeWindow) {
1232 m_netWmUserTimeWindow = xcb_generate_id(xcb_connection());
1233 xcb_create_window(xcb_connection(),
1234 XCB_COPY_FROM_PARENT, // depth -- same as root
1235 m_netWmUserTimeWindow, // window id
1236 m_window, // parent window id
1237 -1, -1, 1, 1,
1238 0, // border width
1239 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
1240 m_visualId, // visual
1241 0, // value mask
1242 nullptr); // value list
1243 wid = m_netWmUserTimeWindow;
1244 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::Atom_NET_WM_USER_TIME_WINDOW),
1245 XCB_ATOM_WINDOW, 32, 1, &m_netWmUserTimeWindow);
1246 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_USER_TIME));
1247
1248 QXcbWindow::setWindowTitle(connection(), m_netWmUserTimeWindow,
1249 QStringLiteral("Qt NET_WM User Time Window"));
1250
1251 } else if (!isSupportedByWM) {
1252 // WM no longer supports it, then we should remove the
1253 // _NET_WM_USER_TIME_WINDOW atom.
1254 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_USER_TIME_WINDOW));
1255 xcb_destroy_window(xcb_connection(), m_netWmUserTimeWindow);
1256 m_netWmUserTimeWindow = XCB_NONE;
1257 } else {
1258 wid = m_netWmUserTimeWindow;
1259 }
1260 }
1261 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::Atom_NET_WM_USER_TIME),
1262 XCB_ATOM_CARDINAL, 32, 1, &timestamp);
1263}
1264
1265void QXcbWindow::setTransparentForMouseEvents(bool transparent)
1266{
1267 if (!connection()->hasXFixes() || transparent == m_transparent)
1268 return;
1269
1270 xcb_rectangle_t rectangle;
1271
1272 xcb_rectangle_t *rect = nullptr;
1273 int nrect = 0;
1274
1275 if (!transparent) {
1276 rectangle.x = 0;
1277 rectangle.y = 0;
1278 rectangle.width = geometry().width();
1279 rectangle.height = geometry().height();
1280 rect = &rectangle;
1281 nrect = 1;
1282 }
1283
1284 xcb_xfixes_region_t region = xcb_generate_id(xcb_connection());
1285 xcb_xfixes_create_region(xcb_connection(), region, nrect, rect);
1286 xcb_xfixes_set_window_shape_region_checked(xcb_connection(), m_window, XCB_SHAPE_SK_INPUT, 0, 0, region);
1287 xcb_xfixes_destroy_region(xcb_connection(), region);
1288
1289 m_transparent = transparent;
1290}
1291
1292void QXcbWindow::updateDoesNotAcceptFocus(bool doesNotAcceptFocus)
1293{
1294 xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_hints_unchecked(xcb_connection(), m_window);
1295
1296 xcb_icccm_wm_hints_t hints;
1297 if (!xcb_icccm_get_wm_hints_reply(xcb_connection(), cookie, &hints, nullptr))
1298 return;
1299
1300 xcb_icccm_wm_hints_set_input(&hints, !doesNotAcceptFocus);
1301 xcb_icccm_set_wm_hints(xcb_connection(), m_window, &hints);
1302}
1303
1304WId QXcbWindow::winId() const
1305{
1306 return m_window;
1307}
1308
1309void QXcbWindow::setParent(const QPlatformWindow *parent)
1310{
1311 QPoint topLeft = geometry().topLeft();
1312
1313 xcb_window_t xcb_parent_id;
1314 if (parent) {
1315 const QXcbWindow *qXcbParent = static_cast<const QXcbWindow *>(parent);
1316 xcb_parent_id = qXcbParent->xcb_window();
1317 m_embedded = qXcbParent->isForeignWindow();
1318 } else {
1319 xcb_parent_id = xcbScreen()->root();
1320 m_embedded = false;
1321 }
1322 xcb_reparent_window(xcb_connection(), xcb_window(), xcb_parent_id, topLeft.x(), topLeft.y());
1323 connection()->sync();
1324}
1325
1326void QXcbWindow::setWindowTitle(const QString &title)
1327{
1328 setWindowTitle(connection(), m_window, title);
1329}
1330
1331QString QXcbWindow::windowTitle() const
1332{
1333 return windowTitle(connection(), m_window);
1334}
1335
1336void QXcbWindow::setWindowIconText(const QString &title)
1337{
1338 const QByteArray ba = title.toUtf8();
1339 xcb_change_property(xcb_connection(),
1340 XCB_PROP_MODE_REPLACE,
1341 m_window,
1342 atom(QXcbAtom::Atom_NET_WM_ICON_NAME),
1343 atom(QXcbAtom::AtomUTF8_STRING),
1344 8,
1345 ba.size(),
1346 ba.constData());
1347}
1348
1349void QXcbWindow::setWindowIcon(const QIcon &icon)
1350{
1351 QList<quint32> icon_data;
1352 const uint32_t sizeLimit = xcb_get_maximum_request_length(xcb_connection());
1353 if (!icon.isNull()) {
1354 QList<QSize> availableSizes = icon.availableSizes();
1355 if (availableSizes.isEmpty()) {
1356 // try to use default sizes since the icon can be a scalable image like svg.
1357 availableSizes.push_back(QSize(16,16));
1358 availableSizes.push_back(QSize(32,32));
1359 availableSizes.push_back(QSize(64,64));
1360 availableSizes.push_back(QSize(128,128));
1361 }
1362 for (int i = 0; i < availableSizes.size(); ++i) {
1363 QSize size = availableSizes.at(i);
1364 QPixmap pixmap = icon.pixmap(size);
1365 if (!pixmap.isNull()) {
1366 QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
1367 int pos = icon_data.size();
1368 int newSize = pos + 2 + image.width()*image.height();
1369 // In the absence of the BIG-REQUESTS extension, or with too big DPR,
1370 // the size of icon data is too big for the xcb request very easily.
1371 if (quint64(newSize) > quint64(sizeLimit))
1372 break;
1373 icon_data.resize(newSize);
1374 icon_data[pos++] = image.width();
1375 icon_data[pos++] = image.height();
1376 memcpy(icon_data.data() + pos, image.bits(), image.width()*image.height()*4);
1377 }
1378 }
1379 }
1380
1381 if (!icon_data.isEmpty()) {
1382 // Ignore icon exceeding maximum xcb request length
1383 if (quint64(icon_data.size()) > quint64(sizeLimit)) {
1384 qWarning() << "Ignoring window icon" << icon_data.size()
1385 << "exceeds maximum xcb request length"
1386 << sizeLimit;
1387 return;
1388 }
1389 xcb_change_property(xcb_connection(),
1390 XCB_PROP_MODE_REPLACE,
1391 m_window,
1392 atom(QXcbAtom::Atom_NET_WM_ICON),
1393 atom(QXcbAtom::AtomCARDINAL),
1394 32,
1395 icon_data.size(),
1396 (unsigned char *) icon_data.data());
1397 } else {
1398 xcb_delete_property(xcb_connection(),
1399 m_window,
1400 atom(QXcbAtom::Atom_NET_WM_ICON));
1401 }
1402}
1403
1404void QXcbWindow::raise()
1405{
1406 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1407 const quint32 values[] = { XCB_STACK_MODE_ABOVE };
1408 xcb_configure_window(xcb_connection(), m_window, mask, values);
1409}
1410
1411void QXcbWindow::lower()
1412{
1413 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1414 const quint32 values[] = { XCB_STACK_MODE_BELOW };
1415 xcb_configure_window(xcb_connection(), m_window, mask, values);
1416}
1417
1418void QXcbWindow::propagateSizeHints()
1419{
1420 // update WM_NORMAL_HINTS
1421 xcb_size_hints_t hints;
1422 memset(&hints, 0, sizeof(hints));
1423
1424 const QRect rect = geometry();
1425 QWindowPrivate *win = qt_window_private(window());
1426
1427 if (!win->positionAutomatic)
1428 xcb_icccm_size_hints_set_position(&hints, true, rect.x(), rect.y());
1429 if (rect.width() < QWINDOWSIZE_MAX || rect.height() < QWINDOWSIZE_MAX)
1430 xcb_icccm_size_hints_set_size(&hints, true, rect.width(), rect.height());
1431
1432 /* Gravity describes how to interpret x and y values the next time
1433 window needs to be positioned on a screen.
1434 XCB_GRAVITY_STATIC : the left top corner of the client window
1435 XCB_GRAVITY_NORTH_WEST : the left top corner of the frame window */
1436 auto gravity = win->positionPolicy == QWindowPrivate::WindowFrameInclusive
1437 ? XCB_GRAVITY_NORTH_WEST : XCB_GRAVITY_STATIC;
1438
1439 xcb_icccm_size_hints_set_win_gravity(&hints, gravity);
1440
1441 QSize minimumSize = windowMinimumSize();
1442 QSize maximumSize = windowMaximumSize();
1443 QSize baseSize = windowBaseSize();
1444 QSize sizeIncrement = windowSizeIncrement();
1445
1446 if (minimumSize.width() > 0 || minimumSize.height() > 0)
1447 xcb_icccm_size_hints_set_min_size(&hints,
1448 qMin(XCOORD_MAX,minimumSize.width()),
1449 qMin(XCOORD_MAX,minimumSize.height()));
1450
1451 if (maximumSize.width() < QWINDOWSIZE_MAX || maximumSize.height() < QWINDOWSIZE_MAX)
1452 xcb_icccm_size_hints_set_max_size(&hints,
1453 qMin(XCOORD_MAX, maximumSize.width()),
1454 qMin(XCOORD_MAX, maximumSize.height()));
1455
1456 if (sizeIncrement.width() > 0 || sizeIncrement.height() > 0) {
1457 if (!baseSize.isNull() && baseSize.isValid())
1458 xcb_icccm_size_hints_set_base_size(&hints, baseSize.width(), baseSize.height());
1459 xcb_icccm_size_hints_set_resize_inc(&hints, sizeIncrement.width(), sizeIncrement.height());
1460 }
1461
1462 xcb_icccm_set_wm_normal_hints(xcb_connection(), m_window, &hints);
1463
1464 m_sizeHintsScaleFactor = QHighDpiScaling::factor(screen());
1465}
1466
1467void QXcbWindow::requestActivateWindow()
1468{
1469 /* Never activate embedded windows; doing that would prevent the container
1470 * to re-gain the keyboard focus later. */
1471 if (m_embedded) {
1472 QPlatformWindow::requestActivateWindow();
1473 return;
1474 }
1475
1476 {
1477 QMutexLocker locker(&m_mappedMutex);
1478 if (!m_mapped) {
1479 m_deferredActivation = true;
1480 return;
1481 }
1482 m_deferredActivation = false;
1483 }
1484
1485 updateNetWmUserTime(connection()->time());
1486 QWindow *focusWindow = QGuiApplication::focusWindow();
1487 xcb_window_t current = XCB_NONE;
1488 if (focusWindow) {
1489 if (QPlatformWindow *pw = focusWindow->handle())
1490 current = pw->winId();
1491 }
1492
1493 if (window()->isTopLevel()
1494 && !(window()->flags() & Qt::X11BypassWindowManagerHint)
1495 && (!focusWindow || !window()->isAncestorOf(focusWindow))
1496 && connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::Atom_NET_ACTIVE_WINDOW))) {
1497 xcb_client_message_event_t event;
1498
1499 event.response_type = XCB_CLIENT_MESSAGE;
1500 event.format = 32;
1501 event.sequence = 0;
1502 event.window = m_window;
1503 event.type = atom(QXcbAtom::Atom_NET_ACTIVE_WINDOW);
1504 event.data.data32[0] = 1;
1505 event.data.data32[1] = connection()->time();
1506 event.data.data32[2] = current;
1507 event.data.data32[3] = 0;
1508 event.data.data32[4] = 0;
1509
1510 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1511 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1512 (const char *)&event);
1513 } else {
1514 xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, connection()->time());
1515 }
1516
1517 connection()->sync();
1518}
1519
1520QSurfaceFormat QXcbWindow::format() const
1521{
1522 return m_format;
1523}
1524
1525QXcbWindow::WindowTypes QXcbWindow::wmWindowTypes() const
1526{
1527 WindowTypes result;
1528
1529 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, xcb_connection(),
1530 0, m_window, atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE),
1531 XCB_ATOM_ATOM, 0, 1024);
1532 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) {
1533 const xcb_atom_t *types = static_cast<const xcb_atom_t *>(xcb_get_property_value(reply.get()));
1534 const xcb_atom_t *types_end = types + reply->length;
1535 for (; types != types_end; types++) {
1536 QXcbAtom::Atom type = connection()->qatom(*types);
1537 switch (type) {
1538 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL:
1539 result |= WindowType::Normal;
1540 break;
1541 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DESKTOP:
1542 result |= WindowType::Desktop;
1543 break;
1544 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DOCK:
1545 result |= WindowType::Dock;
1546 break;
1547 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLBAR:
1548 result |= WindowType::Toolbar;
1549 break;
1550 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_MENU:
1551 result |= WindowType::Menu;
1552 break;
1553 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_UTILITY:
1554 result |= WindowType::Utility;
1555 break;
1556 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_SPLASH:
1557 result |= WindowType::Splash;
1558 break;
1559 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DIALOG:
1560 result |= WindowType::Dialog;
1561 break;
1562 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DROPDOWN_MENU:
1563 result |= WindowType::DropDownMenu;
1564 break;
1565 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_POPUP_MENU:
1566 result |= WindowType::PopupMenu;
1567 break;
1568 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLTIP:
1569 result |= WindowType::Tooltip;
1570 break;
1571 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NOTIFICATION:
1572 result |= WindowType::Notification;
1573 break;
1574 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_COMBO:
1575 result |= WindowType::Combo;
1576 break;
1577 case QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DND:
1578 result |= WindowType::Dnd;
1579 break;
1580 case QXcbAtom::Atom_KDE_NET_WM_WINDOW_TYPE_OVERRIDE:
1581 result |= WindowType::KdeOverride;
1582 break;
1583 default:
1584 break;
1585 }
1586 }
1587 }
1588 return result;
1589}
1590
1591void QXcbWindow::setWmWindowType(WindowTypes types, Qt::WindowFlags flags)
1592{
1593 QList<xcb_atom_t> atoms;
1594
1595 // manual selection 1 (these are never set by Qt and take precedence)
1596 if (types & WindowType::Normal)
1597 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL));
1598 if (types & WindowType::Desktop)
1599 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DESKTOP));
1600 if (types & WindowType::Dock)
1601 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DOCK));
1602 if (types & WindowType::Notification)
1603 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NOTIFICATION));
1604
1605 // manual selection 2 (Qt uses these during auto selection);
1606 if (types & WindowType::Utility)
1607 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_UTILITY));
1608 if (types & WindowType::Splash)
1609 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_SPLASH));
1610 if (types & WindowType::Dialog)
1611 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DIALOG));
1612 if (types & WindowType::Tooltip)
1613 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLTIP));
1614 if (types & WindowType::KdeOverride)
1615 atoms.append(atom(QXcbAtom::Atom_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
1616
1617 // manual selection 3 (these can be set by Qt, but don't have a
1618 // corresponding Qt::WindowType). note that order of the *MENU
1619 // atoms is important
1620 if (types & WindowType::Menu)
1621 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_MENU));
1622 if (types & WindowType::DropDownMenu)
1623 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DROPDOWN_MENU));
1624 if (types & WindowType::PopupMenu)
1625 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_POPUP_MENU));
1626 if (types & WindowType::Toolbar)
1627 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLBAR));
1628 if (types & WindowType::Combo)
1629 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_COMBO));
1630 if (types & WindowType::Dnd)
1631 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DND));
1632
1633 // automatic selection
1634 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
1635 switch (type) {
1636 case Qt::Dialog:
1637 case Qt::Sheet:
1638 if (!(types & WindowType::Dialog))
1639 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_DIALOG));
1640 break;
1641 case Qt::Tool:
1642 case Qt::Drawer:
1643 if (!(types & WindowType::Utility))
1644 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_UTILITY));
1645 break;
1646 case Qt::ToolTip:
1647 if (!(types & WindowType::Tooltip))
1648 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_TOOLTIP));
1649 break;
1650 case Qt::SplashScreen:
1651 if (!(types & WindowType::Splash))
1652 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_SPLASH));
1653 break;
1654 default:
1655 break;
1656 }
1657
1658 if ((flags & Qt::FramelessWindowHint) && !(types & WindowType::KdeOverride)) {
1659 // override netwm type - quick and easy for KDE noborder
1660 atoms.append(atom(QXcbAtom::Atom_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
1661 }
1662
1663 if (atoms.size() == 1 && atoms.first() == atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL))
1664 atoms.clear();
1665 else
1666 atoms.append(atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE_NORMAL));
1667
1668 if (atoms.isEmpty()) {
1669 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE));
1670 } else {
1671 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
1672 atom(QXcbAtom::Atom_NET_WM_WINDOW_TYPE), XCB_ATOM_ATOM, 32,
1673 atoms.size(), atoms.constData());
1674 }
1675 xcb_flush(xcb_connection());
1676}
1677
1678void QXcbWindow::setWindowRole(const QString &role)
1679{
1680 QByteArray roleData = role.toLatin1();
1681 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
1682 atom(QXcbAtom::AtomWM_WINDOW_ROLE), XCB_ATOM_STRING, 8,
1683 roleData.size(), roleData.constData());
1684}
1685
1686void QXcbWindow::setParentRelativeBackPixmap()
1687{
1688 const quint32 mask = XCB_CW_BACK_PIXMAP;
1689 const quint32 values[] = { XCB_BACK_PIXMAP_PARENT_RELATIVE };
1690 xcb_change_window_attributes(xcb_connection(), m_window, mask, values);
1691}
1692
1693bool QXcbWindow::requestSystemTrayWindowDock()
1694{
1695 if (!connection()->systemTrayTracker())
1696 return false;
1697 connection()->systemTrayTracker()->requestSystemTrayWindowDock(m_window);
1698 return true;
1699}
1700
1701bool QXcbWindow::handleNativeEvent(xcb_generic_event_t *event)
1702{
1703 auto eventType = connection()->nativeInterface()->nativeEventType();
1704 qintptr result = 0; // Used only by MS Windows
1705 return QWindowSystemInterface::handleNativeEvent(window(), eventType, event, &result);
1706}
1707
1708void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
1709{
1710 QRect rect(event->x, event->y, event->width, event->height);
1711 m_exposeRegion |= rect;
1712
1713 bool pending = true;
1714
1715 connection()->eventQueue()->peek(QXcbEventQueue::PeekConsumeMatchAndContinue,
1716 [this, &pending](xcb_generic_event_t *event, int type) {
1717 if (type != XCB_EXPOSE)
1718 return false;
1719 auto expose = reinterpret_cast<xcb_expose_event_t *>(event);
1720 if (expose->window != m_window)
1721 return false;
1722 if (expose->count == 0)
1723 pending = false;
1724 m_exposeRegion |= QRect(expose->x, expose->y, expose->width, expose->height);
1725 free(expose);
1726 return true;
1727 });
1728
1729 // if count is non-zero there are more expose events pending
1730 if (event->count == 0 || !pending) {
1731 QWindowSystemInterface::handleExposeEvent(window(), m_exposeRegion);
1732 m_exposeRegion = QRegion();
1733 }
1734}
1735
1736void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event)
1737{
1738 if (event->format != 32)
1739 return;
1740
1741 if (event->type == atom(QXcbAtom::AtomWM_PROTOCOLS)) {
1742 xcb_atom_t protocolAtom = event->data.data32[0];
1743 if (protocolAtom == atom(QXcbAtom::AtomWM_DELETE_WINDOW)) {
1744 QWindowSystemInterface::handleCloseEvent(window());
1745 } else if (protocolAtom == atom(QXcbAtom::AtomWM_TAKE_FOCUS)) {
1746 connection()->setTime(event->data.data32[1]);
1747 relayFocusToModalWindow();
1748 return;
1749 } else if (protocolAtom == atom(QXcbAtom::Atom_NET_WM_PING)) {
1750 if (event->window == xcbScreen()->root())
1751 return;
1752
1753 xcb_client_message_event_t reply = *event;
1754
1755 reply.response_type = XCB_CLIENT_MESSAGE;
1756 reply.window = xcbScreen()->root();
1757
1758 xcb_send_event(xcb_connection(), 0, xcbScreen()->root(),
1759 XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
1760 (const char *)&reply);
1761 xcb_flush(xcb_connection());
1762 } else if (protocolAtom == atom(QXcbAtom::Atom_NET_WM_SYNC_REQUEST)) {
1763 connection()->setTime(event->data.data32[1]);
1764 m_syncValue.lo = event->data.data32[2];
1765 m_syncValue.hi = event->data.data32[3];
1766 if (connection()->hasXSync())
1767 m_syncState = SyncReceived;
1768#ifndef QT_NO_WHATSTHIS
1769 } else if (protocolAtom == atom(QXcbAtom::Atom_NET_WM_CONTEXT_HELP)) {
1770 QWindowSystemInterface::handleEnterWhatsThisEvent();
1771#endif
1772 } else {
1773 qCWarning(lcQpaXcb, "Unhandled WM_PROTOCOLS (%s)",
1774 connection()->atomName(protocolAtom).constData());
1775 }
1776#if QT_CONFIG(draganddrop)
1777 } else if (event->type == atom(QXcbAtom::AtomXdndEnter)) {
1778 connection()->drag()->handleEnter(this, event);
1779 } else if (event->type == atom(QXcbAtom::AtomXdndPosition)) {
1780 connection()->drag()->handlePosition(this, event);
1781 } else if (event->type == atom(QXcbAtom::AtomXdndLeave)) {
1782 connection()->drag()->handleLeave(this, event);
1783 } else if (event->type == atom(QXcbAtom::AtomXdndDrop)) {
1784 connection()->drag()->handleDrop(this, event);
1785#endif
1786 } else if (event->type == atom(QXcbAtom::Atom_XEMBED)) {
1787 handleXEmbedMessage(event);
1788 } else if (event->type == atom(QXcbAtom::Atom_NET_ACTIVE_WINDOW)) {
1789 doFocusIn();
1790 } else if (event->type == atom(QXcbAtom::AtomMANAGER)
1791 || event->type == atom(QXcbAtom::Atom_NET_WM_STATE)
1792 || event->type == atom(QXcbAtom::AtomWM_CHANGE_STATE)) {
1793 // Ignore _NET_WM_STATE, MANAGER which are relate to tray icons
1794 // and other messages.
1795 } else if (event->type == atom(QXcbAtom::Atom_COMPIZ_DECOR_PENDING)
1796 || event->type == atom(QXcbAtom::Atom_COMPIZ_DECOR_REQUEST)
1797 || event->type == atom(QXcbAtom::Atom_COMPIZ_DECOR_DELETE_PIXMAP)
1798 || event->type == atom(QXcbAtom::Atom_COMPIZ_TOOLKIT_ACTION)
1799 || event->type == atom(QXcbAtom::Atom_GTK_LOAD_ICONTHEMES)) {
1800 //silence the _COMPIZ and _GTK messages for now
1801 } else {
1802 qCWarning(lcQpaXcb) << "Unhandled client message: " << connection()->atomName(event->type);
1803 }
1804}
1805
1806void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event)
1807{
1808 bool fromSendEvent = (event->response_type & 0x80);
1809 QPoint pos(event->x, event->y);
1810 if (!QPlatformWindow::parent() && !fromSendEvent) {
1811 // Do not trust the position, query it instead.
1812 auto reply = Q_XCB_REPLY(xcb_translate_coordinates, xcb_connection(),
1813 xcb_window(), xcbScreen()->root(), 0, 0);
1814 if (reply) {
1815 pos.setX(reply->dst_x);
1816 pos.setY(reply->dst_y);
1817 }
1818 }
1819
1820 const QRect actualGeometry = QRect(pos, QSize(event->width, event->height));
1821 QPlatformScreen *newScreen = QPlatformWindow::parent() ? QPlatformWindow::parent()->screen() : screenForGeometry(actualGeometry);
1822 if (!newScreen)
1823 return;
1824
1825 QWindowSystemInterface::handleGeometryChange(window(), actualGeometry);
1826
1827 // QPlatformScreen::screen() is updated asynchronously, so we can't compare it
1828 // with the newScreen. Just send the WindowScreenChanged event and QGuiApplication
1829 // will make the comparison later.
1830 QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen());
1831
1832 if (!qFuzzyCompare(QHighDpiScaling::factor(newScreen), m_sizeHintsScaleFactor))
1833 propagateSizeHints();
1834
1835 // Send the synthetic expose event on resize only when the window is shrunk,
1836 // because the "XCB_GRAVITY_NORTH_WEST" flag doesn't send it automatically.
1837 if (!m_oldWindowSize.isEmpty()
1838 && (actualGeometry.width() < m_oldWindowSize.width()
1839 || actualGeometry.height() < m_oldWindowSize.height())) {
1840 QWindowSystemInterface::handleExposeEvent(window(), QRegion(0, 0, actualGeometry.width(), actualGeometry.height()));
1841 }
1842 m_oldWindowSize = actualGeometry.size();
1843
1844 if (connection()->hasXSync() && m_syncState == SyncReceived)
1845 m_syncState = SyncAndConfigureReceived;
1846
1847 m_dirtyFrameMargins = true;
1848}
1849
1850bool QXcbWindow::isExposed() const
1851{
1852 return m_mapped;
1853}
1854
1855bool QXcbWindow::isEmbedded() const
1856{
1857 return m_embedded;
1858}
1859
1860QPoint QXcbWindow::mapToGlobal(const QPoint &pos) const
1861{
1862 if (!m_embedded)
1863 return QPlatformWindow::mapToGlobal(pos);
1864
1865 QPoint ret;
1866 auto reply = Q_XCB_REPLY(xcb_translate_coordinates, xcb_connection(),
1867 xcb_window(), xcbScreen()->root(),
1868 pos.x(), pos.y());
1869 if (reply) {
1870 ret.setX(reply->dst_x);
1871 ret.setY(reply->dst_y);
1872 }
1873
1874 return ret;
1875}
1876
1877QPoint QXcbWindow::mapFromGlobal(const QPoint &pos) const
1878{
1879 if (!m_embedded)
1880 return QPlatformWindow::mapFromGlobal(pos);
1881
1882 QPoint ret;
1883 auto reply = Q_XCB_REPLY(xcb_translate_coordinates, xcb_connection(),
1884 xcbScreen()->root(), xcb_window(),
1885 pos.x(), pos.y());
1886 if (reply) {
1887 ret.setX(reply->dst_x);
1888 ret.setY(reply->dst_y);
1889 }
1890
1891 return ret;
1892}
1893
1894void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event)
1895{
1896 if (event->window == m_window) {
1897 m_mappedMutex.lock();
1898 m_mapped = true;
1899 const bool deferredActivation = m_deferredActivation;
1900 m_mappedMutex.unlock();
1901 if (deferredActivation)
1902 requestActivateWindow();
1903
1904 QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size()));
1905 }
1906}
1907
1908void QXcbWindow::handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event)
1909{
1910 if (event->window == m_window) {
1911 m_mappedMutex.lock();
1912 m_mapped = false;
1913 m_mappedMutex.unlock();
1914 QWindowSystemInterface::handleExposeEvent(window(), QRegion());
1915 }
1916}
1917
1918void QXcbWindow::handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y,
1919 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
1920 QEvent::Type type, Qt::MouseEventSource source)
1921{
1922 const bool isWheel = detail >= 4 && detail <= 7;
1923 if (!isWheel && window() != QGuiApplication::focusWindow()) {
1924 QWindow *w = static_cast<QWindowPrivate *>(QObjectPrivate::get(window()))->eventReceiver();
1925 if (!(w->flags() & (Qt::WindowDoesNotAcceptFocus | Qt::BypassWindowManagerHint))
1926 && w->type() != Qt::ToolTip
1927 && w->type() != Qt::Popup) {
1928 w->requestActivate();
1929 }
1930 }
1931
1932 updateNetWmUserTime(timestamp);
1933
1934 if (m_embedded && !m_trayIconWindow) {
1935 if (window() != QGuiApplication::focusWindow()) {
1936 const QXcbWindow *container = static_cast<const QXcbWindow *>(QPlatformWindow::parent());
1937 Q_ASSERT(container != nullptr);
1938
1939 sendXEmbedMessage(container->xcb_window(), XEMBED_REQUEST_FOCUS);
1940 }
1941 }
1942 QPoint local(event_x, event_y);
1943 QPoint global(root_x, root_y);
1944
1945 if (isWheel) {
1946 if (!connection()->isAtLeastXI21()) {
1947 QPoint angleDelta;
1948 if (detail == 4)
1949 angleDelta.setY(120);
1950 else if (detail == 5)
1951 angleDelta.setY(-120);
1952 else if (detail == 6)
1953 angleDelta.setX(120);
1954 else if (detail == 7)
1955 angleDelta.setX(-120);
1956 if (modifiers & Qt::AltModifier)
1957 angleDelta = angleDelta.transposed();
1958 QWindowSystemInterface::handleWheelEvent(window(), timestamp, local, global, QPoint(), angleDelta, modifiers);
1959 }
1960 return;
1961 }
1962
1963 connection()->setMousePressWindow(this);
1964
1965 handleMouseEvent(timestamp, local, global, modifiers, type, source);
1966}
1967
1968void QXcbWindow::handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
1969 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
1970 QEvent::Type type, Qt::MouseEventSource source)
1971{
1972 QPoint local(event_x, event_y);
1973 QPoint global(root_x, root_y);
1974
1975 if (detail >= 4 && detail <= 7) {
1976 // mouse wheel, handled in handleButtonPressEvent()
1977 return;
1978 }
1979
1980 if (connection()->buttonState() == Qt::NoButton) {
1981 connection()->setMousePressWindow(nullptr);
1982 m_ignorePressedWindowOnMouseLeave = false;
1983 }
1984
1985 handleMouseEvent(timestamp, local, global, modifiers, type, source);
1986}
1987
1988static inline bool doCheckUnGrabAncestor(QXcbConnection *conn)
1989{
1990 /* Checking for XCB_NOTIFY_MODE_GRAB and XCB_NOTIFY_DETAIL_ANCESTOR prevents unwanted
1991 * enter/leave events on AwesomeWM on mouse button press. It also ignores duplicated
1992 * enter/leave events on Alt+Tab switching on some WMs with XInput2 events.
1993 * Without XInput2 events the (Un)grabAncestor cannot be checked when mouse button is
1994 * not pressed, otherwise (e.g. on Alt+Tab) it can igonre important enter/leave events.
1995 */
1996 if (conn) {
1997 const bool mouseButtonsPressed = (conn->buttonState() != Qt::NoButton);
1998 return mouseButtonsPressed || conn->hasXInput2();
1999 }
2000 return true;
2001}
2002
2003static bool ignoreLeaveEvent(quint8 mode, quint8 detail, QXcbConnection *conn)
2004{
2005 return ((doCheckUnGrabAncestor(conn)
2006 && mode == XCB_NOTIFY_MODE_GRAB && detail == XCB_NOTIFY_DETAIL_ANCESTOR)
2007 || (mode == XCB_NOTIFY_MODE_UNGRAB && detail == XCB_NOTIFY_DETAIL_INFERIOR)
2008 || detail == XCB_NOTIFY_DETAIL_VIRTUAL
2009 || detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL);
2010}
2011
2012static bool ignoreEnterEvent(quint8 mode, quint8 detail, QXcbConnection *conn = nullptr)
2013{
2014 return ((doCheckUnGrabAncestor(conn)
2015 && mode == XCB_NOTIFY_MODE_UNGRAB && detail == XCB_NOTIFY_DETAIL_ANCESTOR)
2016 || (mode != XCB_NOTIFY_MODE_NORMAL && mode != XCB_NOTIFY_MODE_UNGRAB)
2017 || detail == XCB_NOTIFY_DETAIL_VIRTUAL
2018 || detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL);
2019}
2020
2021void QXcbWindow::handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y,
2022 quint8 mode, quint8 detail, xcb_timestamp_t timestamp)
2023{
2024 connection()->setTime(timestamp);
2025
2026 if (ignoreEnterEvent(mode, detail, connection())
2027 || (connection()->mousePressWindow() && !m_ignorePressedWindowOnMouseLeave)) {
2028 return;
2029 }
2030
2031 // Updates scroll valuators, as user might have done some scrolling outside our X client.
2032 connection()->xi2UpdateScrollingDevices();
2033
2034 if (mode == XCB_NOTIFY_MODE_UNGRAB && connection()->queryMouseButtons() != Qt::NoButton)
2035 m_ignorePressedWindowOnMouseLeave = true;
2036
2037 const QPoint global = QPoint(root_x, root_y);
2038 const QPoint local(event_x, event_y);
2039 QWindowSystemInterface::handleEnterEvent(window(), local, global);
2040}
2041
2042void QXcbWindow::handleLeaveNotifyEvent(int root_x, int root_y,
2043 quint8 mode, quint8 detail, xcb_timestamp_t timestamp)
2044{
2045 connection()->setTime(timestamp);
2046
2047 QXcbWindow *mousePressWindow = connection()->mousePressWindow();
2048 if (ignoreLeaveEvent(mode, detail, connection())
2049 || (mousePressWindow && !m_ignorePressedWindowOnMouseLeave)) {
2050 return;
2051 }
2052
2053 // check if enter event is buffered
2054 auto event = connection()->eventQueue()->peek([](xcb_generic_event_t *event, int type) {
2055 if (type != XCB_ENTER_NOTIFY)
2056 return false;
2057 auto enter = reinterpret_cast<xcb_enter_notify_event_t *>(event);
2058 return !ignoreEnterEvent(enter->mode, enter->detail);
2059 });
2060 auto enter = reinterpret_cast<xcb_enter_notify_event_t *>(event);
2061 QXcbWindow *enterWindow = enter ? connection()->platformWindowFromId(enter->event) : nullptr;
2062
2063 if (enterWindow) {
2064 QPoint local(enter->event_x, enter->event_y);
2065 QPoint global = QPoint(root_x, root_y);
2066 QWindowSystemInterface::handleEnterLeaveEvent(enterWindow->window(), window(), local, global);
2067 } else {
2068 QWindowSystemInterface::handleLeaveEvent(window());
2069 if (m_ignorePressedWindowOnMouseLeave)
2070 connection()->setMousePressWindow(nullptr);
2071 }
2072
2073 free(enter);
2074}
2075
2076void QXcbWindow::handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
2077 Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
2078 QEvent::Type type, Qt::MouseEventSource source)
2079{
2080 QPoint local(event_x, event_y);
2081 QPoint global(root_x, root_y);
2082
2083 // "mousePressWindow" can be NULL i.e. if a window will be grabbed or unmapped, so set it again here.
2084 // Unset "mousePressWindow" when mouse button isn't pressed - in some cases the release event won't arrive.
2085 const bool isMouseButtonPressed = (connection()->buttonState() != Qt::NoButton);
2086 const bool hasMousePressWindow = (connection()->mousePressWindow() != nullptr);
2087 if (isMouseButtonPressed && !hasMousePressWindow)
2088 connection()->setMousePressWindow(this);
2089 else if (hasMousePressWindow && !isMouseButtonPressed)
2090 connection()->setMousePressWindow(nullptr);
2091
2092 handleMouseEvent(timestamp, local, global, modifiers, type, source);
2093}
2094
2095void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
2096{
2097 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
2098 handleButtonPressEvent(event->event_x, event->event_y, event->root_x, event->root_y, event->detail,
2099 modifiers, event->time, QEvent::MouseButtonPress);
2100}
2101
2102void QXcbWindow::handleButtonReleaseEvent(const xcb_button_release_event_t *event)
2103{
2104 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
2105 handleButtonReleaseEvent(event->event_x, event->event_y, event->root_x, event->root_y, event->detail,
2106 modifiers, event->time, QEvent::MouseButtonRelease);
2107}
2108
2109void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
2110{
2111 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
2112 handleMotionNotifyEvent(event->event_x, event->event_y, event->root_x, event->root_y, modifiers,
2113 event->time, QEvent::MouseMove);
2114}
2115
2116static inline int fixed1616ToInt(xcb_input_fp1616_t val)
2117{
2118 return int(qreal(val) / 0x10000);
2119}
2120
2121#define qt_xcb_mask_is_set(ptr, event) (((unsigned char*)(ptr))[(event)>>3] & (1 << ((event) & 7)))
2122
2123void QXcbWindow::handleXIMouseEvent(xcb_ge_event_t *event, Qt::MouseEventSource source)
2124{
2125 QXcbConnection *conn = connection();
2126 auto *ev = reinterpret_cast<xcb_input_button_press_event_t *>(event);
2127
2128 if (ev->buttons_len > 0) {
2129 unsigned char *buttonMask = (unsigned char *) &ev[1];
2130 // There is a bug in the evdev driver which leads to receiving mouse events without
2131 // XIPointerEmulated being set: https://bugs.freedesktop.org/show_bug.cgi?id=98188
2132 // Filter them out by other attributes: when their source device is a touch screen
2133 // and the LMB is pressed.
2134 if (qt_xcb_mask_is_set(buttonMask, 1) && conn->isTouchScreen(ev->sourceid)) {
2135 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2136 qCDebug(lcQpaXInput, "XI2 mouse event from touch device %d was ignored", ev->sourceid);
2137 return;
2138 }
2139 for (int i = 1; i <= 15; ++i)
2140 conn->setButtonState(conn->translateMouseButton(i), qt_xcb_mask_is_set(buttonMask, i));
2141 }
2142
2143 const Qt::KeyboardModifiers modifiers = conn->keyboard()->translateModifiers(ev->mods.effective);
2144 const int event_x = fixed1616ToInt(ev->event_x);
2145 const int event_y = fixed1616ToInt(ev->event_y);
2146 const int root_x = fixed1616ToInt(ev->root_x);
2147 const int root_y = fixed1616ToInt(ev->root_y);
2148
2149 conn->keyboard()->updateXKBStateFromXI(&ev->mods, &ev->group);
2150
2151 const Qt::MouseButton button = conn->xiToQtMouseButton(ev->detail);
2152
2153 const char *sourceName = nullptr;
2154 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled())) {
2155 const QMetaObject *metaObject = qt_getEnumMetaObject(source);
2156 const QMetaEnum me = metaObject->enumerator(metaObject->indexOfEnumerator(qt_getEnumName(source)));
2157 sourceName = me.valueToKey(source);
2158 }
2159
2160 switch (ev->event_type) {
2161 case XCB_INPUT_BUTTON_PRESS:
2162 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2163 qCDebug(lcQpaXInputEvents, "XI2 mouse press, button %d, time %d, source %s", button, ev->time, sourceName);
2164 conn->setButtonState(button, true);
2165 handleButtonPressEvent(event_x, event_y, root_x, root_y, ev->detail, modifiers, ev->time, QEvent::MouseButtonPress, source);
2166 break;
2167 case XCB_INPUT_BUTTON_RELEASE:
2168 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2169 qCDebug(lcQpaXInputEvents, "XI2 mouse release, button %d, time %d, source %s", button, ev->time, sourceName);
2170 conn->setButtonState(button, false);
2171 handleButtonReleaseEvent(event_x, event_y, root_x, root_y, ev->detail, modifiers, ev->time, QEvent::MouseButtonRelease, source);
2172 break;
2173 case XCB_INPUT_MOTION:
2174 if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
2175 qCDebug(lcQpaXInputEvents, "XI2 mouse motion %d,%d, time %d, source %s", event_x, event_y, ev->time, sourceName);
2176 handleMotionNotifyEvent(event_x, event_y, root_x, root_y, modifiers, ev->time, QEvent::MouseMove, source);
2177 break;
2178 default:
2179 qWarning() << "Unrecognized XI2 mouse event" << ev->event_type;
2180 break;
2181 }
2182}
2183
2184void QXcbWindow::handleXIEnterLeave(xcb_ge_event_t *event)
2185{
2186 auto *ev = reinterpret_cast<xcb_input_enter_event_t *>(event);
2187
2188 // Compare the window with current mouse grabber to prevent deliver events to any other windows.
2189 // If leave event occurs and the window is under mouse - allow to deliver the leave event.
2190 QXcbWindow *mouseGrabber = connection()->mouseGrabber();
2191 if (mouseGrabber && mouseGrabber != this
2192 && (ev->event_type != XCB_INPUT_LEAVE || QGuiApplicationPrivate::currentMouseWindow != window())) {
2193 return;
2194 }
2195
2196 const int root_x = fixed1616ToInt(ev->root_x);
2197 const int root_y = fixed1616ToInt(ev->root_y);
2198
2199 switch (ev->event_type) {
2200 case XCB_INPUT_ENTER: {
2201 const int event_x = fixed1616ToInt(ev->event_x);
2202 const int event_y = fixed1616ToInt(ev->event_y);
2203 qCDebug(lcQpaXInputEvents, "XI2 mouse enter %d,%d, mode %d, detail %d, time %d",
2204 event_x, event_y, ev->mode, ev->detail, ev->time);
2205 handleEnterNotifyEvent(event_x, event_y, root_x, root_y, ev->mode, ev->detail, ev->time);
2206 break;
2207 }
2208 case XCB_INPUT_LEAVE:
2209 qCDebug(lcQpaXInputEvents, "XI2 mouse leave, mode %d, detail %d, time %d",
2210 ev->mode, ev->detail, ev->time);
2211 connection()->keyboard()->updateXKBStateFromXI(&ev->mods, &ev->group);
2212 handleLeaveNotifyEvent(root_x, root_y, ev->mode, ev->detail, ev->time);
2213 break;
2214 }
2215}
2216
2217QXcbWindow *QXcbWindow::toWindow() { return this; }
2218
2219void QXcbWindow::handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global,
2220 Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source)
2221{
2222 m_lastPointerPosition = local;
2223 m_lastPointerGlobalPosition = global;
2224 connection()->setTime(time);
2225 Qt::MouseButton button = type == QEvent::MouseMove ? Qt::NoButton : connection()->button();
2226 QWindowSystemInterface::handleMouseEvent(window(), time, local, global,
2227 connection()->buttonState(), button,
2228 type, modifiers, source);
2229}
2230
2231void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
2232{
2233 handleEnterNotifyEvent(event->event_x, event->event_y, event->root_x, event->root_y, event->mode, event->detail, event->time);
2234}
2235
2236void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
2237{
2238 handleLeaveNotifyEvent(event->root_x, event->root_y, event->mode, event->detail, event->time);
2239}
2240
2241void QXcbWindow::handlePropertyNotifyEvent(const xcb_property_notify_event_t *event)
2242{
2243 connection()->setTime(event->time);
2244
2245 const bool propertyDeleted = event->state == XCB_PROPERTY_DELETE;
2246
2247 if (event->atom == atom(QXcbAtom::Atom_NET_WM_STATE) || event->atom == atom(QXcbAtom::AtomWM_STATE)) {
2248 if (propertyDeleted)
2249 return;
2250
2251 Qt::WindowStates newState = Qt::WindowNoState;
2252
2253 if (event->atom == atom(QXcbAtom::AtomWM_STATE)) { // WM_STATE: Quick check for 'Minimize'.
2254 auto reply = Q_XCB_REPLY(xcb_get_property, xcb_connection(),
2255 0, m_window, atom(QXcbAtom::AtomWM_STATE),
2256 XCB_ATOM_ANY, 0, 1024);
2257 if (reply && reply->format == 32 && reply->type == atom(QXcbAtom::AtomWM_STATE)) {
2258 const quint32 *data = (const quint32 *)xcb_get_property_value(reply.get());
2259 if (reply->length != 0)
2260 m_minimized = (data[0] == XCB_ICCCM_WM_STATE_ICONIC
2261 || (data[0] == XCB_ICCCM_WM_STATE_WITHDRAWN && m_minimized));
2262 }
2263 }
2264
2265 const NetWmStates states = netWmStates();
2266 // _NET_WM_STATE_HIDDEN should be set by the Window Manager to indicate that a window would
2267 // not be visible on the screen if its desktop/viewport were active and its coordinates were
2268 // within the screen bounds. The canonical example is that minimized windows should be in
2269 // the _NET_WM_STATE_HIDDEN state.
2270 if (m_minimized && (!connection()->wmSupport()->isSupportedByWM(NetWmStateHidden)
2271 || states.testFlag(NetWmStateHidden)))
2272 newState = Qt::WindowMinimized;
2273
2274 if (states & NetWmStateFullScreen)
2275 newState |= Qt::WindowFullScreen;
2276 if ((states & NetWmStateMaximizedHorz) && (states & NetWmStateMaximizedVert))
2277 newState |= Qt::WindowMaximized;
2278 // Send Window state, compress events in case other flags (modality, etc) are changed.
2279 if (m_lastWindowStateEvent != newState) {
2280 QWindowSystemInterface::handleWindowStateChanged(window(), newState);
2281 m_lastWindowStateEvent = newState;
2282 m_windowState = newState;
2283 if ((m_windowState & Qt::WindowMinimized) && connection()->mouseGrabber() == this)
2284 connection()->setMouseGrabber(nullptr);
2285 }
2286 return;
2287 } else if (event->atom == atom(QXcbAtom::Atom_NET_FRAME_EXTENTS)) {
2288 m_dirtyFrameMargins = true;
2289 }
2290}
2291
2292void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *event)
2293{
2294 // Ignore focus events that are being sent only because the pointer is over
2295 // our window, even if the input focus is in a different window.
2296 if (event->detail == XCB_NOTIFY_DETAIL_POINTER)
2297 return;
2298
2299 connection()->focusInTimer().stop();
2300 doFocusIn();
2301}
2302
2303
2304void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *event)
2305{
2306 // Ignore focus events that are being sent only because the pointer is over
2307 // our window, even if the input focus is in a different window.
2308 if (event->detail == XCB_NOTIFY_DETAIL_POINTER)
2309 return;
2310 doFocusOut();
2311}
2312
2313void QXcbWindow::updateSyncRequestCounter()
2314{
2315 if (m_syncState != SyncAndConfigureReceived) {
2316 // window manager does not expect a sync event yet.
2317 return;
2318 }
2319 if (connection()->hasXSync() && (m_syncValue.lo != 0 || m_syncValue.hi != 0)) {
2320 xcb_sync_set_counter(xcb_connection(), m_syncCounter, m_syncValue);
2321 xcb_flush(xcb_connection());
2322
2323 m_syncValue.lo = 0;
2324 m_syncValue.hi = 0;
2325 m_syncState = NoSyncNeeded;
2326 }
2327}
2328
2329const xcb_visualtype_t *QXcbWindow::createVisual()
2330{
2331 return xcbScreen() ? xcbScreen()->visualForFormat(m_format)
2332 : nullptr;
2333}
2334
2335bool QXcbWindow::setKeyboardGrabEnabled(bool grab)
2336{
2337 if (grab && !connection()->canGrab())
2338 return false;
2339
2340 if (!grab) {
2341 xcb_ungrab_keyboard(xcb_connection(), XCB_TIME_CURRENT_TIME);
2342 return true;
2343 }
2344
2345 auto reply = Q_XCB_REPLY(xcb_grab_keyboard, xcb_connection(), false,
2346 m_window, XCB_TIME_CURRENT_TIME,
2347 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
2348 return reply && reply->status == XCB_GRAB_STATUS_SUCCESS;
2349}
2350
2351bool QXcbWindow::setMouseGrabEnabled(bool grab)
2352{
2353 if (!grab && connection()->mouseGrabber() == this)
2354 connection()->setMouseGrabber(nullptr);
2355
2356 if (grab && !connection()->canGrab())
2357 return false;
2358
2359 if (connection()->hasXInput2()) {
2360 bool result = connection()->xi2SetMouseGrabEnabled(m_window, grab);
2361 if (grab && result)
2362 connection()->setMouseGrabber(this);
2363 return result;
2364 }
2365
2366 if (!grab) {
2367 xcb_ungrab_pointer(xcb_connection(), XCB_TIME_CURRENT_TIME);
2368 return true;
2369 }
2370
2371 auto reply = Q_XCB_REPLY(xcb_grab_pointer, xcb_connection(),
2372 false, m_window,
2373 (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
2374 | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_ENTER_WINDOW
2375 | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION),
2376 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
2377 XCB_WINDOW_NONE, XCB_CURSOR_NONE,
2378 XCB_TIME_CURRENT_TIME);
2379 bool result = reply && reply->status == XCB_GRAB_STATUS_SUCCESS;
2380 if (result)
2381 connection()->setMouseGrabber(this);
2382 return result;
2383}
2384
2385bool QXcbWindow::windowEvent(QEvent *event)
2386{
2387 switch (event->type()) {
2388 case QEvent::FocusIn:
2389 if (m_embedded && !m_trayIconWindow && !event->spontaneous()) {
2390 QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event);
2391 switch (focusEvent->reason()) {
2392 case Qt::TabFocusReason:
2393 case Qt::BacktabFocusReason:
2394 {
2395 const QXcbWindow *container =
2396 static_cast<const QXcbWindow *>(QPlatformWindow::parent());
2397 sendXEmbedMessage(container->xcb_window(),
2398 focusEvent->reason() == Qt::TabFocusReason ?
2399 XEMBED_FOCUS_NEXT : XEMBED_FOCUS_PREV);
2400 event->accept();
2401 }
2402 break;
2403 default:
2404 break;
2405 }
2406 }
2407 break;
2408 default:
2409 break;
2410 }
2411 return QPlatformWindow::windowEvent(event);
2412}
2413
2414bool QXcbWindow::startSystemResize(Qt::Edges edges)
2415{
2416 return startSystemMoveResize(m_lastPointerPosition, edges);
2417}
2418
2419bool QXcbWindow::startSystemMove()
2420{
2421 return startSystemMoveResize(m_lastPointerPosition, 16);
2422}
2423
2424bool QXcbWindow::startSystemMoveResize(const QPoint &pos, int edges)
2425{
2426 const xcb_atom_t moveResize = connection()->atom(QXcbAtom::Atom_NET_WM_MOVERESIZE);
2427 if (!connection()->wmSupport()->isSupportedByWM(moveResize))
2428 return false;
2429
2430 // ### FIXME QTBUG-53389
2431 bool startedByTouch = connection()->startSystemMoveResizeForTouch(m_window, edges);
2432 if (startedByTouch) {
2433 const QString wmname = connection()->windowManagerName();
2434 if (wmname != "kwin"_L1 && wmname != "openbox"_L1) {
2435 qCDebug(lcQpaInputDevices) << "only KDE and OpenBox support startSystemMove/Resize which is triggered from touch events: XDG_CURRENT_DESKTOP="
2436 << qgetenv("XDG_CURRENT_DESKTOP");
2437 connection()->abortSystemMoveResize(m_window);
2438 return false;
2439 }
2440 // KWin, Openbox, AwesomeWM and Gnome have been tested to work with _NET_WM_MOVERESIZE.
2441 } else { // Started by mouse press.
2442 doStartSystemMoveResize(mapToGlobal(pos), edges);
2443 }
2444
2445 return true;
2446}
2447
2448static uint qtEdgesToXcbMoveResizeDirection(Qt::Edges edges)
2449{
2450 if (edges == (Qt::TopEdge | Qt::LeftEdge))
2451 return 0;
2452 if (edges == Qt::TopEdge)
2453 return 1;
2454 if (edges == (Qt::TopEdge | Qt::RightEdge))
2455 return 2;
2456 if (edges == Qt::RightEdge)
2457 return 3;
2458 if (edges == (Qt::RightEdge | Qt::BottomEdge))
2459 return 4;
2460 if (edges == Qt::BottomEdge)
2461 return 5;
2462 if (edges == (Qt::BottomEdge | Qt::LeftEdge))
2463 return 6;
2464 if (edges == Qt::LeftEdge)
2465 return 7;
2466
2467 qWarning() << "Cannot convert " << edges << "to _NET_WM_MOVERESIZE direction.";
2468 return 0;
2469}
2470
2471void QXcbWindow::doStartSystemMoveResize(const QPoint &globalPos, int edges)
2472{
2473 qCDebug(lcQpaInputDevices) << "triggered system move or resize via sending _NET_WM_MOVERESIZE client message";
2474 const xcb_atom_t moveResize = connection()->atom(QXcbAtom::Atom_NET_WM_MOVERESIZE);
2475 xcb_client_message_event_t xev;
2476 xev.response_type = XCB_CLIENT_MESSAGE;
2477 xev.type = moveResize;
2478 xev.sequence = 0;
2479 xev.window = xcb_window();
2480 xev.format = 32;
2481 xev.data.data32[0] = globalPos.x();
2482 xev.data.data32[1] = globalPos.y();
2483 if (edges == 16)
2484 xev.data.data32[2] = 8; // move
2485 else
2486 xev.data.data32[2] = qtEdgesToXcbMoveResizeDirection(Qt::Edges(edges));
2487 xev.data.data32[3] = XCB_BUTTON_INDEX_1;
2488 xev.data.data32[4] = 0;
2489 xcb_ungrab_pointer(connection()->xcb_connection(), XCB_CURRENT_TIME);
2490 xcb_send_event(connection()->xcb_connection(), false, xcbScreen()->root(),
2491 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
2492 (const char *)&xev);
2493
2494 connection()->setDuringSystemMoveResize(true);
2495}
2496
2497// Sends an XEmbed message.
2498void QXcbWindow::sendXEmbedMessage(xcb_window_t window, quint32 message,
2499 quint32 detail, quint32 data1, quint32 data2)
2500{
2501 xcb_client_message_event_t event;
2502
2503 event.response_type = XCB_CLIENT_MESSAGE;
2504 event.format = 32;
2505 event.sequence = 0;
2506 event.window = window;
2507 event.type = atom(QXcbAtom::Atom_XEMBED);
2508 event.data.data32[0] = connection()->time();
2509 event.data.data32[1] = message;
2510 event.data.data32[2] = detail;
2511 event.data.data32[3] = data1;
2512 event.data.data32[4] = data2;
2513 xcb_send_event(xcb_connection(), false, window, XCB_EVENT_MASK_NO_EVENT, (const char *)&event);
2514}
2515
2516static bool focusWindowChangeQueued(const QWindow *window)
2517{
2518 /* Check from window system event queue if the next queued activation
2519 * targets a window other than @window.
2520 */
2521 QWindowSystemInterfacePrivate::FocusWindowEvent *systemEvent =
2522 static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>
2523 (QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::FocusWindow));
2524 return systemEvent && systemEvent->focused != window;
2525}
2526
2527void QXcbWindow::handleXEmbedMessage(const xcb_client_message_event_t *event)
2528{
2529 connection()->setTime(event->data.data32[0]);
2530 switch (event->data.data32[1]) {
2531 case XEMBED_WINDOW_ACTIVATE:
2532 case XEMBED_WINDOW_DEACTIVATE:
2533 break;
2534 case XEMBED_EMBEDDED_NOTIFY:
2535 xcb_map_window(xcb_connection(), m_window);
2536 xcbScreen()->windowShown(this);
2537 break;
2538 case XEMBED_FOCUS_IN:
2539 connection()->focusInTimer().stop();
2540 Qt::FocusReason reason;
2541 switch (event->data.data32[2]) {
2542 case XEMBED_FOCUS_FIRST:
2543 reason = Qt::TabFocusReason;
2544 break;
2545 case XEMBED_FOCUS_LAST:
2546 reason = Qt::BacktabFocusReason;
2547 break;
2548 case XEMBED_FOCUS_CURRENT:
2549 default:
2550 reason = Qt::OtherFocusReason;
2551 break;
2552 }
2553 connection()->setFocusWindow(window());
2554 QWindowSystemInterface::handleFocusWindowChanged(window(), reason);
2555 break;
2556 case XEMBED_FOCUS_OUT:
2557 if (window() == QGuiApplication::focusWindow()
2558 && !focusWindowChangeQueued(window())) {
2559 connection()->setFocusWindow(nullptr);
2560 QWindowSystemInterface::handleFocusWindowChanged(nullptr);
2561 }
2562 break;
2563 }
2564}
2565
2566static inline xcb_rectangle_t qRectToXCBRectangle(const QRect &r)
2567{
2568 xcb_rectangle_t result;
2569 result.x = qMax(SHRT_MIN, r.x());
2570 result.y = qMax(SHRT_MIN, r.y());
2571 result.width = qMin((int)USHRT_MAX, r.width());
2572 result.height = qMin((int)USHRT_MAX, r.height());
2573 return result;
2574}
2575
2576void QXcbWindow::setOpacity(qreal level)
2577{
2578 if (!m_window)
2579 return;
2580
2581 quint32 value = qRound64(qBound(qreal(0), level, qreal(1)) * qreal(0xffffffff));
2582
2583 xcb_change_property(xcb_connection(),
2584 XCB_PROP_MODE_REPLACE,
2585 m_window,
2586 atom(QXcbAtom::Atom_NET_WM_WINDOW_OPACITY),
2587 XCB_ATOM_CARDINAL,
2588 32,
2589 1,
2590 (uchar *)&value);
2591}
2592
2593QList<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion &region)
2594{
2595 QList<xcb_rectangle_t> rects;
2596 rects.reserve(region.rectCount());
2597 for (const QRect &r : region)
2598 rects.push_back(qRectToXCBRectangle(r));
2599 return rects;
2600}
2601
2602void QXcbWindow::setMask(const QRegion &region)
2603{
2604 if (!connection()->hasXShape())
2605 return;
2606 if (region.isEmpty()) {
2607 xcb_shape_mask(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
2608 XCB_SHAPE_SK_BOUNDING, xcb_window(), 0, 0, XCB_NONE);
2609 } else {
2610 const auto rects = qRegionToXcbRectangleList(region);
2611 xcb_shape_rectangles(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
2612 XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
2613 xcb_window(), 0, 0, rects.size(), &rects[0]);
2614 }
2615}
2616
2617void QXcbWindow::setAlertState(bool enabled)
2618{
2619 if (m_alertState == enabled)
2620 return;
2621
2622 m_alertState = enabled;
2623
2624 setNetWmState(enabled, atom(QXcbAtom::Atom_NET_WM_STATE_DEMANDS_ATTENTION));
2625}
2626
2627uint QXcbWindow::visualId() const
2628{
2629 return m_visualId;
2630}
2631
2632bool QXcbWindow::needsSync() const
2633{
2634 return m_syncState == SyncAndConfigureReceived;
2635}
2636
2637void QXcbWindow::postSyncWindowRequest()
2638{
2639 if (!m_pendingSyncRequest) {
2640 QXcbSyncWindowRequest *e = new QXcbSyncWindowRequest(this);
2641 m_pendingSyncRequest = e;
2642 QCoreApplication::postEvent(xcbScreen()->connection(), e);
2643 }
2644}
2645
2646QXcbScreen *QXcbWindow::xcbScreen() const
2647{
2648 return static_cast<QXcbScreen *>(screen());
2649}
2650
2651void QXcbWindow::setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title)
2652{
2653 QString fullTitle = formatWindowTitle(title, QString::fromUtf8(" \xe2\x80\x94 ")); // unicode character U+2014, EM DASH
2654 const QByteArray ba = std::move(fullTitle).toUtf8();
2655 xcb_change_property(conn->xcb_connection(),
2656 XCB_PROP_MODE_REPLACE,
2657 window,
2658 conn->atom(QXcbAtom::Atom_NET_WM_NAME),
2659 conn->atom(QXcbAtom::AtomUTF8_STRING),
2660 8,
2661 ba.size(),
2662 ba.constData());
2663
2664#if QT_CONFIG(xcb_xlib)
2665 Display *dpy = static_cast<Display *>(conn->xlib_display());
2666 XTextProperty *text = qstringToXTP(dpy, title);
2667 if (text)
2668 XSetWMName(dpy, window, text);
2669#endif
2670 xcb_flush(conn->xcb_connection());
2671}
2672
2673QString QXcbWindow::windowTitle(const QXcbConnection *conn, xcb_window_t window)
2674{
2675 const xcb_atom_t utf8Atom = conn->atom(QXcbAtom::AtomUTF8_STRING);
2676 auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, conn->xcb_connection(),
2677 false, window, conn->atom(QXcbAtom::Atom_NET_WM_NAME),
2678 utf8Atom, 0, 1024);
2679 if (reply && reply->format == 8 && reply->type == utf8Atom) {
2680 const char *name = reinterpret_cast<const char *>(xcb_get_property_value(reply.get()));
2681 return QString::fromUtf8(name, xcb_get_property_value_length(reply.get()));
2682 }
2683
2684 reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, conn->xcb_connection(),
2685 false, window, conn->atom(QXcbAtom::AtomWM_NAME),
2686 XCB_ATOM_STRING, 0, 1024);
2687 if (reply && reply->format == 8 && reply->type == XCB_ATOM_STRING) {
2688 const char *name = reinterpret_cast<const char *>(xcb_get_property_value(reply.get()));
2689 return QString::fromLatin1(name, xcb_get_property_value_length(reply.get()));
2690 }
2691
2692 return QString();
2693}
2694
2695QT_END_NAMESPACE
Definition qlist.h:81
QXcbForeignWindow(QWindow *window, WId nativeHandle)
@ defaultWindowHeight
Definition qioswindow.mm:35
@ defaultWindowWidth
Definition qioswindow.mm:34
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define Q_XCB_REPLY(call,...)
#define Q_XCB_REPLY_UNCHECKED(call,...)
static Qt::WindowFlags x11AdjustedWindowFlags(Qt::WindowFlags flags)
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