GNOME Bugzilla – Bug 763364
add an api to query XDG_CURRENT_DESKTOP
Last modified: 2016-03-09 21:38:35 UTC
Since XDG_CURRENT_DESKTOP was standardised its about 20 lines of boiler plate code to check this variable for the running desktop, it would be nice if there a central API to check to this, rather than having to split the string from colons and then cycle through checking values. This mostly affects Ubuntu, since there are quite a number of patches that check XDG_CURRENT_DESKTOP for Unity or GNOME, to change for example CSD's on/off. However there are snippets of code through the upstream code that also so this, nautilus, empathy etc The idea would be to have say an in_desktop("GNOME") call that checks if the string matches in XDG_CURRENT_DESKTOP. I am not sure where this would live though? logic wise its fairly close to the g_desktop_app_info stuff, but its clearly not app specific.
You are not going to get me to agree to this. I think this environment variable business is a mistake and should not have been done in the first place. It only encourages splintering the user experience and unreproducible bugs.
Of course I disagree with Matthias here -- it is pretty important for things like desktop files and preferred apps. OnlyShowIn (and friends) never worked properly before this was introduced. However, I do worry that it ends up being used for too many purposes... Let's say we wanted to add this API anyway. What do you propose it would look like? Return a strv? const gchar * const * get_current_desktop_ids (); () -> ["MATE", "GNOME"] Able to query for which one of a particular sequence is found first? gint check_desktop_ids (const gchar * const *ids); (["MATE", "GNOME"]) -> 1 ('GNOME' is best match) ? And what specific places would you intend to use this API?
(In reply to Allison Ryan Lortie (desrt) from comment #2) > Of course I disagree with Matthias here -- it is pretty important for things > like desktop files and preferred apps. OnlyShowIn (and friends) never > worked properly before this was introduced. However, I do worry that it > ends up being used for too many purposes... > This. Once you add an api for this that is even easier than parsing the environment variable yourself, things will go really go downhill for desktop-specific hacks in apps. Just say no
I think that this bug was opened with idea that if needed one could just call for example if (g_in_desktop ("GNOME")) and it would return TRUE if GNOME is somewhere in XDG_CURRENT_DESKTOP and FALSE if it was not found. Something like this: g_in_desktop (const gchar *name) { const gchar *xdg_current_desktop; gboolean in_desktop; gchar **desktops; gint i; xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP"); if (!xdg_current_desktop) return FALSE; in_desktop = FALSE; desktops = g_strsplit (xdg_current_desktop, ":", -1); for (i = 0; desktops[i] != NULL; i++) { if (g_strcmp0 (desktops[i], name) == 0) { in_desktop = TRUE; break; } } g_strfreev (desktops); return in_dekstop; }