summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/xcb/qxcbwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbwindow.cpp')
-rw-r--r--src/plugins/platforms/xcb/qxcbwindow.cpp950
1 files changed, 794 insertions, 156 deletions
diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index 20e4187541..db8d37e817 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -42,9 +42,13 @@
#include "qxcbwindow.h"
#include <QtDebug>
+#include <QScreen>
#include "qxcbconnection.h"
#include "qxcbscreen.h"
+#include "qxcbdrag.h"
+#include "qxcbwmsupport.h"
+
#ifdef XCB_USE_DRI2
#include "qdri2context.h"
#endif
@@ -61,9 +65,10 @@
#define xcb_set_wm_hints xcb_icccm_set_wm_hints
#endif
-#include <private/qapplication_p.h>
-#include <private/qwindowsurface_p.h>
+#include <private/qguiapplication_p.h>
+#include <private/qwindow_p.h>
+#include <QtGui/QPlatformBackingStore>
#include <QtGui/QWindowSystemInterface>
#include <stdio.h>
@@ -75,38 +80,71 @@
#if defined(XCB_USE_GLX)
#include "qglxintegration.h"
-#include "qglxconvenience.h"
+#include <QtPlatformSupport/private/qglxconvenience_p.h>
#elif defined(XCB_USE_EGL)
-#include "../eglconvenience/qeglplatformcontext.h"
-#include "../eglconvenience/qeglconvenience.h"
-#include "../eglconvenience/qxlibeglintegration.h"
+#include "qxcbeglsurface.h"
+#include <QtPlatformSupport/private/qeglconvenience_p.h>
+#include <QtPlatformSupport/private/qxlibeglintegration_p.h>
#endif
+#define XCOORD_MAX 16383
+
+//#ifdef NET_WM_STATE_DEBUG
+
// Returns true if we should set WM_TRANSIENT_FOR on \a w
-static inline bool isTransient(const QWidget *w)
+static inline bool isTransient(const QWindow *w)
{
- return ((w->windowType() == Qt::Dialog
- || w->windowType() == Qt::Sheet
- || w->windowType() == Qt::Tool
- || w->windowType() == Qt::SplashScreen
- || w->windowType() == Qt::ToolTip
- || w->windowType() == Qt::Drawer
- || w->windowType() == Qt::Popup)
- && !w->testAttribute(Qt::WA_X11BypassTransientForHint));
+ return w->windowType() == Qt::Dialog
+ || w->windowType() == Qt::Sheet
+ || w->windowType() == Qt::Tool
+ || w->windowType() == Qt::SplashScreen
+ || w->windowType() == Qt::ToolTip
+ || w->windowType() == Qt::Drawer
+ || w->windowType() == Qt::Popup;
}
-QXcbWindow::QXcbWindow(QWidget *tlw)
- : QPlatformWindow(tlw)
- , m_context(0)
+QXcbWindow::QXcbWindow(QWindow *window)
+ : QPlatformWindow(window)
+ , m_window(0)
+ , m_syncCounter(0)
+ , m_mapped(false)
+ , m_netWmUserTimeWindow(XCB_NONE)
+#if defined(XCB_USE_EGL)
+ , m_eglSurface(0)
+#endif
{
- m_screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(tlw));
+ m_screen = static_cast<QXcbScreen *>(window->screen()->handle());
setConnection(m_screen->connection());
- const quint32 mask = XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK;
+ create();
+}
+
+void QXcbWindow::create()
+{
+ destroy();
+
+ m_windowState = Qt::WindowNoState;
+ m_dirtyFrameMargins = true;
+
+ Qt::WindowType type = window()->windowType();
+
+ if (type == Qt::Desktop) {
+ m_window = m_screen->root();
+ m_depth = m_screen->screen()->root_depth;
+ m_imageFormat = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
+ connection()->addWindow(m_window, this);
+ return;
+ }
+
+ const quint32 mask = XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_SAVE_UNDER | XCB_CW_EVENT_MASK;
const quint32 values[] = {
// XCB_CW_BACK_PIXMAP
XCB_NONE,
+ // XCB_CW_OVERRIDE_REDIRECT
+ type == Qt::Popup || type == Qt::ToolTip,
+ // XCB_CW_SAVE_UNDER
+ type == Qt::Popup || type == Qt::Tool || type == Qt::SplashScreen || type == Qt::ToolTip || type == Qt::Drawer,
// XCB_CW_EVENT_MASK
XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_STRUCTURE_NOTIFY
@@ -117,20 +155,33 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
| XCB_EVENT_MASK_BUTTON_MOTION
| XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_LEAVE_WINDOW
+ | XCB_EVENT_MASK_POINTER_MOTION
| XCB_EVENT_MASK_PROPERTY_CHANGE
| XCB_EVENT_MASK_FOCUS_CHANGE
};
-#if defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
- if (tlw->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL
- && QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
- || tlw->platformWindowFormat().alpha())
+ QRect rect = window()->geometry();
+ QPlatformWindow::setGeometry(rect);
+
+ rect.setWidth(qBound(1, rect.width(), XCOORD_MAX));
+ rect.setHeight(qBound(1, rect.height(), XCOORD_MAX));
+
+ xcb_window_t xcb_parent_id = m_screen->root();
+ if (parent())
+ xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window();
+
+ m_requestedFormat = window()->format();
+
+#if (defined(XCB_USE_GLX) || defined(XCB_USE_EGL)) && defined(XCB_USE_XLIB)
+ if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
+ || window()->format().hasAlpha())
{
#if defined(XCB_USE_GLX)
- XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), tlw->platformWindowFormat());
+ XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), window()->format());
+
#elif defined(XCB_USE_EGL)
EGLDisplay eglDisplay = connection()->egl_display();
- EGLConfig eglConfig = q_configFromQPlatformWindowFormat(eglDisplay,tlw->platformWindowFormat(),true);
+ EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, window()->format(), true);
VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig);
XVisualInfo visualInfoTemplate;
@@ -143,18 +194,16 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
#endif //XCB_USE_GLX
if (visualInfo) {
m_depth = visualInfo->depth;
- m_format = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
- Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), m_screen->root(), visualInfo->visual, AllocNone);
+ m_imageFormat = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
+ Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), xcb_parent_id, visualInfo->visual, AllocNone);
XSetWindowAttributes a;
a.background_pixel = WhitePixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber());
a.border_pixel = BlackPixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber());
a.colormap = cmap;
- m_window = XCreateWindow(DISPLAY_FROM_XCB(this), m_screen->root(), tlw->x(), tlw->y(), tlw->width(), tlw->height(),
+ m_window = XCreateWindow(DISPLAY_FROM_XCB(this), xcb_parent_id, rect.x(), rect.y(), rect.width(), rect.height(),
0, visualInfo->depth, InputOutput, visualInfo->visual,
CWBackPixel|CWBorderPixel|CWColormap, &a);
-
- printf("created GL window: %d\n", m_window);
} else {
qFatal("no window!");
}
@@ -163,25 +212,25 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
{
m_window = xcb_generate_id(xcb_connection());
m_depth = m_screen->screen()->root_depth;
- m_format = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
+ m_imageFormat = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
Q_XCB_CALL(xcb_create_window(xcb_connection(),
XCB_COPY_FROM_PARENT, // depth -- same as root
m_window, // window id
- m_screen->root(), // parent window id
- tlw->x(),
- tlw->y(),
- tlw->width(),
- tlw->height(),
+ xcb_parent_id, // parent window id
+ rect.x(),
+ rect.y(),
+ rect.width(),
+ rect.height(),
0, // border width
XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
m_screen->screen()->root_visual, // visual
0, // value mask
0)); // value list
-
- printf("created regular window: %d\n", m_window);
}
+ connection()->addWindow(m_window, this);
+
Q_XCB_CALL(xcb_change_window_attributes(xcb_connection(), m_window, mask, values));
xcb_atom_t properties[4];
@@ -193,7 +242,7 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
if (m_screen->syncRequestSupported())
properties[propertyCount++] = atom(QXcbAtom::_NET_WM_SYNC_REQUEST);
- if (tlw->windowFlags() & Qt::WindowContextHelpButtonHint)
+ if (window()->windowFlags() & Qt::WindowContextHelpButtonHint)
properties[propertyCount++] = atom(QXcbAtom::_NET_WM_CONTEXT_HELP);
Q_XCB_CALL(xcb_change_property(xcb_connection(),
@@ -221,29 +270,49 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
&m_syncCounter));
}
- if (isTransient(tlw) && tlw->parentWidget()) {
- // ICCCM 4.1.2.6
- QWidget *p = tlw->parentWidget()->window();
- xcb_window_t parentWindow = p->winId();
- Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
- XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
- 1, &parentWindow));
-
- }
-
// set the PID to let the WM kill the application if unresponsive
long pid = getpid();
Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
atom(QXcbAtom::_NET_WM_PID), XCB_ATOM_CARDINAL, 32,
1, &pid));
+
+ xcb_wm_hints_t hints;
+ memset(&hints, 0, sizeof(hints));
+ xcb_wm_hints_set_normal(&hints);
+
+ xcb_set_wm_hints(xcb_connection(), m_window, &hints);
+
+ xcb_window_t leader = m_screen->clientLeader();
+ Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
+ atom(QXcbAtom::WM_CLIENT_LEADER), XCB_ATOM_WINDOW, 32,
+ 1, &leader));
+
+ setWindowFlags(window()->windowFlags());
+ setWindowTitle(window()->windowTitle());
+ setWindowState(window()->windowState());
+
+ connection()->drag()->dndEnable(this, true);
}
QXcbWindow::~QXcbWindow()
{
- delete m_context;
- if (m_screen->syncRequestSupported())
+ destroy();
+}
+
+void QXcbWindow::destroy()
+{
+ if (m_syncCounter && m_screen->syncRequestSupported())
Q_XCB_CALL(xcb_sync_destroy_counter(xcb_connection(), m_syncCounter));
- Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window));
+ if (m_window) {
+ connection()->removeWindow(m_window);
+ Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window));
+ }
+ m_mapped = false;
+
+#if defined(XCB_USE_EGL)
+ delete m_eglSurface;
+ m_eglSurface = 0;
+#endif
}
void QXcbWindow::setGeometry(const QRect &rect)
@@ -251,40 +320,182 @@ void QXcbWindow::setGeometry(const QRect &rect)
QPlatformWindow::setGeometry(rect);
const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
- const quint32 values[] = { rect.x(), rect.y(), rect.width(), rect.height() };
+ const quint32 values[] = { rect.x(),
+ rect.y(),
+ qBound(1, rect.width(), XCOORD_MAX),
+ qBound(1, rect.height(), XCOORD_MAX) };
Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
}
+QMargins QXcbWindow::frameMargins() const
+{
+ if (m_dirtyFrameMargins) {
+ xcb_window_t window = m_window;
+ xcb_window_t parent = m_window;
+
+ bool foundRoot = false;
+
+ const QVector<xcb_window_t> &virtualRoots =
+ connection()->wmSupport()->virtualRoots();
+
+ while (!foundRoot) {
+ xcb_query_tree_cookie_t cookie = xcb_query_tree(xcb_connection(), parent);
+
+ xcb_generic_error_t *error;
+ xcb_query_tree_reply_t *reply = xcb_query_tree_reply(xcb_connection(), cookie, &error);
+ if (reply) {
+ if (reply->root == reply->parent || virtualRoots.indexOf(reply->parent) != -1) {
+ foundRoot = true;
+ } else {
+ window = parent;
+ parent = reply->parent;
+ }
+
+ free(reply);
+ } else {
+ if (error) {
+ connection()->handleXcbError(error);
+ free(error);
+ }
+
+ m_dirtyFrameMargins = false;
+ m_frameMargins = QMargins();
+ return m_frameMargins;
+ }
+ }
+
+ QPoint offset;
+
+ xcb_generic_error_t *error;
+ xcb_translate_coordinates_reply_t *reply =
+ xcb_translate_coordinates_reply(
+ xcb_connection(),
+ xcb_translate_coordinates(xcb_connection(), window, parent, 0, 0),
+ &error);
+
+ if (reply) {
+ offset = QPoint(reply->dst_x, reply->dst_y);
+ free(reply);
+ } else if (error) {
+ free(error);
+ }
+
+ xcb_get_geometry_reply_t *geom =
+ xcb_get_geometry_reply(
+ xcb_connection(),
+ xcb_get_geometry(xcb_connection(), parent),
+ &error);
+
+ if (geom) {
+ // --
+ // add the border_width for the window managers frame... some window managers
+ // do not use a border_width of zero for their frames, and if we the left and
+ // top strut, we ensure that pos() is absolutely correct. frameGeometry()
+ // will still be incorrect though... perhaps i should have foffset as well, to
+ // indicate the frame offset (equal to the border_width on X).
+ // - Brad
+ // -- copied from qwidget_x11.cpp
+
+ int left = offset.x() + geom->border_width;
+ int top = offset.y() + geom->border_width;
+ int right = geom->width + geom->border_width - geometry().width() - offset.x();
+ int bottom = geom->height + geom->border_width - geometry().height() - offset.y();
+
+ m_frameMargins = QMargins(left, top, right, bottom);
+
+ free(geom);
+ } else if (error) {
+ free(error);
+ }
+
+ m_dirtyFrameMargins = false;
+ }
+
+ return m_frameMargins;
+}
+
void QXcbWindow::setVisible(bool visible)
{
- xcb_wm_hints_t hints;
- if (visible) {
- if (widget()->isMinimized())
+ if (visible)
+ show();
+ else
+ hide();
+}
+
+void QXcbWindow::show()
+{
+ if (window()->isTopLevel()) {
+ xcb_get_property_cookie_t cookie = xcb_get_wm_hints(xcb_connection(), m_window);
+
+ xcb_generic_error_t *error;
+
+ xcb_wm_hints_t hints;
+ xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, &error);
+
+ if (error) {
+ connection()->handleXcbError(error);
+ free(error);
+ }
+
+ m_dirtyFrameMargins = true;
+
+ if (window()->windowState() & Qt::WindowMinimized)
xcb_wm_hints_set_iconic(&hints);
else
xcb_wm_hints_set_normal(&hints);
+
xcb_set_wm_hints(xcb_connection(), m_window, &hints);
- Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
- connection()->sync();
- } else {
- Q_XCB_CALL(xcb_unmap_window(xcb_connection(), m_window));
-
- // send synthetic UnmapNotify event according to icccm 4.1.4
- xcb_unmap_notify_event_t event;
- event.response_type = XCB_UNMAP_NOTIFY;
- event.sequence = 0; // does this matter?
- event.event = m_screen->root();
- event.window = m_window;
- event.from_configure = false;
- Q_XCB_CALL(xcb_send_event(xcb_connection(), false, m_screen->root(),
- XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
- xcb_flush(xcb_connection());
+ // update WM_NORMAL_HINTS
+ propagateSizeHints();
+
+ // update WM_TRANSIENT_FOR
+ if (window()->transientParent() && isTransient(window())) {
+ QXcbWindow *transientXcbParent = static_cast<QXcbWindow *>(window()->transientParent()->handle());
+ if (transientXcbParent) {
+ // ICCCM 4.1.2.6
+ xcb_window_t parentWindow = transientXcbParent->xcb_window();
+
+ // todo: set transient for group (wm_client_leader) if no parent, a la qwidget_x11.cpp
+ Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
+ XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
+ 1, &parentWindow));
+ }
+ }
+
+ // update _MOTIF_WM_HINTS
+ updateMotifWmHintsBeforeMap();
+
+ // update _NET_WM_STATE
+ updateNetWmStateBeforeMap();
}
+
+ Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
+ xcb_flush(xcb_connection());
+
+ connection()->sync();
+}
+
+void QXcbWindow::hide()
+{
+ Q_XCB_CALL(xcb_unmap_window(xcb_connection(), m_window));
+
+ // send synthetic UnmapNotify event according to icccm 4.1.4
+ xcb_unmap_notify_event_t event;
+ event.response_type = XCB_UNMAP_NOTIFY;
+ event.event = m_screen->root();
+ event.window = m_window;
+ event.from_configure = false;
+ Q_XCB_CALL(xcb_send_event(xcb_connection(), false, m_screen->root(),
+ XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
+
+ xcb_flush(xcb_connection());
+
+ m_mapped = false;
}
-struct QtMWMHints {
+struct QtMotifWmHints {
quint32 flags, functions, decorations;
qint32 input_mode;
quint32 status;
@@ -317,33 +528,142 @@ enum {
MWM_INPUT_FULL_APPLICATION_MODAL = 3L
};
+static QtMotifWmHints getMotifWmHints(QXcbConnection *c, xcb_window_t window)
+{
+ QtMotifWmHints hints;
+
+ xcb_get_property_cookie_t get_cookie =
+ xcb_get_property(c->xcb_connection(), 0, window, c->atom(QXcbAtom::_MOTIF_WM_HINTS),
+ c->atom(QXcbAtom::_MOTIF_WM_HINTS), 0, 20);
+
+ xcb_generic_error_t *error;
+
+ xcb_get_property_reply_t *reply =
+ xcb_get_property_reply(c->xcb_connection(), get_cookie, &error);
+
+ if (reply && reply->format == 32 && reply->type == c->atom(QXcbAtom::_MOTIF_WM_HINTS)) {
+ hints = *((QtMotifWmHints *)xcb_get_property_value(reply));
+ } else if (error) {
+ c->handleXcbError(error);
+ free(error);
+
+ hints.flags = 0L;
+ hints.functions = MWM_FUNC_ALL;
+ hints.decorations = MWM_DECOR_ALL;
+ hints.input_mode = 0L;
+ hints.status = 0L;
+ }
+
+ free(reply);
+
+ return hints;
+}
+
+static void setMotifWmHints(QXcbConnection *c, xcb_window_t window, const QtMotifWmHints &hints)
+{
+ if (hints.flags != 0l) {
+ Q_XCB_CALL2(xcb_change_property(c->xcb_connection(),
+ XCB_PROP_MODE_REPLACE,
+ window,
+ c->atom(QXcbAtom::_MOTIF_WM_HINTS),
+ c->atom(QXcbAtom::_MOTIF_WM_HINTS),
+ 32,
+ 5,
+ &hints), c);
+ } else {
+ Q_XCB_CALL2(xcb_delete_property(c->xcb_connection(), window, c->atom(QXcbAtom::_MOTIF_WM_HINTS)), c);
+ }
+}
+
+void QXcbWindow::printNetWmState(const QVector<xcb_atom_t> &state)
+{
+ printf("_NET_WM_STATE (%d): ", state.size());
+ for (int i = 0; i < state.size(); ++i) {
+#define CHECK_WM_STATE(state_atom) \
+ if (state.at(i) == atom(QXcbAtom::state_atom))\
+ printf(#state_atom " ");
+ CHECK_WM_STATE(_NET_WM_STATE_ABOVE)
+ CHECK_WM_STATE(_NET_WM_STATE_BELOW)
+ CHECK_WM_STATE(_NET_WM_STATE_FULLSCREEN)
+ CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_HORZ)
+ CHECK_WM_STATE(_NET_WM_STATE_MAXIMIZED_VERT)
+ CHECK_WM_STATE(_NET_WM_STATE_MODAL)
+ CHECK_WM_STATE(_NET_WM_STATE_STAYS_ON_TOP)
+ CHECK_WM_STATE(_NET_WM_STATE_DEMANDS_ATTENTION)
+#undef CHECK_WM_STATE
+ }
+ printf("\n");
+}
+
+QVector<xcb_atom_t> QXcbWindow::getNetWmState()
+{
+ QVector<xcb_atom_t> result;
+
+ xcb_get_property_cookie_t get_cookie =
+ xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::_NET_WM_STATE),
+ XCB_ATOM_ATOM, 0, 1024);
+
+ xcb_generic_error_t *error;
+
+ xcb_get_property_reply_t *reply =
+ xcb_get_property_reply(xcb_connection(), get_cookie, &error);
+
+ if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) {
+ result.resize(reply->length);
+
+ memcpy(result.data(), xcb_get_property_value(reply), reply->length * sizeof(xcb_atom_t));
+
+#ifdef NET_WM_STATE_DEBUG
+ printf("getting net wm state (%x)\n", m_window);
+ printNetWmState(result);
+#endif
+
+ free(reply);
+ } else if (error) {
+ connection()->handleXcbError(error);
+ free(error);
+ } else {
+#ifdef NET_WM_STATE_DEBUG
+ printf("getting net wm state (%x), empty\n", m_window);
+#endif
+ }
+
+ return result;
+}
+
+void QXcbWindow::setNetWmState(const QVector<xcb_atom_t> &atoms)
+{
+ if (atoms.isEmpty()) {
+ Q_XCB_CALL(xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_STATE)));
+ } else {
+ Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
+ atom(QXcbAtom::_NET_WM_STATE), XCB_ATOM_ATOM, 32,
+ atoms.count(), atoms.constData()));
+ }
+ xcb_flush(xcb_connection());
+}
+
+
Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
{
Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
- setNetWmWindowTypes(flags);
-
if (type == Qt::ToolTip)
flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint;
if (type == Qt::Popup)
flags |= Qt::X11BypassWindowManagerHint;
- bool topLevel = (flags & Qt::Window);
- bool popup = (type == Qt::Popup);
- bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet);
- bool desktop = (type == Qt::Desktop);
- bool tool = (type == Qt::Tool || type == Qt::SplashScreen
- || type == Qt::ToolTip || type == Qt::Drawer);
+ setNetWmWindowFlags(flags);
+ setMotifWindowFlags(flags);
- Q_UNUSED(topLevel);
- Q_UNUSED(dialog);
- Q_UNUSED(desktop);
- Q_UNUSED(tool);
+ return flags;
+}
- bool tooltip = (type == Qt::ToolTip);
+void QXcbWindow::setMotifWindowFlags(Qt::WindowFlags flags)
+{
+ Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
- QtMWMHints mwmhints;
+ QtMotifWmHints mwmhints;
mwmhints.flags = 0L;
mwmhints.functions = 0L;
mwmhints.decorations = 0;
@@ -403,30 +723,90 @@ Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
mwmhints.decorations = 0;
}
- if (mwmhints.flags != 0l) {
- Q_XCB_CALL(xcb_change_property(xcb_connection(),
- XCB_PROP_MODE_REPLACE,
- m_window,
- atom(QXcbAtom::_MOTIF_WM_HINTS),
- atom(QXcbAtom::_MOTIF_WM_HINTS),
- 32,
- 5,
- &mwmhints));
- } else {
- Q_XCB_CALL(xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_MOTIF_WM_HINTS)));
- }
+ setMotifWmHints(connection(), m_window, mwmhints);
+}
+
+void QXcbWindow::changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two)
+{
+ xcb_client_message_event_t event;
+
+ event.response_type = XCB_CLIENT_MESSAGE;
+ event.format = 32;
+ event.window = m_window;
+ event.type = atom(QXcbAtom::_NET_WM_STATE);
+ event.data.data32[0] = set ? 1 : 0;
+ event.data.data32[1] = one;
+ event.data.data32[2] = two;
+ event.data.data32[3] = 0;
+ event.data.data32[4] = 0;
+
+ 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));
+}
- if (popup || tooltip) {
- const quint32 mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_SAVE_UNDER;
- const quint32 values[] = { true, true };
+Qt::WindowState QXcbWindow::setWindowState(Qt::WindowState state)
+{
+ if (state == m_windowState)
+ return state;
+
+ m_dirtyFrameMargins = true;
+
+ // unset old state
+ switch (m_windowState) {
+ case Qt::WindowMinimized:
+ Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
+ break;
+ case Qt::WindowMaximized:
+ changeNetWmState(false,
+ atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
+ atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
+ break;
+ case Qt::WindowFullScreen:
+ changeNetWmState(false, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
+ break;
+ default:
+ break;
+ }
- Q_XCB_CALL(xcb_change_window_attributes(xcb_connection(), m_window, mask, values));
+ // set new state
+ switch (state) {
+ case Qt::WindowMinimized:
+ {
+ xcb_client_message_event_t event;
+
+ event.response_type = XCB_CLIENT_MESSAGE;
+ event.format = 32;
+ event.window = m_window;
+ event.type = atom(QXcbAtom::WM_CHANGE_STATE);
+ event.data.data32[0] = XCB_WM_STATE_ICONIC;
+ event.data.data32[1] = 0;
+ event.data.data32[2] = 0;
+ event.data.data32[3] = 0;
+ event.data.data32[4] = 0;
+
+ 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));
+ }
+ break;
+ case Qt::WindowMaximized:
+ changeNetWmState(true,
+ atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ),
+ atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
+ break;
+ case Qt::WindowFullScreen:
+ changeNetWmState(true, atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
+ break;
+ case Qt::WindowNoState:
+ break;
+ default:
+ break;
}
- return QPlatformWindow::setWindowFlags(flags);
+ connection()->sync();
+
+ m_windowState = state;
+ return m_windowState;
}
-void QXcbWindow::setNetWmWindowTypes(Qt::WindowFlags flags)
+void QXcbWindow::setNetWmWindowFlags(Qt::WindowFlags flags)
{
// in order of decreasing priority
QVector<uint> windowTypes;
@@ -462,6 +842,127 @@ void QXcbWindow::setNetWmWindowTypes(Qt::WindowFlags flags)
windowTypes.count(), windowTypes.constData()));
}
+void QXcbWindow::updateMotifWmHintsBeforeMap()
+{
+ QtMotifWmHints mwmhints = getMotifWmHints(connection(), m_window);
+
+ if (window()->windowModality() != Qt::NonModal) {
+ switch (window()->windowModality()) {
+ case Qt::WindowModal:
+ mwmhints.input_mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL;
+ break;
+ case Qt::ApplicationModal:
+ default:
+ mwmhints.input_mode = MWM_INPUT_FULL_APPLICATION_MODAL;
+ break;
+ }
+ mwmhints.flags |= MWM_HINTS_INPUT_MODE;
+ } else {
+ mwmhints.input_mode = MWM_INPUT_MODELESS;
+ mwmhints.flags &= ~MWM_HINTS_INPUT_MODE;
+ }
+
+ if (window()->minimumSize() == window()->maximumSize()) {
+ // fixed size, remove the resize handle (since mwm/dtwm
+ // isn't smart enough to do it itself)
+ mwmhints.flags |= MWM_HINTS_FUNCTIONS;
+ if (mwmhints.functions == MWM_FUNC_ALL) {
+ mwmhints.functions = MWM_FUNC_MOVE;
+ } else {
+ mwmhints.functions &= ~MWM_FUNC_RESIZE;
+ }
+
+ if (mwmhints.decorations == MWM_DECOR_ALL) {
+ mwmhints.flags |= MWM_HINTS_DECORATIONS;
+ mwmhints.decorations = (MWM_DECOR_BORDER
+ | MWM_DECOR_TITLE
+ | MWM_DECOR_MENU);
+ } else {
+ mwmhints.decorations &= ~MWM_DECOR_RESIZEH;
+ }
+ }
+
+ if (window()->windowFlags() & Qt::WindowMinimizeButtonHint) {
+ mwmhints.flags |= MWM_HINTS_DECORATIONS;
+ mwmhints.decorations |= MWM_DECOR_MINIMIZE;
+ mwmhints.functions |= MWM_FUNC_MINIMIZE;
+ }
+ if (window()->windowFlags() & Qt::WindowMaximizeButtonHint) {
+ mwmhints.flags |= MWM_HINTS_DECORATIONS;
+ mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
+ mwmhints.functions |= MWM_FUNC_MAXIMIZE;
+ }
+ if (window()->windowFlags() & Qt::WindowCloseButtonHint)
+ mwmhints.functions |= MWM_FUNC_CLOSE;
+
+ setMotifWmHints(connection(), m_window, mwmhints);
+}
+
+void QXcbWindow::updateNetWmStateBeforeMap()
+{
+ QVector<xcb_atom_t> netWmState;
+
+ Qt::WindowFlags flags = window()->windowFlags();
+ if (flags & Qt::WindowStaysOnTopHint) {
+ netWmState.append(atom(QXcbAtom::_NET_WM_STATE_ABOVE));
+ netWmState.append(atom(QXcbAtom::_NET_WM_STATE_STAYS_ON_TOP));
+ } else if (flags & Qt::WindowStaysOnBottomHint) {
+ netWmState.append(atom(QXcbAtom::_NET_WM_STATE_BELOW));
+ }
+
+ if (window()->windowState() & Qt::WindowFullScreen) {
+ netWmState.append(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN));
+ }
+
+ if (window()->windowState() & Qt::WindowMaximized) {
+ netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ));
+ netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT));
+ }
+
+ if (window()->windowModality() != Qt::NonModal) {
+ netWmState.append(atom(QXcbAtom::_NET_WM_STATE_MODAL));
+ }
+
+ setNetWmState(netWmState);
+}
+
+void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
+{
+ xcb_window_t wid = m_window;
+
+ const bool isSupportedByWM = connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
+ if (m_netWmUserTimeWindow || isSupportedByWM) {
+ if (!m_netWmUserTimeWindow) {
+ m_netWmUserTimeWindow = xcb_generate_id(xcb_connection());
+ Q_XCB_CALL(xcb_create_window(xcb_connection(),
+ XCB_COPY_FROM_PARENT, // depth -- same as root
+ m_netWmUserTimeWindow, // window id
+ m_window, // parent window id
+ -1, -1, 1, 1,
+ 0, // border width
+ XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
+ m_screen->screen()->root_visual, // visual
+ 0, // value mask
+ 0)); // value list
+ wid = m_netWmUserTimeWindow;
+ xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW),
+ XCB_ATOM_WINDOW, 32, 1, &m_netWmUserTimeWindow);
+ xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME));
+ } else if (!isSupportedByWM) {
+ // WM no longer supports it, then we should remove the
+ // _NET_WM_USER_TIME_WINDOW atom.
+ xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW));
+ xcb_destroy_window(xcb_connection(), m_netWmUserTimeWindow);
+ m_netWmUserTimeWindow = XCB_NONE;
+ } else {
+ wid = m_netWmUserTimeWindow;
+ }
+ }
+ xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::_NET_WM_USER_TIME),
+ XCB_ATOM_CARDINAL, 32, 1, &timestamp);
+}
+
+
WId QXcbWindow::winId() const
{
return m_window;
@@ -469,8 +970,13 @@ WId QXcbWindow::winId() const
void QXcbWindow::setParent(const QPlatformWindow *parent)
{
+ // re-create for compatibility
+ create();
+
QPoint topLeft = geometry().topLeft();
- Q_XCB_CALL(xcb_reparent_window(xcb_connection(), window(), static_cast<const QXcbWindow *>(parent)->window(), topLeft.x(), topLeft.y()));
+
+ xcb_window_t xcb_parent_id = parent ? static_cast<const QXcbWindow *>(parent)->xcb_window() : m_screen->root();
+ Q_XCB_CALL(xcb_reparent_window(xcb_connection(), xcb_window(), xcb_parent_id, topLeft.x(), topLeft.y()));
}
void QXcbWindow::setWindowTitle(const QString &title)
@@ -500,56 +1006,87 @@ void QXcbWindow::lower()
Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
}
+void QXcbWindow::propagateSizeHints()
+{
+ // update WM_NORMAL_HINTS
+ xcb_size_hints_t hints;
+ memset(&hints, 0, sizeof(hints));
+
+ QRect rect = geometry();
+
+ xcb_size_hints_set_position(&hints, true, rect.x(), rect.y());
+ xcb_size_hints_set_size(&hints, true, rect.width(), rect.height());
+ xcb_size_hints_set_win_gravity(&hints, XCB_GRAVITY_STATIC);
+
+ QWindow *win = window();
+
+ QSize minimumSize = win->minimumSize();
+ QSize maximumSize = win->maximumSize();
+ QSize baseSize = win->baseSize();
+ QSize sizeIncrement = win->sizeIncrement();
+
+ if (minimumSize.width() > 0 || minimumSize.height() > 0)
+ xcb_size_hints_set_min_size(&hints, minimumSize.width(), minimumSize.height());
+
+ if (maximumSize.width() < QWINDOWSIZE_MAX || maximumSize.height() < QWINDOWSIZE_MAX)
+ xcb_size_hints_set_max_size(&hints,
+ qMin(XCOORD_MAX, maximumSize.width()),
+ qMin(XCOORD_MAX, maximumSize.height()));
+
+ if (sizeIncrement.width() > 0 || sizeIncrement.height() > 0) {
+ xcb_size_hints_set_base_size(&hints, baseSize.width(), baseSize.height());
+ xcb_size_hints_set_resize_inc(&hints, sizeIncrement.width(), sizeIncrement.height());
+ }
+
+ xcb_set_wm_normal_hints(xcb_connection(), m_window, &hints);
+}
+
void QXcbWindow::requestActivateWindow()
{
- Q_XCB_CALL(xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, XCB_TIME_CURRENT_TIME));
+ if (m_mapped){
+ updateNetWmUserTime(connection()->time());
+ Q_XCB_CALL(xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, connection()->time()));
+ }
connection()->sync();
}
-QPlatformGLContext *QXcbWindow::glContext() const
+QSurfaceFormat QXcbWindow::format() const
{
- if (!QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) {
- printf("no opengl\n");
- return 0;
- }
- if (!m_context) {
-#if defined(XCB_USE_GLX)
- QXcbWindow *that = const_cast<QXcbWindow *>(this);
- that->m_context = new QGLXContext(m_window, m_screen, widget()->platformWindowFormat());
-#elif defined(XCB_USE_EGL)
+ // ### return actual format
+ return m_requestedFormat;
+}
+
+#if defined(XCB_USE_EGL)
+QXcbEGLSurface *QXcbWindow::eglSurface() const
+{
+ if (!m_eglSurface) {
EGLDisplay display = connection()->egl_display();
- EGLConfig config = q_configFromQPlatformWindowFormat(display,widget()->platformWindowFormat(),true);
- QVector<EGLint> eglContextAttrs;
- eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
- eglContextAttrs.append(2);
- eglContextAttrs.append(EGL_NONE);
-
- EGLSurface eglSurface = eglCreateWindowSurface(display,config,(EGLNativeWindowType)m_window,0);
- QXcbWindow *that = const_cast<QXcbWindow *>(this);
- that->m_context = new QEGLPlatformContext(display, config, eglContextAttrs.data(), eglSurface, EGL_OPENGL_ES_API);
-#elif defined(XCB_USE_DRI2)
- QXcbWindow *that = const_cast<QXcbWindow *>(this);
- that->m_context = new QDri2Context(that);
-#endif
+ EGLConfig config = q_configFromGLFormat(display, window()->format(), true);
+ EGLSurface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_window, 0);
+
+ m_eglSurface = new QXcbEGLSurface(display, surface);
}
- return m_context;
+
+ return m_eglSurface;
}
+#endif
void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
{
- QWindowSurface *surface = widget()->windowSurface();
- if (surface) {
- QRect rect(event->x, event->y, event->width, event->height);
-
- surface->flush(widget(), rect, QPoint());
- }
+ QRect rect(event->x, event->y, event->width, event->height);
+ QWindowSystemInterface::handleSynchronousExposeEvent(window(), rect);
}
void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event)
{
- if (event->format == 32 && event->type == atom(QXcbAtom::WM_PROTOCOLS)) {
+ if (event->format != 32)
+ return;
+
+ if (event->type == atom(QXcbAtom::WM_PROTOCOLS)) {
if (event->data.data32[0] == atom(QXcbAtom::WM_DELETE_WINDOW)) {
- QWindowSystemInterface::handleCloseEvent(widget());
+ QWindowSystemInterface::handleCloseEvent(window());
+ } else if (event->data.data32[0] == atom(QXcbAtom::WM_TAKE_FOCUS)) {
+ connection()->setTime(event->data.data32[1]);
} else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_PING)) {
xcb_client_message_event_t reply = *event;
@@ -559,13 +1096,22 @@ void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *even
xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&reply);
xcb_flush(xcb_connection());
} else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_SYNC_REQUEST)) {
- if (!m_hasReceivedSyncRequest) {
- m_hasReceivedSyncRequest = true;
- printf("Window manager supports _NET_WM_SYNC_REQUEST, syncing resizes\n");
- }
+ connection()->setTime(event->data.data32[1]);
m_syncValue.lo = event->data.data32[2];
m_syncValue.hi = event->data.data32[3];
+ } else {
+ qWarning() << "unhandled WM_PROTOCOLS message:" << connection()->atomName(event->data.data32[0]);
}
+ } else if (event->type == atom(QXcbAtom::XdndEnter)) {
+ connection()->drag()->handleEnter(window(), event);
+ } else if (event->type == atom(QXcbAtom::XdndPosition)) {
+ connection()->drag()->handlePosition(window(), event, false);
+ } else if (event->type == atom(QXcbAtom::XdndLeave)) {
+ connection()->drag()->handleLeave(window(), event, false);
+ } else if (event->type == atom(QXcbAtom::XdndDrop)) {
+ connection()->drag()->handleDrop(window(), event, false);
+ } else {
+ qWarning() << "unhandled client message:" << connection()->atomName(event->type);
}
}
@@ -581,11 +1127,8 @@ void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *
QRect rect(xpos, ypos, event->width, event->height);
- if (rect == geometry())
- return;
-
QPlatformWindow::setGeometry(rect);
- QWindowSystemInterface::handleGeometryChange(widget(), rect);
+ QWindowSystemInterface::handleGeometryChange(window(), rect);
#if XCB_USE_DRI2
if (m_context)
@@ -593,6 +1136,22 @@ void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *
#endif
}
+void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event)
+{
+ if (event->window == m_window) {
+ m_mapped = true;
+ QWindowSystemInterface::handleMapEvent(window());
+ }
+}
+
+void QXcbWindow::handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event)
+{
+ if (event->window == m_window) {
+ m_mapped = false;
+ QWindowSystemInterface::handleUnmapEvent(window());
+ }
+}
+
static Qt::MouseButtons translateMouseButtons(int s)
{
Qt::MouseButtons ret = 0;
@@ -621,6 +1180,8 @@ static Qt::MouseButton translateMouseButton(xcb_button_t s)
void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
{
+ updateNetWmUserTime(event->time);
+
QPoint local(event->event_x, event->event_y);
QPoint global(event->root_x, event->root_y);
@@ -633,7 +1194,7 @@ void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
&& (modifiers & Qt::AltModifier))
|| (event->detail == 6 || event->detail == 7));
- QWindowSystemInterface::handleWheelEvent(widget(), event->time,
+ QWindowSystemInterface::handleWheelEvent(window(), event->time,
local, global, delta, hor ? Qt::Horizontal : Qt::Vertical);
return;
}
@@ -659,32 +1220,65 @@ void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
void QXcbWindow::handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global)
{
+ connection()->setTime(time);
+
Qt::MouseButtons buttons = translateMouseButtons(state);
Qt::MouseButton button = translateMouseButton(detail);
buttons ^= button; // X event uses state *before*, Qt uses state *after*
- QWindowSystemInterface::handleMouseEvent(widget(), time, local, global, buttons);
+ QWindowSystemInterface::handleMouseEvent(window(), time, local, global, buttons);
}
-void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *)
+void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
{
- QWindowSystemInterface::handleEnterEvent(widget());
+ connection()->setTime(event->time);
+
+ if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
+ || event->detail == XCB_NOTIFY_DETAIL_VIRTUAL
+ || event->detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL)
+ {
+ return;
+ }
+
+ QWindowSystemInterface::handleEnterEvent(window());
}
-void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *)
+void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
{
- QWindowSystemInterface::handleLeaveEvent(widget());
+ connection()->setTime(event->time);
+
+ if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
+ || event->detail == XCB_NOTIFY_DETAIL_INFERIOR)
+ {
+ return;
+ }
+
+ QWindowSystemInterface::handleLeaveEvent(window());
}
void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *)
{
- QWindowSystemInterface::handleWindowActivated(widget());
+ QWindowSystemInterface::handleWindowActivated(window());
+}
+
+static bool focusInPeeker(xcb_generic_event_t *event)
+{
+ if (!event) {
+ // FocusIn event is not in the queue, proceed with FocusOut normally.
+ QWindowSystemInterface::handleWindowActivated(0);
+ return true;
+ }
+ uint response_type = event->response_type & ~0x80;
+ return response_type == XCB_FOCUS_IN;
}
void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *)
{
- QWindowSystemInterface::handleWindowActivated(0);
+ // Do not set the active window to 0 if there is a FocusIn coming.
+ // There is however no equivalent for XPutBackEvent so register a
+ // callback for QXcbConnection instead.
+ connection()->addPeekFunc(focusInPeeker);
}
void QXcbWindow::updateSyncRequestCounter()
@@ -698,3 +1292,47 @@ void QXcbWindow::updateSyncRequestCounter()
m_syncValue.hi = 0;
}
}
+
+bool QXcbWindow::setKeyboardGrabEnabled(bool grab)
+{
+ if (!grab) {
+ xcb_ungrab_keyboard(xcb_connection(), XCB_TIME_CURRENT_TIME);
+ return true;
+ }
+ xcb_grab_keyboard_cookie_t cookie = xcb_grab_keyboard(xcb_connection(), false,
+ m_window, XCB_TIME_CURRENT_TIME,
+ XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
+ xcb_generic_error_t *err;
+ xcb_grab_keyboard_reply_t *reply = xcb_grab_keyboard_reply(xcb_connection(), cookie, &err);
+ bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
+ free(reply);
+ free(err);
+ return result;
+}
+
+bool QXcbWindow::setMouseGrabEnabled(bool grab)
+{
+ if (!grab) {
+ xcb_ungrab_pointer(xcb_connection(), XCB_TIME_CURRENT_TIME);
+ return true;
+ }
+ xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer(xcb_connection(), false, m_window,
+ (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
+ | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_ENTER_WINDOW
+ | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION),
+ XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
+ XCB_WINDOW_NONE, XCB_CURSOR_NONE,
+ XCB_TIME_CURRENT_TIME);
+ xcb_generic_error_t *err;
+ xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(xcb_connection(), cookie, &err);
+ bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS);
+ free(reply);
+ free(err);
+ return result;
+}
+
+void QXcbWindow::setCursor(xcb_cursor_t cursor)
+{
+ xcb_change_window_attributes(xcb_connection(), m_window, XCB_CW_CURSOR, &cursor);
+ xcb_flush(xcb_connection());
+}