From d2bd40f0f17ed1c01872ee37afde706f2243eec2 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Mon, 5 Nov 2012 20:50:08 +0100 Subject: [PATCH] Allow setting of input box color and fonts. --- src/command.c | 7 ++++++- src/config.h | 5 ----- src/main.c | 38 +++++++++++++++++--------------------- src/main.h | 14 +++++++++++--- src/setting.c | 32 +++++++++++++++++++++++++++++++- 5 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/command.c b/src/command.c index add7da5..f6a59ac 100644 --- a/src/command.c +++ b/src/command.c @@ -115,7 +115,12 @@ gboolean command_input(const Arg* arg) const gchar* url; /* reset the colors and fonts to defalts */ - vp_set_widget_font(vp.gui.inputbox, inputbox_font[0], inputbox_bg[0], inputbox_fg[0]); + vp_set_widget_font( + vp.gui.inputbox, + &vp.style.input_fg[VP_MSG_NORMAL], + &vp.style.input_bg[VP_MSG_NORMAL], + vp.style.input_font[VP_MSG_NORMAL] + ); /* remove content from input box */ gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), ""); diff --git a/src/config.h b/src/config.h index 99c7a7c..86495db 100644 --- a/src/config.h +++ b/src/config.h @@ -24,11 +24,6 @@ #define START_PAGE "http://sourceforge.net/apps/trac/vimprobable" - /* normal error */ -const char *inputbox_font[2] = { "monospace normal 8", "monospace bold 8"}; -const char *inputbox_fg[2] = { "#000000", "#000000" }; -const char *inputbox_bg[2] = { "#ffffff", "#ff0000" }; - #define SETTING_DEFAUL_FONT_SIZE 12 #define SETTING_USER_AGENT PROJECT "/" VERSION " (X11; Linux i686) AppleWebKit/535.22+ Compatible (Safari)" #define SETTING_MAX_CONNS 25 diff --git a/src/main.c b/src/main.c index 272ae0c..0acf590 100644 --- a/src/main.c +++ b/src/main.c @@ -254,8 +254,14 @@ static gboolean vp_hide_message(void) if (vp.state.mode == VP_MODE_COMMAND) { return FALSE; } - const MessageType type = VP_MSG_NORMAL; - vp_set_widget_font(vp.gui.inputbox, inputbox_font[type], inputbox_bg[type], inputbox_fg[type]); + + vp_set_widget_font( + vp.gui.inputbox, + &vp.style.input_fg[VP_MSG_NORMAL], + &vp.style.input_bg[VP_MSG_NORMAL], + vp.style.input_font[VP_MSG_NORMAL] + ); + gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), ""); return FALSE; @@ -354,7 +360,12 @@ void vp_echo(const MessageType type, const char *error, ...) } /* set the collors according to message type */ - vp_set_widget_font(vp.gui.inputbox, inputbox_font[type], inputbox_bg[type], inputbox_fg[type]); + vp_set_widget_font( + vp.gui.inputbox, + &vp.style.input_fg[type], + &vp.style.input_bg[type], + vp.style.input_font[type] + ); gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), message); g_timeout_add_seconds(2, (GSourceFunc)vp_hide_message, NULL); } @@ -456,8 +467,6 @@ static void vp_init_gui(void) gtk_entry_set_inner_border(GTK_ENTRY(gui->inputbox), NULL); g_object_set(gtk_widget_get_settings(gui->inputbox), "gtk-entry-select-on-focus", FALSE, NULL); - vp_set_widget_font(gui->inputbox, inputbox_font[0], inputbox_bg[0], inputbox_fg[0]); - /* Prepare the statusbar */ gui->statusbar.box = GTK_BOX(gtk_hbox_new(FALSE, 0)); gui->statusbar.left = gtk_label_new(NULL); @@ -503,24 +512,11 @@ static void vp_init_files(void) g_free(path); } -void vp_set_widget_font(GtkWidget* widget, const gchar* font_definition, const gchar* bg_color, const gchar* fg_color) +void vp_set_widget_font(GtkWidget* widget, const GdkColor* fg, const GdkColor* bg, PangoFontDescription* font) { - GdkColor fg, bg; - PangoFontDescription *font; - - font = pango_font_description_from_string(font_definition); gtk_widget_modify_font(widget, font); - pango_font_description_free(font); - - if (fg_color) { - gdk_color_parse(fg_color, &fg); - } - if (bg_color) { - gdk_color_parse(bg_color, &bg); - } - - gtk_widget_modify_text(widget, GTK_STATE_NORMAL, fg_color ? &fg : NULL); - gtk_widget_modify_base(widget, GTK_STATE_NORMAL, bg_color ? &bg : NULL); + gtk_widget_modify_text(widget, GTK_STATE_NORMAL, fg); + gtk_widget_modify_base(widget, GTK_STATE_NORMAL, bg); } static void vp_setup_signals(void) diff --git a/src/main.h b/src/main.h index 99674a3..735e2a4 100644 --- a/src/main.h +++ b/src/main.h @@ -90,7 +90,8 @@ enum { }; typedef enum { VP_MSG_NORMAL, - VP_MSG_ERROR + VP_MSG_ERROR, + VP_MSG_LAST } MessageType; enum { @@ -169,6 +170,12 @@ typedef struct { GList* active; } Completions; +typedef struct { + GdkColor input_fg[VP_MSG_LAST]; + GdkColor input_bg[VP_MSG_LAST]; + PangoFontDescription* input_font[VP_MSG_LAST]; +} Style; + /* core struct */ typedef struct { Gui gui; @@ -180,6 +187,7 @@ typedef struct { #endif Config config; Completions comps; + Style style; #if 0 Ssl ssl; Communication comm; @@ -193,9 +201,9 @@ extern VpCore vp; /* functions */ void vp_update_statusbar(void); void vp_update_urlbar(const gchar* uri); -void vp_echo(const MessageType type, const char *error, ...); +void vp_echo(const MessageType type, const char* error, ...); gboolean vp_set_mode(const Arg* arg); -void vp_set_widget_font(GtkWidget* widget, const gchar* font_definition, const gchar* bg_color, const gchar* fg_color); +void vp_set_widget_font(GtkWidget* widget, const GdkColor* fg, const GdkColor* bg, PangoFontDescription* font); gboolean vp_load_uri(const Arg* arg); void vp_clean_up(void); diff --git a/src/setting.c b/src/setting.c index 3ece1e6..738a085 100644 --- a/src/setting.c +++ b/src/setting.c @@ -28,6 +28,7 @@ static gboolean setting_scrollstep(const Setting* s); static gboolean setting_status_color_bg(const Setting* s); static gboolean setting_status_color_fg(const Setting* s); static gboolean setting_status_font(const Setting* s); +static gboolean setting_style(const Setting* s); static Setting default_settings[] = { /* webkit settings */ @@ -83,6 +84,12 @@ static Setting default_settings[] = { {"status-color-bg", TYPE_CHAR, setting_status_color_bg, {.s = "#000"}}, {"status-color-fg", TYPE_CHAR, setting_status_color_fg, {.s = "#fff"}}, {"status-font", TYPE_CHAR, setting_status_font, {.s = "monospace bold 8"}}, + {"input-bg-normal", TYPE_CHAR, setting_style, {.s = "#fff"}}, + {"input-bg-error", TYPE_CHAR, setting_style, {.s = "#f00"}}, + {"input-fg-normal", TYPE_CHAR, setting_style, {.s = "#000"}}, + {"input-fg-error", TYPE_CHAR, setting_style, {.s = "#000"}}, + {"input-font-normal", TYPE_CHAR, setting_style, {.s = "monospace normal 8"}}, + {"input-font-error", TYPE_CHAR, setting_style, {.s = "monospace bold 8"}}, }; static GHashTable* settings = NULL; @@ -129,7 +136,7 @@ gboolean setting_run(const gchar* name, const gchar* param) a = util_char_to_arg(param, s->type); if (a == NULL) { vp_echo(VP_MSG_ERROR, "No valid value"); - return FALSE; + return FALSE; } s->arg = *a; @@ -220,3 +227,26 @@ static gboolean setting_status_font(const Setting* s) return TRUE; } + +static gboolean setting_style(const Setting* s) +{ + Style* style = &vp.style; + + MessageType type = g_str_has_suffix(s->name, "error") ? VP_MSG_ERROR : VP_MSG_NORMAL; + + if (g_str_has_prefix(s->name, "input-bg")) { + PRINT_DEBUG("Set style %s -> %s", s->name, s->arg.s); + gdk_color_parse(s->arg.s, &style->input_bg[type]); + } else if (g_str_has_prefix(s->name, "input-fg")) { + PRINT_DEBUG("Set style %s -> %s", s->name, s->arg.s); + gdk_color_parse(s->name, &style->input_fg[type]); + } else if (g_str_has_prefix(s->arg.s, "input-font")) { + PRINT_DEBUG("Set style %s -> %s", s->name, s->arg.s); + if (style->input_font[type]) { + pango_font_description_free(style->input_font[type]); + } + style->input_font[type] = pango_font_description_from_string(s->arg.s); + } + + return TRUE; +} -- 2.20.1