diff options
-rw-r--r-- | src/utils.c | 28 | ||||
-rw-r--r-- | src/utils.h | 7 | ||||
-rw-r--r-- | tests/tst_utils.cpp | 20 | ||||
-rw-r--r-- | tests/tst_utils.vala | 21 |
4 files changed, 67 insertions, 9 deletions
diff --git a/src/utils.c b/src/utils.c index 29d4bf6..d46c604 100644 --- a/src/utils.c +++ b/src/utils.c @@ -25,7 +25,7 @@ // TODO: make case insensitive gboolean -is_xdg_current_desktop (const gchar* desktop) +is_xdg_current_desktop (const gchar* desktop, const gchar* session) { const gchar *xdg_current_desktop; gchar **desktop_names; @@ -42,49 +42,61 @@ is_xdg_current_desktop (const gchar* desktop) } g_strfreev (desktop_names); } + + if (session != NULL) + { + const gchar *desktop_session = g_getenv ("DESKTOP_SESSION"); + + if (desktop_session != NULL && g_str_equal(desktop_session, session)) + { + return TRUE; + } + + } + return FALSE; } gboolean ayatana_common_utils_is_lomiri () { - return is_xdg_current_desktop(DESKTOP_LOMIRI); + return is_xdg_current_desktop(DESKTOP_LOMIRI, SESSION_LOMIRI); } gboolean ayatana_common_utils_is_gnome () { - return is_xdg_current_desktop(DESKTOP_GNOME); + return is_xdg_current_desktop(DESKTOP_GNOME, SESSION_GNOME); } gboolean ayatana_common_utils_is_unity () { - return is_xdg_current_desktop(DESKTOP_UNITY); + return is_xdg_current_desktop(DESKTOP_UNITY, SESSION_UNITY); } gboolean ayatana_common_utils_is_mate () { - return is_xdg_current_desktop(DESKTOP_MATE); + return is_xdg_current_desktop(DESKTOP_MATE, SESSION_MATE); } gboolean ayatana_common_utils_is_xfce () { - return is_xdg_current_desktop(DESKTOP_XFCE); + return is_xdg_current_desktop(DESKTOP_XFCE, SESSION_XFCE); } gboolean ayatana_common_utils_is_pantheon () { - return is_xdg_current_desktop(DESKTOP_PANTHEON); + return is_xdg_current_desktop(DESKTOP_PANTHEON, SESSION_PANTHEON); } gboolean ayatana_common_utils_is_budgie () { - return is_xdg_current_desktop(DESKTOP_BUDGIE); + return is_xdg_current_desktop(DESKTOP_BUDGIE, SESSION_BUDGIE); } gboolean diff --git a/src/utils.h b/src/utils.h index b8e70cb..59bf008 100644 --- a/src/utils.h +++ b/src/utils.h @@ -29,6 +29,13 @@ static const char *DESKTOP_GNOME = "GNOME"; static const char *DESKTOP_XFCE = "XFCE"; static const char *DESKTOP_PANTHEON = "PANTHEON"; static const char *DESKTOP_BUDGIE = "Budgie"; +static const char *SESSION_LOMIRI = "ubuntu-touch"; +static const char *SESSION_UNITY = NULL; +static const char *SESSION_MATE = "mate"; +static const char *SESSION_GNOME = "gnome"; +static const char *SESSION_XFCE = "xfce"; +static const char *SESSION_PANTHEON = NULL; +static const char *SESSION_BUDGIE = "budgie-desktop"; gboolean ayatana_common_utils_is_lomiri(); gboolean ayatana_common_utils_is_unity(); diff --git a/tests/tst_utils.cpp b/tests/tst_utils.cpp index c6b82fb..a1cf7c5 100644 --- a/tests/tst_utils.cpp +++ b/tests/tst_utils.cpp @@ -34,13 +34,17 @@ public: void TearDown() { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); } }; TEST_F(XdgCurrentDesktopUtilsTest, isLomiri) { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); EXPECT_FALSE(ayatana_common_utils_is_lomiri()); + setenv("DESKTOP_SESSION", "ubuntu-touch", 1); + EXPECT_TRUE(ayatana_common_utils_is_lomiri()); setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); EXPECT_TRUE(ayatana_common_utils_is_lomiri()); } @@ -48,13 +52,19 @@ TEST_F(XdgCurrentDesktopUtilsTest, isLomiri) TEST_F(XdgCurrentDesktopUtilsTest, isGnome) { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); EXPECT_FALSE(ayatana_common_utils_is_gnome()); + setenv("DESKTOP_SESSION", "gnome", 1); + EXPECT_TRUE(ayatana_common_utils_is_gnome()); setenv("XDG_CURRENT_DESKTOP", "GNOME", 1); EXPECT_TRUE(ayatana_common_utils_is_gnome()); } TEST_F(XdgCurrentDesktopUtilsTest, isUnity) { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); + EXPECT_FALSE(ayatana_common_utils_is_unity()); + setenv("DESKTOP_SESSION", "gnome-fallback", 1); EXPECT_FALSE(ayatana_common_utils_is_unity()); setenv("XDG_CURRENT_DESKTOP", "Unity", 1); EXPECT_TRUE(ayatana_common_utils_is_unity()); @@ -62,20 +72,27 @@ TEST_F(XdgCurrentDesktopUtilsTest, isUnity) TEST_F(XdgCurrentDesktopUtilsTest, isMate) { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); EXPECT_FALSE(ayatana_common_utils_is_mate()); + setenv("DESKTOP_SESSION", "mate", 1); + EXPECT_TRUE(ayatana_common_utils_is_mate()); setenv("XDG_CURRENT_DESKTOP", "MATE", 1); EXPECT_TRUE(ayatana_common_utils_is_mate()); } TEST_F(XdgCurrentDesktopUtilsTest, isXfce) { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); EXPECT_FALSE(ayatana_common_utils_is_xfce()); + setenv("DESKTOP_SESSION", "xfce", 1); + EXPECT_TRUE(ayatana_common_utils_is_xfce()); setenv("XDG_CURRENT_DESKTOP", "XFCE", 1); EXPECT_TRUE(ayatana_common_utils_is_xfce()); } TEST_F(XdgCurrentDesktopUtilsTest, isPantheon) { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); EXPECT_FALSE(ayatana_common_utils_is_pantheon()); setenv("XDG_CURRENT_DESKTOP", "PANTHEON", 1); EXPECT_TRUE(ayatana_common_utils_is_pantheon()); @@ -83,7 +100,10 @@ TEST_F(XdgCurrentDesktopUtilsTest, isPantheon) TEST_F(XdgCurrentDesktopUtilsTest, isBudgie) { unsetenv("XDG_CURRENT_DESKTOP"); + unsetenv("DESKTOP_SESSION"); EXPECT_FALSE(ayatana_common_utils_is_budgie()); + setenv("DESKTOP_SESSION", "budgie-desktop", 1); + EXPECT_TRUE(ayatana_common_utils_is_budgie()); setenv("XDG_CURRENT_DESKTOP", "Budgie:GNOME", 1); EXPECT_TRUE(ayatana_common_utils_is_budgie()); } diff --git a/tests/tst_utils.vala b/tests/tst_utils.vala index a7a624b..44ce6fe 100644 --- a/tests/tst_utils.vala +++ b/tests/tst_utils.vala @@ -5,44 +5,63 @@ using GLib; static int main(string[] args) { assert(args.length == 2); - unset_variable("DESKTOP_SESSION"); + unset_variable("DESKTOP_SESSION"); unset_variable("XDG_CURRENT_DESKTOP"); assert(! utils_is_lomiri()); + set_variable("DESKTOP_SESSION", "ubuntu-touch", true); + assert(utils_is_lomiri()); set_variable("XDG_CURRENT_DESKTOP", "Lomiri", true); assert(utils_is_lomiri()); unset_variable("XDG_CURRENT_DESKTOP"); + unset_variable("DESKTOP_SESSION"); assert(! utils_is_gnome()); + set_variable("DESKTOP_SESSION", "gnome", true); + assert(utils_is_gnome()); set_variable("XDG_CURRENT_DESKTOP", "GNOME", true); assert(utils_is_gnome()); unset_variable("XDG_CURRENT_DESKTOP"); + unset_variable("DESKTOP_SESSION"); + assert(! utils_is_unity()); + set_variable("DESKTOP_SESSION", "gnome-fallback", true); assert(! utils_is_unity()); set_variable("XDG_CURRENT_DESKTOP", "Unity", true); assert(utils_is_unity()); unset_variable("XDG_CURRENT_DESKTOP"); + unset_variable("DESKTOP_SESSION"); assert(! utils_is_mate()); + set_variable("DESKTOP_SESSION", "mate", true); + assert(utils_is_mate()); set_variable("XDG_CURRENT_DESKTOP", "MATE", true); assert(utils_is_mate()); unset_variable("XDG_CURRENT_DESKTOP"); + unset_variable("DESKTOP_SESSION"); assert(! utils_is_xfce()); + set_variable("DESKTOP_SESSION", "xfce", true); + assert(utils_is_xfce()); set_variable("XDG_CURRENT_DESKTOP", "XFCE", true); assert(utils_is_xfce()); unset_variable("XDG_CURRENT_DESKTOP"); + unset_variable("DESKTOP_SESSION"); assert(! utils_is_pantheon()); set_variable("XDG_CURRENT_DESKTOP", "PANTHEON", true); assert(utils_is_pantheon()); unset_variable("XDG_CURRENT_DESKTOP"); + unset_variable("DESKTOP_SESSION"); assert(! utils_is_budgie()); + set_variable("DESKTOP_SESSION", "budgie-desktop", true); + assert(utils_is_budgie()); set_variable("XDG_CURRENT_DESKTOP", "Budgie:GNOME", true); assert(utils_is_budgie()); unset_variable("XDG_CURRENT_DESKTOP"); + unset_variable("DESKTOP_SESSION"); set_variable("GSETTINGS_SCHEMA_DIR", args[1], true); set_variable("GSETTINGS_BACKEND", "memory", true); |