From 7b7b7d8b1d2318d436adbe0546826b4fe7cc6283 Mon Sep 17 00:00:00 2001 From: Filipe Moreira Date: Tue, 29 Sep 2026 10:06:11 -0300 Subject: [PATCH] fix: primary display from Windows' own flag; embed only rtss-cli - MonitorInfo.IsPrimary was "active and at (0,0)", ambiguous when screens are cloned (several share the origin). It now uses MONITORINFOF_PRIMARY through NativeDisplays.IsPrimary. - The csproj embedded artifacts/tools/*.exe, so a leftover MultiMonitorTool/SoundVolumeView from an older build ended up inside the exe (never extracted, just dead weight). It embeds rtss-cli*.exe only; CI is unaffected (it never had the others). Co-Authored-By: Claude Sonnet 5.5 --- src/ConsoleMode/ConsoleMode.csproj | 2 +- src/ConsoleMode/Native/NativeDisplays.cs | 9 +++++++++ src/ConsoleMode/Services/DisplayBackend.cs | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ConsoleMode/ConsoleMode.csproj b/src/ConsoleMode/ConsoleMode.csproj index ea0eb43..c6ce683 100644 --- a/src/ConsoleMode/ConsoleMode.csproj +++ b/src/ConsoleMode/ConsoleMode.csproj @@ -39,7 +39,7 @@ - + diff --git a/src/ConsoleMode/Native/NativeDisplays.cs b/src/ConsoleMode/Native/NativeDisplays.cs index d9a70aa..f64c5cc 100644 --- a/src/ConsoleMode/Native/NativeDisplays.cs +++ b/src/ConsoleMode/Native/NativeDisplays.cs @@ -253,6 +253,15 @@ private static (string Friendly, string DevicePath) GetTargetName(LUID adapterId : ("", ""); } + /// Windows' own primary flag (MONITORINFOF_PRIMARY); position (0,0) is ambiguous when screens are cloned. + public static bool IsPrimary(string gdiName) + { + var hMonitor = FindHMonitor(gdiName); + if (hMonitor == 0) return false; + var info = new MONITORINFOEX { cbSize = Marshal.SizeOf() }; + return GetMonitorInfo(hMonitor, ref info) && (info.dwFlags & 1) != 0; + } + private static nint FindHMonitor(string gdiName) { nint found = 0; diff --git a/src/ConsoleMode/Services/DisplayBackend.cs b/src/ConsoleMode/Services/DisplayBackend.cs index d8c38a8..0d0d4c1 100644 --- a/src/ConsoleMode/Services/DisplayBackend.cs +++ b/src/ConsoleMode/Services/DisplayBackend.cs @@ -44,7 +44,7 @@ public List ListMonitors() Height = height, Frequency = current?.Frequency > 0 ? current.Frequency.ToString() : "", Colors = current?.BitsPerPel > 0 ? current.BitsPerPel.ToString() : "", - IsPrimary = m.IsActive && m.PositionX == 0 && m.PositionY == 0, + IsPrimary = m.IsActive && NativeDisplays.IsPrimary(m.GdiName), IsActive = m.IsActive, IsDisconnected = !m.IsActive, MonitorName = !string.IsNullOrWhiteSpace(m.FriendlyName) ? m.FriendlyName : edid.Name,