Hyprland/src/protocols/FractionalScale.hpp

68 lines
2 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;
2024-04-20 15:14:54 +02:00
class CFractionalScaleAddon {
public:
2024-04-20 15:14:54 +02:00
CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, wlr_surface* surf_);
void setScale(const float& scale);
void onSurfaceDestroy();
bool good();
2024-04-20 15:14:54 +02:00
wlr_surface* surf();
2024-04-20 15:14:54 +02:00
bool operator==(const wl_resource* other) const {
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;
wlr_surface* surface = nullptr;
bool surfaceGone = false;
2024-04-20 15:14:54 +02:00
friend class CFractionalScaleProtocol;
};
2024-04-20 15:14:54 +02:00
struct SSurfaceListener {
DYNLISTENER(surfaceDestroy);
};
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 onManagerResourceDestroy(wl_resource* res);
void onGetFractionalScale(CWpFractionalScaleManagerV1* pMgr, uint32_t id, wlr_surface* surface);
void sendScale(wlr_surface* surf, const float& scale);
void onSurfaceDestroy(wlr_surface* surf);
void removeAddon(CFractionalScaleAddon*);
private:
2024-04-20 15:14:54 +02:00
void registerSurface(wlr_surface*);
std::unordered_map<wlr_surface*, SSurfaceListener> m_mSurfaceDestroyListeners;
2024-04-20 15:14:54 +02:00
std::unordered_map<wlr_surface*, float> m_mSurfaceScales;
std::unordered_map<wlr_surface*, UP<CFractionalScaleAddon>> m_mAddons;
std::vector<UP<CWpFractionalScaleManagerV1>> m_vManagers;
};
2024-04-20 15:14:54 +02:00
namespace PROTO {
inline UP<CFractionalScaleProtocol> fractional;
};