ladybird/Userland/Libraries/LibKeyboard/CharacterMap.cpp
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

49 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CharacterMap.h"
#include <AK/StringBuilder.h>
#include <LibKeyboard/CharacterMapFile.h>
#include <errno.h>
#include <serenity.h>
namespace Keyboard {
ErrorOr<CharacterMap> CharacterMap::load_from_file(DeprecatedString const& map_name)
{
auto result = TRY(CharacterMapFile::load_from_file(map_name));
return CharacterMap(map_name, result);
}
CharacterMap::CharacterMap(DeprecatedString const& map_name, CharacterMapData const& map_data)
: m_character_map_data(map_data)
, m_character_map_name(map_name)
{
}
int CharacterMap::set_system_map()
{
return setkeymap(m_character_map_name.characters(), 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_data.shift_altgr_map);
}
ErrorOr<CharacterMap> CharacterMap::fetch_system_map()
{
CharacterMapData map_data;
char keymap_name[50 + 1] = { 0 };
if (getkeymap(keymap_name, sizeof(keymap_name), map_data.map, map_data.shift_map, map_data.alt_map, map_data.altgr_map, map_data.shift_altgr_map) < 0)
return Error::from_errno(errno);
return CharacterMap { keymap_name, map_data };
}
DeprecatedString const& CharacterMap::character_map_name() const
{
return m_character_map_name;
}
}