mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
Userland: Actually use the correct character map index from KeyEvent
Instead of using a scan code, which for scan code set 2 will not represent the expected character mapping index, we could just use another variable in the KeyEvent structure that correctly points to the character index. This change is mostly relevant to the KeyboardMapper application, and also to the WindowServer code, as both handle KeyEvents and need to use the character mapping index in various situations.
This commit is contained in:
parent
b89cc81674
commit
60a96b3786
9 changed files with 41 additions and 32 deletions
|
@ -477,6 +477,7 @@ void Window::event(Core::Event& event)
|
|||
m_client->async_key_up(m_window_id,
|
||||
(u32) static_cast<KeyEvent const&>(event).code_point(),
|
||||
(u32) static_cast<KeyEvent const&>(event).key(),
|
||||
(u8) static_cast<KeyEvent const&>(event).map_entry_index(),
|
||||
static_cast<KeyEvent const&>(event).modifiers(),
|
||||
(u32) static_cast<KeyEvent const&>(event).scancode());
|
||||
break;
|
||||
|
@ -516,33 +517,34 @@ void Window::handle_keydown_event(KeyEvent const& event)
|
|||
if (event.modifiers() == Mod_Alt && event.code_point() && m_menubar.has_menus()) {
|
||||
// When handling alt shortcuts, we only care about the key that has been pressed in addition
|
||||
// to alt, not the code point that has been mapped to alt+[key], so we have to look up the
|
||||
// scancode directly from the "unmodified" character map.
|
||||
// kernel map_entry_index value directly from the "unmodified" character map.
|
||||
auto character_map_or_error = Keyboard::CharacterMap::fetch_system_map();
|
||||
if (!character_map_or_error.is_error()) {
|
||||
auto& character_map = character_map_or_error.value();
|
||||
|
||||
// The lowest byte serves as our index into the character table.
|
||||
auto index = event.scancode() & 0xff;
|
||||
u32 character = to_ascii_lowercase(character_map.character_map_data().map[index]);
|
||||
auto index = event.map_entry_index();
|
||||
if (index != 0xff) {
|
||||
u32 character = to_ascii_lowercase(character_map.character_map_data().map[index]);
|
||||
|
||||
Menu* menu_to_open = nullptr;
|
||||
m_menubar.for_each_menu([&](Menu& menu) {
|
||||
if (to_ascii_lowercase(menu.alt_shortcut_character()) == character) {
|
||||
menu_to_open = &menu;
|
||||
return IterationDecision::Break;
|
||||
Menu* menu_to_open = nullptr;
|
||||
m_menubar.for_each_menu([&](Menu& menu) {
|
||||
if (to_ascii_lowercase(menu.alt_shortcut_character()) == character) {
|
||||
menu_to_open = &menu;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
if (menu_to_open) {
|
||||
frame().open_menubar_menu(*menu_to_open);
|
||||
if (!menu_to_open->is_empty())
|
||||
menu_to_open->set_hovered_index(0);
|
||||
return;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
if (menu_to_open) {
|
||||
frame().open_menubar_menu(*menu_to_open);
|
||||
if (!menu_to_open->is_empty())
|
||||
menu_to_open->set_hovered_index(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_client->async_key_down(m_window_id, (u32)event.code_point(), (u32)event.key(), event.modifiers(), (u32)event.scancode());
|
||||
m_client->async_key_down(m_window_id, (u32)event.code_point(), (u32)event.key(), (u8)event.map_entry_index(), event.modifiers(), (u32)event.scancode());
|
||||
}
|
||||
|
||||
void Window::set_visible(bool b)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue