add possibility for comma separated integer list in --bar display=... (#354)

This commit is contained in:
Felix Kratz 2023-04-13 22:23:37 +02:00
parent 3fcab887f6
commit 084c9b642e
4 changed files with 47 additions and 18 deletions

View file

@ -24,7 +24,7 @@ void bar_manager_init(struct bar_manager* bar_manager) {
bar_manager->bars = NULL; bar_manager->bars = NULL;
bar_manager->bar_count = 0; bar_manager->bar_count = 0;
bar_manager->bar_item_count = 0; bar_manager->bar_item_count = 0;
bar_manager->display = DISPLAY_ALL; bar_manager->displays = DISPLAY_ALL_PATTERN;
bar_manager->position = POSITION_TOP; bar_manager->position = POSITION_TOP;
bar_manager->shadow = false; bar_manager->shadow = false;
bar_manager->blur_radius = 0; bar_manager->blur_radius = 0;
@ -206,9 +206,9 @@ bool bar_manager_set_position(struct bar_manager* bar_manager, char pos) {
return true; return true;
} }
bool bar_manager_set_display(struct bar_manager* bar_manager, char display) { bool bar_manager_set_displays(struct bar_manager* bar_manager, uint32_t displays) {
if (bar_manager->display == display) return false; if (bar_manager->displays == displays) return false;
bar_manager->display = display; bar_manager->displays = displays;
bar_manager_reset(bar_manager); bar_manager_reset(bar_manager);
return true; return true;
@ -548,7 +548,7 @@ void bar_manager_reset(struct bar_manager* bar_manager) {
} }
void bar_manager_begin(struct bar_manager* bar_manager) { void bar_manager_begin(struct bar_manager* bar_manager) {
if (bar_manager->display == DISPLAY_MAIN) { if (bar_manager->displays == DISPLAY_MAIN_PATTERN) {
uint32_t did = display_main_display_id(); uint32_t did = display_main_display_id();
bar_manager->bar_count = 1; bar_manager->bar_count = 1;
bar_manager->bars = (struct bar **) realloc( bar_manager->bars = (struct bar **) realloc(
@ -560,16 +560,27 @@ void bar_manager_begin(struct bar_manager* bar_manager) {
bar_manager->bars[0]->adid = display_arrangement(did); bar_manager->bars[0]->adid = display_arrangement(did);
} }
else { else {
bar_manager->bar_count = display_active_display_count(); uint32_t display_count = display_active_display_count();
uint32_t bar_count = 0;
for (uint32_t index = 1; index <= display_count; index++) {
if (!(bar_manager->displays & 1 << (index - 1))) continue;
bar_count++;
}
bar_manager->bar_count = bar_count;
bar_manager->bars = (struct bar **) realloc( bar_manager->bars = (struct bar **) realloc(
bar_manager->bars, bar_manager->bars,
sizeof(struct bar *) * bar_manager->bar_count); sizeof(struct bar *) * bar_manager->bar_count);
memset(bar_manager->bars, 0, sizeof(struct bar*) * bar_manager->bar_count); memset(bar_manager->bars, 0, sizeof(struct bar*) * bar_manager->bar_count);
for (uint32_t index = 1; index <= bar_manager->bar_count; index++) {
uint32_t bar_index = 0;
for (uint32_t index = 1; index <= display_count; index++) {
if (!(bar_manager->displays & 1 << (index - 1))) continue;
uint32_t did = display_arrangement_display_id(index); uint32_t did = display_arrangement_display_id(index);
bar_manager->bars[index - 1] = bar_create(did); bar_manager->bars[bar_index] = bar_create(did);
bar_manager->bars[index - 1]->adid = index; bar_manager->bars[bar_index]->adid = index;
bar_index++;
} }
} }

View file

@ -6,6 +6,9 @@
#define CLOCK_CALLBACK(name) void name(CFRunLoopTimerRef timer, void *context) #define CLOCK_CALLBACK(name) void name(CFRunLoopTimerRef timer, void *context)
typedef CLOCK_CALLBACK(clock_callback); typedef CLOCK_CALLBACK(clock_callback);
#define DISPLAY_MAIN_PATTERN 0
#define DISPLAY_ALL_PATTERN UINT32_MAX
struct bar_manager { struct bar_manager {
CFRunLoopTimerRef clock; CFRunLoopTimerRef clock;
@ -21,7 +24,7 @@ struct bar_manager {
bool bar_needs_update; bool bar_needs_update;
bool bar_needs_resize; bool bar_needs_resize;
char display; uint32_t displays;
char position; char position;
int margin; int margin;
@ -64,7 +67,7 @@ bool bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t r
bool bar_manager_set_position(struct bar_manager* bar_manager, char pos); bool bar_manager_set_position(struct bar_manager* bar_manager, char pos);
bool bar_manager_set_spaces(struct bar_manager* bar_manager, bool value); bool bar_manager_set_spaces(struct bar_manager* bar_manager, bool value);
bool bar_manager_set_spaces_for_all_displays(struct bar_manager* bar_manager, bool value); bool bar_manager_set_spaces_for_all_displays(struct bar_manager* bar_manager, bool value);
bool bar_manager_set_display(struct bar_manager* bar_manager, char display); bool bar_manager_set_displays(struct bar_manager* bar_manager, uint32_t displays);
bool bar_manager_set_hidden(struct bar_manager* bar_manager, uint32_t sid, bool hidden); bool bar_manager_set_hidden(struct bar_manager* bar_manager, uint32_t sid, bool hidden);
bool bar_manager_set_topmost(struct bar_manager* bar_manager, bool topmost); bool bar_manager_set_topmost(struct bar_manager* bar_manager, bool topmost);
bool bar_manager_set_sticky(struct bar_manager *bar_manager, bool sticky); bool bar_manager_set_sticky(struct bar_manager *bar_manager, bool sticky);

View file

@ -382,10 +382,25 @@ static bool handle_domain_bar(FILE *rsp, struct token domain, char *message) {
evaluate_boolean_state(token, evaluate_boolean_state(token,
g_bar_manager.sticky)); g_bar_manager.sticky));
} else if (token_equals(command, PROPERTY_DISPLAY)) { } else if (token_equals(command, PROPERTY_DISPLAY)) {
struct token position = get_token(&message); struct token display = get_token(&message);
if (position.length > 0)
needs_refresh = bar_manager_set_display(&g_bar_manager, uint32_t display_pattern = 0;
position.text[0]); uint32_t count;
char** list = token_split(display, ',', &count);
if (list && count > 0) {
for (int i = 0; i < count; i++) {
if (strcmp(list[i], ARGUMENT_DISPLAY_ALL) == 0) {
display_pattern = DISPLAY_ALL_PATTERN;
} else if (strcmp(list[i], ARGUMENT_DISPLAY_MAIN) == 0) {
display_pattern = DISPLAY_MAIN_PATTERN;
}
else {
display_pattern |= 1 << (strtoul(list[i], NULL, 0) - 1);
}
}
free(list);
}
needs_refresh = bar_manager_set_displays(&g_bar_manager, display_pattern);
} else if (token_equals(command, PROPERTY_POSITION)) { } else if (token_equals(command, PROPERTY_POSITION)) {
struct token position = get_token(&message); struct token position = get_token(&message);
if (position.length > 0) if (position.length > 0)

View file

@ -140,6 +140,9 @@
#define ARGUMENT_COMMON_VAL_BEFORE "before" #define ARGUMENT_COMMON_VAL_BEFORE "before"
#define ARGUMENT_COMMON_VAL_AFTER "after" #define ARGUMENT_COMMON_VAL_AFTER "after"
#define ARGUMENT_DISPLAY_MAIN "main"
#define ARGUMENT_DISPLAY_ALL "all"
#define ARGUMENT_UPDATES_WHEN_SHOWN "when_shown" #define ARGUMENT_UPDATES_WHEN_SHOWN "when_shown"
#define ARGUMENT_DYNAMIC "dynamic" #define ARGUMENT_DYNAMIC "dynamic"
@ -152,9 +155,6 @@
#define POSITION_CENTER_LEFT 'q' #define POSITION_CENTER_LEFT 'q'
#define POSITION_CENTER_RIGHT 'e' #define POSITION_CENTER_RIGHT 'e'
#define DISPLAY_MAIN 'm'
#define DISPLAY_ALL 'a'
#define TYPE_GRAPH "graph" #define TYPE_GRAPH "graph"
#define TYPE_SPACE "space" #define TYPE_SPACE "space"
#define TYPE_ALIAS "alias" #define TYPE_ALIAS "alias"