[Goodies-commits] r6744 - in xfce4-notes-plugin/trunk: . panel-plugin
Mike Massonnet
mmassonnet at xfce.org
Sun Feb 22 09:36:53 CET 2009
Author: mmassonnet
Date: 2009-02-22 08:36:52 +0000 (Sun, 22 Feb 2009)
New Revision: 6744
Added:
xfce4-notes-plugin/trunk/panel-plugin/color.c
xfce4-notes-plugin/trunk/panel-plugin/color.h
Modified:
xfce4-notes-plugin/trunk/ChangeLog
xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
xfce4-notes-plugin/trunk/panel-plugin/defines.h
xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c
Log:
Default background color in the settings dialog
Modified: xfce4-notes-plugin/trunk/ChangeLog
===================================================================
--- xfce4-notes-plugin/trunk/ChangeLog 2009-02-22 06:55:34 UTC (rev 6743)
+++ xfce4-notes-plugin/trunk/ChangeLog 2009-02-22 08:36:52 UTC (rev 6744)
@@ -1,3 +1,17 @@
+2009-02-22 Mike Massonnet <mmassonnet at xfce.org>
+
+Default background color in the settings dialog
+ * panel-plugin/color.[ch]:
+ - New file with functions related to colors and other functions to
+ update the gtk rc style
+ * panel-plugin/defines.h:
+ - New default values for colors
+ * panel-plugin/panel-plugin.c:
+ - (notes_plugin_register): Set initial color
+ - (notes_plugin_xfconf_property_changed): Listen to color changes
+ * panel-plugin/settings-dialog.c:
+ - New background color setting
+
2009-02-21 Mike Massonnet <mmassonnet at xfce.org>
Little change in the menu
Modified: xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/Makefile.am 2009-02-22 06:55:34 UTC (rev 6743)
+++ xfce4-notes-plugin/trunk/panel-plugin/Makefile.am 2009-02-22 08:36:52 UTC (rev 6744)
@@ -18,6 +18,8 @@
xfce4_notes_plugin_SOURCES = \
defines.h \
+ color.h \
+ color.c \
panel-plugin.c \
settings-dialog.c \
settings-dialog.h \
Added: xfce4-notes-plugin/trunk/panel-plugin/color.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/color.c (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/color.c 2009-02-22 08:36:52 UTC (rev 6744)
@@ -0,0 +1,227 @@
+/*
+ * Notes - panel plugin for Xfce Desktop Environment
+ * Copyright (C) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <glib.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+
+#include "color.h"
+
+#define RC_STYLE \
+ "gtk_color_scheme = \"notes_fg_color:#xxxxxxxxxxxx\\nnotes_bg_color:#xxxxxxxxxxxx\\nnotes_base_color:#xxxxxxxxxxxx\\nnotes_text_color:#xxxxxxxxxxxx\\nnotes_selected_bg_color:#xxxxxxxxxxxx\\nnotes_selected_fg_color:#xxxxxxxxxxxx\"\n" \
+ "style \"notes-default\" {\n" \
+ "xthickness = 2\n" \
+ "ythickness = 2\n" \
+ "fg[NORMAL] = @notes_fg_color\n" \
+ "fg[ACTIVE] = @notes_fg_color\n" \
+ "fg[PRELIGHT] = @notes_fg_color\n" \
+ "fg[SELECTED] = @notes_selected_fg_color\n" \
+ "fg[INSENSITIVE] = shade(3.0, at notes_fg_color)\n" \
+ "bg[NORMAL] = @notes_bg_color\n" \
+ "bg[ACTIVE] = shade(1.0233, at notes_bg_color)\n" \
+ "bg[PRELIGHT] = mix(0.90,shade(1.1, at notes_bg_color), at notes_selected_bg_color)\n" \
+ "bg[SELECTED] = @notes_selected_bg_color\n" \
+ "bg[INSENSITIVE] = shade(1.03, at notes_bg_color)\n" \
+ "base[NORMAL] = @notes_base_color\n" \
+ "base[ACTIVE] = shade(0.65, at notes_base_color)\n" \
+ "base[PRELIGHT] = @notes_base_color\n" \
+ "base[SELECTED] = @notes_selected_bg_color\n" \
+ "base[INSENSITIVE] = shade(1.025, at notes_bg_color)\n" \
+ "text[NORMAL] = @notes_text_color\n" \
+ "text[ACTIVE] = shade(0.95, at notes_base_color)\n" \
+ "text[PRELIGHT] = @notes_text_color\n" \
+ "text[SELECTED] = @notes_selected_fg_color\n" \
+ "text[INSENSITIVE] = mix(0.675,shade(0.95, at notes_bg_color), at notes_fg_color)\n" \
+ "}\n" \
+ "widget \"xfce4-notes-plugin*\" style \"notes-default\"\n"
+
+#define INCLUDE_CONTENT \
+ "\n\n# include rc style for the xfce4-notes-plugin" \
+ "\n\n%s" \
+ "\n\n# end of automatic change\n\n"
+
+static inline void
+update_gtkrc (const gchar *notesrc_file)
+{
+ gchar *gtkrc_file;
+ gchar *include_line;
+ gchar *include_content;
+ gchar *contents, *tmp;
+
+ gtkrc_file = g_strdup_printf ("%s/.gtkrc-2.0", g_get_home_dir ());
+ include_line = g_strdup_printf ("include \"%s\"", notesrc_file);
+ include_content = g_strdup_printf (INCLUDE_CONTENT, include_line);
+
+ g_file_get_contents (gtkrc_file, &contents, NULL, NULL);
+
+ if (contents == NULL)
+ {
+ g_file_set_contents (gtkrc_file, include_content, -1, NULL);
+ }
+ else if (!g_strrstr (contents, include_line))
+ {
+ tmp = contents;
+ contents = g_strconcat (tmp, include_content, NULL);
+ g_free (tmp);
+
+ g_file_set_contents (gtkrc_file, contents, -1, NULL);
+ }
+
+ g_free (include_content);
+ g_free (include_line);
+ g_free (gtkrc_file);
+ g_free (contents);
+}
+
+void
+color_set_background (const gchar *background)
+{
+ GdkColor color, *color2;
+ gchar *notesrc_file;
+ gchar *bg;
+ gchar *text;
+ gchar *selected;
+ gchar rc_style[] = RC_STYLE;
+ gchar *offset;
+
+ if (!gdk_color_parse (background, &color))
+ return;
+
+ /* bg */
+ bg = gdk_color_to_string (&color);
+
+ /* text */
+ color2 = gdk_color_copy (&color);
+ __gdk_color_contrast (color2, 5.);
+ text = gdk_color_to_string (color2);
+ gdk_color_free (color2);
+
+ /* selected */
+ color2 = gdk_color_copy (&color);
+ __gdk_color_contrast (color2, 3.2);
+ selected = gdk_color_to_string (color2);
+ gdk_color_free (color2);
+
+ /* notes_fg_color */
+ offset = rc_style + 35;
+ memcpy (offset, bg, 13);
+
+ /* notes_bg_color */
+ offset += 30;
+ memcpy (offset, text, 13);
+
+ /* notes_base_color */
+ offset += 32;
+ memcpy (offset, bg, 13);
+
+ /* notes_text_color */
+ offset += 32;
+ memcpy (offset, text, 13);
+
+ /* notes_selected_bg_color */
+ offset += 39;
+ memcpy (offset, selected, 13);
+
+ /* notes_selected_fg_color */
+ offset += 39;
+ memcpy (offset, bg, 13);
+
+ /* set the rc style */
+ notesrc_file = g_strdup_printf ("%s/xfce4/panel/xfce4-notes-plugin.gtkrc", g_get_user_config_dir ());
+ g_file_set_contents (notesrc_file, rc_style, -1, NULL);
+ update_gtkrc (notesrc_file);
+
+ gtk_rc_reparse_all ();
+
+ g_free (notesrc_file);
+ g_free (bg);
+ g_free (text);
+ g_free (selected);
+}
+
+void
+__gdk_color_contrast (GdkColor *color,
+ gdouble contrast)
+{
+ /* cf. http://accessibility.kde.org/hsl-adjusted.php */
+ gdouble N_r, N_g, N_b;
+ gdouble f_r = 0.2125, f_g = 0.7154, f_b = 0.0721;
+ gdouble L, L_, m, D, D_;
+ gdouble N__1, N_0, N_1;
+ gdouble N_r_, N_g_, N_b_;
+
+ g_return_if_fail (G_LIKELY (contrast >= 1 && contrast <= 21));
+
+ /* Calculate luminosity */
+ N_r = pow ((gdouble)color->red / G_MAXUINT16, 2.2);
+ N_g = pow ((gdouble)color->green / G_MAXUINT16, 2.2);
+ N_b = pow ((gdouble)color->blue / G_MAXUINT16, 2.2);
+
+ L = f_r * N_r + f_g * N_g + f_b * N_b;
+
+ /* Change luminosity */
+ L_ = (L + 0.05) / contrast - 0.05;
+
+ N__1 = MIN (N_r, MIN (N_g, N_b));
+ N_1 = MAX (N_r, MAX (N_g, N_b));
+ if (N_r > N__1 && N_r < N_1)
+ N_0 = N_r;
+ else if (N_g > N__1 && N_g < N_1)
+ N_0 = N_g;
+ else if (N_b > N__1 && N_b < N_1)
+ N_0 = N_b;
+ else
+ N_0 = N_1;
+
+ m = f_g + f_r * (N_0 - N__1) / (N_1 - N__1);
+ D = MIN (L / m, (1 - L) / (1 - m));
+ D_ = MIN (L_ / m, (1 - L_) / (1 - m));
+
+ N_r_ = L_ + (N_r - L) * D_ / D;
+ N_g_ = L_ + (N_g - L) * D_ / D;
+ N_b_ = L_ + (N_b - L) * D_ / D;
+
+ /* Conversion to RGB */
+ color->red = G_MAXUINT16 * pow (N_r_, 1 / 2.2);
+ color->green = G_MAXUINT16 * pow (N_g_, 1 / 2.2);
+ color->blue = G_MAXUINT16 * pow (N_b_, 1 / 2.2);
+}
+
+#if GTK_CHECK_VERSION (2,12,0)
+gchar *
+gdk_color_to_string (const GdkColor *color)
+{
+ g_return_val_if_fail (color != NULL, NULL);
+
+ return g_strdup_printf ("#%04x%04x%04x", color->red, color->green, color->blue);
+}
+#endif
+
Added: xfce4-notes-plugin/trunk/panel-plugin/color.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/color.h (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/color.h 2009-02-22 08:36:52 UTC (rev 6744)
@@ -0,0 +1,35 @@
+/*
+ * Notes - panel plugin for Xfce Desktop Environment
+ * Copyright (C) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef COLOR_H
+#define COLOR_H
+
+#include <glib.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+
+void color_set_background (const gchar *background);
+void __gdk_color_contrast (GdkColor *color,
+ gdouble contrast);
+#if GTK_CHECK_VERSION (2,12,0)
+gchar * gdk_color_to_string (const GdkColor *color);
+#endif
+
+#endif
+
Modified: xfce4-notes-plugin/trunk/panel-plugin/defines.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/defines.h 2009-02-22 06:55:34 UTC (rev 6743)
+++ xfce4-notes-plugin/trunk/panel-plugin/defines.h 2009-02-22 08:36:52 UTC (rev 6744)
@@ -28,6 +28,7 @@
/* Default settings */
#define GENERAL_HIDE_FROM_TASKBAR TRUE
#define GENERAL_HIDE_ARROW_BUTTON FALSE
+#define GENERAL_BACKGROUND_COLOR BACKGROUND_YELLOW
#define NEW_WINDOW_ABOVE FALSE
#define NEW_WINDOW_STICKY TRUE
#define NEW_WINDOW_TABS TRUE
@@ -36,10 +37,20 @@
#define NEW_WINDOW_FONT_DESCR "Sans 10"
#define NEW_WINDOW_WIDTH SIZE_NORMAL
#define NEW_WINDOW_HEIGHT ((gint)NEW_WINDOW_WIDTH*SIZE_FACTOR)
+
+/* Size values */
#define SIZE_SMALL 240
#define SIZE_NORMAL 305
#define SIZE_LARGE 340
#define SIZE_FACTOR 1.15
+/* Background color values */
+#define BACKGROUND_YELLOW "#FFEE75"
+#define BACKGROUND_RED "#FE8484"
+#define BACKGROUND_BLUE "#8FBBEC"
+#define BACKGROUND_GREEN "#95EA84"
+#define BACKGROUND_PURPLE "#D37AFF"
+#define BACKGROUND_WHITE "#F2F1EF"
+
#endif
Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2009-02-22 06:55:34 UTC (rev 6743)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2009-02-22 08:36:52 UTC (rev 6744)
@@ -18,12 +18,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "defines.h"
+#include "color.h"
#include "notes.h"
#ifdef HAVE_XFCONF
#include "settings-dialog.h"
@@ -134,6 +134,14 @@
"/general/hide_arrow_button",
GENERAL_HIDE_ARROW_BUTTON))
gtk_widget_hide (notes_plugin->btn_arrow);
+
+ gchar *background = xfconf_channel_get_string (notes_plugin->xfconf_channel,
+ "/general/background_color",
+ GENERAL_BACKGROUND_COLOR);
+ color_set_background (background);
+ g_free (background);
+#else
+ color_set_background (GENERAL_BACKGROUND_COLOR);
#endif
/* Load the notes */
@@ -408,8 +416,6 @@
gchar *property,
GValue *value)
{
- /* Refresh both elements
- * TODO find out how to guess efficiently the property name */
if (!g_ascii_strcasecmp (property, "/general/hide_windows_from_taskbar"))
{
GSList *l;
@@ -426,6 +432,10 @@
else
gtk_widget_show (notes_plugin->btn_arrow);
}
+ else if (!g_ascii_strcasecmp (property, "/general/background_color"))
+ {
+ color_set_background (g_value_get_string (value));
+ }
}
#endif
Modified: xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c 2009-02-22 06:55:34 UTC (rev 6743)
+++ xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c 2009-02-22 08:36:52 UTC (rev 6744)
@@ -28,18 +28,45 @@
#include "settings-dialog.h"
#include "notes.h"
+enum
+{
+ COMBOBOX_SIZE_SMALL,
+ COMBOBOX_SIZE_NORMAL,
+ COMBOBOX_SIZE_LARGE,
+};
+static GtkWidget *size_combo_box_new ();
+static void cb_size_changed (GtkComboBox *combobox, gpointer data);
-static void cb_size_changed (GtkComboBox *button,
- gpointer data);
+enum
+{
+ COMBOBOX_BACKGROUND_YELLOW,
+ COMBOBOX_BACKGROUND_RED,
+ COMBOBOX_BACKGROUND_BLUE,
+ COMBOBOX_BACKGROUND_GREEN,
+ COMBOBOX_BACKGROUND_PURPLE,
+ COMBOBOX_BACKGROUND_WHITE,
+ COMBOBOX_BACKGROUND_CUSTOM,
+};
+static GtkWidget *background_combo_box_new ();
+static void cb_background_changed (GtkComboBox *combobox, gpointer data);
+
+static GtkWidget *background_dialog_new ();
+static gchar *background_dialog_get_color (GtkColorSelectionDialog *dialog);
+static void cb_selection_changed (GtkColorSelection *selection, gpointer data);
+
+static GtkWidget *color_button_new ();
+static gboolean cb_color_button_pressed (GtkButton *button, GdkEventButton *event, gpointer data);
+
static XfconfChannel *xfconf_channel = NULL;
+static GtkWidget *color_combobox = NULL;
+static GtkWidget *color_button = NULL;
GtkWidget *
prop_dialog_new (NotesPlugin *notes_plugin)
{
GtkWidget *dialog, *frame, *box, *hbox, *button, *label;
- gint size;
/* Configuration channel */
if (NULL == xfconf_channel)
@@ -63,12 +90,11 @@
NULL);
xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog), _("Configure the plugin"));
gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-notes-plugin");
- gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_window_stick (GTK_WINDOW (dialog));
/* === Default settings === */
- box = gtk_vbox_new (TRUE, BORDER);
+ box = gtk_vbox_new (FALSE, BORDER);
frame = xfce_create_framebox_with_content (_("Default settings"), box);
gtk_container_set_border_width (GTK_CONTAINER (frame), BORDER);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), frame);
@@ -78,17 +104,30 @@
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), GENERAL_HIDE_FROM_TASKBAR);
xfconf_g_property_bind (xfconf_channel, "/general/hide_windows_from_taskbar",
G_TYPE_BOOLEAN, G_OBJECT (button), "active");
- gtk_container_add (GTK_CONTAINER (box), button);
+ gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0);
/* Hide arrow button */
button = gtk_check_button_new_with_label (_("Hide arrow button"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), GENERAL_HIDE_ARROW_BUTTON);
xfconf_g_property_bind (xfconf_channel, "/general/hide_arrow_button",
G_TYPE_BOOLEAN, G_OBJECT (button), "active");
- gtk_container_add (GTK_CONTAINER (box), button);
+ gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0);
+ /* Background color */
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, FALSE, 0);
+
+ label = gtk_label_new (_("Background:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ color_combobox = background_combo_box_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), color_combobox, FALSE, FALSE, 0);
+
+ color_button = color_button_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), color_button, FALSE, FALSE, 0);
+
/* === New window settings === */
- box = gtk_vbox_new (TRUE, BORDER);
+ box = gtk_vbox_new (FALSE, BORDER);
frame = xfce_create_framebox_with_content (_("New window settings"), box);
gtk_container_set_border_width (GTK_CONTAINER (frame), BORDER);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), frame);
@@ -136,52 +175,65 @@
label = gtk_label_new (_("Size:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- button = gtk_combo_box_new_text ();
- gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Small"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Normal"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Large"));
+ button = size_combo_box_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+
+ /* === Ending === */
+ gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+
+ return dialog;
+}
+
+static GtkWidget *
+size_combo_box_new ()
+{
+ GtkWidget *combobox;
+ gint size;
+
+ combobox = gtk_combo_box_new_text ();
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Small"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Normal"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Large"));
+
size = xfconf_channel_get_int (xfconf_channel, "/new_window/width", SIZE_NORMAL);
if (size == SIZE_SMALL)
- gtk_combo_box_set_active (GTK_COMBO_BOX (button), 0);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), COMBOBOX_SIZE_SMALL);
else if (size == SIZE_NORMAL)
- gtk_combo_box_set_active (GTK_COMBO_BOX (button), 1);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), COMBOBOX_SIZE_NORMAL);
else if (size == SIZE_LARGE)
- gtk_combo_box_set_active (GTK_COMBO_BOX (button), 2);
- g_signal_connect (button, "changed", G_CALLBACK (cb_size_changed), NULL);
- gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), COMBOBOX_SIZE_LARGE);
- /* === Ending === */
- gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+ g_signal_connect (combobox, "changed", G_CALLBACK (cb_size_changed), NULL);
- return dialog;
+ return combobox;
}
static void
-cb_size_changed (GtkComboBox *button,
+cb_size_changed (GtkComboBox *combobox,
gpointer data)
{
gint id;
gint width, height;
- id = gtk_combo_box_get_active (button);
+ id = gtk_combo_box_get_active (combobox);
- if (id < 0)
+ if (id < 0 || id > COMBOBOX_SIZE_LARGE)
{
- g_critical ("Trying to set a default size but got an active item < 0");
+ g_critical ("Trying to set a default size but got an invalid item");
return;
}
- if (id == 0)
+ if (id == COMBOBOX_SIZE_SMALL)
{
width = SIZE_SMALL;
height = (gint)SIZE_SMALL*SIZE_FACTOR;
}
- else if (id == 1)
+ else if (id == COMBOBOX_SIZE_NORMAL)
{
width = SIZE_NORMAL;
height = (gint)SIZE_NORMAL*SIZE_FACTOR;
}
- else if (id == 2)
+ else if (id == COMBOBOX_SIZE_LARGE)
{
width = SIZE_LARGE;
height = (gint)SIZE_LARGE*SIZE_FACTOR;
@@ -190,5 +242,185 @@
xfconf_channel_set_int (xfconf_channel, "/new_window/width", width);
xfconf_channel_set_int (xfconf_channel, "/new_window/height", height);
}
+
+static GtkWidget *
+background_combo_box_new ()
+{
+ GtkWidget *combobox;
+ gchar *color;
+ gint id;
+
+ combobox = gtk_combo_box_new_text ();
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Yellow"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Red"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Blue"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Green"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Purple"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("White"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combobox), _("Custom..."));
+
+ color = xfconf_channel_get_string (xfconf_channel, "/general/background_color", GENERAL_BACKGROUND_COLOR);
+ if (!g_ascii_strcasecmp (color, BACKGROUND_YELLOW))
+ id = COMBOBOX_BACKGROUND_YELLOW;
+ else if (!g_ascii_strcasecmp (color, BACKGROUND_RED))
+ id = COMBOBOX_BACKGROUND_RED;
+ else if (!g_ascii_strcasecmp (color, BACKGROUND_BLUE))
+ id = COMBOBOX_BACKGROUND_BLUE;
+ else if (!g_ascii_strcasecmp (color, BACKGROUND_GREEN))
+ id = COMBOBOX_BACKGROUND_GREEN;
+ else if (!g_ascii_strcasecmp (color, BACKGROUND_PURPLE))
+ id = COMBOBOX_BACKGROUND_PURPLE;
+ else if (!g_ascii_strcasecmp (color, BACKGROUND_WHITE))
+ id = COMBOBOX_BACKGROUND_WHITE;
+ else
+ id = COMBOBOX_BACKGROUND_CUSTOM;
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), id);
+ g_free (color);
+
+ g_signal_connect (combobox, "changed", G_CALLBACK (cb_background_changed), NULL);
+
+ return combobox;
+}
+
+static void
+cb_background_changed (GtkComboBox *combobox,
+ gpointer data)
+{
+ GtkWidget *dialog;
+ GdkColor gdkcolor;
+ gchar *color;
+ gint id;
+
+ id = gtk_combo_box_get_active (combobox);
+
+ if (id < 0 || id > COMBOBOX_BACKGROUND_CUSTOM)
+ {
+ g_critical ("Trying to set a default background but got an invalid item");
+ return;
+ }
+
+ if (id == COMBOBOX_BACKGROUND_YELLOW)
+ color = BACKGROUND_YELLOW;
+ else if (id == COMBOBOX_BACKGROUND_RED)
+ color = BACKGROUND_RED;
+ else if (id == COMBOBOX_BACKGROUND_BLUE)
+ color = BACKGROUND_BLUE;
+ else if (id == COMBOBOX_BACKGROUND_GREEN)
+ color = BACKGROUND_GREEN;
+ else if (id == COMBOBOX_BACKGROUND_PURPLE)
+ color = BACKGROUND_PURPLE;
+ else if (id == COMBOBOX_BACKGROUND_WHITE)
+ color = BACKGROUND_WHITE;
+ else if (id == COMBOBOX_BACKGROUND_CUSTOM)
+ {
+ dialog = background_dialog_new ();
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+ {
+ color = background_dialog_get_color (GTK_COLOR_SELECTION_DIALOG (dialog));
+ gdk_color_parse (color, &gdkcolor);
+ xfconf_channel_set_string (xfconf_channel, "/general/background_color", color);
+ g_free (color);
+
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (color_button), &gdkcolor);
+ }
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ xfconf_channel_set_string (xfconf_channel, "/general/background_color", color);
+
+ gdk_color_parse (color, &gdkcolor);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (color_button), &gdkcolor);
+}
+
+static GtkWidget *
+background_dialog_new ()
+{
+ GtkWidget *dialog;
+ GtkWidget *selection;
+ GdkColor gdkcolor;
+ gchar *color;
+
+ dialog = gtk_color_selection_dialog_new (_("Background Color"));
+
+ selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog));
+ gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (selection), FALSE);
+ g_signal_connect (selection, "color-changed", G_CALLBACK (cb_selection_changed), NULL);
+
+ color = xfconf_channel_get_string (xfconf_channel, "/general/background_color", GENERAL_BACKGROUND_COLOR);
+ gdk_color_parse (color, &gdkcolor);
+ gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (selection), &gdkcolor);
+ g_free (color);
+
+ return dialog;
+}
+
+static gchar *
+background_dialog_get_color (GtkColorSelectionDialog *dialog)
+{
+ GtkWidget *selection;
+ GdkColor color;
+
+ selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog));
+ gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (selection), &color);
+
+ return gdk_color_to_string (&color);
+}
+
+static void
+cb_selection_changed (GtkColorSelection *selection,
+ gpointer data)
+{
+ GdkColor color, *color2;
+
+ gtk_color_selection_get_current_color (selection, &color);
+
+ color2 = gdk_color_copy (&color);
+ __gdk_color_contrast (color2, 5.);
+
+ gtk_color_selection_set_previous_color (selection, color2);
+
+ gdk_color_free (color2);
+}
+
+static GtkWidget *
+color_button_new ()
+{
+ GtkWidget *button;
+ GdkColor gdkcolor;
+ gchar *color;
+
+ color = xfconf_channel_get_string (xfconf_channel, "/general/background_color", GENERAL_BACKGROUND_COLOR);
+ gdk_color_parse (color, &gdkcolor);
+ g_free (color);
+
+ button = gtk_color_button_new_with_color (&gdkcolor);
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+
+ g_signal_connect (button, "button-press-event", G_CALLBACK (cb_color_button_pressed), NULL);
+
+ return button;
+}
+
+static gboolean
+cb_color_button_pressed (GtkButton *button,
+ GdkEventButton *event,
+ gpointer data)
+{
+ gint id;
+
+ if (event->button != 1)
+ return TRUE;
+
+ id = gtk_combo_box_get_active (GTK_COMBO_BOX (color_combobox));
+
+ if (id == COMBOBOX_BACKGROUND_CUSTOM)
+ cb_background_changed (GTK_COMBO_BOX (color_combobox), NULL);
+ else
+ gtk_combo_box_set_active (GTK_COMBO_BOX (color_combobox), COMBOBOX_BACKGROUND_CUSTOM);
+
+ return TRUE;
+}
+
#endif
More information about the Goodies-commits
mailing list