Added the dmenu-separator config option

This commit is contained in:
Scoopta 2020-01-25 14:29:52 -08:00
parent 008f511891
commit cac4574534
2 changed files with 24 additions and 8 deletions

View File

@ -23,6 +23,9 @@ Combi is not a mode however it does exist as a feature. You can use it by doing
.TP .TP
.B parse_action=\fIBOOL\fR .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. 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 .SH RUN CONFIG OPTIONS
.TP .TP

View File

@ -17,9 +17,10 @@
#include <wofi.h> #include <wofi.h>
static const char* arg_names[] = {"parse_action"}; static const char* arg_names[] = {"parse_action", "separator"};
static bool parse_action; static bool parse_action;
static char* separator;
static struct mode* mode; static struct mode* mode;
struct node { struct node {
@ -32,6 +33,7 @@ static struct wl_list widgets;
void wofi_dmenu_init(struct mode* this, struct map* config) { void wofi_dmenu_init(struct mode* this, struct map* config) {
mode = this; mode = this;
parse_action = strcmp(config_get(config, "parse_action", "false"), "true") == 0; parse_action = strcmp(config_get(config, "parse_action", "false"), "true") == 0;
separator = config_get(config, "separator", "\n");
wl_list_init(&widgets); wl_list_init(&widgets);
@ -43,20 +45,31 @@ void wofi_dmenu_init(struct mode* this, struct map* config) {
struct map* entry_map = map_init(); struct map* entry_map = map_init();
char* buffer = NULL;
char* line = NULL; char* line = NULL;
size_t size = 0; size_t size = 0;
while(getline(&line, &size, stdin) != -1) { while(getline(&line, &size, stdin) != -1) {
char* lf = strchr(line, '\n'); if(buffer == NULL) {
if(lf != NULL) { buffer = strdup(line);
*lf = 0; } 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); 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; struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) { wl_list_for_each_safe(node, tmp, cache, link) {
if(map_contains(entry_map, node->line)) { if(map_contains(entry_map, node->line)) {