mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 06:37:40 +00:00
LibKeyboard: Move character map from Kernel to LibKeyboard
This commit is contained in:
parent
3ebdb5ea30
commit
f79b410baa
3 changed files with 99 additions and 4 deletions
|
@ -26,22 +26,65 @@
|
||||||
|
|
||||||
#include "CharacterMap.h"
|
#include "CharacterMap.h"
|
||||||
#include <Kernel/Syscall.h>
|
#include <Kernel/Syscall.h>
|
||||||
#include <LibKeyboard/CharacterMapFile.h>
|
#ifndef KERNEL
|
||||||
|
# include <LibKeyboard/CharacterMapFile.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Keyboard {
|
namespace Keyboard {
|
||||||
|
|
||||||
CharacterMap::CharacterMap(const String& file_name)
|
CharacterMap::CharacterMap(const String& file_name)
|
||||||
{
|
{
|
||||||
|
#ifdef KERNEL
|
||||||
|
UNUSED_PARAM(file_name);
|
||||||
|
m_character_map_data = default_character_map;
|
||||||
|
#else
|
||||||
auto result = CharacterMapFile::load_from_file(file_name);
|
auto result = CharacterMapFile::load_from_file(file_name);
|
||||||
ASSERT(result.has_value());
|
ASSERT(result.has_value());
|
||||||
|
|
||||||
m_character_map = result.value();
|
m_character_map_data = result.value();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int CharacterMap::set_system_map()
|
int CharacterMap::set_system_map()
|
||||||
{
|
{
|
||||||
Syscall::SC_setkeymap_params params { m_character_map.map, m_character_map.shift_map, m_character_map.alt_map, m_character_map.altgr_map };
|
Syscall::SC_setkeymap_params params { m_character_map_data.map, m_character_map_data.shift_map, m_character_map_data.alt_map, m_character_map_data.altgr_map };
|
||||||
return syscall(SC_setkeymap, ¶ms);
|
return syscall(SC_setkeymap, ¶ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char CharacterMap::get_char(KeyEvent event)
|
||||||
|
{
|
||||||
|
auto modifiers = event.modifiers();
|
||||||
|
auto index = event.scancode & 0xFF; // Index is last byte of scan code.
|
||||||
|
auto caps_lock_on = event.caps_lock_on;
|
||||||
|
|
||||||
|
char character;
|
||||||
|
if (modifiers & Mod_Shift)
|
||||||
|
character = m_character_map_data.shift_map[index];
|
||||||
|
else if (modifiers & Mod_Alt)
|
||||||
|
character = m_character_map_data.alt_map[index];
|
||||||
|
else if (modifiers & Mod_AltGr)
|
||||||
|
character = m_character_map_data.altgr_map[index];
|
||||||
|
else
|
||||||
|
character = m_character_map_data.map[index];
|
||||||
|
|
||||||
|
if (caps_lock_on && (modifiers == 0 || modifiers == Mod_Shift)) {
|
||||||
|
if (character >= 'a' && character <= 'z')
|
||||||
|
character &= ~0x20;
|
||||||
|
else if (character >= 'A' && character <= 'Z')
|
||||||
|
character |= 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.
|
||||||
|
character = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return character;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterMap::set_character_map_data(CharacterMapData character_map_data)
|
||||||
|
{
|
||||||
|
m_character_map_data = character_map_data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
#include <Kernel/KeyCode.h>
|
||||||
#include <LibKeyboard/CharacterMapData.h>
|
#include <LibKeyboard/CharacterMapData.h>
|
||||||
|
|
||||||
namespace Keyboard {
|
namespace Keyboard {
|
||||||
|
@ -37,9 +38,11 @@ public:
|
||||||
CharacterMap(const String& file_name);
|
CharacterMap(const String& file_name);
|
||||||
|
|
||||||
int set_system_map();
|
int set_system_map();
|
||||||
|
char get_char(KeyEvent);
|
||||||
|
void set_character_map_data(CharacterMapData character_map_data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CharacterMapData m_character_map;
|
CharacterMapData m_character_map_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,53 @@ struct CharacterMapData {
|
||||||
char altgr_map[CHAR_MAP_SIZE];
|
char altgr_map[CHAR_MAP_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
static const CharacterMapData default_character_map =
|
||||||
|
{
|
||||||
|
.map = {
|
||||||
|
0, '\033', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x08,
|
||||||
|
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
|
||||||
|
0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0,
|
||||||
|
'\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*', 0,
|
||||||
|
' ', 0, 0,
|
||||||
|
//60 70 80
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, '\\', 0, 0, 0,
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
.shift_map = {
|
||||||
|
0, '\033', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0x08,
|
||||||
|
'\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',
|
||||||
|
0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0,
|
||||||
|
'|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0,
|
||||||
|
' ', 0, 0,
|
||||||
|
//60 70 80
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, '|', 0, 0, 0,
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
.alt_map = {
|
||||||
|
0, '\033', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x08,
|
||||||
|
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
|
||||||
|
0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0,
|
||||||
|
'\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*', 0,
|
||||||
|
' ', 0, 0,
|
||||||
|
|
||||||
|
//60 70 80
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, '\\', 0, 0, 0,
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
.altgr_map = {
|
||||||
|
0, '\033', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x08,
|
||||||
|
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
|
||||||
|
0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0,
|
||||||
|
'\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*', 0,
|
||||||
|
' ', 0, 0,
|
||||||
|
//60 70 80
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, '\\', 0, 0, 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue