Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wpf: add width/height checks when resizing the terminal #7983

Merged
3 commits merged into from
Oct 27, 2020
Merged
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
22 changes: 20 additions & 2 deletions src/cascadia/WpfTerminalControl/TerminalContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ internal void SetTheme(TerminalTheme theme, string fontFamily, short fontSize)

NativeMethods.TerminalSetTheme(this.terminal, theme, fontFamily, fontSize, (int)dpiScale.PixelsPerInchX);

this.Resize(this.TerminalControlSize);
if (!this.RenderSize.IsEmpty)
{
this.Resize(this.TerminalControlSize);
}
}

/// <summary>
Expand All @@ -161,6 +164,11 @@ internal string GetSelectedText()
/// <param name="renderSize">Size of the rendering window.</param>
internal void Resize(Size renderSize)
{
if (renderSize.Width == 0 || renderSize.Height == 0)
{
throw new ArgumentException(nameof(renderSize), "Terminal column or row count cannot be 0.");
}

NativeMethods.TerminalTriggerResize(
this.terminal,
Convert.ToInt16(renderSize.Width),
Expand All @@ -181,6 +189,15 @@ internal void Resize(Size renderSize)
/// <param name="columns">Number of columns to show.</param>
internal void 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
{
Expand Down Expand Up @@ -343,7 +360,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;
}
Expand Down