Reimplement QXcbWindow::setMask() with xcb
authorUli Schlachter <psychon@znc.in>
Tue, 17 Jul 2012 21:40:45 +0000 (23:40 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 24 Jul 2012 22:59:32 +0000 (00:59 +0200)
This functionality does not need libXext. The bindings for the shape extension
from libxcb-shape is enough and is available without Xlib.

Change-Id: I9f1927024c64df00ace1666998c6c6deda2ef782
Signed-off-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/plugins/platforms/xcb/qxcbwindow.cpp
src/plugins/platforms/xcb/qxcbwindow.h
src/plugins/platforms/xcb/xcb.pro

index e51bab4..55ba045 100644 (file)
@@ -64,6 +64,9 @@
 #include <xcb/xcb_icccm.h>
 #undef class
 #include <xcb/xfixes.h>
+#ifndef QT_NO_SHAPE
+#  include <xcb/shape.h>
+#endif // QT_NO_SHAPE
 
 // xcb-icccm 3.8 support
 #ifdef XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS
 #ifdef XCB_USE_XLIB
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
-#ifndef QT_NO_SHAPE
-#  include <X11/extensions/shape.h>
-#endif // QT_NO_SHAPE
 #endif
 
 #if defined(XCB_USE_XINPUT2_MAEMO) || defined(XCB_USE_XINPUT2)
@@ -1704,11 +1704,11 @@ bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner)
     return true;
 }
 
-#if defined(XCB_USE_XLIB) && !defined(QT_NO_SHAPE)
+#if !defined(QT_NO_SHAPE)
 
-static inline XRectangle qRectToX11Rectangle(const QRect &r)
+static inline xcb_rectangle_t qRectToXCBRectangle(const QRect &r)
 {
-    XRectangle result;
+    xcb_rectangle_t result;
     result.x = qMax(SHRT_MIN, r.x());
     result.y = qMax(SHRT_MIN, r.y());
     result.width = qMin((int)USHRT_MAX, r.width());
@@ -1716,42 +1716,21 @@ static inline XRectangle qRectToX11Rectangle(const QRect &r)
     return result;
 }
 
-static inline Region qRegionToX11Region(const QRegion &region)
-{
-    if (region.isEmpty())
-        return None;
-    Region result = XCreateRegion();
-    if (!result)
-        return None;
-    const QVector<QRect> rects = region.rects();
-    if (rects.size() == 1) {
-        XRectangle xrect = qRectToX11Rectangle(region.boundingRect());
-        XUnionRectWithRegion(&xrect, result, result);
-    } else {
-        foreach (const QRect &r, rects) {
-            XRectangle xrect = qRectToX11Rectangle(r);
-            XUnionRectWithRegion(&xrect, result, result);
-        }
-    }
-    return result;
-}
-
-
 void QXcbWindow::setMask(const QRegion &region)
 {
-
-    Display *display = (Display *)connection()->xlib_display();
     if (region.isEmpty()) {
-        XShapeCombineMask(display, xcb_window(),
-                          ShapeBounding, 0, 0,
-                          None, ShapeSet);
+        xcb_shape_mask(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
+                       XCB_SHAPE_SK_BOUNDING, xcb_window(), 0, 0, XCB_NONE);
     } else {
-        XShapeCombineRegion(display, xcb_window(),
-                            ShapeBounding, 0, 0,
-                            qRegionToX11Region(region), ShapeSet);
+        QVector<xcb_rectangle_t> rects;
+        foreach (const QRect &r, region.rects())
+            rects.push_back(qRectToXCBRectangle(r));
+        xcb_shape_rectangles(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
+                             XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
+                             xcb_window(), 0, 0, rects.size(), &rects[0]);
     }
 }
 
-#endif // XCB_USE_XLIB && !QT_NO_SHAPE
+#endif // !QT_NO_SHAPE
 
 QT_END_NAMESPACE
index 0c4ec34..fa5ae63 100644 (file)
@@ -109,9 +109,9 @@ public:
 
     bool startSystemResize(const QPoint &pos, Qt::Corner corner);
 
-#if defined(XCB_USE_XLIB) && !defined(QT_NO_SHAPE)
+#if !defined(QT_NO_SHAPE)
     void setMask(const QRegion &region);
-#endif // XCB_USE_XLIB && !QT_NO_SHAPE
+#endif // !QT_NO_SHAPE
 
     xcb_window_t xcb_window() const { return m_window; }
     uint depth() const { return m_depth; }
index 70992fc..76cdbf4 100644 (file)
@@ -45,7 +45,6 @@ contains(QT_CONFIG, xcb-poll-for-queued-event) {
 # needed by GLX, Xcursor, XLookupString, ...
 contains(QT_CONFIG, xcb-xlib) {
     DEFINES += XCB_USE_XLIB
-    !contains(DEFINES, QT_NO_SHAPE):LIBS += -lXext
     LIBS += -lX11 -lX11-xcb
 
     linux-g++-maemo {
@@ -71,6 +70,8 @@ contains(QT_CONFIG, xcb-render) {
     LIBS += -lxcb-render -lxcb-render-util -lXrender
 }
 
+!contains(DEFINES, QT_NO_SHAPE):LIBS += -lxcb-shape
+
 #    DEFINES += XCB_USE_DRI2
 contains(DEFINES, XCB_USE_DRI2) {
     LIBS += -lxcb-dri2 -lEGL