1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:37:34 +00:00

KeyboardMapper: Add support for dynamic keyboard visualization

This commit is contained in:
Jean-Paul Balabanian 2022-01-07 18:01:58 +01:00 committed by Linus Groh
parent d47573eba6
commit a69598a670
3 changed files with 45 additions and 0 deletions

View file

@ -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);
}