Added setting for completion colors.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 5 Nov 2012 21:08:47 +0000 (22:08 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 10 Nov 2012 13:43:04 +0000 (14:43 +0100)
src/completion.c
src/main.c
src/main.h
src/setting.c

index 8f610b0..7a70ebe 100644 (file)
@@ -27,7 +27,7 @@ typedef struct {
 static GList* completion_init_completion(GList* target, GList* source);
 static GList* completion_update(GList* completion, GList* active, gboolean back);
 static void completion_show(gboolean back);
-static void completion_set_color(Completion* completion, gchar* fg, gchar* bg);
+static void completion_set_color(Completion* completion, const GdkColor* fg, const GdkColor* bg);
 static void completion_set_entry_text(Completion* completion);
 static Completion* completion_get_new(const gchar* label);
 
@@ -183,10 +183,16 @@ static GList* completion_update(GList* completion, GList* active, gboolean back)
         }
     }
 
-    gchar* fg = "#77ff77";
-    gchar* bg = "#333333";
-    completion_set_color(old->data, fg, bg);
-    completion_set_color(new->data, fg, bg);
+    completion_set_color(
+        old->data,
+        &vp.style.comp_fg[VP_COMP_NORMAL],
+        &vp.style.comp_bg[VP_COMP_NORMAL]
+    );
+    completion_set_color(
+        new->data,
+        &vp.style.comp_fg[VP_COMP_ACTIVE],
+        &vp.style.comp_bg[VP_COMP_ACTIVE]
+    );
 
     active = new;
     completion_set_entry_text(active->data);
@@ -211,21 +217,20 @@ static void completion_show(gboolean back)
         }
     }
     if (vp.comps.active != NULL) {
-        gchar* fg = "#77ff77";
-        gchar* bg = "#333333";
-        completion_set_color(vp.comps.active->data, fg, bg);
+        completion_set_color(
+            vp.comps.active->data,
+            &vp.style.comp_fg[VP_COMP_ACTIVE],
+            &vp.style.comp_bg[VP_COMP_ACTIVE]
+        );
         completion_set_entry_text(vp.comps.active->data);
         gtk_widget_show(vp.gui.compbox);
     }
 }
 
-static void completion_set_color(Completion* completion, gchar* fg, gchar* bg)
+static void completion_set_color(Completion* completion, const GdkColor* fg, const GdkColor* bg)
 {
-    GdkColor color;
-    gdk_color_parse(fg, &color);
-    gtk_widget_modify_fg(completion->label, GTK_STATE_NORMAL, &color);
-    gdk_color_parse(bg, &color);
-    gtk_widget_modify_bg(completion->label, GTK_STATE_NORMAL, &color);
+    gtk_widget_modify_fg(completion->event, GTK_STATE_NORMAL, fg);
+    gtk_widget_modify_bg(completion->event, GTK_STATE_NORMAL, bg);
 }
 
 static void completion_set_entry_text(Completion* completion)
@@ -260,9 +265,11 @@ static Completion* completion_get_new(const gchar* label)
     gtk_label_set_ellipsize(GTK_LABEL(c->label), PANGO_ELLIPSIZE_MIDDLE);
     gtk_misc_set_alignment(GTK_MISC(c->label), 0.0, 0.5);
 
-    gchar* fg = "#77ff77";
-    gchar* bg = "#333333";
-    completion_set_color(c, fg, bg);
+    completion_set_color(
+        c,
+        &vp.style.comp_fg[VP_COMP_NORMAL],
+        &vp.style.comp_bg[VP_COMP_NORMAL]
+    );
 
     GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1, 1);
     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), padding, padding, padding, padding);
index 9eed0b4..02dfc09 100644 (file)
@@ -23,6 +23,7 @@
 #include "keybind.h"
 #include "setting.h"
 #include "config.h"
+#include "completion.h"
 
 /* variables */
 VpCore vp;
@@ -104,6 +105,7 @@ static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data)
     text = gtk_entry_get_text(entry);
 
     if (1 < length && ':' == text[0]) {
+        completion_clean();
         success = vp_process_input((text + 1));
         if (!success) {
             /* switch to normal mode after running command */
index 65bd8c9..cc4aa4b 100644 (file)
@@ -88,12 +88,19 @@ enum {
     VP_SCROLL_UNIT_LINE     = (1 << 3),
     VP_SCROLL_UNIT_HALFPAGE = (1 << 4)
 };
+
 typedef enum {
     VP_MSG_NORMAL,
     VP_MSG_ERROR,
     VP_MSG_LAST
 } MessageType;
 
+typedef enum {
+    VP_COMP_NORMAL,
+    VP_COMP_ACTIVE,
+    VP_COMP_LAST
+} CompletionStyle;
+
 enum {
     FILES_FIRST = 0,
     FILES_CONFIG = 0,
@@ -171,6 +178,9 @@ typedef struct {
     GdkColor              input_fg[VP_MSG_LAST];
     GdkColor              input_bg[VP_MSG_LAST];
     PangoFontDescription* input_font[VP_MSG_LAST];
+    GdkColor              comp_fg[VP_COMP_LAST];
+    GdkColor              comp_bg[VP_COMP_LAST];
+    PangoFontDescription* comp_font[VP_COMP_LAST];
 } Style;
 
 /* core struct */
index 68fbf27..8ca9aa5 100644 (file)
@@ -28,7 +28,8 @@ 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 gboolean setting_input_style(const Setting* s);
+static gboolean setting_completion_style(const Setting* s);
 
 static Setting default_settings[] = {
     /* webkit settings */
@@ -84,12 +85,18 @@ 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"}},
+    {"input-bg-normal", TYPE_CHAR, setting_input_style, {.s = "#fff"}},
+    {"input-bg-error", TYPE_CHAR, setting_input_style, {.s = "#f00"}},
+    {"input-fg-normal", TYPE_CHAR, setting_input_style, {.s = "#000"}},
+    {"input-fg-error", TYPE_CHAR, setting_input_style, {.s = "#000"}},
+    {"input-font-normal", TYPE_CHAR, setting_input_style, {.s = "monospace normal 8"}},
+    {"input-font-error", TYPE_CHAR, setting_input_style, {.s = "monospace bold 8"}},
+    {"completion-font-normal", TYPE_CHAR, setting_completion_style, {.s = "monospace bold 8"}},
+    {"completion-font-active", TYPE_CHAR, setting_completion_style, {.s = "monospace bold 8"}},
+    {"completion-fg-normal", TYPE_CHAR, setting_completion_style, {.s = "#f6f3e8"}},
+    {"completion-fg-active", TYPE_CHAR, setting_completion_style, {.s = "#f6f3e8"}},
+    {"completion-bg-normal", TYPE_CHAR, setting_completion_style, {.s = "#656565"}},
+    {"completion-bg-active", TYPE_CHAR, setting_completion_style, {.s = "#777777"}},
 };
 
 static GHashTable* settings = NULL;
@@ -228,11 +235,10 @@ static gboolean setting_status_font(const Setting* s)
     return TRUE;
 }
 
-static gboolean setting_style(const Setting* s)
+static gboolean setting_input_style(const Setting* s)
 {
     Style* style = &vp.style;
-
-    MessageType type = g_str_has_suffix(s->name, "error") ? VP_MSG_ERROR : VP_MSG_NORMAL;
+    MessageType type = g_str_has_suffix(s->name, "normal") ? VP_MSG_NORMAL : VP_MSG_ERROR;
 
     if (g_str_has_prefix(s->name, "input-bg")) {
         gdk_color_parse(s->arg.s, &style->input_bg[type]);
@@ -247,3 +253,22 @@ static gboolean setting_style(const Setting* s)
 
     return TRUE;
 }
+
+static gboolean setting_completion_style(const Setting* s)
+{
+    Style* style = &vp.style;
+    CompletionStyle type = g_str_has_suffix(s->name, "normal") ? VP_COMP_NORMAL : VP_COMP_ACTIVE;
+
+    if (g_str_has_prefix(s->name, "completion-bg")) {
+        gdk_color_parse(s->arg.s, &style->comp_bg[type]);
+    } else if (g_str_has_prefix(s->name, "completion-fg")) {
+        gdk_color_parse(s->name, &style->comp_fg[type]);
+    } else if (g_str_has_prefix(s->arg.s, "completion-font")) {
+        if (style->comp_font[type]) {
+            pango_font_description_free(style->comp_font[type]);
+        }
+        style->comp_font[type] = pango_font_description_from_string(s->arg.s);
+    }
+
+    return TRUE;
+}