Skip to content

Commit 140d9ec

Browse files
authored
gh-85644: webbrowser: Use $XDG_CURRENT_DESKTOP to check desktop (GH-21731)
Usage of $GNOME_DESKTOP_SESSION_ID env variable is deprecated since GNOME 3.30.0 [1], so should not be used, while the standard XDG_CURRENT_DESKTOP should be instead preferred. [1] https://gitlab.gnome.org/GNOME/gnome-session/-/commit/00e0e6226371d53f65
1 parent 5dc8c84 commit 140d9ec

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Lib/webbrowser.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,18 @@ def register_X_browsers():
418418
if shutil.which("gio"):
419419
register("gio", None, BackgroundBrowser(["gio", "open", "--", "%s"]))
420420

421-
# Equivalent of gio open before 2015
422-
if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gvfs-open"):
421+
xdg_desktop = os.getenv("XDG_CURRENT_DESKTOP", "").split(":")
422+
423+
# The default GNOME3 browser
424+
if (("GNOME" in xdg_desktop or
425+
"GNOME_DESKTOP_SESSION_ID" in os.environ) and
426+
shutil.which("gvfs-open")):
423427
register("gvfs-open", None, BackgroundBrowser("gvfs-open"))
424428

425429
# The default KDE browser
426-
if "KDE_FULL_SESSION" in os.environ and shutil.which("kfmclient"):
430+
if (("KDE" in xdg_desktop or
431+
"KDE_FULL_SESSION" in os.environ) and
432+
shutil.which("kfmclient")):
427433
register("kfmclient", Konqueror, Konqueror("kfmclient"))
428434

429435
# Common symbolic link for the default X11 browser
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use the ``XDG_CURRENT_DESKTOP`` environment variable in :mod:`webbrowser` to check desktop.
2+
Prefer it to the deprecated ``GNOME_DESKTOP_SESSION_ID`` for GNOME detection.

0 commit comments

Comments
 (0)