From d6e220ead3820dd7228a67ad3550c2b828f77fcd Mon Sep 17 00:00:00 2001 From: Filipe Moreira Date: Mon, 16 Nov 2026 10:11:04 -0300 Subject: [PATCH] fix: a TV at 59 Hz is in the 60 Hz mode asked for MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Asked for 2560x1440@60, the owner's LG TV (through NVIDIA) ends up at @59, the 59.94 Hz "60" of TVs that it lists next to @60. The check wanted exactly 60, so every session re-applied the mode twice (the TV going blank each time) and logged "Não foi possível aplicar"; a per-game profile saved at @60 re-applied it too. DisplayModeMatch.IsSame allows 1 Hz either way; the log now says which mode the screen is in. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.en-US.md | 2 ++ CHANGELOG.md | 2 ++ docs/TESTING.md | 6 +++++ .../Services/ConsoleEngine.GameProfiles.cs | 3 ++- src/ConsoleMode/Services/DisplayModeMatch.cs | 18 ++++++++++++++ src/ConsoleMode/Services/MonitorService.cs | 14 ++++++----- .../ConsoleMode.Tests.csproj | 1 + .../DisplayModeMatchTests.cs | 24 +++++++++++++++++++ 8 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/ConsoleMode/Services/DisplayModeMatch.cs create mode 100644 tests/ConsoleMode.Tests/DisplayModeMatchTests.cs diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 786a7f59..882817a0 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -3,6 +3,8 @@ English (US) release notes, mirroring CHANGELOG.md (Brazilian Portuguese). Before publishing a version, add a `## [VERSION]` section to **both** files: the workflow publishes the section matching the tag from each one and fails if either is missing. ## [Unreleased] +### Fixes +- Game screen resolution: a TV left at @59 Hz when @60 is asked for (the "60 Hz" of TVs, 59.94) counts as in the mode asked for. Before, Console Mode re-applied the mode twice at the start of every session, the TV going blank each time, and logged that it couldn't; per-game profiles re-applied it too. The log now says which mode the screen ended up in. (#212) ## [1.7.0] ### What's new diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f24bc4..e9b6b91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Notas em português do Brasil; a versão em inglês (Estados Unidos) fica em `CHANGELOG.en-US.md`. Antes de publicar uma versão, adicione uma seção `## [VERSÃO]` com o changelog daquela versão **nos dois arquivos**. O workflow publica as duas seções correspondentes à tag na mesma release e falha se faltar alguma. ## [Unreleased] +### Correções +- Resolução da tela de jogo: uma TV que fica em @59 Hz quando se pede @60 (o "60 Hz" de TV, 59,94) conta como no modo pedido. Antes o Console Mode reaplicava o modo mais duas vezes no início de toda sessão, com a TV apagando a cada vez, e registrava que não tinha conseguido; o perfil por jogo também reaplicava. O log agora diz em que modo a tela ficou. (#212) ## [1.7.0] ### Novidades diff --git a/docs/TESTING.md b/docs/TESTING.md index 6c281a9d..9eb37f26 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -541,6 +541,12 @@ Pré-requisito: RivaTuner Statistics Server instalado, com "Show On-Screen Displ - [ ] Com a sessão ativa e a opção ligada, minimizar e reabrir pela bandeja continua funcionando; o atalho do controle para abrir o app também traz a janela de volta. - [ ] Fechar no X (sem sessão ativa) continua fechando o app, com a opção ligada ou desligada. +## Resolução da TV a 59/60 Hz (#212) + +- [ ] TV como tela de jogo com 2560x1440 @ 60 Hz em Sistema: a sessão começa e a TV muda de resolução **uma vez só** (sem apagar duas ou três vezes). O log tem "Telas: ... em 2560x1440@59 (pedido 2560x1440@60)" ou "@60", e nenhum "Não foi possível aplicar". Resultado: ______ +- [ ] O mesmo com 3840x2160 @ 60 e com "Não alterar": nada muda para pior. Resultado: ______ +- [ ] Perfil por jogo salvo com @60: abrir o jogo com a TV já em @59 não faz a TV piscar. Resultado: ______ + ## Interface Console no estilo console (1.7.0) ### Início diff --git a/src/ConsoleMode/Services/ConsoleEngine.GameProfiles.cs b/src/ConsoleMode/Services/ConsoleEngine.GameProfiles.cs index 55a59862..c24c5f74 100644 --- a/src/ConsoleMode/Services/ConsoleEngine.GameProfiles.cs +++ b/src/ConsoleMode/Services/ConsoleEngine.GameProfiles.cs @@ -85,7 +85,8 @@ private void Apply(SavedDisplayMode? mode, bool? hdr, int? fpsLimit, string? aud if (mode is { Width: > 0, Height: > 0 }) { var current = NativeWindows.GetCurrentDisplayMode(focus); - if (current is null || current.Width != mode.Width || current.Height != mode.Height || current.Frequency != mode.Frequency) + // A TV at @59 for a profile saved at @60 is already there: re-applying would only blank it. + if (current is null || !DisplayModeMatch.IsSame(mode.Width, mode.Height, mode.Frequency, current.Width, current.Height, current.Frequency)) Try("resolução", () => { Monitors.ApplyFocusMode(focus, mode); diff --git a/src/ConsoleMode/Services/DisplayModeMatch.cs b/src/ConsoleMode/Services/DisplayModeMatch.cs new file mode 100644 index 00000000..bcac80b1 --- /dev/null +++ b/src/ConsoleMode/Services/DisplayModeMatch.cs @@ -0,0 +1,18 @@ +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. +/// +public static class DisplayModeMatch +{ + /// Same size, and a refresh rate within 1 Hz (59/60, 23/24, 29/30, 119/120, 143/144…); 0 = any. + 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; + } +} diff --git a/src/ConsoleMode/Services/MonitorService.cs b/src/ConsoleMode/Services/MonitorService.cs index ae6fade9..f3257682 100644 --- a/src/ConsoleMode/Services/MonitorService.cs +++ b/src/ConsoleMode/Services/MonitorService.cs @@ -339,8 +339,13 @@ public void ApplyFocusMode(string focusMonitor, SavedDisplayMode mode) Thread.Sleep(400); } + // What it really is in: the "@59" of a TV asked for "@60" is said, and a real failure says where it stayed. + var now = NativeWindows.GetCurrentDisplayMode(focusMonitor); + var shown = now is null ? "sem modo atual" : $"{now.Width}x{now.Height}@{now.Frequency}"; if (!IsCurrentMode(focusMonitor, mode.Width, mode.Height, mode.Frequency)) - AppLog.Write($"Não foi possível aplicar {mode.Width}x{mode.Height}@{mode.Frequency} em {focusMonitor}"); + AppLog.Write($"Não foi possível aplicar {mode.Width}x{mode.Height}@{mode.Frequency} em {focusMonitor} (ficou em {shown})"); + else + AppLog.Write($"Telas: {focusMonitor} em {shown} (pedido {mode.Width}x{mode.Height}@{mode.Frequency})"); SetPrimary(focusMonitor); Thread.Sleep(300); @@ -416,11 +421,8 @@ private void SetMonitorMode(string name, int width, int height, int frequency, s private bool IsCurrentMode(string name, int width, int height, int frequency) { var current = NativeWindows.GetCurrentDisplayMode(name); - if (current is null) return false; - if (width > 0 && current.Width != width) return false; - if (height > 0 && current.Height != height) return false; - if (frequency > 0 && current.Frequency != frequency) return false; - return true; + return current is not null + && DisplayModeMatch.IsSame(width, height, frequency, current.Width, current.Height, current.Frequency); } private bool RestorePrimaryWithRetry(string monitorName, Dictionary? spec, int maxAttempts = 3) diff --git a/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj b/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj index 4e153252..f1c7c245 100644 --- a/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj +++ b/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj @@ -42,6 +42,7 @@ + diff --git a/tests/ConsoleMode.Tests/DisplayModeMatchTests.cs b/tests/ConsoleMode.Tests/DisplayModeMatchTests.cs new file mode 100644 index 00000000..2e3e317d --- /dev/null +++ b/tests/ConsoleMode.Tests/DisplayModeMatchTests.cs @@ -0,0 +1,24 @@ +using ConsoleMode.Services; + +namespace ConsoleMode.Tests; + +public class DisplayModeMatchTests +{ + [Theory] + // The owner's LG TV through NVIDIA: asked for 2560x1440@60, Windows puts it at @59 (59.94 Hz). + [InlineData(2560, 1440, 60, 2560, 1440, 59, true)] + [InlineData(2560, 1440, 60, 2560, 1440, 60, true)] + [InlineData(3840, 2160, 24, 3840, 2160, 23, true)] + [InlineData(1920, 1080, 120, 1920, 1080, 119, true)] + [InlineData(1920, 1080, 144, 1920, 1080, 143, true)] + // 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)] + [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). + [InlineData(2560, 1440, 0, 2560, 1440, 59, true)] + [InlineData(0, 0, 60, 3840, 2160, 59, true)] + public void A_screen_is_in_the_mode_asked_for(int w, int h, int hz, int curW, int curH, int curHz, bool same) => + Assert.Equal(same, DisplayModeMatch.IsSame(w, h, hz, curW, curH, curHz)); +}