Skip to content

Commit

Permalink
load Gtk CSS much earlier
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ralfbrown committed Aug 8, 2024
1 parent 7059a7f commit 0c23deb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/common/darktable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
}
Expand Down
43 changes: 28 additions & 15 deletions src/gui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/gui/gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0c23deb

Please sign in to comment.