From 0c23deb782509a9b7ed1a81f2493fb3b711c363b Mon Sep 17 00:00:00 2001 From: ralfbrown Date: Thu, 8 Aug 2024 02:16:17 -0400 Subject: [PATCH] load Gtk CSS much earlier This allows the splash screen to be properly styled from the beginning, so that it does not change color/font in the middle of startup. --- src/common/darktable.c | 6 +++++- src/gui/gtk.c | 43 +++++++++++++++++++++++++++--------------- src/gui/gtk.h | 4 +++- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/common/darktable.c b/src/common/darktable.c index d6c61ecc2639..69db702cec70 100644 --- a/src/common/darktable.c +++ b/src/common/darktable.c @@ -1345,6 +1345,10 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load // make sure that we have no stale global progress bar // visible. thus it's run as early as possible dt_control_progress_init(darktable.control); + + // ensure that we can load the Gtk theme early enough that the splash screen + // doesn't change as we progress through startup + darktable.gui = (dt_gui_gtk_t *)calloc(1, sizeof(dt_gui_gtk_t)); } #ifdef _OPENMP @@ -1393,6 +1397,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load gtk_init(&argc, &argv); darktable.themes = NULL; + dt_gui_theme_init(darktable.gui); darktable_splash_screen_create(NULL); } @@ -1487,7 +1492,6 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load // idem for folder reachability if(init_gui) { - darktable.gui = (dt_gui_gtk_t *)calloc(1, sizeof(dt_gui_gtk_t)); darktable.gui->grouping = dt_conf_get_bool("ui_last/grouping"); dt_film_set_folder_status(); } diff --git a/src/gui/gtk.c b/src/gui/gtk.c index b2a5f197b829..2ce506435aae 100644 --- a/src/gui/gtk.c +++ b/src/gui/gtk.c @@ -1152,6 +1152,25 @@ static void _open_url(GtkWidget *widget, gpointer url) } #endif +int dt_gui_theme_init(dt_gui_gtk_t *gui) +{ + if(gui->gtkrc[0] != '\0') + return 0; // avoid duplicate initializatoin + if(!gui->ui) + gui->ui = g_malloc0(sizeof(dt_ui_t)); + + const char *css_theme = dt_conf_get_string_const("ui_last/theme"); + if(css_theme) + { + g_strlcpy(gui->gtkrc, css_theme, sizeof(gui->gtkrc)); + } + else + g_snprintf(gui->gtkrc, sizeof(gui->gtkrc), "darktable"); + // actually load the theme + dt_gui_load_theme(gui->gtkrc); + return 1; +} + int dt_gui_gtk_init(dt_gui_gtk_t *gui) { /* lets zero mem */ @@ -1178,14 +1197,6 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) dt_loc_get_sharedir(sharedir, sizeof(sharedir)); dt_loc_get_user_config_dir(configdir, sizeof(configdir)); - const char *css_theme = dt_conf_get_string_const("ui_last/theme"); - if(css_theme) - { - g_strlcpy(gui->gtkrc, css_theme, sizeof(gui->gtkrc)); - } - else - g_snprintf(gui->gtkrc, sizeof(gui->gtkrc), "darktable"); - #ifdef MAC_INTEGRATION #ifdef GTK_TYPE_OSX_APPLICATION GtkOSXApplication *OSXApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL); @@ -1268,7 +1279,8 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) #endif GtkWidget *widget; - gui->ui = g_malloc0(sizeof(dt_ui_t)); + if(!gui->ui) + gui->ui = g_malloc0(sizeof(dt_ui_t)); gui->surface = NULL; gui->center_tooltip = 0; gui->grouping = dt_conf_get_bool("ui_last/grouping"); @@ -1284,6 +1296,10 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) g_object_set(G_OBJECT(settings), "gtk-theme-name", "Adwaita", (gchar *)0); g_object_unref(settings); + // Initializing widgets + _init_widgets(gui); + dt_gui_apply_theme(gui); + // smooth scrolling must be enabled to handle trackpad/touch events gui->scroll_mask = GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK; @@ -1293,9 +1309,6 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) // Init focus peaking gui->show_focus_peaking = dt_conf_get_bool("ui/show_focus_peaking"); - // Initializing widgets - _init_widgets(gui); - //init overlay colors dt_guides_set_overlay_colors(); @@ -1425,9 +1438,6 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) darktable.gui->reset = 0; - // load theme - dt_gui_load_theme(gui->gtkrc); - // let's try to support pressure sensitive input devices like tablets for mask drawing dt_print(DT_DEBUG_INPUT, "[input device] Input devices found:\n\n"); @@ -3256,7 +3266,10 @@ void dt_gui_load_theme(const char *theme) g_free(themecss); g_object_unref(themes_style_provider); +} +void dt_gui_apply_theme() +{ // setup the colors GdkRGBA *c = darktable.gui->colors; diff --git a/src/gui/gtk.h b/src/gui/gtk.h index 8c7ebea448d5..dce807805426 100644 --- a/src/gui/gtk.h +++ b/src/gui/gtk.h @@ -200,6 +200,7 @@ void dt_gui_add_class(GtkWidget *widget, const gchar *class_name); void dt_gui_remove_class(GtkWidget *widget, const gchar *class_name); void dt_open_url(const char *url); +int dt_gui_theme_init(dt_gui_gtk_t *gui); int dt_gui_gtk_init(dt_gui_gtk_t *gui); void dt_gui_gtk_run(dt_gui_gtk_t *gui); void dt_gui_gtk_cleanup(dt_gui_gtk_t *gui); @@ -449,7 +450,8 @@ void dt_gui_dialog_add_help(GtkDialog *dialog, void dt_gui_show_help(GtkWidget *widget); // load a CSS theme -void dt_gui_load_theme(const char *theme); +void dt_gui_load_theme(const char *theme); // read them and add user tweaks +void dt_gui_apply_theme(); // apply the loaded theme to darktable's windows // reload GUI scalings void dt_configure_ppd_dpi(dt_gui_gtk_t *gui);