Bug 96822 - snapshots of windows which extend offscreen turn to garbage
Summary: snapshots of windows which extend offscreen turn to garbage
Status: RESOLVED UNMAINTAINED
Alias: None
Product: ksnapshot
Classification: Applications
Component: general (show other bugs)
Version: 0.7
Platform: RedHat Enterprise Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Richard Moore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-12 08:14 UTC by Adam Wiggins
Modified: 2018-09-04 04:20 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
screenshot (33.10 KB, image/png)
2014-07-31 01:02 UTC, kdebugs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Wiggins 2005-01-12 08:14:35 UTC
Version:           0.7 (using KDE KDE 3.3.1)
Installed from:    RedHat RPMs
OS:                Linux

My KMix window is about twice the width of my screen.  When taking a snapshot (to submit a bug report about it), I ended up with this:

http://dusk.org/~adam/bugzilla/ksnapshot.png

This was using "window under cursor" mode.  I was not surprised that it couldn't get the contents of the window that were not visible on screen, but it seems like it should handle this more gracefully - perhaps by clipping the final image, or just filling in the remaining space with black.
Comment 1 Brad Hards 2005-01-29 23:33:45 UTC
I don't see garbage (just black sections - probably a change to Qt), but it is still wrong (because we are  using QPixmap::grabRegion(), and that has a warning that it isn't safe to grab off screen regions).

I've got a patch that just trims to the current screen size:
--- ksnapshot.cpp       11 Dec 2004 21:40:39 -0000      1.78
+++ ksnapshot.cpp       29 Jan 2005 22:23:59 -0000
@@ -498,8 +498,20 @@ void KSnapshot::performGrab()
                y = newy;
            }
        }

+       XWindowAttributes rootAttributes;
+       if ( XGetWindowAttributes( qt_xdisplay(), root, &rootAttributes ) ) {
+           if ( ( x + w ) > rootAttributes.width ) {
+               // then the window is partly off the screen
+               w = rootAttributes.width - x;
+           }
+           if ( ( y + h ) > rootAttributes.height ) {
+               // then the window is partly off the screen
+               h = rootAttributes.height - y;
+           }
+       }
+
        snapshot = QPixmap::grabWindow( qt_xrootwin(), x, y, w, h );

 #ifdef HAVE_X11_EXTENSIONS_SHAPE_H

Is that OK to commit?
Comment 2 Brad Hards 2005-01-30 10:14:40 UTC
That is committed now.
Comment 3 Yuriy Kozlov 2008-07-14 20:28:46 UTC
According to https://bugs.launchpad.net/ubuntu/+source/kdegraphics/+bug/204358 this is still/again a problem in KDE 3.5 and KDE 4.0
Comment 4 Jonathan Thomas 2008-09-07 16:51:11 UTC
Yes, this still is an issue in KDE 4.1.1. Please reopen the bug.
Comment 5 Jonathan Thomas 2009-01-07 15:54:48 UTC
Still a problem in KDE 4.1.85, reopening.
Comment 6 Jonathan Thomas 2009-06-13 22:33:58 UTC
Here's an adaptation of the patch for KDE 4.3:

Index: kdegraphics-4.2.90/ksnapshot/windowgrabber.cpp
===================================================================
--- kdegraphics-4.2.90.orig/ksnapshot/windowgrabber.cpp	2009-06-12 23:16:28.000000000 -0400
+++ kdegraphics-4.2.90/ksnapshot/windowgrabber.cpp	2009-06-12 23:37:00.000000000 -0400
@@ -140,6 +140,18 @@
 QPixmap grabWindow( Window child, int x, int y, uint w, uint h, uint border,
 		    QString *title=0, QString *windowClass=0 )
 {
+    XWindowAttributes rootAttributes;
+    if ( XGetWindowAttributes( QX11Info::display(), QX11Info::appRootWindow(), &rootAttributes ) ) {
+        if ( ( x + w ) > rootAttributes.width ) {
+            // then the window is partly off the screen
+            w = rootAttributes.width - x;
+        }
+        if ( ( y + h ) > rootAttributes.height ) {
+            // then the window is partly off the screen
+            h = rootAttributes.height - y;
+        }
+    }
+
     QPixmap pm( QPixmap::grabWindow( QX11Info::appRootWindow(), x, y, w, h ) );
 
     KWindowInfo winInfo( findRealWindow(child), NET::WMVisibleName, NET::WM2WindowClass );
Comment 7 Elias Probst 2012-12-29 20:44:58 UTC
Can't reproduce this anymore on KDE 4.10 RC1 (4.9.95).
IIRC since KDE 4.5 the window screenshot is grabbed from kwin directly to:
* also include the window decoration's shadow
* create screenshots of windows which are (partially) covered by other windows
* create screenshots of (partially) offscreen windows

It even works when disabling compositing.

I don't know what would happen when using a different WM than kwin, but I don't think that really counts here.

So I'd vote for closing this bug. Any objections?
Comment 8 kdebugs 2014-07-31 01:02:41 UTC
Created attachment 88044 [details]
screenshot

Ubuntu 14.04 (KDE 4.13.2)
Comment 9 Andrew Crouthamel 2018-09-04 04:20:59 UTC
Hello! Sorry to be the bearer of bad news, but this project has been unmaintained for many years and I will be closing this bug. Spectacle is the replacement for ksnapshot now. Please test again and file a new bug for Spectacle if you still have issues. Thank you!