summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValtteri Koskivuori <vkoskiv@gmail.com>2020-08-06 02:03:32 +0300
committerAndreas Kling <kling@serenityos.org>2020-08-06 17:45:06 +0200
commit00a0e525e689e105fa6d1210198d3c947951bf6c (patch)
tree6735f2f208dd471596a8c3f2d76f2d5933908715
parent8dd0c391e9d816a575e888a23dd13de991e413e5 (diff)
downloadserenity-00a0e525e689e105fa6d1210198d3c947951bf6c.zip
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.
-rw-r--r--Kernel/API/Syscall.h1
-rw-r--r--Kernel/Devices/KeyboardDevice.cpp5
-rw-r--r--Kernel/Devices/KeyboardDevice.h4
-rw-r--r--Kernel/Syscalls/setkeymap.cpp11
-rw-r--r--Libraries/LibKeyboard/CharacterMap.cpp13
-rw-r--r--Libraries/LibKeyboard/CharacterMap.h4
6 files changed, 32 insertions, 6 deletions
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h
index e6b0f6c4f2..0c5511166d 100644
--- a/Kernel/API/Syscall.h
+++ b/Kernel/API/Syscall.h
@@ -342,6 +342,7 @@ struct SC_setkeymap_params {
Userspace<const u32*> shift_map;
Userspace<const u32*> alt_map;
Userspace<const u32*> altgr_map;
+ StringArgument map_name;
};
struct SC_create_thread_params {
diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp
index e910fd7552..ac1d5ac349 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 1779a18dad..94dfb8f02e 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<size_t> read(FileDescription&, size_t, u8*, size_t) override;
diff --git a/Kernel/Syscalls/setkeymap.cpp b/Kernel/Syscalls/setkeymap.cpp
index b8f34b6a10..9920435135 100644
--- a/Kernel/Syscalls/setkeymap.cpp
+++ b/Kernel/Syscalls/setkeymap.cpp
@@ -56,7 +56,16 @@ int Process::sys$setkeymap(Userspace<const Syscall::SC_setkeymap_params*> 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 87e9973e89..b5e0f4ee25 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, &params);
}
@@ -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 cf0a8f065e..413f7b4ded 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;
};
}