diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index cc64d85a6d..060431419b 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -17,7 +17,11 @@ #define I8042_MOUSE_BUFFER 0x20 #define I8042_KEYBOARD_BUFFER 0x00 -static char map[0x80] = { +char *map; +char *shift_map; +char *alt_map; + +static char en_map[0x80] = { 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, '\\', @@ -31,7 +35,7 @@ static char map[0x80] = { 0, 0, 0, 0, 0, 0, '\\', 0, 0, 0, }; -static char shift_map[0x80] = { +static char en_shift_map[0x80] = { 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, '|', @@ -242,7 +246,7 @@ static KeyCode numpad_key_map[13] = { Key_7, Key_8, Key_9, Key_Invalid, Key_4, K void KeyboardDevice::key_state_changed(u8 raw, bool pressed) { KeyCode key = (m_modifiers & Mod_Shift) ? shifted_key_map[raw] : unshifted_key_map[raw]; - char character = (m_modifiers & Mod_Shift) ? shift_map[raw] : map[raw]; + char character = (m_modifiers & Mod_Shift) ? shift_map[raw]: (m_modifiers & Mod_Alt) ? alt_map[raw] : map[raw]; if (key == Key_NumLock && pressed) m_num_lock_on = !m_num_lock_on; @@ -261,6 +265,14 @@ void KeyboardDevice::key_state_changed(u8 raw, bool pressed) } } } + else + { + if(m_has_e0_prefix) { + if(key == Key_Slash) { + character = '/'; // On Turkish-QWERTY Keyboard Key_Slash mapped to '.' char, if e0 prefix is true remap to '/' char + } + } + } if (key == Key_CapsLock && pressed) m_caps_lock_on = !m_caps_lock_on; @@ -356,6 +368,8 @@ KeyboardDevice::KeyboardDevice() { s_the = this; + KeyboardDevice::set_maps(en_map, en_shift_map, en_map); + // Empty the buffer of any pending data. // I don't care what you've been pressing until now! while (IO::in8(I8042_STATUS) & I8042_BUFFER_FULL) @@ -397,3 +411,20 @@ ssize_t KeyboardDevice::write(FileDescription&, const u8*, ssize_t) KeyboardClient::~KeyboardClient() { } + +void KeyboardDevice::set_maps(char* n_map, char* n_shift_map, char* n_alt_map) +{ + kfree(map); + kfree(shift_map); + kfree(alt_map); + + map = (char*) kmalloc(0x80); + shift_map = (char*) kmalloc(0x80); + alt_map = (char*) kmalloc(0x80); + + for(int i=0; i < 0x80; i++) { + map[i] = n_map[i]; + shift_map[i] = n_shift_map[i]; + alt_map[i] = n_alt_map[i]; + } +} \ No newline at end of file diff --git a/Kernel/Devices/KeyboardDevice.h b/Kernel/Devices/KeyboardDevice.h index 7ba8493744..65c3cd2f6b 100644 --- a/Kernel/Devices/KeyboardDevice.h +++ b/Kernel/Devices/KeyboardDevice.h @@ -21,6 +21,7 @@ public: KeyboardDevice(); void set_client(KeyboardClient* client) { m_client = client; } + void set_maps(char* n_map, char* n_shift_map, char* n_alt_map); // ^CharacterDevice virtual ssize_t read(FileDescription&, u8* buffer, ssize_t) override; diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 79127fa097..077bd42261 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -3276,6 +3277,22 @@ int Process::sys$getrandom(void* buffer, size_t buffer_size, unsigned int flags return 0; } +int Process::sys$setkeymap(char* map, char* shift_map, char* alt_map) +{ + if (!is_superuser()) + return -EPERM; + + if (!validate_read(map, 0x80)) + return -EFAULT; + if (!validate_read(shift_map, 0x80)) + return -EFAULT; + if (!validate_read(alt_map, 0x80)) + return -EFAULT; + + KeyboardDevice::the().set_maps(map, shift_map, alt_map); + return 0; +} + int Process::sys$clock_gettime(clockid_t clock_id, timespec* ts) { if (!validate_write_typed(ts)) diff --git a/Kernel/Process.h b/Kernel/Process.h index 389c529ef6..31315c1557 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -221,6 +221,7 @@ public: int sys$set_process_icon(int icon_id); int sys$realpath(const char* pathname, char*, size_t); ssize_t sys$getrandom(void*, size_t, unsigned int); + int sys$setkeymap(char* map, char* shift_map, char* alt_map); static void initialize(); diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 530c1c9b51..101490e2c2 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -135,6 +135,7 @@ typedef u32 socklen_t; __ENUMERATE_SYSCALL(get_process_name) \ __ENUMERATE_SYSCALL(fchdir) \ __ENUMERATE_SYSCALL(getrandom) \ + __ENUMERATE_SYSCALL(setkeymap) \ __ENUMERATE_SYSCALL(clock_gettime) \ __ENUMERATE_SYSCALL(clock_nanosleep) \ __ENUMERATE_SYSCALL(openat) \