From d1dcce9a00da55c82d05fea87d6f895d31b23735 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 7 Mar 2024 17:51:14 +0000 Subject: [PATCH] core: formatting and small fixes --- include/hyprcursor/hyprcursor.hpp | 15 ++++++++------- include/hyprcursor/shared.h | 2 ++ libhyprcursor/hyprcursor.cpp | 14 ++++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/hyprcursor/hyprcursor.hpp b/include/hyprcursor/hyprcursor.hpp index 31fbfdb..7e8fc99 100644 --- a/include/hyprcursor/hyprcursor.hpp +++ b/include/hyprcursor/hyprcursor.hpp @@ -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 diff --git a/include/hyprcursor/shared.h b/include/hyprcursor/shared.h index e010fe4..d4416ad 100644 --- a/include/hyprcursor/shared.h +++ b/include/hyprcursor/shared.h @@ -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; diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp index 45de94d..4c31cb2 100644 --- a/libhyprcursor/hyprcursor.cpp +++ b/libhyprcursor/hyprcursor.cpp @@ -166,11 +166,15 @@ SCursorImageData** CHyprcursorManager::getShapesC(int& outSize, const char* shap std::string REQUESTEDSHAPE = shape_; std::vector 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();