Bug 47893 - Snapshots with Keramik are muddled at the edges
Summary: Snapshots with Keramik are muddled at the edges
Status: RESOLVED FIXED
Alias: None
Product: ksnapshot
Classification: Applications
Component: general (show other bugs)
Version: 0.5
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Maksim Orlovich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-15 16:22 UTC by Mike McBride
Modified: 2003-02-06 04:28 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch that makes KSnapshot handle XShape'd windows. (2.77 KB, patch)
2003-01-26 05:41 UTC, Maksim Orlovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike McBride 2002-09-15 16:22:08 UTC
Version:           0.5 (using KDE 3.0.7 (KDE 3.1 beta1))
Installed from:    compiled sources
Compiler:          gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)
OS:          Linux (i686) release 2.4.7-10

When you take a snapshot of a window (not the entire screen), using the Keramik style, the "background" information on either side of the window name (which appears to extend upwards from the window) is garbage.

To reproduce:

Set the desktop background to white via KControl.

Start KSnapshot while in the Keramic mode.

Start KWord.  The first dialog box is smaller than the entire desktop (Choose template dialog). Minimize the other windows (so you only have ksnapshot, and the Choose template dialog window against a white background.

In KSnapshot, place a mark in the checkbox labeled "only grab the window containing the pointer".  

Now click "New Snapshot".

Click once in the Choose dialog box window.  Save the file, then view the file with konqueror.  Notice all the garbage around the top edge of the snapshot.

I will be happy to provide snapshots if you need them.
Comment 1 Maksim Orlovich 2003-01-26 03:51:58 UTC
I have a prototype patch for this, which queries XShape for the boundaries... Unfortunately, it's 
not smart enough to handle fully general windows, and the cleanest way I can see of doing this 
fully is by essentially doing span buffers. I guess I'll finish it up, and submit a patch.  
 
Mike: if you'll be taking any more screenshots soon, I can attach the prototype patch - it should 
be good enough for Keramik. 
 
Comment 2 Maksim Orlovich 2003-01-26 05:41:22 UTC
Created attachment 810 [details]
Patch that makes KSnapshot handle XShape'd windows.

Turns out this is easier than I thought, thanks to QRegion. 
Patch attached - please review.
Comment 3 Richard Moore 2003-01-26 12:55:05 UTC
Subject: Re:  Snapshots with Keramik are muddled at the edges

Maksim Orlovich wrote:
> 
> ------- You are receiving this mail because: -------
> You are the assignee for the bug, or are watching the assignee.
> 
> http://bugs.kde.org/show_bug.cgi?id=47893
> mo002j@mail.rochester.edu changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>          AssignedTo|rich@kde.org                |mo002j@mail.rochester.edu
> 
> ------- Additional Comments From mo002j@mail.rochester.edu  2003-01-26 03:51 -------
> I have a prototype patch for this, which queries XShape for the boundaries... Unfortunately, it's
> not smart enough to handle fully general windows, and the cleanest way I can see of doing this
> fully is by essentially doing span buffers. I guess I'll finish it up, and submit a patch.

You might find using QRegion helpful for calculating the clipping
boundaries. Please cc the patch to me when it is complete as it should
also be applied to the print screen shortcuts in kwin.

Cheers

Rich.

> 
> Mike: if you'll be taking any more screenshots soon, I can attach the prototype patch - it should
> be good enough for Keramik.

Comment 4 Maksim Orlovich 2003-02-06 04:28:03 UTC
Subject: kdegraphics/ksnapshot

CVS commit by orlovich: 


- Handle XShaped windows when taking single-window screenshots - clears the masked-away 
areas with black. Fixes weird random stuff showing up around the "bubble" when taking screenshots with the Keramik KWin deco. (#47893) 

CCMAIL: 47893-done@bugs.kde.org


  A            configure.in.in   1.1
  M +45 -2     ksnapshot.cpp   1.54
  M +1 -0      ksnapshot.h   1.21


--- kdegraphics/ksnapshot/ksnapshot.cpp  #1.53:1.54
@@ -52,4 +52,11 @@
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
+
+#include <config.h>
+
+#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
+#include <X11/extensions/shape.h>
+#endif
+
 #include <kglobal.h>
 
@@ -69,4 +76,10 @@ KSnapshot::KSnapshot(QWidget *parent, co
     KStartupInfo::appStarted();
 
+#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
+    int tmp1, tmp2;
+    //Check whether the extension is available
+    haveXShape = XShapeQueryExtension( qt_xdisplay(), &tmp1, &tmp2 );
+#endif
+
     grabber->show();
     grabber->grabMouse( waitCursor );
@@ -359,4 +372,34 @@ void KSnapshot::performGrab()
 
         snapshot = QPixmap::grabWindow( qt_xrootwin(), x, y, w, h );
+
+#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
+        //No XShape - no work.
+        if (haveXShape) {
+            //As the first step, get the mask from XShape.
+            int count, order;
+            XRectangle* rects = XShapeGetRectangles( qt_xdisplay(), child,
+                                                     ShapeBounding, &count, &order);
+            if (rects) {
+                //Create a region from the rectangles the window contents.
+                QRegion contents;
+                for (int pos = 0; pos < count; pos++)
+                    contents += QRegion(rects[pos].x, rects[pos].y,
+                                        rects[pos].width, rects[pos].height);
+                XFree(rects);
+
+                //Create the bounding box.
+                QRegion bbox(0, 0, snapshot.width(), snapshot.height());
+
+                //Get the masked away are
+                QRegion maskedAway = bbox - contents;
+                QMemArray<QRect> maskedAwayRects = maskedAway.rects();
+
+                QPainter p(&snapshot);
+                for (int pos = 0; pos < maskedAwayRects.count(); pos++)
+                    p.fillRect(maskedAwayRects[pos], Qt::black);
+                p.end();
+            }
+        }
+#endif
     } 
     else {

--- kdegraphics/ksnapshot/ksnapshot.h  #1.20:1.21
@@ -92,4 +92,5 @@ private:
     QString filename;
     bool modified;
+    bool haveXShape;
 };
 


Comment 5 Mike McBride 2003-02-06 04:37:14 UTC
Subject: Re:  Snapshots with Keramik are muddled at the edges

On Thursday February 06 2003 03:28 am, you wrote:

> CVS commit by orlovich:
>
>
> - Handle XShaped windows when taking single-window screenshots - clears the
> masked-away areas with black. Fixes weird random stuff showing up around
> the "bubble" when taking screenshots with the Keramik KWin deco. (#47893)

Hi,

Thank you for fixing this problem.  I have only one other question:  Is there 
any way to make this configurable?  

Unfortunatly for those of us who are writing KDE documentation, the black 
surrounding the window is almost as bad as the previous problem.  What we 
have need of, is a white background where the window does not cover.  The 
white, blends in with the white help pages, and makes the snapshots look good 
on the "page".  The black is going to be obtrusive.

(Sorry if this sounds like I am ungrateful.  I really do appreciate the time 
you put into this)

Comment 6 Maksim Orlovich 2003-02-06 04:45:23 UTC
Subject: Re:  Snapshots with Keramik are muddled at the edges

> Unfortunatly for those of us who are writing KDE documentation, the black
> surrounding the window is almost as bad as the previous problem.  What we
> have need of, is a white background where the window does not cover.  The
> white, blends in with the white help pages, and makes the snapshots look
> good on the "page".  The black is going to be obtrusive.

Will it work right if the background is transparent? (And would it be some 
sort of a problem for the image formats you use?). There is certainly no 
technical difficulty in making this configurable - but there might be a UI 
difficulty of sorts, since KSnapshot doesn't have a config dialog.

What's the timeframe for when you'll need this? 

Thanks,
Maksim