Skip to content

Commit

Permalink
[WPF] Allows setting the WPF control background when setting the term…
Browse files Browse the repository at this point in the history
…inal theme (#10026)

When syncing terminals across users (i.e. Liveshare shared terminals),
the terminal size is synced. This leads to having unused space around
the terminal which is the same color as the terminal's background
causing confusion as to what space is usable within the terminal.

Instead this change allows consumers to set the background color of the
control, separate from the terminal renderer's background, which makes
it easier to identify the edges of the terminal.
  • Loading branch information
javierdlg committed May 4, 2021
1 parent ac265aa commit 31414aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public ITerminalConnection Connection
/// <param name="theme">The color theme to use in the terminal.</param>
/// <param name="fontFamily">The font family to use in the terminal.</param>
/// <param name="fontSize">The font size to use in the terminal.</param>
public void SetTheme(TerminalTheme theme, string fontFamily, short fontSize)
/// <param name="externalBackground">Color for the control background when the terminal window is smaller than the hosting WPF window.</param>
public void SetTheme(TerminalTheme theme, string fontFamily, short fontSize, Color externalBackground = default)
{
PresentationSource source = PresentationSource.FromVisual(this);

Expand All @@ -92,7 +93,12 @@ public void SetTheme(TerminalTheme theme, string fontFamily, short fontSize)
byte g = Convert.ToByte((theme.DefaultBackground >> 8) & 0xff);
byte r = Convert.ToByte(theme.DefaultBackground & 0xff);

this.terminalGrid.Background = new SolidColorBrush(Color.FromRgb(r, g, b));
// Set the background color for the control only if one is provided.
// This is only shown when the terminal renderer is smaller than the enclosing WPF window.
if (externalBackground != default)
{
this.Background = new SolidColorBrush(externalBackground);
}
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/WpfTerminalControl/TerminalTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Microsoft.Terminal.Wpf
{
using System;
using System.Runtime.InteropServices;

/// <summary>
Expand Down

0 comments on commit 31414aa

Please sign in to comment.