hyprcursor/include/hyprcursor.hpp

106 lines
2.6 KiB
C++
Raw Normal View History

2024-03-07 04:19:38 +01:00
#pragma once
2024-03-07 17:01:45 +01:00
#include <vector>
#include <stdlib.h>
#include "shared.h"
2024-03-07 04:19:38 +01:00
class CHyprcursorImplementation;
namespace Hyprcursor {
/*!
2024-03-07 15:50:48 +01:00
Simple struct for styles
2024-03-07 04:19:38 +01:00
*/
2024-03-07 15:50:48 +01:00
struct SCursorStyleInfo {
2024-03-07 16:10:45 +01:00
/*!
2024-03-07 15:50:48 +01:00
Shape size.
0 means "any" or "unspecified".
2024-03-07 04:19:38 +01:00
*/
unsigned int size = 0;
};
2024-03-07 17:01:45 +01:00
/*!
struct for cursor shape data
*/
struct SCursorShapeData {
std::vector<SCursorImageData> images;
};
2024-03-07 04:19:38 +01:00
/*!
Basic Hyprcursor manager.
Has to be created for either a specified theme, or
nullptr if you want to use a default from the env.
If no env is set, picks the first found.
If none found, bool valid() will be false.
If loading fails, bool valid() will be false.
*/
class CHyprcursorManager {
public:
CHyprcursorManager(const char* themeName);
~CHyprcursorManager();
/*!
Returns true if the theme was successfully loaded,
i.e. everything is A-OK and nothing should fail.
*/
bool valid();
2024-03-07 15:50:48 +01:00
/*!
Loads this theme at a given style, synchronously.
2024-03-07 16:10:45 +01:00
Returns whether it succeeded.
2024-03-07 15:50:48 +01:00
*/
bool loadThemeStyle(const SCursorStyleInfo& info);
2024-03-07 04:19:38 +01:00
/*!
2024-03-07 17:01:45 +01:00
Returns the shape data struct for a given
style.
Once done with a style, call cursorSurfaceDone()
The surfaces references stay valid until cursorSurfaceStyleDone() is called on the owning style.
*/
SCursorShapeData getShape(const char* shape, const SCursorStyleInfo& info) {
int size = 0;
SCursorImageData** images = getShapesC(size, shape, info);
SCursorShapeData data;
for (size_t i = 0; i < size; ++i) {
SCursorImageData image;
image.delay = images[i]->delay;
image.size = images[i]->size;
image.surface = images[i]->surface;
data.images.push_back(image);
free(images[i]);
}
2024-03-07 04:19:38 +01:00
2024-03-07 17:01:45 +01:00
free(images);
return data;
}
/*!
Prefer getShape, this is for C compat.
2024-03-07 04:19:38 +01:00
*/
2024-03-07 17:01:45 +01:00
SCursorImageData** getShapesC(int& outSize, const char* shape_, const SCursorStyleInfo& info);
2024-03-07 04:19:38 +01:00
/*!
2024-03-07 15:50:48 +01:00
Marks a certain style as done, allowing it to be potentially freed
2024-03-07 04:19:38 +01:00
*/
2024-03-07 15:50:48 +01:00
void cursorSurfaceStyleDone(const SCursorStyleInfo&);
2024-03-07 04:19:38 +01:00
private:
CHyprcursorImplementation* impl = nullptr;
bool finalizedAndValid = false;
};
}