aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/protocols/PrimarySelection.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocols/PrimarySelection.hpp')
-rw-r--r--src/protocols/PrimarySelection.hpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/protocols/PrimarySelection.hpp b/src/protocols/PrimarySelection.hpp
new file mode 100644
index 00000000..c33a00e8
--- /dev/null
+++ b/src/protocols/PrimarySelection.hpp
@@ -0,0 +1,127 @@
+#pragma once
+
+#include <memory>
+#include <vector>
+#include <cstdint>
+#include "WaylandProtocol.hpp"
+#include "primary-selection-unstable-v1.hpp"
+#include "types/DataDevice.hpp"
+
+class CPrimarySelectionOffer;
+class CPrimarySelectionSource;
+class CPrimarySelectionDevice;
+class CPrimarySelectionManager;
+
+class CPrimarySelectionOffer {
+ public:
+ CPrimarySelectionOffer(SP<CZwpPrimarySelectionOfferV1> resource_, SP<IDataSource> source_);
+
+ bool good();
+ void sendData();
+
+ bool dead = false;
+
+ WP<IDataSource> source;
+
+ private:
+ SP<CZwpPrimarySelectionOfferV1> resource;
+
+ friend class CPrimarySelectionDevice;
+};
+
+class CPrimarySelectionSource : public IDataSource {
+ public:
+ CPrimarySelectionSource(SP<CZwpPrimarySelectionSourceV1> resource_, SP<CPrimarySelectionDevice> device_);
+ ~CPrimarySelectionSource();
+
+ static SP<CPrimarySelectionSource> fromResource(wl_resource*);
+
+ bool good();
+
+ virtual std::vector<std::string> mimes();
+ virtual void send(const std::string& mime, uint32_t fd);
+ virtual void accepted(const std::string& mime);
+ virtual void cancelled();
+ virtual void error(uint32_t code, const std::string& msg);
+
+ std::vector<std::string> mimeTypes;
+ WP<CPrimarySelectionSource> self;
+ WP<CPrimarySelectionDevice> device;
+
+ private:
+ SP<CZwpPrimarySelectionSourceV1> resource;
+};
+
+class CPrimarySelectionDevice {
+ public:
+ CPrimarySelectionDevice(SP<CZwpPrimarySelectionDeviceV1> resource_);
+
+ bool good();
+ wl_client* client();
+
+ void sendDataOffer(SP<CPrimarySelectionOffer> offer);
+ void sendSelection(SP<CPrimarySelectionOffer> selection);
+
+ WP<CPrimarySelectionDevice> self;
+
+ private:
+ SP<CZwpPrimarySelectionDeviceV1> resource;
+ wl_client* pClient = nullptr;
+
+ friend class CPrimarySelectionProtocol;
+};
+
+class CPrimarySelectionManager {
+ public:
+ CPrimarySelectionManager(SP<CZwpPrimarySelectionDeviceManagerV1> resource_);
+
+ bool good();
+
+ WP<CPrimarySelectionDevice> device;
+ std::vector<WP<CPrimarySelectionSource>> sources;
+
+ private:
+ SP<CZwpPrimarySelectionDeviceManagerV1> resource;
+};
+
+class CPrimarySelectionProtocol : public IWaylandProtocol {
+ public:
+ CPrimarySelectionProtocol(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);
+
+ private:
+ void destroyResource(CPrimarySelectionManager* resource);
+ void destroyResource(CPrimarySelectionDevice* resource);
+ void destroyResource(CPrimarySelectionSource* resource);
+ void destroyResource(CPrimarySelectionOffer* resource);
+
+ //
+ std::vector<SP<CPrimarySelectionManager>> m_vManagers;
+ std::vector<SP<CPrimarySelectionDevice>> m_vDevices;
+ std::vector<SP<CPrimarySelectionSource>> m_vSources;
+ std::vector<SP<CPrimarySelectionOffer>> m_vOffers;
+
+ //
+ void setSelection(SP<IDataSource> source);
+ void sendSelectionToDevice(SP<CPrimarySelectionDevice> dev, SP<IDataSource> sel);
+ void updateSelection();
+ void onPointerFocus();
+
+ //
+ SP<CPrimarySelectionDevice> dataDeviceForClient(wl_client*);
+
+ friend class CPrimarySelectionManager;
+ friend class CPrimarySelectionDevice;
+ friend class CPrimarySelectionSource;
+ friend class CPrimarySelectionOffer;
+ friend class CSeatManager;
+
+ struct {
+ CHyprSignalListener onPointerFocusChange;
+ } listeners;
+};
+
+namespace PROTO {
+ inline UP<CPrimarySelectionProtocol> primarySelection;
+};