aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2018-03-21 09:35:59 +0000
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2018-03-21 09:38:29 +0000
commit5a695ecb884f2c97ba1065e95d8d2ee28d8671f7 (patch)
tree0f8e241da8aacb95f0e67915be9628f162ba82a5 /src/utils.c
parent1ace3aee71264279928a574ba44d75b7d8d0b4ba (diff)
downloadayatana-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/utils.c')
-rw-r--r--src/utils.c61
1 files changed, 11 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*