Blame SOURCES/fix-multiple-desktops-in-xdg-current-desktop.patch

34f071
From b4546ab43c2c7ef6fb6cb7e5db83dc3975b56e8e Mon Sep 17 00:00:00 2001
34f071
From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= <alberts.muktupavels@gmail.com>
34f071
Date: Mon, 27 Oct 2014 18:41:34 +0200
34f071
Subject: [PATCH 1/2] desktop-entries: support multiple desktops in
34f071
 XDG_CURRENT_DESKTOP
34f071
34f071
This is based on glib commit:
34f071
5a5e16e93c4f11e635918ecdb41681f63fd05a39
34f071
---
34f071
 libmenu/desktop-entries.c | 110 ++++++++++++++++++++++------------------------
34f071
 1 file changed, 52 insertions(+), 58 deletions(-)
34f071
34f071
diff --git a/libmenu/desktop-entries.c b/libmenu/desktop-entries.c
34f071
index 326f311..bd4f886 100644
34f071
--- a/libmenu/desktop-entries.c
34f071
+++ b/libmenu/desktop-entries.c
34f071
@@ -85,32 +85,27 @@ unix_basename_from_path (const char *path)
34f071
     return path;
34f071
 }
34f071
 
34f071
-static const char *
34f071
-get_current_desktop (void)
34f071
+static const gchar * const *
34f071
+get_current_desktops (void)
34f071
 {
34f071
-  static char *current_desktop = NULL;
34f071
+  static gchar **result;
34f071
 
34f071
-  /* Support XDG_CURRENT_DESKTOP environment variable; this can be used
34f071
-   * to abuse gnome-menus in non-GNOME desktops. */
34f071
-  if (!current_desktop)
34f071
+  if (g_once_init_enter (&result))
34f071
     {
34f071
-      const char *desktop;
34f071
+      const gchar *desktops;
34f071
+      gchar **tmp;
34f071
 
34f071
-      desktop = g_getenv ("XDG_CURRENT_DESKTOP");
34f071
+      desktops = g_getenv ("XDG_CURRENT_DESKTOP");
34f071
 
34f071
-      /* Note: if XDG_CURRENT_DESKTOP is set but empty, do as if it
34f071
-       * was not set */
34f071
-      if (!desktop || desktop[0] == '\0')
34f071
-        current_desktop = g_strdup ("GNOME");
34f071
-      else
34f071
-        current_desktop = g_strdup (desktop);
34f071
-    }
34f071
+      if (desktops)
34f071
+        desktops = "";
34f071
 
34f071
-  /* Using "*" means skipping desktop-related checks */
34f071
-  if (g_strcmp0 (current_desktop, "*") == 0)
34f071
-    return NULL;
34f071
+      tmp = g_strsplit (desktops, ":", 0);
34f071
+
34f071
+      g_once_init_leave (&result, tmp);
34f071
+    }
34f071
 
34f071
-  return current_desktop;
34f071
+  return  (const gchar **) result;
34f071
 }
34f071
 
34f071
 static GIcon *
34f071
@@ -151,52 +146,58 @@ key_file_get_icon (GKeyFile *key_file)
34f071
 static gboolean
34f071
 key_file_get_show_in (GKeyFile *key_file)
34f071
 {
34f071
-  const gchar *current_desktop;
34f071
-  gchar **strv;
34f071
+  const gchar * const *current_desktops;
34f071
+  gchar **only_show_in;
34f071
+  gchar **not_show_in;
34f071
   gboolean show_in = TRUE;
34f071
-  int i;
34f071
-
34f071
-  current_desktop = get_current_desktop ();
34f071
-  if (!current_desktop)
34f071
-    return TRUE;
34f071
-
34f071
-  strv = g_key_file_get_string_list (key_file,
34f071
-                                     DESKTOP_ENTRY_GROUP,
34f071
-                                     "OnlyShowIn",
34f071
-                                     NULL,
34f071
-                                     NULL);
34f071
-  if (strv)
34f071
+  gint i;
34f071
+
34f071
+  current_desktops = get_current_desktops ();
34f071
+  only_show_in = g_key_file_get_string_list (key_file,
34f071
+                                             DESKTOP_ENTRY_GROUP,
34f071
+                                             "OnlyShowIn",
34f071
+                                             NULL,
34f071
+                                             NULL);
34f071
+  not_show_in = g_key_file_get_string_list (key_file,
34f071
+                                            DESKTOP_ENTRY_GROUP,
34f071
+                                            "NotShowIn",
34f071
+                                            NULL,
34f071
+                                            NULL);
34f071
+
34f071
+  for (i = 0; current_desktops[i]; i++)
34f071
     {
34f071
-      show_in = FALSE;
34f071
-      for (i = 0; strv[i]; i++)
34f071
+      gint j;
34f071
+
34f071
+      if (only_show_in)
34f071
         {
34f071
-          if (!strcmp (strv[i], current_desktop))
34f071
+          show_in = FALSE;
34f071
+          for (j = 0; only_show_in[j]; j++)
34f071
             {
34f071
-              show_in = TRUE;
34f071
-              break;
34f071
+              if (g_str_equal (only_show_in[j], current_desktops[i]))
34f071
+                {
34f071
+                  show_in = TRUE;
34f071
+                  goto out;
34f071
+                }
34f071
             }
34f071
         }
34f071
-    }
34f071
-  else
34f071
-    {
34f071
-      strv = g_key_file_get_string_list (key_file,
34f071
-                                         DESKTOP_ENTRY_GROUP,
34f071
-                                         "NotShowIn",
34f071
-                                         NULL,
34f071
-                                         NULL);
34f071
-      if (strv)
34f071
+
34f071
+      if (not_show_in)
34f071
         {
34f071
           show_in = TRUE;
34f071
-          for (i = 0; strv[i]; i++)
34f071
+          for (j = 0; not_show_in[j]; j++)
34f071
             {
34f071
-              if (!strcmp (strv[i], current_desktop))
34f071
+              if (g_str_equal (not_show_in[j], current_desktops[i]))
34f071
                 {
34f071
                   show_in = FALSE;
34f071
+                  goto out;
34f071
                 }
34f071
             }
34f071
         }
34f071
     }
34f071
-  g_strfreev (strv);
34f071
+
34f071
+out:
34f071
+  g_strfreev (only_show_in);
34f071
+  g_strfreev (not_show_in);
34f071
 
34f071
   return show_in;
34f071
 }
34f071
@@ -579,14 +580,7 @@ gboolean
34f071
 desktop_entry_get_show_in (DesktopEntry *entry)
34f071
 {
34f071
   if (entry->type == DESKTOP_ENTRY_DESKTOP)
34f071
-    {
34f071
-      const char *current_desktop = get_current_desktop ();
34f071
-
34f071
-      if (current_desktop == NULL)
34f071
-        return TRUE;
34f071
-      else
34f071
-        return g_desktop_app_info_get_show_in (((DesktopEntryDesktop*)entry)->appinfo, current_desktop);
34f071
-    }
34f071
+    return g_desktop_app_info_get_show_in (((DesktopEntryDesktop*)entry)->appinfo, NULL);
34f071
   return ((DesktopEntryDirectory*)entry)->showin;
34f071
 }
34f071
 
34f071
-- 
34f071
2.4.3
34f071
34f071
34f071
From 4befe76fbdb76aa6a986297ef71d1601b2ced42e Mon Sep 17 00:00:00 2001
34f071
From: Josselin Mouette <joss@debian.org>
34f071
Date: Sun, 14 Dec 2014 20:36:36 +0100
34f071
Subject: [PATCH 2/2] desktop-entries: fix trivial bug in handling of multiple
34f071
 desktops in XDG_CURRENT_DESKTOP.
34f071
34f071
https://bugzilla.gnome.org/show_bug.cgi?id=741505
34f071
---
34f071
 libmenu/desktop-entries.c | 2 +-
34f071
 1 file changed, 1 insertion(+), 1 deletion(-)
34f071
34f071
diff --git a/libmenu/desktop-entries.c b/libmenu/desktop-entries.c
34f071
index bd4f886..a463d79 100644
34f071
--- a/libmenu/desktop-entries.c
34f071
+++ b/libmenu/desktop-entries.c
34f071
@@ -97,7 +97,7 @@ get_current_desktops (void)
34f071
 
34f071
       desktops = g_getenv ("XDG_CURRENT_DESKTOP");
34f071
 
34f071
-      if (desktops)
34f071
+      if (!desktops)
34f071
         desktops = "";
34f071
 
34f071
       tmp = g_strsplit (desktops, ":", 0);
34f071
-- 
34f071
2.4.3
34f071