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

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