add associated_display=active option to associate items to only show on the active display

This commit is contained in:
Felix Kratz 2022-08-24 09:28:07 +02:00
parent 5c646aa7a6
commit 0e717ab34d
4 changed files with 50 additions and 17 deletions

View file

@ -13,9 +13,11 @@ void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool
bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
if (!bar_item->drawing || !bar->shown || bar->hidden) return false;
if (bar_item->associated_display > 0
&& (!(bar_item->associated_display & (1 << bar->adid)))
&& !bar_item->ignore_association)
if (((bar_item->associated_display > 0
&& (!(bar_item->associated_display & (1 << bar->adid))))
|| (bar_item->associated_to_active_display
&& (bar->adid != g_bar_manager.active_adid)))
&& !bar_item->ignore_association)
return false;
if (bar_item->associated_space > 0

View file

@ -87,6 +87,7 @@ void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) {
bar_item->update_frequency = 0;
bar_item->position = POSITION_LEFT;
bar_item->align = POSITION_LEFT;
bar_item->associated_to_active_display = false;
bar_item->associated_display = 0;
bar_item->associated_space = 0;
bar_item->associated_bar = 0;
@ -874,26 +875,38 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE*
struct token token = get_token(&message);
uint32_t prev = bar_item->associated_space;
bar_item->associated_space = 0;
for (int i = 0; i < token.length; i++) {
int sep = -1;
if (token.text[i] == ',') token.text[i] = '\0', sep = i;
bar_item_append_associated_space(bar_item,
1 << strtoul(&token.text[sep + 1],
NULL,
0 ));
uint32_t count;
char** list = token_split(token, ',', &count);
if (list && count > 0) {
for (int i = 0; i < count; i++) {
bar_item_append_associated_space(bar_item,
1 << strtoul(list[i],
NULL,
0 ));
}
free(list);
}
needs_refresh = (prev != bar_item->associated_space);
} else if (token_equals(property, PROPERTY_ASSOCIATED_DISPLAY)) {
struct token token = get_token(&message);
uint32_t prev = bar_item->associated_display;
bar_item->associated_display = 0;
for (int i = 0; i < token.length; i++) {
int sep = -1;
if (token.text[i] == ',') token.text[i] = '\0', sep = i;
bar_item_append_associated_display(bar_item,
1 << strtoul(&token.text[sep + 1],
NULL,
0 ));
bar_item->associated_to_active_display = false;
uint32_t count;
char** list = token_split(token, ',', &count);
if (list && count > 0) {
for (int i = 0; i < count; i++) {
if (strcmp(list[i], "active") == 0) {
bar_item->associated_to_active_display = true;
}
else {
bar_item_append_associated_display(bar_item,
1 << strtoul(list[i],
NULL,
0 ));
}
}
free(list);
}
needs_refresh = (prev != bar_item->associated_display);
} else if (token_equals(property, PROPERTY_YOFFSET)) {

View file

@ -32,6 +32,7 @@ struct bar_item {
uint32_t blur_radius;
// These are 32bit masks where the ith bit represents the ith screen/display/bar association
bool associated_to_active_display;
uint32_t associated_bar;
uint32_t associated_display;
uint32_t associated_space;

View file

@ -192,6 +192,23 @@ static inline char* get_modifier_description(uint32_t modifier) {
return "none";
}
static inline char** token_split(struct token token, char split, uint32_t* count) {
if (!token.text || token.length == 0) return NULL;
char** list = NULL;
*count = 0;
int prev = -1;
for (int i = 0; i < token.length + 1; i++) {
if (token.text[i] == split || token.text[i] == '\0') {
list = realloc(list, sizeof(char*) * ++*count);
token.text[i] = '\0';
list[*count - 1] = &token.text[prev + 1];
prev = i;
}
}
return list;
}
static inline bool token_equals(struct token token, char *match) {
char *at = match;
for (int i = 0; i < token.length; ++i, ++at) {