From a1fbff67cd0cb4714b2a863230df1920a18bea3f Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Fri, 28 Sep 2012 18:03:30 -0400 Subject: [PATCH 1/7] move to pangocairo for hint rendering Also add some configuration options: hint_font, hint_forground and hint_background --- termite.cc | 65 +++++++++++++++++++++++++++++++++++++++++------------ termite.cfg | 4 ++++ 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/termite.cc b/termite.cc index 34ae6a9..acd3ac6 100644 --- a/termite.cc +++ b/termite.cc @@ -67,7 +67,13 @@ struct keybind_info { config_info config; }; +struct hint_info { + PangoFontDescription *font; + cairo_pattern_t *fg, *bg; +}; + static char *browser_cmd[3] = {NULL}; +static hint_info hints = {NULL}; static void launch_browser(char *url); @@ -152,35 +158,44 @@ static void launch_url(const char *text, search_panel_info *info) { } } -static void draw_marker(cairo_t *cr, const char *font, long x, long y, int padding, unsigned id) { +static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, long y, int padding, unsigned id) { char buffer[std::numeric_limits::digits10 + 1]; cairo_text_extents_t ext; - - cairo_select_font_face(cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size(cr, 9); + int width, height; snprintf(buffer, sizeof(buffer), "%u", id); + cairo_text_extents(cr, buffer, &ext); + PangoLayout *layout = pango_cairo_create_layout(cr); + pango_layout_set_font_description(layout, desc); + pango_layout_set_text(layout, buffer, -1); + pango_layout_get_size (layout, &width, &height); - cairo_set_source_rgb(cr, 1, 1, 1); + cairo_set_source(cr, hints.fg); cairo_rectangle(cr, static_cast(x), static_cast(y), - ext.width + padding * 2, ext.height + padding * 2); + static_cast(width / PANGO_SCALE + padding * 2), + static_cast(height / PANGO_SCALE + padding * 2)); cairo_stroke_preserve(cr); - cairo_set_source_rgb(cr, 0, 0, 0); + cairo_set_source(cr, hints.bg); cairo_fill(cr); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_move_to(cr, static_cast(x + padding) - ext.x_bearing, - static_cast(y + padding) - ext.y_bearing); - cairo_show_text(cr, buffer); + cairo_new_path(cr); + cairo_set_line_width(cr, 0.5); + cairo_set_source(cr, hints.fg); + cairo_move_to(cr, static_cast(x + padding), static_cast(y + padding)); + + pango_cairo_update_layout(cr, layout); + pango_cairo_layout_path(cr, layout); + cairo_fill(cr); + + g_object_unref(layout); } static gboolean draw_cb(const search_panel_info *info, cairo_t *cr) { if (!info->url_list.empty()) { - const PangoFontDescription *desc = vte_terminal_get_font(info->vte); - const char *font = pango_font_description_get_family(desc); const long cw = vte_terminal_get_char_width(info->vte); const long ch = vte_terminal_get_char_height(info->vte); + const PangoFontDescription *desc = hints.font ? hints.font : vte_terminal_get_font(info->vte); cairo_set_line_width(cr, 1); cairo_set_source_rgb(cr, 0, 0, 0); @@ -190,7 +205,7 @@ static gboolean draw_cb(const search_panel_info *info, cairo_t *cr) { const url_data &data = info->url_list[i]; const long x = data.col * cw; const long y = data.row * ch; - draw_marker(cr, font, x, y, 3, i + 1); + draw_marker(cr, desc, x, y, 2, i + 1); } } @@ -895,6 +910,12 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, g_free(cfgstr); } + if (get_config_string(config, "options", "hint_font", &cfgstr)) { + hints.font = pango_font_description_from_string(cfgstr); + g_free(cfgstr); + } + + if (get_config_string(config, "options", "word_chars", &cfgstr)) { vte_terminal_set_word_chars(vte, cfgstr); g_free(cfgstr); @@ -1005,6 +1026,22 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, if (get_config_color(config, "highlight", &color)) { vte_terminal_set_color_highlight(vte, &color); } + + if (get_config_color(config, "hint_foreground", &color)) { + hints.fg = cairo_pattern_create_rgb(color.red / 255.0f, + color.green / 255.0f, + color.blue / 255.0f); + } else { + hints.fg = cairo_pattern_create_rgb(1, 1, 1); + } + + if (get_config_color(config, "hint_background", &color)) { + hints.bg = cairo_pattern_create_rgb(color.red / 255.0f, + color.green / 255.0f, + color.blue / 255.0f); + } else { + hints.bg = cairo_pattern_create_rgb(0, 0, 0); + } } g_free(path); g_key_file_free(config); diff --git a/termite.cfg b/termite.cfg index 5fc110d..8fe1ce1 100644 --- a/termite.cfg +++ b/termite.cfg @@ -10,6 +10,7 @@ dynamic_title = true urgent_on_bell = true clickable_url = true font = Monospace 9 +#hint_font = Monospace 12 scrollback_lines = 1000 search_wrap = true #icon_name = terminal @@ -40,6 +41,9 @@ foreground_bold = #ffffff background = #3f3f3f #cursor = #dcdccc +#hint_foreground = #dcdccc +#hint_background = #3f3f3f + # if unset, will reverse foreground and background highlight = #2f2f2f From 58ab9cad0fa43d566a8bb49c809e34b4d4be93a2 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Fri, 28 Sep 2012 18:47:43 -0400 Subject: [PATCH 2/7] wrong resolution --- termite.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/termite.cc b/termite.cc index acd3ac6..ee3813a 100644 --- a/termite.cc +++ b/termite.cc @@ -1028,17 +1028,17 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, } if (get_config_color(config, "hint_foreground", &color)) { - hints.fg = cairo_pattern_create_rgb(color.red / 255.0f, - color.green / 255.0f, - color.blue / 255.0f); + hints.fg = cairo_pattern_create_rgb(color.red / 65535.0, + color.green / 65535.0, + color.blue / 65535.0); } else { hints.fg = cairo_pattern_create_rgb(1, 1, 1); } if (get_config_color(config, "hint_background", &color)) { - hints.bg = cairo_pattern_create_rgb(color.red / 255.0f, - color.green / 255.0f, - color.blue / 255.0f); + hints.bg = cairo_pattern_create_rgb(color.red / 65535.0, + color.green / 65535.0, + color.blue / 65535.0); } else { hints.bg = cairo_pattern_create_rgb(0, 0, 0); } From e5340a90dcd46231974ce497a48d423bf147643a Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Fri, 28 Sep 2012 19:27:10 -0400 Subject: [PATCH 3/7] add a [hints] section --- termite.cc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/termite.cc b/termite.cc index ee3813a..4d1aecc 100644 --- a/termite.cc +++ b/termite.cc @@ -814,10 +814,10 @@ auto get_config_string(std::bind(get_config, g_key_file_get_string, auto get_config_double(std::bind(get_config, g_key_file_get_double, _1, _2, _3, _4)); -static bool get_config_color(GKeyFile *config, const char *key, GdkColor *color) { +static bool get_config_color(GKeyFile *config, const char *section, const char *key, GdkColor *color) { char *cfgstr; bool success = false; - if (get_config_string(config, "colors", key, &cfgstr)) { + if (get_config_string(config, section, key, &cfgstr)) { if (gdk_color_parse(cfgstr, color)) { success = true; } else { @@ -910,12 +910,11 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, g_free(cfgstr); } - if (get_config_string(config, "options", "hint_font", &cfgstr)) { + if (get_config_string(config, "hints", "font", &cfgstr)) { hints.font = pango_font_description_from_string(cfgstr); g_free(cfgstr); } - if (get_config_string(config, "options", "word_chars", &cfgstr)) { vte_terminal_set_word_chars(vte, cfgstr); g_free(cfgstr); @@ -981,7 +980,7 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, for (unsigned i = 0; i < palette_size; i++) { snprintf(color_key, sizeof color_key, "color%u", i); - if (!get_config_color(config, color_key, &palette[i])) { + if (!get_config_color(config, "colors", color_key, &palette[i])) { if (i < 16) { palette[i].blue = (i & 4) ? 0xc000 : 0; palette[i].green = (i & 2) ? 0xc000 : 0; @@ -1007,27 +1006,27 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, } } vte_terminal_set_colors(vte, nullptr, nullptr, palette, palette_size); - if (get_config_color(config, "foreground", &color)) { + if (get_config_color(config, "colors", "foreground", &color)) { vte_terminal_set_color_foreground(vte, &color); } - if (get_config_color(config, "foreground_bold", &color)) { + if (get_config_color(config, "colors", "foreground_bold", &color)) { vte_terminal_set_color_bold(vte, &color); } - if (get_config_color(config, "foreground_dim", &color)) { + if (get_config_color(config, "colors", "foreground_dim", &color)) { vte_terminal_set_color_dim(vte, &color); } - if (get_config_color(config, "background", &color)) { + if (get_config_color(config, "colors", "background", &color)) { vte_terminal_set_color_background(vte, &color); vte_terminal_set_background_tint_color(vte, &color); } - if (get_config_color(config, "cursor", &color)) { + if (get_config_color(config, "colors", "cursor", &color)) { vte_terminal_set_color_cursor(vte, &color); } - if (get_config_color(config, "highlight", &color)) { + if (get_config_color(config, "colors", "highlight", &color)) { vte_terminal_set_color_highlight(vte, &color); } - if (get_config_color(config, "hint_foreground", &color)) { + if (get_config_color(config, "hints", "foreground", &color)) { hints.fg = cairo_pattern_create_rgb(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0); @@ -1035,7 +1034,7 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, hints.fg = cairo_pattern_create_rgb(1, 1, 1); } - if (get_config_color(config, "hint_background", &color)) { + if (get_config_color(config, "hints", "background", &color)) { hints.bg = cairo_pattern_create_rgb(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0); From 11e6bbf8e26900b8495d66bbea9c37c3355e73cb Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Fri, 28 Sep 2012 19:32:59 -0400 Subject: [PATCH 4/7] add setting for hint border width --- termite.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/termite.cc b/termite.cc index 4d1aecc..8699fcb 100644 --- a/termite.cc +++ b/termite.cc @@ -70,6 +70,7 @@ struct keybind_info { struct hint_info { PangoFontDescription *font; cairo_pattern_t *fg, *bg; + double border; }; static char *browser_cmd[3] = {NULL}; @@ -180,7 +181,7 @@ static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, l cairo_fill(cr); cairo_new_path(cr); - cairo_set_line_width(cr, 0.5); + cairo_set_line_width(cr, hints.border); cairo_set_source(cr, hints.fg); cairo_move_to(cr, static_cast(x + padding), static_cast(y + padding)); @@ -910,11 +911,6 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, g_free(cfgstr); } - if (get_config_string(config, "hints", "font", &cfgstr)) { - hints.font = pango_font_description_from_string(cfgstr); - g_free(cfgstr); - } - if (get_config_string(config, "options", "word_chars", &cfgstr)) { vte_terminal_set_word_chars(vte, cfgstr); g_free(cfgstr); @@ -1026,6 +1022,11 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, vte_terminal_set_color_highlight(vte, &color); } + if (get_config_string(config, "hints", "font", &cfgstr)) { + hints.font = pango_font_description_from_string(cfgstr); + g_free(cfgstr); + } + if (get_config_color(config, "hints", "foreground", &color)) { hints.fg = cairo_pattern_create_rgb(color.red / 65535.0, color.green / 65535.0, @@ -1041,6 +1042,9 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, } else { hints.bg = cairo_pattern_create_rgb(0, 0, 0); } + + hints.border = 0.5; + get_config_double(config, "hints", "border", &hints.border); } g_free(path); g_key_file_free(config); From 2d32d938972b87f0ee62313861330ad5a8bdd948 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Fri, 28 Sep 2012 19:34:23 -0400 Subject: [PATCH 5/7] update termite.cfg --- termite.cfg | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/termite.cfg b/termite.cfg index 8fe1ce1..8c425db 100644 --- a/termite.cfg +++ b/termite.cfg @@ -10,7 +10,6 @@ dynamic_title = true urgent_on_bell = true clickable_url = true font = Monospace 9 -#hint_font = Monospace 12 scrollback_lines = 1000 search_wrap = true #icon_name = terminal @@ -38,12 +37,8 @@ cursor_shape = block foreground = #dcdccc foreground_bold = #ffffff #foreground_dim = #888888 -background = #3f3f3f #cursor = #dcdccc -#hint_foreground = #dcdccc -#hint_background = #3f3f3f - # if unset, will reverse foreground and background highlight = #2f2f2f @@ -64,3 +59,9 @@ color12 = #94bff3 color13 = #ec93d3 color14 = #93e0e3 color15 = #ffffff + +[hints] +#font = Monospace 12 +#foreground = #dcdccc +#background = #3f3f3f +#border = 0.5 From 2e3edd46bde974512bbb87925cbe3b9550f2671c Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Fri, 28 Sep 2012 23:08:23 -0400 Subject: [PATCH 6/7] add roundness and border color --- termite.cc | 43 +++++++++++++++++++++++++++++++++---------- termite.cfg | 4 +++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/termite.cc b/termite.cc index 8699fcb..ea92dfa 100644 --- a/termite.cc +++ b/termite.cc @@ -69,8 +69,8 @@ struct keybind_info { struct hint_info { PangoFontDescription *font; - cairo_pattern_t *fg, *bg; - double border; + cairo_pattern_t *fg, *bg, *border; + double border_width, roundness; }; static char *browser_cmd[3] = {NULL}; @@ -159,6 +159,16 @@ static void launch_url(const char *text, search_panel_info *info) { } } +static void draw_rectangle(cairo_t *cr, double x, double y, double height, double width) { + double radius = hints.roundness; + double a = x, b = x + height, c = y, d = y + width; + cairo_arc(cr, a + radius, c + radius, radius, 2*(M_PI/2), 3*(M_PI/2)); + cairo_arc(cr, b - radius, c + radius, radius, 3*(M_PI/2), 4*(M_PI/2)); + cairo_arc(cr, b - radius, d - radius, radius, 0*(M_PI/2), 1*(M_PI/2)); + cairo_arc(cr, a + radius, d - radius, radius, 1*(M_PI/2), 2*(M_PI/2)); + cairo_close_path(cr); +} + static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, long y, int padding, unsigned id) { char buffer[std::numeric_limits::digits10 + 1]; cairo_text_extents_t ext; @@ -172,19 +182,19 @@ static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, l pango_layout_set_text(layout, buffer, -1); pango_layout_get_size (layout, &width, &height); - cairo_set_source(cr, hints.fg); - cairo_rectangle(cr, static_cast(x), static_cast(y), - static_cast(width / PANGO_SCALE + padding * 2), - static_cast(height / PANGO_SCALE + padding * 2)); + draw_rectangle(cr, static_cast(x), static_cast(y), + static_cast(width / PANGO_SCALE + padding * 2), + static_cast(height / PANGO_SCALE + padding * 2)); + cairo_set_source(cr, hints.border); + cairo_set_line_width(cr, hints.border_width); cairo_stroke_preserve(cr); cairo_set_source(cr, hints.bg); cairo_fill(cr); cairo_new_path(cr); - cairo_set_line_width(cr, hints.border); - cairo_set_source(cr, hints.fg); cairo_move_to(cr, static_cast(x + padding), static_cast(y + padding)); + cairo_set_source(cr, hints.fg); pango_cairo_update_layout(cr, layout); pango_cairo_layout_path(cr, layout); cairo_fill(cr); @@ -1043,8 +1053,21 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, hints.bg = cairo_pattern_create_rgb(0, 0, 0); } - hints.border = 0.5; - get_config_double(config, "hints", "border", &hints.border); + if (get_config_color(config, "hints", "border", &color)) { + hints.border = cairo_pattern_create_rgb(color.red / 65535.0, + color.green / 65535.0, + color.blue / 65535.0); + } else { + hints.border = hints.fg; + } + + if (!get_config_double(config, "hints", "border_width", &hints.border_width)) { + hints.border_width = 1.0; + } + + if (!get_config_double(config, "hints", "roundness", &hints.roundness)) { + hints.roundness = 1.5; + } } g_free(path); g_key_file_free(config); diff --git a/termite.cfg b/termite.cfg index 8c425db..7a121dc 100644 --- a/termite.cfg +++ b/termite.cfg @@ -64,4 +64,6 @@ color15 = #ffffff #font = Monospace 12 #foreground = #dcdccc #background = #3f3f3f -#border = 0.5 +#border = #3f3f3f +#border_width = 0.5 +#roundness = 2.0 From 4a87e93620bc692783c5121ab3f29e6bc35ce681 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Sun, 30 Sep 2012 13:05:06 -0400 Subject: [PATCH 7/7] add a configuration for padding --- termite.cc | 17 +++++++++++------ termite.cfg | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/termite.cc b/termite.cc index ea92dfa..f27ca5d 100644 --- a/termite.cc +++ b/termite.cc @@ -70,7 +70,7 @@ struct keybind_info { struct hint_info { PangoFontDescription *font; cairo_pattern_t *fg, *bg, *border; - double border_width, roundness; + double padding, border_width, roundness; }; static char *browser_cmd[3] = {NULL}; @@ -169,7 +169,7 @@ static void draw_rectangle(cairo_t *cr, double x, double y, double height, doubl cairo_close_path(cr); } -static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, long y, int padding, unsigned id) { +static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, long y, unsigned id) { char buffer[std::numeric_limits::digits10 + 1]; cairo_text_extents_t ext; int width, height; @@ -183,8 +183,8 @@ static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, l pango_layout_get_size (layout, &width, &height); draw_rectangle(cr, static_cast(x), static_cast(y), - static_cast(width / PANGO_SCALE + padding * 2), - static_cast(height / PANGO_SCALE + padding * 2)); + static_cast(width / PANGO_SCALE) + hints.padding * 2, + static_cast(height / PANGO_SCALE) + hints.padding * 2); cairo_set_source(cr, hints.border); cairo_set_line_width(cr, hints.border_width); cairo_stroke_preserve(cr); @@ -192,7 +192,8 @@ static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, l cairo_fill(cr); cairo_new_path(cr); - cairo_move_to(cr, static_cast(x + padding), static_cast(y + padding)); + cairo_move_to(cr, static_cast(x) + hints.padding, + static_cast(y) + hints.padding); cairo_set_source(cr, hints.fg); pango_cairo_update_layout(cr, layout); @@ -216,7 +217,7 @@ static gboolean draw_cb(const search_panel_info *info, cairo_t *cr) { const url_data &data = info->url_list[i]; const long x = data.col * cw; const long y = data.row * ch; - draw_marker(cr, desc, x, y, 2, i + 1); + draw_marker(cr, desc, x, y, i + 1); } } @@ -1061,6 +1062,10 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, hints.border = hints.fg; } + if (!get_config_double(config, "hints", "padding", &hints.padding)) { + hints.padding = 2.0; + } + if (!get_config_double(config, "hints", "border_width", &hints.border_width)) { hints.border_width = 1.0; } diff --git a/termite.cfg b/termite.cfg index 7a121dc..05ce63a 100644 --- a/termite.cfg +++ b/termite.cfg @@ -64,6 +64,7 @@ color15 = #ffffff #font = Monospace 12 #foreground = #dcdccc #background = #3f3f3f +#padding = 2 #border = #3f3f3f #border_width = 0.5 -#roundness = 2.0 +#roundness = 2.0