From f8fe519c1b5454ba939ade2a4b60f0066fb6aa14 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Thu, 5 Apr 2012 07:16:11 +0000 Subject: [PATCH] refactor alpha enabling, added some debug traces --- src/cfg.c | 1 - src/main.c | 2 ++ src/ui.c | 44 +++++++++++++++++++------------------------- src/ui.h | 2 ++ 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index 606ecc4..d1a3bed 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -145,7 +145,6 @@ static double config_get_graph_background_alpha() double a = gconf_client_get_float(client, KEY_GRAPH_BACKGROUND_ALPHA, NULL); - if (a == 0) gconf_client_set_float(client, KEY_GRAPH_BACKGROUND_ALPHA, 1.0, NULL); diff --git a/src/main.c b/src/main.c index dde8e5a..8425c34 100644 --- a/src/main.c +++ b/src/main.c @@ -507,6 +507,8 @@ int main(int argc, char **argv) /* drawing box */ ui.w_graph = ui_graph_create(&ui); + ui_enable_alpha_channel(&ui); + /* sensor list */ ui_sensorlist_create(&ui); diff --git a/src/ui.c b/src/ui.c index ee2b8c3..ee75c33 100644 --- a/src/ui.c +++ b/src/ui.c @@ -185,32 +185,35 @@ static GtkWidget *get_menu(struct ui_psensor *ui) return gtk_ui_manager_get_widget(menu_manager, "/MainMenu"); } -static unsigned int enable_alpha_channel(GtkWidget *w) +void ui_enable_alpha_channel(struct ui_psensor *ui) { - GdkScreen *screen = gtk_widget_get_screen(w); + GdkScreen *screen; + GdkVisual *visual; + struct config *cfg; -#if (GTK_CHECK_VERSION(3, 0, 0)) - GdkVisual *visual = gdk_screen_get_rgba_visual(screen); + cfg = ui->config; - if (visual) { - gtk_widget_set_visual(w, visual); - return 1; - } -#else - GdkColormap *colormap = gdk_screen_get_rgba_colormap(screen); + screen = gtk_widget_get_screen(ui->main_window); - if (colormap) { - gtk_widget_set_colormap(w, colormap); - return 1; + log_debug("Config alpha channel enabled: %d", cfg->alpha_channel_enabled); + if (cfg->alpha_channel_enabled && gdk_screen_is_composited(screen)) { + log_debug("Screen is composited"); + visual = gdk_screen_get_rgba_visual(screen); + if (visual) { + gtk_widget_set_visual(ui->main_window, visual); + } else { + cfg->alpha_channel_enabled = 0; + log_err("Enable alpha channel has failed"); + } + } else { + cfg->alpha_channel_enabled = 0; } -#endif - return 0; + } void ui_window_create(struct ui_psensor *ui) { GtkWidget *window, *menubar; - GdkScreen *screen; GdkPixbuf *icon; GtkIconTheme *icon_theme; struct config *cfg; @@ -231,15 +234,6 @@ void ui_window_create(struct ui_psensor *ui) _("Psensor - Temperature Monitor")); gtk_window_set_role(GTK_WINDOW(window), "psensor"); - screen = gtk_widget_get_screen(window); - - if (cfg->alpha_channel_enabled && gdk_screen_is_composited(screen)) { - if (!enable_alpha_channel(window)) - cfg->alpha_channel_enabled = 0; - } else { - cfg->alpha_channel_enabled = 0; - } - icon_theme = gtk_icon_theme_get_default(); icon = gtk_icon_theme_load_icon(icon_theme, "psensor", 48, 0, NULL); if (icon) diff --git a/src/ui.h b/src/ui.h index 753d7b9..b78fab2 100644 --- a/src/ui.h +++ b/src/ui.h @@ -83,4 +83,6 @@ void ui_menu_bar_show(unsigned int show, struct ui_psensor *ui); void ui_show_about_dialog(); +void ui_enable_alpha_channel(struct ui_psensor *ui); + #endif -- 2.7.4