| Flutter Linux Embedder |

Typedefs | Functions
fl_keyboard_manager.h File Reference
`#include <gdk/gdk.h>`
`#include "flutter/shell/platform/linux/fl_keyboard_view_delegate.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"`

Go to the source code of this file.

## Typedefs
typedef void(* | FlKeyboardManagerSendKeyEventHandler) (const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *callback_user_data, gpointer user_data)
typedef guint(* | FlKeyboardManagerLookupKeyHandler) (const GdkKeymapKey *key, gpointer user_data)
typedef void(* | FlKeyboardManagerRedispatchEventHandler) (FlKeyEvent *event, gpointer user_data)
typedef GHashTable *(* | FlKeyboardManagerGetPressedStateHandler) (gpointer user_data)

## Functions
G_BEGIN_DECLS | G_DECLARE_FINAL_TYPE (FlKeyboardManager, fl_keyboard_manager, FL, KEYBOARD_MANAGER, GObject)
FlKeyboardManager * | fl_keyboard_manager_new (FlEngine *engine, FlKeyboardViewDelegate *view_delegate)
gboolean | fl_keyboard_manager_handle_event (FlKeyboardManager *manager, FlKeyEvent *event)
gboolean | fl_keyboard_manager_is_state_clear (FlKeyboardManager *manager)
void | fl_keyboard_manager_sync_modifier_if_needed (FlKeyboardManager *manager, guint state, double event_time)
GHashTable * | fl_keyboard_manager_get_pressed_state (FlKeyboardManager *manager)
void | fl_keyboard_manager_set_send_key_event_handler (FlKeyboardManager *manager, FlKeyboardManagerSendKeyEventHandler send_key_event_handler, gpointer user_data)
void | fl_keyboard_manager_set_lookup_key_handler (FlKeyboardManager *manager, FlKeyboardManagerLookupKeyHandler lookup_key_handler, gpointer user_data)
void | fl_keyboard_manager_set_redispatch_handler (FlKeyboardManager *manager, FlKeyboardManagerRedispatchEventHandler redispatch_handler, gpointer user_data)
void | fl_keyboard_manager_set_get_pressed_state_handler (FlKeyboardManager *manager, FlKeyboardManagerGetPressedStateHandler get_pressed_state_handler, gpointer user_data)

## Typedef Documentation

## ◆ FlKeyboardManagerGetPressedStateHandler

typedef GHashTable*(* FlKeyboardManagerGetPressedStateHandler) (gpointer user_data)

Definition at line 142 of file fl_keyboard_manager.h.

## ◆ FlKeyboardManagerLookupKeyHandler

typedef guint(* FlKeyboardManagerLookupKeyHandler) (const GdkKeymapKey *key, gpointer user_data)

Definition at line 114 of file fl_keyboard_manager.h.

## ◆ FlKeyboardManagerRedispatchEventHandler

typedef void(* FlKeyboardManagerRedispatchEventHandler) (FlKeyEvent *event, gpointer user_data)

Definition at line 128 of file fl_keyboard_manager.h.

## ◆ FlKeyboardManagerSendKeyEventHandler

typedef void(* FlKeyboardManagerSendKeyEventHandler) (const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *callback_user_data, gpointer user_data)

Definition at line 97 of file fl_keyboard_manager.h.

## Function Documentation

## ◆ fl_keyboard_manager_get_pressed_state()

GHashTable* fl_keyboard_manager_get_pressed_state | ( | FlKeyboardManager * | manager | ) |

fl_keyboard_manager_get_pressed_state: @manager: the #FlKeyboardManager 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 566 of file fl_keyboard_manager.cc.

566 {
567 g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), nullptr);
568 if (self->get_pressed_state_handler != nullptr) {
569 return self->get_pressed_state_handler(
570 self->get_pressed_state_handler_user_data);
571 } else {
572 return fl_key_embedder_responder_get_pressed_state(
573 self->key_embedder_responder);
574 }
575 }

References fl_key_embedder_responder_get_pressed_state().

Referenced by get_keyboard_state().

## ◆ fl_keyboard_manager_handle_event()

gboolean fl_keyboard_manager_handle_event | ( | FlKeyboardManager * | manager,
|  | FlKeyEvent * | event
| ) |  |

fl_keyboard_manager_handle_event: @manager: the #FlKeyboardManager self. @event: the event to be dispatched. It is usually a wrap of a GdkEventKey. This event will be managed and released by #FlKeyboardManager.

Make the manager process a system key event. This might eventually send messages to the framework, trigger text input effects, or redispatch the event back to the system.

Definition at line 522 of file fl_keyboard_manager.cc.

523 {
524 g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), FALSE);
525 g_return_val_if_fail(event != nullptr, FALSE);
526
527 guarantee_layout(self, event);
528
529 uint64_t incoming_hash = fl_key_event_hash(event);
530 if (fl_keyboard_manager_remove_redispatched(self, incoming_hash)) {
531 return FALSE;
532 }
533
534 FlKeyboardPendingEvent* pending = fl_keyboard_pending_event_new(event);
535
536 g_ptr_array_add(self->pending_responds, pending);
537 g_autoptr(FlKeyboardManagerData) data =
538 fl_keyboard_manager_data_new(self, pending);
539 uint64_t specified_logical_key = fl_keyboard_layout_get_logical_key(
540 self->derived_layout, fl_key_event_get_group(event),
541 fl_key_event_get_keycode(event));
542 fl_key_embedder_responder_handle_event(
543 self->key_embedder_responder, event, specified_logical_key,
544 responder_handle_embedder_event_callback, g_object_ref(data));
545 fl_key_channel_responder_handle_event(
546 self->key_channel_responder, event, specified_logical_key,
547 self->cancellable, responder_handle_channel_event_cb, g_object_ref(data));
548
549 return TRUE;
550 }

References fl_key_channel_responder_handle_event(), fl_key_embedder_responder_handle_event(), fl_key_event_get_group(), fl_key_event_get_keycode(), fl_key_event_hash(), fl_keyboard_layout_get_logical_key(), fl_keyboard_manager_data_new(), fl_keyboard_manager_remove_redispatched(), fl_keyboard_pending_event_new(), guarantee_layout(), responder_handle_channel_event_cb(), responder_handle_embedder_event_callback(), and TRUE.

Referenced by fl_view_key_press_event(), and fl_view_key_release_event().

## ◆ fl_keyboard_manager_is_state_clear()

gboolean fl_keyboard_manager_is_state_clear | ( | FlKeyboardManager * | manager | ) |

fl_keyboard_manager_is_state_clear: @manager: the #FlKeyboardManager self.

A debug-only method that queries whether the manager's various states are cleared, i.e. no pending events for redispatching or for responding.

Returns: true if the manager's various states are cleared.

Definition at line 552 of file fl_keyboard_manager.cc.

552 {
553 g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), FALSE);
554 return self->pending_responds->len == 0 &&
555 self->pending_redispatches->len == 0;
556 }

## ◆ fl_keyboard_manager_new()

FlKeyboardManager* fl_keyboard_manager_new | ( | FlEngine * | engine,
|  | FlKeyboardViewDelegate * | view_delegate
| ) |  |

FlKeyboardManager:

Processes keyboard events and cooperate with `TextInputManager`.

A keyboard event goes through a few sections, each can choose to handle the event, and only unhandled events can move to the next section:

- Keyboard: Dispatch to the embedder responder and the channel responder simultaneously. After both responders have responded (asynchronously), the event is considered handled if either responder handles it.
- Text input: Events are sent to IM filter (usually owned by `TextInputManager`) and are handled synchronously.
- Redispatching: Events are inserted back to the system for redispatching. fl_keyboard_manager_new: @engine: an #FlEngine. @view_delegate: An interface that the manager requires to communicate with the platform. Usually implemented by FlView.

Create a new #FlKeyboardManager.

Returns: a new #FlKeyboardManager.

Definition at line 462 of file fl_keyboard_manager.cc.

464 {
465 g_return_val_if_fail(FL_IS_KEYBOARD_VIEW_DELEGATE(view_delegate), nullptr);
466
467 FlKeyboardManager* self = FL_KEYBOARD_MANAGER(
468 g_object_new(fl_keyboard_manager_get_type(), nullptr));
469
470 g_weak_ref_init(&self->engine, engine);
471 g_weak_ref_init(&self->view_delegate, view_delegate);
472
473 self->key_embedder_responder = fl_key_embedder_responder_new(
474 [](const FlutterKeyEvent* event, FlutterKeyEventCallback callback,
475 void* callback_user_data, void* send_key_event_user_data) {
476 FlKeyboardManager* self = FL_KEYBOARD_MANAGER(send_key_event_user_data);
477 if (self->send_key_event_handler != nullptr) {
478 self->send_key_event_handler(event, callback, callback_user_data,
479 self->send_key_event_handler_user_data);
480 } else {
481 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
482 if (engine != nullptr) {
483 typedef struct {
484 FlutterKeyEventCallback callback;
485 void* callback_user_data;
486 } SendKeyEventData;
487 SendKeyEventData* data = g_new0(SendKeyEventData, 1);
488 data->callback = callback;
489 data->callback_user_data = callback_user_data;
490 fl_engine_send_key_event(
491 engine, event, self->cancellable,
492 [](GObject* object, GAsyncResult* result, gpointer user_data) {
493 g_autofree SendKeyEventData* data =
494 static_cast<SendKeyEventData*>(user_data);
495 gboolean handled = FALSE;
496 g_autoptr(GError) error = nullptr;
497 if (!fl_engine_send_key_event_finish(
498 FL_ENGINE(object), result, &handled, &error)) {
499 if (g_error_matches(error, G_IO_ERROR,
500 G_IO_ERROR_CANCELLED)) {
501 return;
502 }
503
504 g_warning("Failed to send key event: %s", error->message);
505 }
506
507 if (data->callback != nullptr) {
508 data->callback(handled, data->callback_user_data);
509 }
510 },
511 data);
512 }
513 }
514 },
515 self);
516 self->key_channel_responder =
517 fl_key_channel_responder_new(fl_engine_get_binary_messenger(engine));
518
519 return self;
520 }

References fl_engine_send_key_event(), fl_key_embedder_responder_new(), if(), and user_data.

Referenced by init_keyboard(), and TEST().

## ◆ fl_keyboard_manager_set_get_pressed_state_handler()

void fl_keyboard_manager_set_get_pressed_state_handler | ( | FlKeyboardManager * | manager,
|  | FlKeyboardManagerGetPressedStateHandler | get_pressed_state_handler,
|  | gpointer | user_data
| ) |  |

fl_keyboard_manager_set_get_pressed_state_handler: @manager: the #FlKeyboardManager self.

Set the handler for gettting the keyboard state, for testing purposes only.

Definition at line 604 of file fl_keyboard_manager.cc.

607 {
608 g_return_if_fail(FL_IS_KEYBOARD_MANAGER(self));
609 self->get_pressed_state_handler = get_pressed_state_handler;
610 self->get_pressed_state_handler_user_data = user_data;
611 }

References user_data.

Referenced by TEST().

## ◆ fl_keyboard_manager_set_lookup_key_handler()

void fl_keyboard_manager_set_lookup_key_handler | ( | FlKeyboardManager * | manager,
|  | FlKeyboardManagerLookupKeyHandler | lookup_key_handler,
|  | gpointer | user_data
| ) |  |

fl_keyboard_manager_set_lookup_key_handler: @manager: the #FlKeyboardManager self.

Set the handler for key lookup, for testing purposes only.

Definition at line 586 of file fl_keyboard_manager.cc.

589 {
590 g_return_if_fail(FL_IS_KEYBOARD_MANAGER(self));
591 self->lookup_key_handler = lookup_key_handler;
592 self->lookup_key_handler_user_data = user_data;
593 }

References user_data.

## ◆ fl_keyboard_manager_set_redispatch_handler()

void fl_keyboard_manager_set_redispatch_handler | ( | FlKeyboardManager * | manager,
|  | FlKeyboardManagerRedispatchEventHandler | redispatch_handler,
|  | gpointer | user_data
| ) |  |

fl_keyboard_manager_set_redispatch_handler: @manager: the #FlKeyboardManager self.

Set the handler for redispatches, for testing purposes only.

Definition at line 595 of file fl_keyboard_manager.cc.

598 {
599 g_return_if_fail(FL_IS_KEYBOARD_MANAGER(self));
600 self->redispatch_handler = redispatch_handler;
601 self->redispatch_handler_user_data = user_data;
602 }

References user_data.

## ◆ fl_keyboard_manager_set_send_key_event_handler()

void fl_keyboard_manager_set_send_key_event_handler | ( | FlKeyboardManager * | manager,
|  | FlKeyboardManagerSendKeyEventHandler | send_key_event_handler,
|  | gpointer | user_data
| ) |  |

fl_keyboard_manager_set_send_key_event_handler: @manager: the #FlKeyboardManager self.

Set the handler for sending events, for testing purposes only.

Definition at line 577 of file fl_keyboard_manager.cc.

580 {
581 g_return_if_fail(FL_IS_KEYBOARD_MANAGER(self));
582 self->send_key_event_handler = send_key_event_handler;
583 self->send_key_event_handler_user_data = user_data;
584 }

References user_data.

## ◆ fl_keyboard_manager_sync_modifier_if_needed()

void fl_keyboard_manager_sync_modifier_if_needed | ( | FlKeyboardManager * | manager,
|  | guint | state,
|  | double | event_time
| ) |  |

fl_keyboard_manager_sync_modifier_if_needed: @manager: the #FlKeyboardManager 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 558 of file fl_keyboard_manager.cc.

560 {
561 g_return_if_fail(FL_IS_KEYBOARD_MANAGER(self));
562 fl_key_embedder_responder_sync_modifiers_if_needed(
563 self->key_embedder_responder, state, event_time);
564 }

References fl_key_embedder_responder_sync_modifiers_if_needed(), and state.

Referenced by sync_modifier_if_needed().

## ◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE | ( | FlKeyboardManager | ,
|  | fl_keyboard_manager | ,
|  | FL | ,
|  | KEYBOARD_MANAGER | ,
|  | GObject |
| ) |  |

if
if(end==-1)
Definition: fl_accessible_text_field.cc:42
responder_handle_embedder_event_callback
static void responder_handle_embedder_event_callback(bool handled, gpointer user_data)
Definition: fl_keyboard_manager.cc:265
fl_key_embedder_responder_handle_event
void fl_key_embedder_responder_handle_event(FlKeyEmbedderResponder *self, FlKeyEvent *event, uint64_t specified_logical_key, FlKeyEmbedderResponderAsyncCallback callback, gpointer user_data)
Definition: fl_key_embedder_responder.cc:835
guarantee_layout
static void guarantee_layout(FlKeyboardManager *self, FlKeyEvent *event)
Definition: fl_keyboard_manager.cc:323
responder_handle_channel_event_cb
static void responder_handle_channel_event_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_keyboard_manager.cc:280
fl_key_event_get_group
guint8 fl_key_event_get_group(FlKeyEvent *self)
Definition: fl_key_event.cc:104
fl_key_embedder_responder_get_pressed_state
GHashTable * fl_key_embedder_responder_get_pressed_state(FlKeyEmbedderResponder *self)
Definition: fl_key_embedder_responder.cc:867
fl_key_channel_responder_new
FlKeyChannelResponder * fl_key_channel_responder_new(FlBinaryMessenger *messenger)
Definition: fl_key_channel_responder.cc:59
fl_keyboard_manager_remove_redispatched
static bool fl_keyboard_manager_remove_redispatched(FlKeyboardManager *self, uint64_t hash)
Definition: fl_keyboard_manager.cc:218
fl_engine_get_binary_messenger
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger(FlEngine *self)
Definition: fl_engine.cc:1203
fl_engine_send_key_event
void fl_engine_send_key_event(FlEngine *self, const FlutterKeyEvent *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:1121
fl_keyboard_layout_get_logical_key
uint64_t fl_keyboard_layout_get_logical_key(FlKeyboardLayout *self, uint8_t group, uint16_t keycode)
Definition: fl_keyboard_layout.cc:65
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
fl_key_embedder_responder_new
FlKeyEmbedderResponder * fl_key_embedder_responder_new(EmbedderSendKeyEvent send_key_event, void *send_key_event_user_data)
Definition: fl_key_embedder_responder.cc:237
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_key_channel_responder_handle_event
void fl_key_channel_responder_handle_event(FlKeyChannelResponder *self, FlKeyEvent *event, uint64_t specified_logical_key, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_key_channel_responder.cc:71
fl_key_embedder_responder_sync_modifiers_if_needed
void fl_key_embedder_responder_sync_modifiers_if_needed(FlKeyEmbedderResponder *responder, guint state, double event_time)
Definition: fl_key_embedder_responder.cc:850
fl_key_event_hash
uint64_t fl_key_event_hash(FlKeyEvent *self)
Definition: fl_key_event.cc:114
fl_key_event_get_keycode
guint16 fl_key_event_get_keycode(FlKeyEvent *self)
Definition: fl_key_event.cc:89
fl_keyboard_pending_event_new
FlKeyboardPendingEvent * fl_keyboard_pending_event_new(FlKeyEvent *event)
Definition: fl_keyboard_pending_event.cc:58
fl_keyboard_manager_data_new
static FlKeyboardManagerData * fl_keyboard_manager_data_new(FlKeyboardManager *manager, FlKeyboardPendingEvent *pending)
Definition: fl_keyboard_manager.cc:102