Hyprland/src/protocols/FractionalScale.hpp

65 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
2024-04-20 15:14:54 +02:00
#include <memory>
#include <unordered_map>
#include "WaylandProtocol.hpp"
#include "fractional-scale-v1.hpp"
2024-04-20 15:14:54 +02:00
class CFractionalScaleProtocol;
class CWLSurfaceResource;
2024-04-20 15:14:54 +02:00
class CFractionalScaleAddon {
public:
CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> surf_);
2024-04-20 15:14:54 +02:00
void setScale(const float& scale);
void onSurfaceDestroy();
2024-04-20 15:14:54 +02:00
bool good();
SP<CWLSurfaceResource> surf();
bool operator==(const wl_resource* other) const {
2024-04-20 15:14:54 +02:00
return other == resource->resource();
}
2024-04-20 15:14:54 +02:00
bool operator==(const CFractionalScaleAddon* other) const {
return other->resource == resource;
}
2024-04-20 15:14:54 +02:00
private:
SP<CWpFractionalScaleV1> resource;
float scale = 1.F;
WP<CWLSurfaceResource> surface;
2024-04-20 15:14:54 +02:00
bool surfaceGone = false;
2024-04-20 15:14:54 +02:00
friend class CFractionalScaleProtocol;
};
2024-04-20 15:14:54 +02:00
class CFractionalScaleProtocol : public IWaylandProtocol {
public:
CFractionalScaleProtocol(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 onSurfaceDestroy(SP<CWLSurfaceResource> surf);
void sendScale(SP<CWLSurfaceResource> surf, const float& scale);
private:
void removeAddon(CFractionalScaleAddon*);
void onManagerResourceDestroy(wl_resource* res);
void onGetFractionalScale(CWpFractionalScaleManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surface);
2024-04-20 15:14:54 +02:00
//
std::unordered_map<WP<CWLSurfaceResource>, float> m_mSurfaceScales;
std::unordered_map<WP<CWLSurfaceResource>, UP<CFractionalScaleAddon>> m_mAddons;
std::vector<UP<CWpFractionalScaleManagerV1>> m_vManagers;
friend class CFractionalScaleAddon;
2024-04-20 15:14:54 +02:00
};
2024-04-20 15:14:54 +02:00
namespace PROTO {
inline UP<CFractionalScaleProtocol> fractional;
};