summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-01-12 16:04:33 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-01-18 10:26:19 +0000
commit23ba2f073cf163b379312d5086a880c7ec040209 (patch)
treedcda67322194de106fcb1fea22c5fc498a727b04 /src/plugins
parent5a628fdb98cf6d9fddb890069f7a8d327bdafadf (diff)
Windows QPA: Fix QScreen::grabWindow(0) for non-primary screens
Previously, the code grabbed the client rectangle of GetDesktopWindow(), which is always the primary screen. Fix by using the geometry of the QPlatformScreen. In addition, subtract x, y from the effective size when sizes < 0 were passed in as does XCB. Task-number: QTBUG-58110 Change-Id: I6ed439d2e1da8affd0a1475717d5570017fb1f2b Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/windows/qwindowsscreen.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index 23d43a95a5..7a885b462e 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -188,14 +188,30 @@ QWindowsScreen::QWindowsScreen(const QWindowsScreenData &data) :
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0);
-QPixmap QWindowsScreen::grabWindow(WId window, int x, int y, int width, int height) const
+QPixmap QWindowsScreen::grabWindow(WId window, int xIn, int yIn, int width, int height) const
{
- RECT r;
- HWND hwnd = window ? reinterpret_cast<HWND>(window) : GetDesktopWindow();
- GetClientRect(hwnd, &r);
+ QSize windowSize;
+ int x = xIn;
+ int y = yIn;
+ HWND hwnd = reinterpret_cast<HWND>(window);
+ if (hwnd) {
+ RECT r;
+ GetClientRect(hwnd, &r);
+ windowSize = QSize(r.right - r.left, r.bottom - r.top);
+ } else {
+ // Grab current screen. The client rectangle of GetDesktopWindow() is the
+ // primary screen, but it is possible to grab other screens from it.
+ hwnd = GetDesktopWindow();
+ const QRect screenGeometry = geometry();
+ windowSize = screenGeometry.size();
+ x += screenGeometry.x();
+ y += screenGeometry.y();
+ }
- if (width < 0) width = r.right - r.left;
- if (height < 0) height = r.bottom - r.top;
+ if (width < 0)
+ width = windowSize.width() - xIn;
+ if (height < 0)
+ height = windowSize.height() - yIn;
// Create and setup bitmap
HDC display_dc = GetDC(0);