Skip to content

Commit 3cf083a

Browse files
Add API for getting current IClydeMonitor (space-wizards#6615)
1 parent 3c6a024 commit 3cf083a

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

Robust.Client/Graphics/Clyde/Clyde.Windowing.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ public void SetWindowMonitor(IClydeMonitor monitor)
290290
_windowing!.WindowSetMonitor(_mainWindow!, monitor);
291291
}
292292

293+
public IClydeMonitor? GetMainWindowMonitor()
294+
{
295+
return GetWindowMonitor(_mainWindow!.Owner!);
296+
}
297+
298+
public IClydeMonitor? GetWindowMonitor(IClydeWindow window)
299+
{
300+
DebugTools.AssertNotNull(_windowing);
301+
302+
var reg = ((WindowHandle)window).Reg;
303+
return _windowing!.WindowGetMonitor(reg);
304+
}
305+
293306
public void RequestWindowAttention()
294307
{
295308
DebugTools.AssertNotNull(_windowing);

Robust.Client/Graphics/Clyde/ClydeHeadless.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ public void SetWindowMonitor(IClydeMonitor monitor)
116116
// Nada.
117117
}
118118

119+
public IClydeMonitor? GetWindowMonitor(IClydeWindow window)
120+
{
121+
return null;
122+
}
123+
124+
public IClydeMonitor? GetMainWindowMonitor()
125+
{
126+
return null;
127+
}
128+
119129
public void RequestWindowAttention()
120130
{
121131
// Nada.

Robust.Client/Graphics/Clyde/Windowing/IWindowingImpl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private interface IWindowingImpl
3939
void WindowDestroy(WindowReg reg);
4040
void WindowSetTitle(WindowReg window, string title);
4141
void WindowSetMonitor(WindowReg window, IClydeMonitor monitor);
42+
IClydeMonitor? WindowGetMonitor(WindowReg window);
4243
void WindowSetSize(WindowReg window, Vector2i size);
4344
void WindowSetVisible(WindowReg window, bool visible);
4445
void WindowSetRelativeMouseMode(WindowReg window, bool enabled);

Robust.Client/Graphics/Clyde/Windowing/Sdl3.Window.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Numerics;
34
using System.Runtime.CompilerServices;
45
using System.Threading.Tasks;
@@ -426,6 +427,13 @@ public void WindowSetMonitor(WindowReg window, IClydeMonitor monitor)
426427
_sawmill.Warning("WindowSetMonitor not implemented on SDL3");
427428
}
428429

430+
public IClydeMonitor? WindowGetMonitor(WindowReg window)
431+
{
432+
var displayId = SDL.SDL_GetDisplayForWindow(WinPtr(window));
433+
var monitorId = GetMonitorIdFromDisplayId(displayId);
434+
return _clyde._monitorHandles.GetValueOrDefault(monitorId);
435+
}
436+
429437
public void WindowSetSize(WindowReg window, Vector2i size)
430438
{
431439
SendCmd(new CmdWinSetSize { Window = WinPtr(window), W = size.X, H = size.Y });

Robust.Client/Graphics/IClyde.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public interface IClyde
3737
void SetWindowTitle(string title);
3838
void SetWindowMonitor(IClydeMonitor monitor);
3939

40+
/// <summary>
41+
/// Gets the monitor the specified window is currently on.
42+
/// </summary>
43+
IClydeMonitor? GetWindowMonitor(IClydeWindow window);
44+
45+
/// <summary>
46+
/// Gets the monitor the main game window is currently on.
47+
/// </summary>
48+
IClydeMonitor? GetMainWindowMonitor();
49+
4050
/// <summary>
4151
/// This is the magic method to make the game window ping you in the task bar.
4252
/// </summary>

0 commit comments

Comments
 (0)