Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Skyline.Apple/AppKitWindowBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ private void UpdateDrawableSize()
}
}

public double RefreshRate => (_window.Screen ?? NSScreen.MainScreen)?.MaximumFramesPerSecond ?? 60;

public string Title
{
get => _window.Title;
Expand Down
7 changes: 7 additions & 0 deletions src/Skyline/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ public string? ClipboardText
set => _backend.ClipboardText = value;
}

/// <summary>
/// The display's refresh rate in Hz. Pace animation to this. On macOS it
/// is the window's screen rate; on GLFW it is the window's monitor rate
/// when known (set in fullscreen), otherwise 60.
/// </summary>
public double RefreshRate => _backend.RefreshRate;

public FrameInfo CurrentFrame => Frame(0);

/// <summary>True when this window has been adopted by an <see cref="AppHost"/>. Hosted windows render on the host's thread, so use <c>AppHost.Run</c>, not <see cref="Run"/>.</summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Skyline/GlfwWindowBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public unsafe GlfwWindowBackend(AppWindowOptions options)
public (int Width, int Height) FramebufferSize => (_window.FramebufferSize.X, _window.FramebufferSize.Y);
public (int Width, int Height) LogicalSize => (_window.Size.X, _window.Size.Y);

// The window's monitor when GLFW knows it (set in fullscreen), else 60.
public double RefreshRate => _window.Monitor?.VideoMode.RefreshRate ?? 60;

public string Title
{
get => _window.Title;
Expand Down
3 changes: 3 additions & 0 deletions src/Skyline/IWindowBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ internal interface IWindowBackend : IDisposable
/// <summary>Window size in logical points.</summary>
(int Width, int Height) LogicalSize { get; }

/// <summary>The display's refresh rate in Hz, for pacing animation.</summary>
double RefreshRate { get; }

string Title { get; set; }
string? ClipboardText { get; set; }

Expand Down
1 change: 1 addition & 0 deletions tests/Skyline.Tests/WindowBackendFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private sealed class FakeBackend : IWindowBackend
{
public (int Width, int Height) FramebufferSize => (200, 100);
public (int Width, int Height) LogicalSize => (100, 50);
public double RefreshRate => 60;
public string Title { get; set; } = "fake";
public string? ClipboardText { get; set; }
public bool IsClosing => false;
Expand Down
2 changes: 2 additions & 0 deletions tests/Skyline.WindowedTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void Check(bool condition, string what)
Check(frame.Dpr > 0, "CurrentFrame has a device pixel ratio");
Check(Math.Abs(frame.LogicalWidth - frame.PixelWidth / frame.Dpr) < 0.01, "logical width derives from Dpr");
Check(win.Surface is not null, "native surface source is exposed");
Check(win.RefreshRate > 0, "RefreshRate reports a positive display rate");

win.ClipboardText = "skyline-test";
Check(win.ClipboardText == "skyline-test", "clipboard round-trips");
Expand All @@ -58,6 +59,7 @@ void Check(bool condition, string what)
});
var cf = chromed.CurrentFrame;
Check(cf.PixelWidth > 0 && cf.PixelHeight > 0, $"{chrome} window constructs with a real surface");
Check(chromed.RefreshRate > 0, $"{chrome} GLFW window reports a refresh rate");
}

var soloResized = false;
Expand Down