From 84e8d1810d57b65a0bc3b5ac2998bc023df880f4 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 6 May 2024 02:15:26 +0100 Subject: Tablet: move to new impl Ring and strip are not implemented. Will I implement this? God fucking knows. Nobody seems to have that anyways. --- src/protocols/Tablet.hpp | 236 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 src/protocols/Tablet.hpp (limited to 'src/protocols/Tablet.hpp') diff --git a/src/protocols/Tablet.hpp b/src/protocols/Tablet.hpp new file mode 100644 index 00000000..74a45c63 --- /dev/null +++ b/src/protocols/Tablet.hpp @@ -0,0 +1,236 @@ +#pragma once + +#include +#include +#include +#include "WaylandProtocol.hpp" +#include "tablet-v2.hpp" +#include "../helpers/Vector2D.hpp" + +class CTablet; +class CTabletTool; +class CTabletPad; +class CEventLoopTimer; +class CTabletSeat; + +class CTabletPadStripV2Resource { + public: + CTabletPadStripV2Resource(SP resource_, uint32_t id); + + bool good(); + + uint32_t id = 0; + + private: + SP resource; + + friend class CTabletSeat; + friend class CTabletPadGroupV2Resource; + friend class CTabletV2Protocol; +}; + +class CTabletPadRingV2Resource { + public: + CTabletPadRingV2Resource(SP resource_, uint32_t id); + + bool good(); + + uint32_t id = 0; + + private: + SP resource; + + friend class CTabletSeat; + friend class CTabletPadGroupV2Resource; + friend class CTabletV2Protocol; +}; + +class CTabletPadGroupV2Resource { + public: + CTabletPadGroupV2Resource(SP resource_, size_t idx); + + bool good(); + void sendData(SP pad, wlr_tablet_pad_group* group); + + std::vector> rings; + std::vector> strips; + + size_t idx = 0; + + private: + SP resource; + + friend class CTabletSeat; + friend class CTabletPadV2Resource; + friend class CTabletV2Protocol; +}; + +class CTabletPadV2Resource { + public: + CTabletPadV2Resource(SP resource_, SP pad_, SP seat_); + + bool good(); + void sendData(); + + std::vector> groups; + + WP pad; + WP seat; + + bool inert = false; // removed was sent + + private: + SP resource; + + void createGroup(wlr_tablet_pad_group* group, size_t idx); + + friend class CTabletSeat; + friend class CTabletV2Protocol; +}; + +class CTabletV2Resource { + public: + CTabletV2Resource(SP resource_, SP tablet_, SP seat_); + + bool good(); + void sendData(); + + WP tablet; + WP seat; + + bool inert = false; // removed was sent + + private: + SP resource; + + friend class CTabletSeat; + friend class CTabletV2Protocol; +}; + +class CTabletToolV2Resource { + public: + CTabletToolV2Resource(SP resource_, SP tool_, SP seat_); + ~CTabletToolV2Resource(); + + bool good(); + void sendData(); + void queueFrame(); + void sendFrame(bool removeSource = true); + + bool current = false; + wlr_surface* lastSurf = nullptr; // READ-ONLY + + WP tool; + WP seat; + wl_event_source* frameSource = nullptr; + + bool inert = false; // removed was sent + + private: + SP resource; + + friend class CTabletSeat; + friend class CTabletV2Protocol; +}; + +class CTabletSeat { + public: + CTabletSeat(SP resource_); + + bool good(); + void sendData(); + + std::vector> tools; + std::vector> pads; + std::vector> tablets; + + void sendTool(SP tool); + void sendPad(SP pad); + void sendTablet(SP tablet); + + private: + SP resource; + WP self; + + friend class CTabletV2Protocol; +}; + +class CTabletV2Protocol : public IWaylandProtocol { + public: + CTabletV2Protocol(const wl_interface* iface, const int& ver, const std::string& name); + + virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); + + void registerDevice(SP tablet); + void registerDevice(SP tool); + void registerDevice(SP pad); + + void unregisterDevice(SP tablet); + void unregisterDevice(SP tool); + void unregisterDevice(SP pad); + + void recheckRegisteredDevices(); + + // Tablet tool events + void pressure(SP tool, double value); + void distance(SP tool, double value); + void rotation(SP tool, double value); + void slider(SP tool, double value); + void wheel(SP tool, double value); + void tilt(SP tool, const Vector2D& value); + void up(SP tool); + void down(SP tool); + void proximityIn(SP tool, SP tablet, wlr_surface* surf); + void proximityOut(SP tool); + void buttonTool(SP tool, uint32_t button, uint32_t state); + void motion(SP tool, const Vector2D& value); + + // Tablet pad events + void mode(SP pad, uint32_t group, uint32_t mode, uint32_t timeMs); + void buttonPad(SP pad, uint32_t button, uint32_t timeMs, uint32_t state); + void strip(SP pad, uint32_t strip, double position, bool finger, uint32_t timeMs); + void ring(SP pad, uint32_t ring, double position, bool finger, uint32_t timeMs); + + private: + void onManagerResourceDestroy(wl_resource* res); + void destroyResource(CTabletSeat* resource); + void destroyResource(CTabletToolV2Resource* resource); + void destroyResource(CTabletV2Resource* resource); + void destroyResource(CTabletPadV2Resource* resource); + void destroyResource(CTabletPadGroupV2Resource* resource); + void destroyResource(CTabletPadRingV2Resource* resource); + void destroyResource(CTabletPadStripV2Resource* resource); + void onGetSeat(CZwpTabletManagerV2* pMgr, uint32_t id, wl_resource* seat); + + // + std::vector> m_vManagers; + std::vector> m_vSeats; + std::vector> m_vTools; + std::vector> m_vTablets; + std::vector> m_vPads; + std::vector> m_vGroups; + std::vector> m_vRings; + std::vector> m_vStrips; + + // registered + std::vector> tablets; + std::vector> tools; + std::vector> pads; + + // FIXME: rings and strips are broken, I don't understand how this shit works. + // It's 2am. + SP ringForID(SP pad, uint32_t id); + SP stripForID(SP pad, uint32_t id); + + friend class CTabletSeat; + friend class CTabletToolV2Resource; + friend class CTabletV2Resource; + friend class CTabletPadV2Resource; + friend class CTabletPadGroupV2Resource; + friend class CTabletPadRingV2Resource; + friend class CTabletPadStripV2Resource; +}; + +namespace PROTO { + inline UP tablet; +}; -- cgit v1.2.3