added corner radius option for the bar

This commit is contained in:
FelixKratz 2021-09-01 16:42:27 +02:00
parent 8ce08a2a21
commit 0c08ca88c4
5 changed files with 29 additions and 54 deletions

View file

@ -123,6 +123,7 @@ where the settings currently are:
* *height*: the height of the bar in pixels
* *margin*: the screen padding around the bar itself
* *y_offset*: the y-offset in pixels from the default position
* *corner_radius*: the corner radius of the bar itself
* *padding_left*: padding on the left before first item
* *padding_right*: just as padding_right
* *bar_color*: the color of the bar itself

View file

@ -163,8 +163,20 @@ void bar_refresh(struct bar *bar)
SLSOrderWindow(g_connection, bar->id, -1, 0);
CGContextClearRect(bar->context, bar->frame);
CGContextSetRGBFillColor(bar->context, g_bar_manager.background_color.r, g_bar_manager.background_color.g, g_bar_manager.background_color.b, g_bar_manager.background_color.a);
CGContextFillRect(bar->context, bar->frame);
CGContextStrokePath(bar->context);
CGContextSetRGBStrokeColor(bar->context, g_bar_manager.background_color.r, g_bar_manager.background_color.g, g_bar_manager.background_color.b, g_bar_manager.background_color.a);
CGFloat radius = g_bar_manager.corner_radius;
CGFloat minx = CGRectGetMinX(bar->frame), midx = CGRectGetMidX(bar->frame), maxx = CGRectGetMaxX(bar->frame);
CGFloat miny = CGRectGetMinY(bar->frame), midy = CGRectGetMidY(bar->frame), maxy = CGRectGetMaxY(bar->frame);
CGContextMoveToPoint(bar->context, minx, midy);
CGContextAddArcToPoint(bar->context, minx, miny, midx, miny, radius);
CGContextAddArcToPoint(bar->context, maxx, miny, maxx, midy, radius);
CGContextAddArcToPoint(bar->context, maxx, maxy, midx, maxy, radius);
CGContextAddArcToPoint(bar->context, minx, maxy, minx, midy, radius);
CGContextClosePath(bar->context);
CGContextDrawPath(bar->context, kCGPathFillStroke);
//CGContextFillRect(bar->context, bar->frame);
//CGContextStrokePath(bar->context);
uint32_t did = display_arrangement(bar->did);
uint32_t sid = mission_control_index(display_space_id(bar->did));
if (sid == 0) return;

View file

@ -105,6 +105,7 @@ void bar_manager_init(struct bar_manager *bar_manager) {
bar_manager->position = BAR_POSITION_TOP;
bar_manager->height = 25;
bar_manager->y_offset = 0;
bar_manager->corner_radius = 0;
bar_manager->margin = 0;
bar_manager->padding_left = 20;
bar_manager->padding_right = 20;

View file

@ -20,6 +20,7 @@ struct bar_manager {
char *display;
uint32_t height;
uint32_t margin;
uint32_t corner_radius;
uint32_t y_offset;
uint32_t padding_left;
uint32_t padding_right;

View file

@ -69,6 +69,7 @@ extern bool g_verbose;
#define COMMAND_CONFIG_BAR_HEIGHT "height"
#define COMMAND_CONFIG_BAR_YOFFSET "y_offset"
#define COMMAND_CONFIG_BAR_MARGIN "margin"
#define COMMAND_CONFIG_BAR_CORNER_RADIUS "corner_radius"
#define COMMAND_CONFIG_BAR_PADDING_LEFT "padding_left"
#define COMMAND_CONFIG_BAR_PADDING_RIGHT "padding_right"
#define COMMAND_CONFIG_BAR_DISPLAY "display"
@ -102,11 +103,6 @@ static bool token_equals(struct token token, char *match)
return *at == 0;
}
static bool token_is_valid(struct token token)
{
return token.text && token.length > 0;
}
static char *token_to_string(struct token token)
{
char *result = malloc(token.length + 1);
@ -437,64 +433,28 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
{
struct token command = get_token(&message);
if (token_equals(command, COMMAND_CONFIG_DEBUG_OUTPUT)) {
if (token_equals(command, COMMAND_CONFIG_BAR_BACKGROUND)) {
struct token value = get_token(&message);
if (!token_is_valid(value)) {
fprintf(rsp, "%s\n", bool_str[g_verbose]);
} else if (token_equals(value, ARGUMENT_COMMON_VAL_OFF)) {
g_verbose = false;
} else if (token_equals(value, ARGUMENT_COMMON_VAL_ON)) {
g_verbose = true;
} else {
daemon_fail(rsp, "unknown value '%.*s' given to command '%.*s' for domain '%.*s'\n", value.length, value.text, command.length, command.text, domain.length, domain.text);
}
} else if (token_equals(command, COMMAND_CONFIG_BAR_BACKGROUND)) {
struct token value = get_token(&message);
if (!token_is_valid(value)) {
fprintf(rsp, "0x%x\n", g_bar_manager.background_color.p);
} else {
uint32_t color = token_to_uint32t(value);
if (color) {
bar_manager_set_background_color(&g_bar_manager, color);
} else {
daemon_fail(rsp, "unknown value '%.*s' given to command '%.*s' for domain '%.*s'\n", value.length, value.text, command.length, command.text, domain.length, domain.text);
}
}
uint32_t color = token_to_uint32t(value);
bar_manager_set_background_color(&g_bar_manager, color);
} else if (token_equals(command, COMMAND_CONFIG_BAR_HEIGHT)) {
struct token token = get_token(&message);
if (!token_is_valid(token)) {
fprintf(rsp, "%"PRIu32"\n", g_bar_manager.height ? g_bar_manager.height : 0);
} else {
bar_manager_set_height(&g_bar_manager, atoi(token_to_string(token)));
}
bar_manager_set_height(&g_bar_manager, atoi(token_to_string(token)));
} else if (token_equals(command, COMMAND_CONFIG_BAR_MARGIN)) {
struct token token = get_token(&message);
if (!token_is_valid(token)) {
fprintf(rsp, "%"PRIu32"\n", g_bar_manager.height ? g_bar_manager.height : 0);
} else {
g_bar_manager.margin = token_to_uint32t(token);
}
g_bar_manager.margin = token_to_uint32t(token);
} else if (token_equals(command, COMMAND_CONFIG_BAR_YOFFSET)) {
struct token token = get_token(&message);
if (!token_is_valid(token)) {
fprintf(rsp, "%"PRIu32"\n", g_bar_manager.height ? g_bar_manager.height : 0);
} else {
g_bar_manager.y_offset = token_to_uint32t(token);
}
g_bar_manager.y_offset = token_to_uint32t(token);
} else if (token_equals(command, COMMAND_CONFIG_BAR_CORNER_RADIUS)) {
struct token token = get_token(&message);
g_bar_manager.corner_radius = token_to_uint32t(token);
} else if (token_equals(command, COMMAND_CONFIG_BAR_PADDING_LEFT)) {
struct token token = get_token(&message);
if (!token_is_valid(token)) {
fprintf(rsp, "%"PRIu32"\n", g_bar_manager.padding_left ? g_bar_manager.padding_left : 0);
} else {
bar_manager_set_padding_left(&g_bar_manager, atoi(token_to_string(token)));
}
bar_manager_set_padding_left(&g_bar_manager, atoi(token_to_string(token)));
} else if (token_equals(command, COMMAND_CONFIG_BAR_PADDING_RIGHT)) {
struct token token = get_token(&message);
if (!token_is_valid(token)) {
fprintf(rsp, "%"PRIu32"\n", g_bar_manager.padding_right ? g_bar_manager.padding_right : 0);
} else {
bar_manager_set_padding_right(&g_bar_manager, atoi(token_to_string(token)));
}
bar_manager_set_padding_right(&g_bar_manager, atoi(token_to_string(token)));
} else if (token_equals(command, COMMAND_CONFIG_BAR_DISPLAY)) {
int length = strlen(message);
if (length <= 0) {