1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:27:35 +00:00

Kernel: Stop using LibKeyboard's CharacterMap in HIDManagement

This was easily done, as the Kernel and Userland don't actually share
any of the APIs exposed by it, so instead the Kernel APIs were moved to
the Kernel, and the Userland APIs stayed in LibKeyboard.

This has multiple advantages:
 * The non OOM-fallible String is not longer used for storing the
   character map name in the Kernel
 * The kernel no longer has to link to the userland LibKeyboard code
 * A lot of #ifdef KERNEL cruft can be removed from LibKeyboard
This commit is contained in:
Idan Horowitz 2022-01-21 15:22:36 +02:00 committed by Andreas Kling
parent cecfd42916
commit 0adee378fd
7 changed files with 58 additions and 89 deletions

View file

@ -87,15 +87,16 @@ size_t HIDManagement::generate_minor_device_number_for_keyboard()
}
UNMAP_AFTER_INIT HIDManagement::HIDManagement()
: m_character_map("en-us", DEFAULT_CHARACTER_MAP)
: m_character_map_name(KString::must_create("en-us"sv))
, m_character_map(DEFAULT_CHARACTER_MAP)
{
}
void HIDManagement::set_maps(const Keyboard::CharacterMapData& character_map_data, const String& character_map_name)
void HIDManagement::set_maps(NonnullOwnPtr<KString> character_map_name, Keyboard::CharacterMapData const& character_map_data)
{
m_character_map.set_character_map_data(character_map_data);
m_character_map.set_character_map_name(character_map_name);
dbgln("New Character map '{}' passed in by client.", character_map_name);
m_character_map_name = move(character_map_name);
m_character_map = character_map_data;
dbgln("New Character map '{}' passed in by client.", m_character_map_name);
}
UNMAP_AFTER_INIT void HIDManagement::enumerate()
@ -129,4 +130,41 @@ HIDManagement& HIDManagement::the()
return *s_the;
}
u32 HIDManagement::get_char_from_character_map(KeyEvent event) const
{
auto modifiers = event.modifiers();
auto index = event.scancode & 0xFF; // Index is last byte of scan code.
auto caps_lock_on = event.caps_lock_on;
u32 code_point;
if (modifiers & Mod_Alt)
code_point = m_character_map.alt_map[index];
else if ((modifiers & Mod_Shift) && (modifiers & Mod_AltGr))
code_point = m_character_map.shift_altgr_map[index];
else if (modifiers & Mod_Shift)
code_point = m_character_map.shift_map[index];
else if (modifiers & Mod_AltGr)
code_point = m_character_map.altgr_map[index];
else
code_point = m_character_map.map[index];
if (caps_lock_on && (modifiers == 0 || modifiers == Mod_Shift)) {
if (code_point >= 'a' && code_point <= 'z')
code_point &= ~0x20;
else if (code_point >= 'A' && code_point <= 'Z')
code_point |= 0x20;
}
if (event.e0_prefix && event.key == Key_Slash) {
// If Key_Slash (scancode = 0x35) mapped to other form "/", we fix num pad key of "/" with this case.
code_point = '/';
} else if (event.e0_prefix && event.key != Key_Return) {
// Except for `keypad-/` and 'keypad-return', all e0 scan codes are not actually characters. i.e., `keypad-0` and
// `Insert` have the same scancode except for the prefix, but insert should not have a code_point.
code_point = 0;
}
return code_point;
}
}