File gdm-support-XDG_CURRENT_DESKTOP.patch of Package gdm.16051

commit af384da3c72efee40dcba48bb0e3e2ad6a08f6e4
Author: Lars Uebernickel <lars.uebernickel@canonical.com>
Date:   Thu Apr 3 15:58:53 2014 +0200

    gdm-session: support XDG_CURRENT_DESKTOP
    
    Set XDG_CURRENT_DESKTOP when DesktopNames is set in the session file.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727546

Index: gdm-3.10.0.1/daemon/gdm-session.c
===================================================================
--- gdm-3.10.0.1.orig/daemon/gdm-session.c
+++ gdm-3.10.0.1/daemon/gdm-session.c
@@ -389,6 +389,35 @@ is_prog_in_path (const char *prog)
         return ret;
 }
 
+/* from upstream: f4a96eceddbe0e1feb098f871b87b0 */
+static GKeyFile *
+load_key_file_for_file (const char *file, char **full_path)
+{
+        GKeyFile   *key_file;
+        GError     *error;
+        gboolean    res;
+
+        key_file = g_key_file_new ();
+
+        g_debug ("GdmSession: looking for session file '%s'", file);
+
+        error = NULL;
+        res = g_key_file_load_from_dirs (key_file,
+                                         file,
+                                         get_system_session_dirs (),
+                                         full_path,
+                                         G_KEY_FILE_NONE,
+                                         &error);
+        if (! res) {
+                g_debug ("GdmSession: File '%s' not found: %s", file, error->message);
+                g_error_free (error);
+                g_key_file_free (key_file);
+                key_file = NULL;
+        }
+
+        return key_file;
+}
+
 static gboolean
 get_session_command_for_file (const char *file,
                               char      **command)
@@ -2343,6 +2372,32 @@ get_session_command (GdmSession *self)
         return command;
 }
 
+static gchar *
+get_session_desktop_names (GdmSession *self)
+{
+        gchar *filename;
+        GKeyFile *keyfile;
+        gchar *desktop_names = NULL;
+
+        filename = g_strdup_printf ("%s.desktop", get_session_name (self));
+        keyfile = load_key_file_for_file (filename, NULL);
+        if (keyfile != NULL) {
+              gchar **names;
+
+              names = g_key_file_get_string_list (keyfile, G_KEY_FILE_DESKTOP_GROUP,
+                                                  "DesktopNames", NULL, NULL);
+              if (names != NULL) {
+                      desktop_names = g_strjoinv (":", names);
+
+                      g_strfreev (names);
+              }
+        }
+
+        g_key_file_free (keyfile);
+        g_free (filename);
+        return desktop_names;
+}
+
 void
 gdm_session_set_environment_variable (GdmSession *self,
                                       const char *key,
@@ -2360,6 +2415,7 @@ static void
 setup_session_environment (GdmSession *self)
 {
         const char *locale;
+        gchar *desktop_names;
 
         gdm_session_set_environment_variable (self,
                                               "GDMSESSION",
@@ -2368,6 +2424,11 @@ setup_session_environment (GdmSession *s
                                               "DESKTOP_SESSION",
                                               get_session_name (self));
 
+        desktop_names = get_session_desktop_names (self);
+        if (desktop_names != NULL) {
+                gdm_session_set_environment_variable (self, "XDG_CURRENT_DESKTOP", desktop_names);
+        }
+
         locale = get_language_name (self);
 
         if (locale != NULL && locale[0] != '\0') {
@@ -2402,6 +2463,8 @@ setup_session_environment (GdmSession *s
                                                       "WINDOWPATH",
                                                       g_getenv ("WINDOWPATH"));
         }
+
+        g_free (desktop_names);
 }
 
 void