Changed the widget insertion system, this should hopefully increase performance and be an all around better system
This commit is contained in:
@@ -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) {
|
||||
|
29
modes/drun.c
29
modes/drun.c
@@ -19,6 +19,13 @@
|
||||
|
||||
#define MODE "drun"
|
||||
|
||||
struct node {
|
||||
struct widget* widget;
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
static struct wl_list widgets;
|
||||
|
||||
static char* get_text(char* file, char* action) {
|
||||
GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(file);
|
||||
if(info == NULL || g_desktop_app_info_get_is_hidden(info) || g_desktop_app_info_get_nodisplay(info)) {
|
||||
@@ -197,7 +204,10 @@ static void insert_dir(char* app_dir, struct map* cached, struct map* entries) {
|
||||
char** actions = get_action_actions(full_path, &action_count);
|
||||
|
||||
char* search_text = get_search_text(full_path);
|
||||
wofi_insert_widget(MODE, text, search_text, actions, action_count);
|
||||
|
||||
struct node* node = malloc(sizeof(struct node));
|
||||
node->widget = wofi_create_widget(MODE, text, search_text, actions, action_count);
|
||||
wl_list_insert(&widgets, &node->link);
|
||||
|
||||
for(size_t count = 0; count < action_count; ++count) {
|
||||
free(actions[count]);
|
||||
@@ -218,6 +228,8 @@ void wofi_drun_init(void) {
|
||||
struct map* entries = map_init();
|
||||
struct wl_list* cache = wofi_read_cache(MODE);
|
||||
|
||||
wl_list_init(&widgets);
|
||||
|
||||
struct cache_line* node, *tmp;
|
||||
wl_list_for_each_safe(node, tmp, cache, link) {
|
||||
size_t action_count;
|
||||
@@ -230,7 +242,9 @@ void wofi_drun_init(void) {
|
||||
char** actions = get_action_actions(node->line, &action_count);
|
||||
|
||||
char* search_text = get_search_text(node->line);
|
||||
wofi_insert_widget(MODE, text, search_text, actions, action_count);
|
||||
struct node* widget = malloc(sizeof(struct node));
|
||||
widget->widget = wofi_create_widget(MODE, text, search_text, actions, action_count);
|
||||
wl_list_insert(&widgets, &widget->link);
|
||||
|
||||
char* id = get_id(node->line);
|
||||
|
||||
@@ -280,6 +294,17 @@ void wofi_drun_init(void) {
|
||||
map_free(entries);
|
||||
}
|
||||
|
||||
struct widget* wofi_drun_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;
|
||||
}
|
||||
|
||||
static void launch_done(GObject* obj, GAsyncResult* result, gpointer data) {
|
||||
if(g_app_info_launch_uris_finish(G_APP_INFO(obj), result, NULL)) {
|
||||
exit(0);
|
||||
|
28
modes/run.c
28
modes/run.c
@@ -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);
|
||||
|
Reference in New Issue
Block a user