diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-06-25 13:58:41 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-26 14:40:26 +0200 |
commit | 8e280d1e187b09651c7036bd76272342d52ce401 (patch) | |
tree | 9ddd14d0ec9690dc715bc4c6f60d1a0e2c47bf0d /src/plugins/platforms | |
parent | 799f0841a6f22ccaa03f3673ba91ad7b40f20612 (diff) |
QPlatformWindow: Add Window masks.
Add functionality for window masks to QPlatformWindow, which is
required to implement QWidget::setMask() in order to fix
the regression in functionality from Qt 4.8.
Change-Id: I2c2d5629f0b4c6d90e52595ad70b13559aab1f41
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsintegration.cpp | 2 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 44 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 1 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 54 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/xcb.pro | 1 |
7 files changed, 107 insertions, 0 deletions
diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 52950ecde5..7d4308d578 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -265,6 +265,8 @@ bool QWindowsIntegration::hasCapability(QPlatformIntegration::Capability cap) co return true; # endif // QT_OPENGL_ES_2 #endif // !QT_NO_OPENGL + case WindowMasks: + return true; default: return QPlatformIntegration::hasCapability(cap); } diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index e49b215422..aabea04c20 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -53,6 +53,7 @@ #include <QtGui/QGuiApplication> #include <QtGui/QScreen> #include <QtGui/QWindow> +#include <QtGui/QRegion> #include <private/qwindow_p.h> #include <QtGui/QWindowSystemInterface> @@ -1344,6 +1345,49 @@ void QWindowsWindow::setOpacity(qreal level) } } +static inline HRGN createRectRegion(const QRect &r) +{ + return CreateRectRgn(r.left(), r.top(), r.x() + r.width(), r.y() + r.height()); +} + +static inline void addRectToWinRegion(const QRect &rect, HRGN *winRegion) +{ + if (const HRGN rectRegion = createRectRegion(rect)) { + HRGN result = CreateRectRgn(0, 0, 0, 0); + if (CombineRgn(result, *winRegion, rectRegion, RGN_OR)) { + DeleteObject(winRegion); + *winRegion = result; + } + DeleteObject(rectRegion); + } +} + +static HRGN qRegionToWinRegion(const QRegion ®ion) +{ + const QVector<QRect> rects = region.rects(); + if (rects.isEmpty()) + return NULL; + const int rectCount = rects.size(); + if (rectCount == 1) + return createRectRegion(region.boundingRect()); + HRGN hRegion = createRectRegion(rects.front()); + for (int i = 1; i < rectCount; ++i) + addRectToWinRegion(rects.at(i), &hRegion); + return hRegion; +} + +void QWindowsWindow::setMask(const QRegion ®ion) +{ + if (region.isEmpty()) { + SetWindowRgn(m_data.hwnd, 0, true); + return; + } + const HRGN winRegion = qRegionToWinRegion(region); + // SetWindowRgn takes ownership. + if (!SetWindowRgn(m_data.hwnd, winRegion, true)) + DeleteObject(winRegion); +} + void QWindowsWindow::requestActivateWindow() { if (QWindowsContext::verboseWindows) diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 2fd401029e..743e10dff9 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -168,6 +168,7 @@ public: virtual QMargins frameMargins() const; virtual void setOpacity(qreal level); + virtual void setMask(const QRegion ®ion); qreal opacity() const { return m_opacity; } virtual void requestActivateWindow(); diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index c40ebe47bc..f7576fe19b 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -203,6 +203,7 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const case ThreadedPixmaps: return true; case OpenGL: return true; case ThreadedOpenGL: return false; + case WindowMasks: return true; default: return QPlatformIntegration::hasCapability(cap); } } diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 59e805fd0e..a4ee2a461c 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -44,6 +44,7 @@ #include <QtDebug> #include <QScreen> #include <QtGui/QIcon> +#include <QtGui/QRegion> #include "qxcbconnection.h" #include "qxcbscreen.h" @@ -97,6 +98,9 @@ #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 #ifdef XCB_USE_XINPUT2_MAEMO @@ -1698,4 +1702,54 @@ bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner) return true; } +#if defined(XCB_USE_XLIB) && !defined(QT_NO_SHAPE) + +static inline XRectangle qRectToX11Rectangle(const QRect &r) +{ + XRectangle result; + result.x = qMax(SHRT_MIN, r.x()); + result.y = qMax(SHRT_MIN, r.y()); + result.width = qMin((int)USHRT_MAX, r.width()); + result.height = qMin((int)USHRT_MAX, r.height()); + return result; +} + +static inline Region qRegionToX11Region(const QRegion ®ion) +{ + 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 ®ion) +{ + + Display *display = (Display *)connection()->xlib_display(); + if (region.isEmpty()) { + XShapeCombineMask(display, xcb_window(), + ShapeBounding, 0, 0, + None, ShapeSet); + } else { + XShapeCombineRegion(display, xcb_window(), + ShapeBounding, 0, 0, + qRegionToX11Region(region), ShapeSet); + } +} + +#endif // XCB_USE_XLIB && !QT_NO_SHAPE + QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index d383248428..0c4ec34269 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -109,6 +109,10 @@ public: bool startSystemResize(const QPoint &pos, Qt::Corner corner); +#if defined(XCB_USE_XLIB) && !defined(QT_NO_SHAPE) + void setMask(const QRegion ®ion); +#endif // XCB_USE_XLIB && !QT_NO_SHAPE + xcb_window_t xcb_window() const { return m_window; } uint depth() const { return m_depth; } QImage::Format imageFormat() const { return m_imageFormat; } diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro index 210b770a51..8e6fbc6c63 100644 --- a/src/plugins/platforms/xcb/xcb.pro +++ b/src/plugins/platforms/xcb/xcb.pro @@ -45,6 +45,7 @@ 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 { |