summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c4
-rw-r--r--src/entry.h2
-rw-r--r--src/entry_backend/harfbuzz.c9
-rw-r--r--src/entry_backend/pango.c9
-rw-r--r--src/main.c5
5 files changed, 27 insertions, 2 deletions
diff --git a/src/config.c b/src/config.c
index 75f70b6..0875d86 100644
--- a/src/config.c
+++ b/src/config.c
@@ -335,6 +335,10 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const
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, "placeholder-text") == 0) {
+ snprintf(tofi->window.entry.placeholder_text, N_ELEM(tofi->window.entry.placeholder_text), "%s", value);
+ } else if (strcasecmp(option, "placeholder-color") == 0) {
+ tofi->window.entry.placeholder_color = parse_color(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) {
diff --git a/src/entry.h b/src/entry.h
index caf8c00..335cba2 100644
--- a/src/entry.h
+++ b/src/entry.h
@@ -58,6 +58,7 @@ struct entry {
uint32_t font_size;
char font_name[MAX_FONT_NAME_LENGTH];
char prompt_text[MAX_PROMPT_LENGTH];
+ char placeholder_text[MAX_PROMPT_LENGTH];
uint32_t prompt_padding;
uint32_t corner_radius;
uint32_t padding_top;
@@ -74,6 +75,7 @@ struct entry {
uint32_t outline_width;
struct color foreground_color;
struct color background_color;
+ struct color placeholder_color;
struct color selection_highlight_color;
struct color selection_foreground_color;
struct color selection_background_color;
diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c
index 5d9ba99..fd3c3d7 100644
--- a/src/entry_backend/harfbuzz.c
+++ b/src/entry_backend/harfbuzz.c
@@ -231,7 +231,11 @@ void entry_backend_harfbuzz_update(struct entry *entry)
/* Render the entry text */
hb_buffer_clear_contents(buffer);
setup_hb_buffer(buffer);
- if (entry->hide_input) {
+ if (entry->input_utf8_length == 0) {
+ color = entry->placeholder_color;
+ cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
+ hb_buffer_add_utf8(buffer, entry->placeholder_text, -1, 0, -1);
+ } else if (entry->hide_input) {
size_t char_len = N_ELEM(entry->hidden_character_utf8);
for (size_t i = 0; i < entry->input_utf32_length; i++) {
hb_buffer_add_utf8(buffer, entry->hidden_character_utf8, char_len, 0, char_len);
@@ -246,6 +250,9 @@ void entry_backend_harfbuzz_update(struct entry *entry)
cairo_font_extents_t font_extents;
cairo_font_extents(cr, &font_extents);
+ color = entry->foreground_color;
+ cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
+
uint32_t num_results;
if (entry->num_results == 0) {
num_results = entry->results.count;
diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c
index d533742..c3dadef 100644
--- a/src/entry_backend/pango.c
+++ b/src/entry_backend/pango.c
@@ -86,7 +86,11 @@ void entry_backend_pango_update(struct entry *entry)
cairo_translate(cr, entry->prompt_padding, 0);
/* Render the entry text */
- if (entry->hide_input) {
+ if (entry->input_utf8_length == 0) {
+ color = entry->placeholder_color;
+ cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
+ pango_layout_set_text(layout, entry->placeholder_text, -1);
+ } else if (entry->hide_input) {
/*
* Pango needs to be passed the whole text at once, so we need
* to manually replicate the replacement character in a buffer.
@@ -107,6 +111,9 @@ void entry_backend_pango_update(struct entry *entry)
pango_layout_get_pixel_extents(entry->pango.layout, &ink_rect, &logical_rect);
logical_rect.width = MAX(logical_rect.width, (int)entry->input_width);
+ color = entry->foreground_color;
+ cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
+
uint32_t num_results;
if (entry->num_results == 0) {
num_results = entry->results.count;
diff --git a/src/main.c b/src/main.c
index c70daea..142991b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -642,6 +642,8 @@ static void usage()
" --text-color <color> Color of text.\n"
" --prompt-text <string> Prompt text.\n"
" --prompt-padding <px> Padding between prompt and input.\n"
+" --placeholder-text <string> Placeholder input text.\n"
+" --placeholder-color <px> Color of placeholder input text.\n"
" --num-results <n> Maximum number of results to display.\n"
" --selection-color <color> Color of selected result.\n"
" --selection-match-color <color> Color of the matching portion of the\n"
@@ -707,6 +709,8 @@ const struct option long_options[] = {
{"outline-color", required_argument, NULL, 0},
{"prompt-text", required_argument, NULL, 0},
{"prompt-padding", required_argument, NULL, 0},
+ {"placeholder-text", required_argument, NULL, 0},
+ {"placeholder-color", required_argument, NULL, 0},
{"result-spacing", required_argument, NULL, 0},
{"min-input-width", required_argument, NULL, 0},
{"border-width", required_argument, NULL, 0},
@@ -884,6 +888,7 @@ int main(int argc, char *argv[])
.outline_width = 4,
.background_color = {0.106f, 0.114f, 0.118f, 1.0f},
.foreground_color = {1.0f, 1.0f, 1.0f, 1.0f},
+ .placeholder_color = {1.0f, 1.0f, 1.0f, 0.66f},
.selection_foreground_color = {0.976f, 0.149f, 0.447f, 1.0f},
.border_color = {0.976f, 0.149f, 0.447f, 1.0f},
.outline_color = {0.031f, 0.031f, 0.0f, 1.0f},