mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-10 22:04:28 +00:00
continued background refactoring
This commit is contained in:
parent
968ef7464e
commit
d4948c429f
5 changed files with 28 additions and 69 deletions
|
@ -59,16 +59,14 @@ bool background_set_corner_radius(struct background* background, uint32_t corner
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool background_set_padding_left(struct background* background, uint32_t pad) {
|
||||||
|
if (background->padding_left == pad) return false;
|
||||||
|
background->padding_left = pad;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool background_set_padding_right(struct background* background, uint32_t pad) {
|
||||||
|
if (background->padding_right == pad) return false;
|
||||||
|
background->padding_right = pad;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,5 +19,7 @@ bool background_set_enabled(struct background* background, bool enabled);
|
||||||
bool background_set_height(struct background* background, uint32_t height);
|
bool background_set_height(struct background* background, uint32_t height);
|
||||||
bool background_set_border_width(struct background* background, uint32_t border_width);
|
bool background_set_border_width(struct background* background, uint32_t border_width);
|
||||||
bool background_set_corner_radius(struct background* background, uint32_t corner_radius);
|
bool background_set_corner_radius(struct background* background, uint32_t corner_radius);
|
||||||
|
bool background_set_padding_left(struct background* background, uint32_t pad);
|
||||||
|
bool background_set_padding_right(struct background* background, uint32_t pad);
|
||||||
|
|
||||||
#endif // !BACKGROUND_H
|
#endif // !BACKGROUND_H
|
||||||
|
|
|
@ -38,41 +38,11 @@ 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_refresh(bar_manager, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_manager_set_border_color(struct bar_manager* bar_manager, uint32_t 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->background.border_width = width;
|
|
||||||
bar_manager_refresh(bar_manager, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_manager_set_position(struct bar_manager* bar_manager, char *pos) {
|
void bar_manager_set_position(struct bar_manager* bar_manager, char *pos) {
|
||||||
bar_manager->position = pos;
|
bar_manager->position = pos;
|
||||||
bar_manager_resize(bar_manager);
|
bar_manager_resize(bar_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_manager_set_height(struct bar_manager* bar_manager, uint32_t 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->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->background.padding_right = padding;
|
|
||||||
bar_manager_refresh(bar_manager, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_manager_display_changed(struct bar_manager* bar_manager) {
|
void bar_manager_display_changed(struct bar_manager* bar_manager) {
|
||||||
for (int i = 0; i < bar_manager->bar_count; ++i)
|
for (int i = 0; i < bar_manager->bar_count; ++i)
|
||||||
bar_destroy(bar_manager->bars[i]);
|
bar_destroy(bar_manager->bars[i]);
|
||||||
|
@ -384,6 +354,5 @@ void bar_manager_serialize(struct bar_manager* bar_manager, FILE* rsp) {
|
||||||
if (i < bar_manager->bar_item_count - 1) fprintf(rsp, ",\n");
|
if (i < bar_manager->bar_item_count - 1) fprintf(rsp, ",\n");
|
||||||
else fprintf(rsp, "\n\t]\n}\n");
|
else fprintf(rsp, "\n\t]\n}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,18 +44,12 @@ void bar_manager_serialize(struct bar_manager* bar_manager, FILE* rsp);
|
||||||
void bar_manager_update(struct bar_manager* bar_manager, bool forced);
|
void bar_manager_update(struct bar_manager* bar_manager, bool forced);
|
||||||
void bar_manager_update_space_components(struct bar_manager* bar_manager, bool forced);
|
void bar_manager_update_space_components(struct bar_manager* bar_manager, bool forced);
|
||||||
void bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t radius);
|
void bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t radius);
|
||||||
void bar_manager_set_background_color(struct bar_manager *bar_manager, uint32_t color);
|
|
||||||
void bar_manager_set_position(struct bar_manager *bar_manager, char *pos);
|
void bar_manager_set_position(struct bar_manager *bar_manager, char *pos);
|
||||||
void bar_manager_set_spaces(struct bar_manager *bar_manager, bool value);
|
void bar_manager_set_spaces(struct bar_manager *bar_manager, bool value);
|
||||||
void bar_manager_set_spaces_for_all_displays(struct bar_manager *bar_manager, bool value);
|
void bar_manager_set_spaces_for_all_displays(struct bar_manager *bar_manager, bool value);
|
||||||
void bar_manager_set_height(struct bar_manager *bar_manager, uint32_t height);
|
|
||||||
void bar_manager_set_padding_left(struct bar_manager *bar_manager, uint32_t padding);
|
|
||||||
void bar_manager_set_padding_right(struct bar_manager *bar_manager, uint32_t padding);
|
|
||||||
void bar_manager_set_display(struct bar_manager *bar_manager, char *display);
|
void bar_manager_set_display(struct bar_manager *bar_manager, char *display);
|
||||||
void bar_manager_set_hidden(struct bar_manager *bar_manager, uint32_t sid, bool hidden);
|
void bar_manager_set_hidden(struct bar_manager *bar_manager, uint32_t sid, bool hidden);
|
||||||
void bar_manager_set_topmost(struct bar_manager *bar_manager, bool topmost);
|
void bar_manager_set_topmost(struct bar_manager *bar_manager, bool topmost);
|
||||||
void bar_manager_set_border_width(struct bar_manager* bar_manager, uint32_t width);
|
|
||||||
void bar_manager_set_border_color(struct bar_manager* bar_manager, uint32_t color);
|
|
||||||
void bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smoothing);
|
void bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smoothing);
|
||||||
|
|
||||||
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid);
|
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "alias.h"
|
#include "alias.h"
|
||||||
|
#include "background.h"
|
||||||
#include "bar_item.h"
|
#include "bar_item.h"
|
||||||
#include "bar_manager.h"
|
#include "bar_manager.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
@ -463,11 +464,9 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
|
||||||
bar_item->label.padding_right = token_to_int(get_token(&message));
|
bar_item->label.padding_right = token_to_int(get_token(&message));
|
||||||
needs_update = true;
|
needs_update = true;
|
||||||
} else if (token_equals(property, COMMAND_SET_BACKGROUND_PADDING_LEFT)) {
|
} else if (token_equals(property, COMMAND_SET_BACKGROUND_PADDING_LEFT)) {
|
||||||
bar_item->background.padding_left = token_to_int(get_token(&message));
|
needs_update = background_set_padding_left(&bar_item->background, token_to_int(get_token(&message)));
|
||||||
needs_update = true;
|
|
||||||
} else if (token_equals(property, COMMAND_SET_BACKGROUND_PADDING_RIGHT)) {
|
} else if (token_equals(property, COMMAND_SET_BACKGROUND_PADDING_RIGHT)) {
|
||||||
bar_item->background.padding_right = token_to_int(get_token(&message));
|
needs_update = background_set_padding_right(&bar_item->background, token_to_int(get_token(&message)));
|
||||||
needs_update = true;
|
|
||||||
} else if (token_equals(property, COMMAND_SET_YOFFSET)) {
|
} else if (token_equals(property, COMMAND_SET_YOFFSET)) {
|
||||||
bar_item_set_yoffset(bar_item, token_to_int(get_token(&message)));
|
bar_item_set_yoffset(bar_item, token_to_int(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_CACHE_SCRIPTS)) {
|
} else if (token_equals(property, COMMAND_SET_CACHE_SCRIPTS)) {
|
||||||
|
@ -518,39 +517,34 @@ static void handle_domain_set(FILE* rsp, struct token domain, char* message) {
|
||||||
|
|
||||||
static void handle_domain_bar(FILE *rsp, struct token domain, char *message) {
|
static void handle_domain_bar(FILE *rsp, struct token domain, char *message) {
|
||||||
struct token command = get_token(&message);
|
struct token command = get_token(&message);
|
||||||
|
bool needs_refresh = false;
|
||||||
|
|
||||||
if (token_equals(command, COMMAND_BAR_BACKGROUND)) {
|
if (token_equals(command, COMMAND_BAR_BACKGROUND)) {
|
||||||
struct token value = get_token(&message);
|
needs_refresh = background_set_color(&g_bar_manager.background, token_to_uint32t(get_token(&message)));
|
||||||
uint32_t color = token_to_uint32t(value);
|
|
||||||
bar_manager_set_background_color(&g_bar_manager, color);
|
|
||||||
} else if (token_equals(command, COMMAND_BAR_HEIGHT)) {
|
} else if (token_equals(command, COMMAND_BAR_HEIGHT)) {
|
||||||
struct token token = get_token(&message);
|
needs_refresh = background_set_height(&g_bar_manager.background, atoi(get_token(&message).text));
|
||||||
bar_manager_set_height(&g_bar_manager, atoi(token.text));
|
if (needs_refresh) bar_manager_resize(&g_bar_manager);
|
||||||
} else if (token_equals(command, COMMAND_BAR_BORDER_WIDTH)) {
|
} else if (token_equals(command, COMMAND_BAR_BORDER_WIDTH)) {
|
||||||
struct token token = get_token(&message);
|
needs_refresh = background_set_border_width(&g_bar_manager.background, atoi(get_token(&message).text));
|
||||||
bar_manager_set_border_width(&g_bar_manager, atoi(token.text));
|
|
||||||
} else if (token_equals(command, COMMAND_BAR_BORDER_COLOR)) {
|
} else if (token_equals(command, COMMAND_BAR_BORDER_COLOR)) {
|
||||||
struct token token = get_token(&message);
|
needs_refresh = background_set_border_color(&g_bar_manager.background, token_to_uint32t(get_token(&message)));
|
||||||
uint32_t color = token_to_uint32t(token);
|
|
||||||
bar_manager_set_border_color(&g_bar_manager, color);
|
|
||||||
} else if (token_equals(command, COMMAND_BAR_MARGIN)) {
|
} else if (token_equals(command, COMMAND_BAR_MARGIN)) {
|
||||||
struct token token = get_token(&message);
|
struct token token = get_token(&message);
|
||||||
g_bar_manager.margin = token_to_uint32t(token);
|
g_bar_manager.margin = token_to_uint32t(token);
|
||||||
|
needs_refresh = true;
|
||||||
} else if (token_equals(command, COMMAND_BAR_YOFFSET)) {
|
} else if (token_equals(command, COMMAND_BAR_YOFFSET)) {
|
||||||
struct token token = get_token(&message);
|
struct token token = get_token(&message);
|
||||||
g_bar_manager.y_offset = token_to_uint32t(token);
|
g_bar_manager.y_offset = token_to_uint32t(token);
|
||||||
|
needs_refresh = true;
|
||||||
} else if (token_equals(command, COMMAND_BAR_CORNER_RADIUS)) {
|
} else if (token_equals(command, COMMAND_BAR_CORNER_RADIUS)) {
|
||||||
struct token token = get_token(&message);
|
needs_refresh = background_set_corner_radius(&g_bar_manager.background, token_to_uint32t(get_token(&message)));
|
||||||
g_bar_manager.background.corner_radius = token_to_uint32t(token);
|
|
||||||
} else if (token_equals(command, COMMAND_BAR_BLUR_RADIUS)) {
|
} else if (token_equals(command, COMMAND_BAR_BLUR_RADIUS)) {
|
||||||
struct token token = get_token(&message);
|
struct token token = get_token(&message);
|
||||||
bar_manager_set_background_blur(&g_bar_manager, token_to_uint32t(token));
|
bar_manager_set_background_blur(&g_bar_manager, token_to_uint32t(token));
|
||||||
} else if (token_equals(command, COMMAND_BAR_PADDING_LEFT)) {
|
} else if (token_equals(command, COMMAND_BAR_PADDING_LEFT)) {
|
||||||
struct token token = get_token(&message);
|
needs_refresh = background_set_padding_left(&g_bar_manager.background, atoi(get_token(&message).text));
|
||||||
bar_manager_set_padding_left(&g_bar_manager, atoi(token.text));
|
|
||||||
} else if (token_equals(command, COMMAND_BAR_PADDING_RIGHT)) {
|
} else if (token_equals(command, COMMAND_BAR_PADDING_RIGHT)) {
|
||||||
struct token token = get_token(&message);
|
needs_refresh = background_set_padding_right(&g_bar_manager.background, atoi(get_token(&message).text));
|
||||||
bar_manager_set_padding_right(&g_bar_manager, atoi(token.text));
|
|
||||||
} else if (token_equals(command, COMMAND_BAR_FONT_SMOOTHING)) {
|
} else if (token_equals(command, COMMAND_BAR_FONT_SMOOTHING)) {
|
||||||
struct token state = get_token(&message);
|
struct token state = get_token(&message);
|
||||||
bar_manager_set_font_smoothing(&g_bar_manager, evaluate_boolean_state(state, g_bar_manager.font_smoothing));
|
bar_manager_set_font_smoothing(&g_bar_manager, evaluate_boolean_state(state, g_bar_manager.font_smoothing));
|
||||||
|
@ -594,6 +588,8 @@ static void handle_domain_bar(FILE *rsp, struct token domain, char *message) {
|
||||||
fprintf(rsp, "unknown command '%s' for domain 'bar'\n", command.text);
|
fprintf(rsp, "unknown command '%s' for domain 'bar'\n", command.text);
|
||||||
printf("unknown command '%s' for domain 'bar'\n", command.text);
|
printf("unknown command '%s' for domain 'bar'\n", command.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needs_refresh) bar_manager_refresh(&g_bar_manager, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* reformat_batch_key_value_pair(struct token token) {
|
static char* reformat_batch_key_value_pair(struct token token) {
|
||||||
|
|
Loading…
Reference in a new issue