Fix #926: Use system background color in window mode
authorColin Clark <colin.clark@cclark.uk>
Mon, 4 Oct 2021 12:32:44 +0000 (13:32 +0100)
committerColin Clark <colin.clark@cclark.uk>
Mon, 4 Oct 2021 12:32:44 +0000 (13:32 +0100)
https://github.com/BestImageViewer/geeqie/issues/926

The default background color for both windowed and fullscreen modes is
the theme background color.

This feature is not available when compiled for GTK2.

src/image.c
src/main.c
src/renderer-tiles.c

index f73762c..1326ff1 100644 (file)
@@ -1888,6 +1888,12 @@ void image_background_set_color(ImageWindow *imd, GdkColor *color)
 void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen)
 {
        GdkColor *color = NULL;
 void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen)
 {
        GdkColor *color = NULL;
+#if GTK_CHECK_VERSION(3,0,0)
+       GdkColor theme_color;
+       GdkRGBA bg_color;
+       GtkStyleContext *style_context;
+       LayoutWindow *lw = NULL;
+#endif
 
        if ((options->image.use_custom_border_color && !fullscreen) ||
            (options->image.use_custom_border_color_in_fullscreen && fullscreen))
 
        if ((options->image.use_custom_border_color && !fullscreen) ||
            (options->image.use_custom_border_color_in_fullscreen && fullscreen))
@@ -1895,6 +1901,22 @@ void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscre
                color = &options->image.border_color;
                }
 
                color = &options->image.border_color;
                }
 
+#if GTK_CHECK_VERSION(3,0,0)
+       else
+               {
+               if (!layout_valid(&lw)) return;
+
+               style_context = gtk_widget_get_style_context(lw->window);
+               gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color);
+
+               theme_color.red = bg_color.red * 65535;
+               theme_color.green = bg_color.green * 65535;
+               theme_color.blue = bg_color.blue * 65535;
+
+               color = &theme_color;
+               }
+#endif
+
        image_background_set_color(imd, color);
 }
 
        image_background_set_color(imd, color);
 }
 
index 2cef1c9..c117f71 100644 (file)
@@ -38,7 +38,9 @@
 #include "filedata.h"
 #include "filefilter.h"
 #include "history_list.h"
 #include "filedata.h"
 #include "filefilter.h"
 #include "history_list.h"
+#include "image.h"
 #include "image-overlay.h"
 #include "image-overlay.h"
+#include "img-view.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "layout_util.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "layout_util.h"
@@ -1239,6 +1241,46 @@ static void setup_sigbus_handler(void)
 #endif
 }
 
 #endif
 }
 
+static void set_theme_bg_color()
+{
+#if GTK_CHECK_VERSION(3,0,0)
+       GdkRGBA bg_color;
+       GdkColor theme_color;
+       GtkStyleContext *style_context;
+       GList *work;
+       LayoutWindow *lw;
+
+       if (!options->image.use_custom_border_color)
+               {
+               work = layout_window_list;
+               lw = work->data;
+
+               style_context = gtk_widget_get_style_context(lw->window);
+               gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color);
+
+               theme_color.red = bg_color.red * 65535;
+               theme_color.green = bg_color.green * 65535;
+               theme_color.blue = bg_color.blue * 65535;
+
+               while (work)
+                       {
+                       lw = work->data;
+                       image_background_set_color(lw->image, &theme_color);
+                       work = work->next;
+                       }
+               }
+
+       view_window_colors_update();
+#endif
+}
+
+static gboolean theme_change_cb(GObject *gobject, GParamSpec *pspec, gpointer data)
+{
+       set_theme_bg_color();
+
+       return FALSE;
+}
+
 /**
  * @brief Set up the application paths
  * 
 /**
  * @brief Set up the application paths
  * 
@@ -1285,6 +1327,7 @@ gint main(gint argc, gchar *argv[])
        gboolean disable_clutter = FALSE;
        gboolean single_dir = TRUE;
        LayoutWindow *lw;
        gboolean disable_clutter = FALSE;
        gboolean single_dir = TRUE;
        LayoutWindow *lw;
+       GtkSettings *default_settings;
 
 #ifdef HAVE_GTHREAD
 #if !GLIB_CHECK_VERSION(2,32,0)
 
 #ifdef HAVE_GTHREAD
 #if !GLIB_CHECK_VERSION(2,32,0)
@@ -1575,6 +1618,10 @@ gint main(gint argc, gchar *argv[])
                marks_load();
        }
 
                marks_load();
        }
 
+       default_settings = gtk_settings_get_default();
+       g_signal_connect(default_settings, "notify::gtk-theme-name", G_CALLBACK(theme_change_cb), NULL);
+       set_theme_bg_color();
+
        DEBUG_1("%s main: gtk_main", get_exec_time());
        gtk_main();
 #ifdef HAVE_GTHREAD
        DEBUG_1("%s main: gtk_main", get_exec_time());
        gtk_main();
 #ifdef HAVE_GTHREAD
index 70257c0..5ebf0d5 100644 (file)
@@ -2235,7 +2235,7 @@ static gboolean rt_realize_cb(GtkWidget *widget, gpointer data)
                rt->surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget));
 
                cr = cairo_create(rt->surface);
                rt->surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget));
 
                cr = cairo_create(rt->surface);
-               cairo_set_source_rgb(cr, (gdouble)options->image.border_color.red  /65535, (gdouble)options->image.border_color.green / 65535, (gdouble)options->image.border_color.blue / 65535);
+               cairo_set_source_rgb(cr, (gdouble)rt->pr->color.red / 65535, (gdouble)rt->pr->color.green / 65535, (gdouble)rt->pr->color.blue / 65535);
                cairo_paint(cr);
                cairo_destroy(cr);
                }
                cairo_paint(cr);
                cairo_destroy(cr);
                }