From 18d1a205bb7c0c40f7c10c58e9ba402389373034 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 28 Jan 2021 12:23:37 -0600 Subject: [PATCH] Add support for the `win` key in keybindings --- src/cascadia/TerminalControl/KeyChord.idl | 3 ++- .../KeyChordSerialization.cpp | 12 +++++++++++- src/cascadia/WindowsTerminal/IslandWindow.cpp | 18 ++---------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cascadia/TerminalControl/KeyChord.idl b/src/cascadia/TerminalControl/KeyChord.idl index 4952688a602..81f7cefc451 100644 --- a/src/cascadia/TerminalControl/KeyChord.idl +++ b/src/cascadia/TerminalControl/KeyChord.idl @@ -9,7 +9,8 @@ namespace Microsoft.Terminal.TerminalControl None = 0x0000, Alt = 0x0001, Ctrl = 0x0002, - Shift = 0x0004 + Shift = 0x0004, + Windows = 0x0008 }; [default_interface] diff --git a/src/cascadia/TerminalSettingsModel/KeyChordSerialization.cpp b/src/cascadia/TerminalSettingsModel/KeyChordSerialization.cpp index b57fdc5207c..0092b520149 100644 --- a/src/cascadia/TerminalSettingsModel/KeyChordSerialization.cpp +++ b/src/cascadia/TerminalSettingsModel/KeyChordSerialization.cpp @@ -11,8 +11,9 @@ using namespace winrt::Microsoft::Terminal::Settings::Model::implementation; static constexpr std::wstring_view CTRL_KEY{ L"ctrl" }; static constexpr std::wstring_view SHIFT_KEY{ L"shift" }; static constexpr std::wstring_view ALT_KEY{ L"alt" }; +static constexpr std::wstring_view WIN_KEY{ L"win" }; -static constexpr int MAX_CHORD_PARTS = 4; +static constexpr int MAX_CHORD_PARTS = 5; // win+ctrl+alt+shift+key // clang-format off static const std::unordered_map vkeyNamePairs { @@ -143,6 +144,10 @@ KeyChord KeyChordSerialization::FromString(const winrt::hstring& hstr) { modifiers |= KeyModifiers::Shift; } + else if (lowercase == WIN_KEY) + { + modifiers |= KeyModifiers::Windows; + } else { bool foundKey = false; @@ -224,6 +229,11 @@ winrt::hstring KeyChordSerialization::ToString(const KeyChord& chord) std::wstring buffer{ L"" }; // Add modifiers + if (WI_IsFlagSet(modifiers, KeyModifiers::Windows)) + { + buffer += WIN_KEY; + buffer += L"+"; + } if (WI_IsFlagSet(modifiers, KeyModifiers::Ctrl)) { buffer += CTRL_KEY; diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index 3ce8b435f7c..d7825627903 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -861,29 +861,15 @@ void IslandWindow::SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalCon 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; auto MODs = MOD_NOREPEAT | + (WI_IsFlagSet(modifiers, KeyModifiers::Windows) ? MOD_WIN : 0) | (WI_IsFlagSet(modifiers, KeyModifiers::Alt) ? MOD_ALT : 0) | (WI_IsFlagSet(modifiers, KeyModifiers::Ctrl) ? MOD_CONTROL : 0) | (WI_IsFlagSet(modifiers, KeyModifiers::Shift) ? MOD_SHIFT : 0); + auto res = RegisterHotKey(_window.get(), 1, MODs, hotkey.Vkey()); LOG_LAST_ERROR_IF(!res); - // if (!res) - // { - // // auto gle = GetLastError(); - - // } - // res; - // auto b = !res; - // b; } }