Skip to content

Commit

Permalink
Improve desktop environment detection
Browse files Browse the repository at this point in the history
Add code that works for Wayland, and any DE
  • Loading branch information
paulcor committed Nov 10, 2023
1 parent 39079cb commit 2d07dd2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
8 changes: 3 additions & 5 deletions interface/wx/apptrait.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ class wxAppTraits
virtual wxRendererNative* CreateRenderer() = 0;

/**
This method returns the name of the desktop environment currently
running in a Unix desktop. Currently only "KDE" or "GNOME" are
supported and the code uses the X11 session protocol vendor name
to figure out, which desktop environment is running. The method
returns an empty string otherwise and on all other platforms.
Returns the name of the desktop environment currently running on a Unix
desktop. It returns an empty string for platforms other than wxGTK, or
if the desktop environment could not be determined.
*/
virtual wxString GetDesktopEnvironment() const = 0;

Expand Down
27 changes: 21 additions & 6 deletions src/gtk/utilsgtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,33 @@ bool wxGUIAppTraits::ShowAssertDialog(const wxString& msg)
wxString wxGUIAppTraits::GetDesktopEnvironment() const
{
wxString de = wxSystemOptions::GetOption(wxT("gtk.desktop"));
if (!de.empty())
return de;

de = wxGetenv(wxS("XDG_CURRENT_DESKTOP"));
if (!de.empty())
{
// Can be a colon separated list according to
// https://wiki.archlinux.org/title/Environment_variables#Examples
de = de.BeforeFirst(':');
}
#if wxUSE_DETECT_SM
if ( de.empty() )
{
static const wxString s_SM = GetSM().Upper();

if (s_SM.Contains(wxT("GNOME")))
de = wxT("GNOME");
else if (s_SM.Contains(wxT("KDE")))
de = wxT("KDE");
static const wxString s_SM(GetSM());
de = s_SM;
de.Replace(wxS("-session"), wxString());
}
#endif // wxUSE_DETECT_SM

de.MakeUpper();
if (de.Contains(wxS("GNOME")))
de = wxS("GNOME");
else if (de.Contains(wxS("KDE")))
de = wxS("KDE");
else if (de.Contains(wxS("XFCE")))
de = wxS("XFCE");

return de;
}

Expand Down

0 comments on commit 2d07dd2

Please sign in to comment.