From dc0c9618a2983d54710b96ceb22eba8fd6e67f0d Mon Sep 17 00:00:00 2001 From: Igor Fedyukin Date: Fri, 8 Nov 2024 17:07:26 +0300 Subject: [PATCH] Support notch_display_height property (#626) --- src/bar.c | 10 +++++++++- src/bar_manager.c | 9 +++++++++ src/bar_manager.h | 2 ++ src/message.c | 6 ++++++ src/misc/defines.h | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/bar.c b/src/bar.c index 12914d63..379e9923 100644 --- a/src/bar.c +++ b/src/bar.c @@ -465,6 +465,7 @@ void bar_calculate_bounds(struct bar* bar) { static CGRect bar_get_frame(struct bar *bar) { bool is_builtin = CGDisplayIsBuiltin(bar->did); int notch_offset = is_builtin ? g_bar_manager.notch_offset : 0; + int notch_display_height = is_builtin ? g_bar_manager.notch_display_height : 0; CGRect bounds = display_bounds(bar->did); @@ -507,8 +508,15 @@ static CGRect bar_get_frame(struct bar *bar) { origin.y += menu.size.height; } + + if (notch_display_height > 0) { + return (CGRect) {{origin.x, origin.y}, + {bounds.size.width, + g_bar_manager.notch_display_height}}; + } + return (CGRect) {{origin.x, origin.y}, - {bounds.size.width, + {bounds.size.width, g_bar_manager.background.bounds.size.height}}; } } diff --git a/src/bar_manager.c b/src/bar_manager.c index 4235d2a9..cce7a4f5 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -38,6 +38,7 @@ void bar_manager_init(struct bar_manager* bar_manager) { bar_manager->topmost = false; bar_manager->notch_width = 200; bar_manager->notch_offset = 0; + bar_manager->notch_display_height = 0; bar_manager->active_adid = display_active_display_adid(); bar_manager->might_need_clipping = false; @@ -242,6 +243,14 @@ bool bar_manager_set_notch_offset(struct bar_manager* bar_manager, uint32_t offs return true; } +bool bar_manager_set_notch_display_height(struct bar_manager* bar_manager, uint32_t offset) { + if (bar_manager->notch_display_height == offset) return false; + + bar_manager->notch_display_height = offset; + bar_manager->bar_needs_resize = true; + return true; +} + bool bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smoothing) { if (bar_manager->font_smoothing == smoothing) return false; bar_manager->font_smoothing = smoothing; diff --git a/src/bar_manager.h b/src/bar_manager.h index ebf5270a..aae70009 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -34,6 +34,7 @@ struct bar_manager { uint32_t blur_radius; uint32_t notch_width; uint32_t notch_offset; + uint32_t notch_display_height; uint32_t active_adid; uint32_t window_level; @@ -79,6 +80,7 @@ bool bar_manager_set_shadow(struct bar_manager* bar_manager, bool shadow); bool bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smoothing); bool bar_manager_set_notch_width(struct bar_manager* bar_manager, uint32_t width); bool bar_manager_set_notch_offset(struct bar_manager* bar_manager, uint32_t offset); +bool bar_manager_set_notch_display_height(struct bar_manager* bar_manager, uint32_t offset); void bar_manager_sort(struct bar_manager* bar_manager, struct bar_item** ordering, uint32_t count); struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, struct window** window_out); diff --git a/src/message.c b/src/message.c index a7defcb9..6a6b9675 100644 --- a/src/message.c +++ b/src/message.c @@ -369,6 +369,12 @@ static bool handle_domain_bar(FILE *rsp, struct token domain, char *message) { &g_bar_manager, g_bar_manager.notch_offset, token_to_int(token) ); + } else if (token_equals(command, PROPERTY_NOTCH_DISPLAY_HEIGHT)) { + struct token token = get_token(&message); + ANIMATE(bar_manager_set_notch_display_height, + &g_bar_manager, + g_bar_manager.notch_display_height, + token_to_int(token) ); } else if (token_equals(command, PROPERTY_HIDDEN)) { struct token state = get_token(&message); uint32_t adid = 0; diff --git a/src/misc/defines.h b/src/misc/defines.h index d87026e8..83ecca4c 100644 --- a/src/misc/defines.h +++ b/src/misc/defines.h @@ -113,6 +113,7 @@ #define PROPERTY_ALIGN "align" #define PROPERTY_NOTCH_WIDTH "notch_width" #define PROPERTY_NOTCH_OFFSET "notch_offset" +#define PROPERTY_NOTCH_DISPLAY_HEIGHT "notch_display_height" #define PROPERTY_HORIZONTAL "horizontal" #define DOMAIN_SUBSCRIBE "--subscribe"