The text used for searches is no longer the same as the text displayed, this allows for a lot more powerful searching especially in drun mode

This commit is contained in:
Scoopta
2019-10-28 14:17:06 -07:00
parent 84ffcb589d
commit da56f43d57
5 changed files with 30 additions and 23 deletions

View File

@@ -23,7 +23,7 @@ void dmenu_init() {
struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) {
wofi_insert_widget(node->line, node->line);
wofi_insert_widget(node->line, node->line, node->line);
map_put(cached, node->line, "true");
free(node->line);
wl_list_remove(&node->link);
@@ -42,7 +42,7 @@ void dmenu_init() {
if(map_contains(cached, line)) {
continue;
}
wofi_insert_widget(line, line);
wofi_insert_widget(line, line, line);
}
free(line);
map_free(cached);

View File

@@ -50,6 +50,14 @@ static char* get_text(char* file) {
}
}
static char* get_search_text(char* file, char* name) {
GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(file);
const char* exec = g_app_info_get_executable(G_APP_INFO(info));
const char* description = g_app_info_get_description(G_APP_INFO(info));
const char* const* keywords = g_desktop_app_info_get_keywords(info);
return utils_concat(5, name, file, exec == NULL ? "" : exec, description == NULL ? "" : description, keywords == NULL ? (const char* const*) "" : keywords);
}
void drun_init() {
struct map* cached = map_init();
struct map* entries = map_init();
@@ -61,8 +69,10 @@ void drun_init() {
if(text == NULL) {
goto cache_cont;
}
wofi_insert_widget(text, node->line);
char* search_text = get_search_text(node->line, text);
wofi_insert_widget(text, search_text, node->line);
map_put(cached, node->line, "true");
free(search_text);
free(text);
cache_cont:
@@ -113,8 +123,10 @@ void drun_init() {
continue;
}
map_put(entries, entry->d_name, "true");
wofi_insert_widget(text, full_path);
char* search_text = get_search_text(full_path, text);
wofi_insert_widget(text, search_text, full_path);
free(text);
free(search_text);
free(full_path);
}
closedir(dir);

View File

@@ -24,8 +24,10 @@ void run_init() {
struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) {
char* text = strrchr(node->line, '/') + 1;
wofi_insert_widget(text, node->line);
char* search_text = utils_concat(2, text, node->line);
wofi_insert_widget(text, search_text, node->line);
map_put(cached, node->line, "true");
free(search_text);
free(node->line);
wl_list_remove(&node->link);
free(node);
@@ -50,7 +52,9 @@ void run_init() {
struct stat info;
stat(full_path, &info);
if(access(full_path, X_OK) == 0 && S_ISREG(info.st_mode) && !map_contains(cached, full_path)) {
wofi_insert_widget(entry->d_name, full_path);
char* search_text = utils_concat(2, entry->d_name, full_path);
wofi_insert_widget(entry->d_name, search_text, full_path);
free(search_text);
}
free(full_path);
}