2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include "DSPointer.h"
27 #include "DSInputEvent.h"
28 #include "DSWaylandPointer.h"
29 #include "DSWaylandSurface.h"
32 namespace display_server
35 DSPointer::DSPointer(DSSeat *seat)
37 __dswlPointer(nullptr),
38 __dswlCompositor(nullptr),
43 DSPointer::DSPointer(DSSeat *seat, DSWaylandPointer *pointer)
45 __dswlPointer(pointer),
46 __dswlCompositor(nullptr),
51 DSPointer::~DSPointer()
54 void DSPointer::processEvent(DSInputMouseEvent *ev, void *data)
56 //TODO : get ptrFocus and send event to it via DSWaylandPointer instance
60 DSLOG_ERR("DSPointer", "No ptrFocus available.");
64 if (ev->getType() == DSInputEvent::MouseInEvent)
66 DSLOG_DBG("DSTouch", "[mouseIn] devicename: %s, timestamp: %u\n",
67 ev->getDevice()->getName().c_str(), ev->getTimestamp());
68 mouseIn(ev->getX(), ev->getY());
70 else if (ev->getType() == DSInputEvent::MouseOutEvent)
72 DSLOG_DBG("DSTouch", "[mouseOut] devicename: %s, timestamp: %u\n",
73 ev->getDevice()->getName().c_str(), ev->getTimestamp());
76 else if (ev->getType() == DSInputEvent::MouseDownEvent)
78 DSLOG_DBG("DSTouch", "[MouseDown] devicename: %s, timestamp: %u\n",
79 ev->getDevice()->getName().c_str(), ev->getTimestamp());
80 mouseDown(ev->getButton());
82 else if (ev->getType() == DSInputEvent::MouseMoveEvent)
84 DSLOG_DBG("DSTouch", "[mouseMove] devicename: %s, timestamp: %u\n",
85 ev->getDevice()->getName().c_str(), ev->getTimestamp());
86 mouseMove(ev->getX(), ev->getY());
88 else if (ev->getType() == DSInputEvent::MouseUpEvent)
90 DSLOG_DBG("DSTouch", "[mouseUp] devicename: %s, timestamp: %u\n",
91 ev->getDevice()->getName().c_str(), ev->getTimestamp());
92 mouseUp(ev->getButton());
96 DSLOG_INF("DSPointer", "Event type %d won't be handled right now.", ev->getType());
101 void DSPointer::mouseDown(uint32_t button)
105 __dswlPointer->sendButtonDown(button);
109 void DSPointer::mouseUp(uint32_t button)
113 __dswlPointer->sendButtonUp(button);
117 void DSPointer::mouseMove(int x, int y)
121 __dswlPointer->sendMotion(x, y);
125 void DSPointer::mouseIn(int x, int y)
129 __dswlPointer->sendEnter(x, y);
133 void DSPointer::mouseOut()
137 __dswlPointer->sendLeave();
141 void DSPointer::setFocus(std::shared_ptr<DSWindow> window)
145 DSLOG_ERR("DSPointer", "__ptrFocus has been changed (%p -> %p)", __ptrFocus, window);
148 __dswlPointer->setFocus(nullptr);
152 DSWaylandSurface * waylandSurface = window->surface();
156 DSLOG_ERR("DSPointer", "Wayland surface of the given window is INVALID. (window : %p, surface : %p)", window, waylandSurface);
160 DSLOG_INF("DSPointer", "focus window has been changed. (%p -> %p)", __ptrFocus, window);
165 DSLOG_ERR("DSPointer", "waylandPointer is NOT available !");
169 __dswlPointer->setFocus(waylandSurface);
172 void DSPointer::resetFocus()
176 __ptrFocus = nullptr;
177 DSLOG_INF("DSPointer", "ptrFocus has been reset.");
181 __dswlPointer->resetFocus();
184 std::shared_ptr<DSWindow> DSPointer::getFocus()
189 } // namespace display_server