diff options
-rw-r--r-- | Userland/Libraries/LibC/serenity.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibC/serenity.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibKeyboard/CharacterMap.cpp | 19 |
3 files changed, 30 insertions, 12 deletions
diff --git a/Userland/Libraries/LibC/serenity.cpp b/Userland/Libraries/LibC/serenity.cpp index 7f2bf8364f..319975c653 100644 --- a/Userland/Libraries/LibC/serenity.cpp +++ b/Userland/Libraries/LibC/serenity.cpp @@ -129,4 +129,24 @@ int serenity_readlink(const char* path, size_t path_length, char* buffer, size_t int rc = syscall(SC_readlink, &small_params); __RETURN_WITH_ERRNO(rc, rc, -1); } + +int setkeymap(const char* name, const u32* map, u32* const shift_map, const u32* alt_map, const u32* altgr_map, const u32* shift_altgr_map) +{ + Syscall::SC_setkeymap_params params { map, shift_map, alt_map, altgr_map, shift_altgr_map, { name, strlen(name) } }; + return syscall(SC_setkeymap, ¶ms); +} + +int getkeymap(char* name_buffer, size_t name_buffer_size, u32* map, u32* shift_map, u32* alt_map, u32* altgr_map, u32* shift_altgr_map) +{ + Syscall::SC_getkeymap_params params { + map, + shift_map, + alt_map, + altgr_map, + shift_altgr_map, + { name_buffer, name_buffer_size } + }; + int rc = syscall(SC_getkeymap, ¶ms); + __RETURN_WITH_ERRNO(rc, rc, -1); +} } diff --git a/Userland/Libraries/LibC/serenity.h b/Userland/Libraries/LibC/serenity.h index e7f95b72d3..70ddf295af 100644 --- a/Userland/Libraries/LibC/serenity.h +++ b/Userland/Libraries/LibC/serenity.h @@ -106,6 +106,9 @@ int anon_create(size_t size, int options); int serenity_readlink(const char* path, size_t path_length, char* buffer, size_t buffer_size); +int getkeymap(char* name_buffer, size_t name_buffer_size, u32* map, u32* shift_map, u32* alt_map, u32* altgr_map, u32* shift_altgr_map); +int setkeymap(const char* name, const u32* map, u32* const shift_map, const u32* alt_map, const u32* altgr_map, const u32* shift_altgr_map); + #ifdef __i386__ ALWAYS_INLINE void send_secret_data_to_userspace_emulator(uintptr_t data1, uintptr_t data2, uintptr_t data3) { diff --git a/Userland/Libraries/LibKeyboard/CharacterMap.cpp b/Userland/Libraries/LibKeyboard/CharacterMap.cpp index 059c6da20f..011a935ffc 100644 --- a/Userland/Libraries/LibKeyboard/CharacterMap.cpp +++ b/Userland/Libraries/LibKeyboard/CharacterMap.cpp @@ -29,6 +29,10 @@ #include <Kernel/API/Syscall.h> #include <LibKeyboard/CharacterMapFile.h> +#ifndef KERNEL +# include <serenity.h> +#endif + namespace Keyboard { #ifndef KERNEL @@ -54,8 +58,7 @@ CharacterMap::CharacterMap(const String& map_name, const CharacterMapData& map_d 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, m_character_map_data.shift_altgr_map, { m_character_map_name.characters(), m_character_map_name.length() } }; - return syscall(SC_setkeymap, ¶ms); + return setkeymap(m_character_map_name.characters(), 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_data.shift_altgr_map); } Result<CharacterMap, OSError> CharacterMap::fetch_system_map() @@ -63,16 +66,8 @@ Result<CharacterMap, OSError> CharacterMap::fetch_system_map() CharacterMapData map_data; char keymap_name[50 + 1] = { 0 }; - Syscall::SC_getkeymap_params params { - map_data.map, map_data.shift_map, - map_data.alt_map, - map_data.altgr_map, - map_data.shift_altgr_map, - { keymap_name, sizeof(keymap_name) } - }; - int rc = syscall(SC_getkeymap, ¶ms); - if (rc < 0) { - return OSError(-rc); + if (getkeymap(keymap_name, sizeof(keymap_name), map_data.map, map_data.shift_map, map_data.alt_map, map_data.altgr_map, map_data.shift_altgr_map) < 0) { + return OSError(errno); } return CharacterMap { keymap_name, map_data }; |