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 #ifdef XCB_USE_XINPUT2_MAEMO
97 #include <X11/extensions/XInput2.h>
100 #if defined(XCB_USE_GLX)
101 #include "qglxintegration.h"
102 #include <QtPlatformSupport/private/qglxconvenience_p.h>
103 #elif defined(XCB_USE_EGL)
104 #include "qxcbeglsurface.h"
105 #include <QtPlatformSupport/private/qeglconvenience_p.h>
106 #include <QtPlatformSupport/private/qxlibeglintegration_p.h>
109 #define XCOORD_MAX 16383
111 //#ifdef NET_WM_STATE_DEBUG
115 // Returns true if we should set WM_TRANSIENT_FOR on \a w
116 static inline bool isTransient(const QWindow *w)
118 return w->windowType() == Qt::Dialog
119 || w->windowType() == Qt::Sheet
120 || w->windowType() == Qt::Tool
121 || w->windowType() == Qt::SplashScreen
122 || w->windowType() == Qt::ToolTip
123 || w->windowType() == Qt::Drawer
124 || w->windowType() == Qt::Popup;
127 static inline QImage::Format imageFormatForDepth(int depth)
130 case 32: return QImage::Format_ARGB32_Premultiplied;
131 case 24: return QImage::Format_RGB32;
132 case 16: return QImage::Format_RGB16;
135 qFatal("Unsupported display depth %d", depth);
136 return QImage::Format_Invalid;
139 QXcbWindow::QXcbWindow(QWindow *window)
140 : QPlatformWindow(window)
144 , m_transparent(false)
145 , m_netWmUserTimeWindow(XCB_NONE)
146 #if defined(XCB_USE_EGL)
150 m_screen = static_cast<QXcbScreen *>(window->screen()->handle());
152 setConnection(m_screen->connection());
157 void QXcbWindow::create()
161 m_windowState = Qt::WindowNoState;
163 Qt::WindowType type = window()->windowType();
165 if (type == Qt::Desktop) {
166 m_window = m_screen->root();
167 m_depth = m_screen->screen()->root_depth;
168 m_imageFormat = imageFormatForDepth(m_depth);
169 connection()->addWindow(m_window, this);
173 const quint32 mask = XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_SAVE_UNDER | XCB_CW_EVENT_MASK;
174 const quint32 values[] = {
175 // XCB_CW_BACK_PIXMAP
177 // XCB_CW_OVERRIDE_REDIRECT
178 type == Qt::Popup || type == Qt::ToolTip,
180 type == Qt::Popup || type == Qt::Tool || type == Qt::SplashScreen || type == Qt::ToolTip || type == Qt::Drawer,
182 XCB_EVENT_MASK_EXPOSURE
183 | XCB_EVENT_MASK_STRUCTURE_NOTIFY
184 | XCB_EVENT_MASK_KEY_PRESS
185 | XCB_EVENT_MASK_KEY_RELEASE
186 | XCB_EVENT_MASK_BUTTON_PRESS
187 | XCB_EVENT_MASK_BUTTON_RELEASE
188 | XCB_EVENT_MASK_BUTTON_MOTION
189 | XCB_EVENT_MASK_ENTER_WINDOW
190 | XCB_EVENT_MASK_LEAVE_WINDOW
191 | XCB_EVENT_MASK_POINTER_MOTION
192 | XCB_EVENT_MASK_PROPERTY_CHANGE
193 | XCB_EVENT_MASK_FOCUS_CHANGE
196 QRect rect = window()->geometry();
197 QPlatformWindow::setGeometry(rect);
199 rect.setWidth(qBound(1, rect.width(), XCOORD_MAX));
200 rect.setHeight(qBound(1, rect.height(), XCOORD_MAX));
202 xcb_window_t xcb_parent_id = m_screen->root();
204 xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window();
206 m_requestedFormat = window()->format();
208 #if (defined(XCB_USE_GLX) || defined(XCB_USE_EGL)) && defined(XCB_USE_XLIB)
209 if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
210 || window()->format().hasAlpha())
212 #if defined(XCB_USE_GLX)
213 XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), window()->format());
215 #elif defined(XCB_USE_EGL)
216 EGLDisplay eglDisplay = connection()->egl_display();
217 EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, window()->format(), true);
218 VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig);
220 XVisualInfo visualInfoTemplate;
221 memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
222 visualInfoTemplate.visualid = id;
224 XVisualInfo *visualInfo;
225 int matchingCount = 0;
226 visualInfo = XGetVisualInfo(DISPLAY_FROM_XCB(this), VisualIDMask, &visualInfoTemplate, &matchingCount);
229 m_depth = visualInfo->depth;
230 m_imageFormat = imageFormatForDepth(m_depth);
231 Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), xcb_parent_id, visualInfo->visual, AllocNone);
233 XSetWindowAttributes a;
234 a.background_pixel = WhitePixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber());
235 a.border_pixel = BlackPixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber());
238 m_visualId = visualInfo->visualid;
240 m_window = XCreateWindow(DISPLAY_FROM_XCB(this), xcb_parent_id, rect.x(), rect.y(), rect.width(), rect.height(),
241 0, visualInfo->depth, InputOutput, visualInfo->visual,
242 CWBackPixel|CWBorderPixel|CWColormap, &a);
244 qFatal("no window!");
247 #endif //defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
249 m_window = xcb_generate_id(xcb_connection());
250 m_depth = m_screen->screen()->root_depth;
251 m_imageFormat = imageFormatForDepth(m_depth);
252 m_visualId = m_screen->screen()->root_visual;
254 Q_XCB_CALL(xcb_create_window(xcb_connection(),
255 XCB_COPY_FROM_PARENT, // depth -- same as root
256 m_window, // window id
257 xcb_parent_id, // parent window id
263 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
264 m_visualId, // visual
269 connection()->addWindow(m_window, this);
271 Q_XCB_CALL(xcb_change_window_attributes(xcb_connection(), m_window, mask, values));
273 propagateSizeHints();
275 xcb_atom_t properties[4];
276 int propertyCount = 0;
277 properties[propertyCount++] = atom(QXcbAtom::WM_DELETE_WINDOW);
278 properties[propertyCount++] = atom(QXcbAtom::WM_TAKE_FOCUS);
279 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_PING);
281 if (m_screen->syncRequestSupported())
282 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_SYNC_REQUEST);
284 if (window()->windowFlags() & Qt::WindowContextHelpButtonHint)
285 properties[propertyCount++] = atom(QXcbAtom::_NET_WM_CONTEXT_HELP);
287 Q_XCB_CALL(xcb_change_property(xcb_connection(),
288 XCB_PROP_MODE_REPLACE,
290 atom(QXcbAtom::WM_PROTOCOLS),
298 if (m_screen->syncRequestSupported()) {
299 m_syncCounter = xcb_generate_id(xcb_connection());
300 Q_XCB_CALL(xcb_sync_create_counter(xcb_connection(), m_syncCounter, m_syncValue));
302 Q_XCB_CALL(xcb_change_property(xcb_connection(),
303 XCB_PROP_MODE_REPLACE,
305 atom(QXcbAtom::_NET_WM_SYNC_REQUEST_COUNTER),
312 // set the PID to let the WM kill the application if unresponsive
314 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
315 atom(QXcbAtom::_NET_WM_PID), XCB_ATOM_CARDINAL, 32,
318 xcb_wm_hints_t hints;
319 memset(&hints, 0, sizeof(hints));
320 xcb_wm_hints_set_normal(&hints);
322 xcb_set_wm_hints(xcb_connection(), m_window, &hints);
324 xcb_window_t leader = m_screen->clientLeader();
325 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
326 atom(QXcbAtom::WM_CLIENT_LEADER), XCB_ATOM_WINDOW, 32,
329 #ifdef XCB_USE_XINPUT2_MAEMO
330 if (connection()->isUsingXInput2()) {
331 XIEventMask xieventmask;
332 uchar bitmask[2] = { 0, 0 };
334 xieventmask.deviceid = XIAllMasterDevices;
335 xieventmask.mask = bitmask;
336 xieventmask.mask_len = sizeof(bitmask);
338 XISetMask(bitmask, XI_ButtonPress);
339 XISetMask(bitmask, XI_ButtonRelease);
340 XISetMask(bitmask, XI_Motion);
342 XISelectEvents(DISPLAY_FROM_XCB(this), m_window, &xieventmask, 1);
346 setWindowFlags(window()->windowFlags());
347 setWindowTitle(window()->windowTitle());
348 setWindowState(window()->windowState());
350 if (window()->windowFlags() & Qt::WindowTransparentForInput)
351 setTransparentForMouseEvents(true);
353 connection()->drag()->dndEnable(this, true);
356 QXcbWindow::~QXcbWindow()
361 void QXcbWindow::destroy()
363 if (m_syncCounter && m_screen->syncRequestSupported())
364 Q_XCB_CALL(xcb_sync_destroy_counter(xcb_connection(), m_syncCounter));
366 connection()->removeWindow(m_window);
367 Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window));
371 #if defined(XCB_USE_EGL)
377 void QXcbWindow::setGeometry(const QRect &rect)
379 QPlatformWindow::setGeometry(rect);
381 propagateSizeHints();
383 const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
384 const quint32 values[] = { rect.x(),
386 qBound(1, rect.width(), XCOORD_MAX),
387 qBound(1, rect.height(), XCOORD_MAX) };
389 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
391 xcb_flush(xcb_connection());
394 QMargins QXcbWindow::frameMargins() const
396 if (m_dirtyFrameMargins) {
397 xcb_window_t window = m_window;
398 xcb_window_t parent = m_window;
400 bool foundRoot = false;
402 const QVector<xcb_window_t> &virtualRoots =
403 connection()->wmSupport()->virtualRoots();
406 xcb_query_tree_cookie_t cookie = xcb_query_tree(xcb_connection(), parent);
408 xcb_generic_error_t *error;
409 xcb_query_tree_reply_t *reply = xcb_query_tree_reply(xcb_connection(), cookie, &error);
411 if (reply->root == reply->parent || virtualRoots.indexOf(reply->parent) != -1) {
415 parent = reply->parent;
421 connection()->handleXcbError(error);
425 m_dirtyFrameMargins = false;
426 m_frameMargins = QMargins();
427 return m_frameMargins;
433 xcb_generic_error_t *error;
434 xcb_translate_coordinates_reply_t *reply =
435 xcb_translate_coordinates_reply(
437 xcb_translate_coordinates(xcb_connection(), window, parent, 0, 0),
441 offset = QPoint(reply->dst_x, reply->dst_y);
447 xcb_get_geometry_reply_t *geom =
448 xcb_get_geometry_reply(
450 xcb_get_geometry(xcb_connection(), parent),
455 // add the border_width for the window managers frame... some window managers
456 // do not use a border_width of zero for their frames, and if we the left and
457 // top strut, we ensure that pos() is absolutely correct. frameGeometry()
458 // will still be incorrect though... perhaps i should have foffset as well, to
459 // indicate the frame offset (equal to the border_width on X).
461 // -- copied from qwidget_x11.cpp
463 int left = offset.x() + geom->border_width;
464 int top = offset.y() + geom->border_width;
465 int right = geom->width + geom->border_width - geometry().width() - offset.x();
466 int bottom = geom->height + geom->border_width - geometry().height() - offset.y();
468 m_frameMargins = QMargins(left, top, right, bottom);
475 m_dirtyFrameMargins = false;
478 return m_frameMargins;
481 void QXcbWindow::setVisible(bool visible)
489 void QXcbWindow::show()
491 if (window()->isTopLevel()) {
492 xcb_get_property_cookie_t cookie = xcb_get_wm_hints(xcb_connection(), m_window);
494 xcb_generic_error_t *error;
496 xcb_wm_hints_t hints;
497 xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, &error);
500 connection()->handleXcbError(error);
504 if (window()->windowState() & Qt::WindowMinimized)
505 xcb_wm_hints_set_iconic(&hints);
507 xcb_wm_hints_set_normal(&hints);
509 xcb_set_wm_hints(xcb_connection(), m_window, &hints);
511 // update WM_NORMAL_HINTS
512 propagateSizeHints();
514 // update WM_TRANSIENT_FOR
515 if (window()->transientParent() && isTransient(window())) {
516 QXcbWindow *transientXcbParent = static_cast<QXcbWindow *>(window()->transientParent()->handle());
517 if (transientXcbParent) {
519 xcb_window_t parentWindow = transientXcbParent->xcb_window();
521 // todo: set transient for group (wm_client_leader) if no parent, a la qwidget_x11.cpp
522 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
523 XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
528 // update _MOTIF_WM_HINTS
529 updateMotifWmHintsBeforeMap();
531 // update _NET_WM_STATE
532 updateNetWmStateBeforeMap();
535 Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
536 xcb_flush(xcb_connection());
538 connection()->sync();
541 void QXcbWindow::hide()
543 Q_XCB_CALL(xcb_unmap_window(xcb_connection(), m_window));
545 // send synthetic UnmapNotify event according to icccm 4.1.4
546 xcb_unmap_notify_event_t event;
547 event.response_type = XCB_UNMAP_NOTIFY;
548 event.event = m_screen->root();
549 event.window = m_window;
550 event.from_configure = false;
551 Q_XCB_CALL(xcb_send_event(xcb_connection(), false, m_screen->root(),
552 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
554 xcb_flush(xcb_connection());
559 struct QtMotifWmHints {
560 quint32 flags, functions, decorations;
566 MWM_HINTS_FUNCTIONS = (1L << 0),
568 MWM_FUNC_ALL = (1L << 0),
569 MWM_FUNC_RESIZE = (1L << 1),
570 MWM_FUNC_MOVE = (1L << 2),
571 MWM_FUNC_MINIMIZE = (1L << 3),
572 MWM_FUNC_MAXIMIZE = (1L << 4),
573 MWM_FUNC_CLOSE = (1L << 5),
575 MWM_HINTS_DECORATIONS = (1L << 1),
577 MWM_DECOR_ALL = (1L << 0),
578 MWM_DECOR_BORDER = (1L << 1),
579 MWM_DECOR_RESIZEH = (1L << 2),
580 MWM_DECOR_TITLE = (1L << 3),
581 MWM_DECOR_MENU = (1L << 4),
582 MWM_DECOR_MINIMIZE = (1L << 5),
583 MWM_DECOR_MAXIMIZE = (1L << 6),
585 MWM_HINTS_INPUT_MODE = (1L << 2),
587 MWM_INPUT_MODELESS = 0L,
588 MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L,
589 MWM_INPUT_FULL_APPLICATION_MODAL = 3L
592 static QtMotifWmHints getMotifWmHints(QXcbConnection *c, xcb_window_t window)
594 QtMotifWmHints hints;
596 xcb_get_property_cookie_t get_cookie =
597 xcb_get_property(c->xcb_connection(), 0, window, c->atom(QXcbAtom::_MOTIF_WM_HINTS),
598 c->atom(QXcbAtom::_MOTIF_WM_HINTS), 0, 20);
600 xcb_generic_error_t *error;
602 xcb_get_property_reply_t *reply =
603 xcb_get_property_reply(c->xcb_connection(), get_cookie, &error);
605 if (reply && reply->format == 32 && reply->type == c->atom(QXcbAtom::_MOTIF_WM_HINTS)) {
606 hints = *((QtMotifWmHints *)xcb_get_property_value(reply));
608 c->handleXcbError(error);
612 hints.functions = MWM_FUNC_ALL;
613 hints.decorations = MWM_DECOR_ALL;
614 hints.input_mode = 0L;
623 static void setMotifWmHints(QXcbConnection *c, xcb_window_t window, const QtMotifWmHints &hints)
625 if (hints.flags != 0l) {
626 Q_XCB_CALL2(xcb_change_property(c->xcb_connection(),
627 XCB_PROP_MODE_REPLACE,
629 c->atom(QXcbAtom::_MOTIF_WM_HINTS),
630 c->atom(QXcbAtom::_MOTIF_WM_HINTS),
635 Q_XCB_CALL2(xcb_delete_property(c->xcb_connection(), window, c->atom(QXcbAtom::_MOTIF_WM_HINTS)), c);
639 void QXcbWindow::printNetWmState(const QVector<xcb_atom_t> &state)
641 printf("_NET_WM_STATE (%d): ", state.size());
642 for (int i = 0; i < state.size(); ++i) {
643 #define CHECK_WM_STATE(state_atom) \
644 if (state.at(i) == atom(QXcbAtom::state_atom))\
645 printf(#state_atom " ");
646 CHECK_WM_STATE(_NET_WM_STATE_ABOVE)
647 CHECK_WM_STATE(_NET_WM_STATE_BELOW)
648 CHECK_WM_STATE(_NET_WM_STATE_FULLSCREEN)
649 CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_HORZ)
650 CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_VERT)
651 CHECK_WM_STATE(_NET_WM_STATE_MODAL)
652 CHECK_WM_STATE(_NET_WM_STATE_STAYS_ON_TOP)
653 CHECK_WM_STATE(_NET_WM_STATE_DEMANDS_ATTENTION)
654 #undef CHECK_WM_STATE
659 QVector<xcb_atom_t> QXcbWindow::getNetWmState()
661 QVector<xcb_atom_t> result;
663 xcb_get_property_cookie_t get_cookie =
664 xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::_NET_WM_STATE),
665 XCB_ATOM_ATOM, 0, 1024);
667 xcb_generic_error_t *error;
669 xcb_get_property_reply_t *reply =
670 xcb_get_property_reply(xcb_connection(), get_cookie, &error);
672 if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) {
673 result.resize(reply->length);
675 memcpy(result.data(), xcb_get_property_value(reply), reply->length * sizeof(xcb_atom_t));
677 #ifdef NET_WM_STATE_DEBUG
678 printf("getting net wm state (%x)\n", m_window);
679 printNetWmState(result);
684 connection()->handleXcbError(error);
687 #ifdef NET_WM_STATE_DEBUG
688 printf("getting net wm state (%x), empty\n", m_window);
695 void QXcbWindow::setNetWmState(const QVector<xcb_atom_t> &atoms)
697 if (atoms.isEmpty()) {
698 Q_XCB_CALL(xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_STATE)));
700 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
701 atom(QXcbAtom::_NET_WM_STATE), XCB_ATOM_ATOM, 32,
702 atoms.count(), atoms.constData()));
704 xcb_flush(xcb_connection());
708 Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
710 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
712 if (type == Qt::ToolTip)
713 flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint;
714 if (type == Qt::Popup)
715 flags |= Qt::X11BypassWindowManagerHint;
717 if (flags & Qt::WindowTransparentForInput) {
718 uint32_t mask = XCB_EVENT_MASK_NO_EVENT;
719 xcb_change_window_attributes(xcb_connection(), xcb_window(), XCB_CW_EVENT_MASK, &mask);
722 setNetWmWindowFlags(flags);
723 setMotifWindowFlags(flags);
725 setTransparentForMouseEvents(flags & Qt::WindowTransparentForInput);
730 void QXcbWindow::setMotifWindowFlags(Qt::WindowFlags flags)
732 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
734 QtMotifWmHints mwmhints;
736 mwmhints.functions = 0L;
737 mwmhints.decorations = 0;
738 mwmhints.input_mode = 0L;
739 mwmhints.status = 0L;
741 if (type != Qt::SplashScreen) {
742 mwmhints.flags |= MWM_HINTS_DECORATIONS;
744 bool customize = flags & Qt::CustomizeWindowHint;
745 if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
746 mwmhints.decorations |= MWM_DECOR_BORDER;
747 mwmhints.decorations |= MWM_DECOR_RESIZEH;
749 if (flags & Qt::WindowTitleHint)
750 mwmhints.decorations |= MWM_DECOR_TITLE;
752 if (flags & Qt::WindowSystemMenuHint)
753 mwmhints.decorations |= MWM_DECOR_MENU;
755 if (flags & Qt::WindowMinimizeButtonHint) {
756 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
757 mwmhints.functions |= MWM_FUNC_MINIMIZE;
760 if (flags & Qt::WindowMaximizeButtonHint) {
761 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
762 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
765 if (flags & Qt::WindowCloseButtonHint)
766 mwmhints.functions |= MWM_FUNC_CLOSE;
769 // if type == Qt::SplashScreen
770 mwmhints.decorations = MWM_DECOR_ALL;
773 if (mwmhints.functions != 0) {
774 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
775 mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
777 mwmhints.functions = MWM_FUNC_ALL;
780 if (!(flags & Qt::FramelessWindowHint)
781 && flags & Qt::CustomizeWindowHint
782 && flags & Qt::WindowTitleHint
784 (Qt::WindowMinimizeButtonHint
785 | Qt::WindowMaximizeButtonHint
786 | Qt::WindowCloseButtonHint)))
788 // a special case - only the titlebar without any button
789 mwmhints.flags = MWM_HINTS_FUNCTIONS;
790 mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
791 mwmhints.decorations = 0;
794 setMotifWmHints(connection(), m_window, mwmhints);
797 void QXcbWindow::changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two)
799 xcb_client_message_event_t event;
801 event.response_type = XCB_CLIENT_MESSAGE;
803 event.window = m_window;
804 event.type = atom(QXcbAtom::_NET_WM_STATE);
805 event.data.data32[0] = set ? 1 : 0;
806 event.data.data32[1] = one;
807 event.data.data32[2] = two;
808 event.data.data32[3] = 0;
809 event.data.data32[4] = 0;
811 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));
814 Qt::WindowState QXcbWindow::setWindowState(Qt::WindowState state)
816 if (state == m_windowState)
820 switch (m_windowState) {
821 case Qt::WindowMinimized:
822 Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
824 case Qt::WindowMaximized:
825 changeNetWmState(false,
826 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
827 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
829 case Qt::WindowFullScreen:
830 changeNetWmState(false, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
838 case Qt::WindowMinimized:
840 xcb_client_message_event_t event;
842 event.response_type = XCB_CLIENT_MESSAGE;
844 event.window = m_window;
845 event.type = atom(QXcbAtom::WM_CHANGE_STATE);
846 event.data.data32[0] = XCB_WM_STATE_ICONIC;
847 event.data.data32[1] = 0;
848 event.data.data32[2] = 0;
849 event.data.data32[3] = 0;
850 event.data.data32[4] = 0;
852 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));
855 case Qt::WindowMaximized:
856 changeNetWmState(true,
857 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
858 atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
860 case Qt::WindowFullScreen:
861 changeNetWmState(true, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
863 case Qt::WindowNoState:
869 connection()->sync();
871 m_windowState = state;
872 return m_windowState;
875 void QXcbWindow::setNetWmWindowFlags(Qt::WindowFlags flags)
877 // in order of decreasing priority
878 QVector<uint> windowTypes;
880 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
885 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_DIALOG));
889 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_UTILITY));
892 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_TOOLTIP));
894 case Qt::SplashScreen:
895 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_SPLASH));
901 if (flags & Qt::FramelessWindowHint)
902 windowTypes.append(atom(QXcbAtom::_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
904 windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_NORMAL));
906 Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
907 atom(QXcbAtom::_NET_WM_WINDOW_TYPE), XCB_ATOM_ATOM, 32,
908 windowTypes.count(), windowTypes.constData()));
911 void QXcbWindow::updateMotifWmHintsBeforeMap()
913 QtMotifWmHints mwmhints = getMotifWmHints(connection(), m_window);
915 if (window()->windowModality() != Qt::NonModal) {
916 switch (window()->windowModality()) {
917 case Qt::WindowModal:
918 mwmhints.input_mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL;
920 case Qt::ApplicationModal:
922 mwmhints.input_mode = MWM_INPUT_FULL_APPLICATION_MODAL;
925 mwmhints.flags |= MWM_HINTS_INPUT_MODE;
927 mwmhints.input_mode = MWM_INPUT_MODELESS;
928 mwmhints.flags &= ~MWM_HINTS_INPUT_MODE;
931 if (window()->minimumSize() == window()->maximumSize()) {
932 // fixed size, remove the resize handle (since mwm/dtwm
933 // isn't smart enough to do it itself)
934 mwmhints.flags |= MWM_HINTS_FUNCTIONS;
935 if (mwmhints.functions == MWM_FUNC_ALL) {
936 mwmhints.functions = MWM_FUNC_MOVE;
938 mwmhints.functions &= ~MWM_FUNC_RESIZE;
941 if (mwmhints.decorations == MWM_DECOR_ALL) {
942 mwmhints.flags |= MWM_HINTS_DECORATIONS;
943 mwmhints.decorations = (MWM_DECOR_BORDER
947 mwmhints.decorations &= ~MWM_DECOR_RESIZEH;
951 if (window()->windowFlags() & Qt::WindowMinimizeButtonHint) {
952 mwmhints.flags |= MWM_HINTS_DECORATIONS;
953 mwmhints.decorations |= MWM_DECOR_MINIMIZE;
954 mwmhints.functions |= MWM_FUNC_MINIMIZE;
956 if (window()->windowFlags() & Qt::WindowMaximizeButtonHint) {
957 mwmhints.flags |= MWM_HINTS_DECORATIONS;
958 mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
959 mwmhints.functions |= MWM_FUNC_MAXIMIZE;
961 if (window()->windowFlags() & Qt::WindowCloseButtonHint)
962 mwmhints.functions |= MWM_FUNC_CLOSE;
964 setMotifWmHints(connection(), m_window, mwmhints);
967 void QXcbWindow::updateNetWmStateBeforeMap()
969 QVector<xcb_atom_t> netWmState;
971 Qt::WindowFlags flags = window()->windowFlags();
972 if (flags & Qt::WindowStaysOnTopHint) {
973 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_ABOVE));
974 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_STAYS_ON_TOP));
975 } else if (flags & Qt::WindowStaysOnBottomHint) {
976 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_BELOW));
979 if (window()->windowState() & Qt::WindowFullScreen) {
980 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
983 if (window()->windowState() & Qt::WindowMaximized) {
984 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ));
985 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
988 if (window()->windowModality() != Qt::NonModal) {
989 netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MODAL));
992 setNetWmState(netWmState);
995 void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
997 xcb_window_t wid = m_window;
999 const bool isSupportedByWM = connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
1000 if (m_netWmUserTimeWindow || isSupportedByWM) {
1001 if (!m_netWmUserTimeWindow) {
1002 m_netWmUserTimeWindow = xcb_generate_id(xcb_connection());
1003 Q_XCB_CALL(xcb_create_window(xcb_connection(),
1004 XCB_COPY_FROM_PARENT, // depth -- same as root
1005 m_netWmUserTimeWindow, // window id
1006 m_window, // parent window id
1009 XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
1010 m_visualId, // visual
1013 wid = m_netWmUserTimeWindow;
1014 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW),
1015 XCB_ATOM_WINDOW, 32, 1, &m_netWmUserTimeWindow);
1016 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME));
1017 } else if (!isSupportedByWM) {
1018 // WM no longer supports it, then we should remove the
1019 // _NET_WM_USER_TIME_WINDOW atom.
1020 xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
1021 xcb_destroy_window(xcb_connection(), m_netWmUserTimeWindow);
1022 m_netWmUserTimeWindow = XCB_NONE;
1024 wid = m_netWmUserTimeWindow;
1027 xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::_NET_WM_USER_TIME),
1028 XCB_ATOM_CARDINAL, 32, 1, ×tamp);
1031 void QXcbWindow::setTransparentForMouseEvents(bool transparent)
1033 if (transparent == m_transparent)
1036 xcb_rectangle_t rectangle;
1038 xcb_rectangle_t *rect = 0;
1044 rectangle.width = geometry().width();
1045 rectangle.height = geometry().height();
1050 xcb_xfixes_region_t region = xcb_generate_id(xcb_connection());
1051 xcb_xfixes_create_region(xcb_connection(), region, nrect, rect);
1052 xcb_xfixes_set_window_shape_region_checked(xcb_connection(), m_window, XCB_SHAPE_SK_INPUT, 0, 0, region);
1053 xcb_xfixes_destroy_region(xcb_connection(), region);
1055 m_transparent = transparent;
1059 WId QXcbWindow::winId() const
1064 void QXcbWindow::setParent(const QPlatformWindow *parent)
1066 // re-create for compatibility
1069 QPoint topLeft = geometry().topLeft();
1071 xcb_window_t xcb_parent_id = parent ? static_cast<const QXcbWindow *>(parent)->xcb_window() : m_screen->root();
1072 Q_XCB_CALL(xcb_reparent_window(xcb_connection(), xcb_window(), xcb_parent_id, topLeft.x(), topLeft.y()));
1075 void QXcbWindow::setWindowTitle(const QString &title)
1077 QByteArray ba = title.toUtf8();
1078 Q_XCB_CALL(xcb_change_property(xcb_connection(),
1079 XCB_PROP_MODE_REPLACE,
1081 atom(QXcbAtom::_NET_WM_NAME),
1082 atom(QXcbAtom::UTF8_STRING),
1088 void QXcbWindow::raise()
1090 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1091 const quint32 values[] = { XCB_STACK_MODE_ABOVE };
1092 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
1095 void QXcbWindow::lower()
1097 const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
1098 const quint32 values[] = { XCB_STACK_MODE_BELOW };
1099 Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
1102 void QXcbWindow::propagateSizeHints()
1104 // update WM_NORMAL_HINTS
1105 xcb_size_hints_t hints;
1106 memset(&hints, 0, sizeof(hints));
1108 QRect rect = geometry();
1110 QWindow *win = window();
1112 xcb_size_hints_set_position(&hints, true, rect.x(), rect.y());
1113 xcb_size_hints_set_size(&hints, true, rect.width(), rect.height());
1114 xcb_size_hints_set_win_gravity(&hints, qt_window_private(win)->positionPolicy == QWindowPrivate::WindowFrameInclusive
1115 ? XCB_GRAVITY_NORTH_WEST : XCB_GRAVITY_STATIC);
1117 QSize minimumSize = win->minimumSize();
1118 QSize maximumSize = win->maximumSize();
1119 QSize baseSize = win->baseSize();
1120 QSize sizeIncrement = win->sizeIncrement();
1122 if (minimumSize.width() > 0 || minimumSize.height() > 0)
1123 xcb_size_hints_set_min_size(&hints, minimumSize.width(), minimumSize.height());
1125 if (maximumSize.width() < QWINDOWSIZE_MAX || maximumSize.height() < QWINDOWSIZE_MAX)
1126 xcb_size_hints_set_max_size(&hints,
1127 qMin(XCOORD_MAX, maximumSize.width()),
1128 qMin(XCOORD_MAX, maximumSize.height()));
1130 if (sizeIncrement.width() > 0 || sizeIncrement.height() > 0) {
1131 xcb_size_hints_set_base_size(&hints, baseSize.width(), baseSize.height());
1132 xcb_size_hints_set_resize_inc(&hints, sizeIncrement.width(), sizeIncrement.height());
1135 xcb_set_wm_normal_hints(xcb_connection(), m_window, &hints);
1138 void QXcbWindow::requestActivateWindow()
1141 updateNetWmUserTime(connection()->time());
1142 Q_XCB_CALL(xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, connection()->time()));
1144 connection()->sync();
1147 QSurfaceFormat QXcbWindow::format() const
1149 // ### return actual format
1150 return m_requestedFormat;
1153 #if defined(XCB_USE_EGL)
1154 QXcbEGLSurface *QXcbWindow::eglSurface() const
1156 if (!m_eglSurface) {
1157 EGLDisplay display = connection()->egl_display();
1158 EGLConfig config = q_configFromGLFormat(display, window()->format(), true);
1159 EGLSurface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_window, 0);
1161 m_eglSurface = new QXcbEGLSurface(display, surface);
1164 return m_eglSurface;
1168 void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
1170 QRect rect(event->x, event->y, event->width, event->height);
1172 if (m_exposeRegion.isEmpty())
1173 m_exposeRegion = rect;
1175 m_exposeRegion |= rect;
1177 // if count is non-zero there are more expose events pending
1178 if (event->count == 0) {
1179 QWindowSystemInterface::handleSynchronousExposeEvent(window(), m_exposeRegion);
1180 m_exposeRegion = QRegion();
1184 void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event)
1186 if (event->format != 32)
1189 if (event->type == atom(QXcbAtom::WM_PROTOCOLS)) {
1190 if (event->data.data32[0] == atom(QXcbAtom::WM_DELETE_WINDOW)) {
1191 QWindowSystemInterface::handleCloseEvent(window());
1192 } else if (event->data.data32[0] == atom(QXcbAtom::WM_TAKE_FOCUS)) {
1193 connection()->setTime(event->data.data32[1]);
1194 } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_PING)) {
1195 xcb_client_message_event_t reply = *event;
1197 reply.response_type = XCB_CLIENT_MESSAGE;
1198 reply.window = m_screen->root();
1200 xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&reply);
1201 xcb_flush(xcb_connection());
1202 } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_SYNC_REQUEST)) {
1203 connection()->setTime(event->data.data32[1]);
1204 m_syncValue.lo = event->data.data32[2];
1205 m_syncValue.hi = event->data.data32[3];
1207 qWarning() << "unhandled WM_PROTOCOLS message:" << connection()->atomName(event->data.data32[0]);
1209 } else if (event->type == atom(QXcbAtom::XdndEnter)) {
1210 connection()->drag()->handleEnter(window(), event);
1211 } else if (event->type == atom(QXcbAtom::XdndPosition)) {
1212 connection()->drag()->handlePosition(window(), event, false);
1213 } else if (event->type == atom(QXcbAtom::XdndLeave)) {
1214 connection()->drag()->handleLeave(window(), event, false);
1215 } else if (event->type == atom(QXcbAtom::XdndDrop)) {
1216 connection()->drag()->handleDrop(window(), event, false);
1218 qWarning() << "unhandled client message:" << connection()->atomName(event->type);
1222 void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event)
1224 QRect rect(event->x, event->y, event->width, event->height);
1226 QPlatformWindow::setGeometry(rect);
1227 QWindowSystemInterface::handleGeometryChange(window(), rect);
1229 m_dirtyFrameMargins = true;
1233 static_cast<QDri2Context *>(m_context)->resize(rect.size());
1237 void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event)
1239 if (event->window == m_window) {
1241 QWindowSystemInterface::handleMapEvent(window());
1245 void QXcbWindow::handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event)
1247 if (event->window == m_window) {
1249 QWindowSystemInterface::handleUnmapEvent(window());
1253 static Qt::MouseButtons translateMouseButtons(int s)
1255 Qt::MouseButtons ret = 0;
1256 if (s & XCB_BUTTON_MASK_1)
1257 ret |= Qt::LeftButton;
1258 if (s & XCB_BUTTON_MASK_2)
1259 ret |= Qt::MidButton;
1260 if (s & XCB_BUTTON_MASK_3)
1261 ret |= Qt::RightButton;
1265 static Qt::MouseButton translateMouseButton(xcb_button_t s)
1269 return Qt::LeftButton;
1271 return Qt::MidButton;
1273 return Qt::RightButton;
1275 return Qt::NoButton;
1279 void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
1281 updateNetWmUserTime(event->time);
1283 QPoint local(event->event_x, event->event_y);
1284 QPoint global(event->root_x, event->root_y);
1286 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1288 if (event->detail >= 4 && event->detail <= 7) {
1289 //logic borrowed from qapplication_x11.cpp
1290 int delta = 120 * ((event->detail == 4 || event->detail == 6) ? 1 : -1);
1291 bool hor = (((event->detail == 4 || event->detail == 5)
1292 && (modifiers & Qt::AltModifier))
1293 || (event->detail == 6 || event->detail == 7));
1295 QWindowSystemInterface::handleWheelEvent(window(), event->time,
1296 local, global, delta, hor ? Qt::Horizontal : Qt::Vertical, modifiers);
1300 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1303 void QXcbWindow::handleButtonReleaseEvent(const xcb_button_release_event_t *event)
1305 QPoint local(event->event_x, event->event_y);
1306 QPoint global(event->root_x, event->root_y);
1307 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1309 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1312 void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
1314 QPoint local(event->event_x, event->event_y);
1315 QPoint global(event->root_x, event->root_y);
1316 Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
1318 handleMouseEvent(event->detail, event->state, event->time, local, global, modifiers);
1321 void QXcbWindow::handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global, Qt::KeyboardModifiers modifiers)
1323 connection()->setTime(time);
1325 Qt::MouseButtons buttons = translateMouseButtons(state);
1326 Qt::MouseButton button = translateMouseButton(detail);
1328 buttons ^= button; // X event uses state *before*, Qt uses state *after*
1330 QWindowSystemInterface::handleMouseEvent(window(), time, local, global, buttons, modifiers);
1333 void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
1335 connection()->setTime(event->time);
1337 if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
1338 || event->detail == XCB_NOTIFY_DETAIL_VIRTUAL
1339 || event->detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL)
1344 QWindowSystemInterface::handleEnterEvent(window());
1347 void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
1349 connection()->setTime(event->time);
1351 if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
1352 || event->detail == XCB_NOTIFY_DETAIL_INFERIOR)
1357 QWindowSystemInterface::handleLeaveEvent(window());
1360 void QXcbWindow::handlePropertyNotifyEvent(const xcb_property_notify_event_t *event)
1362 connection()->setTime(event->time);
1364 bool propertyDeleted = event->state == XCB_PROPERTY_DELETE;
1366 if (event->atom == atom(QXcbAtom::_NET_WM_STATE) || event->atom == atom(QXcbAtom::WM_STATE)) {
1367 if (propertyDeleted)
1370 xcb_get_property_cookie_t get_cookie =
1371 xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::WM_STATE),
1372 XCB_ATOM_ANY, 0, 1024);
1374 xcb_generic_error_t *error;
1376 xcb_get_property_reply_t *reply =
1377 xcb_get_property_reply(xcb_connection(), get_cookie, &error);
1379 xcb_atom_t wm_state = XCB_WM_STATE_WITHDRAWN;
1380 if (reply && reply->format == 32 && reply->type == atom(QXcbAtom::WM_STATE)) {
1381 if (reply->length != 0)
1382 wm_state = ((long *)xcb_get_property_value(reply))[0];
1385 connection()->handleXcbError(error);
1389 QVector<xcb_atom_t> netWmState = getNetWmState();
1391 bool maximized = netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ))
1392 && netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
1393 bool fullscreen = netWmState.contains(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
1395 Qt::WindowState state = Qt::WindowNoState;
1396 if (wm_state == XCB_WM_STATE_ICONIC)
1397 state = Qt::WindowMinimized;
1399 state = Qt::WindowMaximized;
1400 else if (fullscreen)
1401 state = Qt::WindowFullScreen;
1403 QWindowSystemInterface::handleWindowStateChanged(window(), state);
1407 void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *)
1409 QWindowSystemInterface::handleWindowActivated(window());
1412 static bool focusInPeeker(xcb_generic_event_t *event)
1415 // FocusIn event is not in the queue, proceed with FocusOut normally.
1416 QWindowSystemInterface::handleWindowActivated(0);
1419 uint response_type = event->response_type & ~0x80;
1420 return response_type == XCB_FOCUS_IN;
1423 void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *)
1425 // Do not set the active window to 0 if there is a FocusIn coming.
1426 // There is however no equivalent for XPutBackEvent so register a
1427 // callback for QXcbConnection instead.
1428 connection()->addPeekFunc(focusInPeeker);
1431 void QXcbWindow::updateSyncRequestCounter()
1433 if (m_screen->syncRequestSupported() && (m_syncValue.lo != 0 || m_syncValue.hi != 0)) {
1434 Q_XCB_CALL(xcb_sync_set_counter(xcb_connection(), m_syncCounter, m_syncValue));
1435 xcb_flush(xcb_connection());
1436 connection()->sync();
1443 bool QXcbWindow::setKeyboardGrabEnabled(bool grab)
1446 xcb_ungrab_keyboard(xcb_connection(), XCB_TIME_CURRENT_TIME);
1449 xcb_grab_keyboard_cookie_t cookie = xcb_grab_keyboard(xcb_connection(), false,
1450 m_window, XCB_TIME_CURRENT_TIME,
1451 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
1452 xcb_generic_error_t *err;
1453 xcb_grab_keyboard_reply_t *reply = xcb_grab_keyboard_reply(xcb_connection(), cookie, &err);
1454 bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
1460 bool QXcbWindow::setMouseGrabEnabled(bool grab)
1463 xcb_ungrab_pointer(xcb_connection(), XCB_TIME_CURRENT_TIME);
1466 xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer(xcb_connection(), false, m_window,
1467 (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
1468 | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_ENTER_WINDOW
1469 | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION),
1470 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
1471 XCB_WINDOW_NONE, XCB_CURSOR_NONE,
1472 XCB_TIME_CURRENT_TIME);
1473 xcb_generic_error_t *err;
1474 xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(xcb_connection(), cookie, &err);
1475 bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
1481 void QXcbWindow::setCursor(xcb_cursor_t cursor)
1483 xcb_change_window_attributes(xcb_connection(), m_window, XCB_CW_CURSOR, &cursor);
1484 xcb_flush(xcb_connection());