| Flutter Linux Embedder |

fl_keyboard_handler.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
5 #include "flutter/shell/platform/linux/fl_keyboard_handler.h"
6
7 #include "flutter/shell/platform/linux/fl_keyboard_channel.h"
8 #include "flutter/shell/platform/linux/key_mapping.h"
9
10 struct _FlKeyboardHandler {
11 GObject parent_instance;
12
13 FlKeyboardManager* keyboard_manager;
14
15 // The channel used by the framework to query the keyboard pressed state.
16 FlKeyboardChannel* channel;
17 };
18
19 G_DEFINE_TYPE(FlKeyboardHandler, fl_keyboard_handler, G_TYPE_OBJECT);
20
21 // Returns the keyboard pressed state.
22 static FlValue* get_keyboard_state(gpointer user_data) {
23 FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(user_data);
24
25 FlValue* result = fl_value_new_map();
26
27 GHashTable* pressing_records =
28 fl_keyboard_manager_get_pressed_state(self->keyboard_manager);
29
30 g_hash_table_foreach(
31 pressing_records,
32 [](gpointer key, gpointer value, gpointer user_data) {
33 int64_t physical_key = gpointer_to_uint64(key);
34 int64_t logical_key = gpointer_to_uint64(value);
35 FlValue* fl_value_map = reinterpret_cast<FlValue*>(user_data);
36
37 fl_value_set_take(fl_value_map, fl_value_new_int(physical_key),
38 fl_value_new_int(logical_key));
39 },
40 result);
41
42 return result;
43 }
44
45 static void fl_keyboard_handler_dispose(GObject* object) {
46 FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(object);
47
48 g_clear_object(&self->keyboard_manager);
49 g_clear_object(&self->channel);
50
51 G_OBJECT_CLASS(fl_keyboard_handler_parent_class)->dispose(object);
52 }
53
54 static void fl_keyboard_handler_class_init(FlKeyboardHandlerClass* klass) {
55 G_OBJECT_CLASS(klass)->dispose = fl_keyboard_handler_dispose;
56 }
57
58 static FlKeyboardChannelVTable keyboard_channel_vtable = {
59 .get_keyboard_state = get_keyboard_state};
60
61 static void fl_keyboard_handler_init(FlKeyboardHandler* self) {}
62
63 FlKeyboardHandler* fl_keyboard_handler_new(
64 FlBinaryMessenger* messenger,
65 FlKeyboardManager* keyboard_manager) {
66 FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(
67 g_object_new(fl_keyboard_handler_get_type(), nullptr));
68
69 self->keyboard_manager = FL_KEYBOARD_MANAGER(g_object_ref(keyboard_manager));
70 self->channel =
71 fl_keyboard_channel_new(messenger, &keyboard_channel_vtable, self);
72
73 return self;
74 }
user_data
const char FlTextDirection FlAssertiveness gpointer user_data
Definition: fl_accessibility_handler.cc:24
fl_keyboard_channel_new
FlKeyboardChannel * fl_keyboard_channel_new(FlBinaryMessenger *messenger, FlKeyboardChannelVTable *vtable, gpointer user_data)
Definition: fl_keyboard_channel.cc:65
fl_keyboard_channel.h
get_keyboard_state
static FlValue * get_keyboard_state(gpointer user_data)
Definition: fl_keyboard_handler.cc:22
fl_keyboard_handler_new
FlKeyboardHandler * fl_keyboard_handler_new(FlBinaryMessenger *messenger, FlKeyboardManager *keyboard_manager)
Definition: fl_keyboard_handler.cc:63
keyboard_channel_vtable
static FlKeyboardChannelVTable keyboard_channel_vtable
Definition: fl_keyboard_handler.cc:58
G_DEFINE_TYPE
G_DEFINE_TYPE(FlKeyboardHandler, fl_keyboard_handler, G_TYPE_OBJECT)
fl_keyboard_handler_init
static void fl_keyboard_handler_init(FlKeyboardHandler *self)
Definition: fl_keyboard_handler.cc:61
fl_keyboard_handler_class_init
static void fl_keyboard_handler_class_init(FlKeyboardHandlerClass *klass)
Definition: fl_keyboard_handler.cc:54
fl_keyboard_handler_dispose
static void fl_keyboard_handler_dispose(GObject *object)
Definition: fl_keyboard_handler.cc:45
fl_keyboard_handler.h
fl_keyboard_manager_get_pressed_state
GHashTable * fl_keyboard_manager_get_pressed_state(FlKeyboardManager *self)
Definition: fl_keyboard_manager.cc:435
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_set_take
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
key_mapping.h
gpointer_to_uint64
uint64_t gpointer_to_uint64(gpointer pointer)
Definition: key_mapping.h:13
_FlKeyboardHandler
Definition: fl_keyboard_handler.cc:10
_FlKeyboardHandler::parent_instance
GObject parent_instance
Definition: fl_keyboard_handler.cc:11
_FlKeyboardHandler::keyboard_manager
FlKeyboardManager * keyboard_manager
Definition: fl_keyboard_handler.cc:13
_FlKeyboardHandler::channel
FlKeyboardChannel * channel
Definition: fl_keyboard_handler.cc:16
FlKeyboardChannelVTable
Definition: fl_keyboard_channel.h:25
FlKeyboardChannelVTable::get_keyboard_state
FlValue *(* get_keyboard_state)(gpointer user_data)
Definition: fl_keyboard_channel.h:26