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

@@ -23,9 +23,18 @@ static const char* arg_names[] = {"parse_action"};
static bool parse_action;
struct node {
struct widget* widget;
struct wl_list link;
};
static struct wl_list widgets;
void wofi_dmenu_init(struct map* config) {
parse_action = strcmp(config_get(config, "parse_action", "false"), "true") == 0;
wl_list_init(&widgets);
struct map* cached = map_init();
struct wl_list* cache = wofi_read_cache(MODE);
@@ -52,7 +61,9 @@ void wofi_dmenu_init(struct map* config) {
wl_list_for_each_safe(node, tmp, cache, link) {
if(map_contains(entry_map, node->line)) {
map_put(cached, node->line, "true");
wofi_insert_widget(MODE, &node->line, node->line, &node->line, 1);
struct node* widget = malloc(sizeof(struct node));
widget->widget = wofi_create_widget(MODE, &node->line, node->line, &node->line, 1);
wl_list_insert(&widgets, &widget->link);
} else {
wofi_remove_cache(MODE, node->line);
}
@@ -66,7 +77,9 @@ void wofi_dmenu_init(struct map* config) {
wl_list_for_each_reverse_safe(node, tmp, &entries, link) {
if(!map_contains(cached, node->line)) {
wofi_insert_widget(MODE, &node->line, node->line, &node->line, 1);
struct node* widget = malloc(sizeof(struct node));
widget->widget = wofi_create_widget(MODE, &node->line, node->line, &node->line, 1);
wl_list_insert(&widgets, &widget->link);
}
free(node->line);
wl_list_remove(&node->link);
@@ -75,6 +88,17 @@ void wofi_dmenu_init(struct map* config) {
map_free(cached);
}
struct widget* wofi_dmenu_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_dmenu_exec(const gchar* cmd) {
char* action = strdup(cmd);
if(parse_action) {