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.
This commit is contained in:
Valtteri Koskivuori 2020-08-06 02:03:32 +03:00 committed by Andreas Kling
parent 8dd0c391e9
commit 00a0e525e6
Notes: sideshowbarker 2024-07-19 04:13:23 +09:00
6 changed files with 32 additions and 6 deletions

View file

@ -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 {

View file

@ -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.";
}
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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;
};
}