mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibKeyboard: Don't assert on failure
This commit is contained in:
parent
d9e7e13fb2
commit
0e3408d4d6
4 changed files with 21 additions and 16 deletions
|
@ -105,7 +105,7 @@ private:
|
||||||
bool m_has_e0_prefix { false };
|
bool m_has_e0_prefix { false };
|
||||||
EntropySource m_entropy_source;
|
EntropySource m_entropy_source;
|
||||||
|
|
||||||
Keyboard::CharacterMap m_character_map = Keyboard::CharacterMap("en");
|
Keyboard::CharacterMap m_character_map = Keyboard::CharacterMap("en", Keyboard::default_character_map);
|
||||||
};
|
};
|
||||||
|
|
||||||
class KeyboardClient {
|
class KeyboardClient {
|
||||||
|
|
|
@ -27,24 +27,22 @@
|
||||||
#include "CharacterMap.h"
|
#include "CharacterMap.h"
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <Kernel/API/Syscall.h>
|
#include <Kernel/API/Syscall.h>
|
||||||
#ifndef KERNEL
|
#include <LibKeyboard/CharacterMapFile.h>
|
||||||
# include <LibKeyboard/CharacterMapFile.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Keyboard {
|
namespace Keyboard {
|
||||||
|
|
||||||
CharacterMap::CharacterMap(const String& map_name)
|
#ifndef KERNEL
|
||||||
|
// The Kernel explicitly and exclusively links only this file into it.
|
||||||
|
// Thus, we cannot even include a reference to the symbol `CharacterMapFile::load_from_file`.
|
||||||
|
Optional<CharacterMap> CharacterMap::load_from_file(const String& map_name)
|
||||||
{
|
{
|
||||||
#ifdef KERNEL
|
|
||||||
m_character_map_data = default_character_map;
|
|
||||||
#else
|
|
||||||
auto result = CharacterMapFile::load_from_file(map_name);
|
auto result = CharacterMapFile::load_from_file(map_name);
|
||||||
ASSERT(result.has_value());
|
if (!result.has_value())
|
||||||
|
return {};
|
||||||
|
|
||||||
m_character_map_data = result.value();
|
return CharacterMap(map_name, result.value());
|
||||||
#endif
|
|
||||||
m_character_map_name = map_name;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
CharacterMap::CharacterMap(const String& map_name, const CharacterMapData& map_data)
|
CharacterMap::CharacterMap(const String& map_name, const CharacterMapData& map_data)
|
||||||
: m_character_map_data(map_data)
|
: m_character_map_data(map_data)
|
||||||
|
|
|
@ -39,8 +39,8 @@ namespace Keyboard {
|
||||||
class CharacterMap {
|
class CharacterMap {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CharacterMap(const String& map_name);
|
|
||||||
CharacterMap(const String& map_name, const CharacterMapData& map_data);
|
CharacterMap(const String& map_name, const CharacterMapData& map_data);
|
||||||
|
static Optional<CharacterMap> load_from_file(const String& file_name);
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
int set_system_map();
|
int set_system_map();
|
||||||
|
|
|
@ -65,10 +65,17 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Keyboard::CharacterMap character_map(path);
|
auto character_map = Keyboard::CharacterMap::load_from_file(path);
|
||||||
int rc = character_map.set_system_map();
|
if (!character_map.has_value()) {
|
||||||
if (rc != 0)
|
warnln("Cannot read keymap {}", path);
|
||||||
|
warnln("Hint: Must be either a keymap name (e.g. 'en') or a full path.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc = character_map.value().set_system_map();
|
||||||
|
if (rc != 0) {
|
||||||
perror("setkeymap");
|
perror("setkeymap");
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue