mirror of
https://github.com/FelixKratz/SketchyBar
synced 2025-02-16 20:48:26 +00:00
override alias colors
This commit is contained in:
parent
49209b5ec3
commit
657a2b0798
11 changed files with 97 additions and 24 deletions
|
@ -356,9 +356,6 @@ this draws a white background below all my space components. I plan to expand th
|
|||
### Item Alias -- Mirror items of the original macOS status bar into sketchybar
|
||||
It is possible to create an alias for default menu bar items (such as MeetingBar, etc.) in sketchybar. The default menu bar can be set to autohide and this should still work.
|
||||
|
||||
Important: <br>
|
||||
I highly recommend setting a wallpaper on all spaces that makes the default menu bar items appear in either the light or the dark theme consitently.
|
||||
|
||||
It is now possible to create an alias of a default menu bar item with the following syntax:
|
||||
```bash
|
||||
sketchybar --add alias <application_name> <position>
|
||||
|
@ -383,6 +380,10 @@ All further default menu items currently available on your system can be found v
|
|||
```bash
|
||||
sketchybar --query default_menu_items
|
||||
```
|
||||
You can override the color of an alias via the property (HEAD only):
|
||||
```bash
|
||||
sketchybar --set <name> alias.color=<rgba_hex>
|
||||
```
|
||||
|
||||
## Popup Menus
|
||||
<img src="https://user-images.githubusercontent.com/22680421/146688291-b8bc5e77-e6a2-42ee-bd9f-b3709c63d936.png" width="300"> <br>
|
||||
|
|
54
src/alias.c
54
src/alias.c
|
@ -1,7 +1,7 @@
|
|||
#include "alias.h"
|
||||
#include "misc/helpers.h"
|
||||
|
||||
extern void SLSCaptureWindowsContentsToRectWithOptions(uint32_t cid, uint32_t* wid, bool meh, CGRect bounds, uint32_t flags, CGImageRef* image);
|
||||
extern void SLSCaptureWindowsContentsToRectWithOptions(uint32_t cid, uint64_t* wid, bool meh, CGRect bounds, uint32_t flags, CGImageRef* image);
|
||||
extern int SLSGetScreenRectForWindow(uint32_t cid, uint32_t wid, CGRect* out);
|
||||
|
||||
void print_all_menu_items(FILE* rsp) {
|
||||
|
@ -58,11 +58,19 @@ void alias_get_permission(struct alias* alias) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void alias_init(struct alias* alias, char* owner, char* name) {
|
||||
void alias_init(struct alias* alias) {
|
||||
alias->name = NULL;
|
||||
alias->owner = NULL;
|
||||
alias->wid = 0;
|
||||
alias->color_override = false;
|
||||
alias->color = rgba_color_from_hex(0xffff0000);
|
||||
|
||||
image_init(&alias->image);
|
||||
}
|
||||
|
||||
void alias_setup(struct alias* alias, char* owner, char* name) {
|
||||
alias->name = name;
|
||||
alias->owner = owner;
|
||||
alias->wid = 0;
|
||||
image_init(&alias->image);
|
||||
alias_get_permission(alias);
|
||||
alias_update_image(alias);
|
||||
}
|
||||
|
@ -137,15 +145,51 @@ bool alias_update_image(struct alias* alias) {
|
|||
}
|
||||
|
||||
void alias_draw(struct alias* alias, CGContextRef context) {
|
||||
image_draw(&alias->image, context);
|
||||
if (alias->color_override) {
|
||||
CGContextSaveGState(context);
|
||||
image_draw(&alias->image, context);
|
||||
CGContextClipToMask(context, alias->image.bounds, alias->image.image_ref);
|
||||
CGContextSetRGBFillColor(context, alias->color.r, alias->color.g, alias->color.b, alias->color.a);
|
||||
CGContextFillRect(context, alias->image.bounds);
|
||||
CGContextRestoreGState(context);
|
||||
}
|
||||
else {
|
||||
image_draw(&alias->image, context);
|
||||
}
|
||||
}
|
||||
|
||||
void alias_destroy(struct alias* alias) {
|
||||
image_destroy(&alias->image);
|
||||
if (alias->name) free(alias->name);
|
||||
if (alias->owner) free(alias->owner);
|
||||
alias->name = NULL;
|
||||
alias->owner = NULL;
|
||||
}
|
||||
|
||||
void alias_calculate_bounds(struct alias* alias, uint32_t x, uint32_t y) {
|
||||
image_calculate_bounds(&alias->image, x, y);
|
||||
}
|
||||
|
||||
static bool alias_parse_sub_domain(struct alias* alias, FILE* rsp, struct token property, char* message) {
|
||||
struct key_value_pair key_value_pair = get_key_value_pair(property.text, '.');
|
||||
if (key_value_pair.key && key_value_pair.value) {
|
||||
struct token subdom = { key_value_pair.key, strlen(key_value_pair.key) };
|
||||
struct token entry = { key_value_pair.value, strlen(key_value_pair.value) };
|
||||
if (token_equals(subdom, SUB_DOMAIN_SHADOW))
|
||||
return shadow_parse_sub_domain(&alias->image.shadow, rsp, entry, message);
|
||||
else {
|
||||
fprintf(rsp, "Invalid subdomain: %s \n", subdom.text);
|
||||
printf("Invalid subdomain: %s \n", subdom.text);
|
||||
}
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_COLOR)) {
|
||||
alias->color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
||||
alias->color_override = true;
|
||||
return true;
|
||||
} else {
|
||||
fprintf(rsp, "Unknown property: %s \n", property.text);
|
||||
printf("Unknown property: %s \n", property.text);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
10
src/alias.h
10
src/alias.h
|
@ -10,12 +10,16 @@ struct alias {
|
|||
char* owner;
|
||||
|
||||
uint64_t pid;
|
||||
uint32_t wid;
|
||||
uint64_t wid;
|
||||
|
||||
bool color_override;
|
||||
struct rgba_color color;
|
||||
struct image image;
|
||||
|
||||
};
|
||||
|
||||
void alias_init(struct alias* alias, char* owner, char* name);
|
||||
void alias_init(struct alias* alias);
|
||||
void alias_setup(struct alias* alias, char* owner, char* name);
|
||||
bool alias_update_image(struct alias* alias);
|
||||
void alias_find_window(struct alias* alias);
|
||||
uint32_t alias_get_length(struct alias* alias);
|
||||
|
@ -27,4 +31,6 @@ void alias_destroy(struct alias* alias);
|
|||
|
||||
void print_all_menu_items(FILE* rsp);
|
||||
|
||||
static bool alias_parse_sub_domain(struct alias* alias, FILE* rsp, struct token property, char* message);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -99,6 +99,8 @@ void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) {
|
|||
background_init(&bar_item->background);
|
||||
env_vars_init(&bar_item->signal_args.env_vars);
|
||||
popup_init(&bar_item->popup);
|
||||
graph_init(&bar_item->graph);
|
||||
alias_init(&bar_item->alias);
|
||||
|
||||
if (default_item) bar_item_inherit_from_item(bar_item, default_item);
|
||||
}
|
||||
|
|
14
src/graph.c
14
src/graph.c
|
@ -1,19 +1,23 @@
|
|||
#include "graph.h"
|
||||
|
||||
void graph_init(struct graph* graph, uint32_t width) {
|
||||
graph->width = width;
|
||||
graph->y = malloc(sizeof(float) * width);
|
||||
memset(graph->y, 0, sizeof(float) * width);
|
||||
void graph_init(struct graph* graph) {
|
||||
graph->width = 0;
|
||||
graph->cursor = 0;
|
||||
|
||||
graph->line_color = rgba_color_from_hex(0xcccccc);
|
||||
graph->fill_color = rgba_color_from_hex(0xcccccc);
|
||||
graph->line_width = 0.5;
|
||||
graph->line_width = 0.5;
|
||||
graph->fill = true;
|
||||
graph->overrides_fill_color = false;
|
||||
graph->enabled = true;
|
||||
}
|
||||
|
||||
void graph_setup(struct graph* graph, uint32_t width) {
|
||||
graph->width = width;
|
||||
graph->y = malloc(sizeof(float) * width);
|
||||
memset(graph->y, 0, sizeof(float) * width);
|
||||
}
|
||||
|
||||
float graph_get_y(struct graph* graph, uint32_t i) {
|
||||
if (!graph->enabled) return 0.f;
|
||||
return graph->y[ (graph->cursor + i)%graph->width ];
|
||||
|
|
|
@ -17,7 +17,8 @@ struct graph {
|
|||
struct rgba_color fill_color;
|
||||
};
|
||||
|
||||
void graph_init(struct graph* graph, uint32_t width);
|
||||
void graph_init(struct graph* graph);
|
||||
void graph_setup(struct graph* graph, uint32_t width);
|
||||
void graph_push_back(struct graph* graph, float y);
|
||||
float graph_get_y(struct graph* graph, uint32_t i);
|
||||
uint32_t graph_get_length(struct graph* graph);
|
||||
|
|
14
src/image.c
14
src/image.c
|
@ -1,5 +1,6 @@
|
|||
#include "image.h"
|
||||
#include "misc/helpers.h"
|
||||
#include "shadow.h"
|
||||
|
||||
void image_init(struct image* image) {
|
||||
image->enabled = false;
|
||||
|
@ -8,6 +9,8 @@ void image_init(struct image* image) {
|
|||
image->bounds = CGRectNull;
|
||||
image->size = CGSizeZero;
|
||||
image->scale = 1.0;
|
||||
|
||||
shadow_init(&image->shadow);
|
||||
}
|
||||
|
||||
bool image_set_enabled(struct image* image, bool enabled) {
|
||||
|
@ -91,6 +94,17 @@ void image_calculate_bounds(struct image* image, uint32_t x, uint32_t y) {
|
|||
|
||||
void image_draw(struct image* image, CGContextRef context) {
|
||||
if (!image->image_ref) return;
|
||||
|
||||
// if (image->shadow.enabled) {
|
||||
// CGContextSaveGState(context);
|
||||
// CGRect sbounds = shadow_get_bounds(&image->shadow, image->bounds);
|
||||
// CGContextDrawImage(context, sbounds, image->image_ref);
|
||||
// CGContextClipToMask(context, sbounds, image->image_ref);
|
||||
// CGContextSetRGBFillColor(context, image->shadow.color.r, image->shadow.color.g, image->shadow.color.b, image->shadow.color.a);
|
||||
// CGContextFillRect(context, sbounds);
|
||||
// CGContextRestoreGState(context);
|
||||
// }
|
||||
|
||||
CGContextDrawImage(context, image->bounds, image->image_ref);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ struct image {
|
|||
|
||||
CGImageRef image_ref;
|
||||
CFDataRef data_ref;
|
||||
|
||||
struct shadow shadow;
|
||||
};
|
||||
|
||||
void image_init(struct image* image);
|
||||
|
@ -24,4 +26,5 @@ void image_draw(struct image* image, CGContextRef context);
|
|||
void image_clear_pointers(struct image* image);
|
||||
void image_destroy(struct image* image);
|
||||
|
||||
static bool image_parse_sub_domain(struct image* image, FILE* rsp, struct token property, char* message);
|
||||
#endif
|
||||
|
|
|
@ -152,15 +152,15 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) {
|
|||
} else if (command.length > 0) {
|
||||
if (bar_item->type == BAR_COMPONENT_GRAPH) {
|
||||
struct token width = get_token(&message);
|
||||
graph_init(&bar_item->graph, token_to_uint32t(width));
|
||||
graph_setup(&bar_item->graph, token_to_uint32t(width));
|
||||
}
|
||||
else if (bar_item->type == BAR_COMPONENT_ALIAS) {
|
||||
char* tmp_name = string_copy(name.text);
|
||||
struct key_value_pair key_value_pair = get_key_value_pair(tmp_name, ',');
|
||||
if (!key_value_pair.key || !key_value_pair.value)
|
||||
alias_init(&bar_item->alias, token_to_string(name), NULL);
|
||||
alias_setup(&bar_item->alias, token_to_string(name), NULL);
|
||||
else
|
||||
alias_init(&bar_item->alias, string_copy(key_value_pair.key), string_copy(key_value_pair.value));
|
||||
alias_setup(&bar_item->alias, string_copy(key_value_pair.key), string_copy(key_value_pair.value));
|
||||
free(tmp_name);
|
||||
}
|
||||
else if (bar_item->type == BAR_COMPONENT_GROUP) {
|
||||
|
@ -205,6 +205,8 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
|
|||
needs_update = graph_parse_sub_domain(&bar_item->graph, rsp, entry, message);
|
||||
else if (token_equals(subdom, SUB_DOMAIN_POPUP))
|
||||
needs_update = popup_parse_sub_domain(&bar_item->popup, rsp, entry, message);
|
||||
else if (token_equals(subdom, SUB_DOMAIN_ALIAS))
|
||||
needs_update = alias_parse_sub_domain(&bar_item->alias, rsp, entry, message);
|
||||
else {
|
||||
fprintf(rsp, "Invalid subdomain: %s \n", subdom.text);
|
||||
printf("Invalid subdomain: %s \n", subdom.text);
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#define SUB_DOMAIN_LABEL "label"
|
||||
#define SUB_DOMAIN_BACKGROUND "background"
|
||||
#define SUB_DOMAIN_GRAPH "graph"
|
||||
#define SUB_DOMAIN_ALIAS "alias"
|
||||
#define SUB_DOMAIN_POPUP "popup"
|
||||
#define SUB_DOMAIN_SHADOW "shadow"
|
||||
#define SUB_DOMAIN_IMAGE "image"
|
||||
|
|
|
@ -16,13 +16,10 @@ struct signal_args {
|
|||
};
|
||||
|
||||
struct rgba_color {
|
||||
bool is_valid;
|
||||
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
uint32_t p;
|
||||
};
|
||||
|
||||
struct token {
|
||||
|
@ -41,8 +38,6 @@ static uint32_t hex_from_rgba_color(struct rgba_color rgba_color) {
|
|||
|
||||
static struct rgba_color rgba_color_from_hex(uint32_t color) {
|
||||
struct rgba_color result;
|
||||
result.is_valid = true;
|
||||
result.p = color;
|
||||
result.r = ((color >> 16) & 0xff) / 255.0;
|
||||
result.g = ((color >> 8) & 0xff) / 255.0;
|
||||
result.b = ((color >> 0) & 0xff) / 255.0;
|
||||
|
|
Loading…
Add table
Reference in a new issue