From 226b063306291642b9bc9d5df0e54f2886d18486 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Mon, 22 Aug 2022 10:49:19 +0100 Subject: Add --prompt-padding option. --- src/config.c | 3 +++ src/entry.h | 1 + src/entry_backend/harfbuzz.c | 1 + src/entry_backend/pango.c | 1 + src/main.c | 2 ++ 5 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/config.c b/src/config.c index 5dff7f2..e1a30b8 100644 --- a/src/config.c +++ b/src/config.c @@ -258,6 +258,8 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->window.entry.outline_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "prompt-text") == 0) { snprintf(tofi->window.entry.prompt_text, N_ELEM(tofi->window.entry.prompt_text), "%s", value); + } else if (strcasecmp(option, "prompt-padding") == 0) { + tofi->window.entry.prompt_padding = parse_uint32(filename, lineno, value, &err); } else if (strcasecmp(option, "min-input-width") == 0) { tofi->window.entry.input_width = parse_uint32(filename, lineno, value, &err); } else if (strcasecmp(option, "result-spacing") == 0) { @@ -378,6 +380,7 @@ void config_fixup_values(struct tofi *tofi) if (tofi->use_scale) { struct entry *entry = &tofi->window.entry; + entry->prompt_padding *= scale; entry->corner_radius *= scale; entry->selection_background_padding *= scale; entry->result_spacing *= scale; diff --git a/src/entry.h b/src/entry.h index 2dfa47e..46ec65f 100644 --- a/src/entry.h +++ b/src/entry.h @@ -56,6 +56,7 @@ struct entry { uint32_t font_size; char font_name[MAX_FONT_NAME_LENGTH]; char prompt_text[MAX_PROMPT_LENGTH]; + uint32_t prompt_padding; uint32_t corner_radius; uint32_t padding_top; uint32_t padding_bottom; diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c index b90936f..2834d9d 100644 --- a/src/entry_backend/harfbuzz.c +++ b/src/entry_backend/harfbuzz.c @@ -225,6 +225,7 @@ void entry_backend_harfbuzz_update(struct entry *entry) extents = render_hb_buffer(cr, buffer); cairo_translate(cr, extents.x_advance, 0); + cairo_translate(cr, entry->prompt_padding, 0); /* Render the entry text */ hb_buffer_clear_contents(buffer); diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c index 3173d6f..d4737a1 100644 --- a/src/entry_backend/pango.c +++ b/src/entry_backend/pango.c @@ -82,6 +82,7 @@ void entry_backend_pango_update(struct entry *entry) pango_layout_get_pixel_extents(entry->pango.layout, &ink_rect, &logical_rect); cairo_translate(cr, logical_rect.width + logical_rect.x, 0); + cairo_translate(cr, entry->prompt_padding, 0); /* Render the entry text */ pango_layout_set_text(layout, entry->input_mb, -1); diff --git a/src/main.c b/src/main.c index 62a4e81..fa4ca48 100644 --- a/src/main.c +++ b/src/main.c @@ -784,6 +784,7 @@ static void usage() " --border-color Color of the border.\n" " --text-color Color of text.\n" " --prompt-text Prompt text.\n" +" --prompt-padding Padding between prompt and input.\n" " --num-results Maximum number of results to display.\n" " --selection-color Color of selected result.\n" " --selection-match-color Color of the matching portion of the\n" @@ -840,6 +841,7 @@ const struct option long_options[] = { {"outline-width", required_argument, NULL, 0}, {"outline-color", required_argument, NULL, 0}, {"prompt-text", required_argument, NULL, 0}, + {"prompt-padding", required_argument, NULL, 0}, {"result-spacing", required_argument, NULL, 0}, {"min-input-width", required_argument, NULL, 0}, {"border-width", required_argument, NULL, 0}, -- cgit v1.2.3