Flutter Engine
 
Loading...
Searching...
No Matches
fl_keyboard_layout.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7// The maxiumum keycode in a derived layout.
8//
9// Although X supports higher keycodes, Flutter only cares about standard keys,
10// which are below this.
11constexpr size_t kLayoutSize = 128;
12
15
16 // Each keycode->logical key mapping per group.
17 GHashTable* groups;
18};
19
20G_DEFINE_TYPE(FlKeyboardLayout, fl_keyboard_layout, G_TYPE_OBJECT)
21
22static void fl_keyboard_layout_dispose(GObject* object) {
23 FlKeyboardLayout* self = FL_KEYBOARD_LAYOUT(object);
24
25 g_clear_pointer(&self->groups, g_hash_table_unref);
26
27 G_OBJECT_CLASS(fl_keyboard_layout_parent_class)->dispose(object);
28}
29
30static void fl_keyboard_layout_class_init(FlKeyboardLayoutClass* klass) {
31 G_OBJECT_CLASS(klass)->dispose = fl_keyboard_layout_dispose;
32}
33
34static void fl_keyboard_layout_init(FlKeyboardLayout* self) {
35 self->groups = g_hash_table_new_full(
36 g_direct_hash, g_direct_equal, nullptr,
37 reinterpret_cast<GDestroyNotify>(g_hash_table_unref));
38}
39
40FlKeyboardLayout* fl_keyboard_layout_new() {
41 return FL_KEYBOARD_LAYOUT(
42 g_object_new(fl_keyboard_layout_get_type(), nullptr));
43}
44
45gboolean fl_keyboard_layout_has_group(FlKeyboardLayout* self, uint8_t group) {
46 return g_hash_table_lookup(self->groups, GINT_TO_POINTER(group)) != nullptr;
47}
48
50 uint8_t group,
51 uint16_t keycode,
52 uint64_t logical_key) {
53 GHashTable* group_layout = static_cast<GHashTable*>(
54 g_hash_table_lookup(self->groups, GINT_TO_POINTER(group)));
55 if (group_layout == nullptr) {
56 group_layout =
57 g_hash_table_new_full(g_direct_hash, g_direct_equal, nullptr, nullptr);
58 g_hash_table_insert(self->groups, GINT_TO_POINTER(group), group_layout);
59 }
60
61 g_hash_table_insert(group_layout, GINT_TO_POINTER(keycode),
62 GINT_TO_POINTER(logical_key));
63}
64
65uint64_t fl_keyboard_layout_get_logical_key(FlKeyboardLayout* self,
66 uint8_t group,
67 uint16_t keycode) {
68 if (keycode >= kLayoutSize) {
69 return 0;
70 }
71
72 GHashTable* group_layout = static_cast<GHashTable*>(
73 g_hash_table_lookup(self->groups, GINT_TO_POINTER(group)));
74 if (group_layout == nullptr) {
75 return 0;
76 }
77
78 return GPOINTER_TO_INT(
79 g_hash_table_lookup(group_layout, GINT_TO_POINTER(keycode)));
80}
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
FlKeyboardLayout * fl_keyboard_layout_new()
uint64_t fl_keyboard_layout_get_logical_key(FlKeyboardLayout *self, uint8_t group, uint16_t keycode)
constexpr size_t kLayoutSize
void fl_keyboard_layout_set_logical_key(FlKeyboardLayout *self, uint8_t group, uint16_t keycode, uint64_t logical_key)
static void fl_keyboard_layout_class_init(FlKeyboardLayoutClass *klass)
static void fl_keyboard_layout_dispose(GObject *object)
static void fl_keyboard_layout_init(FlKeyboardLayout *self)
gboolean fl_keyboard_layout_has_group(FlKeyboardLayout *self, uint8_t group)
g_hash_table_insert(self->handlers, g_strdup(channel), handler_new(handler, user_data, destroy_notify))