Skip to content

Commit

Permalink
gh-551: Screen scrambled when pressing Alt-F9 under Windows 11 22H2
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Oct 7, 2022
1 parent e54e3d9 commit e4252fd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 07.10.2022 23:13:59 +0100 - build 6038

1. gh-551: Screen scrambled when pressing Alt-F9 under Windows 11 22H2

--------------------------------------------------------------------------------
drkns 06.10.2022 17:43:00 +0100 - build 6037

Expand Down
36 changes: 35 additions & 1 deletion far/interf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,50 @@ void SetVideoMode()
}
}

static bool validate_console_size(point const Size)
{
// https://github.com/microsoft/terminal/issues/10337

// As of 7 Oct 2022 GetLargestConsoleWindowSize is broken in WT.
// It takes the current screen resolution and divides it by an inadequate font size, e.g. 1x16.

// It is unlikely that it is ever gonna be fixed, so we do a few very basic checks here to filter out obvious rubbish.

if (Size.x <= 0 || Size.y <= 0)
return false;

// A typical screen ratio these days is roughly 2:1.
// A typical font cell is about 1:2, so the expected screen ratio in cells
// is around 4 for the landscape and around 1 for the portrait, give or take.
// Anything twice larger than that is likely rubbish.
if (Size.x >= 8 * Size.y || Size.y >= 2 * Size.x)
return false;

// The API works with SHORTs, anything larger than that makes no sense.
if (Size.x >= std::numeric_limits<SHORT>::max() || Size.y >= std::numeric_limits<SHORT>::max())
return false;

return true;
}

void ChangeVideoMode(bool Maximize)
{
point coordScreen;

if (Maximize)
{
SendMessage(console.GetWindow(),WM_SYSCOMMAND,SC_MAXIMIZE,0);
coordScreen = console.GetLargestWindowSize();

if (!validate_console_size(coordScreen))
{
LOGERROR(L"GetLargestConsoleWindowSize(): the reported size ({{{}, {}}} makes no sense. Talk to your terminal or OS vendor."sv, coordScreen.x, coordScreen.y);
return;
}

coordScreen.x += Global->Opt->ScrSize.DeltaX;
coordScreen.y += Global->Opt->ScrSize.DeltaY;

SendMessage(console.GetWindow(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6037
6038

0 comments on commit e4252fd

Please sign in to comment.