From 82d4c237d1f501cd7b0b8afc53ed87fd3ccf0e18 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Fri, 29 Jul 2022 12:44:02 +0100 Subject: Add --selection-padding option. This adds some extra padding in the selection background, rather than tightly wrapping the selection text. --- src/config.c | 2 ++ src/entry.h | 1 + src/entry_backend/harfbuzz.c | 5 ++++- src/entry_backend/pango.c | 5 ++++- src/main.c | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index aebb8e1..b5e7d49 100644 --- a/src/config.c +++ b/src/config.c @@ -263,6 +263,8 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->window.entry.foreground_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "selection-color") == 0) { tofi->window.entry.selection_foreground_color = parse_color(filename, lineno, value, &err); + } else if (strcasecmp(option, "selection-padding") == 0) { + tofi->window.entry.selection_background_padding = parse_uint32(filename, lineno, value, &err); } else if (strcasecmp(option, "selection-background") == 0) { tofi->window.entry.selection_background_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "width") == 0) { diff --git a/src/entry.h b/src/entry.h index c45bb85..690cb2f 100644 --- a/src/entry.h +++ b/src/entry.h @@ -59,6 +59,7 @@ struct entry { uint32_t padding_bottom; uint32_t padding_left; uint32_t padding_right; + uint32_t selection_background_padding; uint32_t input_width; uint32_t border_width; uint32_t outline_width; diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c index af1aad7..db3be66 100644 --- a/src/entry_backend/harfbuzz.c +++ b/src/entry_backend/harfbuzz.c @@ -257,7 +257,10 @@ void entry_backend_harfbuzz_update(struct entry *entry) cairo_save(cr); color = entry->selection_background_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - cairo_rectangle(cr, 0, 0, width, font_extents.height); + uint32_t pad = entry->selection_background_padding; + cairo_translate(cr, -pad, 0); + cairo_rectangle(cr, 0, 0, width + pad * 2, font_extents.height); + cairo_translate(cr, pad, 0); cairo_fill(cr); cairo_restore(cr); cairo_paint(cr); diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c index 3f424ce..bb0847a 100644 --- a/src/entry_backend/pango.c +++ b/src/entry_backend/pango.c @@ -109,7 +109,10 @@ void entry_backend_pango_update(struct entry *entry) cairo_save(cr); color = entry->selection_background_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - cairo_rectangle(cr, 0, 0, (int)(width / PANGO_SCALE), (int)(height / PANGO_SCALE)); + uint32_t pad = entry->selection_background_padding; + cairo_translate(cr, -pad, 0); + cairo_rectangle(cr, 0, 0, (int)(width / PANGO_SCALE) + pad * 2, (int)(height / PANGO_SCALE)); + cairo_translate(cr, pad, 0); cairo_fill(cr); cairo_restore(cr); cairo_paint(cr); diff --git a/src/main.c b/src/main.c index 0587304..9a3ace1 100644 --- a/src/main.c +++ b/src/main.c @@ -687,6 +687,8 @@ static void usage() " --prompt-text Prompt text.\n" " --num-results Maximum number of results to display.\n" " --selection-color Color of selected result.\n" +" --selection-padding Extra horizontal padding for selected\n" +" result background.\n" " --selection-background Color of selected result background.\n" " --result-spacing Spacing between results.\n" " --min-input-width Minimum input width in horizontal mode.\n" @@ -727,6 +729,7 @@ const struct option long_options[] = { {"font-size", required_argument, NULL, 0}, {"num-results", required_argument, NULL, 0}, {"selection-color", required_argument, NULL, 0}, + {"selection-padding", required_argument, NULL, 0}, {"selection-background", required_argument, NULL, 0}, {"outline-width", required_argument, NULL, 0}, {"outline-color", required_argument, NULL, 0}, -- cgit v1.2.3