Skip to content

minor keyboard input changes: adding more key mappings in preparation to future work #1259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<li>Fixes LCD subpixel rendering for overly wide US-ASCII glyphs (#1022)</li>
<li>Fixes alive process when GUI is closed</li>
<li>Fixes vi mode `f` action freeze on last line</li>
<li>Fixes AltGr handling on Windows (#150)</li>
<li>Do not clear search term when entering search editor again.</li>
<li>Clear search term when switch to insert vi mode (#1135)</li>
<li>Delete dpi_scale entry in configuration (#1137)</li>
Expand Down
146 changes: 79 additions & 67 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,47 +532,69 @@ namespace
optional<vtbackend::Key> parseKey(string const& name)
{
using vtbackend::Key;
auto static constexpr Mappings = array { pair { "F1"sv, Key::F1 },
pair { "F2"sv, Key::F2 },
pair { "F3"sv, Key::F3 },
pair { "F4"sv, Key::F4 },
pair { "F5"sv, Key::F5 },
pair { "F6"sv, Key::F6 },
pair { "F7"sv, Key::F7 },
pair { "F8"sv, Key::F8 },
pair { "F9"sv, Key::F9 },
pair { "F10"sv, Key::F10 },
pair { "F11"sv, Key::F11 },
pair { "F12"sv, Key::F12 },
pair { "DownArrow"sv, Key::DownArrow },
pair { "LeftArrow"sv, Key::LeftArrow },
pair { "RightArrow"sv, Key::RightArrow },
pair { "UpArrow"sv, Key::UpArrow },
pair { "Insert"sv, Key::Insert },
pair { "Delete"sv, Key::Delete },
pair { "Home"sv, Key::Home },
pair { "End"sv, Key::End },
pair { "PageUp"sv, Key::PageUp },
pair { "PageDown"sv, Key::PageDown },
pair { "Numpad_NumLock"sv, Key::Numpad_NumLock },
pair { "Numpad_Divide"sv, Key::Numpad_Divide },
pair { "Numpad_Multiply"sv, Key::Numpad_Multiply },
pair { "Numpad_Subtract"sv, Key::Numpad_Subtract },
pair { "Numpad_CapsLock"sv, Key::Numpad_CapsLock },
pair { "Numpad_Add"sv, Key::Numpad_Add },
pair { "Numpad_Decimal"sv, Key::Numpad_Decimal },
pair { "Numpad_Enter"sv, Key::Numpad_Enter },
pair { "Numpad_Equal"sv, Key::Numpad_Equal },
pair { "Numpad_0"sv, Key::Numpad_0 },
pair { "Numpad_1"sv, Key::Numpad_1 },
pair { "Numpad_2"sv, Key::Numpad_2 },
pair { "Numpad_3"sv, Key::Numpad_3 },
pair { "Numpad_4"sv, Key::Numpad_4 },
pair { "Numpad_5"sv, Key::Numpad_5 },
pair { "Numpad_6"sv, Key::Numpad_6 },
pair { "Numpad_7"sv, Key::Numpad_7 },
pair { "Numpad_8"sv, Key::Numpad_8 },
pair { "Numpad_9"sv, Key::Numpad_9 } };
auto static constexpr Mappings = array {
pair { "F1"sv, Key::F1 },
pair { "F2"sv, Key::F2 },
pair { "F3"sv, Key::F3 },
pair { "F4"sv, Key::F4 },
pair { "F5"sv, Key::F5 },
pair { "F6"sv, Key::F6 },
pair { "F7"sv, Key::F7 },
pair { "F8"sv, Key::F8 },
pair { "F9"sv, Key::F9 },
pair { "F10"sv, Key::F10 },
pair { "F11"sv, Key::F11 },
pair { "F12"sv, Key::F12 },
pair { "F13"sv, Key::F13 },
pair { "F14"sv, Key::F14 },
pair { "F15"sv, Key::F15 },
pair { "F16"sv, Key::F16 },
pair { "F17"sv, Key::F17 },
pair { "F18"sv, Key::F18 },
pair { "F19"sv, Key::F19 },
pair { "F20"sv, Key::F20 },
pair { "F21"sv, Key::F21 },
pair { "F22"sv, Key::F22 },
pair { "F23"sv, Key::F23 },
pair { "F24"sv, Key::F24 },
pair { "F25"sv, Key::F25 },
pair { "F26"sv, Key::F26 },
pair { "F27"sv, Key::F27 },
pair { "F28"sv, Key::F28 },
pair { "F29"sv, Key::F29 },
pair { "F30"sv, Key::F30 },
pair { "F31"sv, Key::F31 },
pair { "F32"sv, Key::F32 },
pair { "F33"sv, Key::F33 },
pair { "F34"sv, Key::F34 },
pair { "F35"sv, Key::F35 },
pair { "Escape"sv, Key::Escape },
pair { "Enter"sv, Key::Enter },
pair { "Tab"sv, Key::Tab },
pair { "Backspace"sv, Key::Backspace },
pair { "DownArrow"sv, Key::DownArrow },
pair { "LeftArrow"sv, Key::LeftArrow },
pair { "RightArrow"sv, Key::RightArrow },
pair { "UpArrow"sv, Key::UpArrow },
pair { "Insert"sv, Key::Insert },
pair { "Delete"sv, Key::Delete },
pair { "Home"sv, Key::Home },
pair { "End"sv, Key::End },
pair { "PageUp"sv, Key::PageUp },
pair { "PageDown"sv, Key::PageDown },
pair { "MediaPlay"sv, Key::MediaPlay },
pair { "MediaStop"sv, Key::MediaStop },
pair { "MediaPrevious"sv, Key::MediaPrevious },
pair { "MediaNext"sv, Key::MediaNext },
pair { "MediaPause"sv, Key::MediaPause },
pair { "MediaTogglePlayPause"sv, Key::MediaTogglePlayPause },
pair { "VolumeUp"sv, Key::VolumeUp },
pair { "VolumeDown"sv, Key::VolumeDown },
pair { "VolumeMute"sv, Key::VolumeMute },
pair { "PrintScreen"sv, Key::PrintScreen },
pair { "Pause"sv, Key::Pause },
pair { "Menu"sv, Key::Menu },
};

auto const lowerName = toLower(name);

Expand All @@ -594,31 +616,15 @@ namespace
if (text.size() == 1)
return static_cast<char32_t>(text[0]);

auto constexpr NamedChars = array { pair { "ENTER"sv, (char) C0::CR },
pair { "BACKSPACE"sv, (char) C0::BS },
pair { "TAB"sv, (char) C0::HT },
pair { "ESCAPE"sv, (char) C0::ESC },

pair { "LESS"sv, '<' },
pair { "GREATER"sv, '>' },
pair { "PLUS"sv, '+' },

pair { "APOSTROPHE"sv, '\'' },
pair { "ADD"sv, '+' },
pair { "BACKSLASH"sv, 'x' },
pair { "COMMA"sv, ',' },
pair { "DECIMAL"sv, '.' },
pair { "DIVIDE"sv, '/' },
pair { "EQUAL"sv, '=' },
pair { "LEFT_BRACKET"sv, '[' },
pair { "MINUS"sv, '-' },
pair { "MULTIPLY"sv, '*' },
pair { "PERIOD"sv, '.' },
pair { "RIGHT_BRACKET"sv, ']' },
pair { "SEMICOLON"sv, ';' },
pair { "SLASH"sv, '/' },
pair { "SUBTRACT"sv, '-' },
pair { "SPACE"sv, ' ' } };
auto constexpr NamedChars = array {
pair { "LESS"sv, '<' }, pair { "GREATER"sv, '>' }, pair { "PLUS"sv, '+' },
pair { "APOSTROPHE"sv, '\'' }, pair { "ADD"sv, '+' }, pair { "BACKSLASH"sv, 'x' },
pair { "COMMA"sv, ',' }, pair { "DECIMAL"sv, '.' }, pair { "DIVIDE"sv, '/' },
pair { "EQUAL"sv, '=' }, pair { "LEFT_BRACKET"sv, '[' }, pair { "MINUS"sv, '-' },
pair { "MULTIPLY"sv, '*' }, pair { "PERIOD"sv, '.' }, pair { "RIGHT_BRACKET"sv, ']' },
pair { "SEMICOLON"sv, ';' }, pair { "SLASH"sv, '/' }, pair { "SUBTRACT"sv, '-' },
pair { "SPACE"sv, ' ' }
};

auto const lowerName = toUpper(name);
for (auto const& mapping: NamedChars)
Expand Down Expand Up @@ -661,8 +667,14 @@ namespace
return Modifier::Key::Control;
if (upperKey == "SHIFT")
return Modifier::Key::Shift;
if (upperKey == "SUPER")
return Modifier::Key::Super;
if (upperKey == "META")
return Modifier::Key::Meta;
// TODO: This is technically not correct, but we used the term Meta up until now,
// to refer to the Windows/Cmd key. But Qt also exposes another modifier called
// Meta, which rarely exists on modern keyboards (?), but it we need to support it
// as well, especially since extended CSIu protocol exposes it as well.
return Modifier::Key::Super; // Return Modifier::Key::Meta in the future.
return nullopt;
}

Expand Down
29 changes: 29 additions & 0 deletions src/contour/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ bool sendKeyEvent(QKeyEvent* event, TerminalSession& session)
pair { Qt::Key_F18, Key::F18 },
pair { Qt::Key_F19, Key::F19 },
pair { Qt::Key_F20, Key::F20 },

pair { Qt::Key_MediaPlay, Key::MediaPlay },
pair { Qt::Key_MediaStop, Key::MediaStop },
pair { Qt::Key_MediaPrevious, Key::MediaPrevious },
pair { Qt::Key_MediaNext, Key::MediaNext },
pair { Qt::Key_MediaPause, Key::MediaPause },
pair { Qt::Key_MediaTogglePlayPause, Key::MediaTogglePlayPause },

pair { Qt::Key_VolumeUp, Key::VolumeUp },
pair { Qt::Key_VolumeDown, Key::VolumeDown },
pair { Qt::Key_VolumeMute, Key::VolumeMute },

pair { Qt::Key_Control, Key::Control },
pair { Qt::Key_Alt, Key::Alt },
pair { Qt::Key_Super_L, Key::LeftSuper },
pair { Qt::Key_Super_R, Key::RightSuper },
pair { Qt::Key_Hyper_L, Key::LeftHyper },
pair { Qt::Key_Hyper_R, Key::RightHyper },
pair { Qt::Key_Meta, Key::Meta },

pair { Qt::Key_CapsLock, Key::CapsLock },
pair { Qt::Key_ScrollLock, Key::ScrollLock },
pair { Qt::Key_NumLock, Key::NumLock },
pair { Qt::Key_Print, Key::PrintScreen },
pair { Qt::Key_Pause, Key::Pause },
pair { Qt::Key_Menu, Key::Menu },

// pair { Qt::Key_Num

}; // }}}

static auto constexpr CharMappings = array {
Expand Down
26 changes: 26 additions & 0 deletions src/crispy/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ template <typename flag_type>
class flags
{
public:
flags() noexcept = default;
flags(flag_type flag) noexcept { enable(flag); }

constexpr void enable(flag_type flag) noexcept { _value |= static_cast<unsigned>(flag); }
constexpr void disable(flag_type flag) noexcept { _value &= ~static_cast<unsigned>(flag); }

Expand All @@ -45,8 +48,31 @@ class flags
return *this;
}

[[nodiscard]] constexpr bool none() const noexcept { return _value == 0; }
[[nodiscard]] constexpr bool any() const noexcept { return _value != 0; }

[[nodiscard]] constexpr unsigned value() const noexcept { return _value; }

// NOLINTNEXTLINE(readability-identifier-naming)
[[nodiscard]] static constexpr flags<flag_type> from_value(unsigned value) noexcept
{
auto result = flags<flag_type> {};
result._value = value;
return result;
}

[[nodiscard]] constexpr flags<flag_type> with(flag_type flag) const noexcept
{
return flags<flag_type>::from_value(_value) | flag;
}

[[nodiscard]] constexpr flags<flag_type> without(flag_type flag) const noexcept
{
auto result = flags<flag_type>::from_value(_value);
result &= flag;
return result;
}

private:
unsigned _value = 0;
};
Expand Down
21 changes: 1 addition & 20 deletions src/vtbackend/InputGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,6 @@ namespace mappings

array<KeyMapping, 21> const applicationKeypad {
// clang-format off
KeyMapping { Key::Numpad_NumLock, SS3 "P" },
KeyMapping { Key::Numpad_Divide, SS3 "Q" },
KeyMapping { Key::Numpad_Multiply, SS3 "Q" },
KeyMapping { Key::Numpad_Subtract, SS3 "Q" },
KeyMapping { Key::Numpad_CapsLock, SS3 "m" },
KeyMapping { Key::Numpad_Add, SS3 "l" },
KeyMapping { Key::Numpad_Decimal, SS3 "n" },
KeyMapping { Key::Numpad_Enter, SS3 "M" },
KeyMapping { Key::Numpad_Equal, SS3 "X" },
KeyMapping { Key::Numpad_0, SS3 "p" },
KeyMapping { Key::Numpad_1, SS3 "q" },
KeyMapping { Key::Numpad_2, SS3 "r" },
KeyMapping { Key::Numpad_3, SS3 "s" },
KeyMapping { Key::Numpad_4, SS3 "t" },
KeyMapping { Key::Numpad_5, SS3 "u" },
KeyMapping { Key::Numpad_6, SS3 "v" },
KeyMapping { Key::Numpad_7, SS3 "w" },
KeyMapping { Key::Numpad_8, SS3 "x" },
KeyMapping { Key::Numpad_9, SS3 "y" },
KeyMapping { Key::PageUp, CSI "5~" },
KeyMapping { Key::PageDown, CSI "6~" },
// KeyMapping{Key::Space, SS3 " "}, // TODO
Expand Down Expand Up @@ -230,7 +211,7 @@ bool InputGenerator::generate(char32_t characterEvent, Modifier modifier)
char const chr = static_cast<char>(characterEvent);

// See section "Alt and Meta Keys" in ctlseqs.txt from xterm.
if (modifier.alt())
if (modifier == Modifier::Alt)
// NB: There are other modes in xterm to send Alt+Key options or even send ESC on Meta key instead.
append("\033");

Expand Down
Loading