Set screen bounds for active window grab when compositor is disabled
ClosedPublic

Authored by anemeth on Feb 19 2018, 10:34 PM.

Details

Summary

It failed to capture the window area when the window was outside of the screen and showed a null image to the user when compositor was not enabled.
Now it only captures the area that is on the screen.

BUG: 390652

Diff Detail

Repository
R166 Spectacle
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
anemeth requested review of this revision.Feb 19 2018, 10:34 PM
anemeth created this revision.
anemeth edited the summary of this revision. (Show Details)Feb 19 2018, 10:39 PM
anemeth added a reviewer: Spectacle.
anemeth added a project: Spectacle.
anemeth added a subscriber: ngraham.

Thanks for the patch ;) I'll try to test as soon as a I find the time. Do you plan to submit more patches to KDE in the coming months?

Thanks for the patch! Is this really the right fix, though? If a window is half off the screen, I'm not sure that only capturing the visible part when in Active Window mode is what's expected. It's Active Window, not Visible part of Active Window.

macOS's screenshot tool captures the whole window in this case, for example.

anemeth added a comment.EditedFeb 19 2018, 11:11 PM

@rkflx I'm not sure...
@ngraham Only part of the visible screen can be captured when the compositor is disabled.
I don't know how possible is adding that feature. Maybe @rkflx knows.
That feature should be implemented in a revision of its own anyways.

@rkflx I'm not sure...

It would be a shame if not, because you are talented! Let me know if I can do anything to help you in that regard…

@ngraham Only part of the visible screen can be captured when the compositor is disabled.
I don't know how possible is adding that feature. Maybe @rkflx knows.

I guess you know more about this than I do ;), but it makes sense this way. When the compositor is enabled, though, it should probably work? IIRC I even tested this (not sure ATM). Does this break now?

IIRC I even tested this (not sure ATM). Does this break now?

It's interesting because it works if the window is off screen when "Active Window" mode is selected, but not when "Window Under Cursor" is selected.

ngraham accepted this revision.Feb 19 2018, 11:45 PM

Oh right, this only affects the non-composited use case. Apparently my VM uses compositing, and I can now reproduce the original issue. This patch does what @anemeth says it does and doesn't break the composited use case, or any other use cases I tested.

This revision is now accepted and ready to land.Feb 19 2018, 11:45 PM

Thanks, if I can confirm I'll commit (tomorrow).

broulik requested changes to this revision.Feb 20 2018, 8:42 AM
broulik added a subscriber: broulik.

Thanks for this patch! It does not take into account device pixel ratio, ie. screen scaling. Here the screenshots turn into half (a quarter) the size they should have since I'm on a 2x scaled screen.

This revision now requires changes to proceed.Feb 20 2018, 8:42 AM
davidedmundson added inline comments.
src/PlatformBackends/X11ImageGrabber.cpp
323–332

you are setting rect twice

anemeth updated this revision to Diff 27602.Feb 20 2018, 1:19 PM

Fixed scaling issue

anemeth marked an inline comment as done.Feb 20 2018, 1:20 PM
rkflx added a comment.EditedFeb 20 2018, 3:51 PM

For me there's still a weird case left where I can trigger the bug: Moving a window (I used Kate) under the bottom panel (or even lower, e.g only half of the height visible), Spectacle captures a null image. This happens after setting 1.5x scaling in kcmshell kcm_kscreen and restarting the session.

I don't get it for 1x scaling, though, and with compositing enabled it works for both scaling settings. Letting the window extend to the side is also fine (without the patch this used to break).

For me there's still a weird case left where I can trigger the bug: Moving a window (I used Kate) under the bottom panel (or even lower, e.g only half of the height visible), Spectacle captures a null image. This happens after setting 1.5x scaling in kcmshell kcm_kscreen and restarting the session

I can't reproduce the problem so I can't fix it either.

For me there's still a weird case left where I can trigger the bug: Moving a window (I used Kate) under the bottom panel (or even lower, e.g only half of the height visible), Spectacle captures a null image. This happens after setting 1.5x scaling in kcmshell kcm_kscreen and restarting the session

I can't reproduce the problem so I can't fix it either.

@ngraham Can you reproduce (with compositing off) or am I doing weird things?

Works for me:

rkflx added a comment.Feb 21 2018, 1:55 PM

Works for me:

Looks like you used Window Under Cursor, but here we are all about Active Window. Could you try again, please?

For me, with 1.5x scaling I still get a null image as soon as Kate touches the bottom edge of the screen (if it only touches the bottom panel it's fine, touching left/top/right is good too).

Works for me:

Looks like you used Window Under Cursor, but here we are all about Active Window. Could you try again, please?

For me, with 1.5x scaling I still get a null image as soon as Kate touches the bottom edge of the screen (if it only touches the bottom panel it's fine, touching left/top/right is good too).

Oops, my bad. I tried again with 1.5x scaling, Active Window, and the compositor off and I can reproduce. @anemeth, here are the exact conditions under which you should be able to reproduce:

  • Whole session uses 1.5x scaling (have to reboot afterwards)
  • Kate window goes below the panel
  • Compositor off (don't forgot to turn it off again after rebooting)
  • Using Active Window mode
rkflx added a comment.Feb 21 2018, 2:07 PM

Could this be an off-by-one error, perhaps some coordinate system mixup wrt. QRegion?

anemeth added a comment.EditedFeb 21 2018, 2:22 PM
  • Whole session uses 1.5x scaling (have to reboot afterwards)
  • Kate window goes below the panel
  • Compositor off (don't forgot to turn it off again after rebooting)
  • Using Active Window mode

I still can't reproduce the problem.
I even added the default bottom panel too to see if that is somehow influencing it, but no.
What am I doing wrong?

Use of Latte Dock, maybe? No idea.

Use of Latte Dock, maybe? No idea.

I moved Latte Dock to the side, still works perfectly.

rkflx added a comment.Feb 21 2018, 2:48 PM

I still can't reproduce the problem.
What am I doing wrong?

Perhaps a config/version thing? I cleared my config, now it's working. Let me bisect that tonight, so we know whether it'll affect users or not.

rkflx accepted this revision.Feb 28 2018, 9:16 PM

@broulik I guess we have solved the HiDPI problem you reported. Any additional objections? Patch LGTM.

@anemeth Thanks, all issues fixed and I could not break it in any other ways. If you'd like to solve a similar bug, there is Bug 390787.

@ngraham As this is strictly a bug fix and in terms of risk for regressions this only adds an additional else, I tend to land this on stable. Is this okay with you?


Perhaps a config/version thing? I cleared my config, now it's working. Let me bisect that […]

After resetting the config a second time, suddenly the bug was there again! IOW, config related bug was a red herring.

However, I found a simpler way to reproduce. For me, resizing the (VM) display was enough to either fix or trigger the bug.

Could this be an off-by-one error

Yes, it can ;)

In getToplevelPixmap, adding debug output like this

QPixmap nativePixmap = getPixmapFromDrawable(rootWindow, rect);
qDebug() << rect << endl << nativePixmap;

and decreasing the screen height results in this (the null images result from xcb_image_get failure, convertFromNative is not even reached):

QRect(150,268 712x706)
QPixmap(null)

QRect(150,268 712x691)
QPixmap(QSize(712, 691),...)

QRect(150,268 712x680)
QPixmap(QSize(712, 680),...)

QRect(150,268 712x674)
QPixmap(QSize(712, 674),...)

QRect(150,268 712x664)
QPixmap(null)

Only the height is changing, sometimes resulting in failure, sometimes in success.

If y'all don't mind (as it took me some time to find the culprit), I'll make this a follow-up patch. Follow along in D10930: Capture reliably with compositing off regardless of screen size.

@ngraham As this is strictly a bug fix and in terms of risk for regressions this only adds an additional else, I tend to land this on stable. Is this okay with you?

Sounds good to me!

rkflx added a comment.Mar 6 2018, 12:30 PM

@broulik You are blocking arc land.

Let me know if there are still concerns, otherwise I'll land the Diff anyway tonight.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 6 2018, 8:29 PM
This revision was automatically updated to reflect the committed changes.