Fix background not being cleared

Previously no image would be rendered if hyprland could not find one
to use, leaving last frame as the background.
This commit ensures there will always be an image available to clear
the screen with.
This commit is contained in:
outfoxxed 2023-08-07 23:26:48 -07:00
parent 4986d74ef2
commit aeeecc8129
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E

View file

@ -1708,28 +1708,32 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) {
// or configure the paths at build time
// get the adequate tex
std::string texPath = "/usr/share/hyprland/wall_" + std::string(USEANIME ? (distribution2(engine) == 0 ? "anime_" : "anime2_") : "");
std::string texName = "wall_" + std::string(USEANIME ? (distribution2(engine) == 0 ? "anime_" : "anime2_") : "");
// check if wallpapers exist
Vector2D textureSize;
if (pMonitor->vecTransformedSize.x > 3850) {
textureSize = Vector2D(7680, 4320);
texPath += "8K.png";
texName += "8K.png";
} else if (pMonitor->vecTransformedSize.x > 1930) {
textureSize = Vector2D(3840, 2160);
texPath += "4K.png";
texName += "4K.png";
} else {
textureSize = Vector2D(1920, 1080);
texPath += "2K.png";
texName += "2K.png";
}
if (!std::filesystem::exists(texPath)) {
// try local
texPath = texPath.substr(0, 5) + "local/" + texPath.substr(5);
if (!std::filesystem::exists(texPath))
return; // the texture will be empty, oh well. We'll clear with a solid color anyways.
}
std::string texPath = "/usr/share/hyprland/" + texName;
if (std::filesystem::exists(texPath))
goto hastex;
texPath = "/usr/local/share/hyprland/" + texName;
if (std::filesystem::exists(texPath))
goto hastex;
texPath = "assets/" + texName;
if (std::filesystem::exists(texPath))
goto hastex;
texPath = "";
hastex:
PTEX->m_vSize = textureSize;
@ -1755,9 +1759,20 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) {
m_mMonitorRenderResources[pMonitor].backgroundTexBox = box;
// create a new one with cairo
const auto CAIROSURFACE = cairo_image_surface_create_from_png(texPath.c_str());
cairo_surface_t* CAIROSURFACE;
if (texPath.empty())
// if we couldn't find a texture, use a grey filler image instead.
CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, textureSize.x, textureSize.y);
else
CAIROSURFACE = cairo_image_surface_create_from_png(texPath.c_str());
const auto CAIRO = cairo_create(CAIROSURFACE);
if (texPath.empty()) {
cairo_set_source_rgba(CAIRO, 0.106, 0.106, 0.106, 1.0);
cairo_rectangle(CAIRO, 0, 0, box.width, box.height);
cairo_fill(CAIRO);
}
// scale it to fit the current monitor
cairo_scale(CAIRO, textureSize.x / pMonitor->vecTransformedSize.x, textureSize.y / pMonitor->vecTransformedSize.y);