diff options
author | Jean-Paul Balabanian <jepebe@users.noreply.github.com> | 2022-01-07 18:01:58 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-08 11:50:26 +0100 |
commit | a69598a670bc5fca75c541222928618a18fd1fb4 (patch) | |
tree | aecab58f9a0f4bd9a38296417ec25191b38f7ab6 | |
parent | d47573eba65fe736b9d1c546ce003efe3540ea9a (diff) | |
download | serenity-a69598a670bc5fca75c541222928618a18fd1fb4.zip |
KeyboardMapper: Add support for dynamic keyboard visualization
3 files changed, 45 insertions, 0 deletions
diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp index 9b8cdc19d6..941162d8d2 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp @@ -199,6 +199,10 @@ void KeyboardMapperWidget::keydown_event(GUI::KeyEvent& event) tmp_button->update(); break; } + + if (m_automatic_modifier && event.modifiers() > 0) { + update_modifier_radio_buttons(event); + } } void KeyboardMapperWidget::keyup_event(GUI::KeyEvent& event) @@ -211,6 +215,10 @@ void KeyboardMapperWidget::keyup_event(GUI::KeyEvent& event) tmp_button->update(); break; } + + if (m_automatic_modifier) { + update_modifier_radio_buttons(event); + } } void KeyboardMapperWidget::set_current_map(const String current_map) @@ -247,3 +255,27 @@ void KeyboardMapperWidget::show_error_to_user(Error error) { GUI::MessageBox::show_error(window(), error.string_literal()); } + +void KeyboardMapperWidget::set_automatic_modifier(bool checked) +{ + m_automatic_modifier = checked; +} + +void KeyboardMapperWidget::update_modifier_radio_buttons(GUI::KeyEvent& event) +{ + GUI::RadioButton* radio_button; + if (event.shift() && event.altgr()) { + radio_button = m_map_group->find_child_of_type_named<GUI::RadioButton>("shift_altgr_map"); + } else if (event.altgr()) { + radio_button = m_map_group->find_child_of_type_named<GUI::RadioButton>("altgr_map"); + } else if (event.alt()) { + radio_button = m_map_group->find_child_of_type_named<GUI::RadioButton>("alt_map"); + } else if (event.shift()) { + radio_button = m_map_group->find_child_of_type_named<GUI::RadioButton>("shift_map"); + } else { + radio_button = m_map_group->find_child_of_type_named<GUI::RadioButton>("map"); + } + + if (radio_button) + radio_button->set_checked(true); +} diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h index 810d1b1f1b..90807f4069 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h @@ -22,6 +22,7 @@ public: ErrorOr<void> save(); ErrorOr<void> save_to_file(StringView); void show_error_to_user(Error); + void set_automatic_modifier(bool checked); protected: virtual void keydown_event(GUI::KeyEvent&) override; @@ -37,9 +38,11 @@ private: RefPtr<GUI::Widget> m_map_group; void add_map_radio_button(const StringView map_name, const StringView button_text); u32* map_from_name(const StringView map_name); + void update_modifier_radio_buttons(GUI::KeyEvent&); String m_filename; Keyboard::CharacterMapData m_character_map; String m_current_map_name; bool m_modified { false }; + bool m_automatic_modifier { false }; }; diff --git a/Userland/Applications/KeyboardMapper/main.cpp b/Userland/Applications/KeyboardMapper/main.cpp index 5ec7ccbbdf..e210616456 100644 --- a/Userland/Applications/KeyboardMapper/main.cpp +++ b/Userland/Applications/KeyboardMapper/main.cpp @@ -80,6 +80,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) app->quit(); }); + auto auto_modifier_action = GUI::Action::create("Auto Modifier", [&](auto& act) { + keyboard_mapper_widget->set_automatic_modifier(act.is_checked()); + }); + auto_modifier_action->set_status_tip("Toggle automatic modifier"); + auto_modifier_action->set_checkable(true); + auto_modifier_action->set_checked(false); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(open_action); file_menu.add_action(save_action); @@ -87,6 +94,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) file_menu.add_separator(); file_menu.add_action(quit_action); + auto& settings_menu = window->add_menu("&Settings"); + settings_menu.add_action(auto_modifier_action); + auto& help_menu = window->add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Keyboard Mapper", app_icon, window)); |