Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ConsoleMode/Services/DisplayModeMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ namespace ConsoleMode.Services;
/// Whether the mode a screen is in is the one asked for. TVs and their drivers run the "60 Hz" of video at
/// 59.94 Hz and list both: asking for 2560x1440@60 can leave the TV at @59 (the owner's LG through NVIDIA did),
/// which is that mode, not a failure. Treating it as one made the session re-apply the mode twice (the TV going
/// blank each time) and log that it couldn't. Pure, so it's tested.
/// blank each time) and log that it couldn't. Only that way round: a screen at @60 when @59 was picked is in a
/// different mode from the list, so that one is still applied. Pure, so it's tested.
/// </summary>
public static class DisplayModeMatch
{
/// <summary>Same size, and a refresh rate within 1 Hz (59/60, 23/24, 29/30, 119/120, 143/144…); 0 = any.</summary>
/// <summary>Same size, and the rate asked for or the video one just under it (60→59, 24→23, 30→29, 120→119, 144→143); 0 = any.</summary>
public static bool IsSame(int wantedWidth, int wantedHeight, int wantedHz, int width, int height, int hz)
{
if (wantedWidth > 0 && width != wantedWidth) return false;
if (wantedHeight > 0 && height != wantedHeight) return false;
return wantedHz <= 0 || Math.Abs(hz - wantedHz) <= 1;
return wantedHz <= 0 || hz == wantedHz || hz == wantedHz - 1;
}
}
3 changes: 3 additions & 0 deletions tests/ConsoleMode.Tests/DisplayModeMatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class DisplayModeMatchTests
// A different rate or size is not the mode asked for.
[InlineData(2560, 1440, 60, 2560, 1440, 50, false)]
[InlineData(1920, 1080, 120, 1920, 1080, 60, false)]
// A screen at @60 when @59 was picked (a separate mode in the list) is not there yet.
[InlineData(2560, 1440, 59, 2560, 1440, 60, false)]
[InlineData(3840, 2160, 23, 3840, 2160, 24, false)]
[InlineData(2560, 1440, 60, 3840, 2160, 60, false)]
[InlineData(2560, 1440, 60, 2560, 1600, 60, false)]
// 0 = any (a mode saved without a rate, or only a rate).
Expand Down
Loading