From 00a0e525e689e105fa6d1210198d3c947951bf6c Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Thu, 6 Aug 2020 02:03:32 +0300 Subject: [PATCH] Kernel+LibKeyboard: Store the keymap name when setting system keymap This way we can query the kernel to see which keymap is currently in use. --- Kernel/API/Syscall.h | 1 + Kernel/Devices/KeyboardDevice.cpp | 5 +++-- Kernel/Devices/KeyboardDevice.h | 4 +++- Kernel/Syscalls/setkeymap.cpp | 11 ++++++++++- Libraries/LibKeyboard/CharacterMap.cpp | 13 +++++++++++-- Libraries/LibKeyboard/CharacterMap.h | 4 ++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index e6b0f6c4f24..0c5511166dc 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -342,6 +342,7 @@ struct SC_setkeymap_params { Userspace shift_map; Userspace alt_map; Userspace altgr_map; + StringArgument map_name; }; struct SC_create_thread_params { diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index e910fd7552c..ac1d5ac349d 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -391,10 +391,11 @@ KeyboardClient::~KeyboardClient() { } -void KeyboardDevice::set_maps(Keyboard::CharacterMapData character_map_data) +void KeyboardDevice::set_maps(const Keyboard::CharacterMapData& character_map_data, const String& character_map_name) { m_character_map.set_character_map_data(character_map_data); - dbg() << "New Character map passing to client."; + m_character_map.set_character_map_name(character_map_name); + dbg() << "New Character map \"" << character_map_name << "\" passing to client."; } } diff --git a/Kernel/Devices/KeyboardDevice.h b/Kernel/Devices/KeyboardDevice.h index 1779a18dadc..94dfb8f02e3 100644 --- a/Kernel/Devices/KeyboardDevice.h +++ b/Kernel/Devices/KeyboardDevice.h @@ -51,7 +51,9 @@ public: KeyboardDevice(); void set_client(KeyboardClient* client) { m_client = client; } - void set_maps(Keyboard::CharacterMapData character_map); + void set_maps(const Keyboard::CharacterMapData& character_map, const String& character_map_name); + + const String keymap_name() { return m_character_map.character_map_name(); } // ^CharacterDevice virtual KResultOr read(FileDescription&, size_t, u8*, size_t) override; diff --git a/Kernel/Syscalls/setkeymap.cpp b/Kernel/Syscalls/setkeymap.cpp index b8f34b6a10c..99204351355 100644 --- a/Kernel/Syscalls/setkeymap.cpp +++ b/Kernel/Syscalls/setkeymap.cpp @@ -56,7 +56,16 @@ int Process::sys$setkeymap(Userspace user_p copy_from_user(character_map_data.alt_map, params.alt_map, CHAR_MAP_SIZE * sizeof(u32)); copy_from_user(character_map_data.altgr_map, params.altgr_map, CHAR_MAP_SIZE * sizeof(u32)); - KeyboardDevice::the().set_maps(character_map_data); + auto map_name = get_syscall_path_argument(params.map_name); + if (map_name.is_error()) { + return map_name.error(); + } + constexpr size_t map_name_max_size = 50; + if (map_name.value().length() > map_name_max_size) { + return -ENAMETOOLONG; + } + + KeyboardDevice::the().set_maps(character_map_data, map_name.value()); return 0; } diff --git a/Libraries/LibKeyboard/CharacterMap.cpp b/Libraries/LibKeyboard/CharacterMap.cpp index 87e9973e892..b5e0f4ee250 100644 --- a/Libraries/LibKeyboard/CharacterMap.cpp +++ b/Libraries/LibKeyboard/CharacterMap.cpp @@ -36,7 +36,6 @@ namespace Keyboard { 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); @@ -44,13 +43,14 @@ CharacterMap::CharacterMap(const String& file_name) m_character_map_data = result.value(); #endif + m_character_map_name = file_name; } #ifndef KERNEL int CharacterMap::set_system_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 }; + 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, { m_character_map_name.characters(), m_character_map_name.length() } }; return syscall(SC_setkeymap, ¶ms); } @@ -92,4 +92,13 @@ void CharacterMap::set_character_map_data(CharacterMapData character_map_data) m_character_map_data = character_map_data; } +void CharacterMap::set_character_map_name(const String& character_map_name) +{ + m_character_map_name = character_map_name; +} + +const String CharacterMap::character_map_name() +{ + return m_character_map_name; +} } diff --git a/Libraries/LibKeyboard/CharacterMap.h b/Libraries/LibKeyboard/CharacterMap.h index cf0a8f065e5..413f7b4ded7 100644 --- a/Libraries/LibKeyboard/CharacterMap.h +++ b/Libraries/LibKeyboard/CharacterMap.h @@ -43,9 +43,13 @@ public: u32 get_char(KeyEvent); void set_character_map_data(CharacterMapData character_map_data); + void set_character_map_name(const String& character_map_name); + + const String character_map_name(); private: CharacterMapData m_character_map_data; + String m_character_map_name; }; }