Skip to content

Commit

Permalink
Add support for the win key in keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jan 28, 2021
1 parent 71f6b58 commit 18d1a20
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/cascadia/TerminalControl/KeyChord.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Microsoft.Terminal.TerminalControl
None = 0x0000,
Alt = 0x0001,
Ctrl = 0x0002,
Shift = 0x0004
Shift = 0x0004,
Windows = 0x0008
};

[default_interface]
Expand Down
12 changes: 11 additions & 1 deletion src/cascadia/TerminalSettingsModel/KeyChordSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::wstring_view, int32_t> vkeyNamePairs {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 2 additions & 16 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 18d1a20

Please sign in to comment.