| Flutter Linux Embedder |

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

Go to the source code of this file.

## Macros
#define | FL_TYPE_KEYBOARD_MANAGER fl_keyboard_manager_get_type()

## Functions
| G_DECLARE_FINAL_TYPE (FlKeyboardManager, fl_keyboard_manager, FL, KEYBOARD_MANAGER, GObject)
FlKeyboardManager * | fl_keyboard_manager_new (FlBinaryMessenger *messenger, 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)

## Macro Definition Documentation

## ◆ FL_TYPE_KEYBOARD_MANAGER

#define FL_TYPE_KEYBOARD_MANAGER fl_keyboard_manager_get_type()

Definition at line 14 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 685 of file fl_keyboard_manager.cc.

685 {
686 g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), nullptr);
687
688 // The embedder responder is the first element in
689 // FlKeyboardManager.responder_list.
690 FlKeyEmbedderResponder* responder =
691 FL_KEY_EMBEDDER_RESPONDER(g_ptr_array_index(self->responder_list, 0));
692 return fl_key_embedder_responder_get_pressed_state(responder);
693 }

References fl_key_embedder_responder_get_pressed_state(), and self.

Referenced by fl_view_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 635 of file fl_keyboard_manager.cc.

636 {
637 g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), FALSE);
638 g_return_val_if_fail(event != nullptr, FALSE);
639 g_return_val_if_fail(self->view_delegate != nullptr, FALSE);
640
641 guarantee_layout(self, event);
642
643 uint64_t incoming_hash = fl_keyboard_manager_get_event_hash(event);
644 if (fl_keyboard_manager_remove_redispatched(self, incoming_hash)) {
645 return FALSE;
646 }
647
648 FlKeyboardPendingEvent* pending = fl_keyboard_pending_event_new(
649 std::unique_ptr<FlKeyEvent>(event), ++self->last_sequence_id,
650 self->responder_list->len);
651
652 g_ptr_array_add(self->pending_responds, pending);
653 FlKeyboardManagerUserData* user_data =
654 fl_keyboard_manager_user_data_new(self, pending->sequence_id);
655 DispatchToResponderLoopContext data{
656 .event = event,
657 .specified_logical_key =
658 get_logical_key_from_layout(event, *self->derived_layout),
659 .user_data = user_data,
660 };
661 g_ptr_array_foreach(self->responder_list, dispatch_to_responder, &data);
662
663 return TRUE;
664 }

References dispatch_to_responder(), event, fl_keyboard_manager_get_event_hash(), fl_keyboard_manager_remove_redispatched(), fl_keyboard_manager_user_data_new(), fl_keyboard_pending_event_new(), get_logical_key_from_layout(), guarantee_layout(), self, TRUE, and user_data.

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 666 of file fl_keyboard_manager.cc.

666 {
667 g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), FALSE);
668 return self->pending_responds->len == 0 &&
669 self->pending_redispatches->len == 0;
670 }

## ◆ fl_keyboard_manager_new()

FlKeyboardManager* fl_keyboard_manager_new | ( | FlBinaryMessenger * | messenger,
|  | FlKeyboardViewDelegate * | view_delegate
| ) |  |

FlKeyboardManager:

Processes keyboard events and cooperate with `TextInputPlugin`.

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 `TextInputPlugin`) and are handled synchronously.
- Redispatching: Events are inserted back to the system for redispatching. fl_keyboard_manager_new: @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 585 of file fl_keyboard_manager.cc.

587 {
588 g_return_val_if_fail(FL_IS_KEYBOARD_VIEW_DELEGATE(view_delegate), nullptr);
589
590 FlKeyboardManager* self = FL_KEYBOARD_MANAGER(
591 g_object_new(fl_keyboard_manager_get_type(), nullptr));
592
593 self->view_delegate = view_delegate;
594 g_object_add_weak_pointer(
595 G_OBJECT(view_delegate),
596 reinterpret_cast<gpointer*>(&(self->view_delegate)));
597
598 // The embedder responder must be added before the channel responder.
599 g_ptr_array_add(
600 self->responder_list,
601 FL_KEY_RESPONDER(fl_key_embedder_responder_new(
602 [self](const FlutterKeyEvent* event, FlutterKeyEventCallback callback,
603 void* user_data) {
604 g_return_if_fail(self->view_delegate != nullptr);
605 fl_keyboard_view_delegate_send_key_event(self->view_delegate, event,
606 callback, user_data);
607 })));
608 g_ptr_array_add(self->responder_list,
609 FL_KEY_RESPONDER(fl_key_channel_responder_new(
610 fl_keyboard_view_delegate_get_messenger(view_delegate))));
611
612 fl_keyboard_view_delegate_subscribe_to_layout_change(
613 self->view_delegate, [self]() { self->derived_layout->clear(); });
614
615 // Setup the flutter/keyboard channel.
616 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
617 self->channel =
618 fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
619 fl_method_channel_set_method_call_handler(self->channel, method_call_handler,
620 self, nullptr);
621 return self;
622 }

References callback, event, fl_key_channel_responder_new(), fl_key_embedder_responder_new(), fl_keyboard_view_delegate_get_messenger(), fl_keyboard_view_delegate_send_key_event(), fl_keyboard_view_delegate_subscribe_to_layout_change(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), fl_standard_method_codec_new(), g_object_add_weak_pointer(), kChannelName, method_call_handler(), self, and user_data.

Referenced by init_keyboard().

## ◆ 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 672 of file fl_keyboard_manager.cc.

674 {
675 g_return_if_fail(FL_IS_KEYBOARD_MANAGER(self));
676
677 // The embedder responder is the first element in
678 // FlKeyboardManager.responder_list.
679 FlKeyEmbedderResponder* responder =
680 FL_KEY_EMBEDDER_RESPONDER(g_ptr_array_index(self->responder_list, 0));
681 fl_key_embedder_responder_sync_modifiers_if_needed(responder, state,
682 event_time);
683 }

References fl_key_embedder_responder_sync_modifiers_if_needed(), self, and state.

Referenced by motion_notify_event_cb(), and send_pointer_button_event().

## ◆ G_DECLARE_FINAL_TYPE()

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

event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
guarantee_layout
static void guarantee_layout(FlKeyboardManager *self, FlKeyEvent *event)
Definition: fl_keyboard_manager.cc:468
fl_method_channel_new
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
Definition: fl_method_channel.cc:112
fl_key_embedder_responder_get_pressed_state
GHashTable * fl_key_embedder_responder_get_pressed_state(FlKeyEmbedderResponder *self)
Definition: fl_key_embedder_responder.cc:889
fl_keyboard_pending_event_new
static FlKeyboardPendingEvent * fl_keyboard_pending_event_new(std::unique_ptr< FlKeyEvent > event, uint64_t sequence_id, size_t to_reply)
Definition: fl_keyboard_manager.cc:184
fl_keyboard_view_delegate_subscribe_to_layout_change
void fl_keyboard_view_delegate_subscribe_to_layout_change(FlKeyboardViewDelegate *self, KeyboardLayoutNotifier notifier)
Definition: fl_keyboard_view_delegate.cc:52
fl_standard_method_codec_new
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
Definition: fl_standard_method_codec.cc:248
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
fl_keyboard_manager_remove_redispatched
static bool fl_keyboard_manager_remove_redispatched(FlKeyboardManager *self, uint64_t hash)
Definition: fl_keyboard_manager.cc:402
state
AtkStateType state
Definition: fl_accessible_node.cc:10
fl_key_channel_responder_new
FlKeyChannelResponder * fl_key_channel_responder_new(FlBinaryMessenger *messenger, FlKeyChannelResponderMock *mock)
Definition: fl_key_channel_responder.cc:186
dispatch_to_responder
static void dispatch_to_responder(gpointer responder_data, gpointer foreach_data_ptr)
Definition: fl_keyboard_manager.cc:625
fl_keyboard_manager_get_event_hash
static uint64_t fl_keyboard_manager_get_event_hash(FlKeyEvent *event)
Definition: fl_keyboard_manager.cc:168
get_logical_key_from_layout
static uint64_t get_logical_key_from_layout(const FlKeyEvent *event, const DerivedLayout &layout)
Definition: fl_keyboard_manager.cc:97
fl_key_embedder_responder_new
FlKeyEmbedderResponder * fl_key_embedder_responder_new(EmbedderSendKeyEvent send_key_event)
Definition: fl_key_embedder_responder.cc:262
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
g_object_add_weak_pointer
g_object_add_weak_pointer(G_OBJECT(self), reinterpret_cast< gpointer * >(&self->engine))
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:872
kChannelName
static constexpr char kChannelName[]
Definition: fl_keyboard_manager.cc:22
fl_method_channel_set_method_call_handler
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_method_channel.cc:134
self
GdkEvent FlView * self
Definition: fl_view.cc:100
fl_keyboard_manager_user_data_new
static FlKeyboardManagerUserData * fl_keyboard_manager_user_data_new(FlKeyboardManager *manager, uint64_t sequence_id)
Definition: fl_keyboard_manager.cc:238
fl_keyboard_view_delegate_get_messenger
FlBinaryMessenger * fl_keyboard_view_delegate_get_messenger(FlKeyboardViewDelegate *self)
Definition: fl_keyboard_view_delegate.cc:35
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
method_call_handler
static void method_call_handler(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
Definition: fl_keyboard_manager.cc:565
fl_keyboard_view_delegate_send_key_event
void fl_keyboard_view_delegate_send_key_event(FlKeyboardViewDelegate *self, const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *user_data)
Definition: fl_keyboard_view_delegate.cc:14
FlKeyboardManager
typedefG_BEGIN_DECLS struct _FlKeyboardManager FlKeyboardManager
Definition: fl_key_responder.h:17