mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-23 11:53:02 +00:00
respect all shadows in bounding box calculation (#199)
This commit is contained in:
parent
703fe1319c
commit
c4fe5f4342
3 changed files with 43 additions and 7 deletions
13
src/bar.c
13
src/bar.c
|
@ -219,20 +219,19 @@ void bar_calculate_bounds(struct bar* bar) {
|
|||
|
||||
bar_item->graph.rtl = rtl;
|
||||
|
||||
int shadow_offset = (bar_item->background.shadow.enabled
|
||||
? -bar_item->background.shadow.offset.x
|
||||
: 0);
|
||||
|
||||
CGPoint shadow_offsets = bar_item_calculate_shadow_offsets(bar_item);
|
||||
uint32_t bar_item_length = bar_item_calculate_bounds(bar_item,
|
||||
bar->window.frame.size.height
|
||||
- (g_bar_manager.background.border_width + 1),
|
||||
shadow_offset > 0 ? shadow_offset : 0,
|
||||
(shadow_offsets.x > 0 ? shadow_offsets.x : 0),
|
||||
y );
|
||||
|
||||
CGRect frame = {{bar->window.origin.x + *next_position
|
||||
- (shadow_offset > 0 ? shadow_offset : 0),
|
||||
- (shadow_offsets.x > 0 ? shadow_offsets.x : 0),
|
||||
bar->window.origin.y },
|
||||
{bar_item_display_length + abs(shadow_offset),
|
||||
{bar_item_display_length
|
||||
+ shadow_offsets.x
|
||||
+ shadow_offsets.y,
|
||||
bar->window.frame.size.height} };
|
||||
|
||||
window_set_frame(bar_item_get_window(bar_item, bar->adid), frame);
|
||||
|
|
|
@ -436,6 +436,42 @@ void bar_item_remove_window(struct bar_item* bar_item, uint32_t adid) {
|
|||
}
|
||||
}
|
||||
|
||||
CGPoint bar_item_calculate_shadow_offsets(struct bar_item* bar_item) {
|
||||
CGPoint offset;
|
||||
offset.x = (int)((bar_item->background.shadow.enabled
|
||||
? max(-bar_item->background.shadow.offset.x, 0)
|
||||
: 0)
|
||||
+ (bar_item->icon.shadow.enabled
|
||||
? max(-bar_item->icon.shadow.offset.x, 0)
|
||||
: 0)
|
||||
+ (bar_item->icon.background.shadow.enabled
|
||||
? max(-bar_item->icon.background.shadow.offset.x, 0)
|
||||
: 0)
|
||||
+ (bar_item->label.background.shadow.enabled
|
||||
? max(-bar_item->label.background.shadow.offset.x, 0)
|
||||
: 0)
|
||||
+ (bar_item->label.shadow.enabled
|
||||
? max(-bar_item->label.shadow.offset.x, 0)
|
||||
: 0));
|
||||
|
||||
offset.y = (int)((bar_item->background.shadow.enabled
|
||||
? max(bar_item->background.shadow.offset.x,0)
|
||||
: 0)
|
||||
+ (bar_item->icon.shadow.enabled
|
||||
? max(bar_item->icon.shadow.offset.x, 0)
|
||||
: 0)
|
||||
+ (bar_item->icon.background.shadow.enabled
|
||||
? max(bar_item->icon.background.shadow.offset.x, 0)
|
||||
: 0)
|
||||
+ (bar_item->label.background.shadow.enabled
|
||||
? max(bar_item->label.background.shadow.offset.x, 0)
|
||||
: 0)
|
||||
+ (bar_item->label.shadow.enabled
|
||||
? max(bar_item->label.shadow.offset.x, 0)
|
||||
: 0));
|
||||
return offset;
|
||||
}
|
||||
|
||||
CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) {
|
||||
CGRect bounding_rect;
|
||||
bounding_rect.origin = bar_item->icon.bounds.origin;
|
||||
|
|
|
@ -110,6 +110,7 @@ struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid);
|
|||
void bar_item_remove_window(struct bar_item* bar_item, uint32_t adid);
|
||||
CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item);
|
||||
|
||||
CGPoint bar_item_calculate_shadow_offsets(struct bar_item* bar_item);
|
||||
uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y);
|
||||
void bar_item_draw(struct bar_item* bar_item, CGContextRef context);
|
||||
|
||||
|
|
Loading…
Reference in a new issue