Kernel: Keymaps can now be loaded from files

This commit is contained in:
Bananymous 2024-01-10 14:43:19 +02:00
parent e6d42e5c45
commit 8f89519bcf
7 changed files with 387 additions and 383 deletions

View File

@ -32,7 +32,7 @@ set(KERNEL_SOURCES
kernel/FS/TmpFS/FileSystem.cpp
kernel/FS/TmpFS/Inode.cpp
kernel/FS/VirtualFileSystem.cpp
kernel/Input/KeyboardLayouts/FI.cpp
kernel/Input/KeyboardLayout.cpp
kernel/Input/KeyEvent.cpp
kernel/Input/PS2/Controller.cpp
kernel/Input/PS2/Device.cpp

View File

@ -0,0 +1,30 @@
#pragma once
#include <BAN/Array.h>
#include <BAN/UniqPtr.h>
#include <kernel/Input/KeyEvent.h>
namespace Kernel::Input
{
class KeyboardLayout
{
public:
static BAN::ErrorOr<void> initialize();
static KeyboardLayout& get();
Key get_key_from_event(KeyEvent);
BAN::ErrorOr<void> load_from_file(BAN::StringView path);
private:
KeyboardLayout();
private:
BAN::Array<Key, 0xFF> m_keycode_to_key_normal;
BAN::Array<Key, 0xFF> m_keycode_to_key_shift;
BAN::Array<Key, 0xFF> m_keycode_to_key_altgr;
friend class BAN::UniqPtr<KeyboardLayout>;
};
}

View File

@ -1,8 +0,0 @@
#pragma once
namespace Kernel::Input::KeyboardLayout
{
void initialize_fi();
}

View File

@ -1,20 +1,13 @@
#include <BAN/Array.h>
#include <kernel/Input/KeyboardLayout.h>
#include <kernel/Input/KeyEvent.h>
namespace Kernel::Input
{
BAN::Array<Key, 0xFF> g_keycode_to_key_normal;
BAN::Array<Key, 0xFF> g_keycode_to_key_shift;
BAN::Array<Key, 0xFF> g_keycode_to_key_altgr;
Key key_event_to_key(KeyEvent event)
{
if (event.shift())
return g_keycode_to_key_shift[event.keycode];
if (event.ralt())
return g_keycode_to_key_altgr[event.keycode];
return g_keycode_to_key_normal[event.keycode];
return KeyboardLayout::get().get_key_from_event(event);
}
const char* key_to_utf8(Key key, uint16_t modifier)

View File

@ -0,0 +1,346 @@
#include <BAN/HashMap.h>
#include <kernel/FS/VirtualFileSystem.h>
#include <kernel/Input/KeyboardLayout.h>
#include <ctype.h>
namespace Kernel::Input
{
struct StringViewLower
{
BAN::StringView value;
StringViewLower(BAN::StringView sv)
: value(sv)
{ }
bool operator==(const StringViewLower& other) const
{
if (value.size() != other.value.size())
return false;
for (size_t i = 0; i < value.size(); i++)
if (tolower(value[i]) != tolower(other.value[i]))
return false;
return true;
}
};
struct StringViewLowerHash
{
BAN::hash_t operator()(const StringViewLower& value) const
{
constexpr BAN::hash_t FNV_offset_basis = 0x811c9dc5;
constexpr BAN::hash_t FNV_prime = 0x01000193;
BAN::hash_t hash = FNV_offset_basis;
for (size_t i = 0; i < value.value.size(); i++)
{
hash *= FNV_prime;
hash ^= (uint8_t)tolower(value.value[i]);
}
return hash;
}
};
static BAN::UniqPtr<KeyboardLayout> s_instance;
BAN::ErrorOr<void> KeyboardLayout::initialize()
{
ASSERT(!s_instance);
s_instance = TRY(BAN::UniqPtr<KeyboardLayout>::create());
return {};
}
KeyboardLayout& KeyboardLayout::get()
{
ASSERT(s_instance);
return *s_instance;
}
KeyboardLayout::KeyboardLayout()
{
for (auto& key : m_keycode_to_key_normal)
key = Key::None;
for (auto& key : m_keycode_to_key_shift)
key = Key::None;
for (auto& key : m_keycode_to_key_altgr)
key = Key::None;
}
Key KeyboardLayout::get_key_from_event(KeyEvent event)
{
if (event.shift())
return m_keycode_to_key_shift[event.keycode];
if (event.ralt())
return m_keycode_to_key_altgr[event.keycode];
return m_keycode_to_key_normal[event.keycode];
}
static BAN::Optional<uint8_t> parse_keycode(BAN::StringView str)
{
if (str.size() > 3)
return {};
uint16_t keycode = 0;
for (char c : str)
{
if (!isdigit(c))
return {};
keycode = (keycode * 10) + (c - '0');
}
if (keycode >= 0xFF)
return {};
return keycode;
}
static BAN::HashMap<StringViewLower, Key, StringViewLowerHash> s_name_to_key;
static BAN::ErrorOr<void> initialize_name_to_key();
static BAN::Optional<Key> parse_key(BAN::StringView name)
{
if (s_name_to_key.contains(name))
return s_name_to_key[name];
return {};
}
BAN::ErrorOr<void> KeyboardLayout::load_from_file(BAN::StringView path)
{
if (s_name_to_key.empty())
TRY(initialize_name_to_key());
auto inode = TRY(VirtualFileSystem::get().file_from_absolute_path({ 0, 0, 0, 0 }, path, 0)).inode;
BAN::String file_data;
TRY(file_data.resize(inode->size()));
TRY(inode->read(0, { reinterpret_cast<uint8_t*>(file_data.data()), file_data.size() }));
auto new_layout = TRY(BAN::UniqPtr<KeyboardLayout>::create());
auto lines = TRY(file_data.sv().split('\n'));
for (auto line : lines)
{
auto parts = TRY(line.split([](char c) -> bool { return isspace(c); }));
if (parts.empty() || parts.front().front() == '#')
continue;
if (parts.size() == 1)
{
dprintln("Invalid line in keymap '{}'", line);
dprintln(" format: KEYCODE KEY [MODIFIER=KEY]...");
continue;
}
auto keycode = parse_keycode(parts.front());
if (!keycode.has_value())
{
dprintln("Invalid keycode '{}', keycode must number between [0, 0xFF[", parts.front());
continue;
}
auto default_key = parse_key(parts[1]);
if (!default_key.has_value())
{
dprintln("Unrecognized key '{}'", parts[1]);
continue;
}
new_layout->m_keycode_to_key_normal[*keycode] = *default_key;
new_layout->m_keycode_to_key_shift[*keycode] = *default_key;
new_layout->m_keycode_to_key_altgr[*keycode] = *default_key;
for (size_t i = 2; i < parts.size(); i++)
{
auto pair = TRY(parts[i].split('='));
if (pair.size() != 2)
{
dprintln("Invalid modifier format '{}', modifier format: MODIFIRER=KEY", parts[i]);
continue;
}
auto key = parse_key(pair.back());
if (!key.has_value())
{
dprintln("Unrecognized key '{}'", pair.back());
continue;
}
if (pair.front() == "shift"sv)
new_layout->m_keycode_to_key_shift[*keycode] = *key;
else if (pair.front() == "altgr"sv)
new_layout->m_keycode_to_key_altgr[*keycode] = *key;
else
{
dprintln("Unrecognized modifier '{}'", pair.front());
continue;
}
}
}
m_keycode_to_key_normal = new_layout->m_keycode_to_key_normal;
m_keycode_to_key_shift = new_layout->m_keycode_to_key_shift;
m_keycode_to_key_altgr = new_layout->m_keycode_to_key_altgr;
return {};
}
static BAN::ErrorOr<void> initialize_name_to_key()
{
ASSERT(s_name_to_key.empty());
TRY(s_name_to_key.insert("A_Ring"sv, Key::A_Ring));
TRY(s_name_to_key.insert("A_Umlaut"sv, Key::A_Umlaut));
TRY(s_name_to_key.insert("A"sv, Key::A));
TRY(s_name_to_key.insert("Acute"sv, Key::Acute));
TRY(s_name_to_key.insert("AltGr"sv, Key::AltGr));
TRY(s_name_to_key.insert("Ampersand"sv, Key::Ampersand));
TRY(s_name_to_key.insert("ArrowDown"sv, Key::ArrowDown));
TRY(s_name_to_key.insert("ArrowLeft"sv, Key::ArrowLeft));
TRY(s_name_to_key.insert("ArrowRight"sv, Key::ArrowRight));
TRY(s_name_to_key.insert("ArrowUp"sv, Key::ArrowUp));
TRY(s_name_to_key.insert("Asterix"sv, Key::Asterix));
TRY(s_name_to_key.insert("AtSign"sv, Key::AtSign));
TRY(s_name_to_key.insert("B"sv, Key::B));
TRY(s_name_to_key.insert("BackSlash"sv, Key::BackSlash));
TRY(s_name_to_key.insert("Backspace"sv, Key::Backspace));
TRY(s_name_to_key.insert("BackTick"sv, Key::BackTick));
TRY(s_name_to_key.insert("C"sv, Key::C));
TRY(s_name_to_key.insert("Calculator"sv, Key::Calculator));
TRY(s_name_to_key.insert("CapsLock"sv, Key::CapsLock));
TRY(s_name_to_key.insert("Caret"sv, Key::Caret));
TRY(s_name_to_key.insert("Cedilla"sv, Key::Cedilla));
TRY(s_name_to_key.insert("CloseCurlyBracket"sv, Key::CloseCurlyBracket));
TRY(s_name_to_key.insert("CloseParenthesis"sv, Key::CloseParenthesis));
TRY(s_name_to_key.insert("CloseSquareBracket"sv, Key::CloseSquareBracket));
TRY(s_name_to_key.insert("Colon"sv, Key::Colon));
TRY(s_name_to_key.insert("Comma"sv, Key::Comma));
TRY(s_name_to_key.insert("Currency"sv, Key::Currency));
TRY(s_name_to_key.insert("D"sv, Key::D));
TRY(s_name_to_key.insert("Delete"sv, Key::Delete));
TRY(s_name_to_key.insert("Dollar"sv, Key::Dollar));
TRY(s_name_to_key.insert("DoubleQuote"sv, Key::DoubleQuote));
TRY(s_name_to_key.insert("E"sv, Key::E));
TRY(s_name_to_key.insert("End"sv, Key::End));
TRY(s_name_to_key.insert("Enter"sv, Key::Enter));
TRY(s_name_to_key.insert("Equals"sv, Key::Equals));
TRY(s_name_to_key.insert("Escape"sv, Key::Escape));
TRY(s_name_to_key.insert("Euro"sv, Key::Euro));
TRY(s_name_to_key.insert("Exclamation"sv, Key::ExclamationMark));
TRY(s_name_to_key.insert("ExclamationMark"sv, Key::ExclamationMark));
TRY(s_name_to_key.insert("F"sv, Key::F));
TRY(s_name_to_key.insert("F1"sv, Key::F1));
TRY(s_name_to_key.insert("F10"sv, Key::F10));
TRY(s_name_to_key.insert("F11"sv, Key::F11));
TRY(s_name_to_key.insert("F12"sv, Key::F12));
TRY(s_name_to_key.insert("F2"sv, Key::F2));
TRY(s_name_to_key.insert("F3"sv, Key::F3));
TRY(s_name_to_key.insert("F4"sv, Key::F4));
TRY(s_name_to_key.insert("F5"sv, Key::F5));
TRY(s_name_to_key.insert("F6"sv, Key::F6));
TRY(s_name_to_key.insert("F7"sv, Key::F7));
TRY(s_name_to_key.insert("F8"sv, Key::F8));
TRY(s_name_to_key.insert("F9"sv, Key::F9));
TRY(s_name_to_key.insert("G"sv, Key::G));
TRY(s_name_to_key.insert("GreaterThan"sv, Key::GreaterThan));
TRY(s_name_to_key.insert("H"sv, Key::H));
TRY(s_name_to_key.insert("Half"sv, Key::Half));
TRY(s_name_to_key.insert("Hashtag"sv, Key::Hashtag));
TRY(s_name_to_key.insert("Home"sv, Key::Home));
TRY(s_name_to_key.insert("Hyphen"sv, Key::Hyphen));
TRY(s_name_to_key.insert("I"sv, Key::I));
TRY(s_name_to_key.insert("Insert"sv, Key::Insert));
TRY(s_name_to_key.insert("J"sv, Key::J));
TRY(s_name_to_key.insert("K"sv, Key::K));
TRY(s_name_to_key.insert("Key0"sv, Key::_0));
TRY(s_name_to_key.insert("Key1"sv, Key::_1));
TRY(s_name_to_key.insert("Key2"sv, Key::_2));
TRY(s_name_to_key.insert("Key3"sv, Key::_3));
TRY(s_name_to_key.insert("Key4"sv, Key::_4));
TRY(s_name_to_key.insert("Key5"sv, Key::_5));
TRY(s_name_to_key.insert("Key6"sv, Key::_6));
TRY(s_name_to_key.insert("Key7"sv, Key::_7));
TRY(s_name_to_key.insert("Key8"sv, Key::_8));
TRY(s_name_to_key.insert("Key9"sv, Key::_9));
TRY(s_name_to_key.insert("L"sv, Key::L));
TRY(s_name_to_key.insert("LAlt"sv, Key::LeftAlt));
TRY(s_name_to_key.insert("LControl"sv, Key::LeftCtrl));
TRY(s_name_to_key.insert("LeftAlt"sv, Key::LeftAlt));
TRY(s_name_to_key.insert("LeftControl"sv, Key::LeftCtrl));
TRY(s_name_to_key.insert("LeftShift"sv, Key::LeftShift));
TRY(s_name_to_key.insert("LessThan"sv, Key::LessThan));
TRY(s_name_to_key.insert("LShift"sv, Key::LeftShift));
TRY(s_name_to_key.insert("M"sv, Key::M));
TRY(s_name_to_key.insert("MediaNext"sv, Key::MediaNext));
TRY(s_name_to_key.insert("MediaPlayPause"sv, Key::MediaPlayPause));
TRY(s_name_to_key.insert("MediaPrevious"sv, Key::MediaPrevious));
TRY(s_name_to_key.insert("MediaStop"sv, Key::MediaStop));
TRY(s_name_to_key.insert("N"sv, Key::N));
TRY(s_name_to_key.insert("None"sv, Key::None));
TRY(s_name_to_key.insert("NumLock"sv, Key::NumLock));
TRY(s_name_to_key.insert("Numpad0"sv, Key::Numpad0));
TRY(s_name_to_key.insert("Numpad1"sv, Key::Numpad1));
TRY(s_name_to_key.insert("Numpad2"sv, Key::Numpad2));
TRY(s_name_to_key.insert("Numpad3"sv, Key::Numpad3));
TRY(s_name_to_key.insert("Numpad4"sv, Key::Numpad4));
TRY(s_name_to_key.insert("Numpad5"sv, Key::Numpad5));
TRY(s_name_to_key.insert("Numpad6"sv, Key::Numpad6));
TRY(s_name_to_key.insert("Numpad7"sv, Key::Numpad7));
TRY(s_name_to_key.insert("Numpad8"sv, Key::Numpad8));
TRY(s_name_to_key.insert("Numpad9"sv, Key::Numpad9));
TRY(s_name_to_key.insert("NumpadDecimal"sv, Key::NumpadDecimal));
TRY(s_name_to_key.insert("NumpadDivide"sv, Key::NumpadDivide));
TRY(s_name_to_key.insert("NumpadEnter"sv, Key::NumpadEnter));
TRY(s_name_to_key.insert("NumpadMinus"sv, Key::NumpadMinus));
TRY(s_name_to_key.insert("NumpadMultiply"sv, Key::NumpadMultiply));
TRY(s_name_to_key.insert("NumpadPlus"sv, Key::NumpadPlus));
TRY(s_name_to_key.insert("O_Umlaut"sv, Key::O_Umlaut));
TRY(s_name_to_key.insert("O"sv, Key::O));
TRY(s_name_to_key.insert("OpenCurlyBracket"sv, Key::OpenCurlyBracket));
TRY(s_name_to_key.insert("OpenParenthesis"sv, Key::OpenParenthesis));
TRY(s_name_to_key.insert("OpenSquareBracket"sv, Key::OpenSquareBracket));
TRY(s_name_to_key.insert("P"sv, Key::P));
TRY(s_name_to_key.insert("PageDown"sv, Key::PageDown));
TRY(s_name_to_key.insert("PageUp"sv, Key::PageUp));
TRY(s_name_to_key.insert("Percent"sv, Key::Percent));
TRY(s_name_to_key.insert("Period"sv, Key::Period));
TRY(s_name_to_key.insert("Pipe"sv, Key::Pipe));
TRY(s_name_to_key.insert("Plus"sv, Key::Plus));
TRY(s_name_to_key.insert("Pound"sv, Key::Pound));
TRY(s_name_to_key.insert("PrintScreen"sv, Key::PrintScreen));
TRY(s_name_to_key.insert("Q"sv, Key::Q));
TRY(s_name_to_key.insert("Question"sv, Key::QuestionMark));
TRY(s_name_to_key.insert("QuestionMark"sv, Key::QuestionMark));
TRY(s_name_to_key.insert("R"sv, Key::R));
TRY(s_name_to_key.insert("RAlt"sv, Key::RightAlt));
TRY(s_name_to_key.insert("RControl"sv, Key::RightCtrl));
TRY(s_name_to_key.insert("RightAlt"sv, Key::RightAlt));
TRY(s_name_to_key.insert("RightControl"sv, Key::RightCtrl));
TRY(s_name_to_key.insert("RightShift"sv, Key::RightShift));
TRY(s_name_to_key.insert("RShift"sv, Key::RightShift));
TRY(s_name_to_key.insert("S"sv, Key::S));
TRY(s_name_to_key.insert("ScrollLock"sv, Key::ScrollLock));
TRY(s_name_to_key.insert("Section"sv, Key::Section));
TRY(s_name_to_key.insert("Semicolon"sv, Key::Semicolon));
TRY(s_name_to_key.insert("SingleQuote"sv, Key::SingleQuote));
TRY(s_name_to_key.insert("Slash"sv, Key::Slash));
TRY(s_name_to_key.insert("Space"sv, Key::Space));
TRY(s_name_to_key.insert("Super"sv, Key::Super));
TRY(s_name_to_key.insert("T"sv, Key::T));
TRY(s_name_to_key.insert("Tab"sv, Key::Tab));
TRY(s_name_to_key.insert("Tilde"sv, Key::Tilde));
TRY(s_name_to_key.insert("TwoDots"sv, Key::TwoDots));
TRY(s_name_to_key.insert("U"sv, Key::U));
TRY(s_name_to_key.insert("Underscore"sv, Key::Underscore));
TRY(s_name_to_key.insert("V"sv, Key::V));
TRY(s_name_to_key.insert("VolumeDown"sv, Key::VolumeDown));
TRY(s_name_to_key.insert("VolumeMute"sv, Key::VolumeMute));
TRY(s_name_to_key.insert("VolumeUp"sv, Key::VolumeUp));
TRY(s_name_to_key.insert("W"sv, Key::W));
TRY(s_name_to_key.insert("X"sv, Key::X));
TRY(s_name_to_key.insert("Y"sv, Key::Y));
TRY(s_name_to_key.insert("Z"sv, Key::Z));
return {};
}
}

View File

@ -1,363 +0,0 @@
#include <BAN/Array.h>
#include <kernel/Input/KeyEvent.h>
namespace Kernel::Input
{
extern BAN::Array<Key, 0xFF> g_keycode_to_key_normal;
extern BAN::Array<Key, 0xFF> g_keycode_to_key_shift;
extern BAN::Array<Key, 0xFF> g_keycode_to_key_altgr;
}
namespace Kernel::Input::KeyboardLayout
{
static void initialize_fi_normal();
static void initialize_fi_shift();
static void initialize_fi_altgr();
void initialize_fi()
{
for (auto& key : g_keycode_to_key_normal)
key = Key::None;
for (auto& key : g_keycode_to_key_shift)
key = Key::None;
for (auto& key : g_keycode_to_key_altgr)
key = Key::None;
initialize_fi_normal();
initialize_fi_shift();
initialize_fi_altgr();
}
static void initialize_fi_normal()
{
g_keycode_to_key_normal[keycode_normal(0, 0)] = Key::Section;
g_keycode_to_key_normal[keycode_normal(0, 1)] = Key::_1;
g_keycode_to_key_normal[keycode_normal(0, 2)] = Key::_2;
g_keycode_to_key_normal[keycode_normal(0, 3)] = Key::_3;
g_keycode_to_key_normal[keycode_normal(0, 4)] = Key::_4;
g_keycode_to_key_normal[keycode_normal(0, 5)] = Key::_5;
g_keycode_to_key_normal[keycode_normal(0, 6)] = Key::_6;
g_keycode_to_key_normal[keycode_normal(0, 7)] = Key::_7;
g_keycode_to_key_normal[keycode_normal(0, 8)] = Key::_8;
g_keycode_to_key_normal[keycode_normal(0, 9)] = Key::_9;
g_keycode_to_key_normal[keycode_normal(0, 10)] = Key::_0;
g_keycode_to_key_normal[keycode_normal(0, 11)] = Key::Plus;
g_keycode_to_key_normal[keycode_normal(0, 12)] = Key::Acute;
g_keycode_to_key_normal[keycode_normal(0, 13)] = Key::Backspace;
g_keycode_to_key_normal[keycode_normal(1, 0)] = Key::Tab;
g_keycode_to_key_normal[keycode_normal(1, 1)] = Key::Q;
g_keycode_to_key_normal[keycode_normal(1, 2)] = Key::W;
g_keycode_to_key_normal[keycode_normal(1, 3)] = Key::E;
g_keycode_to_key_normal[keycode_normal(1, 4)] = Key::R;
g_keycode_to_key_normal[keycode_normal(1, 5)] = Key::T;
g_keycode_to_key_normal[keycode_normal(1, 6)] = Key::Y;
g_keycode_to_key_normal[keycode_normal(1, 7)] = Key::U;
g_keycode_to_key_normal[keycode_normal(1, 8)] = Key::I;
g_keycode_to_key_normal[keycode_normal(1, 9)] = Key::O;
g_keycode_to_key_normal[keycode_normal(1, 10)] = Key::P;
g_keycode_to_key_normal[keycode_normal(1, 11)] = Key::A_Ring;
g_keycode_to_key_normal[keycode_normal(1, 12)] = Key::TwoDots;
g_keycode_to_key_normal[keycode_normal(2, 0)] = Key::CapsLock;
g_keycode_to_key_normal[keycode_normal(2, 1)] = Key::A;
g_keycode_to_key_normal[keycode_normal(2, 2)] = Key::S;
g_keycode_to_key_normal[keycode_normal(2, 3)] = Key::D;
g_keycode_to_key_normal[keycode_normal(2, 4)] = Key::F;
g_keycode_to_key_normal[keycode_normal(2, 5)] = Key::G;
g_keycode_to_key_normal[keycode_normal(2, 6)] = Key::H;
g_keycode_to_key_normal[keycode_normal(2, 7)] = Key::J;
g_keycode_to_key_normal[keycode_normal(2, 8)] = Key::K;
g_keycode_to_key_normal[keycode_normal(2, 9)] = Key::L;
g_keycode_to_key_normal[keycode_normal(2, 10)] = Key::O_Umlaut;
g_keycode_to_key_normal[keycode_normal(2, 11)] = Key::A_Umlaut;
g_keycode_to_key_normal[keycode_normal(2, 12)] = Key::SingleQuote;
g_keycode_to_key_normal[keycode_normal(2, 13)] = Key::Enter;
g_keycode_to_key_normal[keycode_normal(3, 0)] = Key::LeftShift;
g_keycode_to_key_normal[keycode_normal(3, 1)] = Key::LessThan;
g_keycode_to_key_normal[keycode_normal(3, 2)] = Key::Z;
g_keycode_to_key_normal[keycode_normal(3, 3)] = Key::X;
g_keycode_to_key_normal[keycode_normal(3, 4)] = Key::C;
g_keycode_to_key_normal[keycode_normal(3, 5)] = Key::V;
g_keycode_to_key_normal[keycode_normal(3, 6)] = Key::B;
g_keycode_to_key_normal[keycode_normal(3, 7)] = Key::N;
g_keycode_to_key_normal[keycode_normal(3, 8)] = Key::M;
g_keycode_to_key_normal[keycode_normal(3, 9)] = Key::Comma;
g_keycode_to_key_normal[keycode_normal(3, 10)] = Key::Period;
g_keycode_to_key_normal[keycode_normal(3, 11)] = Key::Hyphen;
g_keycode_to_key_normal[keycode_normal(3, 12)] = Key::RightShift;
g_keycode_to_key_normal[keycode_normal(4, 0)] = Key::LeftCtrl;
g_keycode_to_key_normal[keycode_normal(4, 1)] = Key::Super;
g_keycode_to_key_normal[keycode_normal(4, 2)] = Key::LeftAlt;
g_keycode_to_key_normal[keycode_normal(4, 3)] = Key::Space;
g_keycode_to_key_normal[keycode_normal(4, 4)] = Key::RightAlt;
g_keycode_to_key_normal[keycode_normal(4, 5)] = Key::RightCtrl;
g_keycode_to_key_normal[keycode_numpad(0, 0)] = Key::NumLock;
g_keycode_to_key_normal[keycode_numpad(0, 1)] = Key::NumpadDivide;
g_keycode_to_key_normal[keycode_numpad(0, 2)] = Key::NumpadMultiply;
g_keycode_to_key_normal[keycode_numpad(0, 3)] = Key::NumpadMinus;
g_keycode_to_key_normal[keycode_numpad(1, 0)] = Key::Numpad7;
g_keycode_to_key_normal[keycode_numpad(1, 1)] = Key::Numpad8;
g_keycode_to_key_normal[keycode_numpad(1, 2)] = Key::Numpad9;
g_keycode_to_key_normal[keycode_numpad(1, 3)] = Key::NumpadPlus;
g_keycode_to_key_normal[keycode_numpad(2, 0)] = Key::Numpad4;
g_keycode_to_key_normal[keycode_numpad(2, 1)] = Key::Numpad5;
g_keycode_to_key_normal[keycode_numpad(2, 2)] = Key::Numpad6;
g_keycode_to_key_normal[keycode_numpad(3, 0)] = Key::Numpad1;
g_keycode_to_key_normal[keycode_numpad(3, 1)] = Key::Numpad2;
g_keycode_to_key_normal[keycode_numpad(3, 2)] = Key::Numpad3;
g_keycode_to_key_normal[keycode_numpad(3, 3)] = Key::NumpadEnter;
g_keycode_to_key_normal[keycode_numpad(4, 0)] = Key::Numpad0;
g_keycode_to_key_normal[keycode_numpad(4, 1)] = Key::NumpadDecimal;
g_keycode_to_key_normal[keycode_function( 0)] = Key::Escape;
g_keycode_to_key_normal[keycode_function( 1)] = Key::F1;
g_keycode_to_key_normal[keycode_function( 2)] = Key::F2;
g_keycode_to_key_normal[keycode_function( 3)] = Key::F3;
g_keycode_to_key_normal[keycode_function( 4)] = Key::F4;
g_keycode_to_key_normal[keycode_function( 5)] = Key::F5;
g_keycode_to_key_normal[keycode_function( 6)] = Key::F6;
g_keycode_to_key_normal[keycode_function( 7)] = Key::F7;
g_keycode_to_key_normal[keycode_function( 8)] = Key::F8;
g_keycode_to_key_normal[keycode_function( 9)] = Key::F9;
g_keycode_to_key_normal[keycode_function(10)] = Key::F10;
g_keycode_to_key_normal[keycode_function(11)] = Key::F11;
g_keycode_to_key_normal[keycode_function(12)] = Key::F12;
g_keycode_to_key_normal[keycode_function(13)] = Key::Insert;
g_keycode_to_key_normal[keycode_function(14)] = Key::PrintScreen;
g_keycode_to_key_normal[keycode_function(15)] = Key::Delete;
g_keycode_to_key_normal[keycode_function(16)] = Key::Home;
g_keycode_to_key_normal[keycode_function(17)] = Key::End;
g_keycode_to_key_normal[keycode_function(18)] = Key::PageUp;
g_keycode_to_key_normal[keycode_function(19)] = Key::PageDown;
g_keycode_to_key_normal[keycode_function(20)] = Key::ScrollLock;
// Arrow keys
g_keycode_to_key_normal[keycode_normal(5, 0)] = Key::ArrowUp;
g_keycode_to_key_normal[keycode_normal(5, 1)] = Key::ArrowLeft;
g_keycode_to_key_normal[keycode_normal(5, 2)] = Key::ArrowDown;
g_keycode_to_key_normal[keycode_normal(5, 3)] = Key::ArrowRight;
}
static void initialize_fi_shift()
{
g_keycode_to_key_shift[keycode_normal(0, 0)] = Key::Half;
g_keycode_to_key_shift[keycode_normal(0, 1)] = Key::ExclamationMark;
g_keycode_to_key_shift[keycode_normal(0, 2)] = Key::DoubleQuote;
g_keycode_to_key_shift[keycode_normal(0, 3)] = Key::Hashtag;
g_keycode_to_key_shift[keycode_normal(0, 4)] = Key::Currency;
g_keycode_to_key_shift[keycode_normal(0, 5)] = Key::Percent;
g_keycode_to_key_shift[keycode_normal(0, 6)] = Key::Ampersand;
g_keycode_to_key_shift[keycode_normal(0, 7)] = Key::Slash;
g_keycode_to_key_shift[keycode_normal(0, 8)] = Key::OpenParenthesis;
g_keycode_to_key_shift[keycode_normal(0, 9)] = Key::CloseParenthesis;
g_keycode_to_key_shift[keycode_normal(0, 10)] = Key::Equals;
g_keycode_to_key_shift[keycode_normal(0, 11)] = Key::QuestionMark;
g_keycode_to_key_shift[keycode_normal(0, 12)] = Key::BackTick;
g_keycode_to_key_shift[keycode_normal(0, 13)] = Key::Backspace;
g_keycode_to_key_shift[keycode_normal(1, 0)] = Key::Tab;
g_keycode_to_key_shift[keycode_normal(1, 1)] = Key::Q;
g_keycode_to_key_shift[keycode_normal(1, 2)] = Key::W;
g_keycode_to_key_shift[keycode_normal(1, 3)] = Key::E;
g_keycode_to_key_shift[keycode_normal(1, 4)] = Key::R;
g_keycode_to_key_shift[keycode_normal(1, 5)] = Key::T;
g_keycode_to_key_shift[keycode_normal(1, 6)] = Key::Y;
g_keycode_to_key_shift[keycode_normal(1, 7)] = Key::U;
g_keycode_to_key_shift[keycode_normal(1, 8)] = Key::I;
g_keycode_to_key_shift[keycode_normal(1, 9)] = Key::O;
g_keycode_to_key_shift[keycode_normal(1, 10)] = Key::P;
g_keycode_to_key_shift[keycode_normal(1, 11)] = Key::A_Ring;
g_keycode_to_key_shift[keycode_normal(1, 12)] = Key::Caret;
g_keycode_to_key_shift[keycode_normal(2, 0)] = Key::CapsLock;
g_keycode_to_key_shift[keycode_normal(2, 1)] = Key::A;
g_keycode_to_key_shift[keycode_normal(2, 2)] = Key::S;
g_keycode_to_key_shift[keycode_normal(2, 3)] = Key::D;
g_keycode_to_key_shift[keycode_normal(2, 4)] = Key::F;
g_keycode_to_key_shift[keycode_normal(2, 5)] = Key::G;
g_keycode_to_key_shift[keycode_normal(2, 6)] = Key::H;
g_keycode_to_key_shift[keycode_normal(2, 7)] = Key::J;
g_keycode_to_key_shift[keycode_normal(2, 8)] = Key::K;
g_keycode_to_key_shift[keycode_normal(2, 9)] = Key::L;
g_keycode_to_key_shift[keycode_normal(2, 10)] = Key::O_Umlaut;
g_keycode_to_key_shift[keycode_normal(2, 11)] = Key::A_Umlaut;
g_keycode_to_key_shift[keycode_normal(2, 12)] = Key::Asterix;
g_keycode_to_key_shift[keycode_normal(2, 13)] = Key::Enter;
g_keycode_to_key_shift[keycode_normal(3, 0)] = Key::LeftShift;
g_keycode_to_key_shift[keycode_normal(3, 1)] = Key::GreaterThan;
g_keycode_to_key_shift[keycode_normal(3, 2)] = Key::Z;
g_keycode_to_key_shift[keycode_normal(3, 3)] = Key::X;
g_keycode_to_key_shift[keycode_normal(3, 4)] = Key::C;
g_keycode_to_key_shift[keycode_normal(3, 5)] = Key::V;
g_keycode_to_key_shift[keycode_normal(3, 6)] = Key::B;
g_keycode_to_key_shift[keycode_normal(3, 7)] = Key::N;
g_keycode_to_key_shift[keycode_normal(3, 8)] = Key::M;
g_keycode_to_key_shift[keycode_normal(3, 9)] = Key::Semicolon;
g_keycode_to_key_shift[keycode_normal(3, 10)] = Key::Colon;
g_keycode_to_key_shift[keycode_normal(3, 11)] = Key::Underscore;
g_keycode_to_key_shift[keycode_normal(3, 12)] = Key::RightShift;
g_keycode_to_key_shift[keycode_normal(4, 0)] = Key::LeftCtrl;
g_keycode_to_key_shift[keycode_normal(4, 1)] = Key::Super;
g_keycode_to_key_shift[keycode_normal(4, 2)] = Key::LeftAlt;
g_keycode_to_key_shift[keycode_normal(4, 3)] = Key::Space;
g_keycode_to_key_shift[keycode_normal(4, 4)] = Key::RightAlt;
g_keycode_to_key_shift[keycode_normal(4, 5)] = Key::RightCtrl;
g_keycode_to_key_shift[keycode_numpad(0, 0)] = Key::NumLock;
g_keycode_to_key_shift[keycode_numpad(0, 1)] = Key::NumpadDivide;
g_keycode_to_key_shift[keycode_numpad(0, 2)] = Key::NumpadMultiply;
g_keycode_to_key_shift[keycode_numpad(0, 3)] = Key::NumpadMinus;
g_keycode_to_key_shift[keycode_numpad(1, 0)] = Key::Numpad7;
g_keycode_to_key_shift[keycode_numpad(1, 1)] = Key::Numpad8;
g_keycode_to_key_shift[keycode_numpad(1, 2)] = Key::Numpad9;
g_keycode_to_key_shift[keycode_numpad(1, 3)] = Key::NumpadPlus;
g_keycode_to_key_shift[keycode_numpad(2, 0)] = Key::Numpad4;
g_keycode_to_key_shift[keycode_numpad(2, 1)] = Key::Numpad5;
g_keycode_to_key_shift[keycode_numpad(2, 2)] = Key::Numpad6;
g_keycode_to_key_shift[keycode_numpad(3, 0)] = Key::Numpad1;
g_keycode_to_key_shift[keycode_numpad(3, 1)] = Key::Numpad2;
g_keycode_to_key_shift[keycode_numpad(3, 2)] = Key::Numpad3;
g_keycode_to_key_shift[keycode_numpad(3, 3)] = Key::NumpadEnter;
g_keycode_to_key_shift[keycode_numpad(4, 0)] = Key::Numpad0;
g_keycode_to_key_shift[keycode_numpad(4, 1)] = Key::NumpadDecimal;
g_keycode_to_key_shift[keycode_function( 0)] = Key::Escape;
g_keycode_to_key_shift[keycode_function( 1)] = Key::F1;
g_keycode_to_key_shift[keycode_function( 2)] = Key::F2;
g_keycode_to_key_shift[keycode_function( 3)] = Key::F3;
g_keycode_to_key_shift[keycode_function( 4)] = Key::F4;
g_keycode_to_key_shift[keycode_function( 5)] = Key::F5;
g_keycode_to_key_shift[keycode_function( 6)] = Key::F6;
g_keycode_to_key_shift[keycode_function( 7)] = Key::F7;
g_keycode_to_key_shift[keycode_function( 8)] = Key::F8;
g_keycode_to_key_shift[keycode_function( 9)] = Key::F9;
g_keycode_to_key_shift[keycode_function(10)] = Key::F10;
g_keycode_to_key_shift[keycode_function(11)] = Key::F11;
g_keycode_to_key_shift[keycode_function(12)] = Key::F12;
g_keycode_to_key_shift[keycode_function(13)] = Key::Insert;
g_keycode_to_key_shift[keycode_function(14)] = Key::PrintScreen;
g_keycode_to_key_shift[keycode_function(15)] = Key::Delete;
g_keycode_to_key_shift[keycode_function(16)] = Key::Home;
g_keycode_to_key_shift[keycode_function(17)] = Key::End;
g_keycode_to_key_shift[keycode_function(18)] = Key::PageUp;
g_keycode_to_key_shift[keycode_function(19)] = Key::PageDown;
g_keycode_to_key_shift[keycode_function(20)] = Key::ScrollLock;
// Arrow keys
g_keycode_to_key_shift[keycode_normal(5, 0)] = Key::ArrowUp;
g_keycode_to_key_shift[keycode_normal(5, 1)] = Key::ArrowLeft;
g_keycode_to_key_shift[keycode_normal(5, 2)] = Key::ArrowDown;
g_keycode_to_key_shift[keycode_normal(5, 3)] = Key::ArrowRight;
}
static void initialize_fi_altgr()
{
g_keycode_to_key_altgr[keycode_normal(0, 0)] = Key::Section;
g_keycode_to_key_altgr[keycode_normal(0, 1)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(0, 2)] = Key::AtSign;
g_keycode_to_key_altgr[keycode_normal(0, 3)] = Key::Pound;
g_keycode_to_key_altgr[keycode_normal(0, 4)] = Key::Dollar;
g_keycode_to_key_altgr[keycode_normal(0, 5)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(0, 6)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(0, 7)] = Key::OpenCurlyBracket;
g_keycode_to_key_altgr[keycode_normal(0, 8)] = Key::OpenSquareBracket;
g_keycode_to_key_altgr[keycode_normal(0, 9)] = Key::CloseSquareBracket;
g_keycode_to_key_altgr[keycode_normal(0, 10)] = Key::CloseCurlyBracket;
g_keycode_to_key_altgr[keycode_normal(0, 11)] = Key::BackSlash;
g_keycode_to_key_altgr[keycode_normal(0, 12)] = Key::Cedilla;
g_keycode_to_key_altgr[keycode_normal(0, 13)] = Key::Backspace;
g_keycode_to_key_altgr[keycode_normal(1, 0)] = Key::Tab;
g_keycode_to_key_altgr[keycode_normal(1, 1)] = Key::Q;
g_keycode_to_key_altgr[keycode_normal(1, 2)] = Key::W;
g_keycode_to_key_altgr[keycode_normal(1, 3)] = Key::Euro;
g_keycode_to_key_altgr[keycode_normal(1, 4)] = Key::R;
g_keycode_to_key_altgr[keycode_normal(1, 5)] = Key::T;
g_keycode_to_key_altgr[keycode_normal(1, 6)] = Key::Y;
g_keycode_to_key_altgr[keycode_normal(1, 7)] = Key::U;
g_keycode_to_key_altgr[keycode_normal(1, 8)] = Key::I;
g_keycode_to_key_altgr[keycode_normal(1, 9)] = Key::O;
g_keycode_to_key_altgr[keycode_normal(1, 10)] = Key::P;
g_keycode_to_key_altgr[keycode_normal(1, 11)] = Key::A_Ring;
g_keycode_to_key_altgr[keycode_normal(1, 12)] = Key::Tilde;
g_keycode_to_key_altgr[keycode_normal(2, 0)] = Key::CapsLock;
g_keycode_to_key_altgr[keycode_normal(2, 1)] = Key::A;
g_keycode_to_key_altgr[keycode_normal(2, 2)] = Key::S;
g_keycode_to_key_altgr[keycode_normal(2, 3)] = Key::D;
g_keycode_to_key_altgr[keycode_normal(2, 4)] = Key::F;
g_keycode_to_key_altgr[keycode_normal(2, 5)] = Key::G;
g_keycode_to_key_altgr[keycode_normal(2, 6)] = Key::H;
g_keycode_to_key_altgr[keycode_normal(2, 7)] = Key::J;
g_keycode_to_key_altgr[keycode_normal(2, 8)] = Key::K;
g_keycode_to_key_altgr[keycode_normal(2, 9)] = Key::L;
g_keycode_to_key_altgr[keycode_normal(2, 10)] = Key::O_Umlaut;
g_keycode_to_key_altgr[keycode_normal(2, 11)] = Key::A_Umlaut;
g_keycode_to_key_altgr[keycode_normal(2, 12)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(2, 13)] = Key::Enter;
g_keycode_to_key_altgr[keycode_normal(3, 0)] = Key::LeftShift;
g_keycode_to_key_altgr[keycode_normal(3, 1)] = Key::Pipe;
g_keycode_to_key_altgr[keycode_normal(3, 2)] = Key::Z;
g_keycode_to_key_altgr[keycode_normal(3, 3)] = Key::X;
g_keycode_to_key_altgr[keycode_normal(3, 4)] = Key::C;
g_keycode_to_key_altgr[keycode_normal(3, 5)] = Key::V;
g_keycode_to_key_altgr[keycode_normal(3, 6)] = Key::B;
g_keycode_to_key_altgr[keycode_normal(3, 7)] = Key::N;
g_keycode_to_key_altgr[keycode_normal(3, 8)] = Key::M;
g_keycode_to_key_altgr[keycode_normal(3, 9)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(3, 10)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(3, 11)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(3, 12)] = Key::RightShift;
g_keycode_to_key_altgr[keycode_normal(4, 0)] = Key::LeftCtrl;
g_keycode_to_key_altgr[keycode_normal(4, 1)] = Key::Super;
g_keycode_to_key_altgr[keycode_normal(4, 2)] = Key::LeftAlt;
g_keycode_to_key_altgr[keycode_normal(4, 3)] = Key::Space;
g_keycode_to_key_altgr[keycode_normal(4, 4)] = Key::RightAlt;
g_keycode_to_key_altgr[keycode_normal(4, 5)] = Key::RightCtrl;
g_keycode_to_key_altgr[keycode_numpad(0, 0)] = Key::NumLock;
g_keycode_to_key_altgr[keycode_numpad(0, 1)] = Key::NumpadDivide;
g_keycode_to_key_altgr[keycode_numpad(0, 2)] = Key::NumpadMultiply;
g_keycode_to_key_altgr[keycode_numpad(0, 3)] = Key::NumpadMinus;
g_keycode_to_key_altgr[keycode_numpad(1, 0)] = Key::Numpad7;
g_keycode_to_key_altgr[keycode_numpad(1, 1)] = Key::Numpad8;
g_keycode_to_key_altgr[keycode_numpad(1, 2)] = Key::Numpad9;
g_keycode_to_key_altgr[keycode_numpad(1, 3)] = Key::NumpadPlus;
g_keycode_to_key_altgr[keycode_numpad(2, 0)] = Key::Numpad4;
g_keycode_to_key_altgr[keycode_numpad(2, 1)] = Key::Numpad5;
g_keycode_to_key_altgr[keycode_numpad(2, 2)] = Key::Numpad6;
g_keycode_to_key_altgr[keycode_numpad(3, 0)] = Key::Numpad1;
g_keycode_to_key_altgr[keycode_numpad(3, 1)] = Key::Numpad2;
g_keycode_to_key_altgr[keycode_numpad(3, 2)] = Key::Numpad3;
g_keycode_to_key_altgr[keycode_numpad(3, 3)] = Key::NumpadEnter;
g_keycode_to_key_altgr[keycode_numpad(4, 0)] = Key::Numpad0;
g_keycode_to_key_altgr[keycode_numpad(4, 1)] = Key::NumpadDecimal;
g_keycode_to_key_altgr[keycode_function( 0)] = Key::Escape;
g_keycode_to_key_altgr[keycode_function( 1)] = Key::F1;
g_keycode_to_key_altgr[keycode_function( 2)] = Key::F2;
g_keycode_to_key_altgr[keycode_function( 3)] = Key::F3;
g_keycode_to_key_altgr[keycode_function( 4)] = Key::F4;
g_keycode_to_key_altgr[keycode_function( 5)] = Key::F5;
g_keycode_to_key_altgr[keycode_function( 6)] = Key::F6;
g_keycode_to_key_altgr[keycode_function( 7)] = Key::F7;
g_keycode_to_key_altgr[keycode_function( 8)] = Key::F8;
g_keycode_to_key_altgr[keycode_function( 9)] = Key::F9;
g_keycode_to_key_altgr[keycode_function(10)] = Key::F10;
g_keycode_to_key_altgr[keycode_function(11)] = Key::F11;
g_keycode_to_key_altgr[keycode_function(12)] = Key::F12;
g_keycode_to_key_altgr[keycode_function(13)] = Key::Insert;
g_keycode_to_key_altgr[keycode_function(14)] = Key::PrintScreen;
g_keycode_to_key_altgr[keycode_function(15)] = Key::Delete;
g_keycode_to_key_altgr[keycode_function(16)] = Key::Home;
g_keycode_to_key_altgr[keycode_function(17)] = Key::End;
g_keycode_to_key_altgr[keycode_function(18)] = Key::PageUp;
g_keycode_to_key_altgr[keycode_function(19)] = Key::PageDown;
g_keycode_to_key_altgr[keycode_function(20)] = Key::ScrollLock;
// Arrow keys
g_keycode_to_key_altgr[keycode_normal(5, 0)] = Key::ArrowUp;
g_keycode_to_key_altgr[keycode_normal(5, 1)] = Key::ArrowLeft;
g_keycode_to_key_altgr[keycode_normal(5, 2)] = Key::ArrowDown;
g_keycode_to_key_altgr[keycode_normal(5, 3)] = Key::ArrowRight;
}
}

View File

@ -8,7 +8,7 @@
#include <kernel/FS/VirtualFileSystem.h>
#include <kernel/GDT.h>
#include <kernel/IDT.h>
#include <kernel/Input/KeyboardLayouts/FI.h>
#include <kernel/Input/KeyboardLayout.h>
#include <kernel/Input/PS2/Controller.h>
#include <kernel/InterruptController.h>
#include <kernel/kprint.h>
@ -177,13 +177,19 @@ static void init2(void*)
DevFileSystem::get().initialize_device_updater();
#if 0
dprintln("sleeping for 5 seconds");
SystemTimer::get().sleep(5000);
#endif
PCI::PCIManager::initialize();
dprintln("PCI initialized");
VirtualFileSystem::initialize(cmdline.root);
dprintln("VFS initialized");
Input::KeyboardLayout::initialize_fi();
// Initialize empty keymap
MUST(Input::KeyboardLayout::initialize());
if (auto res = PS2Controller::initialize(); res.is_error())
dprintln("{}", res.error());