mirror of
https://github.com/hyprwm/hyprpaper.git
synced 2024-11-16 22:25:59 +01:00
Fix crashing when setting wallpaper (#41)
This commit is contained in:
parent
44a38bfedc
commit
1d76f4db0d
1 changed files with 16 additions and 12 deletions
|
@ -200,14 +200,15 @@ void CHyprpaper::ensurePoolBuffersPresent() {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto it = std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [wt = &wt, &m](const std::unique_ptr<SPoolBuffer>& el) {
|
auto it = std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [wt = &wt, &m](const std::unique_ptr<SPoolBuffer>& el) {
|
||||||
return el->target == wt->m_szPath && el->pixelSize == m->size * (m->pCurrentLayerSurface->pFractionalScaleInfo ? m->pCurrentLayerSurface->fScale : m->scale);
|
auto scale = std::round(m->pCurrentLayerSurface && m->pCurrentLayerSurface->pFractionalScaleInfo ? m->pCurrentLayerSurface->fScale : m->scale);
|
||||||
|
return el->target == wt->m_szPath && el->pixelSize == m->size * scale;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (it == m_vBuffers.end()) {
|
if (it == m_vBuffers.end()) {
|
||||||
// create
|
// create
|
||||||
const auto PBUFFER = m_vBuffers.emplace_back(std::make_unique<SPoolBuffer>()).get();
|
const auto PBUFFER = m_vBuffers.emplace_back(std::make_unique<SPoolBuffer>()).get();
|
||||||
|
auto scale = std::round(m->pCurrentLayerSurface && m->pCurrentLayerSurface->pFractionalScaleInfo ? m->pCurrentLayerSurface->fScale : m->scale);
|
||||||
createBuffer(PBUFFER, m->size.x * (m->pCurrentLayerSurface->pFractionalScaleInfo ? m->pCurrentLayerSurface->fScale : m->scale), m->size.y * (m->pCurrentLayerSurface->pFractionalScaleInfo ? m->pCurrentLayerSurface->fScale : m->scale), WL_SHM_FORMAT_ARGB8888);
|
createBuffer(PBUFFER, m->size.x * scale, m->size.y * scale, WL_SHM_FORMAT_ARGB8888);
|
||||||
|
|
||||||
PBUFFER->target = wt.m_szPath;
|
PBUFFER->target = wt.m_szPath;
|
||||||
|
|
||||||
|
@ -392,7 +393,8 @@ void CHyprpaper::destroyBuffer(SPoolBuffer* pBuffer) {
|
||||||
|
|
||||||
SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWallpaperTarget) {
|
SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWallpaperTarget) {
|
||||||
return std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [&](const std::unique_ptr<SPoolBuffer>& el) {
|
return std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [&](const std::unique_ptr<SPoolBuffer>& el) {
|
||||||
return el->target == pWallpaperTarget->m_szPath && el->pixelSize == pMonitor->size * (pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? pMonitor->pCurrentLayerSurface->fScale : pMonitor->scale);
|
auto scale = std::round(pMonitor->pCurrentLayerSurface && pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? pMonitor->pCurrentLayerSurface->fScale : pMonitor->scale);
|
||||||
|
return el->target == pWallpaperTarget->m_szPath && el->pixelSize == pMonitor->size * scale;
|
||||||
})->get();
|
})->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +421,7 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const double SURFACESCALE = pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? pMonitor->pCurrentLayerSurface->fScale : pMonitor->scale;
|
const double SURFACESCALE = std::round( pMonitor->pCurrentLayerSurface && pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? pMonitor->pCurrentLayerSurface->fScale : pMonitor->scale);
|
||||||
const Vector2D DIMENSIONS = Vector2D{std::round(pMonitor->size.x * SURFACESCALE), std::round(pMonitor->size.y * SURFACESCALE)};
|
const Vector2D DIMENSIONS = Vector2D{std::round(pMonitor->size.x * SURFACESCALE), std::round(pMonitor->size.y * SURFACESCALE)};
|
||||||
|
|
||||||
const auto PCAIRO = PBUFFER->cairo;
|
const auto PCAIRO = PBUFFER->cairo;
|
||||||
|
@ -473,6 +475,7 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
|
||||||
cairo_paint(PCAIRO);
|
cairo_paint(PCAIRO);
|
||||||
cairo_restore(PCAIRO);
|
cairo_restore(PCAIRO);
|
||||||
|
|
||||||
|
if(pMonitor->pCurrentLayerSurface) {
|
||||||
wl_surface_attach(pMonitor->pCurrentLayerSurface->pSurface, PBUFFER->buffer, 0, 0);
|
wl_surface_attach(pMonitor->pCurrentLayerSurface->pSurface, PBUFFER->buffer, 0, 0);
|
||||||
wl_surface_set_buffer_scale(pMonitor->pCurrentLayerSurface->pSurface, pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? 1 : pMonitor->scale);
|
wl_surface_set_buffer_scale(pMonitor->pCurrentLayerSurface->pSurface, pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? 1 : pMonitor->scale);
|
||||||
wl_surface_damage_buffer(pMonitor->pCurrentLayerSurface->pSurface, 0, 0, 0xFFFF, 0xFFFF);
|
wl_surface_damage_buffer(pMonitor->pCurrentLayerSurface->pSurface, 0, 0, 0xFFFF, 0xFFFF);
|
||||||
|
@ -481,6 +484,7 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
|
||||||
wp_viewport_set_destination(pMonitor->pCurrentLayerSurface->pViewport, static_cast<int>(std::round(pMonitor->size.x)), static_cast<int>(std::round(pMonitor->size.y)));
|
wp_viewport_set_destination(pMonitor->pCurrentLayerSurface->pViewport, static_cast<int>(std::round(pMonitor->size.x)), static_cast<int>(std::round(pMonitor->size.y)));
|
||||||
}
|
}
|
||||||
wl_surface_commit(pMonitor->pCurrentLayerSurface->pSurface);
|
wl_surface_commit(pMonitor->pCurrentLayerSurface->pSurface);
|
||||||
|
}
|
||||||
|
|
||||||
// check if we dont need to remove a wallpaper
|
// check if we dont need to remove a wallpaper
|
||||||
if (pMonitor->layerSurfaces.size() > 1) {
|
if (pMonitor->layerSurfaces.size() > 1) {
|
||||||
|
|
Loading…
Reference in a new issue