Hyprland/src/devices/Mouse.cpp

153 lines
4.9 KiB
C++
Raw Normal View History

#include "Mouse.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<CMouse> CMouse::create(SP<Aquamarine::IPointer> mouse) {
SP<CMouse> pMouse = SP<CMouse>(new CMouse(mouse));
pMouse->self = pMouse;
return pMouse;
}
2024-06-20 18:05:35 +02:00
CMouse::CMouse(SP<Aquamarine::IPointer> mouse_) : mouse(mouse_) {
if (!mouse)
return;
2024-06-20 18:05:35 +02:00
listeners.destroy = mouse->events.destroy.registerListener([this](std::any d) {
mouse.reset();
events.destroy.emit();
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.motion = mouse->events.move.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SMoveEvent>(d);
pointerEvents.motion.emit(SMotionEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.delta = E.delta,
.unaccel = E.unaccel,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.motionAbsolute = mouse->events.warp.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SWarpEvent>(d);
pointerEvents.motionAbsolute.emit(SMotionAbsoluteEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.absolute = E.absolute,
.device = self.lock(),
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.button = mouse->events.button.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SButtonEvent>(d);
pointerEvents.button.emit(SButtonEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.button = E.button,
.state = E.pressed ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.axis = mouse->events.axis.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SAxisEvent>(d);
pointerEvents.axis.emit(SAxisEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.source = (wl_pointer_axis_source)E.source,
.axis = (wl_pointer_axis)E.axis,
.relativeDirection = (wl_pointer_axis_relative_direction)E.direction,
.delta = E.delta,
.deltaDiscrete = E.discrete,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.frame = mouse->events.frame.registerListener([this](std::any d) { pointerEvents.frame.emit(); });
2024-06-20 18:05:35 +02:00
listeners.swipeBegin = mouse->events.swipeBegin.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SSwipeBeginEvent>(d);
pointerEvents.swipeBegin.emit(SSwipeBeginEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.fingers = E.fingers,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.swipeEnd = mouse->events.swipeEnd.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SSwipeEndEvent>(d);
pointerEvents.swipeEnd.emit(SSwipeEndEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.cancelled = E.cancelled,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.swipeUpdate = mouse->events.swipeUpdate.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SSwipeUpdateEvent>(d);
pointerEvents.swipeUpdate.emit(SSwipeUpdateEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.fingers = E.fingers,
.delta = E.delta,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.pinchBegin = mouse->events.pinchBegin.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SPinchBeginEvent>(d);
pointerEvents.pinchBegin.emit(SPinchBeginEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.fingers = E.fingers,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.pinchEnd = mouse->events.pinchEnd.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SPinchEndEvent>(d);
pointerEvents.pinchEnd.emit(SPinchEndEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.cancelled = E.cancelled,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.pinchUpdate = mouse->events.pinchUpdate.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SPinchUpdateEvent>(d);
pointerEvents.pinchUpdate.emit(SPinchUpdateEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.fingers = E.fingers,
.delta = E.delta,
.scale = E.scale,
.rotation = E.rotation,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.holdBegin = mouse->events.holdBegin.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SHoldBeginEvent>(d);
pointerEvents.holdBegin.emit(SHoldBeginEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.fingers = E.fingers,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
listeners.holdEnd = mouse->events.holdEnd.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IPointer::SHoldEndEvent>(d);
pointerEvents.holdEnd.emit(SHoldEndEvent{
2024-06-20 18:05:35 +02:00
.timeMs = E.timeMs,
.cancelled = E.cancelled,
});
2024-06-20 18:05:35 +02:00
});
2024-06-20 18:05:35 +02:00
deviceName = mouse->getName();
}
bool CMouse::isVirtual() {
return false;
}
2024-06-20 18:05:35 +02:00
SP<Aquamarine::IPointer> CMouse::aq() {
return mouse.lock();
}