summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-06-26 23:44:28 +0100
committerPhil Jones <philj56@gmail.com>2022-06-26 23:44:28 +0100
commitbcff7094627e423dd9ca52a246345512dc3d791c (patch)
treec041d710eed4453091439f2c468113d9d635f1fc /src
parent97aded721dd0bf33a56839517921e4c7094c90d7 (diff)
Add optional background around selected result.
Diffstat (limited to 'src')
-rw-r--r--src/config.c4
-rw-r--r--src/entry.h3
-rw-r--r--src/entry_backend/harfbuzz.c13
-rw-r--r--src/entry_backend/pango.c15
-rw-r--r--src/main.c73
5 files changed, 66 insertions, 42 deletions
diff --git a/src/config.c b/src/config.c
index 8ec6de4..713cc7e 100644
--- a/src/config.c
+++ b/src/config.c
@@ -262,7 +262,9 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const
} else if (strcasecmp(option, "text-color") == 0) {
tofi->window.entry.foreground_color = parse_color(filename, lineno, value, &err);
} else if (strcasecmp(option, "selection-color") == 0) {
- tofi->window.entry.selection_color = parse_color(filename, lineno, value, &err);
+ tofi->window.entry.selection_foreground_color = parse_color(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) {
tofi->window.width = parse_uint32_percent(filename, lineno, value, &err, tofi->output_width);
} else if (strcasecmp(option, "height") == 0) {
diff --git a/src/entry.h b/src/entry.h
index 5fa29c4..4f01252 100644
--- a/src/entry.h
+++ b/src/entry.h
@@ -55,7 +55,8 @@ struct entry {
uint32_t outline_width;
struct color foreground_color;
struct color background_color;
- struct color selection_color;
+ struct color selection_foreground_color;
+ struct color selection_background_color;
struct color border_color;
struct color outline_color;
};
diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c
index 58f4ca6..fe4d7dc 100644
--- a/src/entry_backend/harfbuzz.c
+++ b/src/entry_backend/harfbuzz.c
@@ -231,13 +231,22 @@ void entry_backend_harfbuzz_update(struct entry *entry)
hb_buffer_add_utf8(buffer, entry->results.buf[i], -1, 0, -1);
hb_shape(entry->harfbuzz.hb_font, buffer, NULL, 0);
if (i == entry->selection) {
- cairo_save(cr);
- color = entry->selection_color;
+ cairo_push_group(cr);
+ color = entry->selection_foreground_color;
cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
}
width = render_hb_buffer(cr, buffer);
if (i == entry->selection) {
+ cairo_pop_group_to_source(cr);
+ 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);
+ cairo_fill(cr);
cairo_restore(cr);
+ cairo_paint(cr);
+ color = entry->foreground_color;
+ cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
}
}
diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c
index 019933e..8a0add7 100644
--- a/src/entry_backend/pango.c
+++ b/src/entry_backend/pango.c
@@ -87,15 +87,24 @@ void entry_backend_pango_update(struct entry *entry)
pango_layout_set_text(layout, str, -1);
pango_cairo_update_layout(cr, layout);
if (i == entry->selection) {
- cairo_save(cr);
- color = entry->selection_color;
+ cairo_push_group(cr);
+ color = entry->selection_foreground_color;
cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
}
pango_cairo_show_layout(cr, layout);
+ pango_layout_get_size(layout, &width, &height);
if (i == entry->selection) {
+ cairo_pop_group_to_source(cr);
+ 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));
+ cairo_fill(cr);
cairo_restore(cr);
+ cairo_paint(cr);
+ color = entry->foreground_color;
+ cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
}
- pango_layout_get_size(layout, &width, &height);
}
cairo_restore(cr);
diff --git a/src/main.c b/src/main.c
index d6f6d88..362fef6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -592,40 +592,42 @@ static void usage()
fprintf(stderr, "%s",
"Usage: tofi [options]\n"
"\n"
-" -h, --help Print this message and exit.\n"
-" -c, --config Specify a config file.\n"
-" --font <name|path> Font to use.\n"
-" --font-size <pt> Point size of text.\n"
-" --background-color <color> Color of the background.\n"
-" --outline-width <px> Width of the border outlines.\n"
-" --outline-color <color> Color of the border outlines.\n"
-" --border-width <px> Width of the border.\n"
-" --border-color <color> Color of the border.\n"
-" --text-color <color> Color of text.\n"
-" --prompt-text <string> Prompt text.\n"
-" --num-results <n> Maximum number of results to display.\n"
-" --selection-color <color> Color of selected result.\n"
-" --result-spacing <px> Spacing between results. Can be negative.\n"
-" --min-input-width <px> Minimum width of input in horizontal mode.\n"
-" --width <px|%> Width of the window.\n"
-" --height <px|%> Height of the window.\n"
-" --corner-radius <px> Radius of window corners.\n"
-" --output <name> Name of output to display window on.\n"
-" --anchor <position> Location on screen to anchor window.\n"
-" --margin-top <px|%> Offset from top of screen.\n"
-" --margin-bottom <px|%> Offset from bottom of screen.\n"
-" --margin-left <px|%> Offset from left of screen.\n"
-" --margin-right <px|%> Offset from right of screen.\n"
-" --padding-top <px|%> Padding between top border and text.\n"
-" --padding-bottom <px|%> Padding between bottom border and text.\n"
-" --padding-left <px|%> Padding between left border and text.\n"
-" --padding-right <px|%> Padding between right border and text.\n"
-" --hide-cursor <true|false> Hide the cursor.\n"
-" --horizontal <true|false> List results horizontally.\n"
-" --history <true|false> Sort results by number of usages.\n"
-" --hint-font <true|false> Perform font hinting.\n"
-" --late-keyboard-init (EXPERIMENTAL) Delay keyboard initialisation\n"
-" until after the first draw to screen.\n"
+" -h, --help Print this message and exit.\n"
+" -c, --config Specify a config file.\n"
+" --font <name|path> Font to use.\n"
+" --font-size <pt> Point size of text.\n"
+" --background-color <color> Color of the background.\n"
+" --outline-width <px> Width of the border outlines.\n"
+" --outline-color <color> Color of the border outlines.\n"
+" --border-width <px> Width of the border.\n"
+" --border-color <color> Color of the border.\n"
+" --text-color <color> Color of text.\n"
+" --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-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"
+" --width <px|%> Width of the window.\n"
+" --height <px|%> Height of the window.\n"
+" --corner-radius <px> Radius of window corners.\n"
+" --output <name> Name of output to display window on.\n"
+" --anchor <position> Location on screen to anchor window.\n"
+" --margin-top <px|%> Offset from top of screen.\n"
+" --margin-bottom <px|%> Offset from bottom of screen.\n"
+" --margin-left <px|%> Offset from left of screen.\n"
+" --margin-right <px|%> Offset from right of screen.\n"
+" --padding-top <px|%> Padding between top border and text.\n"
+" --padding-bottom <px|%> Padding between bottom border and text.\n"
+" --padding-left <px|%> Padding between left border and text.\n"
+" --padding-right <px|%> Padding between right border and text.\n"
+" --hide-cursor <true|false> Hide the cursor.\n"
+" --horizontal <true|false> List results horizontally.\n"
+" --history <true|false> Sort results by number of usages.\n"
+" --hint-font <true|false> Perform font hinting.\n"
+" --late-keyboard-init (EXPERIMENTAL) Delay keyboard\n"
+" initialisation until after the first\n"
+" draw to screen.\n"
);
}
@@ -640,6 +642,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-background", required_argument, NULL, 0},
{"outline-width", required_argument, NULL, 0},
{"outline-color", required_argument, NULL, 0},
{"prompt-text", required_argument, NULL, 0},
@@ -771,7 +774,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},
- .selection_color = {0.976f, 0.149f, 0.447f, 1.0f},
+ .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},
}