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

Implement ConEmu's OSC 9;4 to set the taskbar progress indicator #8055

Merged
merged 25 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
af9e4d5
osc 9;4 implementation
PankajBhojwani Oct 27, 2020
606490f
spelling
PankajBhojwani Oct 27, 2020
0decbea
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Oct 27, 2020
4e6f6fe
address comments
PankajBhojwani Oct 27, 2020
da83748
add paused state
PankajBhojwani Oct 27, 2020
3d0ed84
use last focused tab's progress and state
PankajBhojwani Oct 27, 2020
f08c962
use split string
PankajBhojwani Oct 28, 2020
5f83dfd
use sender instead of args, some name changes
PankajBhojwani Oct 28, 2020
ab99ed5
remove all references to SetTaskbarProgressEventArgs, validation for …
PankajBhojwani Oct 29, 2020
4125052
tests
PankajBhojwani Oct 29, 2020
a900678
conflict with main
PankajBhojwani Oct 29, 2020
0aa5667
get the taskbar state and progress from the last active control
PankajBhojwani Oct 29, 2020
e69d0af
addressing comments, cleanups
PankajBhojwani Oct 30, 2020
57d8e07
com ptr
PankajBhojwani Oct 30, 2020
5d724bc
merging main, fixing conflicts
PankajBhojwani Nov 4, 2020
4ab32ec
send event when tab changes
PankajBhojwani Nov 4, 2020
5aff81a
check if control exists before using it
PankajBhojwani Nov 4, 2020
9fc16c8
conflict with main
PankajBhojwani Nov 6, 2020
f19b818
con emu action
PankajBhojwani Nov 6, 2020
f931acc
spel
PankajBhojwani Nov 6, 2020
c694192
_GetTaskbarProgress no longer needed
PankajBhojwani Nov 9, 2020
2476802
conflicts
PankajBhojwani Nov 16, 2020
fc9fedf
com_ptr, nits
PankajBhojwani Nov 18, 2020
bf2051b
narrow cast
PankajBhojwani Nov 18, 2020
378dd7f
narrow 2
PankajBhojwani Nov 18, 2020
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
4 changes: 4 additions & 0 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ IInheritable
IMap
IObject
IStorage
ITaskbar
llabs
LCID
llabs
lround
Expand All @@ -39,6 +41,7 @@ NCHITTEST
NCLBUTTONDBLCLK
NCRBUTTONDBLCLK
NOAGGREGATION
NOPROGRESS
NOREDIRECTIONBITMAP
oaidl
ocidl
Expand All @@ -57,6 +60,7 @@ sregex
STDCPP
strchr
syscall
TBPF
THEMECHANGED
tmp
tx
Expand Down
26 changes: 26 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,32 @@ namespace winrt::TerminalApp::implementation
}
}

// Method Description:
// - Gets the taskbar state value from the last active control
// Return Value:
// - The taskbar state of the last active control
size_t AppLogic::GetLastActiveControlTaskbarState()
{
if (_root)
{
return _root->GetLastActiveControlTaskbarState();
}
return {};
}

// Method Description:
// - Gets the taskbar progress value from the last active control
// Return Value:
// - The taskbar progress of the last active control
size_t AppLogic::GetLastActiveControlTaskbarProgress()
{
if (_root)
{
return _root->GetLastActiveControlTaskbarProgress();
}
return {};
}

// Method Description:
// - Sets the initial commandline to process on startup, and attempts to
// parse it. Commands will be parsed into a list of ShortcutActions that
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ namespace winrt::TerminalApp::implementation

void WindowCloseButtonClicked();

size_t GetLastActiveControlTaskbarState();
size_t GetLastActiveControlTaskbarProgress();

winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);

// -------------------------------- WinRT Events ---------------------------------
Expand Down Expand Up @@ -109,6 +112,7 @@ namespace winrt::TerminalApp::implementation
FORWARDED_TYPED_EVENT(FocusModeChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, FocusModeChanged);
FORWARDED_TYPED_EVENT(FullscreenChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, FullscreenChanged);
FORWARDED_TYPED_EVENT(AlwaysOnTopChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, AlwaysOnTopChanged);
FORWARDED_TYPED_EVENT(SetTaskbarProgress, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, SetTaskbarProgress);
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ namespace TerminalApp
void TitlebarClicked();
void WindowCloseButtonClicked();

UInt64 GetLastActiveControlTaskbarState();
UInt64 GetLastActiveControlTaskbarProgress();

// See IDialogPresenter and TerminalPage's DialogPresenter for more
// information.
Windows.Foundation.IAsyncOperation<Windows.UI.Xaml.Controls.ContentDialogResult> ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog);
Expand All @@ -62,5 +65,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, Object> FocusModeChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> FullscreenChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> AlwaysOnTopChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> SetTaskbarProgress;
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ namespace winrt::TerminalApp::implementation
if (lastFocusedControl)
{
lastFocusedControl.Focus(FocusState::Programmatic);
lastFocusedControl.TaskbarProgressChanged();
}
}

Expand Down
42 changes: 42 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ namespace winrt::TerminalApp::implementation

term.OpenHyperlink({ this, &TerminalPage::_OpenHyperlinkHandler });

// Add an event handler for when the terminal wants to set a progress indicator on the taskbar
term.SetTaskbarProgress({ this, &TerminalPage::_SetTaskbarProgressHandler });

// Bind Tab events to the TermControl and the Tab's Pane
hostingTab.Initialize(term);

Expand Down Expand Up @@ -1863,6 +1866,16 @@ namespace winrt::TerminalApp::implementation
return control.CopySelectionToClipboard(singleLine, formats);
}

// Method Description:
// - Send an event (which will be caught by AppHost) to set the progress indicator on the taskbar
// Arguments:
// - sender (not used)
// - eventArgs: the arguments specifying how to set the progress indicator
void TerminalPage::_SetTaskbarProgressHandler(const IInspectable /*sender*/, const IInspectable /*eventArgs*/)
{
_setTaskbarProgressHandlers(*this, nullptr);
}

// Method Description:
// - Paste text from the Windows Clipboard to the focused terminal
void TerminalPage::_PasteText()
Expand Down Expand Up @@ -2222,6 +2235,34 @@ namespace winrt::TerminalApp::implementation
_dialogPresenter = dialogPresenter;
}

// Method Description:
// - Gets the taskbar state value from the last active control
// Return Value:
// - The taskbar state of the last active control
size_t TerminalPage::GetLastActiveControlTaskbarState()
{
const auto tab = _GetFocusedTab();
if (tab)
{
return tab->GetActiveTerminalControl().GetTaskbarState();
}
return {};
}

// Method Description:
// - Gets the taskbar progress value from the last active control
// Return Value:
// - The taskbar progress of the last active control
size_t TerminalPage::GetLastActiveControlTaskbarProgress()
{
const auto tab = _GetFocusedTab();
if (tab)
{
return tab->GetActiveTerminalControl().GetTaskbarProgress();
}
return {};
}

// Method Description:
// - This is the method that App will call when the titlebar
// has been clicked. It dismisses any open flyouts.
Expand Down Expand Up @@ -2633,4 +2674,5 @@ namespace winrt::TerminalApp::implementation
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, FocusModeChanged, _focusModeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, FullscreenChanged, _fullscreenChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, AlwaysOnTopChanged, _alwaysOnTopChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, SetTaskbarProgress, _setTaskbarProgressHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
}
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ namespace winrt::TerminalApp::implementation
winrt::TerminalApp::IDialogPresenter DialogPresenter() const;
void DialogPresenter(winrt::TerminalApp::IDialogPresenter dialogPresenter);

size_t GetLastActiveControlTaskbarState();
size_t GetLastActiveControlTaskbarProgress();

// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTitleBarContent, _setTitleBarContentHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(FocusModeChanged, _focusModeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(FullscreenChanged, _fullscreenChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(AlwaysOnTopChanged, _alwaysOnTopChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTaskbarProgress, _setTaskbarProgressHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(Initialized, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::RoutedEventArgs);

private:
Expand Down Expand Up @@ -189,6 +193,8 @@ namespace winrt::TerminalApp::implementation
void _ShowCouldNotOpenDialog(winrt::hstring reason, winrt::hstring uri);
bool _CopyText(const bool singleLine, const Windows::Foundation::IReference<Microsoft::Terminal::TerminalControl::CopyFormat>& formats);

void _SetTaskbarProgressHandler(const IInspectable sender, const IInspectable eventArgs);

void _PasteText();

fire_and_forget _LaunchSettings(const Microsoft::Terminal::Settings::Model::SettingsTarget target);
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ namespace TerminalApp
// and because of GH#5224.
IDialogPresenter DialogPresenter;

UInt64 GetLastActiveControlTaskbarState();
UInt64 GetLastActiveControlTaskbarProgress();

event Windows.Foundation.TypedEventHandler<Object, String> TitleChanged;
event Windows.Foundation.TypedEventHandler<Object, LastTabClosedEventArgs> LastTabClosed;
event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.UIElement> SetTitleBarContent;
event Windows.Foundation.TypedEventHandler<Object, Object> FocusModeChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> FullscreenChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> AlwaysOnTopChanged;
event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.RoutedEventArgs> Initialized;
event Windows.Foundation.TypedEventHandler<Object, Object> SetTaskbarProgress;
}
}
30 changes: 30 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
auto pfnCopyToClipboard = std::bind(&TermControl::_CopyToClipboard, this, std::placeholders::_1);
_terminal->SetCopyToClipboardCallback(pfnCopyToClipboard);

_terminal->TaskbarProgressChangedCallback([&]() { TermControl::TaskbarProgressChanged(); });

// This event is explicitly revoked in the destructor: does not need weak_ref
auto onReceiveOutputFn = [this](const hstring str) {
_terminal->Write(str);
Expand Down Expand Up @@ -3064,6 +3066,33 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
return coreColor.has_value() ? Windows::Foundation::IReference<winrt::Windows::UI::Color>(coreColor.value()) : nullptr;
}

// Method Description:
// - Sends an event (which will be caught by TerminalPage and forwarded to AppHost after)
// to set the progress indicator on the taskbar
winrt::fire_and_forget TermControl::TaskbarProgressChanged()
{
co_await resume_foreground(Dispatcher(), CoreDispatcherPriority::High);
_setTaskbarProgressHandlers(*this, nullptr);
}

// Method Description:
// - Gets the internal taskbar state value
// Return Value:
// - The taskbar state of this control
const size_t TermControl::GetTaskbarState() const noexcept
{
return _terminal->GetTaskbarState();
}

// Method Description:
// - Gets the internal taskbar progress value
// Return Value:
// - The taskbar progress of this control
const size_t TermControl::GetTaskbarProgress() const noexcept
{
return _terminal->GetTaskbarProgress();
}

// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
Expand All @@ -3074,5 +3103,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, PasteFromClipboard, _clipboardPasteHandlers, TerminalControl::TermControl, TerminalControl::PasteFromClipboardEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, CopyToClipboard, _clipboardCopyHandlers, TerminalControl::TermControl, TerminalControl::CopyToClipboardEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, OpenHyperlink, _openHyperlinkHandlers, TerminalControl::TermControl, TerminalControl::OpenHyperlinkEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, SetTaskbarProgress, _setTaskbarProgressHandlers, TerminalControl::TermControl, IInspectable);
// clang-format on
}
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation

Windows::Foundation::IReference<winrt::Windows::UI::Color> TabColor() noexcept;

winrt::fire_and_forget TaskbarProgressChanged();
const size_t GetTaskbarState() const noexcept;
const size_t GetTaskbarProgress() const noexcept;

// clang-format off
// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT(TitleChanged, _titleChangedHandlers, TerminalControl::TitleChangedEventArgs);
Expand All @@ -150,6 +154,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(PasteFromClipboard, _clipboardPasteHandlers, TerminalControl::TermControl, TerminalControl::PasteFromClipboardEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(CopyToClipboard, _clipboardCopyHandlers, TerminalControl::TermControl, TerminalControl::CopyToClipboardEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(OpenHyperlink, _openHyperlinkHandlers, TerminalControl::TermControl, TerminalControl::OpenHyperlinkEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTaskbarProgress, _setTaskbarProgressHandlers, TerminalControl::TermControl, IInspectable);

TYPED_EVENT(WarningBell, IInspectable, IInspectable);
TYPED_EVENT(ConnectionStateChanged, TerminalControl::TermControl, IInspectable);
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace Microsoft.Terminal.TerminalControl
event Windows.Foundation.TypedEventHandler<TermControl, CopyToClipboardEventArgs> CopyToClipboard;
event Windows.Foundation.TypedEventHandler<TermControl, PasteFromClipboardEventArgs> PasteFromClipboard;
event Windows.Foundation.TypedEventHandler<TermControl, OpenHyperlinkEventArgs> OpenHyperlink;
event Windows.Foundation.TypedEventHandler<TermControl, Object> SetTaskbarProgress;
event Windows.Foundation.TypedEventHandler<Object, Object> WarningBell;

event Windows.Foundation.TypedEventHandler<TermControl, Windows.UI.Xaml.RoutedEventArgs> Initialized;
Expand Down Expand Up @@ -90,6 +91,10 @@ namespace Microsoft.Terminal.TerminalControl
void SendInput(String input);
void ToggleRetroEffect();

void TaskbarProgressChanged();
UInt64 GetTaskbarState();
UInt64 GetTaskbarProgress();
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

Windows.Foundation.IReference<Windows.UI.Color> TabColor { get; };
event Windows.Foundation.TypedEventHandler<Object, Object> TabColorChanged;
}
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalCore/ITerminalApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace Microsoft::Terminal::Core
virtual bool AddHyperlink(std::wstring_view uri, std::wstring_view params) noexcept = 0;
virtual bool EndHyperlink() noexcept = 0;

virtual bool SetTaskbarProgress(const size_t state, const size_t progress) noexcept = 0;

protected:
ITerminalApi() = default;
};
Expand Down
32 changes: 31 additions & 1 deletion src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ Terminal::Terminal() :
_snapOnInput{ true },
_altGrAliasing{ true },
_blockSelection{ false },
_selection{ std::nullopt }
_selection{ std::nullopt },
_taskbarState{ 0 },
_taskbarProgress{ 0 }
{
auto dispatch = std::make_unique<TerminalDispatch>(*this);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));
Expand Down Expand Up @@ -1102,6 +1104,16 @@ void Terminal::SetBackgroundCallback(std::function<void(const COLORREF)> pfn) no
_pfnBackgroundColorChanged.swap(pfn);
}

// Method Description:
// - Allows settings a callback for settings the taskbar progress indicator
// Arguments:
// - pfn: a function callback that takes 2 size_t parameters, one indicating the progress state
// and the other indicating the progress value
void Microsoft::Terminal::Core::Terminal::TaskbarProgressChangedCallback(std::function<void()> pfn) noexcept
{
_pfnTaskbarProgressChanged.swap(pfn);
}

void Terminal::_InitializeColorTable()
try
{
Expand Down Expand Up @@ -1168,3 +1180,21 @@ BlinkingState& Terminal::GetBlinkingState() const noexcept
{
return _blinkingState;
}

// Method Description:
// - Gets the internal taskbar state value
// Return Value:
// - The taskbar state
const size_t Microsoft::Terminal::Core::Terminal::GetTaskbarState() const noexcept
{
return _taskbarState;
}

// Method Description:
// - Gets the internal taskbar progress value
// Return Value:
// - The taskbar progress
const size_t Microsoft::Terminal::Core::Terminal::GetTaskbarProgress() const noexcept
{
return _taskbarProgress;
}
Loading