From 06d1028025e5e3a2179a1b0b8108b08f3fa8db36 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 8 Mar 2024 02:00:52 +0000 Subject: [PATCH] util: add --resize --- hyprcursor-util/README.md | 6 +++++- hyprcursor-util/src/main.cpp | 7 ++++++- libhyprcursor/internalSharedTypes.hpp | 18 +++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/hyprcursor-util/README.md b/hyprcursor-util/README.md index 115d807..d2a02c3 100644 --- a/hyprcursor-util/README.md +++ b/hyprcursor-util/README.md @@ -15,4 +15,8 @@ Cursor themes can be in 3 states: `--extract | -x [path]` -> extract an xcursor theme into a working state -both commands support `--output | -o` to specify an output directory. This directory will be fully overwritten, and by default is `./theme` and `./extracted` respectively. \ No newline at end of file +both commands support `--output | -o` to specify an output directory. This directory will be fully overwritten, and by default is `./theme` and `./extracted` respectively. + +### Flags + +`--resize [mode]` - for `extract`: specify a default resize algorithm for shapes. Default is `none`. \ No newline at end of file diff --git a/hyprcursor-util/src/main.cpp b/hyprcursor-util/src/main.cpp index 56bf960..305294d 100644 --- a/hyprcursor-util/src/main.cpp +++ b/hyprcursor-util/src/main.cpp @@ -12,6 +12,8 @@ enum eOperation { OPERATION_EXTRACT = 1, }; +eResizeAlgo explicitResizeAlgo = RESIZE_INVALID; + struct XCursorConfigEntry { int size = 0, hotspotX = 0, hotspotY = 0, delay = 0; std::string image; @@ -349,7 +351,7 @@ static std::optional extractXTheme(const std::string& xpath, const } // write a meta.hl - std::string metaString = "resize_algorithm = none\n"; + std::string metaString = std::format("resize_algorithm = {}\n", explicitResizeAlgo == RESIZE_INVALID ? "none" : algoToString(explicitResizeAlgo)); // find hotspot from first entry metaString += @@ -431,6 +433,9 @@ int main(int argc, char** argv, char** envp) { if (arg == "-o" || arg == "--output") { out = argv[++i]; continue; + } else if (arg == "--resize") { + explicitResizeAlgo = stringToAlgo(argv[++i]); + continue; } else { std::cerr << "Unknown arg: " << arg << "\n"; return 1; diff --git a/libhyprcursor/internalSharedTypes.hpp b/libhyprcursor/internalSharedTypes.hpp index baf5364..c5ac601 100644 --- a/libhyprcursor/internalSharedTypes.hpp +++ b/libhyprcursor/internalSharedTypes.hpp @@ -4,9 +4,10 @@ #include enum eResizeAlgo { - RESIZE_NONE = 0, - RESIZE_BILINEAR = 1, - RESIZE_NEAREST = 2, + RESIZE_INVALID = 0, + RESIZE_NONE, + RESIZE_BILINEAR, + RESIZE_NEAREST, }; enum eShapeType { @@ -23,6 +24,17 @@ inline eResizeAlgo stringToAlgo(const std::string& s) { return RESIZE_BILINEAR; } +inline std::string algoToString(const eResizeAlgo a) { + switch (a) { + case RESIZE_BILINEAR: return "bilinear"; + case RESIZE_NEAREST: return "nearest"; + case RESIZE_NONE: return "none"; + default: return "none"; + } + + return "none"; +} + struct SCursorImage { std::string filename; int size = 0;