Skip to content

Commit

Permalink
Fix: Core: WoWScreenDXGI: an issue when the game window is placed on …
Browse files Browse the repository at this point in the history
…a non primary monitor.
  • Loading branch information
Xian55 committed Jan 7, 2024
1 parent b2d304e commit fc9a3ae
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions Core/WoWScreen/WowScreenDXGI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public sealed class WowScreenDXGI : IWowScreen, IAddonDataProvider
public Rectangle ScreenRect => screenRect;
private Rectangle screenRect;

private readonly Vortice.RawRect monitorRect;

public Image<Bgra32> ScreenImage { get; init; }

private readonly SixLabors.ImageSharp.Configuration ContiguousJpegConfiguration
Expand Down Expand Up @@ -88,8 +90,6 @@ public WowScreenDXGI(ILogger<WowScreenDXGI> logger,
Bgra32Size = Unsafe.SizeOf<Bgra32>();

GetRectangle(out screenRect);
windowedMode = IsWindowedMode(screenRect.Location);

ScreenImage = new(ContiguousJpegConfiguration, screenRect.Width, screenRect.Height);

MiniMapRect = new(0, 0, MiniMapSize, MiniMapSize);
Expand All @@ -112,8 +112,22 @@ public WowScreenDXGI(ILogger<WowScreenDXGI> logger,
if (result == Result.Ok &&
output.Description.Monitor == hMonitor)
{
monitorRect = output.Description.DesktopCoordinates;
if ((monitorRect.Right - monitorRect.Left) != screenRect.Width ||
(monitorRect.Bottom - monitorRect.Top) != screenRect.Height)
{
windowedMode = true;
}
else
{
windowedMode = false;
}

NormalizeScreenRect();

break;
}
srcIdx++;
} while (result != Result.Fail);

output1 = output.QueryInterface<IDXGIOutput1>();
Expand Down Expand Up @@ -159,7 +173,9 @@ public WowScreenDXGI(ILogger<WowScreenDXGI> logger,

this.logger.LogInformation($"{screenRect} - " +
$"Windowed Mode: {windowedMode} - " +
$"Scale: {DPI2PPI(GetDpi()):F2}");
$"Scale: {DPI2PPI(GetDpi()):F2} - " +
$"Monitor Rect: {monitorRect} - " +
$"Monitor Index: {srcIdx}");
}

public void Dispose()
Expand Down Expand Up @@ -219,6 +235,7 @@ public void Update()
if (windowedMode)
{
GetRectangle(out screenRect);
NormalizeScreenRect();

// TODO: bounds check
if (screenRect.X < 0 ||
Expand Down Expand Up @@ -382,4 +399,16 @@ public void GetRectangle(out Rectangle rect)
{
NativeMethods.GetWindowRect(process.MainWindowHandle, out rect);
}

private void NormalizeScreenRect()
{
screenRect.X -= monitorRect.Left;
screenRect.Y -= monitorRect.Top;

if (screenRect.X < 0)
screenRect.X = 0;

if (screenRect.Y < 0)
screenRect.Y = 0;
}
}

0 comments on commit fc9a3ae

Please sign in to comment.