diff options
-rw-r--r-- | completions/tofi | 1 | ||||
-rw-r--r-- | doc/config | 3 | ||||
-rw-r--r-- | doc/tofi.5.md | 6 | ||||
-rw-r--r-- | doc/tofi.5.scd | 5 | ||||
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/entry.h | 1 | ||||
-rw-r--r-- | src/entry_backend/harfbuzz.c | 5 | ||||
-rw-r--r-- | src/entry_backend/pango.c | 5 | ||||
-rw-r--r-- | src/main.c | 3 |
9 files changed, 29 insertions, 2 deletions
diff --git a/completions/tofi b/completions/tofi index aa2b999..5942cf7 100644 --- a/completions/tofi +++ b/completions/tofi @@ -16,6 +16,7 @@ _tofi() --font-size --num-results --selection-color + --selection-padding --selection-background --outline-width --outline-color @@ -64,6 +64,9 @@ # Minimum width of input in horizontal mode. min-input-width = 0 + # Extra horizontal padding of the selection background in pixels. + selection-padding = 0 + # ### Window layout # diff --git a/doc/tofi.5.md b/doc/tofi.5.md index 2f3a38d..93db9c7 100644 --- a/doc/tofi.5.md +++ b/doc/tofi.5.md @@ -94,6 +94,12 @@ options. > > Default: \#F92672 +**selection-padding**=*px* + +> Extra horizontal padding of the selection background. +> +> Default: 0 + **selection-background**=*color* > Background color of selected result. See **COLORS** for more diff --git a/doc/tofi.5.scd b/doc/tofi.5.scd index b57c800..53ea3b3 100644 --- a/doc/tofi.5.scd +++ b/doc/tofi.5.scd @@ -85,6 +85,11 @@ options. Default: #F92672 +*selection-padding*=_px_ + Extra horizontal padding of the selection background. + + Default: 0 + *selection-background*=_color_ Background color of selected result. See *COLORS* for more information. 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); @@ -687,6 +687,8 @@ static void usage() " --prompt-text <string> Prompt text.\n" " --num-results <n> Maximum number of results to display.\n" " --selection-color <color> Color of selected result.\n" +" --selection-padding <px> Extra horizontal padding for selected\n" +" result background.\n" " --selection-background <color> Color of selected result background.\n" " --result-spacing <px> Spacing between results.\n" " --min-input-width <px> 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}, |