Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/renderer/AsyncResourceGatherer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ ASP<SPreloadedAsset> CAsyncResourceGatherer::getAssetByID(const std::string& id)
return nullptr;
}

static SP<CCairoSurface> getCairoSurfaceFromImageFile(const std::filesystem::path& path) {
auto image = CImage(path);
static SP<CCairoSurface> getCairoSurfaceFromImageFile(const std::filesystem::path& path, const Vector2D& size = {}) {
auto image = (size.x > 0 && size.y > 0) ? CImage(path.string(), size) : CImage(path);
if (!image.success()) {
Debug::log(ERR, "Image {} could not be loaded: {}", path.string(), image.getError());
return nullptr;
Expand Down Expand Up @@ -128,6 +128,12 @@ void CAsyncResourceGatherer::gather() {
rq.asset = path;
rq.id = id;

// Pass size for image widgets (needed for SVG rendering)
if (c.type == "image" && c.values.contains("size")) {
const auto imgSize = std::any_cast<Hyprlang::INT>(c.values.at("size"));
rq.props["size"] = Vector2D{(double)imgSize, (double)imgSize};
}

renderImage(rq);
}
}
Expand Down Expand Up @@ -204,7 +210,8 @@ void CAsyncResourceGatherer::renderImage(const SPreloadRequest& rq) {
target.id = rq.id;

std::filesystem::path ABSOLUTEPATH(absolutePath(rq.asset, ""));
const auto CAIROISURFACE = getCairoSurfaceFromImageFile(ABSOLUTEPATH);
const Vector2D IMGSIZE = rq.props.contains("size") ? std::any_cast<Vector2D>(rq.props.at("size")) : Vector2D{};
const auto CAIROISURFACE = getCairoSurfaceFromImageFile(ABSOLUTEPATH, IMGSIZE);

if (!CAIROISURFACE) {
Debug::log(ERR, "renderImage: No cairo surface!");
Expand Down
1 change: 1 addition & 0 deletions src/renderer/widgets/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void CImage::onTimerUpdate() {
request.asset = path;
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
request.callback = [REF = m_self]() { onAssetCallback(REF); };
request.props["size"] = Vector2D{(double)size, (double)size};

g_pAsyncResourceGatherer->requestAsyncAssetPreload(request);
}
Expand Down