Fadein/out now applies to layersurfaces too

This commit is contained in:
vaxerski 2022-05-14 17:23:46 +02:00
parent 694f4433a2
commit 109136af97
11 changed files with 153 additions and 15 deletions

View file

@ -513,7 +513,7 @@ CWindow* CCompositor::getWindowForPopup(wlr_xdg_popup* popup) {
wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::list<SLayerSurface*>* layerSurfaces, Vector2D* sCoords) { wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::list<SLayerSurface*>* layerSurfaces, Vector2D* sCoords) {
for (auto& l : *layerSurfaces) { for (auto& l : *layerSurfaces) {
if (!l->layerSurface->mapped) if (l->fadingOut || (l->layerSurface && !l->layerSurface->mapped))
continue; continue;
const auto SURFACEAT = wlr_layer_surface_v1_surface_at(l->layerSurface, pos.x - l->geometry.x, pos.y - l->geometry.y, &sCoords->x, &sCoords->y); const auto SURFACEAT = wlr_layer_surface_v1_surface_at(l->layerSurface, pos.x - l->geometry.x, pos.y - l->geometry.y, &sCoords->x, &sCoords->y);
@ -650,6 +650,24 @@ void CCompositor::cleanupWindows() {
return; return;
} }
} }
for (auto& ls : m_lSurfacesFadingOut) {
if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) {
for (auto& m : m_lMonitors) {
for (auto& lsl : m.m_aLayerSurfaceLists) {
lsl.remove(ls);
}
}
g_pHyprOpenGL->m_mLayerFramebuffers[ls].release();
g_pHyprOpenGL->m_mLayerFramebuffers.erase(ls);
m_lSurfacesFadingOut.remove(ls);
delete ls;
return;
}
}
} }
CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {

View file

@ -67,6 +67,7 @@ public:
std::list<CWorkspace> m_lWorkspaces; std::list<CWorkspace> m_lWorkspaces;
std::list<SSubsurface> m_lSubsurfaces; std::list<SSubsurface> m_lSubsurfaces;
std::list<CWindow*> m_lWindowsFadingOut; std::list<CWindow*> m_lWindowsFadingOut;
std::list<SLayerSurface*> m_lSurfacesFadingOut;
void startCompositor(); void startCompositor();
void cleanupExit(); void cleanupExit();

View file

@ -72,9 +72,6 @@ void Events::listener_destroyLayerSurface(void* owner, void* data) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID); const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID);
// remove the layersurface as it's not used anymore
PMONITOR->m_aLayerSurfaceLists[layersurface->layer].remove(layersurface);
// rearrange to fix the reserved areas // rearrange to fix the reserved areas
if (PMONITOR) { if (PMONITOR) {
g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->ID); g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->ID);
@ -85,7 +82,8 @@ void Events::listener_destroyLayerSurface(void* owner, void* data) {
g_pHyprRenderer->damageBox(&geomFixed); g_pHyprRenderer->damageBox(&geomFixed);
} }
delete layersurface; layersurface->readyToDelete = true;
layersurface->layerSurface = nullptr;
} }
void Events::listener_mapLayerSurface(void* owner, void* data) { void Events::listener_mapLayerSurface(void* owner, void* data) {
@ -121,6 +119,11 @@ void Events::listener_mapLayerSurface(void* owner, void* data) {
wlr_box geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, layersurface->geometry.height}; wlr_box geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, layersurface->geometry.height};
g_pHyprRenderer->damageBox(&geomFixed); g_pHyprRenderer->damageBox(&geomFixed);
layersurface->alpha.setValue(0);
layersurface->alpha = 255.f;
layersurface->readyToDelete = false;
layersurface->fadingOut = false;
} }
void Events::listener_unmapLayerSurface(void* owner, void* data) { void Events::listener_unmapLayerSurface(void* owner, void* data) {
@ -128,6 +131,14 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) {
Debug::log(LOG, "LayerSurface %x unmapped", layersurface->layerSurface); Debug::log(LOG, "LayerSurface %x unmapped", layersurface->layerSurface);
// make a snapshot and start fade
g_pHyprOpenGL->makeLayerSnapshot(layersurface);
layersurface->alpha = 0.f;
layersurface->fadingOut = true;
g_pCompositor->m_lSurfacesFadingOut.push_back(layersurface);
if (layersurface->layerSurface->mapped) if (layersurface->layerSurface->mapped)
layersurface->layerSurface->mapped = false; layersurface->layerSurface->mapped = false;

View file

@ -18,6 +18,7 @@ enum AVARDAMAGEPOLICY {
class CAnimationManager; class CAnimationManager;
class CWorkspace; class CWorkspace;
struct SLayerSurface;
class CAnimatedVariable { class CAnimatedVariable {
public: public:
@ -183,8 +184,12 @@ private:
float* m_pSpeed = nullptr; float* m_pSpeed = nullptr;
int64_t* m_pEnabled = nullptr; int64_t* m_pEnabled = nullptr;
// owners
void* m_pWindow = nullptr; void* m_pWindow = nullptr;
void* m_pWorkspace = nullptr; void* m_pWorkspace = nullptr;
void* m_pLayer = nullptr;
std::string* m_pBezier = nullptr; std::string* m_pBezier = nullptr;
bool m_bDummy = true; bool m_bDummy = true;
@ -196,4 +201,5 @@ private:
friend class CAnimationManager; friend class CAnimationManager;
friend class CWorkspace; friend class CWorkspace;
friend struct SLayerSurface;
}; };

View file

@ -0,0 +1,7 @@
#include "WLClasses.hpp"
#include "../config/ConfigManager.hpp"
SLayerSurface::SLayerSurface() {
alpha.create(AVARTYPE_FLOAT, &g_pConfigManager->getConfigValuePtr("animations:fadein_speed")->floatValue, &g_pConfigManager->getConfigValuePtr("animations:fadein")->intValue, &g_pConfigManager->getConfigValuePtr("animations:fadein_curve")->strValue, nullptr, AVARDAMAGE_ENTIRE);
alpha.m_pLayer = this;
}

View file

@ -5,8 +5,11 @@
#include "../../wlr-layer-shell-unstable-v1-protocol.h" #include "../../wlr-layer-shell-unstable-v1-protocol.h"
#include "../Window.hpp" #include "../Window.hpp"
#include "SubsurfaceTree.hpp" #include "SubsurfaceTree.hpp"
#include "AnimatedVariable.hpp"
struct SLayerSurface { struct SLayerSurface {
SLayerSurface();
wlr_layer_surface_v1* layerSurface; wlr_layer_surface_v1* layerSurface;
wl_list link; wl_list link;
@ -22,6 +25,9 @@ struct SLayerSurface {
int monitorID = -1; int monitorID = -1;
CAnimatedVariable alpha;
bool fadingOut = false;
bool readyToDelete = false;
// For the list lookup // For the list lookup
bool operator==(const SLayerSurface& rhs) { bool operator==(const SLayerSurface& rhs) {

View file

@ -41,12 +41,16 @@ void CAnimationManager::tick() {
// window stuff // window stuff
const auto PWINDOW = (CWindow*)av->m_pWindow; const auto PWINDOW = (CWindow*)av->m_pWindow;
const auto PWORKSPACE = (CWorkspace*)av->m_pWorkspace; const auto PWORKSPACE = (CWorkspace*)av->m_pWorkspace;
const auto PLAYER = (SLayerSurface*)av->m_pLayer;
wlr_box WLRBOXPREV = {0,0,0,0}; wlr_box WLRBOXPREV = {0,0,0,0};
if (PWINDOW) { if (PWINDOW) {
WLRBOXPREV = {(int)PWINDOW->m_vRealPosition.vec().x - BORDERSIZE - 1, (int)PWINDOW->m_vRealPosition.vec().y - BORDERSIZE - 1, (int)PWINDOW->m_vRealSize.vec().x + 2 * BORDERSIZE + 2, (int)PWINDOW->m_vRealSize.vec().y + 2 * BORDERSIZE + 2}; WLRBOXPREV = {(int)PWINDOW->m_vRealPosition.vec().x - BORDERSIZE - 1, (int)PWINDOW->m_vRealPosition.vec().y - BORDERSIZE - 1, (int)PWINDOW->m_vRealSize.vec().x + 2 * BORDERSIZE + 2, (int)PWINDOW->m_vRealSize.vec().y + 2 * BORDERSIZE + 2};
} else if (PWORKSPACE) { } else if (PWORKSPACE) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID);
WLRBOXPREV = {(int)PMONITOR->vecPosition.x, (int)PMONITOR->vecPosition.y, (int)PMONITOR->vecSize.x, (int)PMONITOR->vecSize.y}; WLRBOXPREV = {(int)PMONITOR->vecPosition.x, (int)PMONITOR->vecPosition.y, (int)PMONITOR->vecSize.x, (int)PMONITOR->vecSize.y};
} else if (PLAYER) {
WLRBOXPREV = PLAYER->geometry;
} }
// check if it's disabled, if so, warp // check if it's disabled, if so, warp

View file

@ -698,12 +698,57 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
wlr_output_rollback(PMONITOR->output); wlr_output_rollback(PMONITOR->output);
} }
void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) {
// we trust the window is valid.
const auto PMONITOR = g_pCompositor->getMonitorFromID(pLayer->monitorID);
wlr_output_attach_render(PMONITOR->output, nullptr);
// we need to "damage" the entire monitor
// so that we render the entire window
// this is temporary, doesnt mess with the actual wlr damage
pixman_region32_t fakeDamage;
pixman_region32_init(&fakeDamage);
pixman_region32_union_rect(&fakeDamage, &fakeDamage, 0, 0, (int)PMONITOR->vecSize.x, (int)PMONITOR->vecSize.y);
begin(PMONITOR, &fakeDamage);
pixman_region32_fini(&fakeDamage);
const auto PFRAMEBUFFER = &m_mLayerFramebuffers[pLayer];
PFRAMEBUFFER->m_tTransform = pLayer->layerSurface->surface->current.transform;
PFRAMEBUFFER->alloc(PMONITOR->vecSize.x, PMONITOR->vecSize.y);
PFRAMEBUFFER->bind();
clear(CColor(0, 0, 0, 0)); // JIC
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
// draw the layer
g_pHyprRenderer->renderLayer(pLayer, PMONITOR, &now);
// restore original fb
#ifndef GLES2
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_iCurrentOutputFb);
#else
glBindFramebuffer(GL_FRAMEBUFFER, m_iCurrentOutputFb);
#endif
glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecSize.y);
end();
wlr_output_rollback(PMONITOR->output);
}
void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) {
RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!"); RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!");
const auto PWINDOW = *pWindow; const auto PWINDOW = *pWindow;
auto it = m_mWindowFramebuffers.begin(); auto it = m_mWindowFramebuffers.begin();
for (;it != m_mWindowFramebuffers.end(); it++) { for (; it != m_mWindowFramebuffers.end(); it++) {
if (it->first == PWINDOW) { if (it->first == PWINDOW) {
break; break;
} }
@ -724,6 +769,32 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) {
pixman_region32_fini(&fakeDamage); pixman_region32_fini(&fakeDamage);
} }
void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) {
RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!");
const auto PLAYER = *pLayer;
auto it = m_mLayerFramebuffers.begin();
for (; it != m_mLayerFramebuffers.end(); it++) {
if (it->first == PLAYER) {
break;
}
}
if (it == m_mLayerFramebuffers.end() || !it->second.m_cTex.m_iTexID)
return;
const auto PMONITOR = g_pCompositor->getMonitorFromID(PLAYER->monitorID);
wlr_box windowBox = {0, 0, PMONITOR->vecSize.x, PMONITOR->vecSize.y};
pixman_region32_t fakeDamage;
pixman_region32_init_rect(&fakeDamage, 0, 0, PMONITOR->vecSize.x, PMONITOR->vecSize.y);
renderTextureInternalWithDamage(it->second.m_cTex, &windowBox, PLAYER->alpha.fl(), &fakeDamage, 0);
pixman_region32_fini(&fakeDamage);
}
void CHyprOpenGLImpl::createBGTextureForMonitor(SMonitor* pMonitor) { void CHyprOpenGLImpl::createBGTextureForMonitor(SMonitor* pMonitor) {
RASSERT(m_RenderData.pMonitor, "Tried to createBGTex without begin()!"); RASSERT(m_RenderData.pMonitor, "Tried to createBGTex without begin()!");

View file

@ -60,7 +60,9 @@ public:
void renderBorder(wlr_box*, const CColor&, int thick = 1, int round = 0); void renderBorder(wlr_box*, const CColor&, int thick = 1, int round = 0);
void makeWindowSnapshot(CWindow*); void makeWindowSnapshot(CWindow*);
void makeLayerSnapshot(SLayerSurface*);
void renderSnapshot(CWindow**); void renderSnapshot(CWindow**);
void renderSnapshot(SLayerSurface**);
void clear(const CColor&); void clear(const CColor&);
void clearWithTex(); void clearWithTex();
@ -78,6 +80,7 @@ public:
pixman_region32_t m_rOriginalDamageRegion; // used for storing the pre-expanded region pixman_region32_t m_rOriginalDamageRegion; // used for storing the pre-expanded region
std::unordered_map<CWindow*, CFramebuffer> m_mWindowFramebuffers; std::unordered_map<CWindow*, CFramebuffer> m_mWindowFramebuffers;
std::unordered_map<SLayerSurface*, CFramebuffer> m_mLayerFramebuffers;
std::unordered_map<SMonitor*, SMonitorRenderData> m_mMonitorRenderResources; std::unordered_map<SMonitor*, SMonitorRenderData> m_mMonitorRenderResources;
std::unordered_map<SMonitor*, CTexture> m_mMonitorBGTextures; std::unordered_map<SMonitor*, CTexture> m_mMonitorBGTextures;

View file

@ -121,6 +121,17 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec*
} }
} }
void CHyprRenderer::renderLayer(SLayerSurface* pLayer, SMonitor* pMonitor, timespec* time) {
if (pLayer->fadingOut) {
g_pHyprOpenGL->renderSnapshot(&pLayer);
return;
}
SRenderData renderdata = {pMonitor->output, time, pLayer->geometry.x, pLayer->geometry.y};
renderdata.fadeAlpha = pLayer->alpha.fl();
wlr_surface_for_each_surface(pLayer->layerSurface->surface, renderSurface, &renderdata);
}
void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) { void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(ID); const auto PMONITOR = g_pCompositor->getMonitorFromID(ID);
@ -129,12 +140,10 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
// Render layer surfaces below windows for monitor // Render layer surfaces below windows for monitor
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) { for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) {
SRenderData renderdata = {PMONITOR->output, time, ls->geometry.x, ls->geometry.y}; renderLayer(ls, PMONITOR, time);
wlr_surface_for_each_surface(ls->layerSurface->surface, renderSurface, &renderdata);
} }
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) { for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) {
SRenderData renderdata = {PMONITOR->output, time, ls->geometry.x, ls->geometry.y}; renderLayer(ls, PMONITOR, time);
wlr_surface_for_each_surface(ls->layerSurface->surface, renderSurface, &renderdata);
} }
// if there is a fullscreen window, render it and then do not render anymore. // if there is a fullscreen window, render it and then do not render anymore.
@ -178,12 +187,10 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
// Render surfaces above windows for monitor // Render surfaces above windows for monitor
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
SRenderData renderdata = {PMONITOR->output, time, ls->geometry.x, ls->geometry.y}; renderLayer(ls, PMONITOR, time);
wlr_surface_for_each_surface(ls->layerSurface->surface, renderSurface, &renderdata);
} }
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) { for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) {
SRenderData renderdata = {PMONITOR->output, time, ls->geometry.x, ls->geometry.y}; renderLayer(ls, PMONITOR, time);
wlr_surface_for_each_surface(ls->layerSurface->surface, renderSurface, &renderdata);
} }
renderDragIcon(PMONITOR, time); renderDragIcon(PMONITOR, time);
@ -316,6 +323,9 @@ void CHyprRenderer::arrangeLayerArray(SMonitor* pMonitor, const std::list<SLayer
wlr_box full_area = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y}; wlr_box full_area = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y};
for (auto& ls : layerSurfaces) { for (auto& ls : layerSurfaces) {
if (ls->fadingOut)
continue;
const auto PLAYER = ls->layerSurface; const auto PLAYER = ls->layerSurface;
const auto PSTATE = &PLAYER->current; const auto PSTATE = &PLAYER->current;
if (exclusiveZone != (PSTATE->exclusive_zone > 0)) { if (exclusiveZone != (PSTATE->exclusive_zone > 0)) {

View file

@ -37,6 +37,7 @@ private:
void drawBorderForWindow(CWindow*, SMonitor*, float a = 255.f, const Vector2D& offset = Vector2D(0,0)); void drawBorderForWindow(CWindow*, SMonitor*, float a = 255.f, const Vector2D& offset = Vector2D(0,0));
void renderWorkspaceWithFullscreenWindow(SMonitor*, CWorkspace*, timespec*); void renderWorkspaceWithFullscreenWindow(SMonitor*, CWorkspace*, timespec*);
void renderWindow(CWindow*, SMonitor*, timespec*, bool); void renderWindow(CWindow*, SMonitor*, timespec*, bool);
void renderLayer(SLayerSurface*, SMonitor*, timespec*);
void renderDragIcon(SMonitor*, timespec*); void renderDragIcon(SMonitor*, timespec*);