Kernel: Allow backspace '\b' to be remapped

Previously, one could put '\b' in a keymap, but in non-Terminal
applications, it would just insert a literal '\b' character instead of
behaving like backspace. This patch modifes
`visible_code_point_to_key_code` to include backspace, as well as
renaming it to `code_point_to_key_code` since '\b' is not a visible
character. Additionally, `KeyboardDevice::key_state_changed` has been
rearranged to apply the user's keymap before checking for things like
caps lock.
This commit is contained in:
Corey Williamson 2021-12-21 00:46:46 -06:00 committed by Andreas Kling
parent 452150c632
commit f51834d610
2 changed files with 15 additions and 12 deletions

View file

@ -168,7 +168,7 @@ inline const char* key_code_to_string(KeyCode key)
}
}
inline KeyCode visible_code_point_to_key_code(u32 code_point)
inline KeyCode code_point_to_key_code(u32 code_point)
{
switch (code_point) {
#define MATCH_ALPHA(letter) \
@ -250,6 +250,7 @@ inline KeyCode visible_code_point_to_key_code(u32 code_point)
MATCH_KEY(Backtick, '`')
MATCH_KEY(Space, ' ')
MATCH_KEY(Tab, '\t')
MATCH_KEY(Backspace, '\b')
#undef MATCH_KEY
default:

View file

@ -228,15 +228,6 @@ void KeyboardDevice::key_state_changed(u8 scan_code, bool pressed)
}
}
if (!g_caps_lock_remapped_to_ctrl && key == Key_CapsLock && pressed)
m_caps_lock_on = !m_caps_lock_on;
if (g_caps_lock_remapped_to_ctrl && key == Key_CapsLock)
m_caps_lock_to_ctrl_pressed = pressed;
if (g_caps_lock_remapped_to_ctrl)
update_modifier(Mod_Ctrl, m_caps_lock_to_ctrl_pressed);
Event event;
event.key = key;
event.scancode = m_has_e0_prefix ? 0xe000 + scan_code : scan_code;
@ -246,9 +237,20 @@ void KeyboardDevice::key_state_changed(u8 scan_code, bool pressed)
event.code_point = HIDManagement::the().character_map().get_char(event);
// If using a non-QWERTY layout, event.key needs to be updated to be the same as event.code_point
KeyCode mapped_key = visible_code_point_to_key_code(event.code_point);
if (mapped_key != KeyCode::Key_Invalid)
KeyCode mapped_key = code_point_to_key_code(event.code_point);
if (mapped_key != KeyCode::Key_Invalid) {
event.key = mapped_key;
key = mapped_key;
}
if (!g_caps_lock_remapped_to_ctrl && key == Key_CapsLock && pressed)
m_caps_lock_on = !m_caps_lock_on;
if (g_caps_lock_remapped_to_ctrl && key == Key_CapsLock)
m_caps_lock_to_ctrl_pressed = pressed;
if (g_caps_lock_remapped_to_ctrl)
update_modifier(Mod_Ctrl, m_caps_lock_to_ctrl_pressed);
if (pressed)
event.flags |= Is_Press;