Flutter Linux Embedder
fl_keyboard_manager.h File Reference

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)
 
FlKeyboardManagerfl_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 688 of file fl_keyboard_manager.cc.

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

References fl_key_embedder_responder_get_pressed_state().

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

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

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(), 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 669 of file fl_keyboard_manager.cc.

669  {
670  g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), FALSE);
671  return self->pending_responds->len == 0 &&
672  self->pending_redispatches->len == 0;
673 }

◆ 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  [](const FlutterKeyEvent* event, FlutterKeyEventCallback callback,
603  void* callback_user_data, void* send_key_event_user_data) {
604  FlKeyboardManager* self =
605  FL_KEYBOARD_MANAGER(send_key_event_user_data);
606  g_return_if_fail(self->view_delegate != nullptr);
608  self->view_delegate, event, callback, callback_user_data);
609  },
610  self)));
611  g_ptr_array_add(self->responder_list,
612  FL_KEY_RESPONDER(fl_key_channel_responder_new(
613  fl_keyboard_view_delegate_get_messenger(view_delegate))));
614 
616  self->view_delegate, [self]() { self->derived_layout->clear(); });
617 
618  // Setup the flutter/keyboard channel.
619  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
620  self->channel =
621  fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
623  self, nullptr);
624  return self;
625 }

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(), kChannelName, and method_call_handler().

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

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

References fl_key_embedder_responder_sync_modifiers_if_needed(), 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:895
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:291
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:628
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:263
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
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
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:878
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
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