From fcfa97997993e9ee1e3d978a3255a38659b12f5c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 7 Mar 2024 14:16:22 +0000 Subject: [PATCH] core: add helper for resize algo --- hyprcursor-util/src/main.cpp | 2 +- libhyprcursor/hyprcursor.cpp | 2 +- libhyprcursor/internalSharedTypes.hpp | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hyprcursor-util/src/main.cpp b/hyprcursor-util/src/main.cpp index f2ff014..afc2a48 100644 --- a/hyprcursor-util/src/main.cpp +++ b/hyprcursor-util/src/main.cpp @@ -136,7 +136,7 @@ static std::optional createCursorThemeFromPath(const std::string& p SHAPE.directory = dir.path().stem().string(); SHAPE.hotspotX = std::any_cast(meta->getConfigValue("hotspot_x")); SHAPE.hotspotY = std::any_cast(meta->getConfigValue("hotspot_y")); - SHAPE.resizeAlgo = std::string{std::any_cast(meta->getConfigValue("resize_algorithm"))} == "nearest" ? RESIZE_NEAREST : RESIZE_BILINEAR; + SHAPE.resizeAlgo = stringToAlgo(std::any_cast(meta->getConfigValue("resize_algorithm"))); std::cout << "Shape " << SHAPE.directory << ": \n\toverrides: " << SHAPE.overrides.size() << "\n\tsizes: " << SHAPE.images.size() << "\n"; } diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp index 747b17b..17e119b 100644 --- a/libhyprcursor/hyprcursor.cpp +++ b/libhyprcursor/hyprcursor.cpp @@ -383,7 +383,7 @@ std::optional CHyprcursorImplementation::loadTheme() { SHAPE.directory = cursor.path().stem().string(); SHAPE.hotspotX = std::any_cast(meta->getConfigValue("hotspot_x")); SHAPE.hotspotY = std::any_cast(meta->getConfigValue("hotspot_y")); - SHAPE.resizeAlgo = std::string{std::any_cast(meta->getConfigValue("resize_algorithm"))} == "nearest" ? RESIZE_NEAREST : RESIZE_BILINEAR; + SHAPE.resizeAlgo = stringToAlgo(std::any_cast(meta->getConfigValue("resize_algorithm"))); zip_discard(zip); } diff --git a/libhyprcursor/internalSharedTypes.hpp b/libhyprcursor/internalSharedTypes.hpp index adfbf71..72aae28 100644 --- a/libhyprcursor/internalSharedTypes.hpp +++ b/libhyprcursor/internalSharedTypes.hpp @@ -3,10 +3,19 @@ #include enum eResizeAlgo { - RESIZE_BILINEAR = 0, - RESIZE_NEAREST = 1, + RESIZE_NONE = 0, + RESIZE_BILINEAR = 1, + RESIZE_NEAREST = 2, }; +inline eResizeAlgo stringToAlgo(const std::string& s) { + if (s == "none") + return RESIZE_NONE; + if (s == "nearest") + return RESIZE_NEAREST; + return RESIZE_BILINEAR; +} + struct SCursorImage { std::string filename; int size = 0;