Fixes #787. Console default size is always restored on Driver Init.

This commit is contained in:
BDisp
2020-07-16 15:43:40 +01:00
parent 496e9aa7f4
commit 9a43fe87f6
2 changed files with 22 additions and 23 deletions

View File

@@ -439,6 +439,23 @@ namespace Terminal.Gui {
}
}
[DllImport ("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow ();
[DllImport ("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool ShowWindow (IntPtr hWnd, int nCmdShow);
public const int HIDE = 0;
public const int MAXIMIZE = 3;
public const int MINIMIZE = 6;
public const int RESTORE = 9;
internal void ShowWindow (int state)
{
IntPtr thisConsole = GetConsoleWindow ();
ShowWindow (thisConsole, state);
}
#if false // See: https://github.com/migueldeicaza/gui.cs/issues/357
[StructLayout (LayoutKind.Sequential)]
public struct SMALL_RECT {
@@ -495,30 +512,15 @@ namespace Terminal.Gui {
public override int Rows => rows;
public WindowsDriver ()
{
Initialize ();
}
public WindowsDriver (int cols, int rows)
{
this.cols = cols;
this.rows = rows;
Initialize ();
}
void Initialize ()
{
winConsole = new WindowsConsole ();
SetupColorsAndBorders ();
if (cols == 0 && rows == 0) {
cols = Console.WindowWidth;
rows = Console.WindowHeight;
} else {
Console.SetWindowSize (cols, rows);
}
cols = Console.WindowWidth;
rows = Console.WindowHeight;
winConsole.ShowWindow (WindowsConsole.RESTORE);
WindowsConsole.SmallRect.MakeEmpty (ref damageRegion);
ResizeScreen ();

View File

@@ -161,7 +161,6 @@ namespace Terminal.Gui {
internal static bool _initialized = false;
static int cols, rows;
static IMainLoopDriver oldMainLoopDriver;
static ConsoleDriver oldDriver;
@@ -189,7 +188,7 @@ namespace Terminal.Gui {
mainLoopDriver = new NetMainLoop (() => Console.ReadKey (true));
Driver = new NetDriver ();
} else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
var windowsDriver = cols == 0 && rows == 0 ? new WindowsDriver () : new WindowsDriver (cols, rows);
var windowsDriver = new WindowsDriver ();
mainLoopDriver = windowsDriver;
Driver = windowsDriver;
} else {
@@ -557,8 +556,6 @@ namespace Terminal.Gui {
}
last?.PositionCursor ();
Driver.Refresh ();
cols = Driver.Cols;
rows = Driver.Rows;
}
internal static void End (View view, bool closeDriver = true)