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

Add adjustOpacity action #12092

Merged
49 commits merged into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
43ec102
blindly make control settings read-only, there's only 2 build breaks?
zadjii-msft Sep 23, 2021
dad065e
make this a macro in case we want to reuse this
zadjii-msft Sep 23, 2021
981d8cc
This is a crazy idea but if it works, it'll be a game changer
zadjii-msft Sep 23, 2021
d6989ec
this is wild
zadjii-msft Sep 23, 2021
4b18bb4
missed one
zadjii-msft Sep 23, 2021
7fc2f10
move to a common header
zadjii-msft Sep 23, 2021
c7536ed
This says there's only one build error in Terminal.Control.Lib but th…
zadjii-msft Sep 28, 2021
c26dd6b
This works better than it has any business doing. Plemty of bugs, but…
zadjii-msft Sep 28, 2021
4a1baf0
I think I needed this to get it to build. Or I started breaknig somet…
zadjii-msft Sep 30, 2021
fbba74e
I think we're going to have to cut this
zadjii-msft Oct 14, 2021
1413d01
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/ragnarok
zadjii-msft Oct 14, 2021
31e7998
this builds at least
zadjii-msft Oct 19, 2021
4f7e883
This crashes substantially less frequently
zadjii-msft Oct 19, 2021
a9de82e
saving the settings works again
zadjii-msft Oct 20, 2021
70b9f8c
This is the start of fixing the opacity roundtripping weirdness
zadjii-msft Oct 20, 2021
0371194
okay this seems to fix opacity & cleartype in all cases
zadjii-msft Oct 20, 2021
4912b65
mostly cleanup, 7 TODOs remain
zadjii-msft Oct 20, 2021
888e157
more cleanup, 5 todo!s left
zadjii-msft Oct 20, 2021
17829f4
This is how I wanted to solve the color scheme setting, previewing, b…
zadjii-msft Oct 21, 2021
1aa2849
you've seen WINRT_PROPERTY now get ready for RUNTIME_PROPERTY
zadjii-msft Oct 21, 2021
e3a50cf
turns out we didn't need all them fancy overrides
zadjii-msft Oct 21, 2021
9160966
This almost works for previewing, but I fudged something up with the …
zadjii-msft Oct 26, 2021
282c03c
whoop, it works!
zadjii-msft Oct 26, 2021
6babb4e
cleanup
zadjii-msft Oct 26, 2021
94f4ef5
lots of cleanup
zadjii-msft Oct 26, 2021
28cbad1
get the tests compiling again
zadjii-msft Oct 26, 2021
634b685
fix a bug with toggling the retro effects from the palette
zadjii-msft Oct 26, 2021
48ca704
More cleanup. Forgot to lock here.
zadjii-msft Oct 26, 2021
217742c
Some of these calls were duplicates. Some were redundant. Overall cle…
zadjii-msft Oct 26, 2021
4a700cd
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/ragnarok
zadjii-msft Oct 26, 2021
01cef2f
fix control unit tets
zadjii-msft Oct 26, 2021
8c7ce77
fix the local tests too
zadjii-msft Oct 26, 2021
7c28851
this fixes the weird lock that we really really don't need anymore
zadjii-msft Oct 26, 2021
bf9bf0e
cleanup two of the remaining TODOs
zadjii-msft Oct 26, 2021
f087dd8
no more todos. Bot, tell me what I typod
zadjii-msft Oct 26, 2021
f111c6d
thanks spell bot
zadjii-msft Oct 26, 2021
51486a4
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/ragnarok
zadjii-msft Oct 28, 2021
6da5d79
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/ragnarok
zadjii-msft Nov 1, 2021
83e7aea
Merge remote-tracking branch 'origin/main' into dev/migrie/oop/ragnarok
zadjii-msft Nov 2, 2021
6456108
add action for adjusting opacity at runtime
zadjii-msft Nov 2, 2021
0c33dca
previewing too is good
zadjii-msft Nov 8, 2021
3f3c794
Merge remote-tracking branch 'origin/main' into dev/migrie/f/11205-ad…
zadjii-msft Jan 5, 2022
b26354b
schema too
zadjii-msft Jan 5, 2022
c33b43e
as discussed, relative:true by default
zadjii-msft Jan 12, 2022
3c25489
pr feedback
zadjii-msft Jan 12, 2022
bc037c9
Merge remote-tracking branch 'origin/main' into dev/migrie/f/11205-ad…
zadjii-msft Jan 12, 2022
9f6c62d
hey youre not supposed to be in here
zadjii-msft Jan 12, 2022
1b976cf
Merge remote-tracking branch 'origin/main' into dev/migrie/f/11205-ad…
zadjii-msft Jan 12, 2022
874ea82
Im this close to making this an allowed word
zadjii-msft Jan 12, 2022
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
32 changes: 32 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"toggleShaderEffects",
"wt",
"quit",
"adjustOpacity",
"restoreLastClosed",
"unbound"
],
Expand Down Expand Up @@ -1385,6 +1386,34 @@
}
]
},
"AdjustOpacityAction": {
"description": "Changes the opacity of the active Terminal window. If `relative` is specified, then this action will increase/decrease relative to the current opacity.",
"allOf": [
{
"$ref": "#/$defs/ShortcutAction"
},
{
"properties": {
"action": {
"type": "string",
"const": "adjustOpacity"
},
"opacity": {
"type": "integer",
"minimum": -100,
"maximum": 100,
"default": 0,
"description": "How opaque the terminal should become or how much the opacity should be changed by, depending on the value of `relative`"
},
"relative": {
"type": "boolean",
"default": true,
"description": "If true, then adjust the current opacity by the given `opacity` parameter, additively. If false, set the opacity to exactly that value."
}
}
}
]
},
"Keybinding": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -1493,6 +1522,9 @@
{
"$ref": "#/$defs/QuakeModeAction"
},
{
"$ref": "#/$defs/AdjustOpacityAction"
},
{
"type": "null"
}
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/LocalTests_TerminalApp/TabTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ namespace TerminalAppLocalTests
Log::Comment(L"Emulate committing the SetColorScheme action");

SetColorSchemeArgs args{ L"Vintage" };
page->_EndPreviewColorScheme();
page->_EndPreview();
page->_HandleSetColorScheme(nullptr, ActionEventArgs{ args });
});

Expand Down Expand Up @@ -1395,7 +1395,7 @@ namespace TerminalAppLocalTests

TestOnUIThread([&page]() {
Log::Comment(L"Emulate dismissing the SetColorScheme action");
page->_EndPreviewColorScheme();
page->_EndPreview();
});

TestOnUIThread([&page]() {
Expand Down Expand Up @@ -1469,7 +1469,7 @@ namespace TerminalAppLocalTests
Log::Comment(L"Emulate committing the SetColorScheme action");

SetColorSchemeArgs args{ L"One Half Light" };
page->_EndPreviewColorScheme();
page->_EndPreview();
page->_HandleSetColorScheme(nullptr, ActionEventArgs{ args });
});

Expand Down
36 changes: 31 additions & 5 deletions src/cascadia/TerminalApp/ActionPreviewHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ namespace winrt::TerminalApp::implementation
switch (_lastPreviewedCommand.ActionAndArgs().Action())
{
case ShortcutAction::SetColorScheme:
case ShortcutAction::AdjustOpacity:
{
_EndPreviewColorScheme();
_RunRestorePreviews();
break;
}
}
_lastPreviewedCommand = nullptr;
}

// Method Description:
// - Revert any changes from the preview on a SetColorScheme action. This
// will remove the preview TerminalSettings we inserted into the control's
// TerminalSettings graph, and update the control.
// - Revert any changes from the preview action. This will run the restore
// function that the preview added to _restorePreviewFuncs
// Arguments:
// - <none>
// Return Value:
// - <none>
void TerminalPage::_EndPreviewColorScheme()
void TerminalPage::_RunRestorePreviews()
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
// Apply the reverts in reverse order - If we had multiple previews
// stacked on top of each other, then this will ensure the first one in
Expand Down Expand Up @@ -111,6 +111,27 @@ namespace winrt::TerminalApp::implementation
}
}

void TerminalPage::_PreviewAdjustOpacity(const Settings::Model::AdjustOpacityArgs& args)
{
// Clear the saved preview funcs because we don't need to add a restore each time
// the preview changes, we only need to be able to restore the last one.
_restorePreviewFuncs.clear();

_ApplyToActiveControls([&](const auto& control) {
// Stash a copy of the original opacity.
auto originalOpacity{ control.BackgroundOpacity() };

// Apply the new opacity
control.AdjustOpacity(args.Opacity(), args.Relative());

_restorePreviewFuncs.emplace_back([=]() {
// On dismiss:
// Don't adjust relatively, just set outright.
control.AdjustOpacity(::base::saturated_cast<int>(originalOpacity * 100), false);
});
});
}

// Method Description:
// - Handler for the CommandPalette::PreviewAction event. The Command
// Palette will raise this even when an action is selected, but _not_
Expand Down Expand Up @@ -142,6 +163,11 @@ namespace winrt::TerminalApp::implementation
_PreviewColorScheme(args.ActionAndArgs().Args().try_as<SetColorSchemeArgs>());
break;
}
case ShortcutAction::AdjustOpacity:
{
_PreviewAdjustOpacity(args.ActionAndArgs().Args().try_as<AdjustOpacityArgs>());
break;
}
}

// GH#9818 Other ideas for actions that could be preview-able:
Expand Down
15 changes: 15 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,19 @@ namespace winrt::TerminalApp::implementation
}
}
}

void TerminalPage::_HandleAdjustOpacity(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (args)
{
if (const auto& realArgs = args.ActionArgs().try_as<AdjustOpacityArgs>())
{
const auto res = _ApplyToActiveControls([&](auto& control) {
control.AdjustOpacity(realArgs.Opacity(), realArgs.Relative());
});
args.Handled(res);
}
}
}
}
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ namespace winrt::TerminalApp::implementation

void _PreviewActionHandler(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::Command& args);
void _EndPreview();
void _EndPreviewColorScheme();
void _RunRestorePreviews();
void _PreviewColorScheme(const Microsoft::Terminal::Settings::Model::SetColorSchemeArgs& args);
void _PreviewAdjustOpacity(const Microsoft::Terminal::Settings::Model::AdjustOpacityArgs& args);
winrt::Microsoft::Terminal::Settings::Model::Command _lastPreviewedCommand{ nullptr };
std::vector<std::function<void()>> _restorePreviewFuncs{};

Expand Down
31 changes: 27 additions & 4 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return;
}

auto newOpacity = std::clamp(Opacity() + adjustment,
0.0,
1.0);
_setOpacity(Opacity() + adjustment);
}

void ControlCore::_setOpacity(const double opacity)
{
const auto newOpacity = std::clamp(opacity,
0.0,
1.0);

if (newOpacity == Opacity())
{
return;
}

auto lock = _terminal->LockForWriting();
// Update our runtime opacity value
Opacity(newOpacity);

Expand Down Expand Up @@ -1701,6 +1710,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_settings->FocusedAppearance()->SetColorTableEntry(15, scheme.BrightWhite);

_terminal->ApplyScheme(scheme);

_renderEngine->SetSelectionBackground(til::color{ _settings->SelectionBackground() });

_renderer->TriggerRedrawAll();
Expand All @@ -1712,6 +1722,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _settings->HasUnfocusedAppearance();
}

void ControlCore::AdjustOpacity(const int32_t& opacity, const bool& relative)
{
const double opacityAdjust = static_cast<double>(opacity) / 100.0;
if (relative)
{
AdjustOpacity(opacityAdjust);
}
else
{
_setOpacity(opacityAdjust);
}
}

bool ControlCore::_isBackgroundTransparent()
{
// If we're:
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

static bool IsVintageOpacityAvailable() noexcept;

void AdjustOpacity(const int32_t& opacity, const bool& relative);

RUNTIME_SETTING(double, Opacity, _settings->Opacity());
RUNTIME_SETTING(bool, UseAcrylic, _settings->UseAcrylic());

Expand Down Expand Up @@ -269,6 +271,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void _updateAntiAliasingMode();
void _connectionOutputHandler(const hstring& hstr);
void _updateHoveredCell(const std::optional<til::point> terminalPosition);
void _setOpacity(const double opacity);

bool _isBackgroundTransparent();

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ namespace Microsoft.Terminal.Control

String ReadEntireBuffer();

void AdjustOpacity(Int32 Opacity, Boolean relative);

event FontSizeChangedEventArgs FontSizeChanged;

event Windows.Foundation.TypedEventHandler<Object, CopyToClipboardEventArgs> CopyToClipboard;
Expand Down
15 changes: 14 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const winrt::Windows::Foundation::Size minSize{ 1, 1 };
const double scaleFactor = DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel();
const auto dpi = ::base::saturated_cast<uint32_t>(USER_DEFAULT_SCREEN_DPI * scaleFactor);

return GetProposedDimensions(_core.Settings(), dpi, minSize);
}
}
Expand Down Expand Up @@ -2708,4 +2707,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
_core.ColorScheme(scheme);
}

void TermControl::AdjustOpacity(const int32_t& opacity, const bool& relative)
{
_core.AdjustOpacity(opacity, relative);
}

// - You'd think this should just be "Opacity", but UIElement already
// defines an "Opacity", which we're actually not setting at all. We're
// not overriding or changing _that_ value. Callers that want the opacity
// set by the settings should call this instead.
double TermControl::BackgroundOpacity() const
{
return _core.Opacity();
}
}
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "SearchBoxControl.h"

#include "ControlInteractivity.h"
#include "ControlSettings.h"

namespace Microsoft::Console::VirtualTerminal
{
Expand Down Expand Up @@ -56,6 +57,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
int BufferHeight() const;

bool BracketedPasteEnabled() const noexcept;

double BackgroundOpacity() const;
#pragma endregion

void ScrollViewport(int viewTop);
Expand Down Expand Up @@ -107,6 +110,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::Microsoft::Terminal::Core::Scheme ColorScheme() const noexcept;
void ColorScheme(const winrt::Microsoft::Terminal::Core::Scheme& scheme) const noexcept;

void AdjustOpacity(const int32_t& opacity, const bool& relative);

// -------------------------------- WinRT Events ---------------------------------
// clang-format off
WINRT_CALLBACK(FontSizeChanged, Control::FontSizeChangedEventArgs);
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,14 @@ namespace Microsoft.Terminal.Control
void ToggleReadOnly();

String ReadEntireBuffer();

void AdjustOpacity(Int32 Opacity, Boolean relative);

// You'd think this should just be "Opacity", but UIElement already
Copy link
Member

Choose a reason for hiding this comment

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

Good call on leaving this comment.

// defines an "Opacity", which we're actually not setting at all. We're
// not overriding or changing _that_ value. Callers that want the
// opacity set by the settings should call this instead.
Double BackgroundOpacity { get; };

}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static constexpr std::string_view ExportBufferKey{ "exportBuffer" };
static constexpr std::string_view ClearBufferKey{ "clearBuffer" };
static constexpr std::string_view MultipleActionsKey{ "multipleActions" };
static constexpr std::string_view QuitKey{ "quit" };
static constexpr std::string_view AdjustOpacityKey{ "adjustOpacity" };
static constexpr std::string_view RestoreLastClosedKey{ "restoreLastClosed" };

static constexpr std::string_view ActionKey{ "action" };
Expand Down Expand Up @@ -383,6 +384,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::ClearBuffer, L"" }, // Intentionally omitted, must be generated by GenerateName
{ ShortcutAction::MultipleActions, L"" }, // Intentionally omitted, must be generated by GenerateName
{ ShortcutAction::Quit, RS_(L"QuitCommandKey") },
{ ShortcutAction::AdjustOpacity, L"" }, // Intentionally omitted, must be generated by GenerateName
{ ShortcutAction::RestoreLastClosed, RS_(L"RestoreLastClosedCommandKey") },
};
}();
Expand Down
32 changes: 32 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "ExportBufferArgs.g.cpp"
#include "ClearBufferArgs.g.cpp"
#include "MultipleActionsArgs.g.cpp"
#include "AdjustOpacityArgs.g.cpp"

#include <LibraryResources.h>
#include <WtExeUtils.h>
Expand Down Expand Up @@ -769,4 +770,35 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
return L"";
}

winrt::hstring AdjustOpacityArgs::GenerateName() const
{
if (Relative())
{
if (Opacity() >= 0)
{
// "Increase background opacity by {Opacity}%"
return winrt::hstring{
fmt::format(std::wstring_view(RS_(L"IncreaseOpacityCommandKey")),
Opacity())
};
}
else
{
// "Decrease background opacity by {Opacity}%"
return winrt::hstring{
fmt::format(std::wstring_view(RS_(L"DecreaseOpacityCommandKey")),
Opacity())
};
}
}
else
{
// "Set background opacity to {Opacity}%"
return winrt::hstring{
fmt::format(std::wstring_view(RS_(L"AdjustOpacityCommandKey")),
Opacity())
};
}
}
}
Loading