This will always summon the monarch window
This commit is contained in:
parent
a65f3419e3
commit
1c2f8e5d6a
|
@ -199,6 +199,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
|||
// window, and when the current monarch dies.
|
||||
|
||||
_monarch.FindTargetWindowRequested({ this, &WindowManager::_raiseFindTargetWindowRequested });
|
||||
|
||||
_BecameMonarchHandlers(*this, nullptr);
|
||||
}
|
||||
|
||||
bool WindowManager::_areWeTheKing()
|
||||
|
@ -423,4 +425,9 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
|||
{
|
||||
_FindTargetWindowRequestedHandlers(sender, args);
|
||||
}
|
||||
|
||||
bool WindowManager::IsMonarch()
|
||||
{
|
||||
return _isKing;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
|||
bool ShouldCreateWindow();
|
||||
|
||||
winrt::Microsoft::Terminal::Remoting::Peasant CurrentWindow();
|
||||
bool IsMonarch();
|
||||
|
||||
TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs);
|
||||
TYPED_EVENT(BecameMonarch, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
|
||||
|
||||
private:
|
||||
bool _shouldCreateWindow{ false };
|
||||
|
|
|
@ -10,6 +10,9 @@ namespace Microsoft.Terminal.Remoting
|
|||
void ProposeCommandline(CommandlineArgs args);
|
||||
Boolean ShouldCreateWindow { get; };
|
||||
IPeasant CurrentWindow();
|
||||
Boolean IsMonarch { get; };
|
||||
|
||||
event Windows.Foundation.TypedEventHandler<Object, FindTargetWindowArgs> FindTargetWindowRequested;
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> BecameMonarch;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1276,6 +1276,11 @@ namespace winrt::TerminalApp::implementation
|
|||
return _root ? _root->AlwaysOnTop() : false;
|
||||
}
|
||||
|
||||
TerminalControl::KeyChord AppLogic::GlobalHotkey()
|
||||
{
|
||||
return _settings.GlobalSettings().GlobalHotkey();
|
||||
}
|
||||
|
||||
// -------------------------------- 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.
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);
|
||||
|
||||
winrt::Microsoft::Terminal::TerminalControl::KeyChord GlobalHotkey();
|
||||
|
||||
// -------------------------------- WinRT Events ---------------------------------
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RequestedThemeChanged, _requestedThemeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme);
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ namespace TerminalApp
|
|||
|
||||
Int32 FindTargetWindow(String[] args);
|
||||
|
||||
Microsoft.Terminal.TerminalControl.KeyChord GlobalHotkey();
|
||||
|
||||
// See IDialogPresenter and TerminalPage's DialogPresenter for more
|
||||
// information.
|
||||
Windows.Foundation.IAsyncOperation<Windows.UI.Xaml.Controls.ContentDialogResult> ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../../inc/DefaultSettings.h"
|
||||
#include "JsonUtils.h"
|
||||
#include "TerminalSettingsSerializationHelpers.h"
|
||||
#include "KeyChordSerialization.h"
|
||||
|
||||
#include "GlobalAppSettings.g.cpp"
|
||||
|
||||
|
@ -15,6 +16,7 @@ using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;
|
|||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace ::Microsoft::Console;
|
||||
using namespace winrt::Microsoft::UI::Xaml::Controls;
|
||||
using namespace winrt::Microsoft::Terminal::TerminalControl;
|
||||
|
||||
static constexpr std::string_view LegacyKeybindingsKey{ "keybindings" };
|
||||
static constexpr std::string_view ActionsKey{ "actions" };
|
||||
|
@ -41,6 +43,7 @@ static constexpr std::string_view LegacyUseTabSwitcherModeKey{ "useTabSwitcher"
|
|||
static constexpr std::string_view TabSwitcherModeKey{ "tabSwitcherMode" };
|
||||
static constexpr std::string_view DisableAnimationsKey{ "disableAnimations" };
|
||||
static constexpr std::string_view StartupActionsKey{ "startupActions" };
|
||||
static constexpr std::string_view GlobalHotkeyKey{ "globalHotkey" };
|
||||
|
||||
static constexpr std::string_view DebugFeaturesKey{ "debugFeatures" };
|
||||
|
||||
|
@ -304,6 +307,34 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)
|
|||
|
||||
JsonUtils::GetValueForKey(json, StartupActionsKey, _StartupActions);
|
||||
|
||||
try
|
||||
{
|
||||
const auto keys = json[JsonKey(GlobalHotkeyKey)];
|
||||
const auto validString = keys.isString();
|
||||
const auto validArray = keys.isArray() && keys.size() == 1;
|
||||
|
||||
// GH#4239 - If the user provided more than one key
|
||||
// chord to a "keys" array, warn the user here.
|
||||
// TODO: GH#1334 - remove this check.
|
||||
if (keys.isArray() && keys.size() > 1)
|
||||
{
|
||||
// TODO: add a warning
|
||||
// warnings.push_back(SettingsLoadWarnings::TooManyKeysForChord);
|
||||
}
|
||||
|
||||
if (validString || validArray)
|
||||
{
|
||||
const auto keyChordString = keys.isString() ? winrt::to_hstring(keys.asString()) : winrt::to_hstring(keys[0].asString());
|
||||
|
||||
const auto chord = KeyChordSerialization::FromString(keyChordString);
|
||||
_GlobalHotkey = chord;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// TODO: add a settings warning
|
||||
}
|
||||
|
||||
// This is a helper lambda to get the keybindings and commands out of both
|
||||
// and array of objects. We'll use this twice, once on the legacy
|
||||
// `keybindings` key, and again on the newer `bindings` key.
|
||||
|
|
|
@ -87,6 +87,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
GETSET_SETTING(Model::TabSwitcherMode, TabSwitcherMode, Model::TabSwitcherMode::InOrder);
|
||||
GETSET_SETTING(bool, DisableAnimations, false);
|
||||
GETSET_SETTING(hstring, StartupActions, L"");
|
||||
GETSET_SETTING(TerminalControl::KeyChord, GlobalHotkey, nullptr);
|
||||
|
||||
private:
|
||||
guid _defaultProfile;
|
||||
|
|
|
@ -146,5 +146,9 @@ namespace Microsoft.Terminal.Settings.Model
|
|||
Boolean HasStartupActions();
|
||||
void ClearStartupActions();
|
||||
String StartupActions();
|
||||
|
||||
Boolean HasGlobalHotkey();
|
||||
void ClearGlobalHotkey();
|
||||
Microsoft.Terminal.TerminalControl.KeyChord GlobalHotkey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,12 @@ AppHost::AppHost() noexcept :
|
|||
_window->WindowActivated({ this, &AppHost::_WindowActivated });
|
||||
_window->SetAlwaysOnTop(_logic.GetInitialAlwaysOnTop());
|
||||
_window->MakeWindow();
|
||||
|
||||
_windowManager.BecameMonarch({ this, &AppHost::_BecomeMonarch });
|
||||
if (_windowManager.IsMonarch())
|
||||
{
|
||||
_BecomeMonarch(nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
AppHost::~AppHost()
|
||||
|
@ -563,3 +569,10 @@ void AppHost::_WindowActivated()
|
|||
peasant.ActivateWindow(args);
|
||||
}
|
||||
}
|
||||
|
||||
void AppHost::_BecomeMonarch(const winrt::Windows::Foundation::IInspectable& /*sender*/,
|
||||
const winrt::Windows::Foundation::IInspectable& /*args*/)
|
||||
{
|
||||
auto hotkey{ _logic.GlobalHotkey() };
|
||||
_window->SetGlobalHotkey(hotkey);
|
||||
}
|
||||
|
|
|
@ -51,4 +51,6 @@ private:
|
|||
|
||||
void _FindTargetWindow(const winrt::Windows::Foundation::IInspectable& sender,
|
||||
const winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs& args);
|
||||
void _BecomeMonarch(const winrt::Windows::Foundation::IInspectable& sender,
|
||||
const winrt::Windows::Foundation::IInspectable& args);
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@ using namespace winrt::Windows::UI::Xaml;
|
|||
using namespace winrt::Windows::UI::Xaml::Hosting;
|
||||
using namespace winrt::Windows::Foundation::Numerics;
|
||||
using namespace winrt::Microsoft::Terminal::Settings::Model;
|
||||
using namespace winrt::Microsoft::Terminal::TerminalControl;
|
||||
using namespace ::Microsoft::Console::Types;
|
||||
|
||||
#define XAML_HOSTING_WINDOW_CLASS_NAME L"CASCADIA_HOSTING_WINDOW_CLASS"
|
||||
|
@ -843,5 +844,21 @@ void IslandWindow::_ApplyWindowSize()
|
|||
SWP_FRAMECHANGED | SWP_NOACTIVATE));
|
||||
}
|
||||
|
||||
void IslandWindow::SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalControl::KeyChord& hotkey)
|
||||
{
|
||||
if (hotkey)
|
||||
{
|
||||
auto modifiers = hotkey.Modifiers();
|
||||
WPARAM wParam = hotkey.Vkey() |
|
||||
(WI_IsFlagSet(modifiers, KeyModifiers::Alt) ? HOTKEYF_ALT << 8 : 0) |
|
||||
(WI_IsFlagSet(modifiers, KeyModifiers::Ctrl) ? HOTKEYF_CONTROL << 8 : 0) |
|
||||
(WI_IsFlagSet(modifiers, KeyModifiers::Shift) ? HOTKEYF_SHIFT << 8 : 0);
|
||||
auto result = SendMessage(_window.get(), WM_SETHOTKEY, wParam, 0);
|
||||
result;
|
||||
auto a = result + 1;
|
||||
a;
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_EVENT(IslandWindow, DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
|
||||
DEFINE_EVENT(IslandWindow, WindowCloseButtonClicked, _windowCloseButtonClickedHandler, winrt::delegate<>);
|
||||
|
|
|
@ -38,6 +38,8 @@ public:
|
|||
void FlashTaskbar();
|
||||
void SetTaskbarProgress(const size_t state, const size_t progress);
|
||||
|
||||
void SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalControl::KeyChord& hotkey);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
DECLARE_EVENT(DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
|
||||
|
|
Loading…
Reference in a new issue