2023-11-11 15:37:17 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "../../helpers/Box.hpp"
|
|
|
|
|
|
|
|
class CWindow;
|
|
|
|
class IHyprWindowDecoration;
|
|
|
|
|
2023-11-12 14:01:23 +01:00
|
|
|
enum eDecorationPositioningPolicy
|
|
|
|
{
|
|
|
|
DECORATION_POSITION_ABSOLUTE = 0, /* Decoration wants absolute positioning */
|
2023-11-11 15:37:17 +01:00
|
|
|
DECORATION_POSITION_STICKY, /* Decoration is stuck to some edge of a window */
|
|
|
|
};
|
|
|
|
|
2023-11-12 14:01:23 +01:00
|
|
|
enum eDecorationEdges
|
|
|
|
{
|
2023-11-11 15:37:17 +01:00
|
|
|
DECORATION_EDGE_TOP = 1 << 0,
|
|
|
|
DECORATION_EDGE_BOTTOM = 1 << 1,
|
|
|
|
DECORATION_EDGE_LEFT = 1 << 2,
|
|
|
|
DECORATION_EDGE_RIGHT = 1 << 3
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Request the positioner to position a decoration
|
|
|
|
|
|
|
|
DECORATION_POSITION_ABSOLUTE:
|
2023-11-11 16:18:04 +01:00
|
|
|
- desiredExtents has to contain the extents. Edges has to have the edges used.
|
|
|
|
- reserved allowed
|
2023-11-11 15:37:17 +01:00
|
|
|
DECORATION_POSITION_STICKY:
|
|
|
|
- one edge allowed
|
|
|
|
- priority allowed
|
|
|
|
- desiredExtents contains the desired extents. Any other edge than the one selected is ignored.
|
|
|
|
- reserved is allowed
|
|
|
|
*/
|
|
|
|
struct SDecorationPositioningInfo {
|
|
|
|
eDecorationPositioningPolicy policy = DECORATION_POSITION_ABSOLUTE;
|
|
|
|
uint32_t edges = 0; // enum eDecorationEdges
|
|
|
|
uint32_t priority = 10; // priority, decos will be evaluated high -> low
|
|
|
|
SWindowDecorationExtents desiredExtents;
|
|
|
|
bool reserved = false; // if true, geometry will use reserved area
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
A reply from the positioner. This may be sent multiple times, if anything changes.
|
|
|
|
|
|
|
|
DECORATION_POSITION_ABSOLUTE:
|
|
|
|
- assignedGeometry is empty
|
|
|
|
DECORATION_POSITION_STICKY:
|
|
|
|
- assignedGeometry is relative to the edge's center point
|
|
|
|
- ephemeral is sent
|
|
|
|
*/
|
|
|
|
struct SDecorationPositioningReply {
|
|
|
|
CBox assignedGeometry;
|
|
|
|
bool ephemeral = false; // if true, means it's a result of an animation and will change soon.
|
|
|
|
};
|
|
|
|
|
|
|
|
class CDecorationPositioner {
|
|
|
|
public:
|
|
|
|
CDecorationPositioner();
|
|
|
|
|
|
|
|
Vector2D getEdgeDefinedPoint(uint32_t edges, CWindow* pWindow);
|
|
|
|
|
|
|
|
// called on resize, or insert/removal of a new deco
|
|
|
|
void onWindowUpdate(CWindow* pWindow);
|
|
|
|
void uncacheDecoration(IHyprWindowDecoration* deco);
|
|
|
|
SWindowDecorationExtents getWindowDecorationReserved(CWindow* pWindow);
|
|
|
|
SWindowDecorationExtents getWindowDecorationExtents(CWindow* pWindow, bool inputOnly = false);
|
|
|
|
CBox getBoxWithIncludedDecos(CWindow* pWindow);
|
|
|
|
void repositionDeco(IHyprWindowDecoration* deco);
|
|
|
|
CBox getWindowDecorationBox(IHyprWindowDecoration* deco);
|
2023-11-13 17:42:45 +01:00
|
|
|
void forceRecalcFor(CWindow* pWindow);
|
2023-11-11 15:37:17 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct SWindowPositioningData {
|
|
|
|
CWindow* pWindow = nullptr;
|
|
|
|
IHyprWindowDecoration* pDecoration = nullptr;
|
|
|
|
SDecorationPositioningInfo positioningInfo;
|
|
|
|
SDecorationPositioningReply lastReply;
|
|
|
|
bool needsReposition = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SWindowData {
|
|
|
|
Vector2D lastWindowSize = {};
|
|
|
|
SWindowDecorationExtents reserved = {};
|
|
|
|
SWindowDecorationExtents extents = {};
|
2023-11-11 15:52:27 +01:00
|
|
|
bool needsRecalc = false;
|
2023-11-11 15:37:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map<CWindow*, SWindowData> m_mWindowDatas;
|
|
|
|
std::vector<std::unique_ptr<SWindowPositioningData>> m_vWindowPositioningDatas;
|
|
|
|
|
|
|
|
SWindowPositioningData* getDataFor(IHyprWindowDecoration* pDecoration, CWindow* pWindow);
|
|
|
|
void onWindowUnmap(CWindow* pWindow);
|
2023-11-11 19:07:56 +01:00
|
|
|
void onWindowMap(CWindow* pWindow);
|
|
|
|
void sanitizeDatas();
|
2023-11-11 15:37:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::unique_ptr<CDecorationPositioner> g_pDecorationPositioner;
|