aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2025-12-11 18:37:21 +0100
committerAndre Weissflog <floooh@gmail.com>2025-12-11 18:37:21 +0100
commit555b72bf22800a8ed01ce2bf3a3762921119fa61 (patch)
tree501b0a9eee5e7751d82ad9fb38c231e55b43c94a
parentda55ab6b98a6bbe3adc30bf168cf40659f10e802 (diff)
sokol_gfx.h macos: init internal framebuffer width/height when no window size was provided (see: https://github.com/floooh/sokol/issues/1399)
-rw-r--r--sokol_app.h30
1 files changed, 22 insertions, 8 deletions
diff --git a/sokol_app.h b/sokol_app.h
index 2afad99b..4f342c0d 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -5327,6 +5327,27 @@ _SOKOL_PRIVATE void _sapp_macos_app_event(sapp_event_type type) {
}
}
+// called when in applicationDidFinishedLaunching when no window size was provided
+_SOKOL_PRIVATE void _sapp_macos_init_default_dimensions(void) {
+ if (_sapp.desc.high_dpi) {
+ _sapp.dpi_scale = NSScreen.mainScreen.backingScaleFactor;
+ } else {
+ _sapp.dpi_scale = 1.0f;
+ }
+ NSRect screen_rect = NSScreen.mainScreen.frame;
+ // use 4/5 of screen size as default size
+ const float default_widthf = (screen_rect.size.width * 4.0f) / 5.0f;
+ const float default_heightf = (screen_rect.size.height * 4.0f) / 5.0f;
+ if (_sapp.window_width == 0) {
+ _sapp.window_width = _sapp_roundf_gzero(default_widthf);
+ }
+ if (_sapp.window_height == 0) {
+ _sapp.window_height = _sapp_roundf_gzero(default_heightf);
+ }
+ _sapp.framebuffer_width = _sapp_roundf_gzero(default_widthf * _sapp.dpi_scale);
+ _sapp.framebuffer_height = _sapp_roundf_gzero(default_heightf * _sapp.dpi_scale);
+}
+
/* NOTE: unlike the iOS version of this function, the macOS version
can dynamically update the DPI scaling factor when a window is moved
between HighDPI / LowDPI screens.
@@ -5577,14 +5598,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
_SOKOL_UNUSED(aNotification);
_sapp_macos_init_cursors();
if ((_sapp.window_width == 0) || (_sapp.window_height == 0)) {
- // use 4/5 of screen size as default size
- NSRect screen_rect = NSScreen.mainScreen.frame;
- if (_sapp.window_width == 0) {
- _sapp.window_width = _sapp_roundf_gzero((screen_rect.size.width * 4.0f) / 5.0f);
- }
- if (_sapp.window_height == 0) {
- _sapp.window_height = _sapp_roundf_gzero((screen_rect.size.height * 4.0f) / 5.0f);
- }
+ _sapp_macos_init_default_dimensions();
}
const NSUInteger style =
NSWindowStyleMaskTitled |