DSInputPrivate::~DSInputPrivate()
{
+ if (__dsLibinput) delete __dsLibinput;
+}
+
+void DSInputPrivate::Init()
+{
+ __dsLibinput = new DSLibinput(this);
+}
+
+void DSInputPrivate::PostDeviceAddEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass)
+{
+ DS_GET_PUB(DSInput);
+
+ pub->deviceAdd(name, identifier, devClass, DSInput::NoneSubclass);
+}
+
+void DSInputPrivate::PostDeviceRemoveEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass)
+{
+ DS_GET_PUB(DSInput);
+
+ pub->deviceRemove(name, identifier, devClass, DSInput::NoneSubclass);
}
DSInput::DSInput()
: DS_INIT_PRIVATE_PTR(DSInput)
{
+ DS_GET_PRIV(DSInput);
+
+ priv->Init();
}
DSInput::~DSInput()
{
}
+void DSInput::deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass)
+{
+ DSInputDevice *device = new DSInputDevice(name, identifier, devClass, devSubclass);
+
+ for (auto dev : devList)
+ {
+ if (*dev == *device)
+ {
+ delete device;
+ return;
+ }
+ }
+
+ devList.push_back(device);
+}
+
+void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass)
+{
+ DSInputDevice *device = new DSInputDevice(name, identifier, devClass, devSubclass);
+
+ for (auto dev : devList)
+ {
+ if (*dev == *device)
+ {
+ devList.remove(dev);
+ delete dev;
+ break;
+ }
+ }
+
+ delete device;
+}
+
DSInputDevice::DSInputDevice()
: __deviceName(""),
__deviceIdentifier(""),
{
}
+void DSInputDevice::print()
+{
+ std::cout << "DeviceInfo: " << "name: " << getName() << ", identifier: " << getIdentifier() << ", class: " << getClass() << ", subclass: " << getSubclass() << std::endl;
+}
+
+bool DSInputDevice::operator==(DSInputDevice& device)
+{
+ if ((getName().compare(device.getName()) == 0) &&
+ (getIdentifier().compare(device.getIdentifier()) == 0) &&
+ (getClass() == device.getClass()))
+ {
+ return true;
+ }
+
+ return false;
+}
+
std::string DSInputDevice::getName() const
{
return __deviceName;
{
class DSInputPrivate;
+class DSInputDevice;
class DSInput : public DSObject
{
public:
DSInput();
~DSInput() override;
+
+ 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);
+
+private:
+ std::list<DSInputDevice*> devList;
};
class DSInputDevice
DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass);
~DSInputDevice();
+ void print();
+ bool operator==(DSInputDevice& device);
+
std::string getName() const;
void setName(std::string name);
#define _DSINPUTPRIVATE_H_
#include "DSInput.h"
+#include "DSLibinput.h"
namespace display_server
{
+class DSLibinput;
+
class DSInputPrivate : public DSObjectPrivate
{
DS_PIMPL_USE_PUBLIC(DSInput);
DSInputPrivate(DSInput *p_ptr);
~DSInputPrivate() override;
+ void Init();
+
+ 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);
+
private:
- /* data */
+ DSLibinput *__dsLibinput;
};
}
.close_restricted = DSLibinput::__handleCloseRestricted
};
-DSLibinput::DSLibinput()
+DSLibinput::DSLibinput(DSInputPrivate *p_ptr)
{
+ inputPrivate = p_ptr;
__udev = udev_new();
__libinput = libinput_udev_create_context(&__input_interface, this, __udev);
__fd = libinput_get_fd(__libinput);
__libinput_handler = ecore_main_fd_handler_add(__fd, ECORE_FD_READ, __handleEvents, this, NULL, NULL);
+
+ this->__handleEvents(this, __libinput_handler);
}
DSLibinput::~DSLibinput()
void DSLibinput::__processDeviceAddEvent(struct ::libinput_event *event)
{
- ;
+ struct ::libinput *libinput;
+ struct ::libinput_seat *libinput_seat;
+ struct ::libinput_device *device;
+ std::string seatName, devName, identifier;
+
+ libinput = libinput_event_get_context(event);
+ device = libinput_event_get_device(event);
+ libinput_seat = libinput_device_get_seat(device);
+
+ seatName = libinput_seat_get_logical_name(libinput_seat);
+ devName = libinput_device_get_name(device);
+ identifier= (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
+ {
+ inputPrivate->PostDeviceAddEvent(seatName, devName, identifier, DSInput::KeyboardClass);
+ }
+ else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
+ {
+ inputPrivate->PostDeviceAddEvent(seatName, devName, identifier, DSInput::PointerClass);
+ }
+ else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
+ {
+ inputPrivate->PostDeviceAddEvent(seatName, devName, identifier, DSInput::TouchClass);
+ }
}
void DSLibinput::__processDeviceRemoveEvent(struct ::libinput_event *event)
{
- ;
+ struct ::libinput *libinput;
+ struct ::libinput_seat *libinput_seat;
+ struct ::libinput_device *device;
+ std::string seatName, devName, identifier;
+
+ libinput = libinput_event_get_context(event);
+ device = libinput_event_get_device(event);
+ libinput_seat = libinput_device_get_seat(device);
+
+ seatName = libinput_seat_get_logical_name(libinput_seat);
+ devName = libinput_device_get_name(device);
+ identifier= (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
+ {
+ inputPrivate->PostDeviceRemoveEvent(seatName, devName, identifier, DSInput::KeyboardClass);
+ }
+ else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
+ {
+ inputPrivate->PostDeviceRemoveEvent(seatName, devName, identifier, DSInput::PointerClass);
+ }
+ else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
+ {
+ inputPrivate->PostDeviceRemoveEvent(seatName, devName, identifier, DSInput::TouchClass);
+ }
}
void DSLibinput::__processKeyboardKeyEvent(struct ::libinput_event *event)
#include <libinput.h>
#include <libudev.h>
#include <Ecore.h>
+#include "DSInputPrivate.h"
namespace display_server
{
class DSLibinput
{
public:
- DSLibinput();
+ DSLibinput() = delete;
+ DSLibinput(DSInputPrivate *p_ptr);
~DSLibinput();
private:
+ DSInputPrivate *inputPrivate;
struct ::libinput *__libinput;
udev *__udev;
int __fd;