| Flutter Linux Embedder |

Typedefs | Functions
fl_key_embedder_responder.h File Reference
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/fl_key_event.h"`

Go to the source code of this file.

## Typedefs
typedef void(* | EmbedderSendKeyEvent) (const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *callback_user_data, void *send_key_event_user_data)
typedef void(* | FlKeyEmbedderResponderAsyncCallback) (bool handled, gpointer user_data)

## Functions
G_BEGIN_DECLS | G_DECLARE_FINAL_TYPE (FlKeyEmbedderResponder, fl_key_embedder_responder, FL, KEY_EMBEDDER_RESPONDER, GObject)
FlKeyEmbedderResponder * | fl_key_embedder_responder_new (EmbedderSendKeyEvent send_key_event, void *send_key_event_user_data)
void | fl_key_embedder_responder_handle_event (FlKeyEmbedderResponder *responder, FlKeyEvent *event, uint64_t specified_logical_key, FlKeyEmbedderResponderAsyncCallback callback, gpointer user_data)
void | fl_key_embedder_responder_sync_modifiers_if_needed (FlKeyEmbedderResponder *responder, guint state, double event_time)
GHashTable * | fl_key_embedder_responder_get_pressed_state (FlKeyEmbedderResponder *responder)

## Typedef Documentation

## ◆ EmbedderSendKeyEvent

typedef void(* EmbedderSendKeyEvent) (const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *callback_user_data, void *send_key_event_user_data)

Definition at line 22 of file fl_key_embedder_responder.h.

## ◆ FlKeyEmbedderResponderAsyncCallback

typedef void(* FlKeyEmbedderResponderAsyncCallback) (bool handled, gpointer user_data)

FlKeyEmbedderResponderAsyncCallback: @event: whether the event has been handled. @user_data: the same value as user_data sent by #fl_key_responder_handle_event.

The signature for a callback with which a #FlKeyEmbedderResponder asynchronously reports whether the responder handles the event.

Definition at line 36 of file fl_key_embedder_responder.h.

## Function Documentation

## ◆ fl_key_embedder_responder_get_pressed_state()

GHashTable* fl_key_embedder_responder_get_pressed_state | ( | FlKeyEmbedderResponder * | responder | ) |

fl_key_embedder_responder_get_pressed_state: @responder: the #FlKeyEmbedderResponder self.

Returns the keyboard pressed state. The hash table contains one entry per pressed keys, mapping from the logical key to the physical key.

Definition at line 867 of file fl_key_embedder_responder.cc.

868 {
869 return self->pressing_records;
870 }

Referenced by fl_keyboard_manager_get_pressed_state().

## ◆ fl_key_embedder_responder_handle_event()

void fl_key_embedder_responder_handle_event | ( | FlKeyEmbedderResponder * | responder,
|  | FlKeyEvent * | event,
|  | uint64_t | specified_logical_key,
|  | FlKeyEmbedderResponderAsyncCallback | callback,
|  | gpointer | user_data
| ) |  |

fl_key_embedder_responder_handle_event: @responder: the #FlKeyEmbedderResponder self. @event: the event to be handled. Must not be null. The object is managed by callee and must not be assumed available after this function. @specified_logical_key: @callback: the callback to report the result. It should be called exactly once. Must not be null. @user_data: a value that will be sent back in the callback. Can be null.

Let the responder handle an event, expecting the responder to report whether to handle the event. The result will be reported by invoking `callback` exactly once, which might happen after `fl_key_embedder_responder_handle_event` or during it.

Definition at line 835 of file fl_key_embedder_responder.cc.

840 {
841 self->sent_any_events = false;
842 fl_key_embedder_responder_handle_event_impl(
843 self, event, specified_logical_key, callback, user_data);
844 if (!self->sent_any_events) {
845 self->send_key_event(&kEmptyEvent, nullptr, nullptr,
846 self->send_key_event_user_data);
847 }
848 }

References fl_key_embedder_responder_handle_event_impl(), kEmptyEvent, and user_data.

Referenced by fl_keyboard_manager_handle_event(), and TEST().

## ◆ fl_key_embedder_responder_new()

FlKeyEmbedderResponder* fl_key_embedder_responder_new | ( | EmbedderSendKeyEvent | send_key_event,
|  | void * | send_key_event_user_data
| ) |  |

FlKeyEmbedderResponder:

A #FlKeyResponder that handles events by sending the converted events through the embedder API.

This class communicates with the HardwareKeyboard API in the framework. fl_key_embedder_responder_new: @engine: The #FlEngine, whose the embedder API will be used to send the event.

Creates a new #FlKeyEmbedderResponder. @send_key_event: a function that is called on every key event. @send_key_event_user_data: an opaque pointer that will be sent back as the last argument of send_key_event, created and managed by the object that holds FlKeyEmbedderResponder.

Returns: a new #FlKeyEmbedderResponder.

Definition at line 237 of file fl_key_embedder_responder.cc.

239 {
240 FlKeyEmbedderResponder* self = FL_KEY_EMBEDDER_RESPONDER(
241 g_object_new(fl_key_embedder_responder_get_type(), nullptr));
242
243 self->send_key_event = send_key_event;
244 self->send_key_event_user_data = send_key_event_user_data;
245
246 self->pressing_records = g_hash_table_new(g_direct_hash, g_direct_equal);
247 self->mapping_records = g_hash_table_new(g_direct_hash, g_direct_equal);
248 self->lock_records = 0;
249 self->caps_lock_state_logic_inferrence = STATE_LOGIC_INFERRENCE_UNDECIDED;
250
251 self->modifier_bit_to_checked_keys =
252 g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
253 initialize_modifier_bit_to_checked_keys(self->modifier_bit_to_checked_keys);
254
255 self->lock_bit_to_checked_keys =
256 g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
257 initialize_lock_bit_to_checked_keys(self->lock_bit_to_checked_keys);
258
259 self->logical_key_to_lock_bit =
260 g_hash_table_new(g_direct_hash, g_direct_equal);
261 g_hash_table_foreach(self->lock_bit_to_checked_keys,
262 initialize_logical_key_to_lock_bit_loop_body,
263 self->logical_key_to_lock_bit);
264
265 return self;
266 }

References initialize_lock_bit_to_checked_keys(), initialize_logical_key_to_lock_bit_loop_body(), initialize_modifier_bit_to_checked_keys(), and send_key_event().

Referenced by fl_keyboard_manager_new(), and TEST().

## ◆ fl_key_embedder_responder_sync_modifiers_if_needed()

void fl_key_embedder_responder_sync_modifiers_if_needed | ( | FlKeyEmbedderResponder * | responder,
|  | guint | state,
|  | double | event_time
| ) |  |

fl_key_embedder_responder_sync_modifiers_if_needed: @responder: the #FlKeyEmbedderResponder self. @state: the state of the modifiers mask. @event_time: the time attribute of the incoming GDK event.

If needed, synthesize modifier keys up and down event by comparing their current pressing states with the given modifiers mask.

Definition at line 850 of file fl_key_embedder_responder.cc.

853 {
854 const double timestamp = event_time * kMicrosecondsPerMillisecond;
855
856 SyncStateLoopContext sync_state_context;
857 sync_state_context.self = responder;
858 sync_state_context.state = state;
859 sync_state_context.timestamp = timestamp;
860
861 // Update pressing states.
862 g_hash_table_foreach(responder->modifier_bit_to_checked_keys,
863 synchronize_pressed_states_loop_body,
864 &sync_state_context);
865 }

References kMicrosecondsPerMillisecond, state, and synchronize_pressed_states_loop_body().

Referenced by fl_keyboard_manager_sync_modifier_if_needed().

## ◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE | ( | FlKeyEmbedderResponder | ,
|  | fl_key_embedder_responder | ,
|  | FL | ,
|  | KEY_EMBEDDER_RESPONDER | ,
|  | GObject |
| ) |  |

synchronize_pressed_states_loop_body
static void synchronize_pressed_states_loop_body(gpointer key, gpointer value, gpointer user_data)
Definition: fl_key_embedder_responder.cc:416
state
AtkStateType state
Definition: fl_accessible_node.cc:10
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
initialize_modifier_bit_to_checked_keys
void initialize_modifier_bit_to_checked_keys(GHashTable *table)
Definition: key_mapping.g.cc:414
initialize_lock_bit_to_checked_keys
void initialize_lock_bit_to_checked_keys(GHashTable *table)
Definition: key_mapping.g.cc:446
kMicrosecondsPerMillisecond
constexpr uint64_t kMicrosecondsPerMillisecond
Definition: fl_key_embedder_responder.cc:14
send_key_event
static void send_key_event(FlTextInputHandler *handler, gint keyval, gint state=0)
Definition: fl_text_input_handler_test.cc:144
fl_key_embedder_responder_handle_event_impl
static void fl_key_embedder_responder_handle_event_impl(FlKeyEmbedderResponder *responder, FlKeyEvent *event, uint64_t specified_logical_key, FlKeyEmbedderResponderAsyncCallback callback, gpointer user_data)
Definition: fl_key_embedder_responder.cc:749
initialize_logical_key_to_lock_bit_loop_body
static void initialize_logical_key_to_lock_bit_loop_body(gpointer lock_bit, gpointer value, gpointer user_data)
Definition: fl_key_embedder_responder.cc:225
kEmptyEvent
static const FlutterKeyEvent kEmptyEvent
Definition: fl_key_embedder_responder.cc:16