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

@ -45,7 +45,7 @@ void wofi_init(struct map* config);
struct wl_list* wofi_read_cache(char* mode); struct wl_list* wofi_read_cache(char* mode);
void wofi_insert_widget(char* text, char* action); void wofi_insert_widget(char* text, char* search_text, char* action);
bool wofi_allow_images(); bool wofi_allow_images();

View File

@ -23,7 +23,7 @@ void dmenu_init() {
struct cache_line* node, *tmp; struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) { 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"); map_put(cached, node->line, "true");
free(node->line); free(node->line);
wl_list_remove(&node->link); wl_list_remove(&node->link);
@ -42,7 +42,7 @@ void dmenu_init() {
if(map_contains(cached, line)) { if(map_contains(cached, line)) {
continue; continue;
} }
wofi_insert_widget(line, line); wofi_insert_widget(line, line, line);
} }
free(line); free(line);
map_free(cached); 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() { void drun_init() {
struct map* cached = map_init(); struct map* cached = map_init();
struct map* entries = map_init(); struct map* entries = map_init();
@ -61,8 +69,10 @@ void drun_init() {
if(text == NULL) { if(text == NULL) {
goto cache_cont; 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"); map_put(cached, node->line, "true");
free(search_text);
free(text); free(text);
cache_cont: cache_cont:
@ -113,8 +123,10 @@ void drun_init() {
continue; continue;
} }
map_put(entries, entry->d_name, "true"); 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(text);
free(search_text);
free(full_path); free(full_path);
} }
closedir(dir); closedir(dir);

View File

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

View File

@ -38,7 +38,7 @@ static void (*mode_exec)(const gchar* cmd);
static bool (*exec_search)(); static bool (*exec_search)();
struct node { struct node {
char* text, *action; char* text, *search_text, *action;
}; };
static void nop() {} static void nop() {}
@ -78,7 +78,7 @@ static void get_search(GtkSearchEntry* entry, gpointer data) {
gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box)); gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box));
} }
static GtkWidget* create_label(char* text, char* action) { static GtkWidget* create_label(char* text, char* search_text, char* action) {
GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0); GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_name(box, "unselected"); gtk_widget_set_name(box, "unselected");
GtkStyleContext* style = gtk_widget_get_style_context(box); GtkStyleContext* style = gtk_widget_get_style_context(box);
@ -88,7 +88,6 @@ static GtkWidget* create_label(char* text, char* action) {
char* tmp = strdup(text); char* tmp = strdup(text);
char* original = tmp; char* original = tmp;
char* mode = NULL; char* mode = NULL;
char* filter = NULL;
size_t colon_count = utils_split(tmp, ':'); size_t colon_count = utils_split(tmp, ':');
for(size_t count = 0; count < colon_count; ++count) { for(size_t count = 0; count < colon_count; ++count) {
@ -114,13 +113,6 @@ static GtkWidget* create_label(char* text, char* action) {
gtk_widget_set_name(img, "img"); gtk_widget_set_name(img, "img");
gtk_container_add(GTK_CONTAINER(box), img); gtk_container_add(GTK_CONTAINER(box), img);
} else if(strcmp(mode, "text") == 0) { } else if(strcmp(mode, "text") == 0) {
if(filter == NULL) {
filter = strdup(tmp);
} else {
char* tmp_filter = utils_concat(2, filter, tmp);
free(filter);
filter = tmp_filter;
}
GtkWidget* label = gtk_label_new(tmp); GtkWidget* label = gtk_label_new(tmp);
gtk_widget_set_name(label, "text"); gtk_widget_set_name(label, "text");
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup); gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
@ -131,28 +123,26 @@ static GtkWidget* create_label(char* text, char* action) {
} }
tmp += strlen(tmp) + 1; tmp += strlen(tmp) + 1;
} }
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "filter", filter);
free(filter);
free(original); free(original);
} else { } else {
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "filter", text);
GtkWidget* label = gtk_label_new(text); GtkWidget* label = gtk_label_new(text);
gtk_widget_set_name(label, "text"); gtk_widget_set_name(label, "text");
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup); gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
gtk_label_set_xalign(GTK_LABEL(label), 0); gtk_label_set_xalign(GTK_LABEL(label), 0);
gtk_container_add(GTK_CONTAINER(box), label); gtk_container_add(GTK_CONTAINER(box), label);
} }
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "filter", search_text);
return box; return box;
} }
static gboolean _insert_widget(gpointer data) { static gboolean _insert_widget(gpointer data) {
struct node* node = data; struct node* node = data;
GtkWidget* box = create_label(node->text, node->action); GtkWidget* box = create_label(node->text, node->search_text, node->action);
gtk_container_add(GTK_CONTAINER(inner_box), box); gtk_container_add(GTK_CONTAINER(inner_box), box);
gtk_widget_show_all(box); gtk_widget_show_all(box);
free(node->text); free(node->text);
free(node->search_text);
free(node->action); free(node->action);
free(node); free(node);
return FALSE; return FALSE;
@ -213,9 +203,10 @@ struct wl_list* wofi_read_cache(char* mode) {
return cache; return cache;
} }
void wofi_insert_widget(char* text, char* action) { void wofi_insert_widget(char* text, char* search_text, char* action) {
struct node* widget = malloc(sizeof(struct node)); struct node* widget = malloc(sizeof(struct node));
widget->text = strdup(text); widget->text = strdup(text);
widget->search_text = strdup(search_text);
widget->action = strdup(action); widget->action = strdup(action);
g_idle_add(_insert_widget, widget); g_idle_add(_insert_widget, widget);
utils_sleep_millis(1); utils_sleep_millis(1);