summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHüseyin ASLITÜRK <asliturk@hotmail.com>2020-06-13 13:51:20 +0300
committerAndreas Kling <kling@serenityos.org>2020-06-16 13:15:17 +0200
commit25e14911c5ff0b22ac933528a919e9434433b551 (patch)
treee4670e188027f49cecf08d6e4d3262a86fa20349
parentcfaed044640e2a8ef81023197b42a0a6b46cc721 (diff)
downloadserenity-25e14911c5ff0b22ac933528a919e9434433b551.zip
LibKeyboard: Replace char data type to u32 for code point
-rw-r--r--Libraries/LibKeyboard/CharacterMap.cpp25
-rw-r--r--Libraries/LibKeyboard/CharacterMap.h2
-rw-r--r--Libraries/LibKeyboard/CharacterMapData.h10
-rw-r--r--Libraries/LibKeyboard/CharacterMapFile.cpp35
-rw-r--r--Libraries/LibKeyboard/CharacterMapFile.h2
5 files changed, 39 insertions, 35 deletions
diff --git a/Libraries/LibKeyboard/CharacterMap.cpp b/Libraries/LibKeyboard/CharacterMap.cpp
index 1374ca1911..d3a7ad99a3 100644
--- a/Libraries/LibKeyboard/CharacterMap.cpp
+++ b/Libraries/LibKeyboard/CharacterMap.cpp
@@ -25,6 +25,7 @@
*/
#include "CharacterMap.h"
+#include <AK/StringBuilder.h>
#include <Kernel/Syscall.h>
#ifndef KERNEL
# include <LibKeyboard/CharacterMapFile.h>
@@ -51,35 +52,35 @@ int CharacterMap::set_system_map()
return syscall(SC_setkeymap, &params);
}
-char CharacterMap::get_char(KeyEvent event)
+u32 CharacterMap::get_char(KeyEvent event)
{
auto modifiers = event.modifiers();
auto index = event.scancode & 0xFF; // Index is last byte of scan code.
auto caps_lock_on = event.caps_lock_on;
- char character;
+ u32 code_point;
if (modifiers & Mod_Shift)
- character = m_character_map_data.shift_map[index];
+ code_point = m_character_map_data.shift_map[index];
else if (modifiers & Mod_Alt)
- character = m_character_map_data.alt_map[index];
+ code_point = m_character_map_data.alt_map[index];
else if (modifiers & Mod_AltGr)
- character = m_character_map_data.altgr_map[index];
+ code_point = m_character_map_data.altgr_map[index];
else
- character = m_character_map_data.map[index];
+ code_point = m_character_map_data.map[index];
if (caps_lock_on && (modifiers == 0 || modifiers == Mod_Shift)) {
- if (character >= 'a' && character <= 'z')
- character &= ~0x20;
- else if (character >= 'A' && character <= 'Z')
- character |= 0x20;
+ if (code_point >= 'a' && code_point <= 'z')
+ code_point &= ~0x20;
+ else if (code_point >= 'A' && code_point <= 'Z')
+ code_point |= 0x20;
}
if (event.e0_prefix && event.key == Key_Slash) {
// If Key_Slash (scancode = 0x35) mapped to other form "/", we fix num pad key of "/" with this case.
- character = '/';
+ code_point = '/';
}
- return character;
+ return code_point;
}
void CharacterMap::set_character_map_data(CharacterMapData character_map_data)
diff --git a/Libraries/LibKeyboard/CharacterMap.h b/Libraries/LibKeyboard/CharacterMap.h
index 70d42a3848..569b2732d2 100644
--- a/Libraries/LibKeyboard/CharacterMap.h
+++ b/Libraries/LibKeyboard/CharacterMap.h
@@ -38,7 +38,7 @@ public:
CharacterMap(const String& file_name);
int set_system_map();
- char get_char(KeyEvent);
+ u32 get_char(KeyEvent);
void set_character_map_data(CharacterMapData character_map_data);
private:
diff --git a/Libraries/LibKeyboard/CharacterMapData.h b/Libraries/LibKeyboard/CharacterMapData.h
index 7846412707..e0024ccb00 100644
--- a/Libraries/LibKeyboard/CharacterMapData.h
+++ b/Libraries/LibKeyboard/CharacterMapData.h
@@ -26,15 +26,17 @@
#pragma once
+#include <AK/Types.h>
+
#define CHAR_MAP_SIZE 0x80
namespace Keyboard {
struct CharacterMapData {
- char map[CHAR_MAP_SIZE];
- char shift_map[CHAR_MAP_SIZE];
- char alt_map[CHAR_MAP_SIZE];
- char altgr_map[CHAR_MAP_SIZE];
+ u32 map[CHAR_MAP_SIZE];
+ u32 shift_map[CHAR_MAP_SIZE];
+ u32 alt_map[CHAR_MAP_SIZE];
+ u32 altgr_map[CHAR_MAP_SIZE];
};
// clang-format off
diff --git a/Libraries/LibKeyboard/CharacterMapFile.cpp b/Libraries/LibKeyboard/CharacterMapFile.cpp
index eb50e7f876..f9ff37a8fc 100644
--- a/Libraries/LibKeyboard/CharacterMapFile.cpp
+++ b/Libraries/LibKeyboard/CharacterMapFile.cpp
@@ -25,6 +25,7 @@
*/
#include "CharacterMapFile.h"
+#include <AK/Utf8View.h>
#include <LibCore/File.h>
namespace Keyboard {
@@ -52,34 +53,34 @@ Optional<CharacterMapData> CharacterMapFile::load_from_file(const String& file_n
ASSERT(json_result.has_value());
auto json = json_result.value().as_object();
- ByteBuffer map = read_map(json, "map");
- ByteBuffer shift_map = read_map(json, "shift_map");
- ByteBuffer alt_map = read_map(json, "alt_map");
- ByteBuffer altgr_map = read_map(json, "altgr_map");
+ Vector<u32> map = read_map(json, "map");
+ Vector<u32> shift_map = read_map(json, "shift_map");
+ Vector<u32> alt_map = read_map(json, "alt_map");
+ Vector<u32> altgr_map = read_map(json, "altgr_map");
CharacterMapData character_map;
for (int i = 0; i < CHAR_MAP_SIZE; i++) {
- character_map.map[i] = map[i];
- character_map.shift_map[i] = shift_map[i];
- character_map.alt_map[i] = alt_map[i];
- if (altgr_map) {
- character_map.altgr_map[i] = altgr_map[i];
- } else {
+ character_map.map[i] = map.at(i);
+ character_map.shift_map[i] = shift_map.at(i);
+ character_map.alt_map[i] = alt_map.at(i);
+ if (altgr_map.is_empty()) {
// AltGr map was not found, using Alt map as fallback.
- character_map.altgr_map[i] = alt_map[i];
+ character_map.altgr_map[i] = alt_map.at(i);
+ } else {
+ character_map.altgr_map[i] = altgr_map.at(i);
}
}
return character_map;
}
-ByteBuffer CharacterMapFile::read_map(const JsonObject& json, const String& name)
+Vector<u32> CharacterMapFile::read_map(const JsonObject& json, const String& name)
{
if (!json.has(name))
- return nullptr;
+ return {};
- ByteBuffer buffer;
- buffer.grow(CHAR_MAP_SIZE);
+ Vector<u32> buffer;
+ buffer.resize(CHAR_MAP_SIZE);
auto map_arr = json.get(name).as_array();
for (int i = 0; i < map_arr.size(); i++) {
@@ -89,8 +90,8 @@ ByteBuffer CharacterMapFile::read_map(const JsonObject& json, const String& name
} else if (key_value.length() == 1) {
buffer[i] = key_value.characters()[0];
} else {
- dbg() << "Unknown character in " << name.characters() << "[" << i << "] = " << key_value.characters() << ".";
- ASSERT_NOT_REACHED();
+ Utf8View m_utf8_view(key_value.characters());
+ buffer[i] = *m_utf8_view.begin();
}
}
diff --git a/Libraries/LibKeyboard/CharacterMapFile.h b/Libraries/LibKeyboard/CharacterMapFile.h
index 18cf187b42..60aaacb637 100644
--- a/Libraries/LibKeyboard/CharacterMapFile.h
+++ b/Libraries/LibKeyboard/CharacterMapFile.h
@@ -37,7 +37,7 @@ public:
static Optional<CharacterMapData> load_from_file(const String& file_name);
private:
- static ByteBuffer read_map(const JsonObject& json, const String& name);
+ static Vector<u32> read_map(const JsonObject& json, const String& name);
};
}