aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/utils.c61
-rw-r--r--src/utils.h9
2 files changed, 20 insertions, 50 deletions
diff --git a/src/utils.c b/src/utils.c
index dad9354..9a53eda 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -16,8 +16,8 @@
#include "utils.h"
-gboolean
-is_unity ()
+static gboolean
+is_xdg_current_desktop (const gchar* desktop)
{
const gchar *xdg_current_desktop;
gchar **desktop_names;
@@ -27,7 +27,7 @@ is_unity ()
if (xdg_current_desktop != NULL) {
desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
for (i = 0; desktop_names[i]; ++i) {
- if (!g_strcmp0 (desktop_names[i], "Unity")) {
+ if (!g_strcmp0 (desktop_names[i], desktop)) {
g_strfreev (desktop_names);
return TRUE;
}
@@ -40,64 +40,25 @@ is_unity ()
gboolean
is_gnome ()
{
- const gchar *xdg_current_desktop;
- gchar **desktop_names;
- int i;
+ return is_xdg_current_desktop(DESKTOP_GNOME);
+}
- xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
- if (xdg_current_desktop != NULL) {
- desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
- for (i = 0; desktop_names[i]; ++i) {
- if (!g_strcmp0 (desktop_names[i], "GNOME")) {
- g_strfreev (desktop_names);
- return TRUE;
- }
- }
- g_strfreev (desktop_names);
- }
- return FALSE;
+gboolean
+is_unity ()
+{
+ return is_xdg_current_desktop(DESKTOP_UNITY7);
}
gboolean
is_mate ()
{
- const gchar *xdg_current_desktop;
- gchar **desktop_names;
- int i;
-
- xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
- if (xdg_current_desktop != NULL) {
- desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
- for (i = 0; desktop_names[i]; ++i) {
- if (!g_strcmp0 (desktop_names[i], "MATE")) {
- g_strfreev (desktop_names);
- return TRUE;
- }
- }
- g_strfreev (desktop_names);
- }
- return FALSE;
+ return is_xdg_current_desktop(DESKTOP_MATE);
}
gboolean
is_xfce ()
{
- const gchar *xdg_current_desktop;
- gchar **desktop_names;
- int i;
-
- xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
- if (xdg_current_desktop != NULL) {
- desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
- for (i = 0; desktop_names[i]; ++i) {
- if (!g_strcmp0 (desktop_names[i], "XFCE")) {
- g_strfreev (desktop_names);
- return TRUE;
- }
- }
- g_strfreev (desktop_names);
- }
- return FALSE;
+ return is_xdg_current_desktop(DESKTOP_XFCE);
}
GHashTable*
diff --git a/src/utils.h b/src/utils.h
index 69bf2c6..d39637c 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -20,6 +20,15 @@
#include <glib.h>
#include <string.h>
+
+/* XDG_CURRENT_DESKTOP environment variable values
+ * as set by well-known desktop environments
+ */
+#define DESKTOP_UNITY "Unity"
+#define DESKTOP_MATE "MATE"
+#define DESKTOP_GNOME "GNOME"
+#define DESKTOP_XFCE "XFCE"
+
gboolean is_unity();
gboolean is_gnome();
gboolean is_mate();