From 769a1c1f28fd0d8e528251a6eca59639fe8e3c92 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sat, 25 Dec 2021 00:45:50 +0100 Subject: [PATCH] fixes a critical bug with brackets and adds background shadows --- src/background.c | 24 ++++++++++++++++++++++-- src/background.h | 1 + src/group.c | 2 ++ src/manifest.m | 4 ++-- src/message.c | 12 +++++++++--- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/background.c b/src/background.c index 639b8e1..cc5e719 100644 --- a/src/background.c +++ b/src/background.c @@ -1,5 +1,6 @@ #include "background.h" #include "misc/helpers.h" +#include "shadow.h" void background_init(struct background* background) { background->enabled = false; @@ -14,6 +15,7 @@ void background_init(struct background* background) { background->color = rgba_color_from_hex(0xff000000); background->border_color = rgba_color_from_hex(0xff000000); + shadow_init(&background->shadow); } bool background_set_color(struct background* background, uint32_t color) { @@ -81,6 +83,11 @@ void background_calculate_bounds(struct background* background, uint32_t x, uint void background_draw(struct background* background, CGContextRef context) { if (!background->enabled) return; + if (background->shadow.enabled) { + CGRect bounds = shadow_get_bounds(&background->shadow, background->bounds); + draw_rect(context, bounds, &background->shadow.color, background->corner_radius, background->border_width, &background->shadow.color, false); + } + draw_rect(context, background->bounds, &background->color, background->corner_radius, background->border_width, &background->border_color, false); } @@ -102,8 +109,21 @@ static bool background_parse_sub_domain(struct background* background, FILE* rsp else if (token_equals(property, PROPERTY_PADDING_RIGHT)) return background_set_padding_right(background, token_to_int(get_token(&message))); else { - fprintf(rsp, "Unknown property: %s \n", property.text); - printf("Unknown property: %s \n", property.text); + struct key_value_pair key_value_pair = get_key_value_pair(property.text, '.'); + if (key_value_pair.key && key_value_pair.value) { + struct token subdom = { key_value_pair.key, strlen(key_value_pair.key) }; + struct token entry = { key_value_pair.value, strlen(key_value_pair.value) }; + if (token_equals(subdom, SUB_DOMAIN_SHADOW)) + return shadow_parse_sub_domain(&background->shadow, rsp, entry, message); + else { + fprintf(rsp, "Invalid subdomain: %s \n", subdom.text); + printf("Invalid subdomain: %s \n", subdom.text); + } + } + else { + fprintf(rsp, "Unknown property: %s \n", property.text); + printf("Unknown property: %s \n", property.text); + } } return false; } diff --git a/src/background.h b/src/background.h index 923fb19..339a3a2 100644 --- a/src/background.h +++ b/src/background.h @@ -12,6 +12,7 @@ struct background { int padding_right; struct rgba_color color; struct rgba_color border_color; + struct shadow shadow; }; void background_init(struct background* background); diff --git a/src/group.c b/src/group.c index ba84b06..80aa73c 100644 --- a/src/group.c +++ b/src/group.c @@ -24,12 +24,14 @@ bool group_is_item_member(struct group* group, struct bar_item* item) { } void group_add_member(struct group* group, struct bar_item* item) { + printf("Adding: %s\n", item->name); if (group_is_item_member(group, item)) return; if (item->group && item->group->members && item->group->members[0] == item) { for (int i = 1; i < item->group->num_members; i++) { group_add_member(group, item->group->members[i]); } } else { + printf("Added: %s\n", item->name); group->num_members++; group->members = realloc(group->members, sizeof(struct bar_item*)*group->num_members); group->members[group->num_members - 1] = item; diff --git a/src/manifest.m b/src/manifest.m index 60da52d..a833e21 100644 --- a/src/manifest.m +++ b/src/manifest.m @@ -25,10 +25,10 @@ #include "workspace.h" #include "message.h" #include "display.h" +#include "shadow.h" #include "background.h" #include "bar.h" #include "popup.h" -#include "shadow.h" #include "text.h" #include "graph.h" #include "alias.h" @@ -43,10 +43,10 @@ #include "workspace.m" #include "message.c" #include "display.c" +#include "shadow.c" #include "background.c" #include "bar.c" #include "popup.c" -#include "shadow.c" #include "text.c" #include "graph.c" #include "alias.c" diff --git a/src/message.c b/src/message.c index 2329936..5a1972a 100644 --- a/src/message.c +++ b/src/message.c @@ -133,18 +133,22 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { bar_item_set_type(bar_item, command.text[0]); bar_item->position = position.text[0]; - struct key_value_pair key_value_pair = get_key_value_pair(position.text, '.'); - if (key_value_pair.key && key_value_pair.value) { - if (key_value_pair.key[0] == POSITION_POPUP) { + if (position.text[0] == POSITION_POPUP) { + char* pair = malloc(sizeof(char)*position.length); + memcpy(pair, position.text, position.length); + struct key_value_pair key_value_pair = get_key_value_pair(pair, '.'); + if (key_value_pair.key && key_value_pair.value) { int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, key_value_pair.value); if (item_index_for_name < 0) { fprintf(rsp, "Name: %s not found in bar items \n", key_value_pair.value); printf("Name: %s not found in bar items \n", key_value_pair.value); + free(pair); return; } struct bar_item* target_item = g_bar_manager.bar_items[item_index_for_name]; popup_add_item(&target_item->popup, bar_item); } + free(pair); } bar_item_set_name(bar_item, token_to_string(name)); @@ -167,7 +171,9 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { else if (bar_item->type == BAR_COMPONENT_GROUP) { struct token member = position; while (member.text && member.length > 0) { + int index = bar_manager_get_item_index_for_name(&g_bar_manager, member.text); + printf("Index for item %s, %d\n", member.text, index); if (index >= 0) group_add_member(bar_item->group, g_bar_manager.bar_items[index]); else {