mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibKeyboard+keymap: Support querying the keymap via commandline
This commit is contained in:
parent
a2c21a55e1
commit
dd4e670f72
Notes:
sideshowbarker
2024-07-18 22:40:27 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/dd4e670f72c Pull-request: https://github.com/SerenityOS/serenity/pull/5192 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bcoles Reviewed-by: https://github.com/emanuele6 Reviewed-by: https://github.com/linusg
4 changed files with 52 additions and 7 deletions
|
@ -407,7 +407,7 @@ void KeyboardDevice::set_maps(const Keyboard::CharacterMapData& character_map_da
|
|||
{
|
||||
m_character_map.set_character_map_data(character_map_data);
|
||||
m_character_map.set_character_map_name(character_map_name);
|
||||
dbgln("New Character map '{}' passing to client.", character_map_name);
|
||||
dbgln("New Character map '{}' passed in by client.", character_map_name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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, ¶ms);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return CharacterMap { keymap_name, map_data };
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
u32 CharacterMap::get_char(KeyEvent event)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -49,13 +49,26 @@ int main(int argc, char** argv)
|
|||
|
||||
const char* path = nullptr;
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(path, "The mapping file to be used", "file");
|
||||
args_parser.add_positional_argument(path, "The mapping file to be used", "file", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
dbgln("path is at {:p}, and contains {}", path, path);
|
||||
|
||||
if (!path) {
|
||||
auto keymap = Keyboard::CharacterMap::fetch_system_map();
|
||||
if (keymap.is_error()) {
|
||||
warnln("getkeymap: {}", keymap.error());
|
||||
return 1;
|
||||
}
|
||||
|
||||
outln("{}", keymap.value().character_map_name());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Keyboard::CharacterMap character_map(path);
|
||||
int rc = character_map.set_system_map();
|
||||
if (rc != 0)
|
||||
fprintf(stderr, "%s\n", strerror(-rc));
|
||||
perror("setkeymap");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue