diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index e3221b9fcb9..d473669d0a2 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -4255,27 +4255,12 @@ namespace winrt::TerminalApp::implementation _PropertyChangedHandlers(*this, WUX::Data::PropertyChangedEventArgs{ L"WindowNameForDisplay" }); _PropertyChangedHandlers(*this, WUX::Data::PropertyChangedEventArgs{ L"WindowIdForDisplay" }); - // if (changed) - // { // DON'T display the confirmation if this is the name we were // given on startup! if (page->_startupState == StartupState::Initialized) { page->IdentifyWindow(); - - // TODO! This is wacky. Reconcile with oldIsQuakeMode in TerminalWindow::WindowName - - // // If we're entering quake mode, or leaving it - // if (IsQuakeWindow() != oldIsQuakeMode) - // { - // // If we're entering Quake Mode from ~Focus Mode, then this will enter Focus Mode - // // If we're entering Quake Mode from Focus Mode, then this will do nothing - // // If we're leaving Quake Mode (we're already in Focus Mode), then this will do nothing - // SetFocusMode(true); - // _IsQuakeWindowChangedHandlers(*this, nullptr); - // } } - // } } } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 8ee040a6685..7f2d0e13b4f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -50,22 +50,6 @@ namespace winrt::TerminalApp::implementation _ProposedName{ name } {}; }; - // struct WindowProperties : WindowPropertiesT - // { - // // Normally, WindowName and WindowId would be - // // WINRT_OBSERVABLE_PROPERTY's, but we want them to raise - // // WindowNameForDisplay and WindowIdForDisplay instead - // winrt::hstring WindowName() const noexcept; - // winrt::fire_and_forget WindowName(const winrt::hstring& value); - // uint64_t WindowId() const noexcept; - // void WindowId(const uint64_t& value); - // winrt::hstring WindowIdForDisplay() const noexcept; - // winrt::hstring WindowNameForDisplay() const noexcept; - // bool IsQuakeWindow() const noexcept; - - // public: - // }; - struct TerminalPage : TerminalPageT { public: @@ -79,7 +63,6 @@ namespace winrt::TerminalApp::implementation void Create(); - // bool ShouldUsePersistedLayout(Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) const; bool ShouldImmediatelyHandoffToElevated(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) const; void HandoffToElevated(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings); @@ -140,7 +123,6 @@ namespace winrt::TerminalApp::implementation void SetNumberOfOpenWindows(const uint64_t value); - // bool IsQuakeWindow() const noexcept; bool IsElevated() const noexcept; void OpenSettingsUI(); @@ -152,8 +134,6 @@ namespace winrt::TerminalApp::implementation void WindowProperties(const TerminalApp::IWindowProperties& props); winrt::fire_and_forget WindowNameChanged(); - // WINRT_PROPERTY(TerminalApp::IWindowProperties, WindowProperties, nullptr); - WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); // -------------------------------- WinRT Events --------------------------------- @@ -169,7 +149,7 @@ namespace winrt::TerminalApp::implementation TYPED_EVENT(Initialized, IInspectable, winrt::Windows::UI::Xaml::RoutedEventArgs); TYPED_EVENT(IdentifyWindowsRequested, IInspectable, IInspectable); TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs); - TYPED_EVENT(IsQuakeWindowChanged, IInspectable, IInspectable); + TYPED_EVENT(SummonWindowRequested, IInspectable, IInspectable); TYPED_EVENT(CloseRequested, IInspectable, IInspectable); TYPED_EVENT(OpenSystemMenu, IInspectable, IInspectable); @@ -208,8 +188,7 @@ namespace winrt::TerminalApp::implementation bool _isFullscreen{ false }; bool _isMaximized{ false }; bool _isAlwaysOnTop{ false }; - // winrt::hstring _WindowName{}; - // uint64_t _WindowId{ 0 }; + std::optional _loadFromPersistedLayoutIdx{}; uint64_t _numOpenWindows{ 0 }; diff --git a/src/cascadia/TerminalApp/TerminalPage.idl b/src/cascadia/TerminalApp/TerminalPage.idl index 9a2cfef292c..38ab490162e 100644 --- a/src/cascadia/TerminalApp/TerminalPage.idl +++ b/src/cascadia/TerminalApp/TerminalPage.idl @@ -69,7 +69,7 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler SetTaskbarProgress; event Windows.Foundation.TypedEventHandler IdentifyWindowsRequested; event Windows.Foundation.TypedEventHandler RenameWindowRequested; - event Windows.Foundation.TypedEventHandler IsQuakeWindowChanged; + event Windows.Foundation.TypedEventHandler SummonWindowRequested; event Windows.Foundation.TypedEventHandler CloseRequested; event Windows.Foundation.TypedEventHandler OpenSystemMenu; diff --git a/src/cascadia/TerminalApp/TerminalWindow.cpp b/src/cascadia/TerminalApp/TerminalWindow.cpp index 3b58b7d109a..d5554082952 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.cpp +++ b/src/cascadia/TerminalApp/TerminalWindow.cpp @@ -1116,29 +1116,6 @@ namespace winrt::TerminalApp::implementation } } //////////////////////////////////////////////////////////////////////////// - - void TerminalWindow::IdentifyWindow() - { - if (_root) - { - _root->IdentifyWindow(); - } - } - - void TerminalWindow::RenameFailed() - { - if (_root) - { - _root->RenameFailed(); - } - } - - // TODO! - // bool TerminalWindow::IsQuakeWindow() const noexcept - // { - // return _root->IsQuakeWindow(); - // } - void TerminalWindow::RequestExitFullscreen() { _root->SetFullscreen(false); @@ -1157,6 +1134,22 @@ namespace winrt::TerminalApp::implementation //////////////////////////////////////////////////////////////////////////// + void TerminalWindow::IdentifyWindow() + { + if (_root) + { + _root->IdentifyWindow(); + } + } + + void TerminalWindow::RenameFailed() + { + if (_root) + { + _root->RenameFailed(); + } + } + // WindowName is a otherwise generic WINRT_OBSERVABLE_PROPERTY, but it needs // to raise a PropertyChanged for WindowNameForDisplay, instead of // WindowName. @@ -1167,8 +1160,8 @@ namespace winrt::TerminalApp::implementation void TerminalWindow::WindowName(const winrt::hstring& value) { - // TODO! - // const auto oldIsQuakeMode = IsQuakeWindow(); + const auto oldIsQuakeMode = IsQuakeWindow(); + const auto changed = _WindowName != value; if (changed) { @@ -1176,6 +1169,16 @@ namespace winrt::TerminalApp::implementation if (_root) { _root->WindowNameChanged(); + + // If we're entering quake mode, or leaving it + if (IsQuakeWindow() != oldIsQuakeMode) + { + // If we're entering Quake Mode from ~Focus Mode, then this will enter Focus Mode + // If we're entering Quake Mode from Focus Mode, then this will do nothing + // If we're leaving Quake Mode (we're already in Focus Mode), then this will do nothing + _root->SetFocusMode(true); + _IsQuakeWindowChangedHandlers(*this, nullptr); + } } } } @@ -1229,6 +1232,7 @@ namespace winrt::TerminalApp::implementation { return WindowName() == QuakeWindowName; } + //////////////////////////////////////////////////////////////////////////// bool TerminalWindow::ShouldImmediatelyHandoffToElevated() @@ -1260,4 +1264,6 @@ namespace winrt::TerminalApp::implementation return; } } + + //////////////////////////////////////////////////////////////////////////// }; diff --git a/src/cascadia/TerminalApp/TerminalWindow.h b/src/cascadia/TerminalApp/TerminalWindow.h index 09fcb4dd524..719d87814ce 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.h +++ b/src/cascadia/TerminalApp/TerminalWindow.h @@ -51,7 +51,6 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget UpdateSettings(winrt::TerminalApp::SettingsLoadEventArgs args); bool HasCommandlineArguments() const noexcept; - // bool HasSettingsStartupActions() const noexcept; int32_t SetStartupCommandline(array_view actions); int32_t ExecuteCommandline(array_view actions, const winrt::hstring& cwd); void SetSettingsStartupArgs(const std::vector& actions); @@ -78,7 +77,6 @@ namespace winrt::TerminalApp::implementation void SetNumberOfOpenWindows(const uint64_t num); bool ShouldUsePersistedLayout() const; - // bool IsQuakeWindow() const noexcept; void RequestExitFullscreen(); Windows::Foundation::Size GetLaunchDimensions(uint32_t dpi); @@ -190,13 +188,14 @@ namespace winrt::TerminalApp::implementation FORWARDED_TYPED_EVENT(SetTaskbarProgress, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, SetTaskbarProgress); FORWARDED_TYPED_EVENT(IdentifyWindowsRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IdentifyWindowsRequested); FORWARDED_TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs, _root, RenameWindowRequested); - FORWARDED_TYPED_EVENT(IsQuakeWindowChanged, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IsQuakeWindowChanged); FORWARDED_TYPED_EVENT(SummonWindowRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, SummonWindowRequested); FORWARDED_TYPED_EVENT(CloseRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, CloseRequested); FORWARDED_TYPED_EVENT(OpenSystemMenu, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, OpenSystemMenu); FORWARDED_TYPED_EVENT(QuitRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, QuitRequested); FORWARDED_TYPED_EVENT(ShowWindowChanged, Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Control::ShowWindowArgs, _root, ShowWindowChanged); + TYPED_EVENT(IsQuakeWindowChanged, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable); + TYPED_EVENT(SystemMenuChangeRequested, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::SystemMenuChangeArgs); TYPED_EVENT(SettingsChanged, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::SettingsLoadEventArgs); diff --git a/src/cascadia/TerminalApp/TerminalWindow.idl b/src/cascadia/TerminalApp/TerminalWindow.idl index fc1270641a9..ff23cb76dbe 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.idl +++ b/src/cascadia/TerminalApp/TerminalWindow.idl @@ -56,7 +56,6 @@ namespace TerminalApp Boolean IsElevated(); Boolean HasCommandlineArguments(); - // Boolean HasSettingsStartupActions(); Int32 SetStartupCommandline(String[] commands); @@ -83,7 +82,6 @@ namespace TerminalApp void SetNumberOfOpenWindows(UInt64 num); void RenameFailed(); void RequestExitFullscreen(); - // Boolean IsQuakeWindow(); Windows.Foundation.Size GetLaunchDimensions(UInt32 dpi); Boolean CenterOnLaunch { get; }; diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 192ec2fbe95..eded913c4c8 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -221,6 +221,7 @@ void AppHost::_HandleCommandlineArgs() const auto numPeasants = _windowManager2.GetNumberOfPeasants(); if (numPeasants == 1) { + // TODO! this is vaugely off by one. Not sure, but if you restore 2 windows, you seem to get two copies of the second. Yikes. const auto layouts = ApplicationState::SharedInstance().PersistedWindowLayouts(); if (_appLogic.ShouldUsePersistedLayout() && layouts && @@ -439,16 +440,6 @@ void AppHost::AppTitleChanged(const winrt::Windows::Foundation::IInspectable& /* // - void AppHost::LastTabClosed(const winrt::Windows::Foundation::IInspectable& /*sender*/, const winrt::TerminalApp::LastTabClosedEventArgs& /*args*/) { - // TODO! - // if (_windowManager2.IsMonarch() && _notificationIcon) - // { - // _DestroyNotificationIcon(); - // } - // else if (_window->IsQuakeWindow()) - // { - // _HideNotificationIconRequested(nullptr, nullptr); - // } - // We don't want to try to save layouts if we are about to close. _windowManager2.GetWindowLayoutRequested(_GetWindowLayoutRequestedToken); @@ -1102,22 +1093,6 @@ void AppHost::_HandleSettingsChanged(const winrt::Windows::Foundation::IInspecta void AppHost::_IsQuakeWindowChanged(const winrt::Windows::Foundation::IInspectable&, const winrt::Windows::Foundation::IInspectable&) { - // // We want the quake window to be accessible through the notification icon. - // // This means if there's a quake window _somewhere_, we want the notification icon - // // to show regardless of the notification icon settings. - // // This also means we'll need to destroy the notification icon if it was created - // // specifically for the quake window. If not, it should not be destroyed. - // if (!_window->IsQuakeWindow() && _windowLogic.IsQuakeWindow()) - // { - // _ShowNotificationIconRequested(nullptr, nullptr); - // } - // else if (_window->IsQuakeWindow() && !_windowLogic.IsQuakeWindow()) - // { - // _HideNotificationIconRequested(nullptr, nullptr); - // } - - // TODO! I think we need the emperor to listen to windowLogic's IsQuakeWindowChanged event, to replicate this - _window->IsQuakeWindow(_windowLogic.IsQuakeWindow()); } diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index 1a983b4946d..678ef2b0e1c 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -150,6 +150,12 @@ void WindowEmperor::CreateNewWindowThread(Remoting::WindowRequestedArgs args, co auto func = [this, args, peasant, firstWindow]() { auto window{ std::make_shared(_app.Logic(), args, _manager, peasant) }; _windows.push_back(window); + + window->Logic().IsQuakeWindowChanged([this](auto&&, auto &&) -> winrt::fire_and_forget { + co_await wil::resume_foreground(this->_dispatcher); + this->_checkWindowsForNotificationIcon(); + }); + return window->WindowProc(); }; @@ -176,22 +182,12 @@ void WindowEmperor::_becomeMonarch() //////////////////////////////////////////////////////////////////////////// - // if (_windowManager2.DoesQuakeWindowExist() || - // _window->IsQuakeWindow() || - // (_windowLogic.GetAlwaysShowNotificationIcon() || _windowLogic.GetMinimizeToNotificationArea())) - // { - // _CreateNotificationIcon(); - // } - - // // These events are coming from peasants that become or un-become quake windows. - // _revokers.ShowNotificationIconRequested = _windowManager2.ShowNotificationIconRequested(winrt::auto_revoke, { this, &AppHost::_ShowNotificationIconRequested }); - // _revokers.HideNotificationIconRequested = _windowManager2.HideNotificationIconRequested(winrt::auto_revoke, { this, &AppHost::_HideNotificationIconRequested }); + _checkWindowsForNotificationIcon(); //////////////////////////////////////////////////////////////////////////// - // // Set the number of open windows (so we know if we are the last window) - // // and subscribe for updates if there are any changes to that number. - // _windowLogic.SetNumberOfOpenWindows(_windowManager2.GetNumberOfPeasants()); + // Set the number of open windows (so we know if we are the last window) + // and subscribe for updates if there are any changes to that number. _WindowCreatedToken = _manager.WindowCreated({ this, &WindowEmperor::_numberOfWindowsChanged }); _WindowClosedToken = _manager.WindowClosed({ this, &WindowEmperor::_numberOfWindowsChanged }); @@ -224,6 +220,11 @@ void WindowEmperor::_numberOfWindowsChanged(const winrt::Windows::Foundation::II { _windowThread->Logic().SetNumberOfOpenWindows(numWindows); } + + // If we closed out the quake window, and don't otherwise need the tray + // icon, let's get rid of it. + _checkWindowsForNotificationIcon(); + // TODO! apparently, we crash when whe actually post a quit, handle it, and // then leak all our threads. That's not good, but also, this should only // happen once our threads all exited. So figure that out.