Flutter Linux Embedder
fl_keyboard_handler.h File Reference

Go to the source code of this file.

Macros

#define FL_TYPE_KEYBOARD_HANDLER   fl_keyboard_handler_get_type()
 

Functions

 G_DECLARE_FINAL_TYPE (FlKeyboardHandler, fl_keyboard_handler, FL, KEYBOARD_HANDLER, GObject)
 
FlKeyboardHandler * fl_keyboard_handler_new (FlBinaryMessenger *messenger, FlKeyboardViewDelegate *view_delegate)
 
gboolean fl_keyboard_handler_handle_event (FlKeyboardHandler *handler, FlKeyEvent *event)
 
gboolean fl_keyboard_handler_is_state_clear (FlKeyboardHandler *handler)
 
void fl_keyboard_handler_sync_modifier_if_needed (FlKeyboardHandler *handler, guint state, double event_time)
 
GHashTable * fl_keyboard_handler_get_pressed_state (FlKeyboardHandler *handler)
 

Macro Definition Documentation

◆ FL_TYPE_KEYBOARD_HANDLER

#define FL_TYPE_KEYBOARD_HANDLER   fl_keyboard_handler_get_type()

Definition at line 14 of file fl_keyboard_handler.h.

Function Documentation

◆ fl_keyboard_handler_get_pressed_state()

GHashTable* fl_keyboard_handler_get_pressed_state ( FlKeyboardHandler *  handler)

fl_keyboard_handler_get_pressed_state: @handler: the #FlKeyboardHandler 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 590 of file fl_keyboard_handler.cc.

590  {
591  g_return_val_if_fail(FL_IS_KEYBOARD_HANDLER(self), nullptr);
592 
593  // The embedder responder is the first element in
594  // FlKeyboardHandler.responder_list.
595  FlKeyEmbedderResponder* responder =
596  FL_KEY_EMBEDDER_RESPONDER(g_ptr_array_index(self->responder_list, 0));
598 }

References fl_key_embedder_responder_get_pressed_state().

Referenced by fl_view_get_keyboard_state().

◆ fl_keyboard_handler_handle_event()

gboolean fl_keyboard_handler_handle_event ( FlKeyboardHandler *  handler,
FlKeyEvent *  event 
)

fl_keyboard_handler_handle_event: @handler: the #FlKeyboardHandler self. @event: the event to be dispatched. It is usually a wrap of a GdkEventKey. This event will be managed and released by #FlKeyboardHandler.

Make the handler 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 541 of file fl_keyboard_handler.cc.

542  {
543  g_return_val_if_fail(FL_IS_KEYBOARD_HANDLER(self), FALSE);
544  g_return_val_if_fail(event != nullptr, FALSE);
545  g_return_val_if_fail(self->view_delegate != nullptr, FALSE);
546 
547  guarantee_layout(self, event);
548 
549  uint64_t incoming_hash = fl_key_event_hash(event);
550  if (fl_keyboard_handler_remove_redispatched(self, incoming_hash)) {
551  return FALSE;
552  }
553 
554  FlKeyboardPendingEvent* pending = fl_keyboard_pending_event_new(
555  event, ++self->last_sequence_id, self->responder_list->len);
556 
557  g_ptr_array_add(self->pending_responds, pending);
558  FlKeyboardHandlerUserData* user_data = fl_keyboard_handler_user_data_new(
560  DispatchToResponderLoopContext data{
561  .event = event,
562  .specified_logical_key =
563  get_logical_key_from_layout(event, *self->derived_layout),
564  .user_data = user_data,
565  };
566  g_ptr_array_foreach(self->responder_list, dispatch_to_responder, &data);
567 
568  return TRUE;
569 }

References dispatch_to_responder(), event, fl_key_event_hash(), fl_keyboard_handler_remove_redispatched(), fl_keyboard_handler_user_data_new(), fl_keyboard_pending_event_get_sequence_id(), 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_handler_is_state_clear()

gboolean fl_keyboard_handler_is_state_clear ( FlKeyboardHandler *  handler)

fl_keyboard_handler_is_state_clear: @handler: the #FlKeyboardHandler self.

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

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

Definition at line 571 of file fl_keyboard_handler.cc.

571  {
572  g_return_val_if_fail(FL_IS_KEYBOARD_HANDLER(self), FALSE);
573  return self->pending_responds->len == 0 &&
574  self->pending_redispatches->len == 0;
575 }

◆ fl_keyboard_handler_new()

FlKeyboardHandler* fl_keyboard_handler_new ( FlBinaryMessenger *  messenger,
FlKeyboardViewDelegate *  view_delegate 
)

FlKeyboardHandler:

Processes keyboard events and cooperate with TextInputHandler.

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 TextInputHandler) and are handled synchronously.
  • Redispatching: Events are inserted back to the system for redispatching. fl_keyboard_handler_new: @view_delegate: An interface that the handler requires to communicate with the platform. Usually implemented by FlView.

Create a new #FlKeyboardHandler.

Returns: a new #FlKeyboardHandler.

Definition at line 499 of file fl_keyboard_handler.cc.

501  {
502  g_return_val_if_fail(FL_IS_KEYBOARD_VIEW_DELEGATE(view_delegate), nullptr);
503 
504  FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(
505  g_object_new(fl_keyboard_handler_get_type(), nullptr));
506 
507  self->view_delegate = view_delegate;
508  g_object_add_weak_pointer(
509  G_OBJECT(view_delegate),
510  reinterpret_cast<gpointer*>(&(self->view_delegate)));
511 
512  // The embedder responder must be added before the channel responder.
513  g_ptr_array_add(
514  self->responder_list,
515  FL_KEY_RESPONDER(fl_key_embedder_responder_new(
516  [](const FlutterKeyEvent* event, FlutterKeyEventCallback callback,
517  void* callback_user_data, void* send_key_event_user_data) {
518  FlKeyboardHandler* self =
519  FL_KEYBOARD_HANDLER(send_key_event_user_data);
520  g_return_if_fail(self->view_delegate != nullptr);
522  self->view_delegate, event, callback, callback_user_data);
523  },
524  self)));
525  g_ptr_array_add(self->responder_list,
526  FL_KEY_RESPONDER(fl_key_channel_responder_new(
527  fl_keyboard_view_delegate_get_messenger(view_delegate))));
528 
530  self->view_delegate, [self]() { self->derived_layout->clear(); });
531 
532  // Setup the flutter/keyboard channel.
533  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
534  self->channel =
535  fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
537  self, nullptr);
538  return self;
539 }

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_handler_sync_modifier_if_needed()

void fl_keyboard_handler_sync_modifier_if_needed ( FlKeyboardHandler *  handler,
guint  state,
double  event_time 
)

fl_keyboard_handler_sync_modifier_if_needed: @handler: the #FlKeyboardHandler 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 577 of file fl_keyboard_handler.cc.

579  {
580  g_return_if_fail(FL_IS_KEYBOARD_HANDLER(self));
581 
582  // The embedder responder is the first element in
583  // FlKeyboardHandler.responder_list.
584  FlKeyEmbedderResponder* responder =
585  FL_KEY_EMBEDDER_RESPONDER(g_ptr_array_index(self->responder_list, 0));
587  event_time);
588 }

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 ( FlKeyboardHandler  ,
fl_keyboard_handler  ,
FL  ,
KEYBOARD_HANDLER  ,
GObject   
)
event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
kChannelName
static constexpr char kChannelName[]
Definition: fl_keyboard_handler.cc:23
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:896
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:51
fl_standard_method_codec_new
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
Definition: fl_standard_method_codec.cc:291
fl_keyboard_handler_user_data_new
static FlKeyboardHandlerUserData * fl_keyboard_handler_user_data_new(FlKeyboardHandler *handler, uint64_t sequence_id)
Definition: fl_keyboard_handler.cc:146
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
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
fl_keyboard_pending_event_get_sequence_id
uint64_t fl_keyboard_pending_event_get_sequence_id(FlKeyboardPendingEvent *self)
Definition: fl_keyboard_pending_event.cc:75
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
guarantee_layout
static void guarantee_layout(FlKeyboardHandler *self, FlKeyEvent *event)
Definition: fl_keyboard_handler.cc:321
fl_keyboard_handler_remove_redispatched
static bool fl_keyboard_handler_remove_redispatched(FlKeyboardHandler *self, uint64_t hash)
Definition: fl_keyboard_handler.cc:255
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:879
method_call_handler
static void method_call_handler(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
Definition: fl_keyboard_handler.cc:418
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_key_event_hash
uint64_t fl_key_event_hash(FlKeyEvent *self)
Definition: fl_key_event.cc:114
fl_keyboard_view_delegate_get_messenger
FlBinaryMessenger * fl_keyboard_view_delegate_get_messenger(FlKeyboardViewDelegate *self)
Definition: fl_keyboard_view_delegate.cc:35
fl_keyboard_pending_event_new
FlKeyboardPendingEvent * fl_keyboard_pending_event_new(FlKeyEvent *event, uint64_t sequence_id, size_t to_reply)
Definition: fl_keyboard_pending_event.cc:55
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
dispatch_to_responder
static void dispatch_to_responder(gpointer responder_data, gpointer foreach_data_ptr)
Definition: fl_keyboard_handler.cc:439
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
get_logical_key_from_layout
static uint64_t get_logical_key_from_layout(FlKeyEvent *event, const DerivedLayout &layout)
Definition: fl_keyboard_handler.cc:92