Skip to content

Commit

Permalink
Bring back MTY_WindwGetRefreshRate
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisd1100 committed Jan 30, 2024
1 parent 1488749 commit c155830
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/matoya.h
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,12 @@ MTY_WindowGetScreenSize(MTY_App *app, MTY_Window window);
MTY_EXPORT float
MTY_WindowGetScreenScale(MTY_App *app, MTY_Window window);

/// @brief Get the refresh rate of the display where the window currently resides.
/// @param app The MTY_App.
/// @param window An MTY_Window.
MTY_EXPORT uint32_t
MTY_WindowGetRefreshRate(MTY_App *app, MTY_Window window);

/// @brief Set the window's title.
/// @param app The MTY_App.
/// @param window An MTY_Window.
Expand Down
5 changes: 5 additions & 0 deletions src/unix/apple/iphoneos/app.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ float MTY_WindowGetScreenScale(MTY_App *app, MTY_Window window)
return 1.0f;
}

uint32_t MTY_WindowGetRefreshRate(MTY_App *app, MTY_Window window)
{
return 60;
}

void MTY_WindowSetTitle(MTY_App *app, MTY_Window window, const char *title)
{
}
Expand Down
19 changes: 19 additions & 0 deletions src/unix/apple/macosx/app.m
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,25 @@ float MTY_WindowGetScreenScale(MTY_App *app, MTY_Window window)
return mty_screen_scale(ctx->nsw.screen);
}

uint32_t MTY_WindowGetRefreshRate(MTY_App *app, MTY_Window window)
{
uint32_t r = 60;

struct window *ctx = app_get_window(app, window);

if (ctx) {
CGDirectDisplayID display = screen_get_display_id(ctx->nsw.screen);
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(display);

if (mode) {
r = lrint(CGDisplayModeGetRefreshRate(mode));
CGDisplayModeRelease(mode);
}
}

return r;
}

void MTY_WindowSetTitle(MTY_App *app, MTY_Window window, const char *title)
{
struct window *ctx = app_get_window(app, window);
Expand Down
5 changes: 5 additions & 0 deletions src/unix/linux/android/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,11 @@ float MTY_WindowGetScreenScale(MTY_App *app, MTY_Window window)
return app->scale;
}

uint32_t MTY_WindowGetRefreshRate(MTY_App *app, MTY_Window window)
{
return 60;
}

void MTY_WindowSetTitle(MTY_App *app, MTY_Window window, const char *title)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/unix/linux/x11/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,11 @@ float MTY_WindowGetScreenScale(MTY_App *app, MTY_Window window)
return app->scale;
}

uint32_t MTY_WindowGetRefreshRate(MTY_App *app, MTY_Window window)
{
return 60;
}

void MTY_WindowSetTitle(MTY_App *app, MTY_Window window, const char *title)
{
struct window *ctx = app_get_window(app, window);
Expand Down
5 changes: 5 additions & 0 deletions src/unix/web/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ float MTY_WindowGetScreenScale(MTY_App *app, MTY_Window window)
return app->scale;
}

uint32_t MTY_WindowGetRefreshRate(MTY_App *app, MTY_Window window)
{
return 60;
}

void MTY_WindowSetTitle(MTY_App *app, MTY_Window window, const char *title)
{
web_set_title(title);
Expand Down
15 changes: 15 additions & 0 deletions src/windows/appw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,21 @@ float MTY_WindowGetScreenScale(MTY_App *app, MTY_Window window)
return monitor_get_scale(monitor_from_hwnd(ctx->hwnd));
}

uint32_t MTY_WindowGetRefreshRate(MTY_App *app, MTY_Window window)
{
struct window *ctx = app_get_window(app, window);
if (!ctx)
return 60;

MONITORINFOEX info = monitor_get_info(monitor_from_hwnd(ctx->hwnd));
DEVMODE mode = {.dmSize = sizeof(DEVMODE)};

if (EnumDisplaySettings(info.szDevice, ENUM_CURRENT_SETTINGS, &mode))
return mode.dmDisplayFrequency;

return 60;
}

void MTY_WindowSetTitle(MTY_App *app, MTY_Window window, const char *title)
{
struct window *ctx = app_get_window(app, window);
Expand Down

0 comments on commit c155830

Please sign in to comment.