Flutter Linux Embedder
fl_key_embedder_responder.h File Reference

Go to the source code of this file.

Functions

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (FlKeyEmbedderResponder, fl_key_embedder_responder, FL, KEY_EMBEDDER_RESPONDER, GObject)
 
FlKeyEmbedderResponder * fl_key_embedder_responder_new (FlEngine *engine)
 
void fl_key_embedder_responder_handle_event (FlKeyEmbedderResponder *responder, FlKeyEvent *event, uint64_t specified_logical_key, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
gboolean fl_key_embedder_responder_handle_event_finish (FlKeyEmbedderResponder *responder, GAsyncResult *result, gboolean *handled, GError **error)
 
void fl_key_embedder_responder_sync_modifiers_if_needed (FlKeyEmbedderResponder *responder, guint state, double event_time)
 
GHashTable * fl_key_embedder_responder_get_pressed_state (FlKeyEmbedderResponder *responder)
 

Function Documentation

◆ fl_key_embedder_responder_get_pressed_state()

GHashTable* fl_key_embedder_responder_get_pressed_state ( FlKeyEmbedderResponder *  responder)

fl_key_embedder_responder_get_pressed_state: @responder: the #FlKeyEmbedderResponder 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 782 of file fl_key_embedder_responder.cc.

783  {
784  return self->pressing_records;
785 }

Referenced by fl_keyboard_manager_get_pressed_state().

◆ fl_key_embedder_responder_handle_event()

void fl_key_embedder_responder_handle_event ( FlKeyEmbedderResponder *  responder,
FlKeyEvent *  event,
uint64_t  specified_logical_key,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_key_embedder_responder_handle_event: @responder: the #FlKeyEmbedderResponder self. @event: the event to be handled. Must not be null. The object is managed by callee and must not be assumed available after this function. @specified_logical_key: @cancellable: (allow-none): a #GCancellable or NULL. @callback: (scope async): a #GAsyncReadyCallback to call when the view is added. @user_data: (closure): user data to pass to @callback.

Let the responder handle an event, expecting the responder to report whether to handle the event.

Definition at line 736 of file fl_key_embedder_responder.cc.

741  {
742  g_autoptr(GTask) task = g_task_new(self, cancellable, callback, user_data);
743 
744  self->sent_any_events = false;
746  specified_logical_key, task);
747  if (!self->sent_any_events) {
748  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
749  if (engine != nullptr) {
750  fl_engine_send_key_event(engine, &kEmptyEvent, self->cancellable, nullptr,
751  nullptr);
752  }
753  }
754 }
g_autoptr(FlEngine) engine
const char FlTextDirection FlAssertiveness gpointer user_data
void fl_engine_send_key_event(FlEngine *self, const FlutterKeyEvent *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:1451
static const FlutterKeyEvent kEmptyEvent
static void fl_key_embedder_responder_handle_event_impl(FlKeyEmbedderResponder *responder, FlKeyEvent *event, uint64_t specified_logical_key, GTask *task)

References fl_engine_send_key_event(), fl_key_embedder_responder_handle_event_impl(), g_autoptr(), kEmptyEvent, and user_data.

Referenced by fl_keyboard_manager_handle_event(), and TEST_F().

◆ fl_key_embedder_responder_handle_event_finish()

gboolean fl_key_embedder_responder_handle_event_finish ( FlKeyEmbedderResponder *  responder,
GAsyncResult *  result,
gboolean *  handled,
GError **  error 
)

fl_key_embedder_responder_handle_event_finish: @responder: an #FlKeyEmbedderResponder.

Returns
: a #GAsyncResult. @handled: location to write if this event was handled by the embedder. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore. If error is not NULL, *error must be initialized (typically NULL, but an error from a previous call using GLib error handling is explicitly valid).

Completes request started with fl_key_embedder_responder_handle_event().

Returns TRUE on success.

Definition at line 756 of file fl_key_embedder_responder.cc.

760  {
761  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
762 
763  g_autofree gboolean* return_value =
764  static_cast<gboolean*>(g_task_propagate_pointer(G_TASK(result), error));
765  if (return_value == nullptr) {
766  return FALSE;
767  }
768 
769  *handled = *return_value;
770  return TRUE;
771 }
return TRUE
const uint8_t uint32_t uint32_t GError ** error

References error, and TRUE.

Referenced by responder_handle_embedder_event_cb(), and TEST_F().

◆ fl_key_embedder_responder_new()

FlKeyEmbedderResponder* fl_key_embedder_responder_new ( FlEngine *  engine)

FlKeyEmbedderResponder:

A #FlKeyResponder that handles events by sending the converted events through the embedder API.

This class communicates with the HardwareKeyboard API in the framework. fl_key_embedder_responder_new: @engine: The #FlEngine, whose the embedder API will be used to send the event.

Creates a new #FlKeyEmbedderResponder.

Returns: a new #FlKeyEmbedderResponder.

Definition at line 180 of file fl_key_embedder_responder.cc.

180  {
181  FlKeyEmbedderResponder* self = FL_KEY_EMBEDDER_RESPONDER(
182  g_object_new(fl_key_embedder_responder_get_type(), nullptr));
183 
184  g_weak_ref_init(&self->engine, engine);
185 
186  self->pressing_records = g_hash_table_new(g_direct_hash, g_direct_equal);
187  self->mapping_records = g_hash_table_new(g_direct_hash, g_direct_equal);
188  self->lock_records = 0;
189  self->caps_lock_state_logic_inferrence = STATE_LOGIC_INFERRENCE_UNDECIDED;
190 
191  self->modifier_bit_to_checked_keys =
192  g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
193  initialize_modifier_bit_to_checked_keys(self->modifier_bit_to_checked_keys);
194 
195  self->lock_bit_to_checked_keys =
196  g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
197  initialize_lock_bit_to_checked_keys(self->lock_bit_to_checked_keys);
198 
199  // Associate a logical key with its corresponding modifier bit.
200  self->logical_key_to_lock_bit =
201  g_hash_table_new(g_direct_hash, g_direct_equal);
202  GHashTableIter iter;
203  g_hash_table_iter_init(&iter, self->lock_bit_to_checked_keys);
204  gpointer key, value;
205  while (g_hash_table_iter_next(&iter, &key, &value)) {
206  guint lock_bit = GPOINTER_TO_UINT(key);
207  FlKeyEmbedderCheckedKey* checked_key =
208  reinterpret_cast<FlKeyEmbedderCheckedKey*>(value);
209  g_hash_table_insert(self->logical_key_to_lock_bit,
211  GUINT_TO_POINTER(lock_bit));
212  }
213 
214  return self;
215 }
void initialize_modifier_bit_to_checked_keys(GHashTable *table)
void initialize_lock_bit_to_checked_keys(GHashTable *table)
gpointer uint64_to_gpointer(uint64_t number)
uint8_t value

References initialize_lock_bit_to_checked_keys(), initialize_modifier_bit_to_checked_keys(), FlKeyEmbedderCheckedKey::primary_logical_key, uint64_to_gpointer(), and value.

Referenced by fl_keyboard_manager_new(), and TEST_F().

◆ fl_key_embedder_responder_sync_modifiers_if_needed()

void fl_key_embedder_responder_sync_modifiers_if_needed ( FlKeyEmbedderResponder *  responder,
guint  state,
double  event_time 
)

fl_key_embedder_responder_sync_modifiers_if_needed: @responder: the #FlKeyEmbedderResponder 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 773 of file fl_key_embedder_responder.cc.

776  {
777  g_return_if_fail(FL_IS_KEY_EMBEDDER_RESPONDER(self));
778  synchronize_pressed_states(self, state,
779  event_time * kMicrosecondsPerMillisecond);
780 }
static void synchronize_pressed_states(FlKeyEmbedderResponder *self, guint state, double timestamp)
constexpr uint64_t kMicrosecondsPerMillisecond

References kMicrosecondsPerMillisecond, and synchronize_pressed_states().

Referenced by fl_keyboard_manager_sync_modifier_if_needed().

◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE ( FlKeyEmbedderResponder  ,
fl_key_embedder_responder  ,
FL  ,
KEY_EMBEDDER_RESPONDER  ,
GObject   
)