Fixed bug where mode order wasn't being taken into account when loading entries

This commit is contained in:
Scoopta 2020-01-31 23:15:13 -08:00
parent 2f4f53fa44
commit 4fac0ee652

View File

@ -66,6 +66,7 @@ struct mode {
void (*mode_exec)(const gchar* cmd); void (*mode_exec)(const gchar* cmd);
struct widget* (*mode_get_widget)(void); struct widget* (*mode_get_widget)(void);
char* name; char* name;
struct wl_list link;
}; };
struct widget { struct widget {
@ -416,6 +417,20 @@ static gboolean _insert_widget(gpointer data) {
return TRUE; return TRUE;
} }
static gboolean insert_all_widgets(gpointer data) {
struct wl_list* modes = data;
if(modes->prev == modes) {
free(modes);
return FALSE;
} else {
struct mode* mode = wl_container_of(modes->prev, mode, link);
if(!_insert_widget(mode)) {
wl_list_remove(&mode->link);
}
return TRUE;
}
}
static char* escape_lf(const char* cmd) { static char* escape_lf(const char* cmd) {
size_t len = strlen(cmd); size_t len = strlen(cmd);
char* buffer = calloc(1, (len + 1) * 2); char* buffer = calloc(1, (len + 1) * 2);
@ -906,7 +921,7 @@ static void* load_mode(char* _mode, struct mode* mode_ptr, struct map* props) {
return init; return init;
} }
static void add_mode(char* _mode) { static struct mode* add_mode(char* _mode) {
struct mode* mode_ptr = calloc(1, sizeof(struct mode)); struct mode* mode_ptr = calloc(1, sizeof(struct mode));
struct map* props = map_init(); struct map* props = map_init();
void (*init)(struct mode* _mode, struct map* props) = load_mode(_mode, mode_ptr, props); void (*init)(struct mode* _mode, struct map* props) = load_mode(_mode, mode_ptr, props);
@ -930,22 +945,29 @@ static void add_mode(char* _mode) {
} }
map_put_void(modes, _mode, mode_ptr); map_put_void(modes, _mode, mode_ptr);
init(mode_ptr, props); init(mode_ptr, props);
gdk_threads_add_idle(_insert_widget, mode_ptr);
map_free(props); map_free(props);
return mode_ptr;
} }
static void* start_thread(void* data) { static void* start_thread(void* data) {
char* mode = data; char* mode = data;
struct wl_list* modes = malloc(sizeof(struct wl_list));
wl_list_init(modes);
if(strchr(mode, ',') != NULL) { if(strchr(mode, ',') != NULL) {
char* save_ptr; char* save_ptr;
char* str = strtok_r(mode, ",", &save_ptr); char* str = strtok_r(mode, ",", &save_ptr);
do { do {
add_mode(str); struct mode* mode_ptr = add_mode(str);
wl_list_insert(modes, &mode_ptr->link);
} while((str = strtok_r(NULL, ",", &save_ptr)) != NULL); } while((str = strtok_r(NULL, ",", &save_ptr)) != NULL);
} else { } else {
add_mode(mode); struct mode* mode_ptr = add_mode(mode);
wl_list_insert(modes, &mode_ptr->link);
} }
gdk_threads_add_idle(insert_all_widgets, modes);
return NULL; return NULL;
} }