fix a bug with toggling the retro effects from the palette

This commit is contained in:
Mike Griese 2021-10-26 10:23:26 -05:00
parent 28cbad1470
commit 634b6854dc
10 changed files with 32 additions and 63 deletions

View file

@ -1464,20 +1464,7 @@ void Pane::UpdateSettings(const TerminalSettingsCreateResult& settings, const Pr
assert(_IsLeaf());
_profile = profile;
// auto controlSettings = _control.Settings().as<TerminalSettings>();
// // Update the parent of the control's settings object (and not the object itself) so
// // that any overrides made by the control don't get affected by the reload
// controlSettings.SetParent(settings.DefaultSettings());
// auto unfocusedSettings{ settings.UnfocusedSettings() };
// if (unfocusedSettings)
// {
// // Note: the unfocused settings needs to be entirely unchanged _except_ we need to
// // set its parent to the settings object that lives in the control. This is because
// // the overrides made by the control live in that settings object, so we want to make
// // sure the unfocused settings inherit from that.
// unfocusedSettings.SetParent(controlSettings);
// }
// // _control.UnfocusedAppearance(unfocusedSettings);
_control.UpdateControlSettings(settings.DefaultSettings(), settings.UnfocusedSettings());
}

View file

@ -2161,11 +2161,7 @@ namespace winrt::TerminalApp::implementation
{
// Give term control a child of the settings so that any overrides go in the child
// This way, when we do a settings reload we just update the parent and the overrides remain
// const auto child = TerminalSettings::CreateWithParent(settings);
TermControl term{ settings.DefaultSettings(), settings.UnfocusedSettings(), connection };
// term.UnfocusedAppearance(child.UnfocusedSettings()); // It is okay for the unfocused settings to be null
return term;
}

View file

@ -1638,4 +1638,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderer->TriggerRedrawAll();
_BackgroundColorChangedHandlers(*this, nullptr);
}
bool ControlCore::HasUnfocusedAppearance() const
{
return _settings->HasUnfocusedAppearance();
}
}

View file

@ -67,6 +67,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
};
Control::IControlAppearance FocusedAppearance() const { return *_settings->FocusedAppearance(); };
Control::IControlAppearance UnfocusedAppearance() const { return *_settings->UnfocusedAppearance(); };
bool HasUnfocusedAppearance() const;
winrt::Microsoft::Terminal::Core::Scheme ColorScheme() const noexcept;
void ColorScheme(const winrt::Microsoft::Terminal::Core::Scheme& scheme);

View file

@ -41,11 +41,12 @@ namespace Microsoft.Terminal.Control
Double compositionScale);
void UpdateSettings(IControlSettings settings, IControlAppearance appearance);
// void UpdateAppearance(IControlAppearance appearance);
void ApplyAppearance(Boolean focused);
IControlSettings Settings { get; };
IControlAppearance FocusedAppearance { get; };
IControlAppearance UnfocusedAppearance { get; };
Boolean HasUnfocusedAppearance();
UInt64 SwapChainHandle { get; };
@ -81,7 +82,6 @@ namespace Microsoft.Terminal.Control
void BlinkAttributeTick();
void UpdatePatternLocations();
void Search(String text, Boolean goForward, Boolean caseSensitive);
// void SetBackgroundOpacity(Double opacity);
Microsoft.Terminal.Core.Color BackgroundColor { get; };
Boolean HasSelection { get; };

View file

@ -17,6 +17,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
struct ControlSettings : public winrt::implements<ControlSettings, Microsoft::Terminal::Control::IControlSettings, Microsoft::Terminal::Control::IControlAppearance, Microsoft::Terminal::Core::ICoreSettings, Microsoft::Terminal::Core::ICoreAppearance>
{
// Getters and setters for each *Setting member. We're not using
// WINRT_PROPERTY for these, because they actually exist inside the
// _focusedAppearance member. We don't need to reserve another member to
// hold them.
#define SETTINGS_GEN(type, name, ...) WINRT_PROPERTY(type, name, __VA_ARGS__);
CORE_SETTINGS(SETTINGS_GEN)
CONTROL_SETTINGS(SETTINGS_GEN)
@ -25,16 +29,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation
private:
winrt::com_ptr<ControlAppearance> _unfocusedAppearance{ nullptr };
winrt::com_ptr<ControlAppearance> _focusedAppearance{ nullptr };
bool _hasUnfocusedAppearance{ false };
public:
ControlSettings(const Control::IControlSettings& settings,
const Control::IControlAppearance& unfocusedAppearance)
{
_hasUnfocusedAppearance = unfocusedAppearance != nullptr;
_focusedAppearance = winrt::make_self<implementation::ControlAppearance>(settings);
_unfocusedAppearance = unfocusedAppearance ?
winrt::make_self<implementation::ControlAppearance>(unfocusedAppearance) :
_focusedAppearance;
// Copy every value from the passed in settings, into us.
#define COPY_SETTING(type, name, ...) _##name = settings.name();
CORE_SETTINGS(COPY_SETTING)
CONTROL_SETTINGS(COPY_SETTING)
@ -43,7 +51,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::com_ptr<ControlAppearance> UnfocusedAppearance() { return _unfocusedAppearance; }
winrt::com_ptr<ControlAppearance> FocusedAppearance() { return _focusedAppearance; }
bool HasUnfocusedAppearance() { return _hasUnfocusedAppearance; }
// Getters and setters for each Appearance member. We're not using
// WINRT_PROPERTY for these, because they actually exist inside the
// _focusedAppearance member. We don't need to reserve another member to
// hold them.
#define APPEARANCE_GEN(type, name, ...) \
type name() const noexcept { return _focusedAppearance->name(); } \
void name(const type& value) noexcept { _focusedAppearance->name(value); }

View file

@ -1501,10 +1501,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_blinkTimer->Start();
}
// Only update the appearance here if an unfocused config exists -
// if an unfocused config does not exist then we never would have switched
// appearances anyway so there's no need to switch back upon gaining focus
if (_core.UnfocusedAppearance())
// Only update the appearance here if an unfocused config exists - if an
// unfocused config does not exist then we never would have switched
// appearances anyway so there's no need to switch back upon gaining
// focus
if (_core.HasUnfocusedAppearance())
{
UpdateAppearance(_core.FocusedAppearance());
}
@ -1548,10 +1549,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// Check if there is an unfocused config we should set the appearance to
// upon losing focus
// if (_settings->UnfocusedAppearance())
// {
UpdateAppearance(_core.UnfocusedAppearance());
// }
if (_core.HasUnfocusedAppearance())
{
UpdateAppearance(_core.UnfocusedAppearance());
}
}
// Method Description:

View file

@ -206,38 +206,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_Opacity = appearance.Opacity();
}
// Method Description:
// - Creates a TerminalSettingsCreateResult from a parent TerminalSettingsCreateResult
// - The returned defaultSettings inherits from the parent's defaultSettings, and the
// returned unfocusedSettings inherits from the returned defaultSettings
// - Note that the unfocused settings needs to be entirely unchanged _except_ we need to
// set its parent to the other settings object that we return. This is because the overrides
// made by the control will live in that other settings object, so we want to make
// sure the unfocused settings inherit from that.
// - Another way to think about this is that initially we have UnfocusedSettings inherit
// from DefaultSettings. This function simply adds another TerminalSettings object
// in the middle of these two, so UnfocusedSettings now inherits from the new object
// and the new object inherits from the DefaultSettings. And this new object is what
// the control can put overrides in.
// Arguments:
// - parent: the TerminalSettingsCreateResult that we create a new one from
// Return Value:
// - A TerminalSettingsCreateResult object that contains a defaultSettings that inherits
// from parent's defaultSettings, and contains an unfocusedSettings that inherits from
// its defaultSettings
Model::TerminalSettingsCreateResult TerminalSettings::CreateWithParent(const Model::TerminalSettingsCreateResult& parent)
{
THROW_HR_IF_NULL(E_INVALIDARG, parent);
auto defaultImpl{ get_self<TerminalSettings>(parent.DefaultSettings()) };
auto defaultChild = defaultImpl->CreateChild();
if (parent.UnfocusedSettings())
{
parent.UnfocusedSettings().SetParent(*defaultChild);
}
return winrt::make<TerminalSettingsCreateResult>(*defaultChild, parent.UnfocusedSettings());
}
// Method Description:
// - Sets our parent to the provided TerminalSettings
// Arguments:

View file

@ -64,8 +64,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
const Model::NewTerminalArgs& newTerminalArgs,
const Control::IKeyBindings& keybindings);
static Model::TerminalSettingsCreateResult CreateWithParent(const Model::TerminalSettingsCreateResult& parent);
Model::TerminalSettings GetParent();
void SetParent(const Model::TerminalSettings& parent);

View file

@ -28,7 +28,6 @@ namespace Microsoft.Terminal.Settings.Model
static TerminalSettingsCreateResult CreateWithProfile(CascadiaSettings appSettings, Profile profile, Microsoft.Terminal.Control.IKeyBindings keybindings);
static TerminalSettingsCreateResult CreateWithNewTerminalArgs(CascadiaSettings appSettings, NewTerminalArgs newTerminalArgs, Microsoft.Terminal.Control.IKeyBindings keybindings);
static TerminalSettingsCreateResult CreateWithParent(TerminalSettingsCreateResult parent);
void SetParent(TerminalSettings parent);
TerminalSettings GetParent();