Skip to content

gh-85644: webbrowser: Use $XDG_CURRENT_DESKTOP to check desktop #21731

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

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,18 @@ def register_X_browsers():
if shutil.which("gio"):
register("gio", None, BackgroundBrowser(["gio", "open", "--", "%s"]))

# Equivalent of gio open before 2015
if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gvfs-open"):
xdg_desktop = os.getenv("XDG_CURRENT_DESKTOP", "").split(":")

# The default GNOME3 browser
if (("GNOME" in xdg_desktop or
"GNOME_DESKTOP_SESSION_ID" in os.environ) and
shutil.which("gvfs-open")):
register("gvfs-open", None, BackgroundBrowser("gvfs-open"))

# The default KDE browser
if "KDE_FULL_SESSION" in os.environ and shutil.which("kfmclient"):
if (("KDE" in xdg_desktop or
"KDE_FULL_SESSION" in os.environ) and
shutil.which("kfmclient")):
register("kfmclient", Konqueror, Konqueror("kfmclient"))

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