From 308844667b85480850df057b207b69667158c592 Mon Sep 17 00:00:00 2001 From: Javier De la Garza Sanchez Date: Tue, 20 Oct 2020 14:16:22 -0700 Subject: [PATCH 1/2] Added checks when resizing the terminal --- .../WpfTerminalControl/TerminalContainer.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cascadia/WpfTerminalControl/TerminalContainer.cs b/src/cascadia/WpfTerminalControl/TerminalContainer.cs index b242faa0f14..3c7f0b163df 100644 --- a/src/cascadia/WpfTerminalControl/TerminalContainer.cs +++ b/src/cascadia/WpfTerminalControl/TerminalContainer.cs @@ -139,7 +139,10 @@ internal void SetTheme(TerminalTheme theme, string fontFamily, short fontSize) NativeMethods.TerminalSetTheme(this.terminal, theme, fontFamily, fontSize, (int)dpiScale.PixelsPerInchX); - this.TriggerResize(this.RenderSize); + if (!this.RenderSize.IsEmpty) + { + this.TriggerResize(this.RenderSize); + } } /// @@ -163,6 +166,11 @@ internal string GetSelectedText() /// Tuple with rows and columns. internal (int rows, int columns) TriggerResize(Size renderSize) { + if (renderSize.Width == 0 || renderSize.Height == 0) + { + throw new ArgumentException(nameof(renderSize), "Terminal column or row count cannot be 0."); + } + var dpiScale = VisualTreeHelper.GetDpi(this); NativeMethods.COORD dimensions; @@ -187,6 +195,15 @@ internal string GetSelectedText() /// pair with the new width and height size in pixels for the renderer. internal (int width, int height) Resize(uint rows, uint columns) { + if (rows == 0) + { + throw new ArgumentException(nameof(rows), "Terminal row count cannot be 0."); + } + else if (columns == 0) + { + throw new ArgumentException(nameof(columns), "Terminal column count cannot be 0."); + } + NativeMethods.SIZE dimensionsInPixels; NativeMethods.COORD dimensions = new NativeMethods.COORD { @@ -328,7 +345,8 @@ private IntPtr TerminalContainer_MessageHook(IntPtr hwnd, int msg, IntPtr wParam case NativeMethods.WindowMessage.WM_WINDOWPOSCHANGED: var windowpos = (NativeMethods.WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(NativeMethods.WINDOWPOS)); - if (((NativeMethods.SetWindowPosFlags)windowpos.flags).HasFlag(NativeMethods.SetWindowPosFlags.SWP_NOSIZE)) + if (((NativeMethods.SetWindowPosFlags)windowpos.flags).HasFlag(NativeMethods.SetWindowPosFlags.SWP_NOSIZE) + || (windowpos.cx == 0 && windowpos.cy == 0)) { break; } From 5b0ba5c7c9d320c10be1bccfbb0c26711254df48 Mon Sep 17 00:00:00 2001 From: Javier De la Garza Sanchez Date: Fri, 23 Oct 2020 09:34:54 -0700 Subject: [PATCH 2/2] Removed bad merge line --- src/cascadia/WpfTerminalControl/TerminalContainer.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cascadia/WpfTerminalControl/TerminalContainer.cs b/src/cascadia/WpfTerminalControl/TerminalContainer.cs index 5f67bc9afef..1e553bb95b0 100644 --- a/src/cascadia/WpfTerminalControl/TerminalContainer.cs +++ b/src/cascadia/WpfTerminalControl/TerminalContainer.cs @@ -169,8 +169,6 @@ internal void Resize(Size renderSize) throw new ArgumentException(nameof(renderSize), "Terminal column or row count cannot be 0."); } - var dpiScale = VisualTreeHelper.GetDpi(this); - NativeMethods.TerminalTriggerResize( this.terminal, Convert.ToInt16(renderSize.Width),