Hyprland/src/protocols/PrimarySelection.hpp

128 lines
3.8 KiB
C++
Raw Normal View History

#pragma once
#include <vector>
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "primary-selection-unstable-v1.hpp"
#include "types/DataDevice.hpp"
core: begin using CFileDescriptor from hyprutils (#9122) * config: make fd use CFileDescriptor make use of the new hyprutils CFileDescriptor instead of manual FD handling. * hyprctl: make fd use CFileDescriptor make use of the new hyprutils CFileDescriptor instead of manual FD handling. * ikeyboard: make fd use CFileDescriptor make use of the new CFileDescriptor instead of manual FD handling, also in sendKeymap remove dead code, it already early returns if keyboard isnt valid, and dont try to close the FD that ikeyboard owns. * core: make SHMFile functions use CFileDescriptor make SHMFile misc functions use CFileDescriptor and its associated usage in dmabuf and keyboard. * core: make explicit sync use CFileDescriptor begin using CFileDescriptor in explicit sync and its timelines and eglsync usage in opengl, there is still a bit left with manual handling that requires future aquamarine change aswell. * eventmgr: make fd and sockets use CFileDescriptor make use of the hyprutils CFileDescriptor instead of manual FD and socket handling and closing. * eventloopmgr: make timerfd use CFileDescriptor make the timerfd use CFileDescriptor instead of manual fd handling * opengl: make gbm fd use CFileDescriptor make the gbm rendernode fd use CFileDescriptor instead of manual fd handling * core: make selection source/offer use CFileDescriptor make data selection source and offers use CFileDescriptor and its associated use in xwm and protocols * protocols: convert protocols fd to CFileDescriptor make most fd handling use CFileDescriptor in protocols * shm: make SHMPool use CfileDescriptor make SHMPool use CFileDescriptor instead of manual fd handling. * opengl: duplicate fd with CFileDescriptor duplicate fenceFD with CFileDescriptor duplicate instead. * xwayland: make sockets and fds use CFileDescriptor instead of manual opening/closing make sockets and fds use CFileDescriptor * keybindmgr: make sockets and fds use CFileDescriptor make sockets and fds use CFileDescriptor instead of manual handling.
2025-01-30 12:30:12 +01:00
#include <hyprutils/os/FileDescriptor.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();
core: begin using CFileDescriptor from hyprutils (#9122) * config: make fd use CFileDescriptor make use of the new hyprutils CFileDescriptor instead of manual FD handling. * hyprctl: make fd use CFileDescriptor make use of the new hyprutils CFileDescriptor instead of manual FD handling. * ikeyboard: make fd use CFileDescriptor make use of the new CFileDescriptor instead of manual FD handling, also in sendKeymap remove dead code, it already early returns if keyboard isnt valid, and dont try to close the FD that ikeyboard owns. * core: make SHMFile functions use CFileDescriptor make SHMFile misc functions use CFileDescriptor and its associated usage in dmabuf and keyboard. * core: make explicit sync use CFileDescriptor begin using CFileDescriptor in explicit sync and its timelines and eglsync usage in opengl, there is still a bit left with manual handling that requires future aquamarine change aswell. * eventmgr: make fd and sockets use CFileDescriptor make use of the hyprutils CFileDescriptor instead of manual FD and socket handling and closing. * eventloopmgr: make timerfd use CFileDescriptor make the timerfd use CFileDescriptor instead of manual fd handling * opengl: make gbm fd use CFileDescriptor make the gbm rendernode fd use CFileDescriptor instead of manual fd handling * core: make selection source/offer use CFileDescriptor make data selection source and offers use CFileDescriptor and its associated use in xwm and protocols * protocols: convert protocols fd to CFileDescriptor make most fd handling use CFileDescriptor in protocols * shm: make SHMPool use CfileDescriptor make SHMPool use CFileDescriptor instead of manual fd handling. * opengl: duplicate fd with CFileDescriptor duplicate fenceFD with CFileDescriptor duplicate instead. * xwayland: make sockets and fds use CFileDescriptor instead of manual opening/closing make sockets and fds use CFileDescriptor * keybindmgr: make sockets and fds use CFileDescriptor make sockets and fds use CFileDescriptor instead of manual handling.
2025-01-30 12:30:12 +01:00
virtual void send(const std::string& mime, Hyprutils::OS::CFileDescriptor 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;
};