changeset 208:fa0e05f985c3

set user-defined color as image background - patch by Laurent MONIN
author nadvornik
date Sat, 29 Mar 2008 10:38:15 +0000
parents ec068409bee7
children ad78ad18523a
files 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
diffstat 15 files changed, 110 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/fullscreen.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/fullscreen.c	Sat Mar 29 10:38:15 2008 +0000
@@ -292,10 +292,9 @@
 
 	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);
--- a/src/fullscreen.h	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/fullscreen.h	Sat Mar 29 10:38:15 2008 +0000
@@ -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,
--- a/src/globals.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/globals.c	Sat Mar 29 10:38:15 2008 +0000
@@ -91,7 +91,8 @@
 
 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;
--- a/src/gqview.h	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/gqview.h	Sat Mar 29 10:38:15 2008 +0000
@@ -156,7 +156,8 @@
 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;
--- a/src/image.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/image.c	Sat Mar 29 10:38:15 2008 +0000
@@ -1559,11 +1559,6 @@
 	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);
--- a/src/image.h	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/image.h	Sat Mar 29 10:38:15 2008 +0000
@@ -92,7 +92,6 @@
 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 */
--- a/src/img-view.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/img-view.c	Sat Mar 29 10:38:15 2008 +0000
@@ -859,7 +859,7 @@
 
 	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 @@
 		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);
 		}
 }
 
--- a/src/layout.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/layout.c	Sat Mar 29 10:38:15 2008 +0000
@@ -1731,8 +1731,9 @@
 		{
 		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);
 		}
 }
 
--- a/src/layout_image.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/layout_image.c	Sat Mar 29 10:38:15 2008 +0000
@@ -1616,7 +1616,7 @@
 
 		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);
 
--- a/src/pixbuf-renderer.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/pixbuf-renderer.c	Sat Mar 29 10:38:15 2008 +0000
@@ -1285,33 +1285,25 @@
 
 	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);
-}
-
 
 /*
  *-------------------------------------------------------------------
--- a/src/pixbuf-renderer.h	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/pixbuf-renderer.h	Sat Mar 29 10:38:15 2008 +0000
@@ -212,9 +212,7 @@
 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 */
 
--- a/src/preferences.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/preferences.c	Sat Mar 29 10:38:15 2008 +0000
@@ -114,7 +114,8 @@
 
 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 @@
 
 	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 @@
 
 	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);
 
--- a/src/rcfile.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/rcfile.c	Sat Mar 29 10:38:15 2008 +0000
@@ -81,6 +81,29 @@
 	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 @@
 
 	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 @@
 		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);
--- a/src/ui_misc.c	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/ui_misc.c	Sat Mar 29 10:38:15 2008 +0000
@@ -1614,3 +1614,50 @@
 }
 
 
+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;
+}
--- a/src/ui_misc.h	Sat Mar 29 10:11:02 2008 +0000
+++ b/src/ui_misc.h	Sat Mar 29 10:38:15 2008 +0000
@@ -179,5 +179,11 @@
 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