Skip to content
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

Do not use gnome-screenshot on Linux if X11 can be used instead #7139

Closed
wants to merge 1 commit into from

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented May 6, 2023

Alternative to #7143

#7100 (comment)

although gnome-screenshot is widely present in Linux systems, in newer systems such as Ubuntu 20.04, there will be a full-screen animation effect when taking screenshots, and it is not easy to close. This feature may cause inconvenience to users in some tasks.

For this reason, a later comment in the thread requested that X11 be preferred over gnome-screenshot.

This PR modifies ImageGrab to not use gnome-screenshot if X11 is in use and Pillow has XCB support.

@@ -61,7 +61,9 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
left, top, right, bottom = bbox
im = im.crop((left - x0, top - y0, right - x0, bottom - y0))
return im
elif shutil.which("gnome-screenshot"):
elif not (
Image.core.HAVE_XCB and os.environ.get("XDG_SESSION_TYPE") == "x11"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if XDG_SESSION_TYPE is not set? Or alternatively, if the X11 connection is not configured properly (e.g. DISPLAY is not set)? The following is set on my Ubuntu 20.04 (in WSL), with the DISPLAY value being valid only when I do not forget to run my X server. I imagine the DISPLAY value could be invalid for other reasons as well.

$ set | grep DISPLAY
DISPLAY=:0
$ set | grep XDG
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
    local -a dirs=(${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions);
    for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share};
$

I think a better option is to use a try-except block instead to prefer X11 over gnome-screenshot: #7143

@radarhere
Copy link
Member Author

Closing in favour of #7143

@radarhere radarhere closed this May 13, 2023
@radarhere radarhere deleted the x11 branch May 13, 2023 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants