change screen, display association logic to allow for multiple associations

This commit is contained in:
FelixKratz 2021-08-14 21:54:43 +02:00
parent b1ee965a36
commit a553aa46ce
6 changed files with 12 additions and 6 deletions

View file

@ -13,8 +13,9 @@ What I have added:
* ... feel free to explore my sketchybarrc file for more details on the options
I have many more plans for the project:
* ~~Let items subscribe to system events (e.g. space changed, window focused, etc.) for their refresh action (like in yabai)~~ (DONE)
* Cache the scripts in RAM to reduce I/O operations
* Make the associated_space / associated_display properties more powerful by allowing to associate to more than one screen/display
* ~~Make the associated_space / associated_display properties more powerful by allowing to associate to more than one screen/display~~ (DONE)
* Make application specific widgets with associated_app argument (e.g. when gvim is open show the vim mode indicator in the status bar)
* Fix the currently static positioning of the bar
* A y_offset property for all items to create (in combination with the nospace modifier) vertically stacked labels

View file

@ -96,6 +96,10 @@ sketchybar -m set clock icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set clock label_padding_left 10
sketchybar -m add item mailIndicator right
# Items can be associated to multiple spaces / displays
sketchybar -m set mailIndicator associated_space 1
sketchybar -m set mailIndicator associated_space 2
sketchybar -m set mailIndicator associated_space 3
sketchybar -m set mailIndicator update_freq 10
sketchybar -m set mailIndicator script "/Users/felix/.config/sketchybar/plugins/mailIndicator.sh"
sketchybar -m set mailIndicator icon_font "Hack Nerd Font:Bold:20.0"

View file

@ -265,8 +265,8 @@ void bar_refresh(struct bar *bar)
CGPoint label_position = bar_align_line(bar, *label, ALIGN_CENTER, ALIGN_CENTER);
if(bar_item->associated_display > 0 && bar_item->associated_display != did) continue;
if((strcmp(bar_item->identifier, BAR_COMPONENT_SPACE) != 0) && bar_item->associated_space > 0 && bar_item->associated_space != sid) continue;
if(bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << did))) continue;
if((strcmp(bar_item->identifier, BAR_COMPONENT_SPACE) != 0) && bar_item->associated_space > 0 && !(bar_item->associated_space & (1 << sid))) continue;
if (bar_item->position == BAR_POSITION_LEFT) {
icon_position.x = bar_left_final_item_x + bar_item->icon_spacing_left;

View file

@ -46,7 +46,7 @@ void bar_item_update_component(struct bar_item* bar_item, uint32_t did, uint32_t
if (strcmp(bar_item->identifier, BAR_COMPONENT_TITLE) == 0)
bar_item_set_label(bar_item, focused_window_title());
else if (strcmp(bar_item->identifier, BAR_COMPONENT_SPACE) == 0) {
if (sid == bar_item->associated_space && did == bar_item->associated_display)
if ((1 << sid) & bar_item->associated_space && (1 << did) & bar_item->associated_display)
bar_item_set_icon(bar_item, bar_item->icon, bar_item->icon_highlight_color);
else
bar_item_set_icon(bar_item, bar_item->icon, bar_item->icon_color);

View file

@ -18,6 +18,7 @@ struct bar_item {
char type;
char* identifier;
// These are 32bit masks where the ith bit represents the ith screen/display association
uint32_t associated_display;
uint32_t associated_space;
uint32_t update_frequency;

View file

@ -283,10 +283,10 @@ static void handle_domain_set(FILE* rsp, struct token domain, char* message) {
bar_item->position = token_to_string(value)[0];
} else if (token_equals(property, COMMAND_SET_ASSOCIATED_SPACE)) {
struct token value = get_token(&message);
bar_item->associated_space = token_to_uint32t(value);
bar_item->associated_space |= 1 << token_to_uint32t(value);
} else if (token_equals(property, COMMAND_SET_ASSOCIATED_DISPLAY)) {
struct token value = get_token(&message);
bar_item->associated_display = token_to_uint32t(value);
bar_item->associated_display |= 1 << token_to_uint32t(value);
} else if (token_equals(property, COMMAND_SET_ICON_PADDING_LEFT)) {
struct token value = get_token(&message);
bar_item->icon_spacing_left = token_to_uint32t(value);