[gnome-session] gsm: Support XDG_CURRENT_DESKTOP



commit 28247060fe3daa6b9238531ddb50a7130647e9ec
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Aug 12 09:55:30 2011 +0200

    gsm: Support XDG_CURRENT_DESKTOP
    
    This enables the abuse of gnome-session in non-GNOME session. We put
    this in since it's really simple to support.
    
    Based on patch by Michael Terry <michael terry canonical com>.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=654041

 gnome-session/gsm-autostart-app.c |   12 +++++++++---
 gnome-session/gsm-util.c          |   28 +++++++++++++++++++++++++++-
 gnome-session/gsm-util.h          |    2 ++
 3 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/gnome-session/gsm-autostart-app.c b/gnome-session/gsm-autostart-app.c
index 9d8c117..5443c44 100644
--- a/gnome-session/gsm-autostart-app.c
+++ b/gnome-session/gsm-autostart-app.c
@@ -108,6 +108,7 @@ static gboolean
 is_disabled (GsmApp *app)
 {
         GsmAutostartAppPrivate *priv;
+        const char *current_desktop;
 
         priv = GSM_AUTOSTART_APP (app)->priv;
 
@@ -130,9 +131,14 @@ is_disabled (GsmApp *app)
         }
 
         /* Check OnlyShowIn/NotShowIn/TryExec */
-        if (!egg_desktop_file_can_launch (priv->desktop_file, "GNOME")) {
-                g_debug ("app %s not installed or not for GNOME",
-                         gsm_app_peek_id (app));
+        current_desktop = gsm_util_get_current_desktop ();
+        if (!egg_desktop_file_can_launch (priv->desktop_file, current_desktop)) {
+                if (current_desktop) {
+                        g_debug ("app %s not installed or not for %s",
+                                 gsm_app_peek_id (app), current_desktop);
+                } else {
+                        g_debug ("app %s not installed", gsm_app_peek_id (app));
+                }
                 return TRUE;
         }
 
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index faad668..38f6ddd 100644
--- a/gnome-session/gsm-util.c
+++ b/gnome-session/gsm-util.c
@@ -182,7 +182,6 @@ gsm_util_get_saved_session_dir (void)
         return _saved_session_dir;
 }
 
-
 char **
 gsm_util_get_autostart_dirs ()
 {
@@ -296,6 +295,33 @@ gsm_util_get_desktop_dirs (gboolean include_saved_session,
 	return result;
 }
 
+const char *
+gsm_util_get_current_desktop ()
+{
+        static char *current_desktop = NULL;
+
+        /* Support XDG_CURRENT_DESKTOP environment variable; this can be used
+         * to abuse gnome-session in non-GNOME desktops. */
+        if (!current_desktop) {
+                const char *desktop;
+
+                desktop = g_getenv ("XDG_CURRENT_DESKTOP");
+
+                /* Note: if XDG_CURRENT_DESKTOP is set but empty, do as if it
+                 * was not set */
+                if (!desktop || desktop[0] == '\0')
+                        current_desktop = g_strdup ("GNOME");
+                else
+                        current_desktop = g_strdup (desktop);
+        }
+
+        /* Using "*" means skipping desktop-related checks */
+        if (g_strcmp0 (current_desktop, "*") == 0)
+                return NULL;
+
+        return current_desktop;
+}
+
 gboolean
 gsm_util_text_is_blank (const char *str)
 {
diff --git a/gnome-session/gsm-util.h b/gnome-session/gsm-util.h
index de1bd6a..821706f 100644
--- a/gnome-session/gsm-util.h
+++ b/gnome-session/gsm-util.h
@@ -42,6 +42,8 @@ gchar**     gsm_util_get_autostart_dirs             (void);
 gchar **    gsm_util_get_desktop_dirs               (gboolean include_saved_session,
                                                      gboolean autostart_first);
 
+const char *gsm_util_get_current_desktop            (void);
+
 gboolean    gsm_util_text_is_blank                  (const char *str);
 
 void        gsm_util_init_error                     (gboolean    fatal,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]