From: Daniel Carl Date: Sun, 23 Dec 2012 01:40:42 +0000 (+0100) Subject: Allow to set hint element style on runtime. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=06e7ae451015635c07b79f019c5ef0870c53f8bc;p=vimb.git Allow to set hint element style on runtime. --- diff --git a/src/hints.c b/src/hints.c index 8f81cdb..906207e 100644 --- a/src/hints.c +++ b/src/hints.c @@ -27,10 +27,6 @@ #define HINT_CONTAINER_ID "__hint_container" #define HINT_CLASS "__hint" -#define ELEM_BACKGROUND "#ff0" -#define ELEM_BACKGROUND_FOCUS "#8f0" -#define ELEM_COLOR "#000" - #define HINT_CONTAINER_STYLE "line-height:1em;" #define HINT_STYLE "z-index:100000;"\ "position:absolute;"\ @@ -293,8 +289,8 @@ static void hints_create_for_window(const gchar* input, Window* win, gulong hint g_free(num); /* change the style of the hinted element */ - dom_element_style_set_property(newHint->elem, "background-color", ELEM_BACKGROUND); - dom_element_style_set_property(newHint->elem, "color", ELEM_COLOR); + dom_element_style_set_property(newHint->elem, "background-color", vp.style.hint_bg); + dom_element_style_set_property(newHint->elem, "color", vp.style.hint_fg); webkit_dom_node_append_child(WEBKIT_DOM_NODE(container), WEBKIT_DOM_NODE(hint), NULL); } @@ -322,7 +318,7 @@ static void hints_focus(const gulong num) Hint* hint = hints_get_hint_by_number(vp.hints.focusNum); if (hint) { /* reset previous focused element */ - dom_element_style_set_property(hint->elem, "background-color", ELEM_BACKGROUND); + dom_element_style_set_property(hint->elem, "background-color", vp.style.hint_bg); doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(hint->elem)); dom_dispatch_mouse_event(doc, hint->elem, "mouseout", 0); @@ -331,7 +327,7 @@ static void hints_focus(const gulong num) hint = hints_get_hint_by_number(num); if (hint) { /* mark new hint as focused */ - dom_element_style_set_property(hint->elem, "background-color", ELEM_BACKGROUND_FOCUS); + dom_element_style_set_property(hint->elem, "background-color", vp.style.hint_bg_focus); doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(hint->elem)); dom_dispatch_mouse_event(doc, hint->elem, "mouseover", 0); diff --git a/src/main.h b/src/main.h index 1159946..c944f51 100644 --- a/src/main.h +++ b/src/main.h @@ -69,6 +69,8 @@ #define VP_WIDGET_OVERRIDE_FONT gtk_widget_modify_font #endif +#define HEX_COLOR_LEN 8 + /* enums */ typedef enum _vp_mode { VP_MODE_NORMAL = 1<<0, @@ -215,6 +217,10 @@ typedef struct { VpColor comp_fg[VP_COMP_LAST]; VpColor comp_bg[VP_COMP_LAST]; PangoFontDescription* comp_font[VP_COMP_LAST]; + /* hint style */ + gchar hint_bg[HEX_COLOR_LEN]; + gchar hint_bg_focus[HEX_COLOR_LEN]; + gchar hint_fg[HEX_COLOR_LEN]; } Style; typedef struct { diff --git a/src/setting.c b/src/setting.c index fa083bf..271ced3 100644 --- a/src/setting.c +++ b/src/setting.c @@ -30,6 +30,7 @@ static gboolean setting_status_color_fg(const Setting* s); static gboolean setting_status_font(const Setting* s); static gboolean setting_input_style(const Setting* s); static gboolean setting_completion_style(const Setting* s); +static gboolean setting_hint_style(const Setting* s); static Setting default_settings[] = { /* webkit settings */ @@ -96,6 +97,9 @@ static Setting default_settings[] = { {NULL, "completion-fg-active", TYPE_CHAR, setting_completion_style, {.s = "#fff"}}, {NULL, "completion-bg-normal", TYPE_CHAR, setting_completion_style, {.s = "#656565"}}, {NULL, "completion-bg-active", TYPE_CHAR, setting_completion_style, {.s = "#777777"}}, + {NULL, "hint-bg", TYPE_CHAR, setting_hint_style, {.s = "#ff0"}}, + {NULL, "hint-bg-focus", TYPE_CHAR, setting_hint_style, {.s = "#8f0"}}, + {NULL, "hint-fg", TYPE_CHAR, setting_hint_style, {.s = "#000"}}, }; @@ -272,3 +276,20 @@ static gboolean setting_completion_style(const Setting* s) return TRUE; } + +static gboolean setting_hint_style(const Setting* s) +{ + Style* style = &vp.style; + if (!g_strcmp0(s->name, "hint-bg")) { + strncpy(style->hint_bg, s->arg.s, HEX_COLOR_LEN - 1); + style->hint_bg[HEX_COLOR_LEN - 1] = '\0'; + } else if (!g_strcmp0(s->name, "hint-bg-focus")) { + strncpy(style->hint_bg_focus, s->arg.s, HEX_COLOR_LEN - 1); + style->hint_bg_focus[HEX_COLOR_LEN] = '\0'; + } else if (!g_strcmp0(s->name, "hint-fg")) { + strncpy(style->hint_fg, s->arg.s, HEX_COLOR_LEN - 1); + style->hint_fg[HEX_COLOR_LEN - 1] = '\0'; + } + + return TRUE; +}