Reimplement QXcbWindow::startSystemResize() with xcb
authorUli Schlachter <psychon@znc.in>
Thu, 21 Jun 2012 19:01:48 +0000 (21:01 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 22 Jun 2012 09:47:24 +0000 (11:47 +0200)
This function just sends a ClientMessage to the window manager. XCB can
do this fine and there is no need to require Xlib for the job.

Change-Id: Iad3d78c393c1f439fff987fa19b4d82513810930
Signed-off-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/plugins/platforms/xcb/qxcbwindow.cpp
src/plugins/platforms/xcb/qxcbwindow.h

index a1ac5c5..59e805f 100644 (file)
@@ -1670,37 +1670,32 @@ void QXcbWindow::setCursor(xcb_cursor_t cursor)
     xcb_flush(xcb_connection());
 }
 
-#ifdef XCB_USE_XLIB
-
 bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner)
 {
     const xcb_atom_t moveResize = connection()->atom(QXcbAtom::_NET_WM_MOVERESIZE);
     if (!connection()->wmSupport()->isSupportedByWM(moveResize))
         return false;
-    XEvent xev;
-    xev.xclient.type = ClientMessage;
-    xev.xclient.message_type = moveResize;
-    Display *display = (Display *)connection()->xlib_display();
-    xev.xclient.display = display;
-    xev.xclient.window = xcb_window();
-    xev.xclient.format = 32;
+    xcb_client_message_event_t xev;
+    xev.response_type = XCB_CLIENT_MESSAGE;
+    xev.type = moveResize;
+    xev.window = xcb_window();
+    xev.format = 32;
     const QPoint globalPos = window()->mapToGlobal(pos);
-    xev.xclient.data.l[0] = globalPos.x();
-    xev.xclient.data.l[1] = globalPos.y();
+    xev.data.data32[0] = globalPos.x();
+    xev.data.data32[1] = globalPos.y();
     const bool bottom = corner == Qt::BottomRightCorner || corner == Qt::BottomLeftCorner;
     const bool left = corner == Qt::BottomLeftCorner || corner == Qt::TopLeftCorner;
     if (bottom)
-        xev.xclient.data.l[2] = left ? 6 : 4; // bottomleft/bottomright
+        xev.data.data32[2] = left ? 6 : 4; // bottomleft/bottomright
     else
-        xev.xclient.data.l[2] = left ? 0 : 2; // topleft/topright
-    xev.xclient.data.l[3] = Button1;
-    xev.xclient.data.l[4] = 0;
-    XUngrabPointer(display, CurrentTime);
-    XSendEvent(display, m_screen->root(), False,
-               SubstructureRedirectMask | SubstructureNotifyMask, &xev);
+        xev.data.data32[2] = left ? 0 : 2; // topleft/topright
+    xev.data.data32[3] = Button1;
+    xev.data.data32[4] = 0;
+    xcb_ungrab_pointer(connection()->xcb_connection(), XCB_CURRENT_TIME);
+    xcb_send_event(connection()->xcb_connection(), false, m_screen->root(),
+                   XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
+                   (const char *)&xev);
     return true;
 }
 
-#endif // XCB_USE_XLIB
-
 QT_END_NAMESPACE
index 6cafa03..d383248 100644 (file)
@@ -107,9 +107,7 @@ public:
 
     QSurfaceFormat format() const;
 
-#ifdef XCB_USE_XLIB
     bool startSystemResize(const QPoint &pos, Qt::Corner corner);
-#endif // XCB_USE_XLIB
 
     xcb_window_t xcb_window() const { return m_window; }
     uint depth() const { return m_depth; }