bpo-40767: Allow pure Wayland to get default XDG web browser (GH-20382)

Would be nice to backport to python 3.7+. I don't think it's worth the hassle to backport this all the way down to 3.10. But I'll let the maintainers decide.

This is hard to test because the test setup already includes this [environment variable](https://github.com/python/cpython/blob/master/Lib/test/pythoninfo.py#L292)

Let me know if something doesn't match the PR guidelines. This is my first PR in the python source code.
This commit is contained in:
Jeremy Attali 2020-06-03 08:42:33 -04:00 committed by GitHub
parent fa7ab6aa0f
commit c822efeda9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -545,7 +545,7 @@ def register_standard_browsers():
register(browser, None, BackgroundBrowser(browser)) register(browser, None, BackgroundBrowser(browser))
else: else:
# Prefer X browsers if present # Prefer X browsers if present
if os.environ.get("DISPLAY"): if os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"):
try: try:
cmd = "xdg-settings get default-web-browser".split() cmd = "xdg-settings get default-web-browser".split()
raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL) raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)

View File

@ -0,0 +1,3 @@
:mod:`webbrowser` now properly finds the default browser in pure Wayland
systems by checking the WAYLAND_DISPLAY environment variable. Patch
contributed by Jérémy Attali.