mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:27:35 +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
|
@ -60,8 +60,9 @@ enum MouseButton : u8 {
|
|||
|
||||
class KeyEvent final : public Event {
|
||||
public:
|
||||
KeyEvent(Type type, int key, u32 code_point, u8 modifiers, u32 scancode)
|
||||
KeyEvent(Type type, int key, u8 map_entry_index, u32 code_point, u8 modifiers, u32 scancode)
|
||||
: Event(type)
|
||||
, m_map_entry_index(map_entry_index)
|
||||
, m_key(key)
|
||||
, m_code_point(code_point)
|
||||
, m_modifiers(modifiers)
|
||||
|
@ -77,10 +78,12 @@ public:
|
|||
u8 modifiers() const { return m_modifiers; }
|
||||
u32 code_point() const { return m_code_point; }
|
||||
u32 scancode() const { return m_scancode; }
|
||||
u8 map_entry_index() const { return m_map_entry_index; }
|
||||
|
||||
private:
|
||||
friend class EventLoop;
|
||||
friend class Screen;
|
||||
u8 m_map_entry_index { 0 };
|
||||
int m_key { 0 };
|
||||
u32 m_code_point { 0 };
|
||||
u8 m_modifiers { 0 };
|
||||
|
|
|
@ -459,7 +459,7 @@ void ScreenInput::on_receive_mouse_data(MousePacket const& packet)
|
|||
void ScreenInput::on_receive_keyboard_data(::KeyEvent kernel_event)
|
||||
{
|
||||
m_modifiers = kernel_event.modifiers();
|
||||
auto message = make<KeyEvent>(kernel_event.is_press() ? Event::KeyDown : Event::KeyUp, kernel_event.key, kernel_event.code_point, kernel_event.modifiers(), kernel_event.scancode);
|
||||
auto message = make<KeyEvent>(kernel_event.is_press() ? Event::KeyDown : Event::KeyUp, kernel_event.key, kernel_event.map_entry_index, kernel_event.code_point, kernel_event.modifiers(), kernel_event.scancode);
|
||||
Core::EventLoop::current().post_event(WindowManager::the(), move(message));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -15,8 +15,8 @@ endpoint WindowClient
|
|||
window_left(i32 window_id) =|
|
||||
window_input_preempted(i32 window_id) =|
|
||||
window_input_restored(i32 window_id) =|
|
||||
key_down(i32 window_id, u32 code_point, u32 key, u32 modifiers, u32 scancode) =|
|
||||
key_up(i32 window_id, u32 code_point, u32 key, u32 modifiers, u32 scancode) =|
|
||||
key_down(i32 window_id, u32 code_point, u32 key, u8 map_entry_index, u32 modifiers, u32 scancode) =|
|
||||
key_up(i32 window_id, u32 code_point, u32 key, u8 map_entry_index, u32 modifiers, u32 scancode) =|
|
||||
window_activated(i32 window_id) =|
|
||||
window_deactivated(i32 window_id) =|
|
||||
window_state_changed(i32 window_id, bool minimized, bool maximized, bool occluded) =|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue