From 5a695ecb884f2c97ba1065e95d8d2ee28d8671f7 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Wed, 21 Mar 2018 09:35:59 +0000 Subject: src/utils.(c|h): Reduce code duplications in desktop env detection code. --- src/utils.c | 61 +++++++++++-------------------------------------------------- 1 file changed, 11 insertions(+), 50 deletions(-) (limited to 'src/utils.c') 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* -- cgit v1.2.3