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

Enable Vintage Opacity #11180

Merged
26 commits merged into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
40cc30a
This is what jevan told me to do, but I don't have the right SDK
zadjii-msft Aug 26, 2021
b2a217e
Hey this _did_ work!
zadjii-msft Aug 26, 2021
4ce85b7
This did nothing honestly. Just a dead end
zadjii-msft Aug 30, 2021
f959507
HOLY SHIT IT WORKED
zadjii-msft Sep 7, 2021
548a00b
tiny cleanup
zadjii-msft Sep 7, 2021
fa64eed
Start working on a setting for this, which obviously doesn't work yet
zadjii-msft Sep 7, 2021
5adb068
This sorta fixes it on init. Sorta. Defaults to 50% tho?
zadjii-msft Sep 7, 2021
ef91af9
fix some weird windowing issues
zadjii-msft Sep 7, 2021
492e22d
fix the actual setting of this valuie
zadjii-msft Sep 7, 2021
cc91b01
This substantially simplifies wheeling opacity
zadjii-msft Sep 7, 2021
dfa94c9
fix pane animations, SUI background
zadjii-msft Sep 7, 2021
cb4f58d
In retrospect, I hate doing it this way
zadjii-msft Sep 7, 2021
d16fa55
Revert "In retrospect, I hate doing it this way"
zadjii-msft Sep 7, 2021
8e14c14
fix the percentage converter, default value
zadjii-msft Sep 8, 2021
c5518d4
add back to the SUI
zadjii-msft Sep 8, 2021
f97efcc
I suppose this works for the titlebar in fomo
zadjii-msft Sep 8, 2021
6b5d03b
update schema, actually fix the default values.
zadjii-msft Sep 8, 2021
5df299c
bump package version
zadjii-msft Sep 8, 2021
16f5c3b
wow one typo is a record low for me
zadjii-msft Sep 8, 2021
62ddb32
These are the PR nits
zadjii-msft Sep 9, 2021
3f90543
poop
zadjii-msft Sep 9, 2021
6c59118
Merge remote-tracking branch 'origin/main' into dev/migrie/f/603-it-w…
zadjii-msft Sep 14, 2021
9e29769
at least it builds
zadjii-msft Sep 14, 2021
3e41b6f
fix the tests
zadjii-msft Sep 14, 2021
39a3809
Merge remote-tracking branch 'origin/main' into dev/migrie/f/603-it-w…
zadjii-msft Sep 16, 2021
f0563e6
carlos nits
zadjii-msft Sep 16, 2021
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
10 changes: 9 additions & 1 deletion doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,8 @@
"properties": {
"acrylicOpacity": {
"default": 0.5,
"description": "When useAcrylic is set to true, it sets the transparency of the window for the profile. Accepts floating point values from 0-1 (default 0.5).",
"description": "[deprecated] Please use `opacity` instead.",
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
"deprecated": true,
"maximum": 1,
"minimum": 0,
"type": "number"
Expand Down Expand Up @@ -1614,6 +1615,13 @@
"minLength": 1,
"type": "string"
},
"opacity": {
"default": 100,
"description": "Sets the opacity of the window for the profile. Accepts values from 0-100. Defaults to 50 when useAcrylic is set to true.",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"padding": {
"default": "8, 8, 8, 8",
"description": "Sets the padding around the text within the window. Can have three different formats:\n -\"#\" sets the same padding for all sides \n -\"#, #\" sets the same padding for left-right and top-bottom\n -\"#, #, #, #\" sets the padding individually for left, top, right, and bottom.",
Expand Down
2 changes: 1 addition & 1 deletion scratch/ScratchIslandApp/SampleApp/MySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace winrt::SampleApp::implementation

WINRT_PROPERTY(winrt::hstring, ProfileName);
WINRT_PROPERTY(bool, UseAcrylic, false);
WINRT_PROPERTY(double, TintOpacity, 0.5);
WINRT_PROPERTY(double, Opacity, .5);
WINRT_PROPERTY(winrt::hstring, Padding, DEFAULT_PADDING);
WINRT_PROPERTY(winrt::hstring, FontFace, L"Consolas");
WINRT_PROPERTY(int32_t, FontSize, DEFAULT_FONT_SIZE);
Expand Down
25 changes: 19 additions & 6 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ Pane::Pane(const Profile& profile, const TermControl& control, const bool lastFo
_SetupResources();
}

// Use the unfocused border color as the pane background, so an actual color
// appears behind panes as we animate them sliding in.
_root.Background(s_unfocusedBorderBrush);

// Register an event with the control to have it inform us when it gains focus.
_gotFocusRevoker = _control.GotFocus(winrt::auto_revoke, { this, &Pane::_ControlGotFocusHandler });
_lostFocusRevoker = _control.LostFocus(winrt::auto_revoke, { this, &Pane::_ControlLostFocusHandler });
Expand Down Expand Up @@ -1616,6 +1612,8 @@ winrt::fire_and_forget Pane::_CloseChildRoutine(const bool closeFirst)
// Create the dummy grid. This grid will be the one we actually animate,
// in the place of the closed pane.
Controls::Grid dummyGrid;
// GH#603 - we can safely add a BG here, as the control is gone right
// away, to fill the space as the rest of the pane expands.
dummyGrid.Background(s_unfocusedBorderBrush);
// It should be the size of the closed pane.
dummyGrid.Width(removedOriginalSize.Width);
Expand Down Expand Up @@ -1871,6 +1869,19 @@ void Pane::_SetupEntranceAnimation()
return;
}

// Use the unfocused border color as the pane background, so an actual color
// appears behind panes as we animate them sliding in.
//
// GH#603 - We set only the background of the new pane, while it animates
// in. Once the animation is done, we'll remove that background, so if the
// user wants vintage opacity, they'll be able to see what's under the
// window.
// * If we don't give it a background, then the BG will be entirely transparent.
// * If we give the parent (us) root BG a color, then a transparent pane
// will flash opaque during the animation, then back to transparent, which
// looks bad.
_secondChild->_root.Background(s_unfocusedBorderBrush);

const auto [firstSize, secondSize] = _CalcChildrenSizes(::base::saturated_cast<float>(totalSize));

// This is safe to capture this, because it's only being called in the
Expand Down Expand Up @@ -1938,11 +1949,12 @@ void Pane::_SetupEntranceAnimation()

// When the animation is completed, undo the trickiness from before, to
// restore the controls to the behavior they'd usually have.
animation.Completed([childGrid, control](auto&&, auto&&) {
animation.Completed([childGrid, control, root = _secondChild->_root](auto&&, auto&&) {
control.Width(NAN);
childGrid.Width(NAN);
childGrid.HorizontalAlignment(HorizontalAlignment::Stretch);
control.HorizontalAlignment(HorizontalAlignment::Stretch);
root.Background(nullptr);
});
}
else
Expand All @@ -1956,11 +1968,12 @@ void Pane::_SetupEntranceAnimation()

// When the animation is completed, undo the trickiness from before, to
// restore the controls to the behavior they'd usually have.
animation.Completed([childGrid, control](auto&&, auto&&) {
animation.Completed([childGrid, control, root = _secondChild->_root](auto&&, auto&&) {
control.Height(NAN);
childGrid.Height(NAN);
childGrid.VerticalAlignment(VerticalAlignment::Stretch);
control.VerticalAlignment(VerticalAlignment::Stretch);
root.Background(nullptr);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace winrt::TerminalApp::implementation
TraceLoggingBool(usedManualProfile, "ProfileSpecified", "Whether the new tab specified a profile explicitly"),
TraceLoggingGuid(profile.Guid(), "ProfileGuid", "The GUID of the profile spawned in the new tab"),
TraceLoggingBool(settings.DefaultSettings().UseAcrylic(), "UseAcrylic", "The acrylic preference from the settings"),
TraceLoggingFloat64(settings.DefaultSettings().TintOpacity(), "TintOpacity", "Opacity preference from the settings"),
TraceLoggingFloat64(settings.DefaultSettings().Opacity(), "TintOpacity", "Opacity preference from the settings"),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"TintOpacity" -> "Opacity"?

TraceLoggingWideString(settings.DefaultSettings().FontFace().c_str(), "FontFace", "Font face chosen in the settings"),
TraceLoggingWideString(schemeName.data(), "SchemeName", "Color scheme set in the settings"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
xmlns:local="using:TerminalApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
Background="Transparent"
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
mc:Ignorable="d">

<Grid x:Name="Root"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
Expand Down
38 changes: 7 additions & 31 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// GH#5098: Inform the engine of the opacity of the default text background.
if (_settings.UseAcrylic())
{
_renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast<float>(_settings.TintOpacity()));
_renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast<float>(_settings.Opacity()));
}

THROW_IF_FAILED(_renderEngine->Enable());
Expand Down Expand Up @@ -425,41 +425,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return;
}

auto newOpacity = std::clamp(_settings.TintOpacity() + adjustment,
auto newOpacity = std::clamp(_settings.Opacity() + adjustment,
0.0,
1.0);
if (_settings.UseAcrylic())
{
try
{
_settings.TintOpacity(newOpacity);

if (newOpacity >= 1.0)
{
_settings.UseAcrylic(false);
}
Comment on lines -437 to -440
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're putting a lot of trust in the platform that it will "do the right thing" when acrylic is enabled and set to 1.0.

else
{
// GH#5098: Inform the engine of the new opacity of the default text background.
SetBackgroundOpacity(::base::saturated_cast<float>(newOpacity));
}
// GH#5098: Inform the engine of the new opacity of the default text background.
SetBackgroundOpacity(::base::saturated_cast<float>(newOpacity));

auto eventArgs = winrt::make_self<TransparencyChangedEventArgs>(newOpacity);
_TransparencyChangedHandlers(*this, *eventArgs);
}
CATCH_LOG();
}
else if (adjustment < 0)
{
_settings.UseAcrylic(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I had to guess, this is part of what breaks the "go from solid to acrylic" wheel action on Windows 10. ☹️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooof. Might need to add this back to fix #11285, to make sure that we have some acrylic on win10. Gross.

_settings.Opacity(newOpacity);

//Setting initial opacity set to 1 to ensure smooth transition to acrylic during mouse scroll
newOpacity = std::clamp(1.0 + adjustment, 0.0, 1.0);
_settings.TintOpacity(newOpacity);

auto eventArgs = winrt::make_self<TransparencyChangedEventArgs>(newOpacity);
_TransparencyChangedHandlers(*this, *eventArgs);
}
auto eventArgs = winrt::make_self<TransparencyChangedEventArgs>(newOpacity);
_TransparencyChangedHandlers(*this, *eventArgs);
}

void ControlCore::ToggleShaderEffects()
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/IControlAppearance.idl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.Terminal.Control
Windows.UI.Xaml.VerticalAlignment BackgroundImageVerticalAlignment;
Boolean IntenseIsBold;
// IntenseIsBright is in Core Appearance
Double Opacity;

// Experimental settings
Boolean RetroTerminalEffect;
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/IControlSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace Microsoft.Terminal.Control
String ProfileName;

Boolean UseAcrylic;
Double TintOpacity;
ScrollbarState ScrollState;

String FontFace;
Expand Down
10 changes: 7 additions & 3 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - <none>
void TermControl::_InitializeBackgroundBrush()
{
auto appearance = _settings.try_as<IControlAppearance>();
if (_settings.UseAcrylic())
{
// See if we've already got an acrylic background brush
Expand All @@ -449,7 +450,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
acrylic.TintColor(bgColor);

// Apply brush settings
acrylic.TintOpacity(_settings.TintOpacity());
acrylic.TintOpacity(appearance.Opacity());

// Apply brush to control if it's not already there
if (RootGrid().Background() != acrylic)
Expand All @@ -458,15 +459,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}

// GH#5098: Inform the engine of the new opacity of the default text background.
_core.SetBackgroundOpacity(::base::saturated_cast<float>(_settings.TintOpacity()));
_core.SetBackgroundOpacity(::base::saturated_cast<float>(appearance.Opacity()));
}
else
{
Media::SolidColorBrush solidColor{};
solidColor.Opacity(_settings.Opacity());
RootGrid().Background(solidColor);

// GH#5098: Inform the engine of the new opacity of the default text background.
_core.SetBackgroundOpacity(1.0f);
_core.SetBackgroundOpacity(appearance.Opacity());
}
}

Expand Down Expand Up @@ -497,7 +499,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
else if (auto solidColor = RootGrid().Background().try_as<Media::SolidColorBrush>())
{
const auto originalOpacity = solidColor.Opacity();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because .Color will erase it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my guess. I didn't experiment too carefully with this though.

solidColor.Color(bg);
solidColor.Opacity(originalOpacity);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
d:DesignWidth="1024"
AllowDrop="True"
AllowFocusOnInteraction="True"
Background="Transparent"
CharacterReceived="_CharacterHandler"
DragOver="_DragOverHandler"
Drop="_DragDropHandler"
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Page.Resources>
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalSettingsEditor/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void SetAcrylicOpacityPercentageValue(double value)
{
AcrylicOpacity(winrt::Microsoft::Terminal::Settings::Editor::Converters::PercentageValueToPercentage(value));
_profile.DefaultAppearance().Opacity(winrt::Microsoft::Terminal::Settings::Editor::Converters::PercentageValueToPercentage(value));
};

void SetPadding(double value)
Expand Down Expand Up @@ -66,7 +66,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_profile, TabColor);
OBSERVABLE_PROJECTED_SETTING(_profile, SuppressApplicationTitle);
OBSERVABLE_PROJECTED_SETTING(_profile, UseAcrylic);
OBSERVABLE_PROJECTED_SETTING(_profile, AcrylicOpacity);
OBSERVABLE_PROJECTED_SETTING(_profile, ScrollState);
OBSERVABLE_PROJECTED_SETTING(_profile, Padding);
OBSERVABLE_PROJECTED_SETTING(_profile, Commandline);
Expand All @@ -78,6 +77,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), Background);
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), SelectionBackground);
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), CursorColor);
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), Opacity);
OBSERVABLE_PROJECTED_SETTING(_profile, HistorySize);
OBSERVABLE_PROJECTED_SETTING(_profile, SnapOnInput);
OBSERVABLE_PROJECTED_SETTING(_profile, AltGrAliasing);
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalSettingsEditor/Profiles.idl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Microsoft.Terminal.Settings.Editor
OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference<Microsoft.Terminal.Core.Color>, TabColor);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, SuppressApplicationTitle);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, UseAcrylic);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Double, AcrylicOpacity);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Double, Opacity);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Microsoft.Terminal.Control.ScrollbarState, ScrollState);
OBSERVABLE_PROJECTED_PROFILE_SETTING(String, Padding);
OBSERVABLE_PROJECTED_PROFILE_SETTING(String, Commandline);
Expand Down Expand Up @@ -109,6 +109,6 @@ namespace Microsoft.Terminal.Settings.Editor
IInspectable CurrentScrollState;
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> ScrollStateList { get; };

Windows.UI.Xaml.Controls.Slider AcrylicOpacitySlider { get; };
Windows.UI.Xaml.Controls.Slider OpacitySlider { get; };
}
}
Loading