mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Kernel: Implement AltGr key support
This commit is contained in:
parent
36f1de3c89
commit
624116a8b1
Notes:
sideshowbarker
2024-07-19 10:30:34 +09:00
Author: https://github.com/xTibor Commit: https://github.com/SerenityOS/serenity/commit/624116a8b1c Pull-request: https://github.com/SerenityOS/serenity/pull/972
6 changed files with 36 additions and 15 deletions
|
@ -20,6 +20,7 @@
|
|||
char *map;
|
||||
char *shift_map;
|
||||
char *alt_map;
|
||||
char *altgr_map;
|
||||
|
||||
static char en_map[0x80] = {
|
||||
0, '\033', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x08, '\t',
|
||||
|
@ -246,7 +247,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]: (m_modifiers & Mod_Alt) ? alt_map[raw] : map[raw];
|
||||
char character = (m_modifiers & Mod_Shift) ? shift_map[raw] : (m_modifiers & Mod_Alt) ? alt_map[raw] : (m_modifiers & Mod_AltGr) ? altgr_map[raw] : map[raw];
|
||||
|
||||
if (key == Key_NumLock && pressed)
|
||||
m_num_lock_on = !m_num_lock_on;
|
||||
|
@ -318,7 +319,10 @@ void KeyboardDevice::handle_irq()
|
|||
#endif
|
||||
switch (ch) {
|
||||
case 0x38:
|
||||
update_modifier(Mod_Alt, pressed);
|
||||
if (m_has_e0_prefix)
|
||||
update_modifier(Mod_AltGr, pressed);
|
||||
else
|
||||
update_modifier(Mod_Alt, pressed);
|
||||
break;
|
||||
case 0x1d:
|
||||
update_modifier(Mod_Ctrl, pressed);
|
||||
|
@ -368,7 +372,7 @@ KeyboardDevice::KeyboardDevice()
|
|||
{
|
||||
s_the = this;
|
||||
|
||||
KeyboardDevice::set_maps(en_map, en_shift_map, en_map);
|
||||
KeyboardDevice::set_maps(en_map, en_shift_map, en_map, en_map);
|
||||
|
||||
// Empty the buffer of any pending data.
|
||||
// I don't care what you've been pressing until now!
|
||||
|
@ -412,19 +416,22 @@ KeyboardClient::~KeyboardClient()
|
|||
{
|
||||
}
|
||||
|
||||
void KeyboardDevice::set_maps(char* n_map, char* n_shift_map, char* n_alt_map)
|
||||
void KeyboardDevice::set_maps(const char* n_map, const char* n_shift_map, const char* n_alt_map, const char* n_altgr_map)
|
||||
{
|
||||
kfree(map);
|
||||
kfree(shift_map);
|
||||
kfree(alt_map);
|
||||
kfree(altgr_map);
|
||||
|
||||
map = (char*) kmalloc(0x80);
|
||||
shift_map = (char*) kmalloc(0x80);
|
||||
alt_map = (char*) kmalloc(0x80);
|
||||
altgr_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];
|
||||
altgr_map[i] = n_altgr_map[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +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);
|
||||
void set_maps(const char* n_map, const char* n_shift_map, const char* n_alt_map, const char* n_altgr_map);
|
||||
|
||||
// ^CharacterDevice
|
||||
virtual ssize_t read(FileDescription&, u8* buffer, ssize_t) override;
|
||||
|
|
|
@ -119,7 +119,8 @@ enum KeyModifier {
|
|||
Mod_Ctrl = 0x02,
|
||||
Mod_Shift = 0x04,
|
||||
Mod_Logo = 0x08,
|
||||
Mod_Mask = 0x0f,
|
||||
Mod_AltGr = 0x10,
|
||||
Mod_Mask = 0x1f,
|
||||
|
||||
Is_Press = 0x80,
|
||||
};
|
||||
|
@ -132,6 +133,7 @@ struct KeyEvent {
|
|||
bool ctrl() const { return flags & Mod_Ctrl; }
|
||||
bool shift() const { return flags & Mod_Shift; }
|
||||
bool logo() const { return flags & Mod_Logo; }
|
||||
bool altgr() const { return flags & Mod_AltGr; }
|
||||
unsigned modifiers() const { return flags & Mod_Mask; }
|
||||
bool is_press() const { return flags & Is_Press; }
|
||||
};
|
||||
|
|
|
@ -3584,19 +3584,24 @@ 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)
|
||||
int Process::sys$setkeymap(const Syscall::SC_setkeymap_params* params)
|
||||
{
|
||||
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))
|
||||
if (!validate_read_typed(params))
|
||||
return -EFAULT;
|
||||
|
||||
KeyboardDevice::the().set_maps(map, shift_map, alt_map);
|
||||
if (!validate_read(params->map, 0x80))
|
||||
return -EFAULT;
|
||||
if (!validate_read(params->shift_map, 0x80))
|
||||
return -EFAULT;
|
||||
if (!validate_read(params->alt_map, 0x80))
|
||||
return -EFAULT;
|
||||
if (!validate_read(params->altgr_map, 0x80))
|
||||
return -EFAULT;
|
||||
|
||||
KeyboardDevice::the().set_maps(params->map, params->shift_map, params->alt_map, params->altgr_map);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -227,7 +227,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);
|
||||
int sys$setkeymap(const Syscall::SC_setkeymap_params*);
|
||||
int sys$module_load(const char* path, size_t path_length);
|
||||
int sys$module_unload(const char* name, size_t name_length);
|
||||
int sys$profiling_enable(pid_t);
|
||||
|
|
|
@ -270,6 +270,13 @@ struct SC_futex_params {
|
|||
const timespec* timeout;
|
||||
};
|
||||
|
||||
struct SC_setkeymap_params {
|
||||
const char* map;
|
||||
const char* shift_map;
|
||||
const char* alt_map;
|
||||
const char* altgr_map;
|
||||
};
|
||||
|
||||
struct SC_create_thread_params {
|
||||
unsigned int m_detach_state = 0; // JOINABLE or DETACHED
|
||||
int m_schedule_priority = 30; // THREAD_PRIORITY_NORMAL
|
||||
|
|
Loading…
Reference in a new issue