Added support for combi style functionality

This commit is contained in:
Scoopta 2019-11-04 20:56:40 -08:00
parent 0eb03b7adc
commit 2ab1c53b4d
5 changed files with 47 additions and 21 deletions

View File

@ -45,7 +45,7 @@ void wofi_init(struct map* config);
struct wl_list* wofi_read_cache(char* mode); struct wl_list* wofi_read_cache(char* mode);
void wofi_insert_widget(char* text, char* search_text, char* action); void wofi_insert_widget(char* mode, char* text, char* search_text, char* action);
bool wofi_allow_images(); bool wofi_allow_images();

View File

@ -23,7 +23,7 @@ void wofi_dmenu_init() {
struct cache_line* node, *tmp; struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) { wl_list_for_each_safe(node, tmp, cache, link) {
wofi_insert_widget(node->line, node->line, node->line); wofi_insert_widget("dmenu", node->line, node->line, node->line);
map_put(cached, node->line, "true"); map_put(cached, node->line, "true");
free(node->line); free(node->line);
wl_list_remove(&node->link); wl_list_remove(&node->link);
@ -42,7 +42,7 @@ void wofi_dmenu_init() {
if(map_contains(cached, line)) { if(map_contains(cached, line)) {
continue; continue;
} }
wofi_insert_widget(line, line, line); wofi_insert_widget("dmenu", line, line, line);
} }
free(line); free(line);
map_free(cached); map_free(cached);

View File

@ -91,7 +91,7 @@ static void insert_dir(char* app_dir, struct map* cached, struct map* entries) {
} }
map_put(entries, entry->d_name, "true"); map_put(entries, entry->d_name, "true");
char* search_text = get_search_text(full_path); char* search_text = get_search_text(full_path);
wofi_insert_widget(text, search_text, full_path); wofi_insert_widget("drun", text, search_text, full_path);
free(text); free(text);
free(search_text); free(search_text);
free(full_path); free(full_path);
@ -111,7 +111,7 @@ void wofi_drun_init() {
goto cache_cont; goto cache_cont;
} }
char* search_text = get_search_text(node->line); char* search_text = get_search_text(node->line);
wofi_insert_widget(text, search_text, node->line); wofi_insert_widget("drun", text, search_text, node->line);
map_put(cached, node->line, "true"); map_put(cached, node->line, "true");
free(search_text); free(search_text);
free(text); free(text);

View File

@ -25,7 +25,7 @@ void wofi_run_init() {
wl_list_for_each_safe(node, tmp, cache, link) { wl_list_for_each_safe(node, tmp, cache, link) {
char* text = strrchr(node->line, '/') + 1; char* text = strrchr(node->line, '/') + 1;
char* search_text = utils_concat(2, text, node->line); char* search_text = utils_concat(2, text, node->line);
wofi_insert_widget(text, search_text, node->line); wofi_insert_widget("run", text, search_text, node->line);
map_put(cached, node->line, "true"); map_put(cached, node->line, "true");
free(search_text); free(search_text);
free(node->line); free(node->line);
@ -53,7 +53,7 @@ void wofi_run_init() {
stat(full_path, &info); stat(full_path, &info);
if(access(full_path, X_OK) == 0 && S_ISREG(info.st_mode) && !map_contains(cached, full_path)) { if(access(full_path, X_OK) == 0 && S_ISREG(info.st_mode) && !map_contains(cached, full_path)) {
char* search_text = utils_concat(2, entry->d_name, full_path); char* search_text = utils_concat(2, entry->d_name, full_path);
wofi_insert_widget(entry->d_name, search_text, full_path); wofi_insert_widget("run", entry->d_name, search_text, full_path);
free(search_text); free(search_text);
} }
free(full_path); free(full_path);

View File

@ -24,7 +24,7 @@ static int64_t x, y;
static struct zwlr_layer_shell_v1* shell; static struct zwlr_layer_shell_v1* shell;
static GtkWidget* window, *outer_box, *scroll, *entry, *inner_box, *previous_selection = NULL; static GtkWidget* window, *outer_box, *scroll, *entry, *inner_box, *previous_selection = NULL;
static const gchar* filter; static const gchar* filter;
static char* mode; static char* mode = NULL;
static time_t filter_time; static time_t filter_time;
static int64_t filter_rate; static int64_t filter_rate;
static bool allow_images, allow_markup; static bool allow_images, allow_markup;
@ -35,10 +35,14 @@ static bool run_in_term;
static char* terminal; static char* terminal;
static GtkOrientation outer_orientation; static GtkOrientation outer_orientation;
static bool exec_search; static bool exec_search;
static void (*mode_exec)(const gchar* cmd); static struct map* modes;
struct node { struct node {
char* text, *search_text, *action; char* mode, *text, *search_text, *action;
};
struct mode {
void (*mode_exec)(const gchar* cmd);
}; };
static void nop() {} static void nop() {}
@ -78,11 +82,12 @@ static void get_search(GtkSearchEntry* entry, gpointer data) {
gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box)); gtk_flow_box_invalidate_filter(GTK_FLOW_BOX(inner_box));
} }
static GtkWidget* create_label(char* text, char* search_text, char* action) { static GtkWidget* create_label(char* mode, char* text, char* search_text, char* action) {
GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0); GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_name(box, "unselected"); gtk_widget_set_name(box, "unselected");
GtkStyleContext* style = gtk_widget_get_style_context(box); GtkStyleContext* style = gtk_widget_get_style_context(box);
gtk_style_context_add_class(style, "entry"); gtk_style_context_add_class(style, "entry");
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "mode", mode);
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "action", action); wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "action", action);
if(allow_images) { if(allow_images) {
char* tmp = strdup(text); char* tmp = strdup(text);
@ -137,10 +142,11 @@ static GtkWidget* create_label(char* text, char* search_text, char* action) {
static gboolean _insert_widget(gpointer data) { static gboolean _insert_widget(gpointer data) {
struct node* node = data; struct node* node = data;
GtkWidget* box = create_label(node->text, node->search_text, node->action); GtkWidget* box = create_label(node->mode, node->text, node->search_text, node->action);
gtk_container_add(GTK_CONTAINER(inner_box), box); gtk_container_add(GTK_CONTAINER(inner_box), box);
gtk_widget_show_all(box); gtk_widget_show_all(box);
free(node->mode);
free(node->text); free(node->text);
free(node->search_text); free(node->search_text);
free(node->action); free(node->action);
@ -203,8 +209,9 @@ struct wl_list* wofi_read_cache(char* mode) {
return cache; return cache;
} }
void wofi_insert_widget(char* text, char* search_text, char* action) { void wofi_insert_widget(char* mode, char* text, char* search_text, char* action) {
struct node* widget = malloc(sizeof(struct node)); struct node* widget = malloc(sizeof(struct node));
widget->mode = strdup(mode);
widget->text = strdup(text); widget->text = strdup(text);
widget->search_text = strdup(search_text); widget->search_text = strdup(search_text);
widget->action = strdup(action); widget->action = strdup(action);
@ -237,6 +244,7 @@ void wofi_term_run(const char* cmd) {
} }
static void execute_action(char* mode, const gchar* cmd) { static void execute_action(char* mode, const gchar* cmd) {
struct mode* mode_ptr = map_get(modes, mode);
char* cache_path = get_cache_path(mode); char* cache_path = get_cache_path(mode);
struct wl_list lines; struct wl_list lines;
wl_list_init(&lines); wl_list_init(&lines);
@ -279,14 +287,14 @@ static void execute_action(char* mode, const gchar* cmd) {
fclose(file); fclose(file);
free(cache_path); free(cache_path);
mode_exec(cmd); mode_ptr->mode_exec(cmd);
} }
static void activate_item(GtkFlowBox* flow_box, GtkFlowBoxChild* row, gpointer data) { static void activate_item(GtkFlowBox* flow_box, GtkFlowBoxChild* row, gpointer data) {
(void) flow_box; (void) flow_box;
(void) data; (void) data;
GtkWidget* box = gtk_bin_get_child(GTK_BIN(row)); GtkWidget* box = gtk_bin_get_child(GTK_BIN(row));
execute_action(mode, wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action")); execute_action(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "mode"), wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action"));
} }
static void select_item(GtkFlowBox* flow_box, gpointer data) { static void select_item(GtkFlowBox* flow_box, gpointer data) {
@ -328,7 +336,7 @@ static void activate_search(GtkEntry* entry, gpointer data) {
execute_action(mode, gtk_entry_get_text(entry)); execute_action(mode, gtk_entry_get_text(entry));
} else { } else {
GtkWidget* box = gtk_bin_get_child(GTK_BIN(child)); GtkWidget* box = gtk_bin_get_child(GTK_BIN(child));
execute_action(mode, wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action")); execute_action(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "mode"), wofi_property_box_get_property(WOFI_PROPERTY_BOX(box), "action"));
} }
} }
@ -400,14 +408,15 @@ static void* get_plugin_proc(const char* prefix, const char* suffix) {
return proc; return proc;
} }
static void* start_thread(void* data) { static void add_mode(char* mode) {
char* mode = data;
char* dso = strstr(mode, ".so"); char* dso = strstr(mode, ".so");
struct mode* mode_ptr = calloc(1, sizeof(struct mode));
map_put_void(modes, mode, mode_ptr);
void (*init)(); void (*init)();
if(dso == NULL) { if(dso == NULL) {
init = get_plugin_proc(mode, "_init"); init = get_plugin_proc(mode, "_init");
mode_exec = get_plugin_proc(mode, "_exec"); mode_ptr->mode_exec = get_plugin_proc(mode, "_exec");
} else { } else {
char* plugins_dir = utils_concat(2, config_dir, "/plugins/"); char* plugins_dir = utils_concat(2, config_dir, "/plugins/");
char* full_name = utils_concat(2, plugins_dir, mode); char* full_name = utils_concat(2, plugins_dir, mode);
@ -415,7 +424,7 @@ static void* start_thread(void* data) {
free(full_name); free(full_name);
free(plugins_dir); free(plugins_dir);
init = dlsym(plugin, "init"); init = dlsym(plugin, "init");
mode_exec = dlsym(plugin, "exec"); mode_ptr->mode_exec = dlsym(plugin, "exec");
} }
if(init != NULL) { if(init != NULL) {
@ -424,7 +433,23 @@ static void* start_thread(void* data) {
fprintf(stderr, "I would love to show %s but Idk what it is\n", mode); fprintf(stderr, "I would love to show %s but Idk what it is\n", mode);
exit(1); exit(1);
} }
}
static void* start_thread(void* data) {
char* modes = data;
if(strchr(modes, ',') != NULL) {
char* save_ptr;
char* _mode = strtok_r(modes, ",", &save_ptr);
if(mode == NULL) {
mode = _mode;
}
do {
add_mode(_mode);
} while((_mode = strtok_r(NULL, ",", &save_ptr)) != NULL);
} else {
mode = modes;
add_mode(modes);
}
return NULL; return NULL;
} }
@ -434,7 +459,7 @@ void wofi_init(struct map* config) {
x = strtol(config_get(config, "x", "-1"), NULL, 10); x = strtol(config_get(config, "x", "-1"), NULL, 10);
y = strtol(config_get(config, "y", "-1"), NULL, 10); y = strtol(config_get(config, "y", "-1"), NULL, 10);
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0; bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
mode = map_get(config, "mode"); char* mode = map_get(config, "mode");
uint8_t orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "vertical", "horizontal"); uint8_t orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "vertical", "horizontal");
outer_orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "horizontal", "vertical"); outer_orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "horizontal", "vertical");
uint8_t halign = config_get_mnemonic(config, "halign", "fill", 4, "fill", "start", "end", "center"); uint8_t halign = config_get_mnemonic(config, "halign", "fill", 4, "fill", "start", "end", "center");
@ -454,6 +479,7 @@ void wofi_init(struct map* config) {
terminal = map_get(config, "term"); terminal = map_get(config, "term");
char* password_char = map_get(config, "password_char"); char* password_char = map_get(config, "password_char");
exec_search = strcmp(config_get(config, "exec_search", "false"), "true") == 0; exec_search = strcmp(config_get(config, "exec_search", "false"), "true") == 0;
modes = map_init_void();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_realize(window); gtk_widget_realize(window);