From 870471dd96724474869d2e648b623c17df12fb57 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:05:08 +0200 Subject: [PATCH] internal: allow opening empty special workspaces Fixes point 2 of #2596 --- src/Compositor.cpp | 20 +++++++++++++------- src/events/Windows.cpp | 6 ++++-- src/helpers/Workspace.cpp | 15 ++++++++++++--- src/managers/KeybindManager.cpp | 10 ++-------- src/render/Renderer.cpp | 33 ++++++++++++++++----------------- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 511ae3bcf..ef611d8d2 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1145,14 +1145,20 @@ void CCompositor::sanityCheckWorkspaces() { const auto WINDOWSONWORKSPACE = getWindowsOnWorkspace((*it)->m_iID); - if ((*it)->m_bIsSpecialWorkspace && WINDOWSONWORKSPACE == 0) { - getMonitorFromID((*it)->m_iMonitorID)->setSpecialWorkspace(nullptr); - - it = m_vWorkspaces.erase(it); - continue; - } - if ((WINDOWSONWORKSPACE == 0 && !isWorkspaceVisible((*it)->m_iID))) { + + if ((*it)->m_bIsSpecialWorkspace) { + if ((*it)->m_fAlpha.fl() > 0.f /* don't abruptly end the fadeout */) { + ++it; + continue; + } + + const auto PMONITOR = getMonitorFromID((*it)->m_iMonitorID); + + if (PMONITOR && PMONITOR->specialWorkspaceID == (*it)->m_iID) + PMONITOR->setSpecialWorkspace(nullptr); + } + it = m_vWorkspaces.erase(it); continue; } diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 02ccd9505..c1f3c4db0 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -142,10 +142,12 @@ void Events::listener_mapWindow(void* owner, void* data) { } } - PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)->activeWorkspace; + const auto PMONITORFROMID = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + + PWINDOW->m_iWorkspaceID = PMONITOR->specialWorkspaceID ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; if (PWINDOW->m_iMonitorID != PMONITOR->ID) { g_pKeybindManager->m_mDispatchers["focusmonitor"](std::to_string(PWINDOW->m_iMonitorID)); - PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + PMONITOR = PMONITORFROMID; } Debug::log(ERR, "Rule monitor, applying to window %lx -> mon: %i, workspace: %i", PWINDOW, PWINDOW->m_iMonitorID, PWINDOW->m_iWorkspaceID); diff --git a/src/helpers/Workspace.cpp b/src/helpers/Workspace.cpp index eddd21432..09149ec80 100644 --- a/src/helpers/Workspace.cpp +++ b/src/helpers/Workspace.cpp @@ -66,9 +66,7 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) { try { auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' ') + 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); @@ -133,6 +131,17 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) { } } + 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) { m_vRenderOffset.warp(); m_fAlpha.warp(); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9614774ac..81a2aaf5e 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1515,12 +1515,8 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { return; } - if (g_pCompositor->getWindowsOnWorkspace(workspaceID) == 0) { - Debug::log(LOG, "Can't open empty special workspace!"); - return; - } - bool requestedWorkspaceIsAlreadyOpen = false; + bool requestedWorkspaceExists = g_pCompositor->getWorkspaceByID(workspaceID); const auto PMONITOR = *PFOLLOWMOUSE == 1 ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->m_pLastMonitor; int specialOpenOnMonitor = PMONITOR->specialWorkspaceID; @@ -1566,10 +1562,8 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { // not open anywhere auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceID); - if (!PSPECIALWORKSPACE) { - // ??? happens sometimes...? + if (!PSPECIALWORKSPACE) PSPECIALWORKSPACE = g_pCompositor->createNewWorkspace(workspaceID, PMONITOR->ID, workspaceName); - } PMONITOR->setSpecialWorkspace(PSPECIALWORKSPACE); } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 0105780dd..4adae0f7c 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -594,22 +594,10 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* } // and then special - bool renderedSpecialBG = false; - for (auto& w : g_pCompositor->m_vWindows) { - if (w->isHidden() && !w->m_bIsMapped && !w->m_bFadingOut) - continue; - - if (!g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) - continue; - - if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) - continue; - - if (!renderedSpecialBG) { - const auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID); - const auto SPECIALANIMPROGRS = - PSPECIALWORKSPACE->m_vRenderOffset.isBeingAnimated() ? PSPECIALWORKSPACE->m_vRenderOffset.getCurveValue() : PSPECIALWORKSPACE->m_fAlpha.getCurveValue(); - const bool ANIMOUT = !pMonitor->specialWorkspaceID; + for (auto& ws : g_pCompositor->m_vWorkspaces) { + if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.fl() > 0.f && ws->m_bIsSpecialWorkspace) { + const auto SPECIALANIMPROGRS = ws->m_vRenderOffset.isBeingAnimated() ? ws->m_vRenderOffset.getCurveValue() : ws->m_fAlpha.getCurveValue(); + const bool ANIMOUT = !pMonitor->specialWorkspaceID; if (*PDIMSPECIAL != 0.f) { wlr_box monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; @@ -621,8 +609,19 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* g_pHyprOpenGL->renderRectWithBlur(&monbox, CColor(0, 0, 0, 0), 0, (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS)); } - renderedSpecialBG = true; + break; } + } + + for (auto& w : g_pCompositor->m_vWindows) { + if (w->isHidden() && !w->m_bIsMapped && !w->m_bFadingOut) + continue; + + if (!g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + continue; + + if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + continue; // render the bad boy renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_ALL);