summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c2
-rw-r--r--src/entry.h1
-rw-r--r--src/entry_backend/harfbuzz.c4
-rw-r--r--src/entry_backend/pango.c14
-rw-r--r--src/main.c9
5 files changed, 25 insertions, 5 deletions
diff --git a/src/config.c b/src/config.c
index 2239b31..400c73f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -253,6 +253,8 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const
tofi->window.entry.border.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, "min-input-width") == 0) {
+ tofi->window.entry.input_width = parse_uint32(filename, lineno, value, &err);
} else if (strcasecmp(option, "result-padding") == 0) {
tofi->window.entry.result_padding = parse_int32(filename, lineno, value, &err);
} else if (strcasecmp(option, "border-width") == 0) {
diff --git a/src/entry.h b/src/entry.h
index 01cf1b9..f59411f 100644
--- a/src/entry.h
+++ b/src/entry.h
@@ -46,6 +46,7 @@ struct entry {
char prompt_text[MAX_PROMPT_LENGTH];
uint32_t corner_radius;
uint32_t padding;
+ uint32_t input_width;
int32_t result_padding;
struct color foreground_color;
struct color background_color;
diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c
index 61a691f..fff4950 100644
--- a/src/entry_backend/harfbuzz.c
+++ b/src/entry_backend/harfbuzz.c
@@ -23,6 +23,9 @@ const struct {
#include <freetype/fterrors.h>
+#undef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
static const char *get_ft_error_string(int err_code)
{
for (size_t i = 0; i < N_ELEM(ft_errors); i++) {
@@ -199,6 +202,7 @@ void entry_backend_harfbuzz_update(struct entry *entry)
hb_buffer_add_utf8(buffer, entry->input_mb, -1, 0, -1);
hb_shape(entry->harfbuzz.hb_font, buffer, NULL, 0);
width = render_hb_buffer(cr, buffer);
+ width = MAX(width, entry->input_width);
cairo_font_extents_t font_extents;
cairo_font_extents(cr, &font_extents);
diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c
index 49365fb..084d34f 100644
--- a/src/entry_backend/pango.c
+++ b/src/entry_backend/pango.c
@@ -5,6 +5,9 @@
#include "../log.h"
#include "../nelem.h"
+#undef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
void entry_backend_pango_init(struct entry *entry, uint32_t *width, uint32_t *height)
{
cairo_t *cr = entry->cairo[0].cr;
@@ -60,11 +63,17 @@ void entry_backend_pango_update(struct entry *entry)
pango_cairo_update_layout(cr, layout);
pango_cairo_show_layout(cr, layout);
+ int width;
int height;
- pango_layout_get_size(layout, NULL, &height);
+ pango_layout_get_size(layout, &width, &height);
+ width = MAX(width, (int)entry->input_width * PANGO_SCALE);
for (size_t i = 0; i < entry->num_results && i < entry->results.count; i++) {
- cairo_translate(cr, 0, (int)(height / PANGO_SCALE));
+ if (entry->horizontal) {
+ cairo_translate(cr, (int)(width / PANGO_SCALE) + entry->result_padding, 0);
+ } else {
+ cairo_translate(cr, 0, (int)(height / PANGO_SCALE) + entry->result_padding);
+ }
const char *str;
if (i < entry->results.count) {
str = entry->results.buf[i];
@@ -82,5 +91,6 @@ void entry_backend_pango_update(struct entry *entry)
if (i == entry->selection) {
cairo_restore(cr);
}
+ pango_layout_get_size(layout, &width, &height);
}
}
diff --git a/src/main.c b/src/main.c
index 95c7b33..cf0e3a8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -195,12 +195,12 @@ static void wl_keyboard_key(
return;
}
- if (sym == XKB_KEY_Up) {
+ if (sym == XKB_KEY_Up || sym == XKB_KEY_Left) {
uint32_t nsel = MAX(MIN(tofi->window.entry.num_results, tofi->window.entry.results.count), 1);
tofi->window.entry.selection += nsel;
tofi->window.entry.selection--;
tofi->window.entry.selection %= nsel;
- } else if (sym == XKB_KEY_Down) {
+ } else if (sym == XKB_KEY_Down || sym == XKB_KEY_Right) {
uint32_t nsel = MAX(MIN(tofi->window.entry.num_results, tofi->window.entry.results.count), 1);
tofi->window.entry.selection++;
tofi->window.entry.selection %= nsel;
@@ -575,6 +575,7 @@ static void usage()
" --num-results <n> Maximum number of results to display.\n"
" --selection-color <color> Color of selected result.\n"
" --result-padding <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"
" --anchor <position> Location on screen to anchor window.\n"
@@ -583,6 +584,7 @@ static void usage()
" --margin-left <px|%> Offset from left of screen.\n"
" --margin-right <px|%> Offset from right of screen.\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"
);
}
@@ -606,6 +608,7 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[])
{"outline-color", required_argument, NULL, 0},
{"prompt-text", required_argument, NULL, 0},
{"result-padding", required_argument, NULL, 0},
+ {"min-input-width", required_argument, NULL, 0},
{"border-width", required_argument, NULL, 0},
{"border-color", required_argument, NULL, 0},
{"text-color", required_argument, NULL, 0},
@@ -615,7 +618,7 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[])
{"margin-bottom", required_argument, NULL, 0},
{"margin-left", required_argument, NULL, 0},
{"margin-right", required_argument, NULL, 0},
- {"layout-horizontal", required_argument, NULL, 0},
+ {"horizontal", required_argument, NULL, 0},
{"hide-cursor", required_argument, NULL, 0},
{"history", required_argument, NULL, 0},
{NULL, 0, NULL, 0}