Changed the widget insertion system, this should hopefully increase performance and be an all around better system

This commit is contained in:
Scoopta
2020-01-16 16:35:51 -08:00
parent 27227fa3bb
commit e5300b2995
5 changed files with 103 additions and 18 deletions

View File

@@ -24,10 +24,19 @@ static const char* arg_names[] = {"always_parse_args", "show_all"};
static bool always_parse_args;
static bool show_all;
struct node {
struct widget* widget;
struct wl_list link;
};
static struct wl_list widgets;
void wofi_run_init(struct map* config) {
always_parse_args = strcmp(config_get(config, arg_names[0], "false"), "true") == 0;
show_all = strcmp(config_get(config, arg_names[1], "true"), "true") == 0;
wl_list_init(&widgets);
struct map* cached = map_init();
struct wl_list* cache = wofi_read_cache(MODE);
@@ -45,7 +54,9 @@ void wofi_run_init(struct map* config) {
struct stat info;
stat(node->line, &info);
if(access(node->line, X_OK) == 0 && S_ISREG(info.st_mode)) {
wofi_insert_widget(MODE, &text, text, &node->line, 1);
struct node* widget = malloc(sizeof(struct node));
widget->widget = wofi_create_widget(MODE, &text, text, &node->line, 1);
wl_list_insert(&widgets, &widget->link);
map_put(cached, node->line, "true");
map_put(entries, text, "true");
} else {
@@ -78,7 +89,9 @@ void wofi_run_init(struct map* config) {
if(access(full_path, X_OK) == 0 && S_ISREG(info.st_mode) && !map_contains(cached, full_path) && (show_all || !map_contains(entries, entry->d_name))) {
char* text = strdup(entry->d_name);
map_put(entries, text, "true");
wofi_insert_widget(MODE, &text, text, &full_path, 1);
struct node* widget = malloc(sizeof(struct node));
widget->widget = wofi_create_widget(MODE, &text, text, &full_path, 1);
wl_list_insert(&widgets, &widget->link);
free(text);
}
free(full_path);
@@ -90,6 +103,17 @@ void wofi_run_init(struct map* config) {
map_free(entries);
}
struct widget* wofi_run_get_widget() {
struct node* node, *tmp;
wl_list_for_each_reverse_safe(node, tmp, &widgets, link) {
struct widget* widget = node->widget;
wl_list_remove(&node->link);
free(node);
return widget;
}
return NULL;
}
void wofi_run_exec(const gchar* cmd) {
if(wofi_mod_shift()) {
wofi_write_cache(MODE, cmd);