implement ws scaling

This commit is contained in:
Vaxry 2024-08-24 20:29:31 +02:00
parent 66586c38f5
commit b509273759
5 changed files with 137 additions and 92 deletions

View file

@ -741,8 +741,6 @@ void CConfigManager::setDefaultAnimationVars() {
INITANIMCFG("fadeShadow"); INITANIMCFG("fadeShadow");
INITANIMCFG("fadeDim"); INITANIMCFG("fadeDim");
// border
// workspaces // workspaces
INITANIMCFG("workspaces"); INITANIMCFG("workspaces");
INITANIMCFG("workspacesIn"); INITANIMCFG("workspacesIn");
@ -777,6 +775,12 @@ void CConfigManager::setDefaultAnimationVars() {
CREATEANIMCFG("fadeLayers", "fade"); CREATEANIMCFG("fadeLayers", "fade");
CREATEANIMCFG("fadeLayersIn", "fadeLayers"); CREATEANIMCFG("fadeLayersIn", "fadeLayers");
CREATEANIMCFG("fadeLayersOut", "fadeLayers"); CREATEANIMCFG("fadeLayersOut", "fadeLayers");
CREATEANIMCFG("fadeWorkspaces", "fade");
CREATEANIMCFG("fadeWorkspacesIn", "fadeWorkspaces");
CREATEANIMCFG("fadeWorkspacesOut", "fadeWorkspaces");
CREATEANIMCFG("fadeSpecialWorkspace", "fadeWorkspaces");
CREATEANIMCFG("fadeSpecialWorkspaceIn", "fadeSpecialWorkspace");
CREATEANIMCFG("fadeSpecialWorkspaceOut", "fadeSpecialWorkspace");
CREATEANIMCFG("workspacesIn", "workspaces"); CREATEANIMCFG("workspacesIn", "workspaces");
CREATEANIMCFG("workspacesOut", "workspaces"); CREATEANIMCFG("workspacesOut", "workspaces");

View file

@ -26,12 +26,18 @@ void CWorkspace::init(PHLWORKSPACE self) {
g_pConfigManager->getAnimationPropertyConfig("workspacesIn"), g_pConfigManager->getAnimationPropertyConfig("workspacesIn"),
self, AVARDAMAGE_ENTIRE); self, AVARDAMAGE_ENTIRE);
m_fAlpha.create(AVARTYPE_FLOAT, m_fAlpha.create(AVARTYPE_FLOAT,
m_bIsSpecialWorkspace ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspaceIn") : g_pConfigManager->getAnimationPropertyConfig("workspacesIn"), self, m_bIsSpecialWorkspace ? g_pConfigManager->getAnimationPropertyConfig("fadeSpecialWorkspaceIn") :
AVARDAMAGE_ENTIRE); g_pConfigManager->getAnimationPropertyConfig("fadeWorkspacesIn"),
self, AVARDAMAGE_ENTIRE);
m_fAlpha.setValueAndWarp(1.f); m_fAlpha.setValueAndWarp(1.f);
m_fScaleClients.create(
AVARTYPE_FLOAT, m_bIsSpecialWorkspace ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspaceIn") : g_pConfigManager->getAnimationPropertyConfig("workspacesIn"),
self, AVARDAMAGE_ENTIRE);
m_fScaleClients.setValueAndWarp(1.f);
m_vRenderOffset.registerVar(); m_vRenderOffset.registerVar();
m_fAlpha.registerVar(); m_fAlpha.registerVar();
m_fScaleClients.registerVar();
const auto RULEFORTHIS = g_pConfigManager->getWorkspaceRuleFor(self); const auto RULEFORTHIS = g_pConfigManager->getWorkspaceRuleFor(self);
if (RULEFORTHIS.defaultName.has_value()) if (RULEFORTHIS.defaultName.has_value())
@ -83,13 +89,15 @@ CWorkspace::~CWorkspace() {
void CWorkspace::startAnim(bool in, bool left, bool instant) { void CWorkspace::startAnim(bool in, bool left, bool instant) {
if (!instant) { if (!instant) {
const std::string ANIMNAME = std::format("{}{}", m_bIsSpecialWorkspace ? "specialWorkspace" : "workspaces", in ? "In" : "Out"); const std::string ANIMNAME = std::format("{}{}", m_bIsSpecialWorkspace ? "specialWorkspace" : "workspaces", in ? "In" : "Out");
const std::string ANIMNAME2 = std::format("fade{}{}", m_bIsSpecialWorkspace ? "SpecialWorkspace" : "Workspaces", in ? "In" : "Out");
m_fAlpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig(ANIMNAME); m_fAlpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig(ANIMNAME2);
m_vRenderOffset.m_pConfig = g_pConfigManager->getAnimationPropertyConfig(ANIMNAME); m_vRenderOffset.m_pConfig = g_pConfigManager->getAnimationPropertyConfig(ANIMNAME);
m_fScaleClients.m_pConfig = g_pConfigManager->getAnimationPropertyConfig(ANIMNAME);
} }
const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle; const auto ANIMSTYLE = m_vRenderOffset.m_pConfig->pValues->internalStyle;
static auto PWORKSPACEGAP = CConfigValue<Hyprlang::INT>("general:gaps_workspaces"); static auto PWORKSPACEGAP = CConfigValue<Hyprlang::INT>("general:gaps_workspaces");
// set floating windows offset callbacks // set floating windows offset callbacks
@ -102,95 +110,71 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) {
}; };
}); });
if (ANIMSTYLE.starts_with("slidefade")) { m_fAlpha.setValueAndWarp(in ? 0.F : 1.F);
m_fAlpha = in ? 1.F : 0.F;
// handle animation styles for the movement one
if (ANIMSTYLE.starts_with("slide") && ANIMSTYLE.contains("%")) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
float movePerc = 100.f; float movePerc = 100.f;
if (ANIMSTYLE.find("%") != std::string::npos) { try {
try { auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' ') + 1);
auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' ') + 1); movePerc = std::stoi(percstr.substr(0, percstr.length() - 1));
movePerc = std::stoi(percstr.substr(0, percstr.length() - 1)); } catch (std::exception& e) { Debug::log(ERR, "Error in startAnim: invalid percentage"); }
} catch (std::exception& e) { Debug::log(ERR, "Error in startAnim: invalid percentage"); }
}
m_fAlpha.setValueAndWarp(1.f); m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
m_fScaleClients.setValueAndWarp(1.F);
if (ANIMSTYLE.starts_with("slidevert")) {
if (in) {
m_vRenderOffset.setValueAndWarp(Vector2D(0.0, (left ? PMONITOR->vecSize.y : -PMONITOR->vecSize.y) * (movePerc / 100.f)));
m_vRenderOffset = Vector2D(0, 0);
} else
m_vRenderOffset = Vector2D(0.0, (left ? -PMONITOR->vecSize.y : PMONITOR->vecSize.y) * (movePerc / 100.f));
} else {
if (in) {
m_vRenderOffset.setValueAndWarp(Vector2D((left ? PMONITOR->vecSize.x : -PMONITOR->vecSize.x) * (movePerc / 100.f), 0.0));
m_vRenderOffset = Vector2D(0, 0);
} else
m_vRenderOffset = Vector2D((left ? -PMONITOR->vecSize.x : PMONITOR->vecSize.x) * (movePerc / 100.f), 0.0);
}
} else if (ANIMSTYLE.starts_with("popin")) {
m_vRenderOffset.setValueAndWarp(Vector2D(0, 0)); m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
if (ANIMSTYLE.starts_with("slidefadevert")) { float startPerc = 100.f;
if (in) {
m_fAlpha.setValueAndWarp(0.f); try {
m_vRenderOffset.setValueAndWarp(Vector2D(0.0, (left ? PMONITOR->vecSize.y : -PMONITOR->vecSize.y) * (movePerc / 100.f))); auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' ') + 1);
m_fAlpha = 1.f; startPerc = std::stoi(percstr.substr(0, percstr.length() - 1));
m_vRenderOffset = Vector2D(0, 0); } catch (std::exception& e) { Debug::log(ERR, "Error in startAnim: invalid percentage"); }
} else {
m_fAlpha.setValueAndWarp(1.f);
m_fAlpha = 0.f;
m_vRenderOffset = Vector2D(0.0, (left ? -PMONITOR->vecSize.y : PMONITOR->vecSize.y) * (movePerc / 100.f));
}
} else {
if (in) {
m_fAlpha.setValueAndWarp(0.f);
m_vRenderOffset.setValueAndWarp(Vector2D((left ? PMONITOR->vecSize.x : -PMONITOR->vecSize.x) * (movePerc / 100.f), 0.0));
m_fAlpha = 1.f;
m_vRenderOffset = Vector2D(0, 0);
} else {
m_fAlpha.setValueAndWarp(1.f);
m_fAlpha = 0.f;
m_vRenderOffset = Vector2D((left ? -PMONITOR->vecSize.x : PMONITOR->vecSize.x) * (movePerc / 100.f), 0.0);
}
}
} else if (ANIMSTYLE == "fade") {
m_vRenderOffset.setValueAndWarp(Vector2D(0, 0)); // fix a bug, if switching from slide -> fade.
if (in) { if (in) {
m_fAlpha.setValueAndWarp(0.f); m_fScaleClients.setValueAndWarp(startPerc / 100.F);
m_fAlpha = 1.f; m_fScaleClients = 1.F;
} else { } else {
m_fAlpha.setValueAndWarp(1.f); m_fScaleClients.setValueAndWarp(1.F);
m_fAlpha = 0.f; m_fScaleClients = startPerc / 100.F;
}
} else if (ANIMSTYLE == "slidevert") {
// fallback is slide
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
const auto YDISTANCE = PMONITOR->vecSize.y + *PWORKSPACEGAP;
m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide.
if (in) {
m_vRenderOffset.setValueAndWarp(Vector2D(0.0, left ? YDISTANCE : -YDISTANCE));
m_vRenderOffset = Vector2D(0, 0);
} else {
m_vRenderOffset = Vector2D(0.0, left ? -YDISTANCE : YDISTANCE);
} }
} else { } else {
// fallback is slide // fallback is slide
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
const auto XDISTANCE = PMONITOR->vecSize.x + *PWORKSPACEGAP; const auto XDISTANCE = PMONITOR->vecSize.x + *PWORKSPACEGAP;
m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide. m_fScaleClients.setValueAndWarp(1.F);
if (in) { if (in) {
m_vRenderOffset.setValueAndWarp(Vector2D(left ? XDISTANCE : -XDISTANCE, 0.0)); m_vRenderOffset.setValueAndWarp(Vector2D(left ? XDISTANCE : -XDISTANCE, 0.0));
m_vRenderOffset = Vector2D(0, 0); m_vRenderOffset = Vector2D(0, 0);
} else { } else
m_vRenderOffset = Vector2D(left ? -XDISTANCE : XDISTANCE, 0.0); m_vRenderOffset = Vector2D(left ? -XDISTANCE : XDISTANCE, 0.0);
}
}
if (m_bIsSpecialWorkspace) {
// required for open/close animations
if (in) {
m_fAlpha.setValueAndWarp(0.f);
m_fAlpha = 1.f;
} else {
m_fAlpha.setValueAndWarp(1.f);
m_fAlpha = 0.f;
}
} }
if (instant) { if (instant) {
m_vRenderOffset.warp(); m_vRenderOffset.warp();
m_fAlpha.warp(); m_fAlpha.warp();
m_fScaleClients.warp();
} }
} }

View file

@ -39,6 +39,7 @@ class CWorkspace {
// for animations // for animations
CAnimatedVariable<Vector2D> m_vRenderOffset; CAnimatedVariable<Vector2D> m_vRenderOffset;
CAnimatedVariable<float> m_fAlpha; CAnimatedVariable<float> m_fAlpha;
CAnimatedVariable<float> m_fScaleClients;
bool m_bForceRendering = false; bool m_bForceRendering = false;
// allows damage to propagate. // allows damage to propagate.

View file

@ -472,9 +472,9 @@ std::string CAnimationManager::styleValidInConfigVar(const std::string& config,
return "unknown style"; return "unknown style";
} else if (config.starts_with("workspaces") || config.starts_with("specialWorkspace")) { } else if (config.starts_with("workspaces") || config.starts_with("specialWorkspace")) {
if (style == "slide" || style == "slidevert" || style == "fade") if (style == "slide" || style == "slidevert")
return ""; return "";
else if (style.starts_with("slidefade")) { else if (style.starts_with("slide") || style.starts_with("popin")) {
// try parsing // try parsing
float movePerc = 0.f; float movePerc = 0.f;
if (style.find("%") != std::string::npos) { if (style.find("%") != std::string::npos) {

View file

@ -437,6 +437,17 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS);
// TODO: dedup this with renderallclients
auto preWorkspaceScaleAnim = []() { g_pHyprOpenGL->bindOffMain(); };
auto postWorkspaceScaleAnim = [pMonitor](PHLWORKSPACE workspace) {
g_pHyprOpenGL->bindBackOnMain();
CBox box = CBox{{}, pMonitor->vecPixelSize}.scaleFromCenter(workspace->m_fScaleClients.value());
g_pHyprOpenGL->renderTexture(g_pHyprOpenGL->m_RenderData.pCurrentMonData->offMainFB.m_cTex, &box, 1.F);
};
std::unordered_map<PHLWORKSPACE, std::vector<std::pair<PHLWINDOW, eRenderPassMode>>> toRender;
// Non-floating main // Non-floating main
for (auto& w : g_pCompositor->m_vWindows) { for (auto& w : g_pCompositor->m_vWindows) {
if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut)) if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut))
@ -457,12 +468,11 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
continue; continue;
} }
// render the bad boy toRender[w->m_pWorkspace].emplace_back(w, RENDER_PASS_MAIN);
renderWindow(w, pMonitor, time, true, RENDER_PASS_MAIN);
} }
if (lastWindow) if (lastWindow)
renderWindow(lastWindow, pMonitor, time, true, RENDER_PASS_MAIN); toRender[lastWindow->m_pWorkspace].emplace_back(lastWindow, RENDER_PASS_MAIN);
// Non-floating popup // Non-floating popup
for (auto& w : g_pCompositor->m_vWindows) { for (auto& w : g_pCompositor->m_vWindows) {
@ -478,8 +488,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
if (!shouldRenderWindow(w, pMonitor)) if (!shouldRenderWindow(w, pMonitor))
continue; continue;
// render the bad boy toRender[w->m_pWorkspace].emplace_back(w, RENDER_PASS_POPUP);
renderWindow(w, pMonitor, time, true, RENDER_PASS_POPUP);
} }
// floating on top // floating on top
@ -499,9 +508,39 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID) if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID)
continue; // special on another are rendered as a part of the base pass continue; // special on another are rendered as a part of the base pass
// render the bad boy toRender[w->m_pWorkspace].emplace_back(w, RENDER_PASS_ALL);
renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL);
} }
// firstly, render all workspaces in sync, but leave out main workspace
for (auto& [k, v] : toRender) {
if (k == pWorkspace)
continue;
const bool SCALE = k->m_fScaleClients.value() != 1.F && g_pCompositor->getWindowsOnWorkspace(k->m_iID) > 0;
if (SCALE)
preWorkspaceScaleAnim();
for (auto& [window, mode] : v) {
renderWindow(window, pMonitor, time, true, mode);
}
if (SCALE)
postWorkspaceScaleAnim(k);
}
const bool SCALE = pWorkspace->m_fScaleClients.value() != 1.F && g_pCompositor->getWindowsOnWorkspace(pWorkspace->m_iID) > 0;
if (SCALE)
preWorkspaceScaleAnim();
// lastly, render the current ws
for (auto& [window, mode] : toRender[pWorkspace]) {
renderWindow(window, pMonitor, time, true, mode);
}
if (SCALE)
postWorkspaceScaleAnim(pWorkspace);
} }
void CHyprRenderer::renderWindow(PHLWINDOW pWindow, CMonitor* pMonitor, timespec* time, bool decorate, eRenderPassMode mode, bool ignorePosition, bool ignoreAllGeometry) { void CHyprRenderer::renderWindow(PHLWINDOW pWindow, CMonitor* pMonitor, timespec* time, bool decorate, eRenderPassMode mode, bool ignorePosition, bool ignoreAllGeometry) {
@ -813,11 +852,19 @@ void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, CMon
} }
void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time, const Vector2D& translate, const float& scale) { void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time, const Vector2D& translate, const float& scale) {
static auto PDIMSPECIAL = CConfigValue<Hyprlang::FLOAT>("decoration:dim_special"); static auto PDIMSPECIAL = CConfigValue<Hyprlang::FLOAT>("decoration:dim_special");
static auto PBLURSPECIAL = CConfigValue<Hyprlang::INT>("decoration:blur:special"); static auto PBLURSPECIAL = CConfigValue<Hyprlang::INT>("decoration:blur:special");
static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled"); static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled");
static auto PRENDERTEX = CConfigValue<Hyprlang::INT>("misc:disable_hyprland_logo"); static auto PRENDERTEX = CConfigValue<Hyprlang::INT>("misc:disable_hyprland_logo");
static auto PBACKGROUNDCOLOR = CConfigValue<Hyprlang::INT>("misc:background_color"); static auto PBACKGROUNDCOLOR = CConfigValue<Hyprlang::INT>("misc:background_color");
auto preWorkspaceScaleAnim = []() { g_pHyprOpenGL->bindOffMain(); };
auto postWorkspaceScaleAnim = [pMonitor](PHLWORKSPACE workspace) {
g_pHyprOpenGL->bindBackOnMain();
CBox box = CBox{{}, pMonitor->vecPixelSize}.scaleFromCenter(workspace->m_fScaleClients.value());
g_pHyprOpenGL->renderTexture(g_pHyprOpenGL->m_RenderData.pCurrentMonData->offMainFB.m_cTex, &box, 1.F);
};
SRenderModifData RENDERMODIFDATA; SRenderModifData RENDERMODIFDATA;
if (translate != Vector2D{0, 0}) if (translate != Vector2D{0, 0})
@ -936,12 +983,21 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC
// special // special
for (auto& ws : g_pCompositor->m_vWorkspaces) { for (auto& ws : g_pCompositor->m_vWorkspaces) {
if (ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { if (ws->m_fAlpha.value() <= 0.F || !ws->m_bIsSpecialWorkspace)
if (ws->m_bHasFullscreenWindow) continue;
renderWorkspaceWindowsFullscreen(pMonitor, ws, time);
else const bool SCALE = ws->m_fScaleClients.value() != 1.F && g_pCompositor->getWindowsOnWorkspace(ws->m_iID) > 0;
renderWorkspaceWindows(pMonitor, ws, time);
} if (SCALE)
preWorkspaceScaleAnim();
if (ws->m_bHasFullscreenWindow)
renderWorkspaceWindowsFullscreen(pMonitor, ws, time);
else
renderWorkspaceWindows(pMonitor, ws, time);
if (SCALE)
postWorkspaceScaleAnim(ws);
} }
// pinned always above // pinned always above
@ -1316,7 +1372,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
EMIT_HOOK_EVENT("render", RENDER_POST_MIRROR); EMIT_HOOK_EVENT("render", RENDER_POST_MIRROR);
renderCursor = false; renderCursor = false;
} else { } else {
CBox renderBox = {0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y}; CBox renderBox = CBox{0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y};
renderWorkspace(pMonitor, pMonitor->activeWorkspace, &now, renderBox); renderWorkspace(pMonitor, pMonitor->activeWorkspace, &now, renderBox);
renderLockscreen(pMonitor, &now, renderBox); renderLockscreen(pMonitor, &now, renderBox);