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());
233 m_window = XCreateWindow(DISPLAY_FROM_XCB(this), xcb_parent_id, rect.x(), rect.y(), rect.width(), rect.height(),
234 0, visualInfo->depth, InputOutput, visualInfo->visual,
235 CWBackPixel|CWBorderPixel|CWColormap, &a);
237 qFatal("no window!");
240 #endif //defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
242 m_window = xcb_generate_id(xcb_connection());
243 m_depth = m_screen->screen()->root_depth;
244 m_imageFormat = imageFormatForDepth(m_depth);
246 Q_XCB_CALL(xcb_create_window(xcb_connection(),
247 XCB_COPY_FROM_PARENT, // depth -- same as root
248 m_window, // window id
249 xcb_parent_id, // parent window id
255 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
256 m_screen->screen()->root_visual, // visual
261 connection()->addWindow(m_window, this);
263 Q_XCB_CALL(xcb_change_window_attributes(xcb_connection(), m_window, mask, values));
265 propagateSizeHints();
267 xcb_atom_t properties[4];
268 int propertyCount = 0;
269 properties[propertyCount++] = atom(QXcbAtom::WM_DELETE_WINDOW);
270 properties[propertyCount++] = atom(QXcbAtom::WM_TAKE_FOCUS);
271 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_PING);
273 if (m_screen->syncRequestSupported())
274 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_SYNC_REQUEST);
276 if (window()->windowFlags() & Qt::WindowContextHelpButtonHint)
277 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_CONTEXT_HELP);
279 Q_XCB_CALL(xcb_change_property(xcb_connection(),
280 XCB_PROP_MODE_REPLACE,
282 atom(QXcbAtom::WM_PROTOCOLS),
290 if (m_screen->syncRequestSupported()) {
291 m_syncCounter = xcb_generate_id(xcb_connection());
292 Q_XCB_CALL(xcb_sync_create_counter(xcb_connection(), m_syncCounter, m_syncValue));
294 Q_XCB_CALL(xcb_change_property(xcb_connection(),
295 XCB_PROP_MODE_REPLACE,
297 atom(QXcbAtom::_NET_WM_SYNC_REQUEST_COUNTER),
304 // set the PID to let the WM kill the application if unresponsive
306 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
307 atom(QXcbAtom::_NET_WM_PID), XCB_ATOM_CARDINAL, 32,
310 xcb_wm_hints_t hints;
311 memset(&hints, 0, sizeof(hints));
312 xcb_wm_hints_set_normal(&hints);
314 xcb_set_wm_hints(xcb_connection(), m_window, &hints);
316 xcb_window_t leader = m_screen->clientLeader();
317 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
318 atom(QXcbAtom::WM_CLIENT_LEADER), XCB_ATOM_WINDOW, 32,
321 setWindowFlags(window()->windowFlags());
322 setWindowTitle(window()->windowTitle());
323 setWindowState(window()->windowState());
325 if (window()->windowFlags() & Qt::WindowTransparentForInput)
326 setTransparentForMouseEvents(true);
328 connection()->drag()->dndEnable(this, true);
331 QXcbWindow::~QXcbWindow()
336 void QXcbWindow::destroy()
338 if (m_syncCounter && m_screen->syncRequestSupported())
339 Q_XCB_CALL(xcb_sync_destroy_counter(xcb_connection(), m_syncCounter));
341 connection()->removeWindow(m_window);
342 Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window));
346 #if defined(XCB_USE_EGL)
352 void QXcbWindow::setGeometry(const QRect &rect)
354 QPlatformWindow::setGeometry(rect);
356 propagateSizeHints();
358 const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
359 const quint32 values[] = { rect.x(),
361 qBound(1, rect.width(), XCOORD_MAX),
362 qBound(1, rect.height(), XCOORD_MAX) };
364 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
366 xcb_flush(xcb_connection());
369 QMargins QXcbWindow::frameMargins() const
371 if (m_dirtyFrameMargins) {
372 xcb_window_t window = m_window;
373 xcb_window_t parent = m_window;
375 bool foundRoot = false;
377 const QVector<xcb_window_t> &virtualRoots =
378 connection()->wmSupport()->virtualRoots();
381 xcb_query_tree_cookie_t cookie = xcb_query_tree(xcb_connection(), parent);
383 xcb_generic_error_t *error;
384 xcb_query_tree_reply_t *reply = xcb_query_tree_reply(xcb_connection(), cookie, &error);
386 if (reply->root == reply->parent || virtualRoots.indexOf(reply->parent) != -1) {
390 parent = reply->parent;
396 connection()->handleXcbError(error);
400 m_dirtyFrameMargins = false;
401 m_frameMargins = QMargins();
402 return m_frameMargins;
408 xcb_generic_error_t *error;
409 xcb_translate_coordinates_reply_t *reply =
410 xcb_translate_coordinates_reply(
412 xcb_translate_coordinates(xcb_connection(), window, parent, 0, 0),
416 offset = QPoint(reply->dst_x, reply->dst_y);
422 xcb_get_geometry_reply_t *geom =
423 xcb_get_geometry_reply(
425 xcb_get_geometry(xcb_connection(), parent),
430 // add the border_width for the window managers frame... some window managers
431 // do not use a border_width of zero for their frames, and if we the left and
432 // top strut, we ensure that pos() is absolutely correct. frameGeometry()
433 // will still be incorrect though... perhaps i should have foffset as well, to
434 // indicate the frame offset (equal to the border_width on X).
436 // -- copied from qwidget_x11.cpp
438 int left = offset.x() + geom->border_width;
439 int top = offset.y() + geom->border_width;
440 int right = geom->width + geom->border_width - geometry().width() - offset.x();
441 int bottom = geom->height + geom->border_width - geometry().height() - offset.y();
443 m_frameMargins = QMargins(left, top, right, bottom);
450 m_dirtyFrameMargins = false;
453 return m_frameMargins;
456 void QXcbWindow::setVisible(bool visible)
464 void QXcbWindow::show()
466 if (window()->isTopLevel()) {
467 xcb_get_property_cookie_t cookie = xcb_get_wm_hints(xcb_connection(), m_window);
469 xcb_generic_error_t *error;
471 xcb_wm_hints_t hints;
472 xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, &error);
475 connection()->handleXcbError(error);
479 if (window()->windowState() & Qt::WindowMinimized)
480 xcb_wm_hints_set_iconic(&hints);
482 xcb_wm_hints_set_normal(&hints);
484 xcb_set_wm_hints(xcb_connection(), m_window, &hints);
486 // update WM_NORMAL_HINTS
487 propagateSizeHints();
489 // update WM_TRANSIENT_FOR
490 if (window()->transientParent() && isTransient(window())) {
491 QXcbWindow *transientXcbParent = static_cast<QXcbWindow *>(window()->transientParent()->handle());
492 if (transientXcbParent) {
494 xcb_window_t parentWindow = transientXcbParent->xcb_window();
496 // todo: set transient for group (wm_client_leader) if no parent, a la qwidget_x11.cpp
497 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
498 XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
503 // update _MOTIF_WM_HINTS
504 updateMotifWmHintsBeforeMap();
506 // update _NET_WM_STATE
507 updateNetWmStateBeforeMap();
510 Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
511 xcb_flush(xcb_connection());
513 connection()->sync();
516 void QXcbWindow::hide()
518 Q_XCB_CALL(xcb_unmap_window(xcb_connection(), m_window));
520 // send synthetic UnmapNotify event according to icccm 4.1.4
521 xcb_unmap_notify_event_t event;
522 event.response_type = XCB_UNMAP_NOTIFY;
523 event.event = m_screen->root();
524 event.window = m_window;
525 event.from_configure = false;
526 Q_XCB_CALL(xcb_send_event(xcb_connection(), false, m_screen->root(),
527 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
529 xcb_flush(xcb_connection());
534 struct QtMotifWmHints {
535 quint32 flags, functions, decorations;
541 MWM_HINTS_FUNCTIONS = (1L << 0),
543 MWM_FUNC_ALL = (1L << 0),
544 MWM_FUNC_RESIZE = (1L << 1),
545 MWM_FUNC_MOVE = (1L << 2),
546 MWM_FUNC_MINIMIZE = (1L << 3),
547 MWM_FUNC_MAXIMIZE = (1L << 4),
548 MWM_FUNC_CLOSE = (1L << 5),
550 MWM_HINTS_DECORATIONS = (1L << 1),
552 MWM_DECOR_ALL = (1L << 0),
553 MWM_DECOR_BORDER = (1L << 1),
554 MWM_DECOR_RESIZEH = (1L << 2),
555 MWM_DECOR_TITLE = (1L << 3),
556 MWM_DECOR_MENU = (1L << 4),
557 MWM_DECOR_MINIMIZE = (1L << 5),
558 MWM_DECOR_MAXIMIZE = (1L << 6),
560 MWM_HINTS_INPUT_MODE = (1L << 2),
562 MWM_INPUT_MODELESS = 0L,
563 MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L,
564 MWM_INPUT_FULL_APPLICATION_MODAL = 3L
567 static QtMotifWmHints getMotifWmHints(QXcbConnection *c, xcb_window_t window)
569 QtMotifWmHints hints;
571 xcb_get_property_cookie_t get_cookie =
572 xcb_get_property(c->xcb_connection(), 0, window, c->atom(QXcbAtom::_MOTIF_WM_HINTS),
573 c->atom(QXcbAtom::_MOTIF_WM_HINTS), 0, 20);
575 xcb_generic_error_t *error;
577 xcb_get_property_reply_t *reply =
578 xcb_get_property_reply(c->xcb_connection(), get_cookie, &error);
580 if (reply && reply->format == 32 && reply->type == c->atom(QXcbAtom::_MOTIF_WM_HINTS)) {
581 hints = *((QtMotifWmHints *)xcb_get_property_value(reply));
583 c->handleXcbError(error);
587 hints.functions = MWM_FUNC_ALL;
588 hints.decorations = MWM_DECOR_ALL;
589 hints.input_mode = 0L;
598 static void setMotifWmHints(QXcbConnection *c, xcb_window_t window, const QtMotifWmHints &hints)
600 if (hints.flags != 0l) {
601 Q_XCB_CALL2(xcb_change_property(c->xcb_connection(),
602 XCB_PROP_MODE_REPLACE,
604 c->atom(QXcbAtom::_MOTIF_WM_HINTS),
605 c->atom(QXcbAtom::_MOTIF_WM_HINTS),
610 Q_XCB_CALL2(xcb_delete_property(c->xcb_connection(), window, c->atom(QXcbAtom::_MOTIF_WM_HINTS)), c);
614 void QXcbWindow::printNetWmState(const QVector<xcb_atom_t> &state)
616 printf("_NET_WM_STATE (%d): ", state.size());
617 for (int i = 0; i < state.size(); ++i) {
618 #define CHECK_WM_STATE(state_atom) \
619 if (state.at(i) == atom(QXcbAtom::state_atom))\
620 printf(#state_atom " ");
621 CHECK_WM_STATE(_NET_WM_STATE_ABOVE)
622 CHECK_WM_STATE(_NET_WM_STATE_BELOW)
623 CHECK_WM_STATE(_NET_WM_STATE_FULLSCREEN)
624 CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_HORZ)
625 CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_VERT)
626 CHECK_WM_STATE(_NET_WM_STATE_MODAL)
627 CHECK_WM_STATE(_NET_WM_STATE_STAYS_ON_TOP)
628 CHECK_WM_STATE(_NET_WM_STATE_DEMANDS_ATTENTION)
629 #undef CHECK_WM_STATE
634 QVector<xcb_atom_t> QXcbWindow::getNetWmState()
636 QVector<xcb_atom_t> result;
638 xcb_get_property_cookie_t get_cookie =
639 xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::_NET_WM_STATE),
640 XCB_ATOM_ATOM, 0, 1024);
642 xcb_generic_error_t *error;
644 xcb_get_property_reply_t *reply =
645 xcb_get_property_reply(xcb_connection(), get_cookie, &error);
647 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) {
648 result.resize(reply->length);
650 memcpy(result.data(), xcb_get_property_value(reply), reply->length * sizeof(xcb_atom_t));
652 #ifdef NET_WM_STATE_DEBUG
653 printf("getting net wm state (%x)\n", m_window);
654 printNetWmState(result);
659 connection()->handleXcbError(error);
662 #ifdef NET_WM_STATE_DEBUG
663 printf("getting net wm state (%x), empty\n", m_window);
670 void QXcbWindow::setNetWmState(const QVector<xcb_atom_t> &atoms)
672 if (atoms.isEmpty()) {
673 Q_XCB_CALL(xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_STATE)));
675 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
676 atom(QXcbAtom::_NET_WM_STATE), XCB_ATOM_ATOM, 32,
677 atoms.count(), atoms.constData()));
679 xcb_flush(xcb_connection());
683 Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
685 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
687 if (type == Qt::ToolTip)
688 flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint;
689 if (type == Qt::Popup)
690 flags |= Qt::X11BypassWindowManagerHint;
692 if (flags & Qt::WindowTransparentForInput) {
693 uint32_t mask = XCB_EVENT_MASK_NO_EVENT;
694 xcb_change_window_attributes(xcb_connection(), xcb_window(), XCB_CW_EVENT_MASK, &mask);
697 setNetWmWindowFlags(flags);
698 setMotifWindowFlags(flags);
700 setTransparentForMouseEvents(flags & Qt::WindowTransparentForInput);
705 void QXcbWindow::setMotifWindowFlags(Qt::WindowFlags flags)
707 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
709 QtMotifWmHints mwmhints;
711 mwmhints.functions = 0L;
712 mwmhints.decorations = 0;
713 mwmhints.input_mode = 0L;
714 mwmhints.status = 0L;
716 if (type != Qt::SplashScreen) {
717 mwmhints.flags |= MWM_HINTS_DECORATIONS;
719 bool customize = flags & Qt::CustomizeWindowHint;
720 if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
721 mwmhints.decorations |= MWM_DECOR_BORDER;
722 mwmhints.decorations |= MWM_DECOR_RESIZEH;
724 if (flags & Qt::WindowTitleHint)
725 mwmhints.decorations |= MWM_DECOR_TITLE;
727 if (flags & Qt::WindowSystemMenuHint)
728 mwmhints.decorations |= MWM_DECOR_MENU;
730 if (flags & Qt::WindowMinimizeButtonHint) {
731 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
732 mwmhints.functions |= MWM_FUNC_MINIMIZE;
735 if (flags & Qt::WindowMaximizeButtonHint) {
736 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
737 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
740 if (flags & Qt::WindowCloseButtonHint)
741 mwmhints.functions |= MWM_FUNC_CLOSE;
744 // if type == Qt::SplashScreen
745 mwmhints.decorations = MWM_DECOR_ALL;
748 if (mwmhints.functions != 0) {
749 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
750 mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
752 mwmhints.functions = MWM_FUNC_ALL;
755 if (!(flags & Qt::FramelessWindowHint)
756 && flags & Qt::CustomizeWindowHint
757 && flags & Qt::WindowTitleHint
759 (Qt::WindowMinimizeButtonHint
760 | Qt::WindowMaximizeButtonHint
761 | Qt::WindowCloseButtonHint)))
763 // a special case - only the titlebar without any button
764 mwmhints.flags = MWM_HINTS_FUNCTIONS;
765 mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
766 mwmhints.decorations = 0;
769 setMotifWmHints(connection(), m_window, mwmhints);
772 void QXcbWindow::changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two)
774 xcb_client_message_event_t event;
776 event.response_type = XCB_CLIENT_MESSAGE;
778 event.window = m_window;
779 event.type = atom(QXcbAtom::_NET_WM_STATE);
780 event.data.data32[0] = set ? 1 : 0;
781 event.data.data32[1] = one;
782 event.data.data32[2] = two;
783 event.data.data32[3] = 0;
784 event.data.data32[4] = 0;
786 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));
789 Qt::WindowState QXcbWindow::setWindowState(Qt::WindowState state)
791 if (state == m_windowState)
795 switch (m_windowState) {
796 case Qt::WindowMinimized:
797 Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
799 case Qt::WindowMaximized:
800 changeNetWmState(false,
801 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
802 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
804 case Qt::WindowFullScreen:
805 changeNetWmState(false, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
813 case Qt::WindowMinimized:
815 xcb_client_message_event_t event;
817 event.response_type = XCB_CLIENT_MESSAGE;
819 event.window = m_window;
820 event.type = atom(QXcbAtom::WM_CHANGE_STATE);
821 event.data.data32[0] = XCB_WM_STATE_ICONIC;
822 event.data.data32[1] = 0;
823 event.data.data32[2] = 0;
824 event.data.data32[3] = 0;
825 event.data.data32[4] = 0;
827 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));
830 case Qt::WindowMaximized:
831 changeNetWmState(true,
832 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
833 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
835 case Qt::WindowFullScreen:
836 changeNetWmState(true, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
838 case Qt::WindowNoState:
844 connection()->sync();
846 m_windowState = state;
847 return m_windowState;
850 void QXcbWindow::setNetWmWindowFlags(Qt::WindowFlags flags)
852 // in order of decreasing priority
853 QVector<uint> windowTypes;
855 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
860 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_DIALOG));
864 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_UTILITY));
867 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_TOOLTIP));
869 case Qt::SplashScreen:
870 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_SPLASH));
876 if (flags & Qt::FramelessWindowHint)
877 windowTypes.append(atom(QXcbAtom::_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
879 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_NORMAL));
881 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
882 atom(QXcbAtom::_NET_WM_WINDOW_TYPE), XCB_ATOM_ATOM, 32,
883 windowTypes.count(), windowTypes.constData()));
886 void QXcbWindow::updateMotifWmHintsBeforeMap()
888 QtMotifWmHints mwmhints = getMotifWmHints(connection(), m_window);
890 if (window()->windowModality() != Qt::NonModal) {
891 switch (window()->windowModality()) {
892 case Qt::WindowModal:
893 mwmhints.input_mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL;
895 case Qt::ApplicationModal:
897 mwmhints.input_mode = MWM_INPUT_FULL_APPLICATION_MODAL;
900 mwmhints.flags |= MWM_HINTS_INPUT_MODE;
902 mwmhints.input_mode = MWM_INPUT_MODELESS;
903 mwmhints.flags &= ~MWM_HINTS_INPUT_MODE;
906 if (window()->minimumSize() == window()->maximumSize()) {
907 // fixed size, remove the resize handle (since mwm/dtwm
908 // isn't smart enough to do it itself)
909 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
910 if (mwmhints.functions == MWM_FUNC_ALL) {
911 mwmhints.functions = MWM_FUNC_MOVE;
913 mwmhints.functions &= ~MWM_FUNC_RESIZE;
916 if (mwmhints.decorations == MWM_DECOR_ALL) {
917 mwmhints.flags |= MWM_HINTS_DECORATIONS;
918 mwmhints.decorations = (MWM_DECOR_BORDER
922 mwmhints.decorations &= ~MWM_DECOR_RESIZEH;
926 if (window()->windowFlags() & Qt::WindowMinimizeButtonHint) {
927 mwmhints.flags |= MWM_HINTS_DECORATIONS;
928 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
929 mwmhints.functions |= MWM_FUNC_MINIMIZE;
931 if (window()->windowFlags() & Qt::WindowMaximizeButtonHint) {
932 mwmhints.flags |= MWM_HINTS_DECORATIONS;
933 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
934 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
936 if (window()->windowFlags() & Qt::WindowCloseButtonHint)
937 mwmhints.functions |= MWM_FUNC_CLOSE;
939 setMotifWmHints(connection(), m_window, mwmhints);
942 void QXcbWindow::updateNetWmStateBeforeMap()
944 QVector<xcb_atom_t> netWmState;
946 Qt::WindowFlags flags = window()->windowFlags();
947 if (flags & Qt::WindowStaysOnTopHint) {
948 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_ABOVE));
949 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_STAYS_ON_TOP));
950 } else if (flags & Qt::WindowStaysOnBottomHint) {
951 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_BELOW));
954 if (window()->windowState() & Qt::WindowFullScreen) {
955 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
958 if (window()->windowState() & Qt::WindowMaximized) {
959 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ));
960 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
963 if (window()->windowModality() != Qt::NonModal) {
964 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MODAL));
967 setNetWmState(netWmState);
970 void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
972 xcb_window_t wid = m_window;
974 const bool isSupportedByWM = connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
975 if (m_netWmUserTimeWindow || isSupportedByWM) {
976 if (!m_netWmUserTimeWindow) {
977 m_netWmUserTimeWindow = xcb_generate_id(xcb_connection());
978 Q_XCB_CALL(xcb_create_window(xcb_connection(),
979 XCB_COPY_FROM_PARENT, // depth -- same as root
980 m_netWmUserTimeWindow, // window id
981 m_window, // parent window id
984 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
985 m_screen->screen()->root_visual, // visual
988 wid = m_netWmUserTimeWindow;
989 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW),
990 XCB_ATOM_WINDOW, 32, 1, &m_netWmUserTimeWindow);
991 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME));
992 } else if (!isSupportedByWM) {
993 // WM no longer supports it, then we should remove the
994 // _NET_WM_USER_TIME_WINDOW atom.
995 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
996 xcb_destroy_window(xcb_connection(), m_netWmUserTimeWindow);
997 m_netWmUserTimeWindow = XCB_NONE;
999 wid = m_netWmUserTimeWindow;
1002 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::_NET_WM_USER_TIME),
1003 XCB_ATOM_CARDINAL, 32, 1, ×tamp);
1006 void QXcbWindow::setTransparentForMouseEvents(bool transparent)
1008 if (transparent == m_transparent)
1011 xcb_rectangle_t rectangle;
1013 xcb_rectangle_t *rect = 0;
1019 rectangle.width = geometry().width();
1020 rectangle.height = geometry().height();
1025 xcb_xfixes_region_t region = xcb_generate_id(xcb_connection());
1026 xcb_xfixes_create_region(xcb_connection(), region, nrect, rect);
1027 xcb_xfixes_set_window_shape_region_checked(xcb_connection(), m_window, XCB_SHAPE_SK_INPUT, 0, 0, region);
1028 xcb_xfixes_destroy_region(xcb_connection(), region);
1030 m_transparent = transparent;
1034 WId QXcbWindow::winId() const
1039 void QXcbWindow::setParent(const QPlatformWindow *parent)
1041 // re-create for compatibility
1044 QPoint topLeft = geometry().topLeft();
1046 xcb_window_t xcb_parent_id = parent ? static_cast<const QXcbWindow *>(parent)->xcb_window() : m_screen->root();
1047 Q_XCB_CALL(xcb_reparent_window(xcb_connection(), xcb_window(), xcb_parent_id, topLeft.x(), topLeft.y()));
1050 void QXcbWindow::setWindowTitle(const QString &title)
1052 QByteArray ba = title.toUtf8();
1053 Q_XCB_CALL(xcb_change_property(xcb_connection(),
1054 XCB_PROP_MODE_REPLACE,
1056 atom(QXcbAtom::_NET_WM_NAME),
1057 atom(QXcbAtom::UTF8_STRING),
1063 void QXcbWindow::raise()
1065 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1066 const quint32 values[] = { XCB_STACK_MODE_ABOVE };
1067 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
1070 void QXcbWindow::lower()
1072 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1073 const quint32 values[] = { XCB_STACK_MODE_BELOW };
1074 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
1077 void QXcbWindow::propagateSizeHints()
1079 // update WM_NORMAL_HINTS
1080 xcb_size_hints_t hints;
1081 memset(&hints, 0, sizeof(hints));
1083 QRect rect = geometry();
1085 QWindow *win = window();
1087 xcb_size_hints_set_position(&hints, true, rect.x(), rect.y());
1088 xcb_size_hints_set_size(&hints, true, rect.width(), rect.height());
1089 xcb_size_hints_set_win_gravity(&hints, qt_window_private(win)->positionPolicy == QWindowPrivate::WindowFrameInclusive
1090 ? XCB_GRAVITY_NORTH_WEST : XCB_GRAVITY_STATIC);
1092 QSize minimumSize = win->minimumSize();
1093 QSize maximumSize = win->maximumSize();
1094 QSize baseSize = win->baseSize();
1095 QSize sizeIncrement = win->sizeIncrement();
1097 if (minimumSize.width() > 0 || minimumSize.height() > 0)
1098 xcb_size_hints_set_min_size(&hints, minimumSize.width(), minimumSize.height());
1100 if (maximumSize.width() < QWINDOWSIZE_MAX || maximumSize.height() < QWINDOWSIZE_MAX)
1101 xcb_size_hints_set_max_size(&hints,
1102 qMin(XCOORD_MAX, maximumSize.width()),
1103 qMin(XCOORD_MAX, maximumSize.height()));
1105 if (sizeIncrement.width() > 0 || sizeIncrement.height() > 0) {
1106 xcb_size_hints_set_base_size(&hints, baseSize.width(), baseSize.height());
1107 xcb_size_hints_set_resize_inc(&hints, sizeIncrement.width(), sizeIncrement.height());
1110 xcb_set_wm_normal_hints(xcb_connection(), m_window, &hints);
1113 void QXcbWindow::requestActivateWindow()
1116 updateNetWmUserTime(connection()->time());
1117 Q_XCB_CALL(xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, connection()->time()));
1119 connection()->sync();
1122 QSurfaceFormat QXcbWindow::format() const
1124 // ### return actual format
1125 return m_requestedFormat;
1128 #if defined(XCB_USE_EGL)
1129 QXcbEGLSurface *QXcbWindow::eglSurface() const
1131 if (!m_eglSurface) {
1132 EGLDisplay display = connection()->egl_display();
1133 EGLConfig config = q_configFromGLFormat(display, window()->format(), true);
1134 EGLSurface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_window, 0);
1136 m_eglSurface = new QXcbEGLSurface(display, surface);
1139 return m_eglSurface;
1143 void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
1145 QRect rect(event->x, event->y, event->width, event->height);
1147 if (m_exposeRegion.isEmpty())
1148 m_exposeRegion = rect;
1150 m_exposeRegion |= rect;
1152 // if count is non-zero there are more expose events pending
1153 if (event->count == 0) {
1154 QWindowSystemInterface::handleSynchronousExposeEvent(window(), m_exposeRegion);
1155 m_exposeRegion = QRegion();
1159 void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event)
1161 if (event->format != 32)
1164 if (event->type == atom(QXcbAtom::WM_PROTOCOLS)) {
1165 if (event->data.data32[0] == atom(QXcbAtom::WM_DELETE_WINDOW)) {
1166 QWindowSystemInterface::handleCloseEvent(window());
1167 } else if (event->data.data32[0] == atom(QXcbAtom::WM_TAKE_FOCUS)) {
1168 connection()->setTime(event->data.data32[1]);
1169 } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_PING)) {
1170 xcb_client_message_event_t reply = *event;
1172 reply.response_type = XCB_CLIENT_MESSAGE;
1173 reply.window = m_screen->root();
1175 xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&reply);
1176 xcb_flush(xcb_connection());
1177 } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_SYNC_REQUEST)) {
1178 connection()->setTime(event->data.data32[1]);
1179 m_syncValue.lo = event->data.data32[2];
1180 m_syncValue.hi = event->data.data32[3];
1182 qWarning() << "unhandled WM_PROTOCOLS message:" << connection()->atomName(event->data.data32[0]);
1184 } else if (event->type == atom(QXcbAtom::XdndEnter)) {
1185 connection()->drag()->handleEnter(window(), event);
1186 } else if (event->type == atom(QXcbAtom::XdndPosition)) {
1187 connection()->drag()->handlePosition(window(), event, false);
1188 } else if (event->type == atom(QXcbAtom::XdndLeave)) {
1189 connection()->drag()->handleLeave(window(), event, false);
1190 } else if (event->type == atom(QXcbAtom::XdndDrop)) {
1191 connection()->drag()->handleDrop(window(), event, false);
1193 qWarning() << "unhandled client message:" << connection()->atomName(event->type);
1197 void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event)
1199 QRect rect(event->x, event->y, event->width, event->height);
1201 QPlatformWindow::setGeometry(rect);
1202 QWindowSystemInterface::handleGeometryChange(window(), rect);
1204 m_dirtyFrameMargins = true;
1208 static_cast<QDri2Context *>(m_context)->resize(rect.size());
1212 void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event)
1214 if (event->window == m_window) {
1216 QWindowSystemInterface::handleMapEvent(window());
1220 void QXcbWindow::handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event)
1222 if (event->window == m_window) {
1224 QWindowSystemInterface::handleUnmapEvent(window());
1228 static Qt::MouseButtons translateMouseButtons(int s)
1230 Qt::MouseButtons ret = 0;
1231 if (s & XCB_BUTTON_MASK_1)
1232 ret |= Qt::LeftButton;
1233 if (s & XCB_BUTTON_MASK_2)
1234 ret |= Qt::MidButton;
1235 if (s & XCB_BUTTON_MASK_3)
1236 ret |= Qt::RightButton;
1240 static Qt::MouseButton translateMouseButton(xcb_button_t s)
1244 return Qt::LeftButton;
1246 return Qt::MidButton;
1248 return Qt::RightButton;
1250 return Qt::NoButton;
1254 void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
1256 updateNetWmUserTime(event->time);
1258 QPoint local(event->event_x, event->event_y);
1259 QPoint global(event->root_x, event->root_y);
1261 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1263 if (event->detail >= 4 && event->detail <= 7) {
1264 //logic borrowed from qapplication_x11.cpp
1265 int delta = 120 * ((event->detail == 4 || event->detail == 6) ? 1 : -1);
1266 bool hor = (((event->detail == 4 || event->detail == 5)
1267 && (modifiers & Qt::AltModifier))
1268 || (event->detail == 6 || event->detail == 7));
1270 QWindowSystemInterface::handleWheelEvent(window(), event->time,
1271 local, global, delta, hor ? Qt::Horizontal : Qt::Vertical, modifiers);
1275 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1278 void QXcbWindow::handleButtonReleaseEvent(const xcb_button_release_event_t *event)
1280 QPoint local(event->event_x, event->event_y);
1281 QPoint global(event->root_x, event->root_y);
1282 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1284 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1287 void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
1289 QPoint local(event->event_x, event->event_y);
1290 QPoint global(event->root_x, event->root_y);
1291 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1293 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1296 void QXcbWindow::handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global, Qt::KeyboardModifiers modifiers)
1298 connection()->setTime(time);
1300 Qt::MouseButtons buttons = translateMouseButtons(state);
1301 Qt::MouseButton button = translateMouseButton(detail);
1303 buttons ^= button; // X event uses state *before*, Qt uses state *after*
1305 QWindowSystemInterface::handleMouseEvent(window(), time, local, global, buttons, modifiers);
1308 void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
1310 connection()->setTime(event->time);
1312 if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
1313 || event->detail == XCB_NOTIFY_DETAIL_VIRTUAL
1314 || event->detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL)
1319 QWindowSystemInterface::handleEnterEvent(window());
1322 void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
1324 connection()->setTime(event->time);
1326 if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
1327 || event->detail == XCB_NOTIFY_DETAIL_INFERIOR)
1332 QWindowSystemInterface::handleLeaveEvent(window());
1335 void QXcbWindow::handlePropertyNotifyEvent(const xcb_property_notify_event_t *event)
1337 connection()->setTime(event->time);
1339 bool propertyDeleted = event->state == XCB_PROPERTY_DELETE;
1341 if (event->atom == atom(QXcbAtom::_NET_WM_STATE) || event->atom == atom(QXcbAtom::WM_STATE)) {
1342 if (propertyDeleted)
1345 xcb_get_property_cookie_t get_cookie =
1346 xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::WM_STATE),
1347 XCB_ATOM_ANY, 0, 1024);
1349 xcb_generic_error_t *error;
1351 xcb_get_property_reply_t *reply =
1352 xcb_get_property_reply(xcb_connection(), get_cookie, &error);
1354 xcb_atom_t wm_state = XCB_WM_STATE_WITHDRAWN;
1355 if (reply && reply->format == 32 && reply->type == atom(QXcbAtom::WM_STATE)) {
1356 if (reply->length != 0)
1357 wm_state = ((long *)xcb_get_property_value(reply))[0];
1360 connection()->handleXcbError(error);
1364 QVector<xcb_atom_t> netWmState = getNetWmState();
1366 bool maximized = netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ))
1367 && netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
1368 bool fullscreen = netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
1370 Qt::WindowState state = Qt::WindowNoState;
1371 if (wm_state == XCB_WM_STATE_ICONIC)
1372 state = Qt::WindowMinimized;
1374 state = Qt::WindowMaximized;
1375 else if (fullscreen)
1376 state = Qt::WindowFullScreen;
1378 QWindowSystemInterface::handleWindowStateChanged(window(), state);
1382 void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *)
1384 QWindowSystemInterface::handleWindowActivated(window());
1387 static bool focusInPeeker(xcb_generic_event_t *event)
1390 // FocusIn event is not in the queue, proceed with FocusOut normally.
1391 QWindowSystemInterface::handleWindowActivated(0);
1394 uint response_type = event->response_type & ~0x80;
1395 return response_type == XCB_FOCUS_IN;
1398 void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *)
1400 // Do not set the active window to 0 if there is a FocusIn coming.
1401 // There is however no equivalent for XPutBackEvent so register a
1402 // callback for QXcbConnection instead.
1403 connection()->addPeekFunc(focusInPeeker);
1406 void QXcbWindow::updateSyncRequestCounter()
1408 if (m_screen->syncRequestSupported() && (m_syncValue.lo != 0 || m_syncValue.hi != 0)) {
1409 Q_XCB_CALL(xcb_sync_set_counter(xcb_connection(), m_syncCounter, m_syncValue));
1410 xcb_flush(xcb_connection());
1411 connection()->sync();
1418 bool QXcbWindow::setKeyboardGrabEnabled(bool grab)
1421 xcb_ungrab_keyboard(xcb_connection(), XCB_TIME_CURRENT_TIME);
1424 xcb_grab_keyboard_cookie_t cookie = xcb_grab_keyboard(xcb_connection(), false,
1425 m_window, XCB_TIME_CURRENT_TIME,
1426 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
1427 xcb_generic_error_t *err;
1428 xcb_grab_keyboard_reply_t *reply = xcb_grab_keyboard_reply(xcb_connection(), cookie, &err);
1429 bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
1435 bool QXcbWindow::setMouseGrabEnabled(bool grab)
1438 xcb_ungrab_pointer(xcb_connection(), XCB_TIME_CURRENT_TIME);
1441 xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer(xcb_connection(), false, m_window,
1442 (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
1443 | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_ENTER_WINDOW
1444 | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION),
1445 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
1446 XCB_WINDOW_NONE, XCB_CURSOR_NONE,
1447 XCB_TIME_CURRENT_TIME);
1448 xcb_generic_error_t *err;
1449 xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(xcb_connection(), cookie, &err);
1450 bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
1456 void QXcbWindow::setCursor(xcb_cursor_t cursor)
1458 xcb_change_window_attributes(xcb_connection(), m_window, XCB_CW_CURSOR, &cursor);
1459 xcb_flush(xcb_connection());