mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
KeyboardMapper: Add support for dynamic keyboard visualization
This commit is contained in:
parent
d47573eba6
commit
a69598a670
3 changed files with 45 additions and 0 deletions
|
@ -199,6 +199,10 @@ void KeyboardMapperWidget::keydown_event(GUI::KeyEvent& event)
|
||||||
tmp_button->update();
|
tmp_button->update();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_automatic_modifier && event.modifiers() > 0) {
|
||||||
|
update_modifier_radio_buttons(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardMapperWidget::keyup_event(GUI::KeyEvent& event)
|
void KeyboardMapperWidget::keyup_event(GUI::KeyEvent& event)
|
||||||
|
@ -211,6 +215,10 @@ void KeyboardMapperWidget::keyup_event(GUI::KeyEvent& event)
|
||||||
tmp_button->update();
|
tmp_button->update();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_automatic_modifier) {
|
||||||
|
update_modifier_radio_buttons(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardMapperWidget::set_current_map(const String current_map)
|
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());
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
ErrorOr<void> save();
|
ErrorOr<void> save();
|
||||||
ErrorOr<void> save_to_file(StringView);
|
ErrorOr<void> save_to_file(StringView);
|
||||||
void show_error_to_user(Error);
|
void show_error_to_user(Error);
|
||||||
|
void set_automatic_modifier(bool checked);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void keydown_event(GUI::KeyEvent&) override;
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||||
|
@ -37,9 +38,11 @@ private:
|
||||||
RefPtr<GUI::Widget> m_map_group;
|
RefPtr<GUI::Widget> m_map_group;
|
||||||
void add_map_radio_button(const StringView map_name, const StringView button_text);
|
void add_map_radio_button(const StringView map_name, const StringView button_text);
|
||||||
u32* map_from_name(const StringView map_name);
|
u32* map_from_name(const StringView map_name);
|
||||||
|
void update_modifier_radio_buttons(GUI::KeyEvent&);
|
||||||
|
|
||||||
String m_filename;
|
String m_filename;
|
||||||
Keyboard::CharacterMapData m_character_map;
|
Keyboard::CharacterMapData m_character_map;
|
||||||
String m_current_map_name;
|
String m_current_map_name;
|
||||||
bool m_modified { false };
|
bool m_modified { false };
|
||||||
|
bool m_automatic_modifier { false };
|
||||||
};
|
};
|
||||||
|
|
|
@ -80,6 +80,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
app->quit();
|
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");
|
auto& file_menu = window->add_menu("&File");
|
||||||
file_menu.add_action(open_action);
|
file_menu.add_action(open_action);
|
||||||
file_menu.add_action(save_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_separator();
|
||||||
file_menu.add_action(quit_action);
|
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");
|
auto& help_menu = window->add_menu("&Help");
|
||||||
help_menu.add_action(GUI::CommonActions::make_about_action("Keyboard Mapper", app_icon, window));
|
help_menu.add_action(GUI::CommonActions::make_about_action("Keyboard Mapper", app_icon, window));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue