DSInput: Support input events using ecore event 64/241664/1
authorjeon <jhyuni.kang@samsung.com>
Fri, 24 Jul 2020 08:06:46 +0000 (17:06 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 10:04:25 +0000 (19:04 +0900)
Change-Id: Iaf38a9a8f8b6a08953b8947c1522b1bb8d3f159c

src/DSInput/DSInput.cpp
src/DSInput/DSInput.h
src/meson.build

index ba01dfe..a1bf408 100644 (file)
@@ -73,11 +73,40 @@ void DSInputPrivate::PostTouchEvent(int index, int x, int y, DSInputEvent::Type
                pub->touchUp(index, x, y, devIdentifier, devClass);
 }
 
+int DSInput::DS_INPUT_EVENT_KEY_DOWN = 0;
+int DSInput::DS_INPUT_EVENT_KEY_UP = 0;
+int DSInput::DS_INPUT_EVENT_MOUSE_DOWN = 0;
+int DSInput::DS_INPUT_EVENT_MOUSE_MOVE = 0;
+int DSInput::DS_INPUT_EVENT_MOUSE_UP = 0;
+int DSInput::DS_INPUT_EVENT_TOUCH_DOWN = 0;
+int DSInput::DS_INPUT_EVENT_TOUCH_MOVE = 0;
+int DSInput::DS_INPUT_EVENT_TOUCH_UP = 0;
+
+void DSInput::__initiaiize_ecore_event_types()
+{
+       if (!DS_INPUT_EVENT_KEY_DOWN)
+               DS_INPUT_EVENT_KEY_DOWN = ecore_event_type_new();
+       if (!DS_INPUT_EVENT_KEY_UP)
+               DS_INPUT_EVENT_KEY_UP = ecore_event_type_new();
+       if (!DS_INPUT_EVENT_MOUSE_DOWN)
+               DS_INPUT_EVENT_MOUSE_DOWN = ecore_event_type_new();
+       if (!DS_INPUT_EVENT_MOUSE_MOVE)
+               DS_INPUT_EVENT_MOUSE_MOVE = ecore_event_type_new();
+       if (!DS_INPUT_EVENT_MOUSE_UP)
+               DS_INPUT_EVENT_MOUSE_UP = ecore_event_type_new();
+       if (!DS_INPUT_EVENT_TOUCH_DOWN)
+               DS_INPUT_EVENT_TOUCH_DOWN = ecore_event_type_new();
+       if (!DS_INPUT_EVENT_TOUCH_MOVE)
+               DS_INPUT_EVENT_TOUCH_MOVE = ecore_event_type_new();
+       if (!DS_INPUT_EVENT_TOUCH_UP)
+               DS_INPUT_EVENT_TOUCH_UP = ecore_event_type_new();
+}
 
 DSInput::DSInput()
        : DS_INIT_PRIVATE_PTR(DSInput),
          __seat(nullptr)
 {
+       __initiaiize_ecore_event_types();
 }
 
 DSInput::DSInput(DSSeat *seat)
@@ -89,10 +118,17 @@ DSInput::DSInput(DSSeat *seat)
                DSLOG_ERR("DSInput", "DSSeat ptr is required.");
                return;
        }
+
+       __initiaiize_ecore_event_types();
 }
 
 DSInput::~DSInput()
 {
+       for (auto eventHandler : __eventHandlerList)
+       {
+               ecore_event_handler_del(eventHandler);
+       }
+       __eventHandlerList.clear();
 }
 
 void DSInput::init()
@@ -139,44 +175,80 @@ void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::De
        delete device;
 }
 
+DSInputDevice *DSInput::findDevice(std::string devIdentifier, DSInput::DeviceClass devClass)
+{
+       for (auto dev : devList)
+       {
+               if ((dev->getClass() == devClass) && (dev->getIdentifier().compare(devIdentifier) == 0))
+               {
+                       return dev;
+               }
+       }
+       return nullptr;
+}
+
 void DSInput::keyDown(int keycode, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[keyDown] keycode: " << keycode << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[keyDown] keycode: %d, identifier: %d\n", keycode, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputKeyboardEvent *ev = new DSInputKeyboardEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::KeyDownEvent, 0, keycode);
+       ecore_event_add(DS_INPUT_EVENT_KEY_DOWN, (void *)ev, nullptr, nullptr);
 }
 
 void DSInput::keyUp(int keycode, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[keyUp] keycode: " << keycode << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[keyUp] keycode: %d, identifier: %d\n", keycode, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputKeyboardEvent *ev = new DSInputKeyboardEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::KeyUpEvent, 0, keycode);
+       ecore_event_add(DS_INPUT_EVENT_KEY_UP, (void *)ev, nullptr, nullptr);
 }
 
 void DSInput::mouseDown(int button, int x, int y, int z, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[mouseDown] button: " << button << " (" << x << ", " << y << "), " << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[mouseDown] button: %d (%d, %d, %d), identifier: %d\n", button, x, y, z, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputMouseEvent *ev = new DSInputMouseEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::MouseDownEvent, 0, button, x, y, z);
+       ecore_event_add(DS_INPUT_EVENT_MOUSE_DOWN, (void *)ev, nullptr, nullptr);
 }
 
 void DSInput::mouseMove(int button, int x, int y, int z, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[mouseMove] button: " << button << " (" << x << ", " << y << "), " << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[mouseMove] button: %d (%d, %d, %d), identifier: %d\n", button, x, y, z, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputMouseEvent *ev = new DSInputMouseEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::MouseMoveEvent, 0, button, x, y, z);
+       ecore_event_add(DS_INPUT_EVENT_MOUSE_MOVE, (void *)ev, nullptr, nullptr);
 }
 
 void DSInput::mouseUp(int button, int x, int y, int z, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[mouseUp] button: " << button << " (" << x << ", " << y << "), " << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[mouseUp] button: %d (%d, %d, %d), identifier: %d\n", button, x, y, z, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputMouseEvent *ev = new DSInputMouseEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::MouseUpEvent, 0, button, x, y, z);
+       ecore_event_add(DS_INPUT_EVENT_MOUSE_UP, (void *)ev, nullptr, nullptr);
 }
 
 void DSInput::touchDown(int index, int x, int y, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[touchDown] index: " << index << " (" << x << ", " << y << "), " << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[touchDown] index: %d (%d, %d), identifier: %d\n", index, x, y, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputTouchEvent *ev = new DSInputTouchEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::TouchDownEvent, 0, index, x, y);
+       ecore_event_add(DS_INPUT_EVENT_TOUCH_DOWN, (void *)ev, nullptr, nullptr);
 }
 
 void DSInput::touchMove(int index, int x, int y, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[touchMove] index: " << index << " (" << x << ", " << y << "), " << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[touchMove] index: %d (%d, %d), identifier: %d\n", index, x, y, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputTouchEvent *ev = new DSInputTouchEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::TouchMoveEvent, 0, index, x, y);
+       ecore_event_add(DS_INPUT_EVENT_TOUCH_MOVE, (void *)ev, nullptr, nullptr);
 }
 
 void DSInput::touchUp(int index, int x, int y, std::string devIdentifier, DSInput::DeviceClass devClass)
 {
-       std::cout << "[touchUp] index: " << index << " (" << x << ", " << y << "), " << ", identifier: " << devIdentifier << std::endl;
+       DSLOG_DBG("DSInput", "[touchUp] index: %d (%d, %d), identifier: %d\n", index, x, y, devIdentifier);
+       DSInputDevice *device = findDevice(devIdentifier, devClass);
+       DSInputTouchEvent *ev = new DSInputTouchEvent(std::make_shared<DSInputDevice>(*device), DSInputEvent::TouchUpEvent, 0, index, x, y);
+       ecore_event_add(DS_INPUT_EVENT_TOUCH_UP, (void *)ev, nullptr, nullptr);
 }
 
 
@@ -190,36 +262,44 @@ void DSInput::registerCallbackDeviceRemove(DSObject *slot, std::function<void(st
        this->__deviceRemoveSignal.connect(slot, func);
 }
 
-void DSInput::registerCallbackKeyDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackKeyDown(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_KEY_DOWN, func, slot));
 }
 
-void DSInput::registerCallbackKeyUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackKeyUp(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_KEY_UP, func, slot));
 }
 
-void DSInput::registerCallbackMouseDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackMouseDown(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_MOUSE_DOWN, func, slot));
 }
 
-void DSInput::registerCallbackMouseMove(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackMouseMove(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_MOUSE_MOVE, func, slot));
 }
 
-void DSInput::registerCallbackMouseUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackMouseUp(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_MOUSE_UP, func, slot));
 }
 
-void DSInput::registerCallbackTouchDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackTouchDown(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_TOUCH_DOWN, func, slot));
 }
 
-void DSInput::registerCallbackTouchMove(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackTouchMove(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_TOUCH_MOVE, func, slot));
 }
 
-void DSInput::registerCallbackTouchUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+void DSInput::registerCallbackTouchUp(DSObject *slot, Ecore_Event_Handler_Cb func)
 {
+       __eventHandlerList.push_back(ecore_event_handler_add(DS_INPUT_EVENT_TOUCH_UP, func, slot));
 }
 
 
index e796bdc..6f53993 100644 (file)
@@ -51,14 +51,16 @@ public:
 
        void registerCallbackDeviceAdd(DSObject *slot, std::function<void(std::shared_ptr<DSInputDevice>)> func);
        void registerCallbackDeviceRemove(DSObject *slot, std::function<void(std::shared_ptr<DSInputDevice>)> func);
-       void registerCallbackKeyDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
-       void registerCallbackKeyUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
-       void registerCallbackMouseDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
-       void registerCallbackMouseMove(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
-       void registerCallbackMouseUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
-       void registerCallbackTouchDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
-       void registerCallbackTouchMove(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
-       void registerCallbackTouchUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func);
+       void registerCallbackKeyDown(DSObject *slot, Ecore_Event_Handler_Cb func);
+       void registerCallbackKeyUp(DSObject *slot, Ecore_Event_Handler_Cb func);
+       void registerCallbackMouseDown(DSObject *slot, Ecore_Event_Handler_Cb func);
+       void registerCallbackMouseMove(DSObject *slot, Ecore_Event_Handler_Cb func);
+       void registerCallbackMouseUp(DSObject *slot, Ecore_Event_Handler_Cb func);
+       void registerCallbackTouchDown(DSObject *slot, Ecore_Event_Handler_Cb func);
+       void registerCallbackTouchMove(DSObject *slot, Ecore_Event_Handler_Cb func);
+       void registerCallbackTouchUp(DSObject *slot, Ecore_Event_Handler_Cb func);
+
+       DSInputDevice *findDevice(std::string devIdentifier, DSInput::DeviceClass devClass);
 
 private:
        DSSeat* __seat;
@@ -66,6 +68,19 @@ private:
 
        DSSignal<std::shared_ptr<DSInputDevice>> __deviceAddSignal;
        DSSignal<std::shared_ptr<DSInputDevice>> __deviceRemoveSignal;
+
+       std::list<Ecore_Event_Handler*> __eventHandlerList;
+
+       static int DS_INPUT_EVENT_KEY_DOWN;
+       static int DS_INPUT_EVENT_KEY_UP;
+       static int DS_INPUT_EVENT_MOUSE_DOWN;
+       static int DS_INPUT_EVENT_MOUSE_MOVE;
+       static int DS_INPUT_EVENT_MOUSE_UP;
+       static int DS_INPUT_EVENT_TOUCH_DOWN;
+       static int DS_INPUT_EVENT_TOUCH_MOVE;
+       static int DS_INPUT_EVENT_TOUCH_UP;
+
+       void __initiaiize_ecore_event_types();
 };
 
 class DSInputDevice
index f330b60..4c17274 100644 (file)
@@ -140,7 +140,7 @@ tizen_launch_dep = dependency('tizen-launch-server')
 
 tizen_ext_deps = [tizen_ext_dep, text_dep, tizen_launch_dep, tizen_surface_dep]
 tizen_ext_deps = [tizen_ext_deps, xdg_shell_unstable_v6_dep, xdg_shell_dep]
-libds_deps = []
+libds_deps = [ecore_dep]
 
 libds_include_dirs = include_directories(
        '.',
@@ -200,6 +200,6 @@ libds_declared_dep = declare_dependency(
 
 libds_static_declared_dep = declare_dependency(
        link_with : libds_static_lib,
-       dependencies : libds_deps,
+       dependencies : [libds_deps, ecore_dep],
        include_directories : [libds_include_dirs]
        )