From bb80769bfdf2efcbf000bf838feaee0c1b31183d Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Tue, 26 Jul 2022 22:57:09 +0100 Subject: Add keyword matching for drun searches. There's starting to be a fair amount of duplicated code between the drun and normal run modes. At some point in the future, it's likely to be worth combining them, such that there's only a single `struct search_item` or similar, and just handle the different modes at the start and end of execution. --- src/drun.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/drun.c') diff --git a/src/drun.c b/src/drun.c index 8e1e0b4..482db92 100644 --- a/src/drun.c +++ b/src/drun.c @@ -290,3 +290,23 @@ void drun_launch(const char *filename) g_object_unref(context); g_object_unref(info); } + +static int cmpscorep(const void *restrict a, const void *restrict b) +{ + struct desktop_entry *restrict app1 = (struct desktop_entry *)a; + struct desktop_entry *restrict app2 = (struct desktop_entry *)b; + return app2->history_score - app1->history_score; +} + +void drun_history_sort(struct desktop_vec *apps, struct history *history) +{ + log_debug("Moving already known apps to the front.\n"); + for (size_t i = 0; i < history->count; i++) { + struct desktop_entry *res = desktop_vec_find(apps, history->buf[i].name); + if (res == NULL) { + continue; + } + res->history_score = history->buf[i].run_count; + } + qsort(apps->buf, apps->count, sizeof(apps->buf[0]), cmpscorep); +} -- cgit v1.2.3