diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2018-03-21 09:35:59 +0000 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2018-03-21 09:38:29 +0000 |
commit | 5a695ecb884f2c97ba1065e95d8d2ee28d8671f7 (patch) | |
tree | 0f8e241da8aacb95f0e67915be9628f162ba82a5 /src | |
parent | 1ace3aee71264279928a574ba44d75b7d8d0b4ba (diff) | |
download | ayatana-indicator-session-5a695ecb884f2c97ba1065e95d8d2ee28d8671f7.tar.gz ayatana-indicator-session-5a695ecb884f2c97ba1065e95d8d2ee28d8671f7.tar.bz2 ayatana-indicator-session-5a695ecb884f2c97ba1065e95d8d2ee28d8671f7.zip |
src/utils.(c|h): Reduce code duplications in desktop env detection code.
Diffstat (limited to 'src')
-rw-r--r-- | src/utils.c | 61 | ||||
-rw-r--r-- | src/utils.h | 9 |
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(); |