summaryrefslogtreecommitdiffstats
path: root/platform/macos/display_server_macos.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/macos/display_server_macos.mm')
-rw-r--r--platform/macos/display_server_macos.mm24
1 files changed, 24 insertions, 0 deletions
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index cfa4041147..0041848c78 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -3283,6 +3283,30 @@ void DisplayServerMacOS::status_indicator_set_callback(IndicatorID p_id, const C
[indicators[p_id].delegate setCallback:p_callback];
}
+Rect2 DisplayServerMacOS::status_indicator_get_rect(IndicatorID p_id) const {
+ ERR_FAIL_COND_V(!indicators.has(p_id), Rect2());
+
+ NSStatusItem *item = indicators[p_id].item;
+ NSView *v = item.button;
+ const NSRect contentRect = [v frame];
+ const NSRect nsrect = [v.window convertRectToScreen:contentRect];
+ Rect2 rect;
+
+ // Return the position of the top-left corner, for macOS the y starts at the bottom.
+ const float scale = screen_get_max_scale();
+ rect.size.x = nsrect.size.width;
+ rect.size.y = nsrect.size.height;
+ rect.size *= scale;
+ rect.position.x = nsrect.origin.x;
+ rect.position.y = (nsrect.origin.y + nsrect.size.height);
+ rect.position *= scale;
+ rect.position -= _get_screens_origin();
+ // macOS native y-coordinate relative to _get_screens_origin() is negative,
+ // Godot expects a positive value.
+ rect.position.y *= -1;
+ return rect;
+}
+
void DisplayServerMacOS::delete_status_indicator(IndicatorID p_id) {
ERR_FAIL_COND(!indicators.has(p_id));