DSSeat: adds basic APIs and implements input event handlers 51/241751/1
authorSung-Jin Park <sj76.park@samsung.com>
Thu, 6 Aug 2020 08:08:31 +0000 (17:08 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 10:10:09 +0000 (19:10 +0900)
Change-Id: I43e118be926a504f3b0fef6f929a9593121fb80a
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/DSSeat/DSSeat.cpp
src/DSSeat/DSSeat.h

index 2a49039..2458ee6 100644 (file)
@@ -6,38 +6,53 @@
 #include "DSWaylandCompositor.h"
 #include "DSInputEvent.h"
 #include "DSXkb.h"
+#include "DSZone.h"
+
+#include "DSPointer.h"
+#include "DSKeyboard.h"
+#include "DSTouch.h"
+#include "DSWaylandPointer.h"
+#include "DSWaylandKeyboard.h"
+#include "DSWaylandTouch.h"
 
 namespace display_server
 {
 
+DSSignal<DSInputKeyboardEvent *> DSSeat::__signalHandleKeyEvent;
+DSSignal<DSInputMouseEvent *> DSSeat::__signalHandlePointerEvent;
+DSSignal<DSInputTouchEvent *> DSSeat::__signalHandleTouchEvent;
 
 DSSeat::DSSeat()
        : __input(nullptr),
-         __keyboard(nullptr),
-         __pointer(nullptr),
-         __touch(nullptr),
          __dswlSeat(nullptr),
          __dswlComp(nullptr),
          __compositor(nullptr),
          __xkb(nullptr),
+         __zone(nullptr),
+         __keyboard(nullptr),
+         __pointer(nullptr),
+         __touch(nullptr),
          __numPointer(0),
          __numKeyboard(0),
-         __numTouch(0)
+         __numTouch(0),
+         __focusWin(nullptr)
 {
 }
 
 DSSeat::DSSeat(DSCompositor *compositor, std::string name)
        : __input(nullptr),
-         __keyboard(nullptr),
-         __pointer(nullptr),
-         __touch(nullptr),
          __dswlSeat(nullptr),
          __dswlComp(nullptr),
          __compositor(compositor),
          __xkb(new DSXkb(this)),
+         __zone(nullptr),
+         __keyboard(nullptr),
+         __pointer(nullptr),
+         __touch(nullptr),
          __numPointer(0),
          __numKeyboard(0),
-         __numTouch(0)
+         __numTouch(0),
+         __focusWin(nullptr)
 {
        if (!compositor)
                return;
@@ -54,6 +69,10 @@ DSSeat::DSSeat(DSCompositor *compositor, std::string name)
        __input = new DSInput(this, __xkb);
        DS_ASSERT(__input != nullptr);
 
+       __signalHandleKeyEvent.connect(this, std::bind(&DSSeat::__onKeyEvent, this, std::placeholders::_1));
+       __signalHandlePointerEvent.connect(this, std::bind(&DSSeat::__onPointerEvent, this, std::placeholders::_1));
+       __signalHandleTouchEvent.connect(this, std::bind(&DSSeat::__onTouchEvent, this, std::placeholders::_1));
+
        __input->registerCallbackDeviceAdd(this, std::bind(&DSSeat::slotDeviceAdd, this, std::placeholders::_1));
        __input->registerCallbackDeviceRemove(this, std::bind(&DSSeat::slotDeviceRemove, this, std::placeholders::_1));
        __input->registerCallbackKeyDown(this, inputEventHandlerKey);
@@ -79,31 +98,71 @@ DSSeat::~DSSeat()
                DSWaylandCompositor::releaseInstance();
 }
 
+bool DSSeat::attachZone(std::shared_ptr<DSZone> zone)
+{
+       DSLOG_INF("DSSeat", "The attached zone has been changed (%p -> %p)", __zone, zone);
+
+       __zone = zone;
+       __zone->registerCallbackWindowCreated(this, std::bind(&DSSeat::__onWindowCreated, this, std::placeholders::_1));
+
+       return true;
+}
+
+std::shared_ptr<DSZone> DSSeat::getZone()
+{
+       return __zone;
+}
+
+bool DSSeat::detachZone()
+{
+       if (!__zone)
+       {
+               DSLOG_ERR("DSSeat", "No Zone is not available !");
+               return false;
+       }
+
+       //__zone->deregisterCallbackWindowCreated(this, std::bind(&DSSeat::__onWindowCreated, this, std::placeholders::_1));
+
+       DSLOG_INF("DSSeat", "Zone(%p) has been detached !", __zone);
+       __zone = nullptr;
+
+       return true;
+}
+
 void DSSeat::slotDeviceAdd(std::shared_ptr<DSInputDevice> device)
 {
-       std::cout << "DSSeat slotDeviceAdd!" << std::endl;
+       DSLOG_INF("DSSeat", "");
        device->print();
 
        uint32_t cap = (uint32_t)__dswlSeat->getCapability();
        bool capNeedUpdate = false;
 
-       if ((device->getClass() == DSInput::PointerClass) && (__numPointer == 0))
+       if ((device->getClass() == DSInput::PointerClass) && (__numPointer++ == 0))
        {
-               __numPointer++;
                cap = cap | DSWaylandSeat::capPointer;
                capNeedUpdate = true;
+
+               DSWaylandPointer *dswlPointer = __dswlSeat->getPointer();
+               __pointer = new DSPointer(this, dswlPointer);
+               DS_ASSERT(__pointer != nullptr);
        }
-       else if ((device->getClass() == DSInput::KeyboardClass) && (__numKeyboard == 0))
+       else if ((device->getClass() == DSInput::KeyboardClass) && (__numKeyboard++ == 0))
        {
-               __numKeyboard++;
                cap = cap | DSWaylandSeat::capKeyboard;
                capNeedUpdate = true;
+
+               DSWaylandKeyboard *dswlKeyboard = __dswlSeat->getKeyboard();
+               __keyboard = new DSKeyboard(this, dswlKeyboard);
+               DS_ASSERT(__keyboard != nullptr);
        }
-       else if ((device->getClass() == DSInput::TouchClass) && (__numTouch == 0))
+       else if ((device->getClass() == DSInput::TouchClass) && (__numTouch++ == 0))
        {
-               __numTouch++;
                cap = cap | DSWaylandSeat::capTouch;
                capNeedUpdate = true;
+
+               DSWaylandTouch *dswlTouch = __dswlSeat->getTouch();
+               __touch = new DSTouch(this, dswlTouch);
+               DS_ASSERT(__touch != nullptr);
        }
 
        if (capNeedUpdate)
@@ -112,7 +171,7 @@ void DSSeat::slotDeviceAdd(std::shared_ptr<DSInputDevice> device)
 
 void DSSeat::slotDeviceRemove(std::shared_ptr<DSInputDevice> device)
 {
-       std::cout << "DSSeat slotDeviceRemove!" << std::endl;
+       DSLOG_INF("DSSeat", "");
        device->print();
 
        uint32_t cap = (uint32_t)__dswlSeat->getCapability();
@@ -122,25 +181,234 @@ void DSSeat::slotDeviceRemove(std::shared_ptr<DSInputDevice> device)
        {
                cap = cap & (~DSWaylandSeat::capPointer);
                capNeedUpdate = true;
+
+               if (__pointer)
+               {
+                       delete __pointer;
+                       __pointer = nullptr;
+               }
        }
        else if ((device->getClass() == DSInput::KeyboardClass) && ((--__numKeyboard) == 0))
        {
                cap = cap & (~DSWaylandSeat::capKeyboard);
                capNeedUpdate = true;
+
+               if (__keyboard)
+               {
+                       delete __keyboard;
+                       __keyboard = nullptr;
+               }
        }
        else if ((device->getClass() == DSInput::TouchClass) && ((--__numTouch) == 0))
        {
                cap = cap & (~DSWaylandSeat::capTouch);
                capNeedUpdate = true;
+
+               if (__touch)
+               {
+                       delete __touch;
+                       __touch = nullptr;
+               }
        }
 
        if (capNeedUpdate)
                __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap);
 }
 
+void DSSeat::addPointer()
+{
+       if (0 < __numPointer)
+       {
+               DSLOG_INF("DSSeat", "Pointer exists already. (num=%d)", __numPointer);
+               __numPointer++;
+               return;
+       }
+
+       __pointer = new DSPointer(this);
+       DS_ASSERT(__pointer != nullptr);
+
+       __numPointer++;
+
+       uint32_t cap = (uint32_t)__dswlSeat->getCapability();
+       cap = cap | DSWaylandSeat::capPointer;
+       __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap);
+}
+
+void DSSeat::addKeyboard()
+{
+       if (0 < __numKeyboard)
+       {
+               DSLOG_INF("DSSeat", "Keyboard exists already. (num=%d)", __numKeyboard);
+               __numKeyboard++;
+               return;
+       }
+
+       __keyboard = new DSKeyboard(this);
+       DS_ASSERT(__keyboard != nullptr);
+
+       __numKeyboard++;
+
+       uint32_t cap = (uint32_t)__dswlSeat->getCapability();
+       cap = cap | DSWaylandSeat::capKeyboard;
+       __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap);
+}
+
+void DSSeat::addTouch()
+{
+       if (0 < __numTouch)
+       {
+               DSLOG_INF("DSSeat", "Touch exists already. (num=%d)", __numTouch);
+               __numTouch++;
+               return;
+       }
+
+       __touch = new DSTouch(this);
+       DS_ASSERT(__touch != nullptr);
+
+       __numTouch++;
+
+       uint32_t cap = (uint32_t)__dswlSeat->getCapability();
+       cap = cap | DSWaylandSeat::capTouch;
+       __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap);
+}
+
+void DSSeat::removePointer()
+{
+       if (0 >= __numPointer)
+       {
+               DSLOG_INF("DSSeat", "No pointer exists already. (num=%d)", __numPointer);
+               return;
+       }
+
+       DS_ASSERT(__pointer != nullptr);
+       --__numPointer;
+
+       if (0 == __numPointer)
+       {
+               uint32_t cap = (uint32_t)__dswlSeat->getCapability();
+               cap = cap & (~DSWaylandSeat::capPointer);
+               __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap);
+
+               delete __pointer;
+               __pointer = nullptr;
+       }
+}
+
+void DSSeat::removeKeyboard()
+{
+       if (0 >= __numKeyboard)
+       {
+               DSLOG_INF("DSSeat", "No keyboard exists already. (num=%d)", __numKeyboard);
+               return;
+       }
+
+       DS_ASSERT(__keyboard != nullptr);
+       --__numKeyboard;
+
+       if (0 == __numKeyboard)
+       {
+               uint32_t cap = (uint32_t)__dswlSeat->getCapability();
+               cap = cap & (~DSWaylandSeat::capKeyboard);
+               __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap);
+
+               delete __keyboard;
+               __keyboard = nullptr;
+       }
+}
+
+void DSSeat::removeTouch()
+{
+       if (0 >= __numTouch)
+       {
+               DSLOG_INF("DSSeat", "No touch exists already. (num=%d)", __numTouch);
+               return;
+       }
+
+       DS_ASSERT(__touch != nullptr);
+       --__numTouch;
+
+       if (0 == __numTouch)
+       {
+               uint32_t cap = (uint32_t)__dswlSeat->getCapability();
+               cap = cap & (~DSWaylandSeat::capTouch);
+               __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap);
+
+               delete __touch;
+               __touch = nullptr;
+       }
+}
+
+std::string DSSeat::getName()
+{
+       return __dswlSeat->getName();
+}
+
+void DSSeat::__onKeyEvent(DSInputKeyboardEvent *event)
+{
+       if (__keyboard == nullptr)
+       {
+               DSLOG_DBG("DSSeat", "No keyboard device exists. Key events will be dropped.");
+               return;
+       }
+
+       __keyboard->processEvent(event, nullptr);
+}
+
+void DSSeat::__onPointerEvent(DSInputMouseEvent *event)
+{
+       if (__pointer == nullptr)
+       {
+               DSLOG_DBG("DSSeat", "No pointer device exists. Mouse events will be dropped.");
+               return;
+       }
+
+       __pointer->processEvent(event, nullptr);
+}
+
+void DSSeat::__onTouchEvent(DSInputTouchEvent *event)
+{
+       if (__touch == nullptr)
+       {
+               DSLOG_DBG("DSSeat", "No touch device exists. Touch events will be dropped.");
+               return;
+       }
+
+       __touch->processEvent(event, nullptr);
+}
+
+void DSSeat::__onWindowCreated(std::shared_ptr<DSWindow> window)
+{
+       DSLOG_INF("DSSeat", "window created : %p", window);
+
+       if (window == nullptr)
+       {
+               DSLOG_ERR("DSSeat", "Invalid window is given.");
+               return;
+       }
+
+       /* Set newly created window as focus window for keyboard/pointer/touch temporarily */
+       /* FIXME when DSWindowShell and DSWMPolicy has been implmented properly */
+       if (__keyboard)
+       {
+               DSLOG_INF("DSSeat", "keyboard focus : %p -> %p", __focusWin, window);
+               __keyboard->setFocus(window);
+       }
+
+       if (__pointer)
+       {
+               DSLOG_INF("DSSeat", "pointer focus : %p -> %p", __focusWin, window);
+               __pointer->setFocus(window);
+       }
+
+       if (__touch)
+       {
+               DSLOG_INF("DSSeat", "touch focus : %p -> %p", __focusWin, window);
+               __touch->setFocus(window);
+       }
+}
+
 Eina_Bool DSSeat::inputEventHandlerKey(void *data, int type, void *event)
 {
-       //DSSeat *seat = static_cast< DSSeat* >(data);
        DSInputKeyboardEvent *ev = static_cast< DSInputKeyboardEvent* >(event);
        std::string typeString;
 
@@ -149,14 +417,15 @@ Eina_Bool DSSeat::inputEventHandlerKey(void *data, int type, void *event)
        else
                typeString = "up";
 
-       DSLOG_DBG("DSSeat", "[key%s] keycode: %d, devicename: %s\n", typeString.c_str(), ev->getKeycode(), ev->getDevice()->getName().c_str());
+       DSLOG_DBG("DSSeat", "[key %s] keycode: %d, devicename: %s\n", typeString.c_str(), ev->getKeycode(), ev->getDevice()->getName().c_str());
+
+       __signalHandleKeyEvent.emit(ev);
 
        return EINA_TRUE;
 }
 
 Eina_Bool DSSeat::inputEventHandlerMouse(void *data, int type, void *event)
 {
-       //DSSeat *seat = static_cast< DSSeat* >(data);
        DSInputMouseEvent *ev = static_cast< DSInputMouseEvent* >(event);
        std::string typeString;
 
@@ -167,14 +436,15 @@ Eina_Bool DSSeat::inputEventHandlerMouse(void *data, int type, void *event)
        else
                typeString = "up";
 
-       DSLOG_DBG("DSSeat", "[mouse%s] button: %d (%d, %d, %d), devicename: %s\n", typeString.c_str(), ev->getButton(), ev->getX(), ev->getY(), ev->getZ(), ev->getDevice()->getName().c_str());
+       DSLOG_DBG("DSSeat", "[mouse %s] button: %d (%d, %d, %d), devicename: %s\n", typeString.c_str(), ev->getButton(), ev->getX(), ev->getY(), ev->getZ(), ev->getDevice()->getName().c_str());
+
+       __signalHandlePointerEvent.emit(ev);
 
        return EINA_TRUE;
 }
 
 Eina_Bool DSSeat::inputEventHandlerTouch(void *data, int type, void *event)
 {
-       //DSSeat *seat = static_cast< DSSeat* >(data);
        DSInputTouchEvent *ev = static_cast< DSInputTouchEvent* >(event);
        std::string typeString;
 
@@ -185,11 +455,12 @@ Eina_Bool DSSeat::inputEventHandlerTouch(void *data, int type, void *event)
        else
                typeString = "up";
 
-       DSLOG_DBG("DSSeat", "[touch%s] index: %d (%d, %d), devicename: %s\n", typeString.c_str(), ev->getIndex(), ev->getX(), ev->getY(), ev->getDevice()->getName().c_str());
+       DSLOG_DBG("DSSeat", "[touch %s] index: %d (%d, %d), devicename: %s\n", typeString.c_str(), ev->getIndex(), ev->getX(), ev->getY(), ev->getDevice()->getName().c_str());
+
+       __signalHandleTouchEvent.emit(ev);
 
        return EINA_TRUE;
 }
 
-
 } // namespace display_server
 
index 5842428..d98f28e 100644 (file)
@@ -1,13 +1,16 @@
 #ifndef _DSSEAT_H_
 #define _DSSEAT_H_
 
-#include <DSInput.h>
+#include "DSCore.h"
+#include "DSObject.h"
+#include "DSSignal.h"
 #include <memory>
 #include <Ecore.h>
 
 namespace display_server
 {
 
+class DSInput;
 class DSKeyboard;
 class DSPointer;
 class DSTouch;
@@ -16,6 +19,11 @@ class DSCompositor;
 class DSWaylandSeat;
 class DSWaylandCompositor;
 class DSXkb;
+class DSZone;
+class DSWindow;
+class DSInputKeyboardEvent;
+class DSInputMouseEvent;
+class DSInputTouchEvent;
 
 class DSSeat : public DSObject
 {
@@ -24,28 +32,57 @@ public:
        DSSeat(DSCompositor *compositor, std::string name);
        virtual ~DSSeat();
 
+       bool attachZone(std::shared_ptr<DSZone> zone);
+       std::shared_ptr<DSZone> getZone();
+       bool detachZone();
+
        void slotDeviceAdd(std::shared_ptr<DSInputDevice> device);
        void slotDeviceRemove(std::shared_ptr<DSInputDevice> device);
 
+       std::string getName();
+
+       void addPointer();
+       void addKeyboard();
+       void addTouch();
+       void removePointer();
+       void removeKeyboard();
+       void removeTouch();
+
 private:
        DSInput *__input;
-       DSKeyboard *__keyboard;
-       DSPointer *__pointer;
-       DSTouch *__touch;
        DSWaylandSeat *__dswlSeat;
        DSWaylandCompositor *__dswlComp;
        DSCompositor *__compositor;
        DSXkb *__xkb;
+       std::shared_ptr<DSZone> __zone;
 
+       DSKeyboard *__keyboard;
+       DSPointer *__pointer;
+       DSTouch *__touch;
        uint32_t __numPointer;
        uint32_t __numKeyboard;
        uint32_t __numTouch;
 
+       std::shared_ptr<DSWindow> __focusWin;
+
+       /* ecore key/mouse/touch event handler */
        static Eina_Bool inputEventHandlerKey(void *data, int type, void *event);
        static Eina_Bool inputEventHandlerMouse(void *data, int type, void *event);
        static Eina_Bool inputEventHandlerTouch(void *data, int type, void *event);
+
+       /* signals */
+       static DSSignal<DSInputKeyboardEvent *> __signalHandleKeyEvent;
+       static DSSignal<DSInputMouseEvent *> __signalHandlePointerEvent;
+       static DSSignal<DSInputTouchEvent *> __signalHandleTouchEvent;
+
+       /* slots */
+       void __onKeyEvent(DSInputKeyboardEvent *event);
+       void __onPointerEvent(DSInputMouseEvent *event);
+       void __onTouchEvent(DSInputTouchEvent *event);
+       void __onWindowCreated(std::shared_ptr<DSWindow> window);
+
 };
 
 }
 
-#endif
\ No newline at end of file
+#endif