summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibKeyboard
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-01-30 22:01:34 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-01 09:54:32 +0100
commitdd4e670f72c44a59b40ffb6af72751606fadd680 (patch)
treecf2dc592ea46ecb58668ae9a451865e4bbc09abf /Userland/Libraries/LibKeyboard
parenta2c21a55e17189b61b416688cfe072c0856cba00 (diff)
downloadserenity-dd4e670f72c44a59b40ffb6af72751606fadd680.zip
LibKeyboard+keymap: Support querying the keymap via commandline
Diffstat (limited to 'Userland/Libraries/LibKeyboard')
-rw-r--r--Userland/Libraries/LibKeyboard/CharacterMap.cpp32
-rw-r--r--Userland/Libraries/LibKeyboard/CharacterMap.h8
2 files changed, 36 insertions, 4 deletions
diff --git a/Userland/Libraries/LibKeyboard/CharacterMap.cpp b/Userland/Libraries/LibKeyboard/CharacterMap.cpp
index 9d5b186383..3ea6604df2 100644
--- a/Userland/Libraries/LibKeyboard/CharacterMap.cpp
+++ b/Userland/Libraries/LibKeyboard/CharacterMap.cpp
@@ -33,17 +33,23 @@
namespace Keyboard {
-CharacterMap::CharacterMap(const String& file_name)
+CharacterMap::CharacterMap(const String& map_name)
{
#ifdef KERNEL
m_character_map_data = default_character_map;
#else
- auto result = CharacterMapFile::load_from_file(file_name);
+ auto result = CharacterMapFile::load_from_file(map_name);
ASSERT(result.has_value());
m_character_map_data = result.value();
#endif
- m_character_map_name = file_name;
+ m_character_map_name = map_name;
+}
+
+CharacterMap::CharacterMap(const String& map_name, const CharacterMapData& map_data)
+ : m_character_map_data(map_data)
+ , m_character_map_name(map_name)
+{
}
#ifndef KERNEL
@@ -54,6 +60,26 @@ int CharacterMap::set_system_map()
return syscall(SC_setkeymap, &params);
}
+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, &params);
+ if (rc < 0) {
+ return OSError(-rc);
+ }
+
+ return CharacterMap { keymap_name, map_data };
+}
+
#endif
u32 CharacterMap::get_char(KeyEvent event)
diff --git a/Userland/Libraries/LibKeyboard/CharacterMap.h b/Userland/Libraries/LibKeyboard/CharacterMap.h
index 242eac2a39..848b32a7fa 100644
--- a/Userland/Libraries/LibKeyboard/CharacterMap.h
+++ b/Userland/Libraries/LibKeyboard/CharacterMap.h
@@ -26,6 +26,10 @@
#pragma once
+#ifndef KERNEL
+# include <AK/OSError.h>
+# include <AK/Result.h>
+#endif
#include <AK/String.h>
#include <Kernel/API/KeyCode.h>
#include <LibKeyboard/CharacterMapData.h>
@@ -35,10 +39,12 @@ namespace Keyboard {
class CharacterMap {
public:
- CharacterMap(const String& file_name);
+ CharacterMap(const String& map_name);
+ CharacterMap(const String& map_name, const CharacterMapData& map_data);
#ifndef KERNEL
int set_system_map();
+ static Result<CharacterMap, OSError> fetch_system_map();
#endif
u32 get_char(KeyEvent);