diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 5a4d726..fc27ba9 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -7,6 +7,8 @@ English (US) release notes, mirroring CHANGELOG.md (Brazilian Portuguese). Befor - TV: an optional **Command when going back to the PC** is sent to the TV when the desk comes back, before standby, to take it to its Home screen or another input instead of only turning it off (asked by PLEXX-DE, issue #209). (#213) ### Changes - TV control (Google TV / Android TV over the network) is back: the **TV** category returns to the System tab and sessions again turn the TV on, switch it to the PC's input (also with your own **Input command**) and, if chosen, put it in standby on the way back. Anyone who set it up in 1.6 finds it as they left it. (#208) +### 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 c36f672..d2c1466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ Notas em português do Brasil; a versão em inglês (Estados Unidos) fica em `CH - TV: um **Comando ao voltar ao PC** opcional vai para a TV quando a mesa volta, antes da espera, para levá-la à tela inicial ou a outra entrada em vez de só desligar (pedido do PLEXX-DE, issue #209). (#213) ### Mudanças - O controle da TV (Google TV / Android TV pela rede) volta: a categoria **TV** reaparece na aba Sistema e a sessão volta a ligar a TV, trocar para a entrada do PC (inclusive com um **Comando de entrada** próprio) e, se escolhido, colocá-la em espera na volta. Quem já tinha configurado na 1.6 encontra tudo como deixou. (#208) +### 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 a590d69..6e7c4aa 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -547,6 +547,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: ______ + ## Comando na TV ao voltar ao PC (#213, issue #209) - [ ] Android TV configurada, **Comando ao voltar ao PC** = `input keyevent 3`, espera desligada: ao voltar ao PC a TV vai para a tela inicial e continua ligada. O log tem "TV: voltar ao PC (androidTv) ok". Resultado: ______ diff --git a/src/ConsoleMode/Services/ConsoleEngine.GameProfiles.cs b/src/ConsoleMode/Services/ConsoleEngine.GameProfiles.cs index 55a5986..c24c5f7 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 0000000..bcac80b --- /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 ae6fade..f325768 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 4e15325..f1c7c24 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 0000000..2e3e317 --- /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)); +}