diff options
-rw-r--r-- | meson.build | 20 | ||||
-rw-r--r-- | src/compgen.c | 20 | ||||
-rw-r--r-- | src/compgen.h | 3 | ||||
-rw-r--r-- | src/entry.c | 1 | ||||
-rw-r--r-- | src/entry_backend/harfbuzz.c | 2 | ||||
-rw-r--r-- | src/entry_backend/pango.c | 9 | ||||
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/main_compgen.c | 12 |
8 files changed, 48 insertions, 22 deletions
diff --git a/meson.build b/meson.build index 4b4b100..ebdcead 100644 --- a/meson.build +++ b/meson.build @@ -64,12 +64,20 @@ common_sources = files( pango_sources = files('src/entry_backend/pango.c') harfbuzz_sources = files('src/entry_backend/harfbuzz.c') +compgen_sources = files( + 'src/main_compgen.c', + 'src/compgen.c', + 'src/log.c', + 'src/string_vec.c', + 'src/xmalloc.c' +) cc = meson.get_compiler('c') libm = cc.find_library('m', required: false) freetype = dependency('freetype2') glib = dependency('glib-2.0') harfbuzz = dependency('harfbuzz') +cairo = dependency('cairo') pangocairo = dependency('pangocairo') wayland_client = dependency('wayland-client') wayland_protocols = dependency('wayland-protocols', native: true) @@ -107,6 +115,13 @@ endforeach executable( 'tofi', + common_sources, harfbuzz_sources, wl_proto_src, wl_proto_headers, + dependencies: [libm, glib, freetype, harfbuzz, cairo, wayland_client, xkbcommon], + install: true +) + +executable( + 'tofi-pango', common_sources, pango_sources, wl_proto_src, wl_proto_headers, dependencies: [glib, pangocairo, wayland_client, xkbcommon], c_args: '-DUSE_PANGO', @@ -114,9 +129,8 @@ executable( ) executable( - 'tofi-hb', - common_sources, harfbuzz_sources, wl_proto_src, wl_proto_headers, - dependencies: [libm, glib, freetype, harfbuzz, pangocairo, wayland_client, xkbcommon], + 'tofi-compgen', + compgen_sources, install: true ) diff --git a/src/compgen.c b/src/compgen.c index 3ab228a..b0ea44d 100644 --- a/src/compgen.c +++ b/src/compgen.c @@ -9,7 +9,7 @@ #include "string_vec.h" #include "xmalloc.h" -struct string_vec compgen(struct history *history) +struct string_vec compgen() { log_debug("Retrieving PATH.\n"); const char *env_path = getenv("PATH"); @@ -54,6 +54,11 @@ struct string_vec compgen(struct history *history) log_debug("Making unique.\n"); string_vec_uniq(&programs); + return programs; +} + +void compgen_history_sort(struct string_vec *programs, struct history *history) +{ log_debug("Moving already known programs to the front.\n"); /* * Remove any programs in our history from the generated list, and @@ -63,7 +68,7 @@ struct string_vec compgen(struct history *history) */ struct string_vec to_add = string_vec_create(); for (size_t i = 0; i < history->count; i++) { - char **res = string_vec_find(&programs, history->buf[i].name); + char **res = string_vec_find(programs, history->buf[i].name); if (res == NULL) { continue; } @@ -73,7 +78,7 @@ struct string_vec compgen(struct history *history) } /* Sort the vector to push the removed entries to the end. */ - string_vec_sort(&programs); + string_vec_sort(programs); /* * Move the results down by the number of items we want to add. There's @@ -81,14 +86,13 @@ struct string_vec compgen(struct history *history) * many items. */ memmove( - &programs.buf[to_add.count], - programs.buf, - (programs.count - to_add.count) * sizeof(programs.buf[0])); + &programs->buf[to_add.count], + programs->buf, + (programs->count - to_add.count) * sizeof(programs->buf[0])); /* Add our history to the front in order. */ for (size_t i = 0; i < to_add.count; i++) { - programs.buf[i] = xstrdup(to_add.buf[i]); + programs->buf[i] = xstrdup(to_add.buf[i]); } string_vec_destroy(&to_add); - return programs; } diff --git a/src/compgen.h b/src/compgen.h index 502bcb5..c79f548 100644 --- a/src/compgen.h +++ b/src/compgen.h @@ -4,6 +4,7 @@ #include "history.h" #include "string_vec.h" -struct string_vec compgen(struct history *history); +struct string_vec compgen(void); +void compgen_history_sort(struct string_vec *programs, struct history *history); #endif /* COMPGEN_H */ diff --git a/src/entry.c b/src/entry.c index 453f3c5..252e3e1 100644 --- a/src/entry.c +++ b/src/entry.c @@ -1,5 +1,4 @@ #include <cairo/cairo.h> -#include <glib.h> #include <wchar.h> #include "entry.h" #include "log.h" diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c index 78d0757..89ed13b 100644 --- a/src/entry_backend/harfbuzz.c +++ b/src/entry_backend/harfbuzz.c @@ -1,6 +1,5 @@ #include <cairo/cairo.h> #include <harfbuzz/hb-ft.h> -#include <harfbuzz/hb-glib.h> #include <math.h> #include <wchar.h> #include "harfbuzz.h" @@ -162,7 +161,6 @@ void entry_backend_init( log_debug("Creating Harfbuzz buffer.\n"); hb_buffer_t *buffer = hb_buffer_create(); entry->backend.hb_buffer = buffer; - hb_buffer_set_unicode_funcs(buffer, hb_glib_get_unicode_funcs()); setup_hb_buffer(buffer); /* Draw the prompt now, as this only needs to be done once */ diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c index 787dfd8..6aafaef 100644 --- a/src/entry_backend/pango.c +++ b/src/entry_backend/pango.c @@ -27,10 +27,6 @@ void entry_backend_init(struct entry *entry, uint32_t *width, uint32_t *height, entry->backend.layout = pango_layout_new(context); log_debug("Setting Pango text.\n"); pango_layout_set_text(entry->backend.layout, "run: ", -1); - int prompt_width; - int prompt_height; - log_debug("Get Pango pixel size.\n"); - pango_layout_get_pixel_size(entry->backend.layout, &prompt_width, &prompt_height); log_debug("First Pango draw.\n"); pango_cairo_update_layout(cr, entry->backend.layout); @@ -40,6 +36,8 @@ void entry_backend_init(struct entry *entry, uint32_t *width, uint32_t *height, pango_cairo_show_layout(cr, entry->backend.layout); /* Move and clip so we don't draw over the prompt */ + int prompt_width; + pango_layout_get_pixel_size(entry->backend.layout, &prompt_width, NULL); cairo_translate(cr, prompt_width, 0); *width -= prompt_width; cairo_rectangle(cr, 0, 0, *width, *height); @@ -63,9 +61,8 @@ void entry_backend_update(struct entry *entry) pango_cairo_update_layout(cr, layout); pango_cairo_show_layout(cr, layout); - int width; int height; - pango_layout_get_size(entry->backend.layout, &width, &height); + pango_layout_get_size(layout, NULL, &height); for (size_t i = 0; i < 5; i++) { cairo_translate(cr, 0, (int)(height / PANGO_SCALE)); @@ -584,7 +584,8 @@ int main(int argc, char *argv[]) log_debug("Generating command list.\n"); log_indent(); tofi.window.entry.history = history_load(); - tofi.window.entry.commands = compgen(&tofi.window.entry.history); + tofi.window.entry.commands = compgen(); + compgen_history_sort(&tofi.window.entry.commands, &tofi.window.entry.history); tofi.window.entry.results = string_vec_copy(&tofi.window.entry.commands); log_unindent(); log_debug("Command list generated.\n"); diff --git a/src/main_compgen.c b/src/main_compgen.c new file mode 100644 index 0000000..a62bc11 --- /dev/null +++ b/src/main_compgen.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#include "compgen.h" +#include "string_vec.h" + +int main() +{ + struct string_vec commands = compgen(); + for (size_t i = 0; i < commands.count; i++) { + printf("%s\n", commands.buf[i]); + } + string_vec_destroy(&commands); +} |