summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2011-08-19 11:46:51 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-08-19 11:49:17 (GMT)
commitaaf94776ce1034ec2b2402b9ca0e5cf7c7848b12 (patch)
tree7855f45480a78b50ea9affea16e2fd11216f48d4 /src
parent3a3b4a0aca8ca31bb135b456eb58763733cf047f (diff)
downloadQt-aaf94776ce1034ec2b2402b9ca0e5cf7c7848b12.zip
Qt-aaf94776ce1034ec2b2402b9ca0e5cf7c7848b12.tar.gz
Qt-aaf94776ce1034ec2b2402b9ca0e5cf7c7848b12.tar.bz2
Fix QPixmap::grabWindow() on Mac OS X Lion
The old approach was not the recommended one and although it worked on Mac OS X 10.6 it did not work on 10.7. The new approach works correctly on 10.6 and 10.7, so the fix is applied for both versions. Task-number: QTBUG-19824 Merge-request: 1332 Reviewed-by: sroedal
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qpixmap_mac.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp
index 6872cfa..45f00a0 100644
--- a/src/gui/image/qpixmap_mac.cpp
+++ b/src/gui/image/qpixmap_mac.cpp
@@ -841,6 +841,31 @@ static void qt_mac_grabDisplayRect(CGDirectDisplayID display, const QRect &displ
}
// Returns a pixmap containing the screen contents at rect.
+static QPixmap qt_mac_grabScreenRect_10_6(const QRect &rect)
+{
+ const int maxDisplays = 128; // 128 displays should be enough for everyone.
+ CGDirectDisplayID displays[maxDisplays];
+ CGDisplayCount displayCount;
+ const CGRect cgRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
+ const CGDisplayErr err = CGGetDisplaysWithRect(cgRect, maxDisplays, displays, &displayCount);
+
+ if (err && displayCount == 0)
+ return QPixmap();
+ QPixmap windowPixmap(rect.size());
+ for (uint i = 0; i < displayCount; ++i) {
+ const CGRect bounds = CGDisplayBounds(displays[i]);
+ // Translate to display-local coordinates
+ QRect displayRect = rect.translated(qRound(-bounds.origin.x), qRound(-bounds.origin.y));
+ // Adjust for inverted y axis.
+ displayRect.moveTop(qRound(bounds.size.height) - displayRect.y() - rect.height());
+ QCFType<CGImageRef> image = CGDisplayCreateImageForRect(displays[i], bounds);
+ QPixmap pix = QPixmap::fromMacCGImageRef(image);
+ QPainter painter(&windowPixmap);
+ painter.drawPixmap(-bounds.origin.x, -bounds.origin.y, pix);
+ }
+ return windowPixmap;
+}
+
static QPixmap qt_mac_grabScreenRect(const QRect &rect)
{
if (!resolveOpenGLSymbols())
@@ -916,7 +941,8 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
QRect rect(globalCoord.x() + x, globalCoord.y() + y, w, h);
#ifdef QT_MAC_USE_COCOA
- return qt_mac_grabScreenRect(rect);
+ return (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) ?
+ qt_mac_grabScreenRect_10_6(rect) : qt_mac_grabScreenRect(rect);
#else
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {