DSWaylandServer: add processEvent(), set/getFocus() in DSPointer/DSKeyboard/DSTouch... 47/241747/1
authorSung-Jin Park <sj76.park@samsung.com>
Wed, 5 Aug 2020 11:49:08 +0000 (20:49 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 10:10:02 +0000 (19:10 +0900)
Change-Id: Ie0abbaab240d2c9a8e0a4b3e0c92573d293b55e6
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/DSSeat/DSKeyboard.cpp
src/DSSeat/DSKeyboard.h
src/DSSeat/DSPointer.cpp
src/DSSeat/DSPointer.h
src/DSSeat/DSTouch.cpp
src/DSSeat/DSTouch.h
tests/DSKeyboard-test.cpp [new file with mode: 0644]
tests/DSPointer-test.cpp [new file with mode: 0644]
tests/DSTouch-test.cpp [new file with mode: 0644]
tests/meson.build

index c8ea7a7..36f14cf 100644 (file)
@@ -1,19 +1,80 @@
 #include "DSKeyboard.h"
+#include "DSSeat.h"
+#include "DSWindow.h"
+#include "DSInputEvent.h"
+#include "DSWaylandKeyboard.h"
+#include "DSWaylandSurface.h"
 
 namespace display_server
 {
 
-DSKeyboard::DSKeyboard()
-       : __seat(nullptr)
+DSKeyboard::DSKeyboard(DSSeat *seat)
+       : __seat(seat),
+         __dswlKeyboard(nullptr),
+         __dswlCompositor(nullptr),
+         __kbdFocus(nullptr)
 {
+       if (nullptr == __dswlKeyboard)
+       {
+               //TODO : register slot for monitoring the creation of DSWaylandKeyboard
+               ;
+       }
 }
 
-DSKeyboard::DSKeyboard(DSSeat *seat)
-       : __seat(seat)
+DSKeyboard::DSKeyboard(DSSeat *seat, DSWaylandKeyboard *keyboard)
+       : __seat(seat),
+         __dswlKeyboard(keyboard),
+         __dswlCompositor(nullptr),
+         __kbdFocus(nullptr)
 {
 }
 
 DSKeyboard::~DSKeyboard()
 {}
 
+void DSKeyboard::processEvent(DSInputKeyboardEvent *ev, void *data)
+{
+       //TODO : get kbdFocus and send event to it via DSWaylandKeyboard instance
+
+       if (!__kbdFocus)
+       {
+               DSLOG_ERR("DSKeyboard", "No kbdFocus available.");
+               return;
+       }
+}
+
+void DSKeyboard::setFocus(std::shared_ptr<DSWindow> window)
+{
+       if (!window)
+       {
+               DSLOG_ERR("DSKeyboard", "Given window is INVALID. (window : %p)", window);
+               return;
+       }
+
+       DSWaylandSurface * waylandSurface = window->surface();
+
+       if (!waylandSurface)
+       {
+               DSLOG_ERR("DSKeyboard", "Wayland surface of the given window is INVALID. (window : %p, surface : %p)", window, waylandSurface);
+               return;
+       }
+
+       DSLOG_INF("DSKeyboard", "focus window has been changed. (%p -> %p)", __kbdFocus, window);
+       __kbdFocus = window;
+
+       if (!__dswlKeyboard)
+       {
+               DSLOG_ERR("DSKeyboard", "waylandKeyboard is NOT available !");
+               return;
+       }
+
+       __dswlKeyboard->setFocus(waylandSurface);
+
+}
+
+std::shared_ptr<DSWindow> DSKeyboard::getFocus()
+{
+       return __kbdFocus;
+}
+
 } // namespace display_server
\ No newline at end of file
index db5081e..800326c 100644 (file)
@@ -1,22 +1,37 @@
-#ifndef _DSKEYBOARD_H_
-#define _DSKEYBOARD_H_
+#ifndef __DSKEYBOARD_H__
+#define __DSKEYBOARD_H__
 
-#include <DSSeat.h>
+#include "DSCore.h"
+#include "DSObject.h"
 
 namespace display_server
 {
 
-class DSKeyboard
+class DSSeat;
+class DSWindow;
+class DSInputKeyboardEvent;
+class DSWaylandKeyboard;
+class DSWaylandCompositor;
+
+class DSKeyboard : public DSObject
 {
 public:
-       DSKeyboard();
+       DSKeyboard() = delete;
        DSKeyboard(DSSeat *seat);
+       DSKeyboard(DSSeat *seat, DSWaylandKeyboard *keyboard);
        virtual ~DSKeyboard();
 
+       void processEvent(DSInputKeyboardEvent *ev, void *data);
+       void setFocus(std::shared_ptr<DSWindow> window);
+       std::shared_ptr<DSWindow> getFocus();
+
 private:
        DSSeat *__seat;
+       DSWaylandKeyboard *__dswlKeyboard;
+       DSWaylandCompositor *__dswlCompositor;
+       std::shared_ptr<DSWindow> __kbdFocus;
 };
 
 }
 
-#endif
\ No newline at end of file
+#endif //__DSKEYBOARD_H__
\ No newline at end of file
index 8f243ef..525fd85 100644 (file)
@@ -1,19 +1,74 @@
 #include "DSPointer.h"
+#include "DSSeat.h"
+#include "DSWindow.h"
+#include "DSInputEvent.h"
+#include "DSWaylandPointer.h"
+#include "DSWaylandSurface.h"
 
 namespace display_server
 {
 
-DSPointer::DSPointer()
-       : __seat(nullptr)
+DSPointer::DSPointer(DSSeat *seat)
+       : __seat(seat),
+         __dswlPointer(nullptr),
+         __dswlCompositor(nullptr),
+         __ptrFocus(nullptr)
 {
 }
 
-DSPointer::DSPointer(DSSeat *seat)
-       : __seat(seat)
+DSPointer::DSPointer(DSSeat *seat, DSWaylandPointer *pointer)
+       : __seat(seat),
+         __dswlPointer(pointer),
+         __dswlCompositor(nullptr),
+         __ptrFocus(nullptr)
 {
 }
 
 DSPointer::~DSPointer()
 {}
 
+void DSPointer::processEvent(DSInputMouseEvent *ev, void *data)
+{
+       //TODO : get ptrFocus and send event to it via DSWaylandPointer instance
+
+       if (!__ptrFocus)
+       {
+               DSLOG_ERR("DSPointer", "No ptrFocus available.");
+               return;
+       }
+}
+
+void DSPointer::setFocus(std::shared_ptr<DSWindow> window)
+{
+       if (!window)
+       {
+               DSLOG_ERR("DSPointer", "Given window is INVALID. (window : %p)", window);
+               return;
+       }
+
+       DSWaylandSurface * waylandSurface = window->surface();
+
+       if (!waylandSurface)
+       {
+               DSLOG_ERR("DSPointer", "Wayland surface of the given window is INVALID. (window : %p, surface : %p)", window, waylandSurface);
+               return;
+       }
+
+       DSLOG_INF("DSPointer", "focus window has been changed. (%p -> %p)", __ptrFocus, window);
+       __ptrFocus = window;
+
+       if (!__dswlPointer)
+       {
+               DSLOG_ERR("DSPointer", "waylandPointer is NOT available !");
+               return;
+       }
+
+       __dswlPointer->setFocus(waylandSurface);
+}
+
+std::shared_ptr<DSWindow> DSPointer::getFocus()
+{
+       return __ptrFocus;
+}
+
 } // namespace display_server
\ No newline at end of file
index d5ac041..05e58e5 100644 (file)
@@ -1,22 +1,37 @@
-#ifndef _DSKEYBOARD_H_
-#define _DSPOINTER_H_
+#ifndef __DSPOINTER_H__
+#define __DSPOINTER_H__
 
-#include <DSSeat.h>
+#include "DSCore.h"
+#include "DSObject.h"
 
 namespace display_server
 {
 
-class DSPointer
+class DSSeat;
+class DSWindow;
+class DSInputMouseEvent;
+class DSWaylandPointer;
+class DSWaylandCompositor;
+
+class DSPointer : public DSObject
 {
 public:
-       DSPointer();
+       DSPointer() = delete;
        DSPointer(DSSeat *seat);
+       DSPointer(DSSeat *seat, DSWaylandPointer *pointer);
        virtual ~DSPointer();
 
+       void processEvent(DSInputMouseEvent *ev, void *data);
+       void setFocus(std::shared_ptr<DSWindow> window);
+       std::shared_ptr<DSWindow> getFocus();
+
 private:
        DSSeat *__seat;
+       DSWaylandPointer *__dswlPointer;
+       DSWaylandCompositor *__dswlCompositor;
+       std::shared_ptr<DSWindow> __ptrFocus;
 };
 
 }
 
-#endif
\ No newline at end of file
+#endif //__DSPOINTER_H__
\ No newline at end of file
index 6913f4d..ea72127 100644 (file)
@@ -1,19 +1,73 @@
 #include "DSTouch.h"
+#include "DSSeat.h"
+#include "DSWindow.h"
+#include "DSInputEvent.h"
+#include "DSWaylandTouch.h"
 
 namespace display_server
 {
 
-DSTouch::DSTouch()
-       : __seat(nullptr)
+DSTouch::DSTouch(DSSeat *seat)
+       : __seat(seat),
+         __dswlTouch(nullptr),
+         __dswlCompositor(nullptr),
+         __touchFocus(nullptr)
 {
 }
 
-DSTouch::DSTouch(DSSeat *seat)
-       : __seat(seat)
+DSTouch::DSTouch(DSSeat *seat, DSWaylandTouch *touch)
+       : __seat(seat),
+         __dswlTouch(touch),
+         __dswlCompositor(nullptr),
+         __touchFocus(nullptr)
 {
 }
 
 DSTouch::~DSTouch()
 {}
 
+void DSTouch::processEvent(DSInputTouchEvent *ev, void *data)
+{
+       //TODO : get touchFocus and send event to it via DSWaylandTouch instance
+
+       if (!__touchFocus)
+       {
+               DSLOG_ERR("DSTouch", "No touchFocus available.");
+               return;
+       }
+}
+
+void DSTouch::setFocus(std::shared_ptr<DSWindow> window)
+{
+       if (!window)
+       {
+               DSLOG_ERR("DSTouch", "Given window is INVALID. (window : %p)", window);
+               return;
+       }
+
+       DSWaylandSurface * waylandSurface = window->surface();
+
+       if (!waylandSurface)
+       {
+               DSLOG_ERR("DSTouch", "Wayland surface of the given window is INVALID. (window : %p, surface : %p)", window, waylandSurface);
+               return;
+       }
+
+       DSLOG_INF("DSTouch", "focus window has been changed. (%p -> %p)", __touchFocus, window);
+       __touchFocus = window;
+
+       if (!__dswlTouch)
+       {
+               DSLOG_ERR("DSTouch", "waylandTouch is NOT available !");
+               return;
+       }
+
+       __dswlTouch->setFocus(waylandSurface);
+}
+
+std::shared_ptr<DSWindow> DSTouch::getFocus()
+{
+       return __touchFocus;
+}
+
 } // namespace display_server
\ No newline at end of file
index df3e8f3..61e809f 100644 (file)
@@ -1,22 +1,37 @@
-#ifndef _DSTOUCH_H_
-#define _DSTOUCH_H_
+#ifndef __DSTOUCH_H__
+#define __DSTOUCH_H__
 
-#include <DSSeat.h>
+#include "DSCore.h"
+#include "DSObject.h"
 
 namespace display_server
 {
 
-class DSTouch
+class DSSeat;
+class DSWindow;
+class DSWaylandTouch;
+class DSInputTouchEvent;
+class DSWaylandCompositor;
+
+class DSTouch : public DSObject
 {
 public:
-       DSTouch();
+       DSTouch() = delete;
        DSTouch(DSSeat *seat);
+       DSTouch(DSSeat *seat, DSWaylandTouch *touch);
        virtual ~DSTouch();
 
+       void processEvent(DSInputTouchEvent *ev, void *data);
+       void setFocus(std::shared_ptr<DSWindow> window);
+       std::shared_ptr<DSWindow> getFocus();
+
 private:
        DSSeat *__seat;
+       DSWaylandTouch *__dswlTouch;
+       DSWaylandCompositor *__dswlCompositor;
+       std::shared_ptr<DSWindow> __touchFocus;
 };
 
 }
 
-#endif
\ No newline at end of file
+#endif //__DSTOUCH_H__
\ No newline at end of file
diff --git a/tests/DSKeyboard-test.cpp b/tests/DSKeyboard-test.cpp
new file mode 100644 (file)
index 0000000..0db9a36
--- /dev/null
@@ -0,0 +1,84 @@
+#include "libds-tests.h"
+#include "DSKeyboard.h"
+#include "DSSeat.h"
+#include "DSWaylandKeyboard.h"
+#include "DSWaylandSeat.h"
+#include "DSWaylandCompositor.h"
+#include "DSWindow.h"
+
+using namespace display_server;
+
+class DSKeyboardTest : public ::testing::Test
+{
+public:
+       void SetUp(void) override
+       {
+               setenv("XDG_RUNTIME_DIR", "/run", 1);
+       }
+       void TearDown(void) override
+       {
+               unsetenv("XDG_RUNTIME_DIR");
+       }
+};
+
+TEST_F(DSKeyboardTest, NewDSKeyboardWithDSSeat)
+{
+       auto seat = new DSSeat();
+       EXPECT_TRUE(seat != nullptr);
+
+       if (seat)
+       {
+               auto keyboard = new DSKeyboard(seat);
+               EXPECT_TRUE(keyboard != nullptr);
+       }
+}
+
+TEST_F(DSKeyboardTest, NewDSKeyboardWithDSWaylandKeyboard)
+{
+       auto waylandCompositor = DSWaylandCompositor::getInstance();
+       EXPECT_TRUE(waylandCompositor != nullptr);
+
+       if (waylandCompositor)
+       {
+               auto seat = new DSSeat();
+               EXPECT_TRUE(seat != nullptr);
+
+               auto waylandSeat = new DSWaylandSeat(waylandCompositor, DSWaylandSeat::capAll);
+               EXPECT_TRUE(waylandSeat != nullptr);
+
+               if (seat && waylandSeat)
+               {
+                       auto waylandKeyboard = new DSWaylandKeyboard(waylandSeat);
+                       EXPECT_TRUE(waylandKeyboard != nullptr);
+
+                       if (waylandKeyboard)
+                       {
+                               auto keyboard = new DSKeyboard(seat, waylandKeyboard);
+                               EXPECT_TRUE(keyboard != nullptr);
+                       }
+               }
+
+               DSWaylandCompositor::releaseInstance();
+       }
+
+}
+TEST_F(DSKeyboardTest, BasicMethods)
+{
+       auto seat = new DSSeat();
+        EXPECT_TRUE(seat != nullptr);
+
+       auto window = std::make_shared<DSWindow>();
+       EXPECT_TRUE(window != nullptr);
+
+       if (seat && window)
+       {
+               auto keyboard = new DSKeyboard(seat);
+               EXPECT_TRUE(keyboard != nullptr);
+
+               if (keyboard)
+               {
+                       keyboard->setFocus(window);
+                       EXPECT_TRUE(window == keyboard->getFocus());
+               }
+       }
+}
diff --git a/tests/DSPointer-test.cpp b/tests/DSPointer-test.cpp
new file mode 100644 (file)
index 0000000..b6be57d
--- /dev/null
@@ -0,0 +1,84 @@
+#include "libds-tests.h"
+#include "DSPointer.h"
+#include "DSSeat.h"
+#include "DSWaylandPointer.h"
+#include "DSWaylandSeat.h"
+#include "DSWaylandCompositor.h"
+#include "DSWindow.h"
+
+using namespace display_server;
+
+class DSPointerTest : public ::testing::Test
+{
+public:
+       void SetUp(void) override
+       {
+               setenv("XDG_RUNTIME_DIR", "/run", 1);
+       }
+       void TearDown(void) override
+       {
+               unsetenv("XDG_RUNTIME_DIR");
+       }
+};
+
+TEST_F(DSPointerTest, NewDSPointerWithDSSeat)
+{
+       auto seat = new DSSeat();
+       EXPECT_TRUE(seat != nullptr);
+
+       if (seat)
+       {
+               auto pointer = new DSPointer(seat);
+               EXPECT_TRUE(pointer != nullptr);
+       }
+}
+
+TEST_F(DSPointerTest, NewDSPointerWithDSWaylandPointer)
+{
+       auto waylandCompositor = DSWaylandCompositor::getInstance();
+       EXPECT_TRUE(waylandCompositor != nullptr);
+
+       if (waylandCompositor)
+       {
+               auto seat = new DSSeat();
+               EXPECT_TRUE(seat != nullptr);
+
+               auto waylandSeat = new DSWaylandSeat(waylandCompositor, DSWaylandSeat::capAll);
+               EXPECT_TRUE(waylandSeat != nullptr);
+
+               if (seat && waylandSeat)
+               {
+                       auto waylandPointer = new DSWaylandPointer(waylandSeat);
+                       EXPECT_TRUE(waylandPointer != nullptr);
+
+                       if (waylandPointer)
+                       {
+                               auto pointer = new DSPointer(seat, waylandPointer);
+                               EXPECT_TRUE(pointer != nullptr);
+                       }
+               }
+
+               DSWaylandCompositor::releaseInstance();
+       }
+
+}
+TEST_F(DSPointerTest, BasicMethods)
+{
+       auto seat = new DSSeat();
+        EXPECT_TRUE(seat != nullptr);
+
+       auto window = std::make_shared<DSWindow>();
+       EXPECT_TRUE(window != nullptr);
+
+       if (seat && window)
+       {
+               auto pointer = new DSPointer(seat);
+               EXPECT_TRUE(pointer != nullptr);
+
+               if (pointer)
+               {
+                       pointer->setFocus(window);
+                       EXPECT_TRUE(window == pointer->getFocus());
+               }
+       }
+}
diff --git a/tests/DSTouch-test.cpp b/tests/DSTouch-test.cpp
new file mode 100644 (file)
index 0000000..56b4b1a
--- /dev/null
@@ -0,0 +1,84 @@
+#include "libds-tests.h"
+#include "DSTouch.h"
+#include "DSSeat.h"
+#include "DSWaylandTouch.h"
+#include "DSWaylandSeat.h"
+#include "DSWaylandCompositor.h"
+#include "DSWindow.h"
+
+using namespace display_server;
+
+class DSTouchTest : public ::testing::Test
+{
+public:
+       void SetUp(void) override
+       {
+               setenv("XDG_RUNTIME_DIR", "/run", 1);
+       }
+       void TearDown(void) override
+       {
+               unsetenv("XDG_RUNTIME_DIR");
+       }
+};
+
+TEST_F(DSTouchTest, NewDSTouchWithDSSeat)
+{
+       auto seat = new DSSeat();
+       EXPECT_TRUE(seat != nullptr);
+
+       if (seat)
+       {
+               auto touch = new DSTouch(seat);
+               EXPECT_TRUE(touch != nullptr);
+       }
+}
+
+TEST_F(DSTouchTest, NewDSTouchWithDSWaylandTouch)
+{
+       auto waylandCompositor = DSWaylandCompositor::getInstance();
+       EXPECT_TRUE(waylandCompositor != nullptr);
+
+       if (waylandCompositor)
+       {
+               auto seat = new DSSeat();
+               EXPECT_TRUE(seat != nullptr);
+
+               auto waylandSeat = new DSWaylandSeat(waylandCompositor, DSWaylandSeat::capAll);
+               EXPECT_TRUE(waylandSeat != nullptr);
+
+               if (seat && waylandSeat)
+               {
+                       auto waylandTouch = new DSWaylandTouch(waylandSeat);
+                       EXPECT_TRUE(waylandTouch != nullptr);
+
+                       if (waylandTouch)
+                       {
+                               auto touch = new DSTouch(seat, waylandTouch);
+                               EXPECT_TRUE(touch != nullptr);
+                       }
+               }
+
+               DSWaylandCompositor::releaseInstance();
+       }
+
+}
+TEST_F(DSTouchTest, BasicMethods)
+{
+       auto seat = new DSSeat();
+        EXPECT_TRUE(seat != nullptr);
+
+       auto window = std::make_shared<DSWindow>();
+       EXPECT_TRUE(window != nullptr);
+
+       if (seat && window)
+       {
+               auto touch = new DSTouch(seat);
+               EXPECT_TRUE(touch != nullptr);
+
+               if (touch)
+               {
+                       touch->setFocus(window);
+                       EXPECT_TRUE(window == touch->getFocus());
+               }
+       }
+}
index 6f427ed..b97f3d4 100644 (file)
@@ -48,6 +48,9 @@ libds_tests_srcs = [
        'DSWaylandInputPanel-test.cpp',
        'DSWaylandInputPanelSurface-test.cpp',
        'DSXkb-test.cpp',
+       'DSPointer-test.cpp',
+       'DSKeyboard-test.cpp',
+       'DSTouch-test.cpp',
        ]
 
 gmock_dep = dependency('gmock', method : 'pkg-config')