GNOME Bugzilla – Bug 682626
Area Screenshot fails with "Unable to capture a screenshot"
Last modified: 2020-11-26 15:45:55 UTC
Created attachment 222353 [details] Error Message Recently when trying to capture area selection screenshots using gnome-screenshot in 64 bit Fedora 17, I get intermittent failures, with a message of "Unable to capture a screenshot" "All possible methods failed". Instead of giving me a cursor to make my area selection, both of my monitors flash, as it tried to take a screenshot, and then it displays that error message. It seems like it will always fail once I get that first failure until I change my active windows and try again. I have two monitors, one being my Lenovo T520 in a dock, and an external hooked up to the dock via DVI, both are 1080p displays (if any of that matters). I preupgraded from F16 to F17, but I only noticed this happening a few weeks ago, and I upgraded earlier than that. Package Info: gnome-screenshot-3.4.1-2.fc17.x86_64
Reproduced on Fedora Beta 19 with file File-Roller 3.8.2
Sorry mistake on comment : reproduced on Fedora beta 19 with gnome-screenshot 3.8.2
Created attachment 257274 [details] [review] gnome-screenshot_arearapidclick.patch Problem is due to a case where the GdkRectangle struct isn't null ; however due to the rapid click, widht-height are 0, hence the bug. Please consider the attached patch, which corrects this behavior. At worst, gnome-screenshot will now fall back to "capture the whole screen".
I don't think the above mentioned patch is the right thing to do, as it means that the behavior is to take the full screenshot instead of showing the crosshairs. What should happen is that if the rectangle is empty, it should wait with the crosshairs. I want to point out that while this bug has sat idle for 4 years, there's been plenty of reports of this in other places: https://github.com/linuxmint/Cinnamon/issues/3981 https://github.com/mate-desktop/mate-utils/issues/37 https://unix.stackexchange.com/questions/344319/run-gnome-screenshot-a-with-cinnamon-keyboard-shortcut i.e. it's 2017 and anything that uses gnome-screenshot still has this issue where pressing Shift+PrtScn for a few extra milliseconds leads to gnome-screenshot -a not working.
I suspect that this is not an issue in GNOME proper, because the screenshot uses the internal screenshot capabilities and it's only a problem on other Desktop Environments that try to use gnome-screenshot command. In that case, the application falls back to using the X11 screen grabbing and that's the one that fails. It seems to me that the issue might be here: https://github.com/GNOME/gnome-screenshot/blob/master/src/screenshot-area-selection.c#L266 The code is trying to grab the keyboard and if it can't do that, it just dies. No retries of any kind. My suspicion is that if the PrtScn key is pressed while the program is starting, it can't grab the keyboard and thus it fails. A possible fix would be to retry grabbing the keyboard until a timeout is reached.
(In reply to Margarita Manterola from comment #5) > I suspect that this is not an issue in GNOME proper, because the screenshot > uses the internal screenshot capabilities and it's only a problem on other > Desktop Environments that try to use gnome-screenshot command. In that case, > the application falls back to using the X11 screen grabbing and that's the > one that fails. > > It seems to me that the issue might be here: > https://github.com/GNOME/gnome-screenshot/blob/master/src/screenshot-area- > selection.c#L266 > > The code is trying to grab the keyboard and if it can't do that, it just > dies. No retries of any kind. > > My suspicion is that if the PrtScn key is pressed while the program is > starting, it can't grab the keyboard and thus it fails. A possible fix would > be to retry grabbing the keyboard until a timeout is reached. Thanks for looking into this -- it sounds like a plausible explanation for this issue. I would accept a patch that adds a retry in case gdk_device_grab() indicates that another grab is already in effect.
Patch failed to materialise in 3 years, and to be honest other desktop environments should not expect gnome-screenshot to work for them; it's the *GNOME* screenshot tool, not "generic X11 screenshot tool". The X11 fallback code path is there mostly for legacy reasons, and it's not meant to exist forever. If somebody wishes to write a patch, they are absolutely free to open a merge request: https://gitlab.gnome.org/GNOME/gnome-screenshot/