From cac457453466fd773e3278602d84b1582ae1641a Mon Sep 17 00:00:00 2001 From: Scoopta Date: Sat, 25 Jan 2020 14:29:52 -0800 Subject: [PATCH] Added the dmenu-separator config option --- man/wofi.7 | 3 +++ modes/dmenu.c | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/man/wofi.7 b/man/wofi.7 index dc802b7..ba4d984 100644 --- a/man/wofi.7 +++ b/man/wofi.7 @@ -23,6 +23,9 @@ Combi is not a mode however it does exist as a feature. You can use it by doing .TP .B parse_action=\fIBOOL\fR If true the result returned by dmenu will be stripped of image escape sequences and pango markup, default is false. +.TP +.B separator=\fICHAR\fR +The character used to separate dmenu entries, default is \\n. .SH RUN CONFIG OPTIONS .TP diff --git a/modes/dmenu.c b/modes/dmenu.c index cf093f4..79cd66d 100644 --- a/modes/dmenu.c +++ b/modes/dmenu.c @@ -17,9 +17,10 @@ #include -static const char* arg_names[] = {"parse_action"}; +static const char* arg_names[] = {"parse_action", "separator"}; static bool parse_action; +static char* separator; static struct mode* mode; struct node { @@ -32,6 +33,7 @@ static struct wl_list widgets; void wofi_dmenu_init(struct mode* this, struct map* config) { mode = this; parse_action = strcmp(config_get(config, "parse_action", "false"), "true") == 0; + separator = config_get(config, "separator", "\n"); wl_list_init(&widgets); @@ -43,20 +45,31 @@ void wofi_dmenu_init(struct mode* this, struct map* config) { struct map* entry_map = map_init(); + char* buffer = NULL; + char* line = NULL; size_t size = 0; while(getline(&line, &size, stdin) != -1) { - char* lf = strchr(line, '\n'); - if(lf != NULL) { - *lf = 0; + if(buffer == NULL) { + buffer = strdup(line); + } else { + char* old = buffer; + buffer = utils_concat(2, buffer, line); + free(old); } - struct cache_line* node = malloc(sizeof(struct cache_line)); - node->line = strdup(line); - wl_list_insert(&entries, &node->link); - map_put(entry_map, line, "true"); } free(line); + char* save_ptr; + char* str = strtok_r(buffer, separator, &save_ptr); + do { + struct cache_line* node = malloc(sizeof(struct cache_line)); + node->line = strdup(str); + wl_list_insert(&entries, &node->link); + map_put(entry_map, str, "true"); + } while((str = strtok_r(NULL, separator, &save_ptr)) != NULL); + free(buffer); + struct cache_line* node, *tmp; wl_list_for_each_safe(node, tmp, cache, link) { if(map_contains(entry_map, node->line)) {