Skip to content

Commit

Permalink
Support device type for KeyEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
JSUYA committed Apr 4, 2024
1 parent d53f19c commit 843318d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions flutter/shell/platform/tizen/channels/input_device_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class InputDeviceChannel {
last_keyboard_name_ = name;
}

std::string last_keyboard_name() { return last_keyboard_name_; }

private:
void HandleMethodCall(const MethodCall<EncodableValue>& method_call,
std::unique_ptr<MethodResult<EncodableValue>> result);
Expand Down
8 changes: 6 additions & 2 deletions flutter/shell/platform/tizen/channels/keyboard_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void KeyboardChannel::SendKey(const char* key,
uint32_t modifiers,
uint32_t scan_code,
bool is_down,
FlutterKeyEventDeviceType device_type,
std::function<void(bool)> callback) {
uint64_t sequence_id = last_sequence_id_++;

Expand All @@ -142,7 +143,7 @@ void KeyboardChannel::SendKey(const char* key,
}

SendEmbedderEvent(key, string, compose, modifiers, scan_code, is_down,
sequence_id);
sequence_id, device_type);
// The channel-based API (RawKeyEvent) is deprecated and |SendChannelEvent|
// will be removed in the future. This class (KeyboardChannel) itself will
// also be renamed and refactored then.
Expand Down Expand Up @@ -205,7 +206,8 @@ void KeyboardChannel::SendEmbedderEvent(const char* key,
uint32_t modifiers,
uint32_t scan_code,
bool is_down,
uint64_t sequence_id) {
uint64_t sequence_id,
FlutterKeyEventDeviceType device_type) {
uint64_t physical_key = GetPhysicalKey(scan_code);
uint64_t logical_key = GetLogicalKey(key);
const char* character = is_down ? string : nullptr;
Expand Down Expand Up @@ -242,6 +244,7 @@ void KeyboardChannel::SendEmbedderEvent(const char* key,
.logical = 0,
.character = "",
.synthesized = false,
.device_type = device_type,
};
send_event_(empty_event, nullptr, nullptr);
ResolvePendingEvent(sequence_id, true);
Expand All @@ -263,6 +266,7 @@ void KeyboardChannel::SendEmbedderEvent(const char* key,
event.logical = last_logical_record != 0 ? last_logical_record : logical_key;
event.character = character;
event.synthesized = false;
event.device_type = device_type;

send_event_(
event,
Expand Down
4 changes: 3 additions & 1 deletion flutter/shell/platform/tizen/channels/keyboard_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class KeyboardChannel {
uint32_t modifiers,
uint32_t scan_code,
bool is_down,
FlutterKeyEventDeviceType device_type,
std::function<void(bool)> callback);

private:
Expand Down Expand Up @@ -69,7 +70,8 @@ class KeyboardChannel {
uint32_t modifiers,
uint32_t scan_code,
bool is_down,
uint64_t sequence_id);
uint64_t sequence_id,
FlutterKeyEventDeviceType device_type);

void SendChannelEvent(const char* key,
const char* string,
Expand Down
18 changes: 17 additions & 1 deletion flutter/shell/platform/tizen/flutter_tizen_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const std::vector<std::string> kBindableSystemKeys = {
"XF86Exit",
};

const std::vector<std::string> kRemoteControlDeviceTypeNameKeywords = {
"rc device", // wt61p807 rc device
"Smart Control", // Smart Control 2016
};

// The multiplier is taken from the Chromium source
// (ui/events/x/events_x_utils.cc).
constexpr int32_t kScrollOffsetMultiplier = 53;
Expand Down Expand Up @@ -352,9 +357,20 @@ void FlutterTizenView::OnKey(const char* key,
}
}

FlutterKeyEventDeviceType device_type =
FlutterKeyEventDeviceType::kFlutterKeyEventDeviceTypeKeyboard;
for (const std::string& key : kRemoteControlDeviceTypeNameKeywords) {
if (input_device_channel_->last_keyboard_name().find(key) !=
std::string::npos) {
device_type =
FlutterKeyEventDeviceType::kFlutterKeyEventDeviceTypeDirectionalPad;
break;
}
}

if (engine_->keyboard_channel()) {
engine_->keyboard_channel()->SendKey(
key, string, compose, modifiers, scan_code, is_down,
key, string, compose, modifiers, scan_code, is_down, device_type,
[engine = engine_.get(), symbol = std::string(key),
is_down](bool handled) {
if (handled) {
Expand Down

0 comments on commit 843318d

Please sign in to comment.