Skip to content

Commit

Permalink
Center window according to monitor geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
deccer committed Aug 13, 2023
1 parent 142288b commit 1bd7caf
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/EngineKit/Application.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
Expand All @@ -23,7 +22,6 @@ public class Application : IApplication
private readonly IMetrics _metrics;
private readonly IInputProvider _inputProvider;
private readonly ILogger _logger;
private readonly IList<string> _extensions;
private nint _windowHandle;

private GL.GLDebugProc? _debugProcCallback;
Expand Down Expand Up @@ -197,6 +195,11 @@ protected virtual bool Initialize()
var screenHeight = videoMode.Height;
DesiredFramerate = videoMode.RefreshRate;

Glfw.GetMonitorPos(
monitorHandle,
out var monitorLeft,
out var monitorTop);

_applicationContext.ScreenSize = new Point(screenWidth, screenHeight);
_applicationContext.WindowSize = windowResizable
? new Point(_windowSettings.Value.ResolutionWidth, _windowSettings.Value.ResolutionHeight)
Expand Down Expand Up @@ -277,12 +280,12 @@ protected virtual bool Initialize()
{
Glfw.SetWindowPos(
_windowHandle,
screenWidth / 2 - _applicationContext.WindowSize.X / 2,
screenHeight / 2 - _applicationContext.WindowSize.Y / 2);
screenWidth / 2 - _applicationContext.WindowSize.X / 2 + monitorLeft,
screenHeight / 2 - _applicationContext.WindowSize.Y / 2 + monitorTop);
}
else
{
Glfw.SetWindowPos(_windowHandle, 0,0);
Glfw.SetWindowPos(_windowHandle, monitorLeft, monitorTop);
}

Glfw.GetFramebufferSize(
Expand Down

0 comments on commit 1bd7caf

Please sign in to comment.