Added parse_action option to dmenu

This commit is contained in:
Scoopta 2019-12-16 19:15:16 -08:00
parent 62861d3686
commit c248461260
3 changed files with 33 additions and 3 deletions

View File

@ -44,6 +44,8 @@ struct cache_line {
void wofi_init(struct map* config);
char* wofi_parse_image_escapes(const char* text);
void wofi_write_cache(const gchar* mode, const gchar* cmd);
struct wl_list* wofi_read_cache(char* mode);

View File

@ -19,7 +19,13 @@
#define MODE "dmenu"
void wofi_dmenu_init() {
static const char* arg_names[] = {"parse_action"};
static bool parse_action;
void wofi_dmenu_init(struct map* config) {
parse_action = strcmp(config_get(config, "parse_action", "false"), "true") == 0;
struct map* cached = map_init();
struct wl_list* cache = wofi_read_cache(MODE);
@ -51,7 +57,25 @@ void wofi_dmenu_init() {
}
void wofi_dmenu_exec(const gchar* cmd) {
char* action = strdup(cmd);
if(parse_action) {
free(action);
action = wofi_parse_image_escapes(cmd);
char* out;
pango_parse_markup(action, -1, 0, NULL, &out, NULL, NULL);
free(action);
action = out;
}
wofi_write_cache(MODE, cmd);
printf("%s\n", cmd);
printf("%s\n", action);
free(action);
exit(0);
}
const char** wofi_dmenu_get_arg_names() {
return arg_names;
}
size_t wofi_dmenu_get_arg_count() {
return sizeof(arg_names) / sizeof(char*);
}

View File

@ -95,7 +95,7 @@ static void get_search(GtkSearchEntry* entry, gpointer data) {
gtk_flow_box_invalidate_sort(GTK_FLOW_BOX(inner_box));
}
static char* parse_images(WofiPropertyBox* box, char* text, bool create_widgets) {
static char* parse_images(WofiPropertyBox* box, const char* text, bool create_widgets) {
char* ret = strdup("");
struct map* mode_map = map_init();
map_put(mode_map, "img", "true");
@ -214,6 +214,10 @@ static char* parse_images(WofiPropertyBox* box, char* text, bool create_widgets)
}
}
char* wofi_parse_image_escapes(const char* text) {
return parse_images(NULL, text, false);
}
static GtkWidget* create_label(char* mode, char* text, char* search_text, char* action) {
GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_name(box, "unselected");