DSInput: Get input events using DSLibinput 56/241656/1
authorjeon <jhyuni.kang@samsung.com>
Wed, 22 Jul 2020 10:53:14 +0000 (19:53 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 09:54:26 +0000 (18:54 +0900)
Change-Id: I54e2548a9d676dd65ae96d524a12873168f7a14d

src/DSInput/DSInput.cpp
src/DSInput/DSInput.h
src/DSInput/DSInputEvent.h
src/DSInput/DSInputPrivate.h
src/DSInput/DSLibinput.cpp
src/meson.build

index 28bd088..ba01dfe 100644 (file)
@@ -39,6 +39,41 @@ void DSInputPrivate::PostDeviceRemoveEvent(std::string seat, std::string name, s
        pub->deviceRemove(name, identifier, devClass, DSInput::NoneSubclass);
 }
 
+void DSInputPrivate::PostKeyboardEvent(int keycode, bool pressed, std::string devIdentifier, DSInput::DeviceClass devClass)
+{
+       DS_GET_PUB(DSInput);
+
+       if (pressed)
+               pub->keyDown(keycode, devIdentifier, devClass);
+       else
+               pub->keyUp(keycode, devIdentifier, devClass);
+}
+
+void DSInputPrivate::PostPointerEvent(int button, int x, int y, int z, DSInputEvent::Type type, std::string devIdentifier, DSInput::DeviceClass devClass)
+{
+       DS_GET_PUB(DSInput);
+
+       if (type == DSInputEvent::MouseDownEvent)
+               pub->mouseDown(button, x, y, z, devIdentifier, devClass);
+       else if (type == DSInputEvent::MouseMoveEvent)
+               pub->mouseMove(button, x, y, z, devIdentifier, devClass);
+       else if (type == DSInputEvent::MouseUpEvent)
+               pub->mouseUp(button, x, y, z, devIdentifier, devClass);
+}
+
+void DSInputPrivate::PostTouchEvent(int index, int x, int y, DSInputEvent::Type type, std::string devIdentifier, DSInput::DeviceClass devClass)
+{
+       DS_GET_PUB(DSInput);
+
+       if (type == DSInputEvent::TouchDownEvent)
+               pub->touchDown(index, x, y, devIdentifier, devClass);
+       else if (type == DSInputEvent::TouchMoveEvent)
+               pub->touchMove(index, x, y, devIdentifier, devClass);
+       else if (type == DSInputEvent::TouchUpEvent)
+               pub->touchUp(index, x, y, devIdentifier, devClass);
+}
+
+
 DSInput::DSInput()
        : DS_INIT_PRIVATE_PTR(DSInput),
          __seat(nullptr)
@@ -104,6 +139,47 @@ void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::De
        delete device;
 }
 
+void DSInput::keyDown(int keycode, std::string devIdentifier, DSInput::DeviceClass devClass)
+{
+       std::cout << "[keyDown] keycode: " << keycode << ", identifier: " << devIdentifier << std::endl;
+}
+
+void DSInput::keyUp(int keycode, std::string devIdentifier, DSInput::DeviceClass devClass)
+{
+       std::cout << "[keyUp] keycode: " << keycode << ", identifier: " << devIdentifier << std::endl;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+
 void DSInput::registerCallbackDeviceAdd(DSObject *slot, std::function<void(std::shared_ptr<DSInputDevice>)> func)
 {
        this->__deviceAddSignal.connect(slot, func);
@@ -114,6 +190,38 @@ 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::registerCallbackKeyUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+{
+}
+
+void DSInput::registerCallbackMouseDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+{
+}
+
+void DSInput::registerCallbackMouseMove(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+{
+}
+
+void DSInput::registerCallbackMouseUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+{
+}
+
+void DSInput::registerCallbackTouchDown(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+{
+}
+
+void DSInput::registerCallbackTouchMove(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+{
+}
+
+void DSInput::registerCallbackTouchUp(DSObject *slot, std::function<Eina_Bool(void *,int,void *)> func)
+{
+}
+
 
 DSInputDevice::DSInputDevice()
        : __deviceName(""),
index 26b150b..e796bdc 100644 (file)
@@ -9,6 +9,8 @@
 #include <DSSignal.h>
 #include <functional>
 
+#include <Ecore.h>
+
 namespace display_server
 {
 
@@ -38,9 +40,25 @@ public:
 
        void deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass);
        void deviceRemove(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass);
+       void keyDown(int keycode, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void keyUp(int keycode, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void mouseDown(int button, int x, int y, int z, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void mouseMove(int button, int x, int y, int z, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void mouseUp(int button, int x, int y, int z, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void touchDown(int index, int x, int y, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void touchMove(int index, int x, int y, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void touchUp(int index, int x, int y, std::string devIdentifier, DSInput::DeviceClass devClass);
 
        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);
 
 private:
        DSSeat* __seat;
index a412a83..7a8f75e 100644 (file)
@@ -23,7 +23,7 @@ public:
                MouseWheelEvent,
                MouseHWheelEvent,
                TouchDownEvent,
-               TOuchMoveEvent,
+               TouchMoveEvent,
                TouchUpEvent
        };
 
index 8d566eb..8b95b81 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "DSInput.h"
 #include "DSLibinput.h"
+#include "DSInputEvent.h"
 
 namespace display_server
 {
@@ -21,6 +22,9 @@ public:
 
        void PostDeviceAddEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass);
        void PostDeviceRemoveEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass);
+       void PostKeyboardEvent(int keycode, bool pressed, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void PostPointerEvent(int button, int x, int y, int z, DSInputEvent::Type type, std::string devIdentifier, DSInput::DeviceClass devClass);
+       void PostTouchEvent(int index, int x, int y, DSInputEvent::Type type, std::string devIdentifier, DSInput::DeviceClass devClass);
 
 private:
        DSLibinput *__dsLibinput;
index d766da3..3c07ec6 100644 (file)
@@ -178,14 +178,33 @@ void DSLibinput::__processDeviceRemoveEvent(struct ::libinput_event *event)
        }
 }
 
-void DSLibinput::__processKeyboardKeyEvent(struct ::libinput_event *event)
+void DSLibinput::__processKeyboardKeyEvent(struct:: libinput_event *event)
 {
-       ;
+       struct:: libinput_event_keyboard *keyboard_event = libinput_event_get_keyboard_event(event);
+       int keycode = libinput_event_keyboard_get_key(keyboard_event) + 8;
+       int state = libinput_event_keyboard_get_key_state(keyboard_event);
+       bool pressed;
+       if (state == LIBINPUT_KEY_STATE_PRESSED) pressed = true;
+       else pressed = false;
+
+       struct ::libinput_device *device = libinput_event_get_device(event);
+       std::string identifier = (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       inputPrivate->PostKeyboardEvent(keycode, pressed, identifier, DSInput::KeyboardClass);
 }
 
 void DSLibinput::__processPointerMotionEvent(struct ::libinput_event *event)
 {
-       ;
+       struct:: libinput_event_pointer *pointer_event = libinput_event_get_pointer_event(event);
+       int dx, dy;
+
+       struct ::libinput_device *device = libinput_event_get_device(event);
+       std::string identifier = (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       dx = libinput_event_pointer_get_dx(pointer_event);
+       dy = libinput_event_pointer_get_dy(pointer_event);
+
+       inputPrivate->PostPointerEvent(0, dx, dy, 0, DSInputEvent::MouseMoveEvent, identifier, DSInput::PointerClass);
 }
 
 void DSLibinput::__processPointerMotionAbsoluteEvent(struct ::libinput_event *event)
@@ -195,7 +214,23 @@ void DSLibinput::__processPointerMotionAbsoluteEvent(struct ::libinput_event *ev
 
 void DSLibinput::__processPointerButtonEvent(struct ::libinput_event *event)
 {
-       ;
+       struct:: libinput_event_pointer *pointer_event = libinput_event_get_pointer_event(event);
+       DSInputEvent::Type eventType;
+       int button;
+       int state;
+
+       struct ::libinput_device *device = libinput_event_get_device(event);
+       std::string identifier = (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       button = libinput_event_pointer_get_button(pointer_event);
+       state = libinput_event_pointer_get_button_state(pointer_event);
+
+       if (state)
+               eventType = DSInputEvent::MouseDownEvent;
+       else
+               eventType = DSInputEvent::MouseUpEvent;
+
+       inputPrivate->PostPointerEvent(button, 0, 0, 0, eventType, identifier, DSInput::PointerClass);
 }
 
 void DSLibinput::__processPointerAxisEvent(struct ::libinput_event *event)
@@ -205,17 +240,47 @@ void DSLibinput::__processPointerAxisEvent(struct ::libinput_event *event)
 
 void DSLibinput::__processTouchDownEvent(struct ::libinput_event *event)
 {
-       ;
+       struct:: libinput_event_touch *touch_event = libinput_event_get_touch_event(event);
+       int index, x, y;
+
+       struct ::libinput_device *device = libinput_event_get_device(event);
+       std::string identifier = (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       index = libinput_event_touch_get_slot(touch_event);
+       x = libinput_event_touch_get_x(touch_event);
+       y = libinput_event_touch_get_y(touch_event);
+
+       inputPrivate->PostTouchEvent(index, x, y, DSInputEvent::TouchDownEvent, identifier, DSInput::TouchClass);
 }
 
 void DSLibinput::__processTouchMotionEvent(struct ::libinput_event *event)
 {
-       ;
+       struct:: libinput_event_touch *touch_event = libinput_event_get_touch_event(event);
+       int index, x, y;
+
+       struct ::libinput_device *device = libinput_event_get_device(event);
+       std::string identifier = (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       index = libinput_event_touch_get_slot(touch_event);
+       x = libinput_event_touch_get_x(touch_event);
+       y = libinput_event_touch_get_y(touch_event);
+
+       inputPrivate->PostTouchEvent(index, x, y, DSInputEvent::TouchMoveEvent, identifier, DSInput::TouchClass);
 }
 
 void DSLibinput::__processTouchUpEvent(struct ::libinput_event *event)
 {
-       ;
+       struct:: libinput_event_touch *touch_event = libinput_event_get_touch_event(event);
+       int index, x, y;
+
+       struct ::libinput_device *device = libinput_event_get_device(event);
+       std::string identifier = (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       index = libinput_event_touch_get_slot(touch_event);
+       x = 0;
+       y = 0;
+
+       inputPrivate->PostTouchEvent(index, x, y, DSInputEvent::TouchUpEvent, identifier, DSInput::TouchClass);
 }
 
 void DSLibinput::__processTouchCancelEvent(struct ::libinput_event *event)
index 44d76c5..af01979 100644 (file)
@@ -191,7 +191,7 @@ pkgconfig.generate(
 
 libds_declared_dep = declare_dependency(
        link_with : libds_lib,
-       dependencies : libds_deps,
+       dependencies : [libds_deps, ecore_dep],
        include_directories : [libds_include_dirs]
        )