1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the plugins of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qxcbwindow.h"
47 #include "qxcbconnection.h"
48 #include "qxcbscreen.h"
50 #include "qxcbkeyboard.h"
51 #include "qxcbwmsupport.h"
54 #include "qdri2context.h"
57 // FIXME This workaround can be removed for xcb-icccm > 3.8
58 #define class class_name
59 #include <xcb/xcb_icccm.h>
61 #include <xcb/xfixes.h>
63 // xcb-icccm 3.8 support
64 #ifdef XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS
65 #define xcb_get_wm_hints_reply xcb_icccm_get_wm_hints_reply
66 #define xcb_get_wm_hints xcb_icccm_get_wm_hints
67 #define xcb_set_wm_hints xcb_icccm_set_wm_hints
68 #define xcb_set_wm_normal_hints xcb_icccm_set_wm_normal_hints
69 #define xcb_size_hints_set_base_size xcb_icccm_size_hints_set_base_size
70 #define xcb_size_hints_set_max_size xcb_icccm_size_hints_set_max_size
71 #define xcb_size_hints_set_min_size xcb_icccm_size_hints_set_min_size
72 #define xcb_size_hints_set_position xcb_icccm_size_hints_set_position
73 #define xcb_size_hints_set_resize_inc xcb_icccm_size_hints_set_resize_inc
74 #define xcb_size_hints_set_size xcb_icccm_size_hints_set_size
75 #define xcb_size_hints_set_win_gravity xcb_icccm_size_hints_set_win_gravity
76 #define xcb_wm_hints_set_iconic xcb_icccm_wm_hints_set_iconic
77 #define xcb_wm_hints_set_normal xcb_icccm_wm_hints_set_normal
78 #define xcb_wm_hints_t xcb_icccm_wm_hints_t
79 #define XCB_WM_STATE_ICONIC XCB_ICCCM_WM_STATE_ICONIC
80 #define XCB_WM_STATE_WITHDRAWN XCB_ICCCM_WM_STATE_WITHDRAWN
83 #include <private/qguiapplication_p.h>
84 #include <private/qwindow_p.h>
86 #include <QtGui/QPlatformBackingStore>
87 #include <QtGui/QWindowSystemInterface>
93 #include <X11/Xutil.h>
96 #if defined(XCB_USE_GLX)
97 #include "qglxintegration.h"
98 #include <QtPlatformSupport/private/qglxconvenience_p.h>
99 #elif defined(XCB_USE_EGL)
100 #include "qxcbeglsurface.h"
101 #include <QtPlatformSupport/private/qeglconvenience_p.h>
102 #include <QtPlatformSupport/private/qxlibeglintegration_p.h>
105 #define XCOORD_MAX 16383
107 //#ifdef NET_WM_STATE_DEBUG
111 // Returns true if we should set WM_TRANSIENT_FOR on \a w
112 static inline bool isTransient(const QWindow *w)
114 return w->windowType() == Qt::Dialog
115 || w->windowType() == Qt::Sheet
116 || w->windowType() == Qt::Tool
117 || w->windowType() == Qt::SplashScreen
118 || w->windowType() == Qt::ToolTip
119 || w->windowType() == Qt::Drawer
120 || w->windowType() == Qt::Popup;
123 static inline QImage::Format imageFormatForDepth(int depth)
126 case 32: return QImage::Format_ARGB32_Premultiplied;
127 case 24: return QImage::Format_RGB32;
128 case 16: return QImage::Format_RGB16;
131 qFatal("Unsupported display depth %d", depth);
132 return QImage::Format_Invalid;
135 QXcbWindow::QXcbWindow(QWindow *window)
136 : QPlatformWindow(window)
140 , m_transparent(false)
141 , m_netWmUserTimeWindow(XCB_NONE)
142 #if defined(XCB_USE_EGL)
146 m_screen = static_cast<QXcbScreen *>(window->screen()->handle());
148 setConnection(m_screen->connection());
153 void QXcbWindow::create()
157 m_windowState = Qt::WindowNoState;
159 Qt::WindowType type = window()->windowType();
161 if (type == Qt::Desktop) {
162 m_window = m_screen->root();
163 m_depth = m_screen->screen()->root_depth;
164 m_imageFormat = imageFormatForDepth(m_depth);
165 connection()->addWindow(m_window, this);
169 const quint32 mask = XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_SAVE_UNDER | XCB_CW_EVENT_MASK;
170 const quint32 values[] = {
171 // XCB_CW_BACK_PIXMAP
173 // XCB_CW_OVERRIDE_REDIRECT
174 type == Qt::Popup || type == Qt::ToolTip,
176 type == Qt::Popup || type == Qt::Tool || type == Qt::SplashScreen || type == Qt::ToolTip || type == Qt::Drawer,
178 XCB_EVENT_MASK_EXPOSURE
179 | XCB_EVENT_MASK_STRUCTURE_NOTIFY
180 | XCB_EVENT_MASK_KEY_PRESS
181 | XCB_EVENT_MASK_KEY_RELEASE
182 | XCB_EVENT_MASK_BUTTON_PRESS
183 | XCB_EVENT_MASK_BUTTON_RELEASE
184 | XCB_EVENT_MASK_BUTTON_MOTION
185 | XCB_EVENT_MASK_ENTER_WINDOW
186 | XCB_EVENT_MASK_LEAVE_WINDOW
187 | XCB_EVENT_MASK_POINTER_MOTION
188 | XCB_EVENT_MASK_PROPERTY_CHANGE
189 | XCB_EVENT_MASK_FOCUS_CHANGE
192 QRect rect = window()->geometry();
193 QPlatformWindow::setGeometry(rect);
195 rect.setWidth(qBound(1, rect.width(), XCOORD_MAX));
196 rect.setHeight(qBound(1, rect.height(), XCOORD_MAX));
198 xcb_window_t xcb_parent_id = m_screen->root();
200 xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window();
202 m_requestedFormat = window()->format();
204 #if (defined(XCB_USE_GLX) || defined(XCB_USE_EGL)) && defined(XCB_USE_XLIB)
205 if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
206 || window()->format().hasAlpha())
208 #if defined(XCB_USE_GLX)
209 XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), window()->format());
211 #elif defined(XCB_USE_EGL)
212 EGLDisplay eglDisplay = connection()->egl_display();
213 EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, window()->format(), true);
214 VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig);
216 XVisualInfo visualInfoTemplate;
217 memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
218 visualInfoTemplate.visualid = id;
220 XVisualInfo *visualInfo;
221 int matchingCount = 0;
222 visualInfo = XGetVisualInfo(DISPLAY_FROM_XCB(this), VisualIDMask, &visualInfoTemplate, &matchingCount);
225 m_depth = visualInfo->depth;
226 m_imageFormat = imageFormatForDepth(m_depth);
227 Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), xcb_parent_id, visualInfo->visual, AllocNone);
229 XSetWindowAttributes a;
230 a.background_pixel = WhitePixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber());
231 a.border_pixel = BlackPixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber());
234 m_visualId = visualInfo->visualid;
236 m_window = XCreateWindow(DISPLAY_FROM_XCB(this), xcb_parent_id, rect.x(), rect.y(), rect.width(), rect.height(),
237 0, visualInfo->depth, InputOutput, visualInfo->visual,
238 CWBackPixel|CWBorderPixel|CWColormap, &a);
240 qFatal("no window!");
243 #endif //defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
245 m_window = xcb_generate_id(xcb_connection());
246 m_depth = m_screen->screen()->root_depth;
247 m_imageFormat = imageFormatForDepth(m_depth);
248 m_visualId = m_screen->screen()->root_visual;
250 Q_XCB_CALL(xcb_create_window(xcb_connection(),
251 XCB_COPY_FROM_PARENT, // depth -- same as root
252 m_window, // window id
253 xcb_parent_id, // parent window id
259 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
260 m_visualId, // visual
265 connection()->addWindow(m_window, this);
267 Q_XCB_CALL(xcb_change_window_attributes(xcb_connection(), m_window, mask, values));
269 propagateSizeHints();
271 xcb_atom_t properties[4];
272 int propertyCount = 0;
273 properties[propertyCount++] = atom(QXcbAtom::WM_DELETE_WINDOW);
274 properties[propertyCount++] = atom(QXcbAtom::WM_TAKE_FOCUS);
275 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_PING);
277 if (m_screen->syncRequestSupported())
278 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_SYNC_REQUEST);
280 if (window()->windowFlags() & Qt::WindowContextHelpButtonHint)
281 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_CONTEXT_HELP);
283 Q_XCB_CALL(xcb_change_property(xcb_connection(),
284 XCB_PROP_MODE_REPLACE,
286 atom(QXcbAtom::WM_PROTOCOLS),
294 if (m_screen->syncRequestSupported()) {
295 m_syncCounter = xcb_generate_id(xcb_connection());
296 Q_XCB_CALL(xcb_sync_create_counter(xcb_connection(), m_syncCounter, m_syncValue));
298 Q_XCB_CALL(xcb_change_property(xcb_connection(),
299 XCB_PROP_MODE_REPLACE,
301 atom(QXcbAtom::_NET_WM_SYNC_REQUEST_COUNTER),
308 // set the PID to let the WM kill the application if unresponsive
310 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
311 atom(QXcbAtom::_NET_WM_PID), XCB_ATOM_CARDINAL, 32,
314 xcb_wm_hints_t hints;
315 memset(&hints, 0, sizeof(hints));
316 xcb_wm_hints_set_normal(&hints);
318 xcb_set_wm_hints(xcb_connection(), m_window, &hints);
320 xcb_window_t leader = m_screen->clientLeader();
321 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
322 atom(QXcbAtom::WM_CLIENT_LEADER), XCB_ATOM_WINDOW, 32,
325 setWindowFlags(window()->windowFlags());
326 setWindowTitle(window()->windowTitle());
327 setWindowState(window()->windowState());
329 if (window()->windowFlags() & Qt::WindowTransparentForInput)
330 setTransparentForMouseEvents(true);
332 connection()->drag()->dndEnable(this, true);
335 QXcbWindow::~QXcbWindow()
340 void QXcbWindow::destroy()
342 if (m_syncCounter && m_screen->syncRequestSupported())
343 Q_XCB_CALL(xcb_sync_destroy_counter(xcb_connection(), m_syncCounter));
345 connection()->removeWindow(m_window);
346 Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window));
350 #if defined(XCB_USE_EGL)
356 void QXcbWindow::setGeometry(const QRect &rect)
358 QPlatformWindow::setGeometry(rect);
360 propagateSizeHints();
362 const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
363 const quint32 values[] = { rect.x(),
365 qBound(1, rect.width(), XCOORD_MAX),
366 qBound(1, rect.height(), XCOORD_MAX) };
368 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
370 xcb_flush(xcb_connection());
373 QMargins QXcbWindow::frameMargins() const
375 if (m_dirtyFrameMargins) {
376 xcb_window_t window = m_window;
377 xcb_window_t parent = m_window;
379 bool foundRoot = false;
381 const QVector<xcb_window_t> &virtualRoots =
382 connection()->wmSupport()->virtualRoots();
385 xcb_query_tree_cookie_t cookie = xcb_query_tree(xcb_connection(), parent);
387 xcb_generic_error_t *error;
388 xcb_query_tree_reply_t *reply = xcb_query_tree_reply(xcb_connection(), cookie, &error);
390 if (reply->root == reply->parent || virtualRoots.indexOf(reply->parent) != -1) {
394 parent = reply->parent;
400 connection()->handleXcbError(error);
404 m_dirtyFrameMargins = false;
405 m_frameMargins = QMargins();
406 return m_frameMargins;
412 xcb_generic_error_t *error;
413 xcb_translate_coordinates_reply_t *reply =
414 xcb_translate_coordinates_reply(
416 xcb_translate_coordinates(xcb_connection(), window, parent, 0, 0),
420 offset = QPoint(reply->dst_x, reply->dst_y);
426 xcb_get_geometry_reply_t *geom =
427 xcb_get_geometry_reply(
429 xcb_get_geometry(xcb_connection(), parent),
434 // add the border_width for the window managers frame... some window managers
435 // do not use a border_width of zero for their frames, and if we the left and
436 // top strut, we ensure that pos() is absolutely correct. frameGeometry()
437 // will still be incorrect though... perhaps i should have foffset as well, to
438 // indicate the frame offset (equal to the border_width on X).
440 // -- copied from qwidget_x11.cpp
442 int left = offset.x() + geom->border_width;
443 int top = offset.y() + geom->border_width;
444 int right = geom->width + geom->border_width - geometry().width() - offset.x();
445 int bottom = geom->height + geom->border_width - geometry().height() - offset.y();
447 m_frameMargins = QMargins(left, top, right, bottom);
454 m_dirtyFrameMargins = false;
457 return m_frameMargins;
460 void QXcbWindow::setVisible(bool visible)
468 void QXcbWindow::show()
470 if (window()->isTopLevel()) {
471 xcb_get_property_cookie_t cookie = xcb_get_wm_hints(xcb_connection(), m_window);
473 xcb_generic_error_t *error;
475 xcb_wm_hints_t hints;
476 xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, &error);
479 connection()->handleXcbError(error);
483 if (window()->windowState() & Qt::WindowMinimized)
484 xcb_wm_hints_set_iconic(&hints);
486 xcb_wm_hints_set_normal(&hints);
488 xcb_set_wm_hints(xcb_connection(), m_window, &hints);
490 // update WM_NORMAL_HINTS
491 propagateSizeHints();
493 // update WM_TRANSIENT_FOR
494 if (window()->transientParent() && isTransient(window())) {
495 QXcbWindow *transientXcbParent = static_cast<QXcbWindow *>(window()->transientParent()->handle());
496 if (transientXcbParent) {
498 xcb_window_t parentWindow = transientXcbParent->xcb_window();
500 // todo: set transient for group (wm_client_leader) if no parent, a la qwidget_x11.cpp
501 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
502 XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
507 // update _MOTIF_WM_HINTS
508 updateMotifWmHintsBeforeMap();
510 // update _NET_WM_STATE
511 updateNetWmStateBeforeMap();
514 Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
515 xcb_flush(xcb_connection());
517 connection()->sync();
520 void QXcbWindow::hide()
522 Q_XCB_CALL(xcb_unmap_window(xcb_connection(), m_window));
524 // send synthetic UnmapNotify event according to icccm 4.1.4
525 xcb_unmap_notify_event_t event;
526 event.response_type = XCB_UNMAP_NOTIFY;
527 event.event = m_screen->root();
528 event.window = m_window;
529 event.from_configure = false;
530 Q_XCB_CALL(xcb_send_event(xcb_connection(), false, m_screen->root(),
531 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
533 xcb_flush(xcb_connection());
538 struct QtMotifWmHints {
539 quint32 flags, functions, decorations;
545 MWM_HINTS_FUNCTIONS = (1L << 0),
547 MWM_FUNC_ALL = (1L << 0),
548 MWM_FUNC_RESIZE = (1L << 1),
549 MWM_FUNC_MOVE = (1L << 2),
550 MWM_FUNC_MINIMIZE = (1L << 3),
551 MWM_FUNC_MAXIMIZE = (1L << 4),
552 MWM_FUNC_CLOSE = (1L << 5),
554 MWM_HINTS_DECORATIONS = (1L << 1),
556 MWM_DECOR_ALL = (1L << 0),
557 MWM_DECOR_BORDER = (1L << 1),
558 MWM_DECOR_RESIZEH = (1L << 2),
559 MWM_DECOR_TITLE = (1L << 3),
560 MWM_DECOR_MENU = (1L << 4),
561 MWM_DECOR_MINIMIZE = (1L << 5),
562 MWM_DECOR_MAXIMIZE = (1L << 6),
564 MWM_HINTS_INPUT_MODE = (1L << 2),
566 MWM_INPUT_MODELESS = 0L,
567 MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L,
568 MWM_INPUT_FULL_APPLICATION_MODAL = 3L
571 static QtMotifWmHints getMotifWmHints(QXcbConnection *c, xcb_window_t window)
573 QtMotifWmHints hints;
575 xcb_get_property_cookie_t get_cookie =
576 xcb_get_property(c->xcb_connection(), 0, window, c->atom(QXcbAtom::_MOTIF_WM_HINTS),
577 c->atom(QXcbAtom::_MOTIF_WM_HINTS), 0, 20);
579 xcb_generic_error_t *error;
581 xcb_get_property_reply_t *reply =
582 xcb_get_property_reply(c->xcb_connection(), get_cookie, &error);
584 if (reply && reply->format == 32 && reply->type == c->atom(QXcbAtom::_MOTIF_WM_HINTS)) {
585 hints = *((QtMotifWmHints *)xcb_get_property_value(reply));
587 c->handleXcbError(error);
591 hints.functions = MWM_FUNC_ALL;
592 hints.decorations = MWM_DECOR_ALL;
593 hints.input_mode = 0L;
602 static void setMotifWmHints(QXcbConnection *c, xcb_window_t window, const QtMotifWmHints &hints)
604 if (hints.flags != 0l) {
605 Q_XCB_CALL2(xcb_change_property(c->xcb_connection(),
606 XCB_PROP_MODE_REPLACE,
608 c->atom(QXcbAtom::_MOTIF_WM_HINTS),
609 c->atom(QXcbAtom::_MOTIF_WM_HINTS),
614 Q_XCB_CALL2(xcb_delete_property(c->xcb_connection(), window, c->atom(QXcbAtom::_MOTIF_WM_HINTS)), c);
618 void QXcbWindow::printNetWmState(const QVector<xcb_atom_t> &state)
620 printf("_NET_WM_STATE (%d): ", state.size());
621 for (int i = 0; i < state.size(); ++i) {
622 #define CHECK_WM_STATE(state_atom) \
623 if (state.at(i) == atom(QXcbAtom::state_atom))\
624 printf(#state_atom " ");
625 CHECK_WM_STATE(_NET_WM_STATE_ABOVE)
626 CHECK_WM_STATE(_NET_WM_STATE_BELOW)
627 CHECK_WM_STATE(_NET_WM_STATE_FULLSCREEN)
628 CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_HORZ)
629 CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_VERT)
630 CHECK_WM_STATE(_NET_WM_STATE_MODAL)
631 CHECK_WM_STATE(_NET_WM_STATE_STAYS_ON_TOP)
632 CHECK_WM_STATE(_NET_WM_STATE_DEMANDS_ATTENTION)
633 #undef CHECK_WM_STATE
638 QVector<xcb_atom_t> QXcbWindow::getNetWmState()
640 QVector<xcb_atom_t> result;
642 xcb_get_property_cookie_t get_cookie =
643 xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::_NET_WM_STATE),
644 XCB_ATOM_ATOM, 0, 1024);
646 xcb_generic_error_t *error;
648 xcb_get_property_reply_t *reply =
649 xcb_get_property_reply(xcb_connection(), get_cookie, &error);
651 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) {
652 result.resize(reply->length);
654 memcpy(result.data(), xcb_get_property_value(reply), reply->length * sizeof(xcb_atom_t));
656 #ifdef NET_WM_STATE_DEBUG
657 printf("getting net wm state (%x)\n", m_window);
658 printNetWmState(result);
663 connection()->handleXcbError(error);
666 #ifdef NET_WM_STATE_DEBUG
667 printf("getting net wm state (%x), empty\n", m_window);
674 void QXcbWindow::setNetWmState(const QVector<xcb_atom_t> &atoms)
676 if (atoms.isEmpty()) {
677 Q_XCB_CALL(xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_STATE)));
679 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
680 atom(QXcbAtom::_NET_WM_STATE), XCB_ATOM_ATOM, 32,
681 atoms.count(), atoms.constData()));
683 xcb_flush(xcb_connection());
687 Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
689 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
691 if (type == Qt::ToolTip)
692 flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint;
693 if (type == Qt::Popup)
694 flags |= Qt::X11BypassWindowManagerHint;
696 if (flags & Qt::WindowTransparentForInput) {
697 uint32_t mask = XCB_EVENT_MASK_NO_EVENT;
698 xcb_change_window_attributes(xcb_connection(), xcb_window(), XCB_CW_EVENT_MASK, &mask);
701 setNetWmWindowFlags(flags);
702 setMotifWindowFlags(flags);
704 setTransparentForMouseEvents(flags & Qt::WindowTransparentForInput);
709 void QXcbWindow::setMotifWindowFlags(Qt::WindowFlags flags)
711 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
713 QtMotifWmHints mwmhints;
715 mwmhints.functions = 0L;
716 mwmhints.decorations = 0;
717 mwmhints.input_mode = 0L;
718 mwmhints.status = 0L;
720 if (type != Qt::SplashScreen) {
721 mwmhints.flags |= MWM_HINTS_DECORATIONS;
723 bool customize = flags & Qt::CustomizeWindowHint;
724 if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
725 mwmhints.decorations |= MWM_DECOR_BORDER;
726 mwmhints.decorations |= MWM_DECOR_RESIZEH;
728 if (flags & Qt::WindowTitleHint)
729 mwmhints.decorations |= MWM_DECOR_TITLE;
731 if (flags & Qt::WindowSystemMenuHint)
732 mwmhints.decorations |= MWM_DECOR_MENU;
734 if (flags & Qt::WindowMinimizeButtonHint) {
735 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
736 mwmhints.functions |= MWM_FUNC_MINIMIZE;
739 if (flags & Qt::WindowMaximizeButtonHint) {
740 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
741 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
744 if (flags & Qt::WindowCloseButtonHint)
745 mwmhints.functions |= MWM_FUNC_CLOSE;
748 // if type == Qt::SplashScreen
749 mwmhints.decorations = MWM_DECOR_ALL;
752 if (mwmhints.functions != 0) {
753 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
754 mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
756 mwmhints.functions = MWM_FUNC_ALL;
759 if (!(flags & Qt::FramelessWindowHint)
760 && flags & Qt::CustomizeWindowHint
761 && flags & Qt::WindowTitleHint
763 (Qt::WindowMinimizeButtonHint
764 | Qt::WindowMaximizeButtonHint
765 | Qt::WindowCloseButtonHint)))
767 // a special case - only the titlebar without any button
768 mwmhints.flags = MWM_HINTS_FUNCTIONS;
769 mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
770 mwmhints.decorations = 0;
773 setMotifWmHints(connection(), m_window, mwmhints);
776 void QXcbWindow::changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two)
778 xcb_client_message_event_t event;
780 event.response_type = XCB_CLIENT_MESSAGE;
782 event.window = m_window;
783 event.type = atom(QXcbAtom::_NET_WM_STATE);
784 event.data.data32[0] = set ? 1 : 0;
785 event.data.data32[1] = one;
786 event.data.data32[2] = two;
787 event.data.data32[3] = 0;
788 event.data.data32[4] = 0;
790 Q_XCB_CALL(xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
793 Qt::WindowState QXcbWindow::setWindowState(Qt::WindowState state)
795 if (state == m_windowState)
799 switch (m_windowState) {
800 case Qt::WindowMinimized:
801 Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
803 case Qt::WindowMaximized:
804 changeNetWmState(false,
805 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
806 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
808 case Qt::WindowFullScreen:
809 changeNetWmState(false, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
817 case Qt::WindowMinimized:
819 xcb_client_message_event_t event;
821 event.response_type = XCB_CLIENT_MESSAGE;
823 event.window = m_window;
824 event.type = atom(QXcbAtom::WM_CHANGE_STATE);
825 event.data.data32[0] = XCB_WM_STATE_ICONIC;
826 event.data.data32[1] = 0;
827 event.data.data32[2] = 0;
828 event.data.data32[3] = 0;
829 event.data.data32[4] = 0;
831 Q_XCB_CALL(xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
834 case Qt::WindowMaximized:
835 changeNetWmState(true,
836 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
837 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
839 case Qt::WindowFullScreen:
840 changeNetWmState(true, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
842 case Qt::WindowNoState:
848 connection()->sync();
850 m_windowState = state;
851 return m_windowState;
854 void QXcbWindow::setNetWmWindowFlags(Qt::WindowFlags flags)
856 // in order of decreasing priority
857 QVector<uint> windowTypes;
859 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
864 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_DIALOG));
868 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_UTILITY));
871 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_TOOLTIP));
873 case Qt::SplashScreen:
874 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_SPLASH));
880 if (flags & Qt::FramelessWindowHint)
881 windowTypes.append(atom(QXcbAtom::_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
883 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_NORMAL));
885 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
886 atom(QXcbAtom::_NET_WM_WINDOW_TYPE), XCB_ATOM_ATOM, 32,
887 windowTypes.count(), windowTypes.constData()));
890 void QXcbWindow::updateMotifWmHintsBeforeMap()
892 QtMotifWmHints mwmhints = getMotifWmHints(connection(), m_window);
894 if (window()->windowModality() != Qt::NonModal) {
895 switch (window()->windowModality()) {
896 case Qt::WindowModal:
897 mwmhints.input_mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL;
899 case Qt::ApplicationModal:
901 mwmhints.input_mode = MWM_INPUT_FULL_APPLICATION_MODAL;
904 mwmhints.flags |= MWM_HINTS_INPUT_MODE;
906 mwmhints.input_mode = MWM_INPUT_MODELESS;
907 mwmhints.flags &= ~MWM_HINTS_INPUT_MODE;
910 if (window()->minimumSize() == window()->maximumSize()) {
911 // fixed size, remove the resize handle (since mwm/dtwm
912 // isn't smart enough to do it itself)
913 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
914 if (mwmhints.functions == MWM_FUNC_ALL) {
915 mwmhints.functions = MWM_FUNC_MOVE;
917 mwmhints.functions &= ~MWM_FUNC_RESIZE;
920 if (mwmhints.decorations == MWM_DECOR_ALL) {
921 mwmhints.flags |= MWM_HINTS_DECORATIONS;
922 mwmhints.decorations = (MWM_DECOR_BORDER
926 mwmhints.decorations &= ~MWM_DECOR_RESIZEH;
930 if (window()->windowFlags() & Qt::WindowMinimizeButtonHint) {
931 mwmhints.flags |= MWM_HINTS_DECORATIONS;
932 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
933 mwmhints.functions |= MWM_FUNC_MINIMIZE;
935 if (window()->windowFlags() & Qt::WindowMaximizeButtonHint) {
936 mwmhints.flags |= MWM_HINTS_DECORATIONS;
937 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
938 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
940 if (window()->windowFlags() & Qt::WindowCloseButtonHint)
941 mwmhints.functions |= MWM_FUNC_CLOSE;
943 setMotifWmHints(connection(), m_window, mwmhints);
946 void QXcbWindow::updateNetWmStateBeforeMap()
948 QVector<xcb_atom_t> netWmState;
950 Qt::WindowFlags flags = window()->windowFlags();
951 if (flags & Qt::WindowStaysOnTopHint) {
952 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_ABOVE));
953 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_STAYS_ON_TOP));
954 } else if (flags & Qt::WindowStaysOnBottomHint) {
955 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_BELOW));
958 if (window()->windowState() & Qt::WindowFullScreen) {
959 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
962 if (window()->windowState() & Qt::WindowMaximized) {
963 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ));
964 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
967 if (window()->windowModality() != Qt::NonModal) {
968 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MODAL));
971 setNetWmState(netWmState);
974 void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
976 xcb_window_t wid = m_window;
978 const bool isSupportedByWM = connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
979 if (m_netWmUserTimeWindow || isSupportedByWM) {
980 if (!m_netWmUserTimeWindow) {
981 m_netWmUserTimeWindow = xcb_generate_id(xcb_connection());
982 Q_XCB_CALL(xcb_create_window(xcb_connection(),
983 XCB_COPY_FROM_PARENT, // depth -- same as root
984 m_netWmUserTimeWindow, // window id
985 m_window, // parent window id
988 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
989 m_visualId, // visual
992 wid = m_netWmUserTimeWindow;
993 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW),
994 XCB_ATOM_WINDOW, 32, 1, &m_netWmUserTimeWindow);
995 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME));
996 } else if (!isSupportedByWM) {
997 // WM no longer supports it, then we should remove the
998 // _NET_WM_USER_TIME_WINDOW atom.
999 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
1000 xcb_destroy_window(xcb_connection(), m_netWmUserTimeWindow);
1001 m_netWmUserTimeWindow = XCB_NONE;
1003 wid = m_netWmUserTimeWindow;
1006 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::_NET_WM_USER_TIME),
1007 XCB_ATOM_CARDINAL, 32, 1, ×tamp);
1010 void QXcbWindow::setTransparentForMouseEvents(bool transparent)
1012 if (transparent == m_transparent)
1015 xcb_rectangle_t rectangle;
1017 xcb_rectangle_t *rect = 0;
1023 rectangle.width = geometry().width();
1024 rectangle.height = geometry().height();
1029 xcb_xfixes_region_t region = xcb_generate_id(xcb_connection());
1030 xcb_xfixes_create_region(xcb_connection(), region, nrect, rect);
1031 xcb_xfixes_set_window_shape_region_checked(xcb_connection(), m_window, XCB_SHAPE_SK_INPUT, 0, 0, region);
1032 xcb_xfixes_destroy_region(xcb_connection(), region);
1034 m_transparent = transparent;
1038 WId QXcbWindow::winId() const
1043 void QXcbWindow::setParent(const QPlatformWindow *parent)
1045 // re-create for compatibility
1048 QPoint topLeft = geometry().topLeft();
1050 xcb_window_t xcb_parent_id = parent ? static_cast<const QXcbWindow *>(parent)->xcb_window() : m_screen->root();
1051 Q_XCB_CALL(xcb_reparent_window(xcb_connection(), xcb_window(), xcb_parent_id, topLeft.x(), topLeft.y()));
1054 void QXcbWindow::setWindowTitle(const QString &title)
1056 QByteArray ba = title.toUtf8();
1057 Q_XCB_CALL(xcb_change_property(xcb_connection(),
1058 XCB_PROP_MODE_REPLACE,
1060 atom(QXcbAtom::_NET_WM_NAME),
1061 atom(QXcbAtom::UTF8_STRING),
1067 void QXcbWindow::raise()
1069 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1070 const quint32 values[] = { XCB_STACK_MODE_ABOVE };
1071 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
1074 void QXcbWindow::lower()
1076 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1077 const quint32 values[] = { XCB_STACK_MODE_BELOW };
1078 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
1081 void QXcbWindow::propagateSizeHints()
1083 // update WM_NORMAL_HINTS
1084 xcb_size_hints_t hints;
1085 memset(&hints, 0, sizeof(hints));
1087 QRect rect = geometry();
1089 QWindow *win = window();
1091 xcb_size_hints_set_position(&hints, true, rect.x(), rect.y());
1092 xcb_size_hints_set_size(&hints, true, rect.width(), rect.height());
1093 xcb_size_hints_set_win_gravity(&hints, qt_window_private(win)->positionPolicy == QWindowPrivate::WindowFrameInclusive
1094 ? XCB_GRAVITY_NORTH_WEST : XCB_GRAVITY_STATIC);
1096 QSize minimumSize = win->minimumSize();
1097 QSize maximumSize = win->maximumSize();
1098 QSize baseSize = win->baseSize();
1099 QSize sizeIncrement = win->sizeIncrement();
1101 if (minimumSize.width() > 0 || minimumSize.height() > 0)
1102 xcb_size_hints_set_min_size(&hints, minimumSize.width(), minimumSize.height());
1104 if (maximumSize.width() < QWINDOWSIZE_MAX || maximumSize.height() < QWINDOWSIZE_MAX)
1105 xcb_size_hints_set_max_size(&hints,
1106 qMin(XCOORD_MAX, maximumSize.width()),
1107 qMin(XCOORD_MAX, maximumSize.height()));
1109 if (sizeIncrement.width() > 0 || sizeIncrement.height() > 0) {
1110 xcb_size_hints_set_base_size(&hints, baseSize.width(), baseSize.height());
1111 xcb_size_hints_set_resize_inc(&hints, sizeIncrement.width(), sizeIncrement.height());
1114 xcb_set_wm_normal_hints(xcb_connection(), m_window, &hints);
1117 void QXcbWindow::requestActivateWindow()
1120 updateNetWmUserTime(connection()->time());
1121 Q_XCB_CALL(xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, connection()->time()));
1123 connection()->sync();
1126 QSurfaceFormat QXcbWindow::format() const
1128 // ### return actual format
1129 return m_requestedFormat;
1132 #if defined(XCB_USE_EGL)
1133 QXcbEGLSurface *QXcbWindow::eglSurface() const
1135 if (!m_eglSurface) {
1136 EGLDisplay display = connection()->egl_display();
1137 EGLConfig config = q_configFromGLFormat(display, window()->format(), true);
1138 EGLSurface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_window, 0);
1140 m_eglSurface = new QXcbEGLSurface(display, surface);
1143 return m_eglSurface;
1147 void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
1149 QRect rect(event->x, event->y, event->width, event->height);
1151 if (m_exposeRegion.isEmpty())
1152 m_exposeRegion = rect;
1154 m_exposeRegion |= rect;
1156 // if count is non-zero there are more expose events pending
1157 if (event->count == 0) {
1158 QWindowSystemInterface::handleSynchronousExposeEvent(window(), m_exposeRegion);
1159 m_exposeRegion = QRegion();
1163 void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event)
1165 if (event->format != 32)
1168 if (event->type == atom(QXcbAtom::WM_PROTOCOLS)) {
1169 if (event->data.data32[0] == atom(QXcbAtom::WM_DELETE_WINDOW)) {
1170 QWindowSystemInterface::handleCloseEvent(window());
1171 } else if (event->data.data32[0] == atom(QXcbAtom::WM_TAKE_FOCUS)) {
1172 connection()->setTime(event->data.data32[1]);
1173 } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_PING)) {
1174 xcb_client_message_event_t reply = *event;
1176 reply.response_type = XCB_CLIENT_MESSAGE;
1177 reply.window = m_screen->root();
1179 xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&reply);
1180 xcb_flush(xcb_connection());
1181 } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_SYNC_REQUEST)) {
1182 connection()->setTime(event->data.data32[1]);
1183 m_syncValue.lo = event->data.data32[2];
1184 m_syncValue.hi = event->data.data32[3];
1186 qWarning() << "unhandled WM_PROTOCOLS message:" << connection()->atomName(event->data.data32[0]);
1188 } else if (event->type == atom(QXcbAtom::XdndEnter)) {
1189 connection()->drag()->handleEnter(window(), event);
1190 } else if (event->type == atom(QXcbAtom::XdndPosition)) {
1191 connection()->drag()->handlePosition(window(), event, false);
1192 } else if (event->type == atom(QXcbAtom::XdndLeave)) {
1193 connection()->drag()->handleLeave(window(), event, false);
1194 } else if (event->type == atom(QXcbAtom::XdndDrop)) {
1195 connection()->drag()->handleDrop(window(), event, false);
1197 qWarning() << "unhandled client message:" << connection()->atomName(event->type);
1201 void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event)
1203 QRect rect(event->x, event->y, event->width, event->height);
1205 QPlatformWindow::setGeometry(rect);
1206 QWindowSystemInterface::handleGeometryChange(window(), rect);
1208 m_dirtyFrameMargins = true;
1212 static_cast<QDri2Context *>(m_context)->resize(rect.size());
1216 void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event)
1218 if (event->window == m_window) {
1220 QWindowSystemInterface::handleMapEvent(window());
1224 void QXcbWindow::handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event)
1226 if (event->window == m_window) {
1228 QWindowSystemInterface::handleUnmapEvent(window());
1232 static Qt::MouseButtons translateMouseButtons(int s)
1234 Qt::MouseButtons ret = 0;
1235 if (s & XCB_BUTTON_MASK_1)
1236 ret |= Qt::LeftButton;
1237 if (s & XCB_BUTTON_MASK_2)
1238 ret |= Qt::MidButton;
1239 if (s & XCB_BUTTON_MASK_3)
1240 ret |= Qt::RightButton;
1244 static Qt::MouseButton translateMouseButton(xcb_button_t s)
1248 return Qt::LeftButton;
1250 return Qt::MidButton;
1252 return Qt::RightButton;
1254 return Qt::NoButton;
1258 void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
1260 updateNetWmUserTime(event->time);
1262 QPoint local(event->event_x, event->event_y);
1263 QPoint global(event->root_x, event->root_y);
1265 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1267 if (event->detail >= 4 && event->detail <= 7) {
1268 //logic borrowed from qapplication_x11.cpp
1269 int delta = 120 * ((event->detail == 4 || event->detail == 6) ? 1 : -1);
1270 bool hor = (((event->detail == 4 || event->detail == 5)
1271 && (modifiers & Qt::AltModifier))
1272 || (event->detail == 6 || event->detail == 7));
1274 QWindowSystemInterface::handleWheelEvent(window(), event->time,
1275 local, global, delta, hor ? Qt::Horizontal : Qt::Vertical, modifiers);
1279 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1282 void QXcbWindow::handleButtonReleaseEvent(const xcb_button_release_event_t *event)
1284 QPoint local(event->event_x, event->event_y);
1285 QPoint global(event->root_x, event->root_y);
1286 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1288 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1291 void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
1293 QPoint local(event->event_x, event->event_y);
1294 QPoint global(event->root_x, event->root_y);
1295 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1297 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1300 void QXcbWindow::handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global, Qt::KeyboardModifiers modifiers)
1302 connection()->setTime(time);
1304 Qt::MouseButtons buttons = translateMouseButtons(state);
1305 Qt::MouseButton button = translateMouseButton(detail);
1307 buttons ^= button; // X event uses state *before*, Qt uses state *after*
1309 QWindowSystemInterface::handleMouseEvent(window(), time, local, global, buttons, modifiers);
1312 void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
1314 connection()->setTime(event->time);
1316 if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
1317 || event->detail == XCB_NOTIFY_DETAIL_VIRTUAL
1318 || event->detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL)
1323 QWindowSystemInterface::handleEnterEvent(window());
1326 void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
1328 connection()->setTime(event->time);
1330 if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
1331 || event->detail == XCB_NOTIFY_DETAIL_INFERIOR)
1336 QWindowSystemInterface::handleLeaveEvent(window());
1339 void QXcbWindow::handlePropertyNotifyEvent(const xcb_property_notify_event_t *event)
1341 connection()->setTime(event->time);
1343 bool propertyDeleted = event->state == XCB_PROPERTY_DELETE;
1345 if (event->atom == atom(QXcbAtom::_NET_WM_STATE) || event->atom == atom(QXcbAtom::WM_STATE)) {
1346 if (propertyDeleted)
1349 xcb_get_property_cookie_t get_cookie =
1350 xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::WM_STATE),
1351 XCB_ATOM_ANY, 0, 1024);
1353 xcb_generic_error_t *error;
1355 xcb_get_property_reply_t *reply =
1356 xcb_get_property_reply(xcb_connection(), get_cookie, &error);
1358 xcb_atom_t wm_state = XCB_WM_STATE_WITHDRAWN;
1359 if (reply && reply->format == 32 && reply->type == atom(QXcbAtom::WM_STATE)) {
1360 if (reply->length != 0)
1361 wm_state = ((long *)xcb_get_property_value(reply))[0];
1364 connection()->handleXcbError(error);
1368 QVector<xcb_atom_t> netWmState = getNetWmState();
1370 bool maximized = netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ))
1371 && netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
1372 bool fullscreen = netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
1374 Qt::WindowState state = Qt::WindowNoState;
1375 if (wm_state == XCB_WM_STATE_ICONIC)
1376 state = Qt::WindowMinimized;
1378 state = Qt::WindowMaximized;
1379 else if (fullscreen)
1380 state = Qt::WindowFullScreen;
1382 QWindowSystemInterface::handleWindowStateChanged(window(), state);
1386 void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *)
1388 QWindowSystemInterface::handleWindowActivated(window());
1391 static bool focusInPeeker(xcb_generic_event_t *event)
1394 // FocusIn event is not in the queue, proceed with FocusOut normally.
1395 QWindowSystemInterface::handleWindowActivated(0);
1398 uint response_type = event->response_type & ~0x80;
1399 return response_type == XCB_FOCUS_IN;
1402 void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *)
1404 // Do not set the active window to 0 if there is a FocusIn coming.
1405 // There is however no equivalent for XPutBackEvent so register a
1406 // callback for QXcbConnection instead.
1407 connection()->addPeekFunc(focusInPeeker);
1410 void QXcbWindow::updateSyncRequestCounter()
1412 if (m_screen->syncRequestSupported() && (m_syncValue.lo != 0 || m_syncValue.hi != 0)) {
1413 Q_XCB_CALL(xcb_sync_set_counter(xcb_connection(), m_syncCounter, m_syncValue));
1414 xcb_flush(xcb_connection());
1415 connection()->sync();
1422 bool QXcbWindow::setKeyboardGrabEnabled(bool grab)
1425 xcb_ungrab_keyboard(xcb_connection(), XCB_TIME_CURRENT_TIME);
1428 xcb_grab_keyboard_cookie_t cookie = xcb_grab_keyboard(xcb_connection(), false,
1429 m_window, XCB_TIME_CURRENT_TIME,
1430 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
1431 xcb_generic_error_t *err;
1432 xcb_grab_keyboard_reply_t *reply = xcb_grab_keyboard_reply(xcb_connection(), cookie, &err);
1433 bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
1439 bool QXcbWindow::setMouseGrabEnabled(bool grab)
1442 xcb_ungrab_pointer(xcb_connection(), XCB_TIME_CURRENT_TIME);
1445 xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer(xcb_connection(), false, m_window,
1446 (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
1447 | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_ENTER_WINDOW
1448 | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION),
1449 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
1450 XCB_WINDOW_NONE, XCB_CURSOR_NONE,
1451 XCB_TIME_CURRENT_TIME);
1452 xcb_generic_error_t *err;
1453 xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(xcb_connection(), cookie, &err);
1454 bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
1460 void QXcbWindow::setCursor(xcb_cursor_t cursor)
1462 xcb_change_window_attributes(xcb_connection(), m_window, XCB_CW_CURSOR, &cursor);
1463 xcb_flush(xcb_connection());