unify background usage

This commit is contained in:
FelixKratz 2021-09-27 21:46:18 +02:00
parent 5629b88173
commit 1840deab3b
4 changed files with 31 additions and 36 deletions

View file

@ -143,14 +143,14 @@ static int bar_get_center_length(struct bar_manager* bar_manager) {
void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool right_to_left) {
if (!bar_item->has_graph) return;
bar_draw_graph_line(bar, &bar_item->graph_data, x, g_bar_manager.border_width + 1, right_to_left);
bar_draw_graph_line(bar, &bar_item->graph_data, x, g_bar_manager.background.border_width + 1, right_to_left);
}
void bar_draw_item_background(struct bar* bar, struct bar_item* bar_item, uint32_t adid) {
if (!bar_item->background.enabled) return;
bool custom_height = bar_item->background.height != 0;
CGRect draw_region = {{bar_item->bounding_rects[adid - 1]->origin.x - bar->origin.x, custom_height ? ((bar->frame.size.height - bar_item->background.height)) / 2 : (g_bar_manager.border_width + 1)},
{bar_item->bounding_rects[adid - 1]->size.width, custom_height ? bar_item->background.height : (bar->frame.size.height - 2*(g_bar_manager.border_width + 1))}};
CGRect draw_region = {{bar_item->bounding_rects[adid - 1]->origin.x - bar->origin.x, custom_height ? ((bar->frame.size.height - bar_item->background.height)) / 2 : (g_bar_manager.background.border_width + 1)},
{bar_item->bounding_rects[adid - 1]->size.width, custom_height ? bar_item->background.height : (bar->frame.size.height - 2*(g_bar_manager.background.border_width + 1))}};
draw_region = CGRectInset(draw_region, bar_item->background.border_width / 2, bar_item->background.border_width / 2);
draw_rect(bar->context, draw_region, &bar_item->background.color, bar_item->background.corner_radius, bar_item->background.border_width, &bar_item->background.border_color, false);
}
@ -167,13 +167,13 @@ void bar_redraw(struct bar* bar) {
uint32_t sid = bar->sid;
if (sid == 0) return;
int bar_left_final_item_x = g_bar_manager.padding_left;
int bar_right_first_item_x = bar->frame.size.width - g_bar_manager.padding_right;
int bar_left_final_item_x = g_bar_manager.background.padding_left;
int bar_right_first_item_x = bar->frame.size.width - g_bar_manager.background.padding_right;
int bar_center_first_item_x = (bar->frame.size.width - bar_get_center_length(&g_bar_manager)) / 2;
SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, bar->id, -1, 0);
draw_rect(bar->context, bar->frame, &g_bar_manager.background_color, g_bar_manager.corner_radius, g_bar_manager.border_width, &g_bar_manager.border_color, true);
draw_rect(bar->context, bar->frame, &g_bar_manager.background.color, g_bar_manager.background.corner_radius, g_bar_manager.background.border_width, &g_bar_manager.background.border_color, true);
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
struct bar_item* bar_item = g_bar_manager.bar_items[i];
@ -262,13 +262,13 @@ void bar_create_frame(struct bar *bar, CFTypeRef *frame_region) {
if (0 == strcmp(g_bar_manager.position, BAR_POSITION_BOTTOM)) {
origin.y = CGRectGetMaxY(bounds) - g_bar_manager.height - 2*g_bar_manager.y_offset;
origin.y = CGRectGetMaxY(bounds) - g_bar_manager.background.height - 2*g_bar_manager.y_offset;
} else if (display_menu_bar_visible() && !g_bar_manager.topmost) {
CGRect menu = display_menu_bar_rect(bar->did);
origin.y += menu.size.height;
}
bar->frame = (CGRect) {{0, 0},{bounds.size.width, g_bar_manager.height}};
bar->frame = (CGRect) {{0, 0},{bounds.size.width, g_bar_manager.background.height}};
bar->origin = origin;
CGSNewRegionWithRect(&bar->frame, frame_region);
}

View file

@ -1,4 +1,5 @@
#include "bar_manager.h"
#include "background.h"
#include "bar.h"
#include "bar_item.h"
#include "misc/helpers.h"
@ -38,17 +39,17 @@ void bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t r
}
void bar_manager_set_background_color(struct bar_manager* bar_manager, uint32_t color) {
bar_manager->background_color = rgba_color_from_hex(color);
bar_manager->background.color = rgba_color_from_hex(color);
bar_manager_refresh(bar_manager, true);
}
void bar_manager_set_border_color(struct bar_manager* bar_manager, uint32_t color) {
bar_manager->border_color = rgba_color_from_hex(color);
bar_manager->background.border_color = rgba_color_from_hex(color);
bar_manager_refresh(bar_manager, true);
}
void bar_manager_set_border_width(struct bar_manager* bar_manager, uint32_t width) {
bar_manager->border_width = width;
bar_manager->background.border_width = width;
bar_manager_refresh(bar_manager, true);
}
@ -58,17 +59,17 @@ void bar_manager_set_position(struct bar_manager* bar_manager, char *pos) {
}
void bar_manager_set_height(struct bar_manager* bar_manager, uint32_t height) {
bar_manager->height = height;
bar_manager->background.height = height;
bar_manager_resize(bar_manager);
}
void bar_manager_set_padding_left(struct bar_manager* bar_manager, uint32_t padding) {
bar_manager->padding_left = padding;
bar_manager->background.padding_left = padding;
bar_manager_refresh(bar_manager, true);
}
void bar_manager_set_padding_right(struct bar_manager* bar_manager, uint32_t padding) {
bar_manager->padding_right = padding;
bar_manager->background.padding_right = padding;
bar_manager_refresh(bar_manager, true);
}
@ -163,19 +164,19 @@ void bar_manager_init(struct bar_manager* bar_manager) {
bar_manager->bar_item_count = 0;
bar_manager->display = BAR_DISPLAY_ALL;
bar_manager->position = BAR_POSITION_TOP;
bar_manager->height = 25;
bar_manager->y_offset = 0;
bar_manager->corner_radius = 0;
bar_manager->blur_radius = 0;
bar_manager->margin = 0;
bar_manager->padding_left = 20;
bar_manager->padding_right = 20;
bar_manager->frozen = false;
bar_manager->window_level = NSFloatingWindowLevel;
bar_manager->topmost = false;
bar_manager->border_width = 0;
bar_manager->border_color = rgba_color_from_hex(0xffff0000);
bar_manager->background_color = rgba_color_from_hex(0x44000000);
background_init(&bar_manager->background);
bar_manager->background.height = 25;
bar_manager->background.padding_left = 20;
bar_manager->background.padding_right = 20;
bar_manager->background.border_color = rgba_color_from_hex(0xffff0000);
bar_manager->background.color = rgba_color_from_hex(0x44000000);
bar_item_init(&bar_manager->default_item, NULL);
custom_events_init(&bar_manager->custom_events);
@ -364,15 +365,15 @@ void bar_manager_serialize(struct bar_manager* bar_manager, FILE* rsp) {
"\t},\n"
"\t\"items\": [\n",
bar_manager->position,
bar_manager->height,
bar_manager->background.height,
bar_manager->margin,
bar_manager->y_offset,
bar_manager->corner_radius,
bar_manager->border_width,
bar_manager->padding_left,
bar_manager->padding_right,
hex_from_rgba_color(bar_manager->background_color),
hex_from_rgba_color(bar_manager->border_color),
bar_manager->background.corner_radius,
bar_manager->background.border_width,
bar_manager->background.padding_left,
bar_manager->background.padding_right,
hex_from_rgba_color(bar_manager->background.color),
hex_from_rgba_color(bar_manager->background.border_color),
bar_manager->blur_radius,
bar_manager->frozen,
bar_manager->topmost,

View file

@ -23,17 +23,11 @@ struct bar_manager {
int bar_item_count;
char *position;
char *display;
uint32_t height;
uint32_t margin;
uint32_t corner_radius;
uint32_t blur_radius;
uint32_t y_offset;
uint32_t padding_left;
uint32_t padding_right;
uint32_t border_width;
struct rgba_color background_color;
struct rgba_color border_color;
struct background background;
struct custom_events custom_events;
};

View file

@ -531,7 +531,7 @@ static void handle_domain_bar(FILE *rsp, struct token domain, char *message) {
g_bar_manager.y_offset = token_to_uint32t(token);
} else if (token_equals(command, COMMAND_BAR_CORNER_RADIUS)) {
struct token token = get_token(&message);
g_bar_manager.corner_radius = token_to_uint32t(token);
g_bar_manager.background.corner_radius = token_to_uint32t(token);
} else if (token_equals(command, COMMAND_BAR_BLUR_RADIUS)) {
struct token token = get_token(&message);
bar_manager_set_background_blur(&g_bar_manager, token_to_uint32t(token));