Skip to content

Commit

Permalink
Instead of option_as_alt introduce command_as_alt and fix behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Jan 31, 2025
1 parent fdf03a3 commit 8d2a018
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ void YAMLConfigReader::loadFromEntry(YAML::Node const& node, std::string const&
loadFromEntry(child, "insert_after_yank", where.insertAfterYank);
loadFromEntry(child, "bell", where.bell);
loadFromEntry(child, "wm_class", where.wmClass);
loadFromEntry(child, "command_as_alt", where.commandKeyAsAlt);
loadFromEntry(child, "margins", where.margins);
loadFromEntry(child, "terminal_id", where.terminalId);
loadFromEntry(child, "frozen_dec_modes", where.frozenModes);
Expand Down
2 changes: 1 addition & 1 deletion src/contour/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ struct TerminalProfile
ConfigEntry<HyperlinkDecorationConfig, documentation::HyperlinkDecoration> hyperlinkDecoration {};

ConfigEntry<std::string, documentation::WMClass> wmClass { CONTOUR_APP_ID };
ConfigEntry<bool, documentation::OptionKeyAsAlt> optionKeyAsAlt { false };
ConfigEntry<bool, documentation::CommandKeyAsAlt> commandKeyAsAlt { true };
};

const InputMappings defaultInputMappings {
Expand Down
16 changes: 8 additions & 8 deletions src/contour/ConfigDocumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1631,22 +1631,22 @@ constexpr StringLiteral HyperlinkDecorationWeb {

};

constexpr StringLiteral OptionKeyAsAltConfig {
"{comment} Tells Contour how to handle Option-Key events on MacOS.\n"
constexpr StringLiteral CommandKeyAsAltConfig {
"{comment} Tells Contour how to handle Command-Key events on MacOS.\n"
"{comment} This value is ignored on other platforms.\n"
"{comment}\n"
"{comment} Default: false\n"
"option_as_alt: {}\n"
"{comment} Default: true\n"
"command_as_alt: {}\n"
"\n"
};

constexpr StringLiteral OptionKeyAsAltWeb {
"section tells Contour how to handle Option-Key events on MacOS.\n"
constexpr StringLiteral CommandKeyAsAltWeb {
"section tells Contour how to handle Command-Key events on MacOS.\n"
"This value is ignored on other platforms.\n"
"``` yaml\n"
"profiles:\n"
" profile_name:\n"
" option_as_alt: false\n"
" command_as_alt: false\n"
"```\n"
"\n"
};
Expand Down Expand Up @@ -1753,7 +1753,7 @@ using TerminalId = DocumentationEntry<TerminalIdConfig, TerminalIdWeb>;
using History = DocumentationEntry<HistoryConfig, HistoryWeb>;
using Scrollbar = DocumentationEntry<ScrollbarConfig, ScrollbarWeb>;
using StatusLine = DocumentationEntry<StatusLineConfig, StatusLineWeb>;
using OptionKeyAsAlt = DocumentationEntry<OptionKeyAsAltConfig, OptionKeyAsAltWeb>;
using CommandKeyAsAlt = DocumentationEntry<CommandKeyAsAltConfig, CommandKeyAsAltWeb>;
using Fonts = DocumentationEntry<FontsConfig, FontsWeb>;
using Permissions = DocumentationEntry<PermissionsConfig, PermissionsWeb>;
using DrawBoldTextWithBrightColors =
Expand Down
2 changes: 1 addition & 1 deletion src/contour/contour.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ profiles:
# This value is ignored on other platforms.
#
# Default: false
option_as_alt: false
command_as_alt: false

# Environment variables to be passed to the shell.
# environment:
Expand Down
8 changes: 4 additions & 4 deletions src/contour/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ bool sendKeyEvent(QKeyEvent* event, vtbackend::KeyboardEventType eventType, Term
return true;
}

#if defined(__apple__)
if (0x20 <= key && key < 0x80 && (modifiers.alt() && session.profile().optionKeyAsAlt.value()))
#if defined(__APPLE__)
if (0x20 <= key && key < 0x80
&& ((modifiers & Modifier::Super) && session.profile().commandKeyAsAlt.value()))
{
auto const ch = static_cast<char32_t>(modifiers.shift() ? std::toupper(key) : std::tolower(key));
session.sendCharEvent(ch, physicalKey, modifiers, eventType, now);
session.sendCharEvent(key, physicalKey, Modifier::Alt, vtbackend::KeyboardEventType::Press, now);
event->accept();
return true;
}
Expand Down

0 comments on commit 8d2a018

Please sign in to comment.