fadein and prep for fadeout

This commit is contained in:
vaxerski 2022-04-05 19:28:10 +02:00
parent f5562941f7
commit f8e0b0b448
11 changed files with 63 additions and 10 deletions

View File

@ -230,7 +230,7 @@ SMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
}
void CCompositor::removeWindowFromVectorSafe(CWindow* pWindow) {
if (windowExists(pWindow))
if (windowExists(pWindow) && !pWindow->m_bFadingOut)
m_lWindows.remove(*pWindow);
}
@ -553,3 +553,14 @@ void CCompositor::moveWindowToTop(CWindow* pWindow) {
}
}
}
void CCompositor::cleanupWindows() {
for (auto& w : m_lWindowsFadingOut) {
if (!w->m_bFadingOut || w->m_fAlpha == 0.f) {
m_lWindows.remove(*w);
m_lWindowsFadingOut.remove(w);
Debug::log(LOG, "Cleanup: cleaned up a window");
return;
}
}
}

View File

@ -58,6 +58,7 @@ public:
std::list<SXDGPopup> m_lXDGPopups;
std::list<SWorkspace> m_lWorkspaces;
std::list<SSubsurface> m_lSubsurfaces;
std::list<CWindow*> m_lWindowsFadingOut;
void startCompositor();
@ -97,6 +98,7 @@ public:
bool doesSeatAcceptInput(wlr_surface*);
bool isWindowActive(CWindow*);
void moveWindowToTop(CWindow*);
void cleanupWindows();
private:
void initAllSignals();

View File

@ -68,6 +68,10 @@ public:
// Animated border
CColor m_cRealBorderColor = CColor(0,0,0,0);
// Fade in-out
float m_fAlpha = 0.f;
bool m_bFadingOut = false;
// For the list lookup
bool operator==(const CWindow& rhs) {

View File

@ -104,6 +104,7 @@ void Events::listener_monitorFrame(void* owner, void* data) {
if (PMONITOR->ID == 0) {
g_pCompositor->sanityCheckWorkspaces();
g_pAnimationManager->tick();
g_pCompositor->cleanupWindows();
}
timespec now;

View File

@ -191,6 +191,10 @@ void Events::listener_unmapWindow(void* owner, void* data) {
SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree);
PWINDOW->m_pSurfaceTree = nullptr;
PWINDOW->m_bFadingOut = true;
g_pCompositor->m_lWindowsFadingOut.push_back(PWINDOW);
}
void Events::listener_commitWindow(void* owner, void* data) {

View File

@ -42,6 +42,9 @@ struct SRenderData {
// for rounding
bool dontRound = true;
// for fade
float fadeAlpha = 255.f;
};
struct SKeyboard {

View File

@ -259,6 +259,10 @@ void CHyprDwindleLayout::onWindowRemoved(CWindow* pWindow) {
m_lDwindleNodesData.remove(*PPARENT);
m_lDwindleNodesData.remove(*PNODE);
// jump back like it jumps in
pWindow->m_vEffectivePosition = pWindow->m_vEffectivePosition + ((pWindow->m_vEffectiveSize - Vector2D(5, 5)) * 0.5f);
pWindow->m_vEffectiveSize = Vector2D(5, 5);
}
void CHyprDwindleLayout::recalculateMonitor(const int& monid) {

View File

@ -10,18 +10,43 @@ void CAnimationManager::tick() {
const bool WINDOWSENABLED = g_pConfigManager->getInt("animations:windows") && !animationsDisabled;
const bool BORDERSENABLED = g_pConfigManager->getInt("animations:borders") && !animationsDisabled;
// const bool FADEENABLED = g_pConfigManager->getInt("animations:fadein") && !animationsDisabled;
const bool FADEENABLED = g_pConfigManager->getInt("animations:fadein") && !animationsDisabled;
const float ANIMSPEED = g_pConfigManager->getFloat("animations:speed");
// Process speeds
const float WINDOWSPEED = g_pConfigManager->getFloat("animations:windows_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:windows_speed");
const float BORDERSPEED = g_pConfigManager->getFloat("animations:borders_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:borders_speed");
const float FADESPEED = g_pConfigManager->getFloat("animations:fadein_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:fadein_speed");
const auto BORDERACTIVECOL = CColor(g_pConfigManager->getInt("general:col.active_border"));
const auto BORDERINACTIVECOL = CColor(g_pConfigManager->getInt("general:col.inactive_border"));
for (auto& w : g_pCompositor->m_lWindows) {
// process fadeinout
if (FADEENABLED) {
const auto GOALALPHA = w.m_bIsMapped ? 255.f : 0.f;
w.m_bFadingOut = false;
if (!deltazero(w.m_fAlpha, GOALALPHA)) {
if (deltaSmallToFlip(w.m_fAlpha, GOALALPHA)) {
w.m_fAlpha = GOALALPHA;
} else {
if (w.m_fAlpha > GOALALPHA)
w.m_bFadingOut = true;
w.m_fAlpha = parabolic(w.m_fAlpha, GOALALPHA, FADESPEED);
}
}
} else {
if (w.m_bIsMapped)
w.m_fAlpha = 255.f;
else {
w.m_fAlpha = 0.f;
w.m_bFadingOut = false;
}
}
// process the borders
const auto& COLOR = g_pCompositor->isWindowActive(&w) ? BORDERACTIVECOL : BORDERINACTIVECOL;

View File

@ -114,9 +114,6 @@ void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) {
} else {
wlr_xdg_toplevel_send_close(pWindow->m_uSurface.xdg->toplevel);
}
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow);
g_pCompositor->removeWindowFromVectorSafe(pWindow);
}
void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, const Vector2D& size) {

View File

@ -31,7 +31,7 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
float matrix[9];
wlr_matrix_project_box(matrix, &windowBox, TRANSFORM, 0, RDATA->output->transform_matrix);
g_pHyprOpenGL->renderTexture(TEXTURE, matrix, 255.f, RDATA->dontRound ? 0 : g_pConfigManager->getInt("decoration:rounding")); // TODO: fadeinout
g_pHyprOpenGL->renderTexture(TEXTURE, matrix, RDATA->fadeAlpha, RDATA->dontRound ? 0 : g_pConfigManager->getInt("decoration:rounding")); // TODO: fadeinout
wlr_surface_send_frame_done(surface, RDATA->when);
@ -88,12 +88,13 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec*
renderdata.w = pWindow->m_vRealSize.x;
renderdata.h = pWindow->m_vRealSize.y;
renderdata.dontRound = false;
renderdata.fadeAlpha = pWindow->m_fAlpha;
wlr_surface_for_each_surface(g_pXWaylandManager->getWindowSurface(pWindow), renderSurface, &renderdata);
// border
if (decorate && !pWindow->m_bX11DoesntWantBorders)
drawBorderForWindow(pWindow, pMonitor);
drawBorderForWindow(pWindow, pMonitor, pWindow->m_fAlpha);
if (pWindow->m_bIsX11) {
if (pWindow->m_uSurface.xwayland->surface) {
@ -394,13 +395,14 @@ void CHyprRenderer::arrangeLayersForMonitor(const int& monitor) {
Debug::log(LOG, "Monitor %s layers arranged: reserved: %f %f %f %f", PMONITOR->szName.c_str(), PMONITOR->vecReservedTopLeft.x, PMONITOR->vecReservedTopLeft.y, PMONITOR->vecReservedBottomRight.x, PMONITOR->vecReservedBottomRight.y);
}
void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor) {
void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor, float alpha) {
const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size");
if (BORDERSIZE < 1)
return;
const auto BORDERCOL = pWindow->m_cRealBorderColor;
auto BORDERCOL = pWindow->m_cRealBorderColor;
BORDERCOL.a *= (alpha / 255.f);
Vector2D correctPos = pWindow->m_vRealPosition - pMonitor->vecPosition;
Vector2D correctSize = pWindow->m_vRealSize;

View File

@ -16,7 +16,7 @@ public:
private:
void arrangeLayerArray(SMonitor*, const std::list<SLayerSurface*>&, bool, wlr_box*);
void drawBorderForWindow(CWindow*, SMonitor*);
void drawBorderForWindow(CWindow*, SMonitor*, float a = 255.f);
void renderWorkspaceWithFullscreenWindow(SMonitor*, SWorkspace*, timespec*);
void renderWindow(CWindow*, SMonitor*, timespec*, bool);
void renderDragIcon(SMonitor*, timespec*);