mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
Kernel: Implement the setkeymap() syscall.
This commit is contained in:
parent
28ada30783
commit
794ca16cca
Notes:
sideshowbarker
2024-07-19 11:05:18 +09:00
Author: https://github.com/asliturk Commit: https://github.com/SerenityOS/serenity/commit/794ca16cca4 Pull-request: https://github.com/SerenityOS/serenity/pull/820
@ -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];
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <Kernel/Arch/i386/PIT.h>
|
||||
#include <Kernel/Console.h>
|
||||
#include <Kernel/Devices/NullDevice.h>
|
||||
#include <Kernel/Devices/KeyboardDevice.h>
|
||||
#include <Kernel/Devices/RandomDevice.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
@ -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))
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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) \
|
||||
|
Loading…
Reference in New Issue
Block a user