Hyprland/src/devices/TouchDevice.cpp

73 lines
2 KiB
C++
Raw Normal View History

#include "TouchDevice.hpp"
#include "../defines.hpp"
2024-06-20 18:05:35 +02:00
#include <aquamarine/input/Input.hpp>
2024-06-20 18:05:35 +02:00
SP<CTouchDevice> CTouchDevice::create(SP<Aquamarine::ITouch> touch) {
SP<CTouchDevice> pTouch = SP<CTouchDevice>(new CTouchDevice(touch));
pTouch->self = pTouch;
return pTouch;
}
2024-06-20 18:05:35 +02:00
CTouchDevice::CTouchDevice(SP<Aquamarine::ITouch> touch_) : touch(touch_) {
if (!touch)
return;
2024-06-20 18:05:35 +02:00
listeners.destroy = touch->events.destroy.registerListener([this](std::any d) {
events.destroy.emit();
2024-06-20 18:05:35 +02:00
touch.reset();
});
2024-06-20 18:05:35 +02:00
listeners.down = touch->events.down.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::ITouch::SDownEvent>(d);
touchEvents.down.emit(SDownEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.touchID = E.touchID,
.pos = E.pos,
.device = self.lock(),
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.up = touch->events.up.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::ITouch::SUpEvent>(d);
touchEvents.up.emit(SUpEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.touchID = E.touchID,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.motion = touch->events.move.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::ITouch::SMotionEvent>(d);
touchEvents.motion.emit(SMotionEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.touchID = E.touchID,
.pos = E.pos,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.cancel = touch->events.cancel.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::ITouch::SCancelEvent>(d);
touchEvents.cancel.emit(SCancelEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.touchID = E.touchID,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.frame = touch->events.frame.registerListener([this](std::any d) { touchEvents.frame.emit(); });
2024-06-20 18:05:35 +02:00
deviceName = touch->getName();
}
bool CTouchDevice::isVirtual() {
return false;
}
2024-06-20 18:05:35 +02:00
SP<Aquamarine::ITouch> CTouchDevice::aq() {
return touch.lock();
}