core: formatting and small fixes

This commit is contained in:
Vaxry 2024-03-07 17:51:14 +00:00
parent ceecc4e7da
commit d1dcce9a00
3 changed files with 20 additions and 11 deletions

View file

@ -20,7 +20,6 @@ namespace Hyprcursor {
*/
unsigned int size = 0;
};
/*!
struct for cursor shape data
@ -68,16 +67,18 @@ namespace Hyprcursor {
The surfaces references stay valid until cursorSurfaceStyleDone() is called on the owning style.
*/
SCursorShapeData getShape(const char* shape, const SCursorStyleInfo& info) {
int size = 0;
int size = 0;
SCursorImageData** images = getShapesC(size, shape, info);
SCursorShapeData data;
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;
image.delay = images[i]->delay;
image.size = images[i]->size;
image.surface = images[i]->surface;
image.hotspotX = images[i]->hotspotX;
image.hotspotY = images[i]->hotspotY;
data.images.push_back(image);
free(images[i]);
@ -91,7 +92,7 @@ namespace Hyprcursor {
/*!
Prefer getShape, this is for C compat.
*/
SCursorImageData** getShapesC(int& outSize, const char* shape_, const SCursorStyleInfo& info);
SCursorImageData** getShapesC(int& outSize, const char* shape_, const SCursorStyleInfo& info);
/*!
Marks a certain style as done, allowing it to be potentially freed

View file

@ -10,6 +10,8 @@ struct SCursorImageData {
cairo_surface_t* surface;
int size;
int delay;
int hotspotX;
int hotspotY;
};
typedef struct SCursorImageData hyprcursor_cursor_image_data;

View file

@ -166,11 +166,15 @@ SCursorImageData** CHyprcursorManager::getShapesC(int& outSize, const char* shap
std::string REQUESTEDSHAPE = shape_;
std::vector<SLoadedCursorImage*> resultingImages;
float hotX = 0, hotY = 0;
for (auto& shape : impl->theme.shapes) {
if (REQUESTEDSHAPE != shape->directory && std::find(shape->overrides.begin(), shape->overrides.end(), REQUESTEDSHAPE) == shape->overrides.end())
continue;
hotX = shape->hotspotX;
hotY = shape->hotspotY;
// matched :)
bool foundAny = false;
for (auto& image : impl->loadedShapes[shape.get()].images) {
@ -225,10 +229,12 @@ SCursorImageData** CHyprcursorManager::getShapesC(int& outSize, const char* shap
// alloc and return what we need
SCursorImageData** data = (SCursorImageData**)malloc(sizeof(SCursorImageData*) * resultingImages.size());
for (size_t i = 0; i < resultingImages.size(); ++i) {
data[i] = (SCursorImageData*)malloc(sizeof(SCursorImageData));
data[i]->delay = resultingImages[i]->delay;
data[i]->size = resultingImages[i]->side;
data[i]->surface = resultingImages[i]->cairoSurface;
data[i] = (SCursorImageData*)malloc(sizeof(SCursorImageData));
data[i]->delay = resultingImages[i]->delay;
data[i]->size = resultingImages[i]->side;
data[i]->surface = resultingImages[i]->cairoSurface;
data[i]->hotspotX = hotX * data[i]->size;
data[i]->hotspotY = hotY * data[i]->size;
}
outSize = resultingImages.size();