44
55#include " key_event_handler.h"
66
7- #ifndef __X64_SHELL__
7+ #ifdef __X64_SHELL__
8+ #include < cstdlib>
9+ #else
810#include < app.h>
911#endif
12+ #include < iostream>
1013
1114#include " flutter/shell/platform/tizen/flutter_tizen_engine.h"
1215#include " flutter/shell/platform/tizen/logger.h"
@@ -18,9 +21,28 @@ namespace {
1821constexpr char kBackKey [] = " XF86Back" ;
1922constexpr char kExitKey [] = " XF86Exit" ;
2023
24+ // Keys that should always be handled by the app first but not by the system.
25+ const std::vector<std::string> kBindableSystemKeys = {
26+ " XF86Menu" , " XF86Back" , " XF86AudioPlay" ,
27+ " XF86AudioPause" , " XF86AudioStop" , " XF86AudioNext" ,
28+ " XF86AudioPrev" , " XF86AudioRewind" , " XF86AudioForward" ,
29+ " XF86AudioPlayPause" , " XF86AudioRecord" , " XF86LowerChannel" ,
30+ " XF86RaiseChannel" , " XF86ChannelList" , " XF86PreviousChannel" ,
31+ " XF86SysMenu" , " XF86SimpleMenu" , " XF86History" ,
32+ " XF86Favorites" , " XF86Info" , " XF86Red" ,
33+ " XF86Green" , " XF86Yellow" , " XF86Blue" ,
34+ " XF86Subtitle" , " XF86PlayBack" , " XF86ChannelGuide" ,
35+ " XF86Caption" , " XF86Exit" ,
36+ };
37+
2138} // namespace
2239
2340KeyEventHandler::KeyEventHandler (FlutterTizenEngine* engine) : engine_(engine) {
41+ if (!engine->renderer () || !engine->renderer ()->IsValid ()) {
42+ return ;
43+ }
44+ engine->renderer ()->BindKeys (kBindableSystemKeys );
45+
2446 key_event_handlers_.push_back (
2547 ecore_event_handler_add (ECORE_EVENT_KEY_DOWN, OnKey, this ));
2648 key_event_handlers_.push_back (
@@ -34,49 +56,53 @@ KeyEventHandler::~KeyEventHandler() {
3456 key_event_handlers_.clear ();
3557}
3658
37- Eina_Bool KeyEventHandler::OnKey (void * data, int type, void * event ) {
59+ Eina_Bool KeyEventHandler::OnKey (void * data, int type, void * raw_event ) {
3860 auto * self = reinterpret_cast <KeyEventHandler*>(data);
39- auto * key = reinterpret_cast <Ecore_Event_Key*>(event );
61+ auto * event = reinterpret_cast <Ecore_Event_Key*>(raw_event );
4062 auto * engine = self->engine_ ;
41- auto is_down = type == ECORE_EVENT_KEY_DOWN;
63+ bool is_down = type == ECORE_EVENT_KEY_DOWN;
4264
43- if (self-> engine_ -> renderer ()->GetWindowId () != key ->window ) {
65+ if (engine-> renderer ()->GetWindowId () != event ->window ) {
4466 return ECORE_CALLBACK_PASS_ON;
4567 }
4668
4769 if (is_down) {
48- FT_LOG (Info) << " Key pressed: " << key->key << " (" << key->keycode << " )" ;
70+ FT_LOG (Info) << " Key symbol: " << event->key << " , code: 0x" << std::setw (8 )
71+ << std::setfill (' 0' ) << std::right << std::hex
72+ << event->keycode ;
4973 }
5074
5175 if (engine->text_input_channel ()) {
52- if (engine->text_input_channel ()->SendKeyEvent (key , is_down)) {
53- return ECORE_CALLBACK_PASS_ON ;
76+ if (engine->text_input_channel ()->SendKeyEvent (event , is_down)) {
77+ return ECORE_CALLBACK_DONE ;
5478 }
5579 }
5680
5781 if (engine->platform_view_channel ()) {
58- engine->platform_view_channel ()->SendKeyEvent (key , is_down);
82+ engine->platform_view_channel ()->SendKeyEvent (event , is_down);
5983 }
6084
6185 if (engine->key_event_channel ()) {
6286 engine->key_event_channel ()->SendKeyEvent (
63- key , is_down,
64- [engine, keyname = std::string (key-> keyname ), is_down](bool handled) {
87+ event , is_down,
88+ [engine, symbol = std::string (event-> key ), is_down](bool handled) {
6589 if (handled) {
6690 return ;
6791 }
68- if (keyname == kBackKey && !is_down) {
92+ if (symbol == kBackKey && !is_down) {
6993 if (engine->navigation_channel ()) {
7094 engine->navigation_channel ()->PopRoute ();
7195 }
72- } else if (keyname == kExitKey && !is_down) {
73- #ifndef __X64_SHELL__
96+ } else if (symbol == kExitKey && !is_down) {
97+ #ifdef __X64_SHELL__
98+ exit (EXIT_SUCCESS);
99+ #else
74100 ui_app_exit ();
75101#endif
76102 }
77103 });
78104 }
79- return ECORE_CALLBACK_PASS_ON ;
105+ return ECORE_CALLBACK_DONE ;
80106}
81107
82108} // namespace flutter
0 commit comments