Skip to content

Commit 1bd7caf

Browse files
committed
Center window according to monitor geometry
1 parent 142288b commit 1bd7caf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/EngineKit/Application.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.Runtime.InteropServices;
54
using System.Threading;
@@ -23,7 +22,6 @@ public class Application : IApplication
2322
private readonly IMetrics _metrics;
2423
private readonly IInputProvider _inputProvider;
2524
private readonly ILogger _logger;
26-
private readonly IList<string> _extensions;
2725
private nint _windowHandle;
2826

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

198+
Glfw.GetMonitorPos(
199+
monitorHandle,
200+
out var monitorLeft,
201+
out var monitorTop);
202+
200203
_applicationContext.ScreenSize = new Point(screenWidth, screenHeight);
201204
_applicationContext.WindowSize = windowResizable
202205
? new Point(_windowSettings.Value.ResolutionWidth, _windowSettings.Value.ResolutionHeight)
@@ -277,12 +280,12 @@ protected virtual bool Initialize()
277280
{
278281
Glfw.SetWindowPos(
279282
_windowHandle,
280-
screenWidth / 2 - _applicationContext.WindowSize.X / 2,
281-
screenHeight / 2 - _applicationContext.WindowSize.Y / 2);
283+
screenWidth / 2 - _applicationContext.WindowSize.X / 2 + monitorLeft,
284+
screenHeight / 2 - _applicationContext.WindowSize.Y / 2 + monitorTop);
282285
}
283286
else
284287
{
285-
Glfw.SetWindowPos(_windowHandle, 0,0);
288+
Glfw.SetWindowPos(_windowHandle, monitorLeft, monitorTop);
286289
}
287290

288291
Glfw.GetFramebufferSize(

0 commit comments

Comments
 (0)