set user-defined color as image background - patch by Laurent MONIN
authorVladimir Nadvornik <nadvornik@suse.cz>
Sat, 29 Mar 2008 10:38:15 +0000 (10:38 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Sat, 29 Mar 2008 10:38:15 +0000 (10:38 +0000)
15 files changed:
src/fullscreen.c
src/fullscreen.h
src/globals.c
src/gqview.h
src/image.c
src/image.h
src/img-view.c
src/layout.c
src/layout_image.c
src/pixbuf-renderer.c
src/pixbuf-renderer.h
src/preferences.c
src/rcfile.c
src/ui_misc.c
src/ui_misc.h

index 8d649c9..6f87ed1 100644 (file)
@@ -292,10 +292,9 @@ FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
 
        gtk_container_add(GTK_CONTAINER(fs->window), fs->imd->widget);
 
-       /* set background to black */
-       if (BLACK_BACKGROUND)
+       if (user_specified_window_background)
                {
-               image_background_set_black(fs->imd, TRUE);
+               image_background_set_color(fs->imd, &window_background_color);
                }
 
        image_set_delay_flip(fs->imd, fullscreen_clean_flip);
index 189920f..3a13060 100644 (file)
@@ -15,7 +15,6 @@
 
 #define FULL_SCREEN_HIDE_MOUSE_DELAY 3000
 #define FULL_SCREEN_BUSY_MOUSE_DELAY 200
-#define BLACK_BACKGROUND 1
 
 
 FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
index c119bca..a1fa2fd 100644 (file)
@@ -91,7 +91,8 @@ gint enable_read_ahead = TRUE;
 
 gint place_dialogs_under_mouse = FALSE;
 
-gint black_window_background = FALSE;
+gint user_specified_window_background = FALSE;
+GdkColor window_background_color = {0, 0, 0, 0};
 
 gint fullscreen_screen = -1;
 gint fullscreen_clean_flip = FALSE;
index ba0008e..49fa4b0 100644 (file)
@@ -156,7 +156,8 @@ extern gint slideshow_repeat;
 extern gint mousewheel_scrolls;
 extern gint enable_in_place_rename;
 
-extern gint black_window_background;
+extern gint user_specified_window_background;
+extern GdkColor window_background_color;
 
 extern gint fullscreen_screen;
 extern gint fullscreen_clean_flip;
index 2deb67b..563541a 100644 (file)
@@ -1559,11 +1559,6 @@ void image_top_window_set_sync(ImageWindow *imd, gint allow_sync)
        g_object_set(G_OBJECT(imd->pr), "window_fit", allow_sync, NULL);
 }
 
-void image_background_set_black(ImageWindow *imd, gint black)
-{
-       pixbuf_renderer_set_black((PixbufRenderer *)imd->pr, black);
-}
-
 void image_background_set_color(ImageWindow *imd, GdkColor *color)
 {
        pixbuf_renderer_set_color((PixbufRenderer *)imd->pr, color);
index b10f91e..d775aa3 100644 (file)
@@ -92,7 +92,6 @@ void image_auto_refresh(ImageWindow *imd, gint interval);
 void image_top_window_set_sync(ImageWindow *imd, gint allow_sync);
 
 /* background of image */
-void image_background_set_black(ImageWindow *imd, gint black);
 void image_background_set_color(ImageWindow *imd, GdkColor *color);
 
 /* color profiles */
index 0f9f284..091ce19 100644 (file)
@@ -859,7 +859,7 @@ static ViewWindow *real_view_window_new(FileData *fd, GList *list, CollectionDat
 
        vw->imd = image_new(FALSE);
 
-       if (black_window_background) image_background_set_black(vw->imd, TRUE);
+       image_background_set_color(vw->imd, user_specified_window_background ? &window_background_color : NULL);
 
        image_attach_window(vw->imd, vw->window, NULL, "Geeqie", TRUE);
 
@@ -1015,7 +1015,7 @@ void view_window_colors_update(void)
                ViewWindow *vw = work->data;
                work = work->next;
 
-               image_background_set_black(vw->imd, black_window_background);
+               image_background_set_color(vw->imd, user_specified_window_background ? &window_background_color : NULL);
                }
 }
 
index 77edcdd..4e49fbb 100644 (file)
@@ -1731,8 +1731,9 @@ void layout_colors_update(void)
                {
                LayoutWindow *lw = work->data;
                work = work->next;
-
-               if (lw->image) image_background_set_black(lw->image, black_window_background);
+               
+               if (!lw->image) continue;
+               image_background_set_color(lw->image, user_specified_window_background ? &window_background_color : NULL);
                }
 }
 
index edc03dc..0c6cc90 100644 (file)
@@ -1616,7 +1616,7 @@ GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
 
                gtk_widget_ref(lw->split_images[i]->widget);
 
-               if (black_window_background) image_background_set_black(lw->split_images[i], TRUE);
+               image_background_set_color(lw->split_images[i], user_specified_window_background ? &window_background_color : NULL);
 
                image_auto_refresh(lw->split_images[i], 0);
 
index 0a552c5..1724b18 100644 (file)
@@ -1285,33 +1285,25 @@ void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkColor *color)
 
        widget = GTK_WIDGET(pr);
 
-       style = gtk_style_copy(gtk_widget_get_style(widget));
-       g_object_ref(G_OBJECT(style));
-
-       if (color)
-               {
+       if (color) {
                GdkColor *slot;
 
+               style = gtk_style_copy(gtk_widget_get_style(widget));
                slot = &style->bg[GTK_STATE_NORMAL];
 
                slot->red = color->red;
                slot->green = color->green;
                slot->blue = color->blue;
                }
+       else {
+               style = gtk_style_copy(gtk_widget_get_default_style());
+       }
 
        gtk_widget_set_style(widget, style);
-       g_object_unref(G_OBJECT(style));
 
        if (GTK_WIDGET_VISIBLE(widget)) pr_border_clear(pr);
 }
 
-void pixbuf_renderer_set_black(PixbufRenderer *pr, gint black)
-{
-       GdkColor color = { 0, 0, 0, 0};
-
-       pixbuf_renderer_set_color(pr, &color);
-}
-
 
 /*
  *-------------------------------------------------------------------
index 28766ba..872b0e9 100644 (file)
@@ -212,9 +212,7 @@ gint pixbuf_renderer_get_visible_rect(PixbufRenderer *pr, GdkRectangle *rect);
 gint pixbuf_renderer_get_virtual_rect(PixbufRenderer *pr, GdkRectangle *rect);
 
 /* background color */
-
 void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkColor *color);
-void pixbuf_renderer_set_black(PixbufRenderer *pr, gint black);
 
 /* overlay */
 
index b7ea641..1714859 100644 (file)
@@ -114,7 +114,8 @@ static gint zoom_increment_c;
 
 static gint enable_read_ahead_c;
 
-static gint black_window_background_c;
+static gint user_specified_window_background_c;
+static GdkColor window_background_color_c;
 
 static gint fullscreen_screen_c;
 static gint fullscreen_clean_flip_c;
@@ -277,10 +278,11 @@ static void config_window_apply(void)
 
        enable_read_ahead = enable_read_ahead_c;
 
-       if (black_window_background != black_window_background_c)
+       if (user_specified_window_background != user_specified_window_background_c
+           || !gdk_color_equal(&window_background_color, &window_background_color_c))
                {
-               black_window_background = black_window_background_c;
-
+               user_specified_window_background = user_specified_window_background_c;
+               window_background_color = window_background_color_c;
                layout_colors_update();
                view_window_colors_update();
                }
@@ -957,8 +959,11 @@ static void config_window_create(void)
 
        group = pref_group_new(vbox, FALSE, _("Appearance"), GTK_ORIENTATION_VERTICAL);
 
-       pref_checkbox_new_int(group, _("Black background"),
-                             black_window_background, &black_window_background_c);
+       pref_checkbox_new_int(group, _("User specified background color"),
+                             user_specified_window_background, &user_specified_window_background_c);
+
+       pref_colorbutton_new(group, _("Background color"), &window_background_color,
+                            G_CALLBACK(pref_background_color_set_cb), &window_background_color_c);
 
        group = pref_group_new(vbox, FALSE, _("Convenience"), GTK_ORIENTATION_VERTICAL);
 
index 0841c44..357f601 100644 (file)
@@ -81,6 +81,29 @@ static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *valu
        return text;
 }
 
+static void write_color_option(FILE *f, gchar *label, GdkColor *color)
+{
+       if (color)
+               {
+               gchar *colorstring = gdk_color_to_string (color);
+
+               fprintf(f,"%s: \"%s\"\n", label, colorstring);
+               g_free(colorstring);
+               }
+       else
+               fprintf(f,"%s: \n", label);
+}
+
+static GdkColor *read_color_option(FILE *f, gchar *option, gchar *label, gchar *value, GdkColor *color)
+{
+       if (strcasecmp(option, label) == 0)
+               {
+               gdk_color_parse(quoted_value(value), color);
+               }
+       return color;
+}
+
+
 static void write_int_option(FILE *f, gchar *label, gint n)
 {
        fprintf(f,"%s: %d\n\n", label, n);
@@ -283,7 +306,8 @@ void save_options(void)
 
        write_bool_option(f, "display_dialogs_under_mouse", place_dialogs_under_mouse);
 
-       write_bool_option(f, "black_window_background", black_window_background);
+       write_bool_option(f, "user_specified_window_background", user_specified_window_background);
+       write_color_option(f, "window_background_color", &window_background_color);
 
        write_int_option(f, "fullscreen_screen", fullscreen_screen);
        write_bool_option(f, "fullscreen_clean_flip", fullscreen_clean_flip);
@@ -547,8 +571,10 @@ void load_options(void)
                place_dialogs_under_mouse = read_bool_option(f, option,
                        "display_dialogs_under_mouse", value, place_dialogs_under_mouse);
 
-               black_window_background = read_bool_option(f, option,
-                       "black_window_background", value, black_window_background);
+               user_specified_window_background = read_bool_option(f, option,
+                       "user_specified_window_background", value, user_specified_window_background);
+               read_color_option(f, option,
+                       "window_background_color", value, &window_background_color);
 
                fullscreen_screen = read_int_option(f, option,
                        "fullscreen_screen", value, fullscreen_screen);
index 618df29..aaf38c3 100644 (file)
@@ -1614,3 +1614,50 @@ gint pref_list_string_get(const gchar *group, const gchar *key, const gchar **re
 }
 
 
+void pref_background_color_set_cb(GtkWidget *widget, gpointer data)
+{
+       GdkColor *color = data;
+
+       gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), color);
+}
+
+GtkWidget *pref_colorbutton_new(GtkWidget *parent_box,
+                               const gchar *title, const GdkColor *color,
+                               GCallback func, gpointer data)
+{
+       GtkWidget *button;
+       
+       if (color)
+               {
+               button = gtk_color_button_new_with_color(color);
+               }
+       else
+               {
+               button = gtk_color_button_new();
+               }
+
+       if (func) g_signal_connect(G_OBJECT(button), "color-set", func, data);
+
+       if (title)
+               {
+               GtkWidget *label;
+               GtkWidget *hbox;
+
+               gtk_color_button_set_title(GTK_COLOR_BUTTON(button), title);
+               label = gtk_label_new(title);
+
+               hbox = gtk_hbox_new(TRUE, 0);
+               gtk_box_pack_start(GTK_BOX(parent_box), hbox, TRUE, TRUE, 0);
+               
+               gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+               gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
+
+               gtk_widget_show_all(hbox);
+               }
+       else
+               {
+               gtk_widget_show(button);
+               }
+       
+       return button;
+}
index 1c98bbc..6d8c12e 100644 (file)
@@ -179,5 +179,11 @@ void pref_list_string_set(const gchar *group, const gchar *key, const gchar *val
 gint pref_list_string_get(const gchar *group, const gchar *key, const gchar **result);
 
 
+void pref_background_color_set_cb(GtkWidget *widget, gpointer data);
+GtkWidget *pref_colorbutton_new(GtkWidget *parent_box,
+                               const gchar *title, const GdkColor *color,
+                               GCallback func, gpointer data);
+
+
 #endif