util: add --resize

This commit is contained in:
Vaxry 2024-03-08 02:00:52 +00:00
parent effb7a4665
commit 06d1028025
3 changed files with 26 additions and 5 deletions

View file

@ -15,4 +15,8 @@ Cursor themes can be in 3 states:
`--extract | -x [path]` -> extract an xcursor theme into a working state `--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. 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`.

View file

@ -12,6 +12,8 @@ enum eOperation {
OPERATION_EXTRACT = 1, OPERATION_EXTRACT = 1,
}; };
eResizeAlgo explicitResizeAlgo = RESIZE_INVALID;
struct XCursorConfigEntry { struct XCursorConfigEntry {
int size = 0, hotspotX = 0, hotspotY = 0, delay = 0; int size = 0, hotspotX = 0, hotspotY = 0, delay = 0;
std::string image; std::string image;
@ -349,7 +351,7 @@ static std::optional<std::string> extractXTheme(const std::string& xpath, const
} }
// write a meta.hl // 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 // find hotspot from first entry
metaString += metaString +=
@ -431,6 +433,9 @@ int main(int argc, char** argv, char** envp) {
if (arg == "-o" || arg == "--output") { if (arg == "-o" || arg == "--output") {
out = argv[++i]; out = argv[++i];
continue; continue;
} else if (arg == "--resize") {
explicitResizeAlgo = stringToAlgo(argv[++i]);
continue;
} else { } else {
std::cerr << "Unknown arg: " << arg << "\n"; std::cerr << "Unknown arg: " << arg << "\n";
return 1; return 1;

View file

@ -4,9 +4,10 @@
#include <memory> #include <memory>
enum eResizeAlgo { enum eResizeAlgo {
RESIZE_NONE = 0, RESIZE_INVALID = 0,
RESIZE_BILINEAR = 1, RESIZE_NONE,
RESIZE_NEAREST = 2, RESIZE_BILINEAR,
RESIZE_NEAREST,
}; };
enum eShapeType { enum eShapeType {
@ -23,6 +24,17 @@ inline eResizeAlgo stringToAlgo(const std::string& s) {
return RESIZE_BILINEAR; 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 { struct SCursorImage {
std::string filename; std::string filename;
int size = 0; int size = 0;