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