This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Split keyevent channel into own class #56911
Merged
robert-ancell
merged 4 commits into
flutter:main
from
robert-ancell:linux-keyevent-channel
Dec 3, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/shell/platform/linux/fl_key_event_channel.h" | ||
|
|
||
| #include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h" | ||
| #include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h" | ||
|
|
||
| static constexpr char kChannelName[] = "flutter/keyevent"; | ||
| static constexpr char kTypeKey[] = "type"; | ||
| static constexpr char kTypeValueUp[] = "keyup"; | ||
| static constexpr char kTypeValueDown[] = "keydown"; | ||
| static constexpr char kKeymapKey[] = "keymap"; | ||
| static constexpr char kKeyCodeKey[] = "keyCode"; | ||
| static constexpr char kScanCodeKey[] = "scanCode"; | ||
| static constexpr char kModifiersKey[] = "modifiers"; | ||
| static constexpr char kToolkitKey[] = "toolkit"; | ||
| static constexpr char kSpecifiedLogicalKey[] = "specifiedLogicalKey"; | ||
| static constexpr char kUnicodeScalarValuesKey[] = "unicodeScalarValues"; | ||
|
|
||
| static constexpr char kGtkToolkit[] = "gtk"; | ||
| static constexpr char kLinuxKeymap[] = "linux"; | ||
|
|
||
| static constexpr int64_t kUnicodeScalarValuesUnset = 0; | ||
| static constexpr int64_t kSpecifiedLogicalKeyUnset = 0; | ||
|
|
||
| struct _FlKeyEventChannel { | ||
| GObject parent_instance; | ||
|
|
||
| FlBasicMessageChannel* channel; | ||
| }; | ||
|
|
||
| G_DEFINE_TYPE(FlKeyEventChannel, fl_key_event_channel, G_TYPE_OBJECT) | ||
|
|
||
| static void fl_key_event_channel_dispose(GObject* object) { | ||
| FlKeyEventChannel* self = FL_KEY_EVENT_CHANNEL(object); | ||
|
|
||
| g_clear_object(&self->channel); | ||
|
|
||
| G_OBJECT_CLASS(fl_key_event_channel_parent_class)->dispose(object); | ||
| } | ||
|
|
||
| static void fl_key_event_channel_class_init(FlKeyEventChannelClass* klass) { | ||
| G_OBJECT_CLASS(klass)->dispose = fl_key_event_channel_dispose; | ||
| } | ||
|
|
||
| static void fl_key_event_channel_init(FlKeyEventChannel* self) {} | ||
|
|
||
| FlKeyEventChannel* fl_key_event_channel_new(FlBinaryMessenger* messenger) { | ||
| g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr); | ||
|
|
||
| FlKeyEventChannel* self = FL_KEY_EVENT_CHANNEL( | ||
| g_object_new(fl_key_event_channel_get_type(), nullptr)); | ||
|
|
||
| g_autoptr(FlJsonMessageCodec) codec = fl_json_message_codec_new(); | ||
| self->channel = fl_basic_message_channel_new(messenger, kChannelName, | ||
| FL_MESSAGE_CODEC(codec)); | ||
|
|
||
| return self; | ||
| } | ||
|
|
||
| void fl_key_event_channel_send(FlKeyEventChannel* self, | ||
| FlKeyEventType type, | ||
| int64_t scan_code, | ||
| int64_t key_code, | ||
| int64_t modifiers, | ||
| int64_t unicode_scalar_values, | ||
| int64_t specified_logical_key, | ||
| GCancellable* cancellable, | ||
| GAsyncReadyCallback callback, | ||
| gpointer user_data) { | ||
| g_return_if_fail(FL_IS_KEY_EVENT_CHANNEL(self)); | ||
|
|
||
| const gchar* type_string; | ||
| switch (type) { | ||
| case FL_KEY_EVENT_TYPE_KEYUP: | ||
| type_string = kTypeValueUp; | ||
| break; | ||
| case FL_KEY_EVENT_TYPE_KEYDOWN: | ||
| type_string = kTypeValueDown; | ||
| break; | ||
| default: | ||
| g_assert_not_reached(); | ||
| } | ||
|
|
||
| g_autoptr(FlValue) message = fl_value_new_map(); | ||
| fl_value_set_string_take(message, kTypeKey, fl_value_new_string(type_string)); | ||
| fl_value_set_string_take(message, kKeymapKey, | ||
| fl_value_new_string(kLinuxKeymap)); | ||
| fl_value_set_string_take(message, kScanCodeKey, fl_value_new_int(scan_code)); | ||
| fl_value_set_string_take(message, kToolkitKey, | ||
| fl_value_new_string(kGtkToolkit)); | ||
| fl_value_set_string_take(message, kKeyCodeKey, fl_value_new_int(key_code)); | ||
| fl_value_set_string_take(message, kModifiersKey, fl_value_new_int(modifiers)); | ||
| if (unicode_scalar_values != kUnicodeScalarValuesUnset) { | ||
| fl_value_set_string_take(message, kUnicodeScalarValuesKey, | ||
| fl_value_new_int(unicode_scalar_values)); | ||
| } | ||
| if (specified_logical_key != kSpecifiedLogicalKeyUnset) { | ||
| fl_value_set_string_take(message, kSpecifiedLogicalKey, | ||
| fl_value_new_int(specified_logical_key)); | ||
| } | ||
| fl_basic_message_channel_send(self->channel, message, cancellable, callback, | ||
| user_data); | ||
| } | ||
|
|
||
| gboolean fl_key_event_channel_send_finish(GObject* object, | ||
| GAsyncResult* result, | ||
| gboolean* handled, | ||
| GError** error) { | ||
| FlValue* message = fl_basic_message_channel_send_finish( | ||
| FL_BASIC_MESSAGE_CHANNEL(object), result, error); | ||
| if (message == nullptr) { | ||
| return FALSE; | ||
| } | ||
|
|
||
| g_autoptr(FlValue) handled_value = fl_value_lookup_string(message, "handled"); | ||
| *handled = fl_value_get_bool(handled_value); | ||
|
|
||
| return TRUE; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_KEY_EVENT_CHANNEL_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_LINUX_FL_KEY_EVENT_CHANNEL_H_ | ||
|
|
||
| #include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h" | ||
|
|
||
| G_BEGIN_DECLS | ||
|
|
||
| G_DECLARE_FINAL_TYPE(FlKeyEventChannel, | ||
| fl_key_event_channel, | ||
| FL, | ||
| KEY_EVENT_CHANNEL, | ||
| GObject); | ||
|
|
||
| /** | ||
| * FlKeyEventChannel: | ||
| * | ||
| * #FlKeyEventChannel is a channel that implements the shell side | ||
| * of SystemChannels.keyEvent from the Flutter services library. | ||
| */ | ||
|
|
||
| typedef enum { | ||
| FL_KEY_EVENT_TYPE_KEYUP, | ||
| FL_KEY_EVENT_TYPE_KEYDOWN, | ||
| } FlKeyEventType; | ||
|
|
||
| /** | ||
| * fl_key_event_channel_new: | ||
| * @messenger: an #FlBinaryMessenger | ||
| * | ||
| * Creates a new channel that implements SystemChannels.keyEvent from the | ||
| * Flutter services library. | ||
| * | ||
| * Returns: a new #FlKeyEventChannel. | ||
| */ | ||
| FlKeyEventChannel* fl_key_event_channel_new(FlBinaryMessenger* messenger); | ||
|
|
||
| /** | ||
| * fl_key_event_channel_send: | ||
| * @channel: an #FlKeyEventChannel | ||
| * @type: event type. | ||
| * @scan_code: scan code. | ||
| * @key_code: key code. | ||
| * @modifiers: modifiers. | ||
| * @unicode_scarlar_values: | ||
| * @specified_logical_key: | ||
| * @cancellable: (allow-none): a #GCancellable or %NULL. | ||
| * @callback: (scope async): a #GAsyncReadyCallback to call when the method | ||
| * returns. | ||
| * @user_data: (closure): user data to pass to @callback. | ||
| * | ||
| * Send a key event to the platform. | ||
| */ | ||
| void fl_key_event_channel_send(FlKeyEventChannel* channel, | ||
| FlKeyEventType type, | ||
| int64_t scan_code, | ||
| int64_t key_code, | ||
| int64_t modifiers, | ||
| int64_t unicode_scarlar_values, | ||
| int64_t specified_logical_key, | ||
| GCancellable* cancellable, | ||
| GAsyncReadyCallback callback, | ||
| gpointer user_data); | ||
|
|
||
| /** | ||
| * fl_key_event_channel_send_finish: | ||
| * @object: | ||
| * @result: a #GAsyncResult. | ||
| * @error: (allow-none): #GError location to store the error occurring, or %NULL | ||
| * to ignore. | ||
| * | ||
| * Completes request started with fl_key_event_channel_send(). | ||
| * | ||
| * Returns: %TRUE on success. | ||
| */ | ||
| gboolean fl_key_event_channel_send_finish(GObject* object, | ||
| GAsyncResult* result, | ||
| gboolean* handled, | ||
| GError** error); | ||
|
|
||
| G_END_DECLS | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_KEY_EVENT_CHANNEL_H_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.