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
2 changes: 2 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: ______
Expand Down
3 changes: 2 additions & 1 deletion src/ConsoleMode/Services/ConsoleEngine.GameProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/ConsoleMode/Services/DisplayModeMatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ConsoleMode.Services;

/// <summary>
/// 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.
/// </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>
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;
}
}
14 changes: 8 additions & 6 deletions src/ConsoleMode/Services/MonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<string, string>? spec, int maxAttempts = 3)
Expand Down
1 change: 1 addition & 0 deletions tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<Compile Include="../../src/ConsoleMode/Services/HardwareStats.cs" Link="HardwareStats.cs" />
<Compile Include="../../src/ConsoleMode/Services/AudioNaming.cs" Link="AudioNaming.cs" />
<Compile Include="../../src/ConsoleMode/Services/DisplayIdentity.cs" Link="DisplayIdentity.cs" />
<Compile Include="../../src/ConsoleMode/Services/DisplayModeMatch.cs" Link="DisplayModeMatch.cs" />
<Compile Include="../../src/ConsoleMode/Services/ControllerMapping.cs" Link="ControllerMapping.cs" />
<Compile Include="../../src/ConsoleMode/Services/ControllerShortcuts.cs" Link="ControllerShortcuts.cs" />
<Compile Include="../../src/ConsoleMode/Services/ControllerBattery.cs" Link="ControllerBattery.cs" />
Expand Down
24 changes: 24 additions & 0 deletions tests/ConsoleMode.Tests/DisplayModeMatchTests.cs
Original file line number Diff line number Diff line change
@@ -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));
}
Loading