summaryrefslogtreecommitdiff
path: root/platform/macos
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-10-10 10:32:41 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-10-10 10:32:41 +0300
commit73430f292b8c0b3803c7d346195ec1cdffd194b8 (patch)
tree9fe51c7c236623efa303c03ff16cb5e3f020196c /platform/macos
parentca25c6e0a3f25948ee4a197f3442c66f019e7424 (diff)
[macOS] Fix window button position and title bar size when editor scale do not match OS UI scale.
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/display_server_macos.h2
-rw-r--r--platform/macos/display_server_macos.mm22
-rw-r--r--platform/macos/godot_button_view.h5
-rw-r--r--platform/macos/godot_button_view.mm22
4 files changed, 40 insertions, 11 deletions
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index e72273a681..484b8ffebc 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -401,7 +401,7 @@ public:
virtual bool window_minimize_on_title_dbl_click() const override;
virtual void window_set_window_buttons_offset(const Vector2i &p_offset, WindowID p_window = MAIN_WINDOW_ID) override;
- virtual Vector2i window_get_safe_title_margins(WindowID p_window = MAIN_WINDOW_ID) const override;
+ virtual Vector3i window_get_safe_title_margins(WindowID p_window = MAIN_WINDOW_ID) const override;
virtual Point2i ime_get_selection() const override;
virtual String ime_get_text() const override;
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index f980129081..f4692abc92 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -2655,25 +2655,33 @@ void DisplayServerMacOS::window_set_window_buttons_offset(const Vector2i &p_offs
ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];
- wd.wb_offset = p_offset;
+ float scale = screen_get_max_scale();
+ wd.wb_offset = p_offset / scale;
+ wd.wb_offset.x = MAX(wd.wb_offset.x, 12);
+ wd.wb_offset.y = MAX(wd.wb_offset.y, 12);
+ if (wd.window_button_view) {
+ [wd.window_button_view setOffset:NSMakePoint(wd.wb_offset.x, wd.wb_offset.y)];
+ }
}
-Vector2i DisplayServerMacOS::window_get_safe_title_margins(WindowID p_window) const {
+Vector3i DisplayServerMacOS::window_get_safe_title_margins(WindowID p_window) const {
_THREAD_SAFE_METHOD_
- ERR_FAIL_COND_V(!windows.has(p_window), Vector2i());
+ ERR_FAIL_COND_V(!windows.has(p_window), Vector3i());
const WindowData &wd = windows[p_window];
if (!wd.window_button_view) {
- return Vector2i();
+ return Vector3i();
}
- float max_x = wd.wb_offset.x + [wd.window_button_view frame].size.width;
+ float scale = screen_get_max_scale();
+ float max_x = [wd.window_button_view getOffset].x + [wd.window_button_view frame].size.width;
+ float max_y = [wd.window_button_view getOffset].y + [wd.window_button_view frame].size.height;
if ([wd.window_object windowTitlebarLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft) {
- return Vector2i(0, max_x * screen_get_max_scale());
+ return Vector3i(0, max_x * scale, max_y * scale);
} else {
- return Vector2i(max_x * screen_get_max_scale(), 0);
+ return Vector3i(max_x * scale, 0, max_y * scale);
}
}
diff --git a/platform/macos/godot_button_view.h b/platform/macos/godot_button_view.h
index e7627a9e9b..ef1d5fe412 100644
--- a/platform/macos/godot_button_view.h
+++ b/platform/macos/godot_button_view.h
@@ -42,10 +42,15 @@
CGFloat spacing;
bool mouse_in_group;
bool rtl;
+ NSButton *close_button;
+ NSButton *miniaturize_button;
+ NSButton *zoom_button;
}
- (void)initButtons:(CGFloat)button_spacing offset:(NSPoint)button_offset rtl:(bool)is_rtl;
- (void)displayButtons;
+- (void)setOffset:(NSPoint)button_offset;
+- (NSPoint)getOffset;
@end
diff --git a/platform/macos/godot_button_view.mm b/platform/macos/godot_button_view.mm
index 9106f0b0db..7d380cbe11 100644
--- a/platform/macos/godot_button_view.mm
+++ b/platform/macos/godot_button_view.mm
@@ -40,6 +40,9 @@
spacing = 20;
mouse_in_group = false;
rtl = false;
+ close_button = nullptr;
+ miniaturize_button = nullptr;
+ zoom_button = nullptr;
return self;
}
@@ -48,15 +51,15 @@
spacing = button_spacing;
rtl = is_rtl;
- NSButton *close_button = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:NSWindowStyleMaskTitled];
+ close_button = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:NSWindowStyleMaskTitled];
[close_button setFrameOrigin:NSMakePoint(rtl ? spacing * 2 : 0, 0)];
[self addSubview:close_button];
- NSButton *miniaturize_button = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSWindowStyleMaskTitled];
+ miniaturize_button = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSWindowStyleMaskTitled];
[miniaturize_button setFrameOrigin:NSMakePoint(spacing, 0)];
[self addSubview:miniaturize_button];
- NSButton *zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:NSWindowStyleMaskTitled];
+ zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:NSWindowStyleMaskTitled];
[zoom_button setFrameOrigin:NSMakePoint(rtl ? 0 : spacing * 2, 0)];
[self addSubview:zoom_button];
@@ -71,6 +74,19 @@
[self displayButtons];
}
+- (void)setOffset:(NSPoint)button_offset {
+ if (zoom_button) {
+ offset.y = button_offset.y - zoom_button.frame.size.height / 2;
+ offset.x = button_offset.x - zoom_button.frame.size.width / 2;
+
+ [self viewDidMoveToWindow];
+ }
+}
+
+- (NSPoint)getOffset {
+ return offset;
+}
+
- (void)viewDidMoveToWindow {
if (!self.window) {
return;