Bug 763364 - add an api to query XDG_CURRENT_DESKTOP
add an api to query XDG_CURRENT_DESKTOP
Status: NEW
Product: glib
Classification: Platform
Component: general
2.43.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2016-03-09 08:59 UTC by darkxst
Modified: 2016-03-09 21:38 UTC (History)
3 users (show)

See Also:
GNOME target: ---
GNOME version: ---


Attachments

Description darkxst 2016-03-09 08:59:01 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.
Comment 1 Matthias Clasen 2016-03-09 12:21:44 UTC
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.
Comment 2 Allison Lortie (desrt) (extended vacation) 2016-03-09 15:48:34 UTC
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?
Comment 3 Matthias Clasen 2016-03-09 17:03:54 UTC
(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
Comment 4 Alberts Muktupāvels 2016-03-09 21:38:35 UTC
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;
}

Note You need to log in before you can comment on or make changes to this bug.