Prevent repeated checks for the desktop environment.

It is sufficient to check the desktop environment only once.
Also don't shadow 'stdin', 'stdout' and 'stderr'.
This commit is contained in:
Ori Bernstein 2007-12-27 02:42:11 +01:00 committed by Christian Dywan
parent 39dedae0d1
commit cd8b1e5b22
1 changed files with 17 additions and 10 deletions

View File

@ -103,21 +103,28 @@ void sokoke_widget_popup(GtkWidget* widget, GtkMenu* menu
typedef enum typedef enum
{ {
SOKOKE_DESKTOP_UNKNOWN, SOKOKE_DESKTOP_UNTESTED,
SOKOKE_DESKTOP_XFCE SOKOKE_DESKTOP_XFCE,
SOKOKE_DESKTOP_UNKNOWN
} SokokeDesktop; } SokokeDesktop;
static SokokeDesktop sokoke_get_desktop(void) static SokokeDesktop sokoke_get_desktop(void)
{ {
// Are we running in Xfce? static SokokeDesktop desktop = SOKOKE_DESKTOP_UNTESTED;
gint result; gchar* stdout; gchar* stderr; if(G_UNLIKELY(desktop == SOKOKE_DESKTOP_UNTESTED))
gboolean success = g_spawn_command_line_sync( {
"xprop -root _DT_SAVE_MODE | grep -q xfce4" // Are we running in Xfce?
, &stdout, &stderr, &result, NULL); gint result; gchar* out; gchar* err;
if(success && !result) gboolean success = g_spawn_command_line_sync(
return SOKOKE_DESKTOP_XFCE; "xprop -root _DT_SAVE_MODE | grep -q xfce4"
, &out, &err, &result, NULL);
if(success && !result)
desktop = SOKOKE_DESKTOP_XFCE;
else
desktop = SOKOKE_DESKTOP_UNKNOWN;
}
return SOKOKE_DESKTOP_UNKNOWN; return desktop;
} }
gpointer sokoke_xfce_header_new(const gchar* icon, const gchar* title) gpointer sokoke_xfce_header_new(const gchar* icon, const gchar* title)