Flutter Engine
The Flutter Engine
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)
 
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}
GHashTable * fl_key_embedder_responder_get_pressed_state(FlKeyEmbedderResponder *self)

◆ 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
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}
FlKeyEvent * event
static FlKeyboardPendingEvent * fl_keyboard_pending_event_new(std::unique_ptr< FlKeyEvent > event, uint64_t sequence_id, size_t to_reply)
static uint64_t get_logical_key_from_layout(const FlKeyEvent *event, const DerivedLayout &layout)
static uint64_t fl_keyboard_manager_get_event_hash(FlKeyEvent *event)
static void guarantee_layout(FlKeyboardManager *self, FlKeyEvent *event)
static FlKeyboardManagerUserData * fl_keyboard_manager_user_data_new(FlKeyboardManager *manager, uint64_t sequence_id)
static void dispatch_to_responder(gpointer responder_data, gpointer foreach_data_ptr)
static bool fl_keyboard_manager_remove_redispatched(FlKeyboardManager *self, uint64_t hash)
return FALSE
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
void * user_data

◆ 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(
603 void* callback_user_data, void* send_key_event_user_data) {
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(
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}
void(* FlutterKeyEventCallback)(bool, void *)
Definition: embedder.h:1155
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
FlKeyChannelResponder * fl_key_channel_responder_new(FlBinaryMessenger *messenger, FlKeyChannelResponderMock *mock)
FlKeyEmbedderResponder * fl_key_embedder_responder_new(EmbedderSendKeyEvent send_key_event, void *send_key_event_user_data)
typedefG_BEGIN_DECLS struct _FlKeyboardManager FlKeyboardManager
static void method_call_handler(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static constexpr char kChannelName[]
void fl_keyboard_view_delegate_send_key_event(FlKeyboardViewDelegate *self, const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *user_data)
FlBinaryMessenger * fl_keyboard_view_delegate_get_messenger(FlKeyboardViewDelegate *self)
void fl_keyboard_view_delegate_subscribe_to_layout_change(FlKeyboardViewDelegate *self, KeyboardLayoutNotifier notifier)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()

◆ 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}
AtkStateType state
void fl_key_embedder_responder_sync_modifiers_if_needed(FlKeyEmbedderResponder *responder, guint state, double event_time)

◆ G_DECLARE_FINAL_TYPE()

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