From ee39966dedf9e8fbee5528c324c807b92b9a6c23 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 30 Jan 2021 12:43:59 +0100 Subject: config: add infrastructure to handle URL mode specific key bindings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add “show-urls” action to regular key bindings * Add url-bindings section to foot.ini * Add “cancel” action to URL mode key bindings --- config.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'config.h') diff --git a/config.h b/config.h index 56273053..f46fa35f 100644 --- a/config.h +++ b/config.h @@ -42,6 +42,12 @@ struct config_key_binding_search { xkb_keysym_t sym; }; +struct config_key_binding_url { + enum bind_action_url action; + struct config_key_modifiers modifiers; + xkb_keysym_t sym; +}; + struct config_mouse_binding { enum bind_action_normal action; struct config_key_modifiers modifiers; @@ -157,6 +163,9 @@ struct config { /* While searching (not - action to *start* a search is in the * 'key' bindings above */ tll(struct config_key_binding_search) search; + + /* While showing URL jump labels */ + tll(struct config_key_binding_url) url; } bindings; struct { -- cgit v1.3 From 4233c806c32fef8f92e51361b2f00fd50799f9be Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 31 Jan 2021 14:27:13 +0100 Subject: config: add ‘url-launch’ option, defaulting to “xdg-open ${url}” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.c | 66 ++++++++++++++++++++++++++++++++++++++++-------------- config.h | 11 +++++---- doc/foot.ini.5.scd | 4 ++++ foot.ini | 4 +++- 4 files changed, 63 insertions(+), 22 deletions(-) (limited to 'config.h') diff --git a/config.c b/config.c index 5fccbea4..18503541 100644 --- a/config.c +++ b/config.c @@ -453,6 +453,33 @@ str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf, return true; } +static bool +str_to_spawn_template(struct config *conf, + const char *s, struct config_spawn_template *template, + const char *path, int lineno, const char *section, + const char *key) +{ + free(template->raw_cmd); + free(template->argv); + + template->raw_cmd = NULL; + template->argv = NULL; + + char *raw_cmd = xstrdup(s); + char **argv = NULL; + + if (!tokenize_cmdline(raw_cmd, &argv)) { + LOG_AND_NOTIFY_ERR( + "%s:%d: [%s]: %s: syntax error in command line", + path, lineno, section, key); + return false; + } + + template->raw_cmd = raw_cmd; + template->argv = argv; + return true; +} + static bool parse_section_main(const char *key, const char *value, struct config *conf, const char *path, unsigned lineno) @@ -675,24 +702,19 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "notify") == 0) { - free(conf->notify.raw_cmd); - free(conf->notify.argv); - - conf->notify.raw_cmd = NULL; - conf->notify.argv = NULL; - - char *raw_cmd = xstrdup(value); - char **argv = NULL; - - if (!tokenize_cmdline(raw_cmd, &argv)) { - LOG_AND_NOTIFY_ERR( - "%s:%d: [default]: notify: syntax error in command line", - path, lineno); + if (!str_to_spawn_template(conf, value, &conf->notify, path, lineno, + "default", "notify")) + { return false; } + } - conf->notify.raw_cmd = raw_cmd; - conf->notify.argv = argv; + else if (strcmp(key, "url-launch") == 0) { + if (!str_to_spawn_template(conf, value, &conf->url_launch, path, lineno, + "default", "url-launch")) + { + return false; + } } else if (strcmp(key, "selection-target") == 0) { @@ -2308,6 +2330,9 @@ config_load(struct config *conf, const char *conf_path, "notify-send -a foot -i foot ${title} ${body}"); tokenize_cmdline(conf->notify.raw_cmd, &conf->notify.argv); + conf->url_launch.raw_cmd = xstrdup("xdg-open ${url}"); + tokenize_cmdline(conf->url_launch.raw_cmd, &conf->url_launch.argv); + tll_foreach(*initial_user_notifications, it) tll_push_back(conf->notifications, it->item); tll_free(*initial_user_notifications); @@ -2372,6 +2397,13 @@ out: return ret; } +static void +free_spawn_template(struct config_spawn_template *template) +{ + free(template->raw_cmd); + free(template->argv); +} + void config_free(struct config conf) { @@ -2381,8 +2413,8 @@ config_free(struct config conf) free(conf.app_id); free(conf.word_delimiters); free(conf.scrollback.indicator.text); - free(conf.notify.raw_cmd); - free(conf.notify.argv); + free_spawn_template(&conf.notify); + free_spawn_template(&conf.url_launch); for (size_t i = 0; i < ALEN(conf.fonts); i++) { tll_foreach(conf.fonts[i], it) config_font_destroy(&it->item); diff --git a/config.h b/config.h index f46fa35f..d6ad2b24 100644 --- a/config.h +++ b/config.h @@ -66,6 +66,11 @@ struct pt_or_px { float pt; }; +struct config_spawn_template { + char *raw_cmd; + char **argv; +}; + struct config { char *term; char *shell; @@ -198,10 +203,8 @@ struct config { SELECTION_TARGET_BOTH } selection_target; - struct { - char *raw_cmd; - char **argv; - } notify; + struct config_spawn_template notify; + struct config_spawn_template url_launch; struct { enum fcft_scaling_filter fcft_filter; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 9982acb8..71fbc313 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -225,6 +225,10 @@ in this order: Default: _notify-send -a foot -i foot ${title} ${body}_. +*url-launch* + Command to execute when opening URLs. _${url}_ will be replaced + with the actual URL. Default: _xdg-open ${url}_. + *selection-target* Clipboard target to automatically copy selected text to. One of *none*, *primary*, *clipboard* or *both*. Default: _primary_. diff --git a/foot.ini b/foot.ini index 2ea574a2..c69f9716 100644 --- a/foot.ini +++ b/foot.ini @@ -20,10 +20,12 @@ # pad=2x2 # optionally append 'center' # resize-delay-ms=100 +# notify=notify-send -a foot -i foot ${title} ${body} +# url-launch=xdg-open ${url} + # bold-text-in-bright=no # bell=none # word-delimiters=,│`|:"'()[]{}<> -# notify=notify-send -a foot -i foot ${title} ${body} # selection-target=primary # workers= -- cgit v1.3 From fcbb5a0bf7c6f77eb067fa223b37a792c575df56 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Feb 2021 10:35:48 +0100 Subject: config: use a packed bitfield for “use custom color” flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.c | 6 ++++-- config.h | 5 ++++- render.c | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'config.h') diff --git a/config.c b/config.c index 74cff1f3..285bc889 100644 --- a/config.c +++ b/config.c @@ -2281,7 +2281,9 @@ config_load(struct config *conf, const char *conf_path, .alpha = 0xffff, .selection_fg = 0x80000000, /* Use default bg */ .selection_bg = 0x80000000, /* Use default fg */ - .selection_uses_custom_colors = false, + .use_custom = { + .selection = false, + }, }, .cursor = { @@ -2378,7 +2380,7 @@ config_load(struct config *conf, const char *conf_path, ret = parse_config_file(f, conf, conf_file.path, errors_are_fatal); fclose(f); - conf->colors.selection_uses_custom_colors = + conf->colors.use_custom.selection = conf->colors.selection_fg >> 24 == 0 && conf->colors.selection_bg >> 24 == 0; diff --git a/config.h b/config.h index d6ad2b24..f8ebb572 100644 --- a/config.h +++ b/config.h @@ -139,7 +139,10 @@ struct config { uint16_t alpha; uint32_t selection_fg; uint32_t selection_bg; - bool selection_uses_custom_colors; + + struct { + bool selection:1; + } use_custom; } colors; struct { diff --git a/render.c b/render.c index 451b0ff3..8415ac81 100644 --- a/render.c +++ b/render.c @@ -412,7 +412,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, uint32_t _fg = 0; uint32_t _bg = 0; - if (is_selected && term->conf->colors.selection_uses_custom_colors) { + if (is_selected && term->conf->colors.use_custom.selection) { _fg = term->conf->colors.selection_fg; _bg = term->conf->colors.selection_bg; } else { -- cgit v1.3 From e9c3d03837bb50ec39b85ee92f2906e2bb40971f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Feb 2021 11:10:40 +0100 Subject: config: add colors.jump_labels and colors.urls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * colors.jump_labels configures the foreground and background colors used when rendering URL jump labels. Defaults to “regular0 regular3” (i.e. black on yellow). * colors.urls configures the color to use when highlighting URLs in URL mode. Note that we aren’t currently doing any highlighting... Defaults to regular3 (i.e. yellow). --- config.c | 68 +++++++++++++++++++++++++++++++++++++++++++----------- config.h | 8 +++++++ doc/foot.ini.5.scd | 9 ++++++++ foot.ini | 2 ++ render.c | 12 ++++++++-- 5 files changed, 84 insertions(+), 15 deletions(-) (limited to 'config.h') diff --git a/config.c b/config.c index 285bc889..f7452994 100644 --- a/config.c +++ b/config.c @@ -420,6 +420,30 @@ str_to_color(const char *s, uint32_t *color, bool allow_alpha, return true; } +static bool +str_to_two_colors(const char *s, uint32_t *first, uint32_t *second, + bool allow_alpha, struct config *conf, const char *path, + int lineno, const char *section, const char *key) +{ + /* TODO: do this without strdup() */ + char *value_copy = xstrdup(s); + const char *first_as_str = strtok(value_copy, " "); + const char *second_as_str = strtok(NULL, " "); + + if (first_as_str == NULL || second_as_str == NULL || + !str_to_color(first_as_str, first, allow_alpha, conf, path, lineno, section, key) || + !str_to_color(second_as_str, second, allow_alpha, conf, path, lineno, section, key)) + { + LOG_AND_NOTIFY_ERR("%s:%d: [%s]: %s: invalid colors: %s", + path, lineno, section, key, s); + free(value_copy); + return false; + } + + free(value_copy); + return true; +} + static bool str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf, const char *path, int lineno, const char *section, const char *key) @@ -845,6 +869,30 @@ parse_section_colors(const char *key, const char *value, struct config *conf, else if (strcmp(key, "bright7") == 0) color = &conf->colors.bright[7]; else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg; else if (strcmp(key, "selection-background") == 0) color = &conf->colors.selection_bg; + + else if (strcmp(key, "jump-labels") == 0) { + if (!str_to_two_colors( + value, &conf->colors.jump_label.fg, &conf->colors.jump_label.bg, + false, conf, path, lineno, "colors", "jump-labels")) + { + return false; + } + + conf->colors.use_custom.jump_label = true; + return true; + } + + else if (strcmp(key, "urls") == 0) { + if (!str_to_color(value, &conf->colors.url, false, + conf, path, lineno, "colors", "urls")) + { + return false; + } + + conf->colors.use_custom.url = true; + return true; + } + else if (strcmp(key, "alpha") == 0) { double alpha; if (!str_to_double(value, &alpha) || alpha < 0. || alpha > 1.) { @@ -892,23 +940,15 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, conf->cursor.blink = str_to_bool(value); else if (strcmp(key, "color") == 0) { - char *value_copy = xstrdup(value); - const char *text = strtok(value_copy, " "); - const char *cursor = strtok(NULL, " "); - - uint32_t text_color, cursor_color; - if (text == NULL || cursor == NULL || - !str_to_color(text, &text_color, false, conf, path, lineno, "cursor", "color") || - !str_to_color(cursor, &cursor_color, false, conf, path, lineno, "cursor", "color")) + if (!str_to_two_colors( + value, &conf->cursor.color.text, &conf->cursor.color.cursor, + false, conf, path, lineno, "cursor", "color")) { - LOG_AND_NOTIFY_ERR("%s:%d: invalid cursor colors: %s", path, lineno, value); - free(value_copy); return false; } - conf->cursor.color.text = 1u << 31 | text_color; - conf->cursor.color.cursor = 1u << 31 | cursor_color; - free(value_copy); + conf->cursor.color.text |= 1u << 31; + conf->cursor.color.cursor |= 1u << 31; } else { @@ -2283,6 +2323,8 @@ config_load(struct config *conf, const char *conf_path, .selection_bg = 0x80000000, /* Use default fg */ .use_custom = { .selection = false, + .jump_label = false, + .url = false, }, }, diff --git a/config.h b/config.h index f8ebb572..94998f28 100644 --- a/config.h +++ b/config.h @@ -139,9 +139,17 @@ struct config { uint16_t alpha; uint32_t selection_fg; uint32_t selection_bg; + uint32_t url; + + struct { + uint32_t fg; + uint32_t bg; + } jump_label; struct { bool selection:1; + bool jump_label:1; + bool url:1; } use_custom; } colors; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 727b81f1..3b913eda 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -351,6 +351,15 @@ _alpha_ option. text. Note that *both* options must be set, or the default will be used. Default: _inverse foreground/background_. +*jump-labels* + To RRGGBB values specifying the foreground (text) and background + colors to use when rendering jump labels in URL mode. Default: + _regular0 regular3_. + +*urls* + Color to use for the underline used to highlight URLs in URL + mode. Default: _regular3_. + # SECTION: csd diff --git a/foot.ini b/foot.ini index d90c0a06..8896eef0 100644 --- a/foot.ini +++ b/foot.ini @@ -66,6 +66,8 @@ # bright7=ffffff # bright white # selection-foreground= # selection-background= +# jump-labels= +# urls= [csd] # preferred=server diff --git a/render.c b/render.c index 8415ac81..040fa34a 100644 --- a/render.c +++ b/render.c @@ -2578,9 +2578,17 @@ render_urls(struct terminal *term) (term->margins.left + x) / term->scale, (term->margins.top + y) / term->scale); + uint32_t fg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.fg + : term->colors.table[0]; + uint32_t bg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.bg + : term->colors.table[3]; + + uint16_t alpha = 0xffff; + render_osd(term, surf, sub_surf, buf, label, - term->colors.table[0], term->colors.table[3], 0xf000, - width, height, margin, margin); + fg, bg, alpha, width, height, margin, margin); } } -- cgit v1.3 From ee1d179b8f147e6314e4823e4c66a35030ab2a0f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Feb 2021 11:12:22 +0100 Subject: config: use a bitfield for flags tracking whether to use custom colors for CSD or not --- config.h | 8 ++++---- render.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'config.h') diff --git a/config.h b/config.h index 94998f28..5ae70ae3 100644 --- a/config.h +++ b/config.h @@ -192,10 +192,10 @@ struct config { int button_width; struct { - bool title_set; - bool minimize_set; - bool maximize_set; - bool close_set; + bool title_set:1; + bool minimize_set:1; + bool maximize_set:1; + bool close_set:1; uint32_t title; uint32_t minimize; uint32_t maximize; diff --git a/render.c b/render.c index 040fa34a..d04fd5d4 100644 --- a/render.c +++ b/render.c @@ -1605,27 +1605,27 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) uint32_t _color; uint16_t alpha = 0xffff; bool is_active = false; - const bool *is_set = NULL; + bool is_set = false; const uint32_t *conf_color = NULL; switch (surf_idx) { case CSD_SURF_MINIMIZE: _color = term->colors.default_table[4]; /* blue */ - is_set = &term->conf->csd.color.minimize_set; + is_set = term->conf->csd.color.minimize_set; conf_color = &term->conf->csd.color.minimize; is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE; break; case CSD_SURF_MAXIMIZE: _color = term->colors.default_table[2]; /* green */ - is_set = &term->conf->csd.color.maximize_set; + is_set = term->conf->csd.color.maximize_set; conf_color = &term->conf->csd.color.maximize; is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE; break; case CSD_SURF_CLOSE: _color = term->colors.default_table[1]; /* red */ - is_set = &term->conf->csd.color.close_set; + is_set = term->conf->csd.color.close_set; conf_color = &term->conf->csd.color.close; is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE; break; @@ -1636,7 +1636,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) } if (is_active) { - if (*is_set) { + if (is_set) { _color = *conf_color; alpha = _color >> 24 | (_color >> 24 << 8); } -- cgit v1.3