diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 441fbd4de..6172f9626 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -13,15 +13,52 @@ using namespace winrt::Windows::ApplicationModel; using namespace winrt::Windows::ApplicationModel::DataTransfer; +using namespace winrt::Windows::System; +using namespace winrt::Windows::UI::Core; +using namespace winrt::Windows::UI::Text::Core; using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Xaml::Controls; -using namespace winrt::Windows::UI::Core; -using namespace winrt::Windows::System; using namespace winrt::Microsoft::Terminal; using namespace winrt::Microsoft::Terminal::Control; using namespace winrt::Microsoft::Terminal::Settings::Model; using namespace ::TerminalApp; +class LanguageProfileNotifier : public winrt::implements +{ +public: + explicit LanguageProfileNotifier(std::function callback) : + _callback{ std::move(callback) } + { + _manager = wil::CoCreateInstance(CLSID_TF_ThreadMgr); + _source = _manager.query(); + if (FAILED(_source->AdviseSink(IID_ITfActiveLanguageProfileNotifySink, static_cast(this), &_cookie))) + { + _cookie = TF_INVALID_COOKIE; + THROW_LAST_ERROR(); + } + } + + ~LanguageProfileNotifier() + { + if (_cookie != TF_INVALID_COOKIE) + { + _source->UnadviseSink(_cookie); + } + } + + HRESULT OnActivated(const IID&, const GUID&, BOOL) + { + _callback(); + return S_OK; + } + +private: + std::function _callback; + wil::com_ptr _manager; + wil::com_ptr _source; + DWORD _cookie = TF_INVALID_COOKIE; +}; + namespace winrt { namespace MUX = Microsoft::UI::Xaml; @@ -191,24 +228,42 @@ namespace winrt::TerminalApp::implementation AppLogic::AppLogic() : _reloadState{ std::chrono::milliseconds(100), []() { ApplicationState::SharedInstance().Reload(); } } { - // For your own sanity, it's better to do setup outside the ctor. - // If you do any setup in the ctor that ends up throwing an exception, - // then it might look like App just failed to activate, which will - // cause you to chase down the rabbit hole of "why is App not - // registered?" when it definitely is. + try + { + // For your own sanity, it's better to do setup outside the ctor. + // If you do any setup in the ctor that ends up throwing an exception, + // then it might look like App just failed to activate, which will + // cause you to chase down the rabbit hole of "why is App not + // registered?" when it definitely is. - // The TerminalPage has to be constructed during our construction, to - // make sure that there's a terminal page for callers of - // SetTitleBarContent - _isElevated = _isUserAdmin(); - _root = winrt::make_self(); + // The TerminalPage has to be constructed during our construction, to + // make sure that there's a terminal page for callers of + // SetTitleBarContent + _isElevated = _isUserAdmin(); + _root = winrt::make_self(); - _reloadSettings = std::make_shared>(_root->Dispatcher(), std::chrono::milliseconds(100), [weakSelf = get_weak()]() { - if (auto self{ weakSelf.get() }) - { - self->_ReloadSettings(); - } - }); + _reloadSettings = std::make_shared>(_root->Dispatcher(), std::chrono::milliseconds(100), [weakSelf = get_weak()]() { + if (auto self{ weakSelf.get() }) + { + self->_ReloadSettings(); + } + }); + + static auto f = winrt::make([]() { + printf(""); + }); + /*auto resourceContext = winrt::Windows::ApplicationModel::Resources::Core::ResourceContext::GetForViewIndependentUse(); + auto qualifierValues = resourceContext.QualifierValues(); + _qualifierValuesChangedRevoker = qualifierValues.MapChanged(winrt::auto_revoke, [this](const auto& sender, const auto& change) { + _reloadSettings->Run(); + _InputLanguageChangedHandlers(sender, change); + });*/ + } + catch (...) + { + LOG_CAUGHT_EXCEPTION(); + throw; + } } // Method Description: diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index 3d7782039..01924d6e6 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -99,6 +99,7 @@ namespace winrt::TerminalApp::implementation // -------------------------------- WinRT Events --------------------------------- TYPED_EVENT(RequestedThemeChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme); TYPED_EVENT(SettingsChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); + TYPED_EVENT(InputLanguageChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); private: bool _isUwp{ false }; @@ -110,8 +111,8 @@ namespace winrt::TerminalApp::implementation // ALSO: If you add any UIElements as roots here, make sure they're // updated in _ApplyTheme. The root currently is _root. winrt::com_ptr _root{ nullptr }; - Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr }; + winrt::Windows::Foundation::Collections::IObservableMap::MapChanged_revoker _qualifierValuesChangedRevoker; wil::unique_folder_change_reader_nothrow _reader; std::shared_ptr> _reloadSettings; diff --git a/src/cascadia/TerminalApp/AppLogic.idl b/src/cascadia/TerminalApp/AppLogic.idl index bb334d26f..737331b54 100644 --- a/src/cascadia/TerminalApp/AppLogic.idl +++ b/src/cascadia/TerminalApp/AppLogic.idl @@ -91,6 +91,7 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler IdentifyWindowsRequested; event Windows.Foundation.TypedEventHandler RenameWindowRequested; event Windows.Foundation.TypedEventHandler SettingsChanged; + event Windows.Foundation.TypedEventHandler InputLanguageChanged; event Windows.Foundation.TypedEventHandler IsQuakeWindowChanged; event Windows.Foundation.TypedEventHandler SummonWindowRequested; } diff --git a/src/cascadia/TerminalApp/pch.h b/src/cascadia/TerminalApp/pch.h index 299d7de63..bf8e1650c 100644 --- a/src/cascadia/TerminalApp/pch.h +++ b/src/cascadia/TerminalApp/pch.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +68,7 @@ TRACELOGGING_DECLARE_PROVIDER(g_hTerminalAppProvider); #include #include +#include #include #include diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 53e21ccdd..d7a0fdad5 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -13,11 +13,12 @@ #include +using namespace winrt::Windows::Foundation::Numerics; using namespace winrt::Windows::UI; using namespace winrt::Windows::UI::Composition; +using namespace winrt::Windows::UI::Text::Core; using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Xaml::Hosting; -using namespace winrt::Windows::Foundation::Numerics; using namespace winrt::Microsoft::Terminal; using namespace winrt::Microsoft::Terminal::Settings::Model; using namespace ::Microsoft::Console; diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h index 5f6d10ca5..b59907341 100644 --- a/src/cascadia/WindowsTerminal/AppHost.h +++ b/src/cascadia/WindowsTerminal/AppHost.h @@ -24,6 +24,7 @@ private: winrt::TerminalApp::App _app; winrt::TerminalApp::AppLogic _logic; winrt::Microsoft::Terminal::Remoting::WindowManager _windowManager{ nullptr }; + winrt::Windows::UI::Text::Core::CoreTextServicesManager::InputLanguageChanged_revoker _inputLanguageChangedRevoker; std::vector _hotkeys; winrt::com_ptr _desktopManager{ nullptr }; diff --git a/src/cascadia/WindowsTerminal/pch.h b/src/cascadia/WindowsTerminal/pch.h index ce71201a4..0e18f4c87 100644 --- a/src/cascadia/WindowsTerminal/pch.h +++ b/src/cascadia/WindowsTerminal/pch.h @@ -29,8 +29,6 @@ Abstract: #include #include -#include -#include #include #include #include @@ -50,26 +48,28 @@ Abstract: #include // Needed just for XamlIslands to work at all: -#include #include +#include +#include #include -#include // Additional headers for various xaml features. We need: // * Core so we can resume_foreground with CoreDispatcher // * Controls for grid // * Media for ScaleTransform // * ApplicationModel for finding the path to wt.exe +#include +#include #include #include #include -#include -#include + +#include #include -#include -#include #include +#include +#include #include #include @@ -85,4 +85,5 @@ TRACELOGGING_DECLARE_PROVIDER(g_hWindowsTerminalProvider); #include #include #include + #include "til.h"