mirror of
https://github.com/FelixKratz/SketchyBar
synced 2025-02-18 21:48:24 +00:00
bar item refactoring
This commit is contained in:
parent
088bcc618a
commit
5629b88173
11 changed files with 323 additions and 289 deletions
74
src/background.c
Normal file
74
src/background.c
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#include "background.h"
|
||||||
|
#include "misc/helpers.h"
|
||||||
|
|
||||||
|
void background_init(struct background* background) {
|
||||||
|
background->enabled = false;
|
||||||
|
|
||||||
|
background->height = 0;
|
||||||
|
background->border_width = 0;
|
||||||
|
background->padding_left = 0;
|
||||||
|
background->padding_right = 0;
|
||||||
|
background->corner_radius = 0;
|
||||||
|
|
||||||
|
background->color = rgba_color_from_hex(0xff000000);
|
||||||
|
background->border_color = rgba_color_from_hex(0xff000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool background_set_color(struct background* background, uint32_t color) {
|
||||||
|
struct rgba_color target_color = rgba_color_from_hex(color);
|
||||||
|
if (background->color.r == target_color.r
|
||||||
|
&& background->color.g == target_color.g
|
||||||
|
&& background->color.b == target_color.b
|
||||||
|
&& background->color.a == target_color.a) return false;
|
||||||
|
background->color = target_color;
|
||||||
|
background_set_enabled(background, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool background_set_border_color(struct background* background, uint32_t color) {
|
||||||
|
struct rgba_color target_color = rgba_color_from_hex(color);
|
||||||
|
if (background->border_color.r == target_color.r
|
||||||
|
&& background->border_color.g == target_color.g
|
||||||
|
&& background->border_color.b == target_color.b
|
||||||
|
&& background->border_color.a == target_color.a) return false;
|
||||||
|
background->border_color = target_color;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool background_set_enabled(struct background* background, bool enabled) {
|
||||||
|
if (background->enabled == enabled) return false;
|
||||||
|
background->enabled = enabled;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool background_set_height(struct background* background, uint32_t height) {
|
||||||
|
if (background->height == height) return false;
|
||||||
|
background->height = height;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool background_set_border_width(struct background* background, uint32_t border_width) {
|
||||||
|
if (background->border_width == border_width) return false;
|
||||||
|
background->border_width = border_width;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool background_set_corner_radius(struct background* background, uint32_t corner_radius) {
|
||||||
|
if (background->corner_radius == corner_radius) return false;
|
||||||
|
background->corner_radius = corner_radius;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
23
src/background.h
Normal file
23
src/background.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef BACKGROUND_H
|
||||||
|
#define BACKGROUND_H
|
||||||
|
|
||||||
|
struct background {
|
||||||
|
bool enabled;
|
||||||
|
uint32_t height;
|
||||||
|
uint32_t corner_radius;
|
||||||
|
uint32_t border_width;
|
||||||
|
int padding_left;
|
||||||
|
int padding_right;
|
||||||
|
struct rgba_color color;
|
||||||
|
struct rgba_color border_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
void background_init(struct background* background);
|
||||||
|
bool background_set_color(struct background* background, uint32_t color);
|
||||||
|
bool background_set_border_color(struct background* background, uint32_t color);
|
||||||
|
bool background_set_enabled(struct background* background, bool enabled);
|
||||||
|
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_corner_radius(struct background* background, uint32_t corner_radius);
|
||||||
|
|
||||||
|
#endif // !BACKGROUND_H
|
48
src/bar.c
48
src/bar.c
|
@ -132,9 +132,9 @@ static int bar_get_center_length(struct bar_manager* bar_manager) {
|
||||||
for (int i = 0; i < bar_manager->bar_item_count; i++) {
|
for (int i = 0; i < bar_manager->bar_item_count; i++) {
|
||||||
struct bar_item* bar_item = bar_manager->bar_items[i];
|
struct bar_item* bar_item = bar_manager->bar_items[i];
|
||||||
if (bar_item->position == BAR_POSITION_CENTER) {
|
if (bar_item->position == BAR_POSITION_CENTER) {
|
||||||
total_length += bar_item->label_line.bounds.size.width + bar_item->icon_line.bounds.size.width + bar_item->icon_padding_right + bar_item->label_padding_left + (bar_item->has_graph ? bar_item->graph_data.graph_width : 0);
|
total_length += bar_item->label.line.bounds.size.width + bar_item->icon.line.bounds.size.width + bar_item->icon.padding_right + bar_item->label.padding_left + (bar_item->has_graph ? bar_item->graph_data.graph_width : 0);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
total_length += bar_manager->bar_items[i-1]->label_padding_right + bar_item->icon_padding_left;
|
total_length += bar_manager->bar_items[i-1]->label.padding_right + bar_item->icon.padding_left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,12 +147,12 @@ void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_draw_item_background(struct bar* bar, struct bar_item* bar_item, uint32_t adid) {
|
void bar_draw_item_background(struct bar* bar, struct bar_item* bar_item, uint32_t adid) {
|
||||||
if (!bar_item->draws_background) return;
|
if (!bar_item->background.enabled) return;
|
||||||
bool custom_height = bar_item->background_height != 0;
|
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)},
|
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))}};
|
{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))}};
|
||||||
draw_region = CGRectInset(draw_region, bar_item->background_border_width / 2, bar_item->background_border_width / 2);
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_draw_alias(struct bar* bar, struct bar_item* bar_item, uint32_t x) {
|
void bar_draw_alias(struct bar* bar, struct bar_item* bar_item, uint32_t x) {
|
||||||
|
@ -182,21 +182,21 @@ void bar_redraw(struct bar* bar) {
|
||||||
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << adid))) continue;
|
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << adid))) continue;
|
||||||
if (bar_item->associated_space > 0 && !(bar_item->associated_space & (1 << sid)) && (bar_item->type != BAR_COMPONENT_SPACE)) continue;
|
if (bar_item->associated_space > 0 && !(bar_item->associated_space & (1 << sid)) && (bar_item->type != BAR_COMPONENT_SPACE)) continue;
|
||||||
|
|
||||||
struct bar_line* label = &bar_item->label_line;
|
struct bar_line* label = &bar_item->label.line;
|
||||||
struct bar_line* icon = &bar_item->icon_line;
|
struct bar_line* icon = &bar_item->icon.line;
|
||||||
CGPoint icon_position = bar_align_line(bar, icon, ALIGN_CENTER, ALIGN_CENTER);
|
CGPoint icon_position = bar_align_line(bar, icon, ALIGN_CENTER, ALIGN_CENTER);
|
||||||
CGPoint label_position = bar_align_line(bar, label, ALIGN_CENTER, ALIGN_CENTER);
|
CGPoint label_position = bar_align_line(bar, label, ALIGN_CENTER, ALIGN_CENTER);
|
||||||
uint32_t graph_x = 0;
|
uint32_t graph_x = 0;
|
||||||
bool graph_rtl = false;
|
bool graph_rtl = false;
|
||||||
|
|
||||||
if (bar_item->position == BAR_POSITION_LEFT) {
|
if (bar_item->position == BAR_POSITION_LEFT) {
|
||||||
icon_position.x = bar_left_final_item_x + bar_item->icon_padding_left + bar_item->background_padding_left;
|
icon_position.x = bar_left_final_item_x + bar_item->icon.padding_left + bar_item->background.padding_left;
|
||||||
label_position.x = icon_position.x + icon->bounds.size.width + bar_item->icon_padding_right + bar_item->label_padding_left;
|
label_position.x = icon_position.x + icon->bounds.size.width + bar_item->icon.padding_right + bar_item->label.padding_left;
|
||||||
|
|
||||||
if (!bar_item->nospace)
|
if (!bar_item->nospace)
|
||||||
bar_left_final_item_x = label_position.x + label->bounds.size.width + bar_item->label_padding_right + bar_item->background_padding_right;
|
bar_left_final_item_x = label_position.x + label->bounds.size.width + bar_item->label.padding_right + bar_item->background.padding_right;
|
||||||
if (bar_item->has_graph) {
|
if (bar_item->has_graph) {
|
||||||
graph_x = bar_item->nospace ? label_position.x + label->bounds.size.width + bar_item->label_padding_right + bar_item->background_padding_right : bar_left_final_item_x;
|
graph_x = bar_item->nospace ? label_position.x + label->bounds.size.width + bar_item->label.padding_right + bar_item->background.padding_right : bar_left_final_item_x;
|
||||||
if (!bar_item->nospace)
|
if (!bar_item->nospace)
|
||||||
bar_left_final_item_x += bar_item->graph_data.graph_width;
|
bar_left_final_item_x += bar_item->graph_data.graph_width;
|
||||||
}
|
}
|
||||||
|
@ -205,13 +205,13 @@ void bar_redraw(struct bar* bar) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (bar_item->position == BAR_POSITION_RIGHT) {
|
else if (bar_item->position == BAR_POSITION_RIGHT) {
|
||||||
label_position.x = bar_right_first_item_x - label->bounds.size.width - bar_item->label_padding_right - bar_item->background_padding_right;
|
label_position.x = bar_right_first_item_x - label->bounds.size.width - bar_item->label.padding_right - bar_item->background.padding_right;
|
||||||
icon_position.x = label_position.x - icon->bounds.size.width - bar_item->icon_padding_right - bar_item->label_padding_left + 1;
|
icon_position.x = label_position.x - icon->bounds.size.width - bar_item->icon.padding_right - bar_item->label.padding_left + 1;
|
||||||
|
|
||||||
if (!bar_item->nospace)
|
if (!bar_item->nospace)
|
||||||
bar_right_first_item_x = icon_position.x - bar_item->icon_padding_left - bar_item->background_padding_left;
|
bar_right_first_item_x = icon_position.x - bar_item->icon.padding_left - bar_item->background.padding_left;
|
||||||
if (bar_item->has_graph) {
|
if (bar_item->has_graph) {
|
||||||
graph_x = bar_item->nospace ? icon_position.x - bar_item->icon_padding_left - bar_item->background_padding_left : bar_right_first_item_x;
|
graph_x = bar_item->nospace ? icon_position.x - bar_item->icon.padding_left - bar_item->background.padding_left : bar_right_first_item_x;
|
||||||
graph_rtl = true;
|
graph_rtl = true;
|
||||||
if (!bar_item->nospace)
|
if (!bar_item->nospace)
|
||||||
bar_right_first_item_x -= bar_item->graph_data.graph_width;
|
bar_right_first_item_x -= bar_item->graph_data.graph_width;
|
||||||
|
@ -222,13 +222,13 @@ void bar_redraw(struct bar* bar) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (bar_item->position == BAR_POSITION_CENTER) {
|
else if (bar_item->position == BAR_POSITION_CENTER) {
|
||||||
icon_position.x = bar_center_first_item_x + bar_item->icon_padding_left + bar_item->background_padding_left;
|
icon_position.x = bar_center_first_item_x + bar_item->icon.padding_left + bar_item->background.padding_left;
|
||||||
label_position.x = icon_position.x + icon->bounds.size.width + bar_item->icon_padding_right + bar_item->label_padding_left;
|
label_position.x = icon_position.x + icon->bounds.size.width + bar_item->icon.padding_right + bar_item->label.padding_left;
|
||||||
|
|
||||||
if (!bar_item->nospace)
|
if (!bar_item->nospace)
|
||||||
bar_center_first_item_x = label_position.x + label->bounds.size.width + bar_item->label_padding_right + bar_item->background_padding_right;
|
bar_center_first_item_x = label_position.x + label->bounds.size.width + bar_item->label.padding_right + bar_item->background.padding_right;
|
||||||
if (bar_item->has_graph) {
|
if (bar_item->has_graph) {
|
||||||
graph_x = bar_item->nospace ? label_position.x + label->bounds.size.width + bar_item->label_padding_right + bar_item->background_padding_right : bar_center_first_item_x;
|
graph_x = bar_item->nospace ? label_position.x + label->bounds.size.width + bar_item->label.padding_right + bar_item->background.padding_right : bar_center_first_item_x;
|
||||||
if (!bar_item->nospace)
|
if (!bar_item->nospace)
|
||||||
bar_center_first_item_x += bar_item->graph_data.graph_width;
|
bar_center_first_item_x += bar_item->graph_data.graph_width;
|
||||||
}
|
}
|
||||||
|
@ -236,8 +236,8 @@ void bar_redraw(struct bar* bar) {
|
||||||
bar_center_first_item_x += bar_item->alias.bounds.size.width;
|
bar_center_first_item_x += bar_item->alias.bounds.size.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bar_item->label_line.bounds.origin = label_position;
|
bar_item->label.line.bounds.origin = label_position;
|
||||||
bar_item->icon_line.bounds.origin = icon_position;
|
bar_item->icon.line.bounds.origin = icon_position;
|
||||||
bar_item_append_associated_bar(bar_item, (1 << (adid - 1)));
|
bar_item_append_associated_bar(bar_item, (1 << (adid - 1)));
|
||||||
bar_item_set_bounding_rect_for_display(bar_item, adid, bar->origin);
|
bar_item_set_bounding_rect_for_display(bar_item, adid, bar->origin);
|
||||||
|
|
||||||
|
|
245
src/bar_item.c
245
src/bar_item.c
|
@ -15,24 +15,23 @@ void bar_item_inherit_from_item(struct bar_item* bar_item, struct bar_item* ance
|
||||||
bar_item->lazy = ancestor->lazy;
|
bar_item->lazy = ancestor->lazy;
|
||||||
bar_item->updates = ancestor->updates;
|
bar_item->updates = ancestor->updates;
|
||||||
bar_item->drawing = ancestor->drawing;
|
bar_item->drawing = ancestor->drawing;
|
||||||
bar_item->icon_color = ancestor->icon_color;
|
|
||||||
bar_item->icon_font_name = ancestor->icon_font_name;
|
text_destroy(&bar_item->icon);
|
||||||
bar_item->label_color = ancestor->label_color;
|
text_destroy(&bar_item->label);
|
||||||
bar_item->label_font_name = ancestor->label_font_name;
|
|
||||||
bar_item->icon_padding_left = ancestor->icon_padding_left;
|
bar_item->icon = ancestor->icon;
|
||||||
bar_item->icon_padding_right = ancestor->icon_padding_right;
|
bar_item->label = ancestor->label;
|
||||||
bar_item->label_padding_left = ancestor->label_padding_left;
|
text_clear_pointers(&bar_item->icon);
|
||||||
bar_item->label_padding_right = ancestor->label_padding_right;
|
text_clear_pointers(&bar_item->label);
|
||||||
|
text_set_font(&bar_item->icon, string_copy(ancestor->icon.font_name), true);
|
||||||
|
text_set_font(&bar_item->label, string_copy(ancestor->label.font_name), true);
|
||||||
|
text_set_string(&bar_item->icon, string_copy(ancestor->icon.string), true);
|
||||||
|
text_set_string(&bar_item->label, string_copy(ancestor->label.string), true);
|
||||||
|
|
||||||
bar_item->update_frequency = ancestor->update_frequency;
|
bar_item->update_frequency = ancestor->update_frequency;
|
||||||
bar_item->cache_scripts = ancestor->cache_scripts;
|
bar_item->cache_scripts = ancestor->cache_scripts;
|
||||||
bar_item->icon_highlight_color = ancestor->icon_highlight_color;
|
|
||||||
bar_item->label_highlight_color = ancestor->label_highlight_color;
|
bar_item->background = ancestor->background;
|
||||||
bar_item->background_color = ancestor->background_color;
|
|
||||||
bar_item->draws_background = ancestor->draws_background;
|
|
||||||
bar_item->background_height = ancestor->background_height;
|
|
||||||
bar_item->background_corner_radius = ancestor->background_corner_radius;
|
|
||||||
bar_item->background_border_color = ancestor->background_border_color;
|
|
||||||
bar_item->background_border_width = ancestor->background_border_width;
|
|
||||||
bar_item->y_offset = ancestor->y_offset;
|
bar_item->y_offset = ancestor->y_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,41 +53,20 @@ void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) {
|
||||||
bar_item->associated_display = 0;
|
bar_item->associated_display = 0;
|
||||||
bar_item->associated_space = 0;
|
bar_item->associated_space = 0;
|
||||||
bar_item->associated_bar = 0;
|
bar_item->associated_bar = 0;
|
||||||
bar_item->icon_font_name = "Hack Nerd Font:Bold:14.0";
|
|
||||||
bar_item->label_font_name = "Hack Nerd Font:Bold:14.0";
|
|
||||||
bar_item->icon_highlight = false;
|
|
||||||
bar_item->icon = "";
|
|
||||||
bar_item->icon_padding_left = 0;
|
|
||||||
bar_item->icon_padding_right = 0;
|
|
||||||
bar_item->icon_color = rgba_color_from_hex(0xffffffff);
|
|
||||||
bar_item->icon_highlight_color = rgba_color_from_hex(0xffffffff);
|
|
||||||
bar_item->label_highlight = false;
|
|
||||||
bar_item->label = "";
|
|
||||||
bar_item->label_padding_left = 0;
|
|
||||||
bar_item->label_padding_right = 0;
|
|
||||||
bar_item->label_color = rgba_color_from_hex(0xffffffff);
|
|
||||||
bar_item->label_highlight_color = rgba_color_from_hex(0xffffffff);
|
|
||||||
bar_item->has_graph = false;
|
|
||||||
bar_item->num_rects = 0;
|
|
||||||
bar_item->draws_background = false;
|
|
||||||
bar_item->background_color = rgba_color_from_hex(0x44ff0000);
|
|
||||||
bar_item->background_border_color = rgba_color_from_hex(0x44ff0000);
|
|
||||||
bar_item->background_height = 0;
|
|
||||||
bar_item->background_corner_radius = 0;
|
|
||||||
bar_item->background_border_width = 0;
|
|
||||||
bar_item->background_padding_left = 0;
|
|
||||||
bar_item->background_padding_right = 0;
|
|
||||||
bar_item->y_offset = 0;
|
bar_item->y_offset = 0;
|
||||||
|
bar_item->num_rects = 0;
|
||||||
bar_item->bounding_rects = NULL;
|
bar_item->bounding_rects = NULL;
|
||||||
|
|
||||||
bar_item->has_alias = false;
|
bar_item->has_alias = false;
|
||||||
|
bar_item->has_graph = false;
|
||||||
|
|
||||||
|
text_init(&bar_item->icon);
|
||||||
|
text_init(&bar_item->label);
|
||||||
|
background_init(&bar_item->background);
|
||||||
|
|
||||||
if (default_item) bar_item_inherit_from_item(bar_item, default_item);
|
if (default_item) bar_item_inherit_from_item(bar_item, default_item);
|
||||||
|
|
||||||
bar_item_set_icon(bar_item, string_copy(""), false);
|
|
||||||
bar_item_set_icon_font(bar_item, string_copy(bar_item->icon_font_name), true);
|
|
||||||
bar_item_set_label_font(bar_item, string_copy(bar_item->label_font_name), true);
|
|
||||||
bar_item_set_label(bar_item, string_copy(""), false);
|
|
||||||
|
|
||||||
strncpy(&bar_item->signal_args.name[0][0], "NAME", 255);
|
strncpy(&bar_item->signal_args.name[0][0], "NAME", 255);
|
||||||
strncpy(&bar_item->signal_args.name[1][0], "SELECTED", 255);
|
strncpy(&bar_item->signal_args.name[1][0], "SELECTED", 255);
|
||||||
strncpy(&bar_item->signal_args.value[1][0], "false", 255);
|
strncpy(&bar_item->signal_args.value[1][0], "false", 255);
|
||||||
|
@ -199,77 +177,6 @@ void bar_item_set_click_script(struct bar_item* bar_item, char* script) {
|
||||||
else bar_item->click_script = script;
|
else bar_item->click_script = script;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_item_set_icon(struct bar_item* bar_item, char* icon, bool forced) {
|
|
||||||
if (!icon) return;
|
|
||||||
if (!forced && bar_item->icon && strcmp(bar_item->icon, icon) == 0) { free(icon); return; }
|
|
||||||
if (bar_item->icon_line.line) bar_destroy_line(&bar_item->icon_line);
|
|
||||||
if (icon != bar_item->icon && !bar_item->icon) free(bar_item->icon);
|
|
||||||
bar_item->icon = icon;
|
|
||||||
bar_prepare_line(&bar_item->icon_line, bar_item->icon_font, bar_item->icon, bar_item->icon_highlight ? bar_item->icon_highlight_color : bar_item->icon_color);
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_update_icon_color(struct bar_item *bar_item) {
|
|
||||||
struct rgba_color target_color = bar_item->icon_highlight ? bar_item->icon_highlight_color : bar_item->icon_color;
|
|
||||||
if (bar_item->icon_line.color.r == target_color.r
|
|
||||||
&& bar_item->icon_line.color.g == target_color.g
|
|
||||||
&& bar_item->icon_line.color.b == target_color.b
|
|
||||||
&& bar_item->icon_line.color.a == target_color.a) return;
|
|
||||||
bar_item->icon_line.color = target_color;
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_icon_color(struct bar_item* bar_item, uint32_t color) {
|
|
||||||
bar_item->icon_color = rgba_color_from_hex(color);
|
|
||||||
bar_item_update_icon_color(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_label(struct bar_item* bar_item, char* label, bool forced) {
|
|
||||||
if (!label) return;
|
|
||||||
if (!forced && bar_item->label && strcmp(bar_item->label, label) == 0) { free(label); return; }
|
|
||||||
if (bar_item->label_line.line) bar_destroy_line(&bar_item->label_line);
|
|
||||||
if (label != bar_item->label && !bar_item->label) free(bar_item->label);
|
|
||||||
bar_item->label = label;
|
|
||||||
bar_prepare_line(&bar_item->label_line, bar_item->label_font, bar_item->label, bar_item->label_highlight ? bar_item->label_highlight_color : bar_item->label_color);
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bar_item_set_label_color(struct bar_item* bar_item, uint32_t color) {
|
|
||||||
bar_item->label_color = rgba_color_from_hex(color);
|
|
||||||
bar_item_update_label_color(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_update_label_color(struct bar_item *bar_item) {
|
|
||||||
struct rgba_color target_color = bar_item->label_highlight ? bar_item->label_highlight_color : bar_item->label_color;
|
|
||||||
if (bar_item->label_line.color.r == target_color.r
|
|
||||||
&& bar_item->label_line.color.g == target_color.g
|
|
||||||
&& bar_item->label_line.color.b == target_color.b
|
|
||||||
&& bar_item->label_line.color.a == target_color.a) return;
|
|
||||||
bar_item->label_line.color = target_color;
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_icon_font(struct bar_item* bar_item, char *font_string, bool forced) {
|
|
||||||
if (!font_string) return;
|
|
||||||
if (!forced && bar_item->icon_font_name && strcmp(bar_item->icon_font_name, font_string) == 0) { free(font_string); return; }
|
|
||||||
if (bar_item->icon_font) CFRelease(bar_item->icon_font);
|
|
||||||
|
|
||||||
bar_item->icon_font = bar_create_font(font_string);
|
|
||||||
bar_item->icon_font_name = font_string;
|
|
||||||
bar_item_set_icon(bar_item, bar_item->icon, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_label_font(struct bar_item* bar_item, char *font_string, bool forced) {
|
|
||||||
if (!font_string) return;
|
|
||||||
if (!forced && bar_item->label_font_name && strcmp(bar_item->label_font_name, font_string) == 0) { free(font_string); return; }
|
|
||||||
if (bar_item->label_font) CFRelease(bar_item->label_font);
|
|
||||||
|
|
||||||
bar_item->label_font = bar_create_font(font_string);
|
|
||||||
bar_item->label_font_name = font_string;
|
|
||||||
bar_item_set_label(bar_item, bar_item->label, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_drawing(struct bar_item* bar_item, bool state) {
|
void bar_item_set_drawing(struct bar_item* bar_item, bool state) {
|
||||||
if (bar_item->drawing == state) return;
|
if (bar_item->drawing == state) return;
|
||||||
bar_item->drawing = state;
|
bar_item->drawing = state;
|
||||||
|
@ -282,51 +189,6 @@ void bar_item_on_click(struct bar_item* bar_item) {
|
||||||
fork_exec(bar_item->click_script, &bar_item->signal_args);
|
fork_exec(bar_item->click_script, &bar_item->signal_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_item_set_background_color(struct bar_item* bar_item, uint32_t color) {
|
|
||||||
struct rgba_color target_color = rgba_color_from_hex(color);
|
|
||||||
if (bar_item->background_color.r == target_color.r
|
|
||||||
&& bar_item->background_color.g == target_color.g
|
|
||||||
&& bar_item->background_color.b == target_color.b
|
|
||||||
&& bar_item->background_color.a == target_color.a) return;
|
|
||||||
bar_item->background_color = target_color;
|
|
||||||
bar_item_set_draws_background(bar_item, true);
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_background_border_color(struct bar_item* bar_item, uint32_t color) {
|
|
||||||
struct rgba_color target_color = rgba_color_from_hex(color);
|
|
||||||
if (bar_item->background_border_color.r == target_color.r
|
|
||||||
&& bar_item->background_border_color.g == target_color.g
|
|
||||||
&& bar_item->background_border_color.b == target_color.b
|
|
||||||
&& bar_item->background_border_color.a == target_color.a) return;
|
|
||||||
bar_item->background_border_color = target_color;
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_draws_background(struct bar_item* bar_item, bool enabled) {
|
|
||||||
if (bar_item->draws_background == enabled) return;
|
|
||||||
bar_item->draws_background = enabled;
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_background_height(struct bar_item* bar_item, uint32_t height) {
|
|
||||||
if (bar_item->background_height == height) return;
|
|
||||||
bar_item->background_height = height;
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_background_border_width(struct bar_item* bar_item, uint32_t border_width) {
|
|
||||||
if (bar_item->background_border_width == border_width) return;
|
|
||||||
bar_item->background_border_width = border_width;
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_background_corner_radius(struct bar_item* bar_item, uint32_t corner_radius) {
|
|
||||||
if (bar_item->background_corner_radius == corner_radius) return;
|
|
||||||
bar_item->background_corner_radius = corner_radius;
|
|
||||||
bar_item_needs_update(bar_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar_item_set_yoffset(struct bar_item* bar_item, int offset) {
|
void bar_item_set_yoffset(struct bar_item* bar_item, int offset) {
|
||||||
if (bar_item->y_offset == offset) return;
|
if (bar_item->y_offset == offset) return;
|
||||||
bar_item->y_offset = offset;
|
bar_item->y_offset = offset;
|
||||||
|
@ -335,13 +197,13 @@ void bar_item_set_yoffset(struct bar_item* bar_item, int offset) {
|
||||||
|
|
||||||
CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) {
|
CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) {
|
||||||
CGRect bounding_rect;
|
CGRect bounding_rect;
|
||||||
bounding_rect.origin = bar_item->icon_line.bounds.origin;
|
bounding_rect.origin = bar_item->icon.line.bounds.origin;
|
||||||
bounding_rect.origin.x -= bar_item->icon_padding_left;
|
bounding_rect.origin.x -= bar_item->icon.padding_left;
|
||||||
bounding_rect.origin.y = bar_item->icon_line.bounds.origin.y < bar_item->label_line.bounds.origin.y ? bar_item->icon_line.bounds.origin.y : bar_item->label_line.bounds.origin.y;
|
bounding_rect.origin.y = bar_item->icon.line.bounds.origin.y < bar_item->label.line.bounds.origin.y ? bar_item->icon.line.bounds.origin.y : bar_item->label.line.bounds.origin.y;
|
||||||
bounding_rect.size.width = bar_item->label_line.bounds.size.width + bar_item->icon_line.bounds.size.width
|
bounding_rect.size.width = bar_item->label.line.bounds.size.width + bar_item->icon.line.bounds.size.width
|
||||||
+ bar_item->icon_padding_left + bar_item->icon_padding_right
|
+ bar_item->icon.padding_left + bar_item->icon.padding_right
|
||||||
+ bar_item->label_padding_right + bar_item->label_padding_left;
|
+ bar_item->label.padding_right + bar_item->label.padding_left;
|
||||||
bounding_rect.size.height = bar_item->label_line.bounds.size.height > bar_item->icon_line.bounds.size.height ? bar_item->label_line.bounds.size.height : bar_item->icon_line.bounds.size.height;
|
bounding_rect.size.height = bar_item->label.line.bounds.size.height > bar_item->icon.line.bounds.size.height ? bar_item->label.line.bounds.size.height : bar_item->icon.line.bounds.size.height;
|
||||||
return bounding_rect;
|
return bounding_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,10 +227,9 @@ void bar_item_destroy(struct bar_item* bar_item) {
|
||||||
if (bar_item->name) free(bar_item->name);
|
if (bar_item->name) free(bar_item->name);
|
||||||
if (bar_item->script && !bar_item->cache_scripts) free(bar_item->script);
|
if (bar_item->script && !bar_item->cache_scripts) free(bar_item->script);
|
||||||
if (bar_item->click_script && !bar_item->cache_scripts) free(bar_item->click_script);
|
if (bar_item->click_script && !bar_item->cache_scripts) free(bar_item->click_script);
|
||||||
if (bar_item->icon) free(bar_item->icon);
|
|
||||||
if (bar_item->icon_font_name) free(bar_item->icon_font_name);
|
text_destroy(&bar_item->icon);
|
||||||
if (bar_item->label) free(bar_item->label);
|
text_destroy(&bar_item->label);
|
||||||
if (bar_item->label_font_name) free(bar_item->label_font_name);
|
|
||||||
|
|
||||||
if (bar_item->bounding_rects) {
|
if (bar_item->bounding_rects) {
|
||||||
for (int j = 0; j < bar_item->num_rects; j++) {
|
for (int j = 0; j < bar_item->num_rects; j++) {
|
||||||
|
@ -427,28 +288,28 @@ void bar_item_serialize(struct bar_item* bar_item, FILE* rsp) {
|
||||||
"\t\"bounding_rects\": {\n",
|
"\t\"bounding_rects\": {\n",
|
||||||
bar_item->name,
|
bar_item->name,
|
||||||
bar_item->type,
|
bar_item->type,
|
||||||
bar_item->icon,
|
bar_item->icon.string,
|
||||||
bar_item->label,
|
bar_item->label.string,
|
||||||
bar_item->icon_font_name,
|
bar_item->icon.font_name,
|
||||||
bar_item->label_font_name,
|
bar_item->label.font_name,
|
||||||
bar_item->position,
|
bar_item->position,
|
||||||
bar_item->nospace,
|
bar_item->nospace,
|
||||||
bar_item->background_padding_left,
|
bar_item->background.padding_left,
|
||||||
bar_item->background_padding_right,
|
bar_item->background.padding_right,
|
||||||
bar_item->icon_padding_left,
|
bar_item->icon.padding_left,
|
||||||
bar_item->icon_padding_right,
|
bar_item->icon.padding_right,
|
||||||
bar_item->label_padding_left,
|
bar_item->label.padding_left,
|
||||||
bar_item->label_padding_right,
|
bar_item->label.padding_right,
|
||||||
hex_from_rgba_color(bar_item->icon_color),
|
hex_from_rgba_color(bar_item->icon.color),
|
||||||
hex_from_rgba_color(bar_item->icon_highlight_color),
|
hex_from_rgba_color(bar_item->icon.highlight_color),
|
||||||
hex_from_rgba_color(bar_item->label_color),
|
hex_from_rgba_color(bar_item->label.color),
|
||||||
hex_from_rgba_color(bar_item->label_highlight_color),
|
hex_from_rgba_color(bar_item->label.highlight_color),
|
||||||
bar_item->draws_background,
|
bar_item->background.enabled,
|
||||||
bar_item->background_height,
|
bar_item->background.height,
|
||||||
bar_item->background_corner_radius,
|
bar_item->background.corner_radius,
|
||||||
bar_item->background_border_width,
|
bar_item->background.border_width,
|
||||||
hex_from_rgba_color(bar_item->background_color),
|
hex_from_rgba_color(bar_item->background.color),
|
||||||
hex_from_rgba_color(bar_item->background_border_color),
|
hex_from_rgba_color(bar_item->background.border_color),
|
||||||
bar_item->drawing,
|
bar_item->drawing,
|
||||||
bar_item->updates,
|
bar_item->updates,
|
||||||
bar_item->lazy,
|
bar_item->lazy,
|
||||||
|
|
|
@ -44,36 +44,13 @@ struct bar_item {
|
||||||
int y_offset;
|
int y_offset;
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
bool draws_background;
|
struct background background;
|
||||||
uint32_t background_height;
|
|
||||||
uint32_t background_corner_radius;
|
|
||||||
uint32_t background_border_width;
|
|
||||||
int background_padding_left;
|
|
||||||
int background_padding_right;
|
|
||||||
struct rgba_color background_color;
|
|
||||||
struct rgba_color background_border_color;
|
|
||||||
|
|
||||||
// Icon properties
|
// Icon properties
|
||||||
bool icon_highlight;
|
struct text icon;
|
||||||
struct bar_line icon_line;
|
|
||||||
char* icon;
|
|
||||||
char* icon_font_name;
|
|
||||||
CTFontRef icon_font;
|
|
||||||
int icon_padding_left;
|
|
||||||
int icon_padding_right;
|
|
||||||
struct rgba_color icon_color;
|
|
||||||
struct rgba_color icon_highlight_color;
|
|
||||||
|
|
||||||
// Label properties
|
// Label properties
|
||||||
bool label_highlight;
|
struct text label;
|
||||||
struct bar_line label_line;
|
|
||||||
char* label;
|
|
||||||
char* label_font_name;
|
|
||||||
CTFontRef label_font;
|
|
||||||
int label_padding_left;
|
|
||||||
int label_padding_right;
|
|
||||||
struct rgba_color label_color;
|
|
||||||
struct rgba_color label_highlight_color;
|
|
||||||
|
|
||||||
// Graph Data
|
// Graph Data
|
||||||
bool has_graph;
|
bool has_graph;
|
||||||
|
@ -109,21 +86,7 @@ void bar_item_set_name(struct bar_item* bar_item, char* name);
|
||||||
void bar_item_set_type(struct bar_item* bar_item, char type);
|
void bar_item_set_type(struct bar_item* bar_item, char type);
|
||||||
void bar_item_set_script(struct bar_item* bar_item, char* script);
|
void bar_item_set_script(struct bar_item* bar_item, char* script);
|
||||||
void bar_item_set_click_script(struct bar_item* bar_item, char* script);
|
void bar_item_set_click_script(struct bar_item* bar_item, char* script);
|
||||||
void bar_item_set_icon(struct bar_item* bar_item, char* icon, bool forced);
|
|
||||||
void bar_item_set_icon_color(struct bar_item* bar_item, uint32_t color);
|
|
||||||
void bar_item_update_icon_color(struct bar_item* bar_item);
|
|
||||||
void bar_item_set_label(struct bar_item* bar_item, char* label, bool forced);
|
|
||||||
void bar_item_set_label_color(struct bar_item* bar_item, uint32_t color);
|
|
||||||
void bar_item_update_label_color(struct bar_item* bar_item);
|
|
||||||
void bar_item_set_label_font(struct bar_item* bar_item, char *font_string, bool forced);
|
|
||||||
void bar_item_set_icon_font(struct bar_item* bar_item, char *font_string, bool forced);
|
|
||||||
void bar_item_set_drawing(struct bar_item* bar_item, bool state);
|
void bar_item_set_drawing(struct bar_item* bar_item, bool state);
|
||||||
void bar_item_set_background_color(struct bar_item* bar_item, uint32_t color);
|
|
||||||
void bar_item_set_background_border_color(struct bar_item* bar_item, uint32_t color);
|
|
||||||
void bar_item_set_draws_background(struct bar_item* bar_item, bool enabled);
|
|
||||||
void bar_item_set_background_height(struct bar_item* bar_item, uint32_t height);
|
|
||||||
void bar_item_set_background_corner_radius(struct bar_item* bar_item, uint32_t corner_radius);
|
|
||||||
void bar_item_set_background_border_width(struct bar_item* bar_item, uint32_t border_width);
|
|
||||||
void bar_item_set_yoffset(struct bar_item* bar_item, int offset);
|
void bar_item_set_yoffset(struct bar_item* bar_item, int offset);
|
||||||
void bar_item_needs_update(struct bar_item* bar_item);
|
void bar_item_needs_update(struct bar_item* bar_item);
|
||||||
void bar_item_clear_needs_update(struct bar_item* bar_item);
|
void bar_item_clear_needs_update(struct bar_item* bar_item);
|
||||||
|
|
|
@ -89,7 +89,6 @@ struct event {
|
||||||
void *context;
|
void *context;
|
||||||
volatile uint32_t *info;
|
volatile uint32_t *info;
|
||||||
enum event_type type;
|
enum event_type type;
|
||||||
int param;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct event *event_create(struct event_loop *event_loop, enum event_type type, void *context);
|
struct event *event_create(struct event_loop *event_loop, enum event_type type, void *context);
|
||||||
|
|
11
src/group.h
Normal file
11
src/group.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef GROUP_H_
|
||||||
|
#define GROUP_H_
|
||||||
|
|
||||||
|
struct group {
|
||||||
|
char* name;
|
||||||
|
|
||||||
|
// Background
|
||||||
|
struct rgba_color background_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -24,7 +24,9 @@
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
#include "background.h"
|
||||||
#include "bar.h"
|
#include "bar.h"
|
||||||
|
#include "text.h"
|
||||||
#include "graph_data.h"
|
#include "graph_data.h"
|
||||||
#include "alias.h"
|
#include "alias.h"
|
||||||
#include "bar_item.h"
|
#include "bar_item.h"
|
||||||
|
@ -37,7 +39,9 @@
|
||||||
#include "workspace.m"
|
#include "workspace.m"
|
||||||
#include "message.c"
|
#include "message.c"
|
||||||
#include "display.c"
|
#include "display.c"
|
||||||
|
#include "background.c"
|
||||||
#include "bar.c"
|
#include "bar.c"
|
||||||
|
#include "text.c"
|
||||||
#include "graph_data.c"
|
#include "graph_data.c"
|
||||||
#include "alias.c"
|
#include "alias.c"
|
||||||
#include "bar_item.c"
|
#include "bar_item.c"
|
||||||
|
|
|
@ -364,38 +364,40 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* bar_item, char* message) {
|
static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* bar_item, char* message) {
|
||||||
|
bool needs_update = false;
|
||||||
struct token property = get_token(&message);
|
struct token property = get_token(&message);
|
||||||
|
|
||||||
if (token_equals(property, COMMAND_SET_ICON)) {
|
if (token_equals(property, COMMAND_SET_ICON)) {
|
||||||
bar_item_set_icon(bar_item, string_copy(message), false);
|
printf("Message: %s \n", message);
|
||||||
|
needs_update = text_set_string(&bar_item->icon, token_to_string(get_token(&message)), false);
|
||||||
} else if (token_equals(property, COMMAND_SET_LABEL)) {
|
} else if (token_equals(property, COMMAND_SET_LABEL)) {
|
||||||
bar_item_set_label(bar_item, string_copy(message), false);
|
needs_update = text_set_string(&bar_item->label, token_to_string(get_token(&message)), false);
|
||||||
} else if (token_equals(property, COMMAND_SET_LABEL_COLOR)) {
|
} else if (token_equals(property, COMMAND_SET_LABEL_COLOR)) {
|
||||||
bar_item_set_label_color(bar_item, token_to_uint32t(get_token(&message)));
|
needs_update = text_set_color(&bar_item->label, token_to_uint32t(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_ICON_COLOR)) {
|
} else if (token_equals(property, COMMAND_SET_ICON_COLOR)) {
|
||||||
bar_item_set_icon_color(bar_item, token_to_uint32t(get_token(&message)));
|
needs_update = text_set_color(&bar_item->icon, token_to_uint32t(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_SCRIPTING) || token_equals(property, COMMAND_SET_UPDATES)) {
|
} else if (token_equals(property, COMMAND_SET_SCRIPTING) || token_equals(property, COMMAND_SET_UPDATES)) {
|
||||||
bar_item->updates = evaluate_boolean_state(get_token(&message), bar_item->updates);
|
bar_item->updates = evaluate_boolean_state(get_token(&message), bar_item->updates);
|
||||||
} else if (token_equals(property, COMMAND_SET_DRAWING)) {
|
} else if (token_equals(property, COMMAND_SET_DRAWING)) {
|
||||||
bar_item_set_drawing(bar_item, evaluate_boolean_state(get_token(&message), bar_item->drawing));
|
bar_item_set_drawing(bar_item, evaluate_boolean_state(get_token(&message), bar_item->drawing));
|
||||||
} else if (token_equals(property, COMMAND_SET_LABEL_HIGHLIGHT)) {
|
} else if (token_equals(property, COMMAND_SET_LABEL_HIGHLIGHT)) {
|
||||||
bar_item->label_highlight = evaluate_boolean_state(get_token(&message), bar_item->label_highlight);
|
bar_item->label.highlight = evaluate_boolean_state(get_token(&message), bar_item->label.highlight);
|
||||||
bar_item_update_label_color(bar_item);
|
needs_update = text_update_color(&bar_item->label);
|
||||||
} else if (token_equals(property, COMMAND_SET_ICON_HIGHLIGHT)) {
|
} else if (token_equals(property, COMMAND_SET_ICON_HIGHLIGHT)) {
|
||||||
bar_item->icon_highlight = evaluate_boolean_state(get_token(&message), bar_item->icon_highlight);
|
bar_item->icon.highlight = evaluate_boolean_state(get_token(&message), bar_item->icon.highlight);
|
||||||
bar_item_update_icon_color(bar_item);
|
needs_update = text_update_color(&bar_item->icon);
|
||||||
} else if (token_equals(property, COMMAND_SET_DRAWS_BACKGROUND)) {
|
} else if (token_equals(property, COMMAND_SET_DRAWS_BACKGROUND)) {
|
||||||
bar_item_set_draws_background(bar_item, evaluate_boolean_state(get_token(&message), bar_item->draws_background));
|
needs_update = background_set_enabled(&bar_item->background, evaluate_boolean_state(get_token(&message), bar_item->background.enabled));
|
||||||
} else if (token_equals(property, COMMAND_SET_BACKGROUND_HEIGHT)) {
|
} else if (token_equals(property, COMMAND_SET_BACKGROUND_HEIGHT)) {
|
||||||
bar_item_set_background_height(bar_item, token_to_uint32t(get_token(&message)));
|
needs_update = background_set_height(&bar_item->background, token_to_uint32t(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_BACKGROUND_CORNER_RADIUS)) {
|
} else if (token_equals(property, COMMAND_SET_BACKGROUND_CORNER_RADIUS)) {
|
||||||
bar_item_set_background_corner_radius(bar_item, token_to_uint32t(get_token(&message)));
|
needs_update = background_set_corner_radius(&bar_item->background, token_to_uint32t(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_BACKGROUND_BORDER_WIDTH)) {
|
} else if (token_equals(property, COMMAND_SET_BACKGROUND_BORDER_WIDTH)) {
|
||||||
bar_item_set_background_border_width(bar_item, token_to_uint32t(get_token(&message)));
|
needs_update = background_set_border_width(&bar_item->background, token_to_uint32t(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_ICON_FONT)) {
|
} else if (token_equals(property, COMMAND_SET_ICON_FONT)) {
|
||||||
bar_item_set_icon_font(bar_item, string_copy(message), false);
|
needs_update = text_set_font(&bar_item->icon, string_copy(message), false);
|
||||||
} else if (token_equals(property, COMMAND_SET_LABEL_FONT)) {
|
} else if (token_equals(property, COMMAND_SET_LABEL_FONT)) {
|
||||||
bar_item_set_label_font(bar_item, string_copy(message), false);
|
needs_update = text_set_font(&bar_item->label, string_copy(message), false);
|
||||||
} else if (token_equals(property, COMMAND_SET_SCRIPT)) {
|
} else if (token_equals(property, COMMAND_SET_SCRIPT)) {
|
||||||
bar_item_set_script(bar_item, string_copy(message));
|
bar_item_set_script(bar_item, string_copy(message));
|
||||||
} else if (token_equals(property, COMMAND_SET_CLICK_SCRIPT)) {
|
} else if (token_equals(property, COMMAND_SET_CLICK_SCRIPT)) {
|
||||||
|
@ -408,18 +410,20 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
|
||||||
} else if (token_equals(property, COMMAND_SET_GRAPH_FILL_COLOR)) {
|
} else if (token_equals(property, COMMAND_SET_GRAPH_FILL_COLOR)) {
|
||||||
bar_item->graph_data.fill_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
bar_item->graph_data.fill_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
||||||
bar_item->graph_data.overrides_fill_color = true;
|
bar_item->graph_data.overrides_fill_color = true;
|
||||||
bar_item_needs_update(bar_item);
|
needs_update = true;
|
||||||
} else if (token_equals(property, COMMAND_SET_GRAPH_LINE_WIDTH)) {
|
} else if (token_equals(property, COMMAND_SET_GRAPH_LINE_WIDTH)) {
|
||||||
bar_item->graph_data.line_width = token_to_float(get_token(&message));
|
bar_item->graph_data.line_width = token_to_float(get_token(&message));
|
||||||
bar_item_needs_update(bar_item);
|
needs_update = true;
|
||||||
} else if (token_equals(property, COMMAND_SET_BACKGROUND_COLOR)) {
|
} else if (token_equals(property, COMMAND_SET_BACKGROUND_COLOR)) {
|
||||||
bar_item_set_background_color(bar_item, token_to_uint32t(get_token(&message)));
|
needs_update = background_set_color(&bar_item->background, token_to_uint32t(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_BACKGROUND_BORDER_COLOR)) {
|
} else if (token_equals(property, COMMAND_SET_BACKGROUND_BORDER_COLOR)) {
|
||||||
bar_item_set_background_border_color(bar_item, token_to_uint32t(get_token(&message)));
|
needs_update = background_set_border_color(&bar_item->background, token_to_uint32t(get_token(&message)));
|
||||||
} else if (token_equals(property, COMMAND_SET_ICON_HIGHLIGHT_COLOR)) {
|
} else if (token_equals(property, COMMAND_SET_ICON_HIGHLIGHT_COLOR)) {
|
||||||
bar_item->icon_highlight_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
bar_item->icon.highlight_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
||||||
|
needs_update = text_update_color(&bar_item->icon);
|
||||||
} else if (token_equals(property, COMMAND_SET_LABEL_HIGHLIGHT_COLOR)) {
|
} else if (token_equals(property, COMMAND_SET_LABEL_HIGHLIGHT_COLOR)) {
|
||||||
bar_item->label_highlight_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
bar_item->label.highlight_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
||||||
|
needs_update = text_update_color(&bar_item->label);
|
||||||
} else if (token_equals(property, COMMAND_SET_POSITION)) {
|
} else if (token_equals(property, COMMAND_SET_POSITION)) {
|
||||||
bar_item->position = get_token(&message).text[0];
|
bar_item->position = get_token(&message).text[0];
|
||||||
} else if (token_equals(property, COMMAND_SET_ASSOCIATED_SPACE)) {
|
} else if (token_equals(property, COMMAND_SET_ASSOCIATED_SPACE)) {
|
||||||
|
@ -437,23 +441,23 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
|
||||||
bar_item_append_associated_display(bar_item, 1 << strtoul(&token.text[sep + 1], NULL, 0));
|
bar_item_append_associated_display(bar_item, 1 << strtoul(&token.text[sep + 1], NULL, 0));
|
||||||
}
|
}
|
||||||
} else if (token_equals(property, COMMAND_SET_ICON_PADDING_LEFT)) {
|
} else if (token_equals(property, COMMAND_SET_ICON_PADDING_LEFT)) {
|
||||||
bar_item->icon_padding_left = token_to_int(get_token(&message));
|
bar_item->icon.padding_left = token_to_int(get_token(&message));
|
||||||
bar_item_needs_update(bar_item);
|
needs_update = true;
|
||||||
} else if (token_equals(property, COMMAND_SET_ICON_PADDING_RIGHT)) {
|
} else if (token_equals(property, COMMAND_SET_ICON_PADDING_RIGHT)) {
|
||||||
bar_item->icon_padding_right = token_to_int(get_token(&message));
|
bar_item->icon.padding_right = token_to_int(get_token(&message));
|
||||||
bar_item_needs_update(bar_item);
|
needs_update = true;
|
||||||
} else if (token_equals(property, COMMAND_SET_LABEL_PADDING_LEFT)) {
|
} else if (token_equals(property, COMMAND_SET_LABEL_PADDING_LEFT)) {
|
||||||
bar_item->label_padding_left = token_to_int(get_token(&message));
|
bar_item->label.padding_left = token_to_int(get_token(&message));
|
||||||
bar_item_needs_update(bar_item);
|
needs_update = true;
|
||||||
} else if (token_equals(property, COMMAND_SET_LABEL_PADDING_RIGHT)) {
|
} else if (token_equals(property, COMMAND_SET_LABEL_PADDING_RIGHT)) {
|
||||||
bar_item->label_padding_right = token_to_int(get_token(&message));
|
bar_item->label.padding_right = token_to_int(get_token(&message));
|
||||||
bar_item_needs_update(bar_item);
|
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));
|
bar_item->background.padding_left = token_to_int(get_token(&message));
|
||||||
bar_item_needs_update(bar_item);
|
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));
|
bar_item->background.padding_right = token_to_int(get_token(&message));
|
||||||
bar_item_needs_update(bar_item);
|
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)) {
|
||||||
|
@ -478,6 +482,8 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
|
||||||
fprintf(rsp, "unknown command '%s' for domain 'set'\n", property.text);
|
fprintf(rsp, "unknown command '%s' for domain 'set'\n", property.text);
|
||||||
printf("unknown command '%s' for domain 'set'\n", property.text);
|
printf("unknown command '%s' for domain 'set'\n", property.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needs_update) bar_item_needs_update(bar_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Syntax: sketchybar -m default <property> <value>
|
// Syntax: sketchybar -m default <property> <value>
|
||||||
|
|
69
src/text.c
Normal file
69
src/text.c
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#include "text.h"
|
||||||
|
#include "misc/helpers.h"
|
||||||
|
|
||||||
|
void text_init(struct text* text) {
|
||||||
|
text->highlight = false;
|
||||||
|
text->padding_left = 0;
|
||||||
|
text->padding_right = 0;
|
||||||
|
|
||||||
|
text->color = rgba_color_from_hex(0xffffffff);
|
||||||
|
|
||||||
|
text->font = NULL;
|
||||||
|
text->string = string_copy("");
|
||||||
|
text->font_name = string_copy("Hack Nerd Font:Bold:14.0");
|
||||||
|
text_set_font(text, text->font_name, true);
|
||||||
|
text_set_string(text, text->string, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool text_set_string(struct text* text, char* string, bool forced) {
|
||||||
|
if (!string) return false;
|
||||||
|
if (!forced && text->string && strcmp(text->string, string) == 0) {
|
||||||
|
if (!(string == text->string)) free(string);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (text->line.line) bar_destroy_line(&text->line);
|
||||||
|
if (string != text->string && !text->string) free(text->string);
|
||||||
|
text->string = string;
|
||||||
|
bar_prepare_line(&text->line, text->font, text->string, text->highlight ? text->highlight_color : text->color);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool text_set_color(struct text* text, uint32_t color) {
|
||||||
|
text->color = rgba_color_from_hex(color);
|
||||||
|
return text_update_color(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool text_set_font(struct text* text, char* font_string, bool forced) {
|
||||||
|
if (!font_string) return false;
|
||||||
|
if (!forced && text->font_name && strcmp(text->font_name, font_string) == 0) { free(font_string); return false; }
|
||||||
|
if (text->font) CFRelease(text->font);
|
||||||
|
|
||||||
|
text->font = bar_create_font(font_string);
|
||||||
|
text->font_name = font_string;
|
||||||
|
return text_set_string(text, text->string, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool text_update_color(struct text* text) {
|
||||||
|
struct rgba_color target_color = text->highlight ? text->highlight_color : text->color;
|
||||||
|
if (text->line.color.r == target_color.r
|
||||||
|
&& text->line.color.g == target_color.g
|
||||||
|
&& text->line.color.b == target_color.b
|
||||||
|
&& text->line.color.a == target_color.a) return false;
|
||||||
|
text->line.color = target_color;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void text_clear_pointers(struct text* text) {
|
||||||
|
text->string = NULL;
|
||||||
|
text->font_name = NULL;
|
||||||
|
text->font = NULL;
|
||||||
|
text->line.line = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void text_destroy(struct text* text) {
|
||||||
|
if (text->string) free(text->string);
|
||||||
|
if (text->font_name) free(text->font_name);
|
||||||
|
if (text->font) CFRelease(text->font);
|
||||||
|
if (text->line.line) CFRelease(text->line.line);
|
||||||
|
text_clear_pointers(text);
|
||||||
|
}
|
24
src/text.h
Normal file
24
src/text.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef TEXT_H
|
||||||
|
#define TEXT_H
|
||||||
|
|
||||||
|
struct text {
|
||||||
|
bool highlight;
|
||||||
|
struct bar_line line;
|
||||||
|
char* string;
|
||||||
|
char* font_name;
|
||||||
|
CTFontRef font;
|
||||||
|
int padding_left;
|
||||||
|
int padding_right;
|
||||||
|
struct rgba_color color;
|
||||||
|
struct rgba_color highlight_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
void text_init(struct text* text);
|
||||||
|
void text_clear_pointers(struct text* text);
|
||||||
|
void text_destroy(struct text* text);
|
||||||
|
bool text_set_string(struct text* text, char* string, bool forced);
|
||||||
|
bool text_set_color(struct text* text, uint32_t color);
|
||||||
|
bool text_set_font(struct text* text, char* font_string, bool forced);
|
||||||
|
bool text_update_color(struct text* text);
|
||||||
|
|
||||||
|
#endif // !TEXT_H_
|
Loading…
Add table
Reference in a new issue