diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-05-03 22:34:10 +0100 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-05-03 22:40:27 +0100 |
| commit | 1237732b97fcf21a19aed16f2ef966118a3ca2aa (patch) | |
| tree | 15a3a29377af7f0ce3dd428229587e476ce92db3 /src/devices/TouchDevice.cpp | |
| parent | 1d2acbe19355c8640d54a4b6cba225c6f4370c85 (diff) | |
input: Introduce basic hyprland HID classes
Implements an intermediary HID class for mice, keyboards and touch devices, removing the old structs from WLClasses.hpp
Yes, virtual ones are duplicated a bit, but will likely be de-duped once wlr_input_device is not used anymore.
Diffstat (limited to 'src/devices/TouchDevice.cpp')
| -rw-r--r-- | src/devices/TouchDevice.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/devices/TouchDevice.cpp b/src/devices/TouchDevice.cpp new file mode 100644 index 00000000..e8e52dc2 --- /dev/null +++ b/src/devices/TouchDevice.cpp @@ -0,0 +1,85 @@ +#include "TouchDevice.hpp" +#include "../defines.hpp" + +SP<CTouchDevice> CTouchDevice::create(wlr_touch* touch) { + SP<CTouchDevice> pTouch = SP<CTouchDevice>(new CTouchDevice(touch)); + + pTouch->self = pTouch; + + return pTouch; +} + +CTouchDevice::CTouchDevice(wlr_touch* touch_) : touch(touch_) { + if (!touch) + return; + + // clang-format off + hyprListener_destroy.initCallback(&touch->base.events.destroy, [this] (void* owner, void* data) { + events.destroy.emit(); + disconnectCallbacks(); + touch = nullptr; + }, this, "CTouchDevice"); + + hyprListener_down.initCallback(&touch->events.down, [this] (void* owner, void* data) { + auto E = (wlr_touch_down_event*)data; + + touchEvents.down.emit(SDownEvent{ + .timeMs = E->time_msec, + .touchID = E->touch_id, + .pos = {E->x, E->y}, + }); + }, this, "CTouchDevice"); + + hyprListener_up.initCallback(&touch->events.up, [this] (void* owner, void* data) { + auto E = (wlr_touch_up_event*)data; + + touchEvents.up.emit(SUpEvent{ + .timeMs = E->time_msec, + .touchID = E->touch_id + }); + }, this, "CTouchDevice"); + + hyprListener_motion.initCallback(&touch->events.motion, [this] (void* owner, void* data) { + auto E = (wlr_touch_motion_event*)data; + + touchEvents.motion.emit(SMotionEvent{ + .timeMs = E->time_msec, + .touchID = E->touch_id, + .pos = {E->x, E->y}, + }); + }, this, "CTouchDevice"); + + hyprListener_cancel.initCallback(&touch->events.cancel, [this] (void* owner, void* data) { + auto E = (wlr_touch_cancel_event*)data; + + touchEvents.cancel.emit(SCancelEvent{ + .timeMs = E->time_msec, + .touchID = E->touch_id + }); + }, this, "CTouchDevice"); + + hyprListener_frame.initCallback(&touch->events.frame, [this] (void* owner, void* data) { + touchEvents.frame.emit(); + }, this, "CTouchDevice"); + + // clang-format on + + deviceName = touch->base.name ? touch->base.name : "UNKNOWN"; +} + +bool CTouchDevice::isVirtual() { + return false; +} + +wlr_touch* CTouchDevice::wlr() { + return touch; +} + +void CTouchDevice::disconnectCallbacks() { + hyprListener_destroy.removeCallback(); + hyprListener_down.removeCallback(); + hyprListener_up.removeCallback(); + hyprListener_motion.removeCallback(); + hyprListener_cancel.removeCallback(); + hyprListener_frame.removeCallback(); +} |
