#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;
__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);
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)
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();
{
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;
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;
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;
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