Modes no longer have to pass a name that matches the name they were loaded with, this was just absurdly bad design and I don't know how I came up with it in the first place

This commit is contained in:
Scoopta
2020-01-20 20:09:40 -08:00
parent c57070122e
commit 05490241a9
5 changed files with 48 additions and 40 deletions

View File

@@ -17,11 +17,10 @@
#include <wofi.h>
#define MODE "dmenu"
static const char* arg_names[] = {"parse_action"};
static bool parse_action;
static struct mode* mode;
struct node {
struct widget* widget;
@@ -30,13 +29,14 @@ struct node {
static struct wl_list widgets;
void wofi_dmenu_init(struct map* config) {
void wofi_dmenu_init(struct mode* this, struct map* config) {
mode = this;
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);
struct wl_list* cache = wofi_read_cache(mode);
struct wl_list entries;
wl_list_init(&entries);
@@ -62,10 +62,10 @@ void wofi_dmenu_init(struct map* config) {
if(map_contains(entry_map, node->line)) {
map_put(cached, node->line, "true");
struct node* widget = malloc(sizeof(struct node));
widget->widget = wofi_create_widget(MODE, &node->line, node->line, &node->line, 1);
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);
wofi_remove_cache(mode, node->line);
}
free(node->line);
wl_list_remove(&node->link);
@@ -78,7 +78,7 @@ void wofi_dmenu_init(struct map* config) {
wl_list_for_each_reverse_safe(node, tmp, &entries, link) {
if(!map_contains(cached, node->line)) {
struct node* widget = malloc(sizeof(struct node));
widget->widget = wofi_create_widget(MODE, &node->line, node->line, &node->line, 1);
widget->widget = wofi_create_widget(mode, &node->line, node->line, &node->line, 1);
wl_list_insert(&widgets, &widget->link);
}
free(node->line);
@@ -113,7 +113,7 @@ void wofi_dmenu_exec(const gchar* cmd) {
action = out;
}
}
wofi_write_cache(MODE, cmd);
wofi_write_cache(mode, cmd);
printf("%s\n", action);
free(action);
exit(0);