Skip to content

Commit 1f13ad1

Browse files
authored
Add the input device channel (#48)
1 parent 41c3c24 commit 1f13ad1

11 files changed

+110
-9
lines changed

flutter/shell/platform/tizen/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ template("embedder") {
8383
"channels/app_control.cc",
8484
"channels/app_control_channel.cc",
8585
"channels/feedback_manager.cc",
86+
"channels/input_device_channel.cc",
8687
"channels/key_event_channel.cc",
8788
"channels/key_mapping.cc",
8889
"channels/lifecycle_channel.cc",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2023 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "input_device_channel.h"
6+
7+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
8+
9+
namespace flutter {
10+
11+
namespace {
12+
13+
constexpr char kChannelName[] = "tizen/internal/inputdevice";
14+
15+
} // namespace
16+
17+
InputDeviceChannel::InputDeviceChannel(BinaryMessenger* messenger)
18+
: channel_(std::make_unique<MethodChannel<EncodableValue>>(
19+
messenger,
20+
kChannelName,
21+
&StandardMethodCodec::GetInstance())) {
22+
channel_->SetMethodCallHandler(
23+
[this](const MethodCall<EncodableValue>& call,
24+
std::unique_ptr<MethodResult<EncodableValue>> result) {
25+
this->HandleMethodCall(call, std::move(result));
26+
});
27+
}
28+
29+
InputDeviceChannel::~InputDeviceChannel() {}
30+
31+
void InputDeviceChannel::HandleMethodCall(
32+
const MethodCall<EncodableValue>& method_call,
33+
std::unique_ptr<MethodResult<EncodableValue>> result) {
34+
const std::string& method_name = method_call.method_name();
35+
36+
if (method_name == "getLastUsedKeyboard") {
37+
EncodableMap map;
38+
map[EncodableValue("name")] = EncodableValue(last_keyboard_name_);
39+
result->Success(EncodableValue(map));
40+
} else {
41+
result->NotImplemented();
42+
}
43+
}
44+
45+
} // namespace flutter
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2023 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef EMBEDDER_INPUT_DEVICE_CHANNEL_H_
6+
#define EMBEDDER_INPUT_DEVICE_CHANNEL_H_
7+
8+
#include <memory>
9+
#include <string>
10+
11+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
12+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"
13+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
14+
15+
namespace flutter {
16+
17+
class InputDeviceChannel {
18+
public:
19+
explicit InputDeviceChannel(BinaryMessenger* messenger);
20+
virtual ~InputDeviceChannel();
21+
22+
void SetLastKeyboardInfo(const std::string& name) {
23+
last_keyboard_name_ = name;
24+
}
25+
26+
private:
27+
void HandleMethodCall(const MethodCall<EncodableValue>& method_call,
28+
std::unique_ptr<MethodResult<EncodableValue>> result);
29+
30+
std::unique_ptr<MethodChannel<EncodableValue>> channel_;
31+
32+
// The name of the last keyboard device used.
33+
std::string last_keyboard_name_;
34+
};
35+
36+
} // namespace flutter
37+
38+
#endif // EMBEDDER_INPUT_DEVICE_CHANNEL_H_

flutter/shell/platform/tizen/flutter_tizen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view,
291291
}
292292
#else
293293
ViewFromHandle(view)->OnKey(key, string, nullptr, modifiers, scan_code,
294-
is_down);
294+
device_name, is_down);
295295
#endif
296296
}
297297

flutter/shell/platform/tizen/flutter_tizen_view.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ void FlutterTizenView::SetEngine(std::unique_ptr<FlutterTizenEngine> engine) {
109109
text_input_channel_ = std::make_unique<TextInputChannel>(
110110
internal_plugin_registrar_->messenger(),
111111
tizen_view_->input_method_context());
112+
113+
input_device_channel_ = std::make_unique<InputDeviceChannel>(messenger);
112114
}
113115

114116
void FlutterTizenView::CreateRenderSurface(
@@ -318,6 +320,7 @@ void FlutterTizenView::OnKey(const char* key,
318320
const char* compose,
319321
uint32_t modifiers,
320322
uint32_t scan_code,
323+
const char* device_name,
321324
bool is_down) {
322325
if (is_down) {
323326
FT_LOG(Info) << "Key symbol: " << key << ", code: 0x" << std::setw(8)
@@ -329,6 +332,11 @@ void FlutterTizenView::OnKey(const char* key,
329332
return;
330333
}
331334

335+
if (input_device_channel_ && is_down) {
336+
input_device_channel_->SetLastKeyboardInfo(
337+
device_name ? std::string(device_name) : std::string());
338+
}
339+
332340
if (text_input_channel_) {
333341
if (text_input_channel_->SendKey(key, string, compose, modifiers, scan_code,
334342
is_down)) {

flutter/shell/platform/tizen/flutter_tizen_view.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
#ifndef EMBEDDER_FLUTTER_TIZEN_VIEW_H_
77
#define EMBEDDER_FLUTTER_TIZEN_VIEW_H_
88

9+
#include <cstdint>
910
#include <memory>
1011
#include <string>
1112

1213
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
1314
#include "flutter/shell/platform/embedder/embedder.h"
15+
#include "flutter/shell/platform/tizen/channels/input_device_channel.h"
1416
#include "flutter/shell/platform/tizen/channels/mouse_cursor_channel.h"
1517
#include "flutter/shell/platform/tizen/channels/platform_channel.h"
1618
#include "flutter/shell/platform/tizen/channels/text_input_channel.h"
@@ -95,6 +97,7 @@ class FlutterTizenView : public TizenViewEventHandlerDelegate {
9597
const char* compose,
9698
uint32_t modifiers,
9799
uint32_t scan_code,
100+
const char* device_name,
98101
bool is_down) override;
99102

100103
void OnComposeBegin() override;
@@ -182,7 +185,7 @@ class FlutterTizenView : public TizenViewEventHandlerDelegate {
182185
// A plugin that implements the Flutter platform channel.
183186
std::unique_ptr<PlatformChannel> platform_channel_;
184187

185-
// A plugin that implements the Flutter platform_views channel.
188+
// A plugin that implements the Flutter platform view channel.
186189
std::unique_ptr<PlatformViewChannel> platform_view_channel_;
187190

188191
// A plugin that implements the Flutter cursor channel.
@@ -191,6 +194,9 @@ class FlutterTizenView : public TizenViewEventHandlerDelegate {
191194
// A plugin that implements the Flutter textinput channel.
192195
std::unique_ptr<TextInputChannel> text_input_channel_;
193196

197+
// A plugin to report input device information.
198+
std::unique_ptr<InputDeviceChannel> input_device_channel_;
199+
194200
// The current view rotation degree.
195201
int32_t rotation_degree_ = 0;
196202

flutter/shell/platform/tizen/tizen_view_elementary.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void TizenViewElementary::RegisterEventHandlers() {
266266
self->view_delegate_->OnKey(
267267
key_event->key, key_event->string, key_event->compose,
268268
EvasModifierToEcoreEventModifiers(key_event->modifiers),
269-
key_event->keycode, true);
269+
key_event->keycode, evas_device_name_get(key_event->dev), true);
270270
}
271271
}
272272
}
@@ -292,7 +292,7 @@ void TizenViewElementary::RegisterEventHandlers() {
292292
self->view_delegate_->OnKey(
293293
key_event->key, key_event->string, key_event->compose,
294294
EvasModifierToEcoreEventModifiers(key_event->modifiers),
295-
key_event->keycode, false);
295+
key_event->keycode, nullptr, false);
296296
}
297297
}
298298
}

flutter/shell/platform/tizen/tizen_view_event_handler_delegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class TizenViewEventHandlerDelegate {
5454
const char* compose,
5555
uint32_t modifiers,
5656
uint32_t scan_code,
57+
const char* device_name,
5758
bool is_down) = 0;
5859

5960
virtual void OnComposeBegin() = 0;

flutter/shell/platform/tizen/tizen_view_nui.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ void TizenViewNui::OnKey(const char* device_name,
9393
}
9494

9595
if (!handled) {
96-
view_delegate_->OnKey(key, string, compose, modifiers, scan_code, is_down);
96+
view_delegate_->OnKey(key, string, compose, modifiers, scan_code,
97+
device_name, is_down);
9798
}
9899
}
99100

flutter/shell/platform/tizen/tizen_window_ecore_wl2.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ void TizenWindowEcoreWl2::RegisterEventHandlers() {
357357
if (!handled) {
358358
self->view_delegate_->OnKey(
359359
key_event->key, key_event->string, key_event->compose,
360-
key_event->modifiers, key_event->keycode, true);
360+
key_event->modifiers, key_event->keycode,
361+
ecore_device_name_get(key_event->dev), true);
361362
}
362363
return ECORE_CALLBACK_DONE;
363364
}
@@ -381,7 +382,7 @@ void TizenWindowEcoreWl2::RegisterEventHandlers() {
381382
if (!handled) {
382383
self->view_delegate_->OnKey(
383384
key_event->key, key_event->string, key_event->compose,
384-
key_event->modifiers, key_event->keycode, false);
385+
key_event->modifiers, key_event->keycode, nullptr, false);
385386
}
386387
return ECORE_CALLBACK_DONE;
387388
}

0 commit comments

Comments
 (0)