From ee0bda8db3fdcb09703023bf3385687d18307369 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Fri, 28 Aug 2009 23:57:47 +0200 Subject: [PATCH] Read window properties without using 'xprop' --- midori/sokoke.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/midori/sokoke.c b/midori/sokoke.c index 4ed87fc2..1bc9aa19 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -25,6 +25,10 @@ #include #include +#ifdef GDK_WINDOWING_X11 + #include +#endif + #include #include #include @@ -409,25 +413,35 @@ sokoke_get_desktop (void) { #if HAVE_OSX return SOKOKE_DESKTOP_OSX; - #else + #elif defined (GDK_WINDOWING_X11) static SokokeDesktop desktop = SOKOKE_DESKTOP_UNTESTED; if (G_UNLIKELY (desktop == SOKOKE_DESKTOP_UNTESTED)) { /* Are we running in Xfce? */ - gint result; - gchar *out = NULL; - gchar *err = NULL; - gboolean success = g_spawn_command_line_sync ("xprop -root _DT_SAVE_MODE", - &out, &err, &result, NULL); - g_free (err); - if (success && ! result && out != NULL && strstr (out, "xfce4") != NULL) - desktop = SOKOKE_DESKTOP_XFCE; - else - desktop = SOKOKE_DESKTOP_UNKNOWN; - g_free (out); + GdkDisplay* display = gdk_display_get_default (); + Display* xdisplay = GDK_DISPLAY_XDISPLAY (display); + Window root_window = RootWindow (xdisplay, 0); + Atom save_mode_atom = gdk_x11_get_xatom_by_name ("_DT_SAVE_MODE"); + Atom actual_type; + int actual_format; + unsigned long n_items, bytes; + gchar* value; + int status = XGetWindowProperty (xdisplay, root_window, + save_mode_atom, 0, (~0L), + False, AnyPropertyType, &actual_type, &actual_format, + &n_items, &bytes, (unsigned char**)&value); + desktop = SOKOKE_DESKTOP_UNKNOWN; + if (status == Success) + { + if (n_items == 6 && !strncmp (value, "xfce4", 6)) + desktop = SOKOKE_DESKTOP_XFCE; + XFree (value); + } } return desktop; + #else + return SOKOKE_DESKTOP_UNKNOWN; #endif }