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