Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Window captures include non-transparent border of background on Gnome #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RoelVdP opened this issue Nov 7, 2020 · 27 comments
Closed
Assignees
Labels

Comments

@RoelVdP
Copy link

RoelVdP commented Nov 7, 2020

Windows captures include an annoying, non-uniform and non-transparent border of background contents:

image
(Example screenshot showing ~2 pixel border on top, 10-15 pixel border on right, left, bottom. Capture was done using keyboard shortcut for "Capture active window")

Window captures should capture windows only, nothing around it. Trying to crop it manually often fails with +/- 1 pixel so it is hard to handle.

Please fix this. OS is Ubuntu 20.04.1 LTS, installed via snap, version is 1.7.2.

@RoelVdP
Copy link
Author

RoelVdP commented Nov 7, 2020

Is there any way to fix this via a workaround please?

@RoelVdP
Copy link
Author

RoelVdP commented Nov 7, 2020

In comparison, here is how Ubuntu captures Windows by default (using ALT+PRTSCR):

image

In other words, it seems the same dimensions, but it automatically sets the border pixels to transparent.

This may be doable by capturing the active window dimensions, or some other programming logic.

@RoelVdP RoelVdP changed the title Window captures include non-uniform border Window captures include non-transparent border of background Nov 7, 2020
@DamirPorobic
Copy link
Member

Is this Wayland or X11?

I don't think that there is a workaround. We take this kind of screenshot by asking the DE what the active window is and what the dimensions of the active window are. The DE provides basically Position, Width and Height of the active window. We don't know what part of those belongs to the window and what is just shadow for example. Then we take a screenshot of that provided region.

We could have a look if there is a way to explicitly ask for only the window without shadow. If we cannot ask something like this via the X11 interface, then there is probably not much we can do.

@ghost
Copy link

ghost commented Nov 10, 2020

Ubuntu Mate 20.04-1
Hi was playing around and it seems it might not always be caused by shadows. I disabled and it still shows up.
Seem to remember reading somewhere shadows were around 11px.
Avidemux and Untitled show the border but Pluma Preferences looks fine even though on screen it had shadow. Took Untitled.jpg and cropped as in Untitled Cropped Method.jpg. (BTW it was easier for me to just drag the corners of the crop window). 10 px worked there but was not needed on Pluma.jpg. Don't know why but tried with shadows off (Mate) on LibreOffice, KiCad, FreeCad, Inkscape and they show the extra border.
Alternate workaround is to take screenshot with working tool and then open in Ksnip to annotate.
Determined that Gnome Screenshot works in my Mate as described by OP in both cases of shadows on and off. Mate version tool works as per OP with shadows off but shows extra border with shadows on.

Untitled Cropped
Untitled Crop Method
Avidemux
Untitled
Pluma

@RoelVdP
Copy link
Author

RoelVdP commented Nov 13, 2020

Thank you

Fromn inxi -G:

Display: x11 server: X.Org 1.20.8

How about having a look at the default capture source code for Ubuntu and matching the capture approach?

@DamirPorobic
Copy link
Member

DamirPorobic commented Nov 14, 2020

Gnome is the DE, it doesn't have to relay on X11, it probably knows the stuff itself. I known for example that Spectacle under KDE Plasma doesn't speak directly to X11 or Wayland but rather to the kWin Desktop Manager and it provides all the stuff required for the screenshots, even the screenshots itself. We can't do that.

@DamirPorobic DamirPorobic self-assigned this Jan 23, 2021
@DamirPorobic
Copy link
Member

Been looking into this issue and might be problematic to resolve it in a generic way, X11 seems to be unaware of this region so it's not possible for us to detect what that border is and what the actual window . What we could do here is for Gnome always reduce the rect for that size (seems to be a fixed size), you would get in that case only the window without the region around it. Problematic is that Mate has same border thickness around the window, Gnome on the other hand has a lot smaller border at the top but anyhow, we could detect if Gnome or Mate and cut appropriately.

@DamirPorobic
Copy link
Member

DamirPorobic commented Jan 25, 2021

I think I have found a way how to get the width of this region, calling xprop -id <WindowId> returns the _GTK_FRAME_EXTENTS(CARDINAL) value for left, right, top and bottom offset that we just need to subtract from the rect.

Problem will be probably the snap because we need to invoke another application here. @LyzardKing can we just add xprop as one of the required applications to the snapcraft file?

@DamirPorobic DamirPorobic changed the title Window captures include non-transparent border of background Window captures include non-transparent border of background on Gnome Jan 26, 2021
DamirPorobic added a commit that referenced this issue Jan 26, 2021
DamirPorobic added a commit that referenced this issue Jan 26, 2021
@DamirPorobic
Copy link
Member

I believe I have found a workaround, it's a bit ugly, using an output from an external program, xprop to find out how much we should crop. My test on Ubuntu 20.10 worked and the window had no border anymore.

@LyzardKing I have added xprop to the snap file, I hope it's not breaking anything: b94a972

@LyzardKing
Copy link
Contributor

LyzardKing commented Jan 27, 2021

Yes, sorry but I just read this today.
It shouldn't be a problem to add xprop to the snap..

EDIT: should we add it to the flatpak as well?

@DamirPorobic
Copy link
Member

Does flatpak has this limitation that it needs to allow applications that are used, like we had it for snap (curl and ftp so far)?

Would be nice if someone could test the snap with Gnome and eventually the flatpak.

@LyzardKing
Copy link
Contributor

Yes, the flatpak either needs to set explicit access to a binatry on the host system or to add the binary in the package.
It would be better to test it before we change something.

@DamirPorobic
Copy link
Member

I have made the change already in the code and the snap package, would be nice if you could give it a try. To trigger it you just have to take a screenshot of an active window on Gnome.

@LyzardKing
Copy link
Contributor

It takes a screenshot of something that is under the ksnip window... not of the currently active window..

@DamirPorobic
Copy link
Member

You have clicked into the active window? Have you tried a small delay, like 1sec?

@LyzardKing
Copy link
Contributor

Ok.. I need to set the delay, otherwise it doesn't work. But I still get the border

@LyzardKing
Copy link
Contributor

The snap in the edge channel isn't updated yet...
I'll rebuild from source anche test that

@DamirPorobic
Copy link
Member

Yes, it's probably to fast, it takes the active window rect at the moment you trigger the screenshot and that is ksnip.

@LyzardKing
Copy link
Contributor

yes, I imagined as such. Shouldn't there be a 1s delay by default?

@LyzardKing
Copy link
Contributor

the package is not xprop but x11-utils

@LyzardKing
Copy link
Contributor

I'm testing now... I'll open a PR with the necessary changes

@DamirPorobic
Copy link
Member

The default delay is 200ms which is enough for ksnip to hide but not for a human to click two windows. You could probably get better results by activating any window and then hitting Global Hotkey for active window screenshot.

Regarding the snap build, strange, last build is 1 day ago
image

@DamirPorobic
Copy link
Member

Of course, you can't get just that simple application you have to get the whole util package...

@LyzardKing
Copy link
Contributor

yes, from before the change I think.. especially since it would have failed with the current change

@LyzardKing
Copy link
Contributor

I opened a PR but that was the only change necessary

@DamirPorobic
Copy link
Member

I need to merge it into the 1.8.1 branch, will do it tonight. Thanks for providing the PR.

@dregad
Copy link
Contributor

dregad commented Mar 5, 2021

I have ksnip 1.8.1 (installed via snap, on Ubuntu 20.04.2), yet I still see the borders around active window screenshots. Do I need any additional setup to fix this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants