Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -44986,6 +44986,8 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_key_embedder_responder_private.
ORIGIN: ../../../flutter/shell/platform/linux/fl_key_embedder_responder_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_key_event.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_key_event.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_keyboard_channel.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_keyboard_channel.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_keyboard_handler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_keyboard_handler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_keyboard_handler_test.cc + ../../../flutter/LICENSE
Expand All @@ -45011,11 +45013,15 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_method_codec_private.h + ../../
ORIGIN: ../../../flutter/shell/platform/linux/fl_method_codec_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_method_response.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_method_response_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_mouse_cursor_channel.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_mouse_cursor_channel.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_mouse_cursor_handler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_mouse_cursor_handler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_channel.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_channel.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_handler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_handler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_handler_test.cc + ../../../flutter/LICENSE
Expand All @@ -45040,6 +45046,8 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_scrolling_manager.h + ../../../
ORIGIN: ../../../flutter/shell/platform/linux/fl_scrolling_manager_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_settings.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_settings.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_settings_channel.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_settings_channel.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_settings_handler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_settings_handler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_settings_handler_test.cc + ../../../flutter/LICENSE
Expand All @@ -45056,6 +45064,8 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_string_codec.cc + ../../../flut
ORIGIN: ../../../flutter/shell/platform/linux/fl_string_codec_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_task_runner.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_task_runner.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_text_input_channel.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_text_input_channel.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_text_input_handler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_text_input_handler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_text_input_handler_test.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -47886,6 +47896,8 @@ FILE: ../../../flutter/shell/platform/linux/fl_key_embedder_responder_private.h
FILE: ../../../flutter/shell/platform/linux/fl_key_embedder_responder_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_key_event.cc
FILE: ../../../flutter/shell/platform/linux/fl_key_event.h
FILE: ../../../flutter/shell/platform/linux/fl_keyboard_channel.cc
FILE: ../../../flutter/shell/platform/linux/fl_keyboard_channel.h
FILE: ../../../flutter/shell/platform/linux/fl_keyboard_handler.cc
FILE: ../../../flutter/shell/platform/linux/fl_keyboard_handler.h
FILE: ../../../flutter/shell/platform/linux/fl_keyboard_handler_test.cc
Expand All @@ -47911,11 +47923,15 @@ FILE: ../../../flutter/shell/platform/linux/fl_method_codec_private.h
FILE: ../../../flutter/shell/platform/linux/fl_method_codec_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_method_response.cc
FILE: ../../../flutter/shell/platform/linux/fl_method_response_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_mouse_cursor_channel.cc
FILE: ../../../flutter/shell/platform/linux/fl_mouse_cursor_channel.h
FILE: ../../../flutter/shell/platform/linux/fl_mouse_cursor_handler.cc
FILE: ../../../flutter/shell/platform/linux/fl_mouse_cursor_handler.h
FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture.cc
FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_channel.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_channel.h
FILE: ../../../flutter/shell/platform/linux/fl_platform_handler.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_handler.h
FILE: ../../../flutter/shell/platform/linux/fl_platform_handler_test.cc
Expand All @@ -47940,6 +47956,8 @@ FILE: ../../../flutter/shell/platform/linux/fl_scrolling_manager.h
FILE: ../../../flutter/shell/platform/linux/fl_scrolling_manager_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_settings.cc
FILE: ../../../flutter/shell/platform/linux/fl_settings.h
FILE: ../../../flutter/shell/platform/linux/fl_settings_channel.cc
FILE: ../../../flutter/shell/platform/linux/fl_settings_channel.h
FILE: ../../../flutter/shell/platform/linux/fl_settings_handler.cc
FILE: ../../../flutter/shell/platform/linux/fl_settings_handler.h
FILE: ../../../flutter/shell/platform/linux/fl_settings_handler_test.cc
Expand All @@ -47956,6 +47974,8 @@ FILE: ../../../flutter/shell/platform/linux/fl_string_codec.cc
FILE: ../../../flutter/shell/platform/linux/fl_string_codec_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_task_runner.cc
FILE: ../../../flutter/shell/platform/linux/fl_task_runner.h
FILE: ../../../flutter/shell/platform/linux/fl_text_input_channel.cc
FILE: ../../../flutter/shell/platform/linux/fl_text_input_channel.h
FILE: ../../../flutter/shell/platform/linux/fl_text_input_handler.cc
FILE: ../../../flutter/shell/platform/linux/fl_text_input_handler.h
FILE: ../../../flutter/shell/platform/linux/fl_text_input_handler_test.cc
Expand Down
5 changes: 5 additions & 0 deletions shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ source_set("flutter_linux_sources") {
"fl_key_channel_responder.cc",
"fl_key_embedder_responder.cc",
"fl_key_event.cc",
"fl_keyboard_channel.cc",
"fl_keyboard_handler.cc",
"fl_keyboard_layout.cc",
"fl_keyboard_manager.cc",
Expand All @@ -126,8 +127,10 @@ source_set("flutter_linux_sources") {
"fl_method_channel.cc",
"fl_method_codec.cc",
"fl_method_response.cc",
"fl_mouse_cursor_channel.cc",
"fl_mouse_cursor_handler.cc",
"fl_pixel_buffer_texture.cc",
"fl_platform_channel.cc",
"fl_platform_handler.cc",
"fl_plugin_registrar.cc",
"fl_plugin_registry.cc",
Expand All @@ -138,6 +141,7 @@ source_set("flutter_linux_sources") {
"fl_renderer_headless.cc",
"fl_scrolling_manager.cc",
"fl_settings.cc",
"fl_settings_channel.cc",
"fl_settings_handler.cc",
"fl_settings_portal.cc",
"fl_socket_accessible.cc",
Expand All @@ -146,6 +150,7 @@ source_set("flutter_linux_sources") {
"fl_string_codec.cc",
"fl_task_runner.cc",
"fl_task_runner.h",
"fl_text_input_channel.cc",
"fl_text_input_handler.cc",
"fl_text_input_view_delegate.cc",
"fl_texture.cc",
Expand Down
84 changes: 84 additions & 0 deletions shell/platform/linux/fl_keyboard_channel.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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_keyboard_channel.h"

#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"

static constexpr char kChannelName[] = "flutter/keyboard";

static constexpr char kGetKeyboardStateMethod[] = "getKeyboardState";

struct _FlKeyboardChannel {
GObject parent_instance;

FlMethodChannel* channel;

FlKeyboardChannelVTable* vtable;

gpointer user_data;
};

G_DEFINE_TYPE(FlKeyboardChannel, fl_keyboard_channel, G_TYPE_OBJECT)

static FlMethodResponse* get_keyboard_state(FlKeyboardChannel* self) {
g_autoptr(FlValue) result = self->vtable->get_keyboard_state(self->user_data);
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

// Called when a method call is received from Flutter.
static void method_call_cb(FlMethodChannel* channel,
FlMethodCall* method_call,
gpointer user_data) {
FlKeyboardChannel* self = FL_KEYBOARD_CHANNEL(user_data);

const gchar* method = fl_method_call_get_name(method_call);
g_autoptr(FlMethodResponse) response = nullptr;
if (strcmp(method, kGetKeyboardStateMethod) == 0) {
response = get_keyboard_state(self);
} else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}

g_autoptr(GError) error = nullptr;
if (!fl_method_call_respond(method_call, response, &error)) {
g_warning("Failed to send method call response: %s", error->message);
}
}

static void fl_keyboard_channel_dispose(GObject* object) {
FlKeyboardChannel* self = FL_KEYBOARD_CHANNEL(object);

g_clear_object(&self->channel);

G_OBJECT_CLASS(fl_keyboard_channel_parent_class)->dispose(object);
}

static void fl_keyboard_channel_class_init(FlKeyboardChannelClass* klass) {
G_OBJECT_CLASS(klass)->dispose = fl_keyboard_channel_dispose;
}

static void fl_keyboard_channel_init(FlKeyboardChannel* self) {}

FlKeyboardChannel* fl_keyboard_channel_new(FlBinaryMessenger* messenger,
FlKeyboardChannelVTable* vtable,
gpointer user_data) {
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
g_return_val_if_fail(vtable != nullptr, nullptr);

FlKeyboardChannel* self = FL_KEYBOARD_CHANNEL(
g_object_new(fl_keyboard_channel_get_type(), nullptr));

self->vtable = vtable;
self->user_data = user_data;

g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
self->channel =
fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(self->channel, method_call_cb, self,
nullptr);

return self;
}
46 changes: 46 additions & 0 deletions shell/platform/linux/fl_keyboard_channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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_KEYBOARD_CHANNEL_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_KEYBOARD_CHANNEL_H_

#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"

G_BEGIN_DECLS

G_DECLARE_FINAL_TYPE(FlKeyboardChannel,
fl_keyboard_channel,
FL,
KEYBOARD_CHANNEL,
GObject);

/**
* FlKeyboardChannel:
*
* #FlKeyboardChannel is a channel that implements the shell side
* of SystemChannels.keyboard from the Flutter services library.
*/

typedef struct {
FlValue* (*get_keyboard_state)(gpointer user_data);
} FlKeyboardChannelVTable;

/**
* fl_keyboard_channel_new:
* @messenger: an #FlBinaryMessenger
* @vtable: callbacks for incoming method calls.
* @user_data: data to pass in callbacks.
*
* Creates a new channel that implements SystemChannels.keyboard from the
* Flutter services library.
*
* Returns: a new #FlKeyboardChannel
*/
FlKeyboardChannel* fl_keyboard_channel_new(FlBinaryMessenger* messenger,
FlKeyboardChannelVTable* vtable,
gpointer user_data);

G_END_DECLS

#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_KEYBOARD_CHANNEL_H_
44 changes: 11 additions & 33 deletions shell/platform/linux/fl_keyboard_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@

#include "flutter/shell/platform/linux/fl_keyboard_handler.h"

#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"

static constexpr char kChannelName[] = "flutter/keyboard";
static constexpr char kGetKeyboardStateMethod[] = "getKeyboardState";
#include "flutter/shell/platform/linux/fl_keyboard_channel.h"

struct _FlKeyboardHandler {
GObject parent_instance;

FlKeyboardManager* keyboard_manager;

// The channel used by the framework to query the keyboard pressed state.
FlMethodChannel* channel;
FlKeyboardChannel* channel;
};

G_DEFINE_TYPE(FlKeyboardHandler, fl_keyboard_handler, G_TYPE_OBJECT);

// Returns the keyboard pressed state.
static FlMethodResponse* get_keyboard_state(FlKeyboardHandler* self) {
g_autoptr(FlValue) result = fl_value_new_map();
static FlValue* get_keyboard_state(gpointer user_data) {
FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(user_data);

FlValue* result = fl_value_new_map();

GHashTable* pressing_records =
fl_keyboard_manager_get_pressed_state(self->keyboard_manager);
Expand All @@ -39,28 +37,8 @@ static FlMethodResponse* get_keyboard_state(FlKeyboardHandler* self) {
fl_value_new_int(logical_key));
},
result);
return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}

// Called when a method call on flutter/keyboard is received from Flutter.
static void method_call_handler(FlMethodChannel* channel,
FlMethodCall* method_call,
gpointer user_data) {
FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(user_data);

const gchar* method = fl_method_call_get_name(method_call);

g_autoptr(FlMethodResponse) response = nullptr;
if (strcmp(method, kGetKeyboardStateMethod) == 0) {
response = get_keyboard_state(self);
} else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}

g_autoptr(GError) error = nullptr;
if (!fl_method_call_respond(method_call, response, &error)) {
g_warning("Failed to send method call response: %s", error->message);
}
return result;
}

static void fl_keyboard_handler_dispose(GObject* object) {
Expand All @@ -76,6 +54,9 @@ static void fl_keyboard_handler_class_init(FlKeyboardHandlerClass* klass) {
G_OBJECT_CLASS(klass)->dispose = fl_keyboard_handler_dispose;
}

static FlKeyboardChannelVTable keyboard_channel_vtable = {
.get_keyboard_state = get_keyboard_state};

static void fl_keyboard_handler_init(FlKeyboardHandler* self) {}

FlKeyboardHandler* fl_keyboard_handler_new(
Expand All @@ -87,10 +68,7 @@ FlKeyboardHandler* fl_keyboard_handler_new(
self->keyboard_manager = FL_KEYBOARD_MANAGER(g_object_ref(keyboard_manager));

// Setup the flutter/keyboard channel.
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
self->channel =
fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(self->channel, method_call_handler,
self, nullptr);
fl_keyboard_channel_new(messenger, &keyboard_channel_vtable, self);
return self;
}
Loading