diff options
author | vaxerski <[email protected]> | 2022-04-23 14:16:02 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-04-23 14:16:02 +0200 |
commit | 0147975faf939db389bebaa95e3a12e5e5a8753f (patch) | |
tree | c6933763435812460ebdc9609ed90eae21110753 | |
parent | fa38dfd416b664033a96bb4af764fd54f7257d7b (diff) | |
download | Hyprland-0147975faf939db389bebaa95e3a12e5e5a8753f.tar.gz Hyprland-0147975faf939db389bebaa95e3a12e5e5a8753f.zip |
New animation system
-rw-r--r-- | src/Compositor.cpp | 52 | ||||
-rw-r--r-- | src/Window.cpp | 7 | ||||
-rw-r--r-- | src/Window.hpp | 13 | ||||
-rw-r--r-- | src/config/ConfigManager.cpp | 4 | ||||
-rw-r--r-- | src/config/ConfigManager.hpp | 4 | ||||
-rw-r--r-- | src/debug/HyprCtl.cpp | 4 | ||||
-rw-r--r-- | src/events/Windows.cpp | 15 | ||||
-rw-r--r-- | src/helpers/AnimatedVariable.cpp | 54 | ||||
-rw-r--r-- | src/helpers/AnimatedVariable.hpp | 131 | ||||
-rw-r--r-- | src/layout/DwindleLayout.cpp | 78 | ||||
-rw-r--r-- | src/managers/AnimationManager.cpp | 142 | ||||
-rw-r--r-- | src/managers/AnimationManager.hpp | 3 | ||||
-rw-r--r-- | src/managers/InputManager.cpp | 12 | ||||
-rw-r--r-- | src/managers/KeybindManager.cpp | 20 | ||||
-rw-r--r-- | src/managers/XWaylandManager.cpp | 4 | ||||
-rw-r--r-- | src/render/OpenGL.cpp | 2 | ||||
-rw-r--r-- | src/render/Renderer.cpp | 22 |
17 files changed, 384 insertions, 183 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 0e07829f..02463c27 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -281,13 +281,13 @@ CWindow* CCompositor::vectorToWindow(const Vector2D& pos) { const auto PMONITOR = getMonitorFromVector(pos); // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y}; + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; if (wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bHidden) return &(*w); } for (auto& w : m_lWindows) { - wlr_box box = {w.m_vRealPosition.x, w.m_vRealPosition.y, w.m_vRealSize.x, w.m_vRealSize.y}; + wlr_box box = {w.m_vRealPosition.vec().x, w.m_vRealPosition.vec().y, w.m_vRealSize.vec().x, w.m_vRealSize.vec().y}; if (wlr_box_contains_point(&box, pos.x, pos.y) && w.m_bIsMapped && !w.m_bIsFloating && PMONITOR->activeWorkspace == w.m_iWorkspaceID && !w.m_bHidden) return &w; } @@ -310,7 +310,7 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) { const auto PMONITOR = getMonitorFromVector(pos); // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y}; + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; if (w->m_bIsFloating && w->m_bIsMapped && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bHidden) return &(*w); } @@ -329,7 +329,7 @@ CWindow* CCompositor::windowFromCursor() { // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y}; + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID)) return &(*w); } @@ -345,7 +345,7 @@ CWindow* CCompositor::windowFromCursor() { CWindow* CCompositor::windowFloatingFromCursor() { for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y}; + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bHidden) return &(*w); } @@ -364,7 +364,7 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW double subx, suby; - const auto PFOUND = wlr_xdg_surface_surface_at(PSURFACE, pos.x - pWindow->m_vRealPosition.x, pos.y - pWindow->m_vRealPosition.y, &subx, &suby); + const auto PFOUND = wlr_xdg_surface_surface_at(PSURFACE, pos.x - pWindow->m_vRealPosition.vec().x, pos.y - pWindow->m_vRealPosition.vec().y, &subx, &suby); if (PFOUND) { sl.x = subx; @@ -372,8 +372,8 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW return PFOUND; } - sl.x = pos.x - pWindow->m_vRealPosition.x; - sl.y = pos.y - pWindow->m_vRealPosition.y; + sl.x = pos.x - pWindow->m_vRealPosition.vec().x; + sl.y = pos.y - pWindow->m_vRealPosition.vec().y; return PSURFACE->surface; } @@ -403,22 +403,40 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { if (m_pLastWindow == pWindow && m_sSeat.seat->keyboard_state.focused_surface == pSurface) return; - if (windowValidMapped(m_pLastWindow) && m_pLastWindow->m_bIsX11) { - wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat); - wlr_seat_pointer_clear_focus(m_sSeat.seat); + const auto PLASTWINDOW = m_pLastWindow; + m_pLastWindow = pWindow; + + // we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window + if (windowValidMapped(PLASTWINDOW)) { + const auto RENDERDATA = g_pLayoutManager->getCurrentLayout()->requestRenderHints(PLASTWINDOW); + if (RENDERDATA.isBorderColor) + PLASTWINDOW->m_cRealBorderColor = RENDERDATA.borderColor; + else + PLASTWINDOW->m_cRealBorderColor = CColor(g_pConfigManager->getInt("general:col.inactive_border")); + + if (PLASTWINDOW->m_bIsX11) { + wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat); + wlr_seat_pointer_clear_focus(m_sSeat.seat); + } } + m_pLastWindow = PLASTWINDOW; + const auto PWINDOWSURFACE = pSurface ? pSurface : g_pXWaylandManager->getWindowSurface(pWindow); focusSurface(PWINDOWSURFACE, pWindow); - g_pXWaylandManager->activateWindow(pWindow, true); + g_pXWaylandManager->activateWindow(pWindow, true); // sets the m_pLastWindow // do pointer focus too - const auto POINTERLOCAL = g_pInputManager->getMouseCoordsInternal() - pWindow->m_vRealPosition; + const auto POINTERLOCAL = g_pInputManager->getMouseCoordsInternal() - pWindow->m_vEffectivePosition; wlr_seat_pointer_notify_enter(m_sSeat.seat, PWINDOWSURFACE, POINTERLOCAL.x, POINTERLOCAL.y); - m_pLastWindow = pWindow; + const auto RENDERDATA = g_pLayoutManager->getCurrentLayout()->requestRenderHints(pWindow); + if (RENDERDATA.isBorderColor) + pWindow->m_cRealBorderColor = RENDERDATA.borderColor; + else + pWindow->m_cRealBorderColor = CColor(g_pConfigManager->getInt("general:col.active_border")); } void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) { @@ -570,7 +588,7 @@ void CCompositor::fixXWaylandWindowsOnWorkspace(const int& id) { // so there is no need to check here // if the window is XWayland or not. if (ISVISIBLE && (!PWORKSPACE->m_bHasFullscreenWindow || w.m_bIsFullscreen)) - g_pXWaylandManager->moveXWaylandWindow(&w, w.m_vRealPosition); + g_pXWaylandManager->moveXWaylandWindow(&w, w.m_vRealPosition.vec()); else g_pXWaylandManager->moveXWaylandWindow(&w, Vector2D(42069,42069)); } @@ -604,7 +622,7 @@ void CCompositor::moveWindowToTop(CWindow* pWindow) { void CCompositor::cleanupWindows() { for (auto& w : m_lWindowsFadingOut) { - if (!w->m_bFadingOut || w->m_fAlpha == 0.f) { + if (!w->m_bFadingOut || w->m_fAlpha.fl() == 0.f) { if (!w->m_bReadyToDelete) continue; @@ -742,4 +760,4 @@ CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) { } return nullptr; -}
\ No newline at end of file +} diff --git a/src/Window.cpp b/src/Window.cpp index ff8ba299..a2a1aae8 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -1,6 +1,13 @@ #include "Window.hpp" #include "Compositor.hpp" +CWindow::CWindow() { + m_vRealPosition.create(AVARTYPE_VECTOR, &g_pConfigManager->getConfigValuePtr("animations:windows_speed")->floatValue, &g_pConfigManager->getConfigValuePtr("animations:windows")->intValue, (void*)this); + m_vRealSize.create(AVARTYPE_VECTOR, &g_pConfigManager->getConfigValuePtr("animations:windows_speed")->floatValue, &g_pConfigManager->getConfigValuePtr("animations:windows")->intValue, (void*)this); + m_cRealBorderColor.create(AVARTYPE_COLOR, &g_pConfigManager->getConfigValuePtr("animations:borders_speed")->floatValue, &g_pConfigManager->getConfigValuePtr("animations:borders")->intValue, (void*)this); + m_fAlpha.create(AVARTYPE_FLOAT, &g_pConfigManager->getConfigValuePtr("animations:fadein_speed")->floatValue, &g_pConfigManager->getConfigValuePtr("animations:fadein")->intValue, (void*)this); +} + CWindow::~CWindow() { if (g_pCompositor->isWindowActive(this)) { g_pCompositor->m_pLastFocus = nullptr; diff --git a/src/Window.hpp b/src/Window.hpp index 6969213a..ccd4efcf 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -3,6 +3,7 @@ #include "defines.hpp" #include "events/Events.hpp" #include "helpers/SubsurfaceTree.hpp" +#include "helpers/AnimatedVariable.hpp" struct SWindowSpecialRenderData { float alpha = 1.f; @@ -10,7 +11,7 @@ struct SWindowSpecialRenderData { class CWindow { public: - + CWindow(); ~CWindow(); DYNLISTENER(commitWindow); @@ -36,8 +37,8 @@ public: Vector2D m_vEffectiveSize = Vector2D(0,0); // this is the real position and size used to draw the thing - Vector2D m_vRealPosition = Vector2D(0,0); - Vector2D m_vRealSize = Vector2D(0,0); + CAnimatedVariable m_vRealPosition; + CAnimatedVariable m_vRealSize; // this is used for pseudotiling bool m_bIsPseudotiled = false; @@ -69,10 +70,10 @@ public: SSurfaceTreeNode* m_pSurfaceTree = nullptr; // Animated border - CColor m_cRealBorderColor = CColor(0,0,0,0); + CAnimatedVariable m_cRealBorderColor; // Fade in-out - float m_fAlpha = 0.f; + CAnimatedVariable m_fAlpha; bool m_bFadingOut = false; bool m_bReadyToDelete = false; @@ -84,7 +85,7 @@ public: // For the list lookup bool operator==(const CWindow& rhs) { - return m_uSurface.xdg == rhs.m_uSurface.xdg && m_uSurface.xwayland == rhs.m_uSurface.xwayland && m_vPosition == rhs.m_vPosition && m_vSize == rhs.m_vSize && m_fAlpha == rhs.m_fAlpha && m_bFadingOut == rhs.m_bFadingOut; + return m_uSurface.xdg == rhs.m_uSurface.xdg && m_uSurface.xwayland == rhs.m_uSurface.xwayland && m_vPosition == rhs.m_vPosition && m_vSize == rhs.m_vSize && m_bFadingOut == rhs.m_bFadingOut; } };
\ No newline at end of file diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f321651c..49af08b8 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -606,3 +606,7 @@ void CConfigManager::performMonitorReload() { m_bWantsMonitorReload = false; } + +SConfigValue* CConfigManager::getConfigValuePtr(std::string val) { + return &configValues[val]; +}
\ No newline at end of file diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 044b9751..19d602fa 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -1,5 +1,7 @@ #pragma once +#define CONFIG_MANAGER_H + #include <map> #include "../debug/Log.hpp" #include <unordered_map> @@ -47,6 +49,8 @@ public: void setInt(std::string, int); void setString(std::string, std::string); + SConfigValue* getConfigValuePtr(std::string); + SMonitorRule getMonitorRuleFor(std::string); std::vector<SWindowRule> getMatchingRules(CWindow*); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index a3a91cca..fab67969 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -26,7 +26,7 @@ std::string clientsRequest() { std::string result = ""; for (auto& w : g_pCompositor->m_lWindows) { result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i (%s)\n\tfloating: %i\n\n", - &w, w.m_szTitle.c_str(), (int)w.m_vRealPosition.x, (int)w.m_vRealPosition.y, (int)w.m_vRealSize.x, (int)w.m_vRealSize.y, w.m_iWorkspaceID, (w.m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w.m_iWorkspaceID)->m_szName.c_str()), (int)w.m_bIsFloating); + &w, w.m_szTitle.c_str(), (int)w.m_vRealPosition.vec().x, (int)w.m_vRealPosition.vec().y, (int)w.m_vRealSize.vec().x, (int)w.m_vRealSize.vec().y, w.m_iWorkspaceID, (w.m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w.m_iWorkspaceID)->m_szName.c_str()), (int)w.m_bIsFloating); } return result; } @@ -47,7 +47,7 @@ std::string activeWindowRequest() { return "Invalid"; return getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i (%s)\n\tfloating: %i\n\n", - PWINDOW, PWINDOW->m_szTitle.c_str(), (int)PWINDOW->m_vRealPosition.x, (int)PWINDOW->m_vRealPosition.y, (int)PWINDOW->m_vRealSize.x, (int)PWINDOW->m_vRealSize.y, PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()), (int)PWINDOW->m_bIsFloating); + PWINDOW, PWINDOW->m_szTitle.c_str(), (int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y, (int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y, PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()), (int)PWINDOW->m_bIsFloating); } std::string layersRequest() { diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 4887560c..5a79f624 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -33,6 +33,7 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->m_bReadyToDelete = false; PWINDOW->m_bFadingOut = false; PWINDOW->m_szTitle = g_pXWaylandManager->getTitle(PWINDOW); + PWINDOW->m_fAlpha = 255.f; // checks if the window wants borders and sets the appriopriate flag g_pXWaylandManager->checkBorders(PWINDOW); @@ -112,6 +113,7 @@ void Events::listener_mapWindow(void* owner, void* data) { Debug::log(LOG, "Rule size, applying to window %x", PWINDOW); + PWINDOW->m_vRealSize = Vector2D(SIZEX, SIZEY); PWINDOW->m_vEffectiveSize = Vector2D(SIZEX, SIZEY); g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vEffectiveSize); } catch (...) { @@ -128,6 +130,7 @@ void Events::listener_mapWindow(void* owner, void* data) { Debug::log(LOG, "Rule move, applying to window %x", PWINDOW); + PWINDOW->m_vRealPosition = Vector2D(POSX, POSY) + PMONITOR->vecPosition; PWINDOW->m_vEffectivePosition = Vector2D(POSX, POSY) + PMONITOR->vecPosition; } catch (...) { Debug::log(LOG, "Rule move failed, rule: %s -> %s", r.szRule.c_str(), r.szValue.c_str()); @@ -194,6 +197,8 @@ void Events::listener_unmapWindow(void* owner, void* data) { // Allow the renderer to catch the last frame. g_pHyprOpenGL->makeWindowSnapshot(PWINDOW); + PWINDOW->m_fAlpha = 0.f; + PWINDOW->m_bMappedX11 = false; // remove the fullscreen window status from workspace if we closed it @@ -298,7 +303,7 @@ void Events::listener_configureX11(void* owner, void* data) { const auto E = (wlr_xwayland_surface_configure_event*)data; if (!PWINDOW->m_bIsFloating) { - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.vec()); g_pInputManager->refocus(); return; } @@ -307,8 +312,8 @@ void Events::listener_configureX11(void* owner, void* data) { wlr_xwayland_surface_restack(PWINDOW->m_uSurface.xwayland, NULL, XCB_STACK_MODE_ABOVE); PWINDOW->m_vEffectivePosition = Vector2D(E->x, E->y); PWINDOW->m_vEffectiveSize = Vector2D(E->width, E->height); - PWINDOW->m_vRealPosition = PWINDOW->m_vEffectivePosition; - PWINDOW->m_vRealSize = PWINDOW->m_vRealSize; + PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vEffectivePosition); + PWINDOW->m_vRealSize.setValue(PWINDOW->m_vEffectiveSize); PWINDOW->m_vPosition = PWINDOW->m_vPosition; PWINDOW->m_vSize = PWINDOW->m_vSize; @@ -322,7 +327,7 @@ void Events::listener_surfaceXWayland(wl_listener* listener, void* data) { Debug::log(LOG, "New XWayland Surface created."); - g_pCompositor->m_lWindows.push_back(CWindow()); + g_pCompositor->m_lWindows.emplace_back(); const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back(); PNEWWINDOW->m_uSurface.xwayland = XWSURFACE; @@ -343,7 +348,7 @@ void Events::listener_newXDGSurface(wl_listener* listener, void* data) { if (XDGSURFACE->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) return; // TODO: handle? - g_pCompositor->m_lWindows.push_back(CWindow()); + g_pCompositor->m_lWindows.emplace_back(); const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back(); PNEWWINDOW->m_uSurface.xdg = XDGSURFACE; diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp new file mode 100644 index 00000000..581ea1c8 --- /dev/null +++ b/src/helpers/AnimatedVariable.cpp @@ -0,0 +1,54 @@ +#include "AnimatedVariable.hpp" +#include "../managers/AnimationManager.hpp" + +CAnimatedVariable::CAnimatedVariable() { + ; // dummy var +} + +void CAnimatedVariable::create(ANIMATEDVARTYPE type, float* speed, int64_t* enabled, void* pWindow) { + m_eVarType = type; + m_pSpeed = speed; + m_pEnabled = enabled; + m_pWindow = pWindow; + + g_pAnimationManager->m_lAnimatedVariables.push_back(this); + + m_bDummy = false; +} + +void CAnimatedVariable::create(ANIMATEDVARTYPE type, std::any val, float* speed, int64_t* enabled, void* pWindow) { + create(type, speed, enabled, pWindow); + + try { + switch (type) { + case AVARTYPE_FLOAT: { + const auto V = std::any_cast<float>(val); + m_fValue = V; + m_fGoal = V; + break; + } + case AVARTYPE_VECTOR: { + const auto V = std::any_cast<Vector2D>(val); + m_vValue = V; + m_vGoal = V; + break; + } + case AVARTYPE_COLOR: { + const auto V = std::any_cast<CColor>(val); + m_cValue = V; + m_cGoal = V; + break; + } + default: + ASSERT(false); + break; + } + } catch (std::exception& e) { + Debug::log(ERR, "CAnimatedVariable create error: %s", e.what()); + RASSERT(false, "CAnimatedVariable create error: %s", e.what()); + } +} + +CAnimatedVariable::~CAnimatedVariable() { + g_pAnimationManager->m_lAnimatedVariables.remove(this); +}
\ No newline at end of file diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp new file mode 100644 index 00000000..bd10c920 --- /dev/null +++ b/src/helpers/AnimatedVariable.hpp @@ -0,0 +1,131 @@ +#pragma once + +#include "../defines.hpp" +#include <any> + +enum ANIMATEDVARTYPE { + AVARTYPE_INVALID = -1, + AVARTYPE_FLOAT, + AVARTYPE_VECTOR, + AVARTYPE_COLOR +}; + +class CAnimationManager; + +class CAnimatedVariable { +public: + CAnimatedVariable(); // dummy var + + void create(ANIMATEDVARTYPE, float* speed, int64_t* enabled, void* pWindow); + void create(ANIMATEDVARTYPE, std::any val, float* speed, int64_t* enabled, void* pWindow); + + ~CAnimatedVariable(); + + Vector2D vec() { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + return m_vValue; + } + + float fl() { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + return m_fValue; + } + + CColor col() { + ASSERT(m_eVarType == AVARTYPE_COLOR); + return m_cValue; + } + + void operator=(const Vector2D& v) { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + m_vGoal = v; + } + + void operator=(const float& v) { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + m_fGoal = v; + } + + void operator=(const CColor& v) { + ASSERT(m_eVarType == AVARTYPE_COLOR); + m_cGoal = v; + } + + // Sets the actual stored value, without affecting the goal + void setValue(const Vector2D& v) { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + m_vValue = v; + } + + // Sets the actual stored value, without affecting the goal + void setValue(const float& v) { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + m_fValue = v; + } + + // Sets the actual stored value, without affecting the goal + void setValue(const CColor& v) { + ASSERT(m_eVarType == AVARTYPE_COLOR); + m_cValue = v; + } + + // Sets the actual value and goal + void setValueAndWarp(const Vector2D& v) { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + m_vGoal = v; + warp(); + } + + // Sets the actual value and goal + void setValueAndWarp(const float& v) { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + m_fGoal = v; + warp(); + } + + // Sets the actual value and goal + void setValueAndWarp(const CColor& v) { + ASSERT(m_eVarType == AVARTYPE_COLOR); + m_cGoal = v; + warp(); + } + +private: + + void warp() { + switch (m_eVarType) { + case AVARTYPE_FLOAT: { + m_fValue = m_fGoal; + break; + } + case AVARTYPE_VECTOR: { + m_vValue = m_vGoal; + break; + } + case AVARTYPE_COLOR: { + m_cValue = m_cGoal; + break; + } + default: + break; + } + } + + Vector2D m_vValue = Vector2D(0,0); + float m_fValue = 0; + CColor m_cValue; + + Vector2D m_vGoal = Vector2D(0,0); + float m_fGoal = 0; + CColor m_cGoal; + + float* m_pSpeed = nullptr; + int64_t* m_pEnabled = nullptr; + void* m_pWindow = nullptr; + + bool m_bDummy = true; + + ANIMATEDVARTYPE m_eVarType = AVARTYPE_INVALID; + + friend class CAnimationManager; +};
\ No newline at end of file diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index e7f4b87a..f5cf454c 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -155,6 +155,9 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode) { } } + PWINDOW->m_vRealSize = PWINDOW->m_vEffectiveSize; + PWINDOW->m_vRealPosition = PWINDOW->m_vEffectivePosition; + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vEffectiveSize); } @@ -190,8 +193,8 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) { applyNodeDataToWindow(PNODE); - pWindow->m_vRealPosition = PNODE->position + PNODE->size / 2.f; - pWindow->m_vRealSize = Vector2D(5, 5); + pWindow->m_vRealPosition.setValue(PNODE->position + PNODE->size / 2.f); + pWindow->m_vRealSize.setValue(Vector2D(5, 5)); return; } @@ -265,8 +268,8 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) { applyNodeDataToWindow(OPENINGON); } - pWindow->m_vRealPosition = PNODE->position + PNODE->size / 2.f; - pWindow->m_vRealSize = Vector2D(5,5); + pWindow->m_vRealPosition.setValue(PNODE->position + PNODE->size / 2.f); + pWindow->m_vRealSize.setValue(Vector2D(5,5)); } void CHyprDwindleLayout::onWindowRemoved(CWindow* pWindow) { @@ -364,16 +367,16 @@ void CHyprDwindleLayout::changeWindowFloatingMode(CWindow* pWindow) { if (!PNODE) { // save real pos cuz the func applies the default 5,5 mid - const auto PSAVEDPOS = pWindow->m_vRealPosition; - const auto PSAVEDSIZE = pWindow->m_vRealSize; + const auto PSAVEDPOS = pWindow->m_vRealPosition.vec(); + const auto PSAVEDSIZE = pWindow->m_vRealSize.vec(); // if the window is pseudo, update its size - pWindow->m_vPseudoSize = pWindow->m_vRealSize; + pWindow->m_vPseudoSize = pWindow->m_vRealSize.vec(); onWindowCreated(pWindow); - pWindow->m_vRealPosition = PSAVEDPOS; - pWindow->m_vRealSize = PSAVEDSIZE; + pWindow->m_vRealPosition.setValue(PSAVEDPOS); + pWindow->m_vRealSize.setValue(PSAVEDSIZE); } else { onWindowRemoved(pWindow); @@ -409,8 +412,8 @@ void CHyprDwindleLayout::onBeginDragWindow() { } m_vBeginDragXY = g_pInputManager->getMouseCoordsInternal(); - m_vBeginDragPositionXY = DRAGGINGWINDOW->m_vRealPosition; - m_vBeginDragSizeXY = DRAGGINGWINDOW->m_vRealSize; + m_vBeginDragPositionXY = DRAGGINGWINDOW->m_vRealPosition.vec(); + m_vBeginDragSizeXY = DRAGGINGWINDOW->m_vRealSize.vec(); m_vLastDragXY = m_vBeginDragXY; g_pHyprRenderer->damageWindow(DRAGGINGWINDOW); @@ -445,16 +448,16 @@ void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) { g_pHyprRenderer->damageWindow(DRAGGINGWINDOW); if (g_pInputManager->dragButton == BTN_LEFT) { - DRAGGINGWINDOW->m_vRealPosition = m_vBeginDragPositionXY + DELTA; - DRAGGINGWINDOW->m_vEffectivePosition = DRAGGINGWINDOW->m_vRealPosition; + DRAGGINGWINDOW->m_vRealPosition.setValueAndWarp(m_vBeginDragPositionXY + DELTA); + DRAGGINGWINDOW->m_vEffectivePosition = DRAGGINGWINDOW->m_vRealPosition.vec(); } else { if (DRAGGINGWINDOW->m_bIsFloating) { - DRAGGINGWINDOW->m_vRealSize = m_vBeginDragSizeXY + DELTA; - DRAGGINGWINDOW->m_vRealSize = Vector2D(std::clamp(DRAGGINGWINDOW->m_vRealSize.x, (double)20, (double)999999), std::clamp(DRAGGINGWINDOW->m_vRealSize.y, (double)20, (double)999999)); + DRAGGINGWINDOW->m_vRealSize.setValueAndWarp(m_vBeginDragSizeXY + DELTA); + DRAGGINGWINDOW->m_vRealSize.setValueAndWarp(Vector2D(std::clamp(DRAGGINGWINDOW->m_vRealSize.vec().x, (double)20, (double)999999), std::clamp(DRAGGINGWINDOW->m_vRealSize.vec().y, (double)20, (double)999999))); - DRAGGINGWINDOW->m_vEffectiveSize = DRAGGINGWINDOW->m_vRealSize; + DRAGGINGWINDOW->m_vEffectiveSize = DRAGGINGWINDOW->m_vRealSize.vec(); - g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize); + g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.vec()); } else { // we need to adjust the splitratio @@ -515,7 +518,7 @@ void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) { } // get middle point - Vector2D middle = DRAGGINGWINDOW->m_vRealPosition + DRAGGINGWINDOW->m_vRealSize / 2.f; + Vector2D middle = DRAGGINGWINDOW->m_vRealPosition.vec() + DRAGGINGWINDOW->m_vRealSize.vec() / 2.f; // and check its monitor const auto PMONITOR = g_pCompositor->getMonitorFromVector(middle); @@ -541,7 +544,7 @@ void CHyprDwindleLayout::onWindowCreatedFloating(CWindow* pWindow) { if (desiredGeometry.width <= 0 || desiredGeometry.height <= 0) { const auto PWINDOWSURFACE = g_pXWaylandManager->getWindowSurface(pWindow); pWindow->m_vEffectiveSize = Vector2D(PWINDOWSURFACE->current.width, PWINDOWSURFACE->current.height); - pWindow->m_vEffectivePosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.x) / 2.f, PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.y) / 2.f); + pWindow->m_vEffectivePosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.vec().x) / 2.f, PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.vec().y) / 2.f); } else { // we respect the size. @@ -562,14 +565,17 @@ void CHyprDwindleLayout::onWindowCreatedFloating(CWindow* pWindow) { } if (!pWindow->m_bX11DoesntWantBorders) { - pWindow->m_vRealPosition = pWindow->m_vEffectivePosition + pWindow->m_vEffectiveSize / 2.f; - pWindow->m_vRealSize = Vector2D(5, 5); + pWindow->m_vRealPosition.setValue(pWindow->m_vEffectivePosition + pWindow->m_vEffectiveSize / 2.f); + pWindow->m_vRealSize.setValue(Vector2D(5, 5)); } else { - pWindow->m_vRealPosition = pWindow->m_vEffectivePosition; - pWindow->m_vRealSize = pWindow->m_vEffectiveSize; + pWindow->m_vRealPosition.setValue(pWindow->m_vEffectivePosition); + pWindow->m_vRealSize.setValue(pWindow->m_vEffectiveSize); } - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize); + pWindow->m_vRealPosition = pWindow->m_vEffectivePosition; + pWindow->m_vRealSize = pWindow->m_vEffectiveSize; + + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vEffectiveSize); g_pCompositor->fixXWaylandWindowsOnWorkspace(PMONITOR->activeWorkspace); g_pCompositor->moveWindowToTop(pWindow); @@ -602,22 +608,22 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow) { pWindow->m_vEffectivePosition = pWindow->m_vPosition; pWindow->m_vEffectiveSize = pWindow->m_vSize; - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize); + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.vec()); } } else { // if it now got fullscreen, make it fullscreen // save position and size if floating if (pWindow->m_bIsFloating) { - pWindow->m_vPosition = pWindow->m_vRealPosition; - pWindow->m_vSize = pWindow->m_vRealSize; + pWindow->m_vPosition = pWindow->m_vRealPosition.vec(); + pWindow->m_vSize = pWindow->m_vRealSize.vec(); } // apply new pos and size being monitors' box pWindow->m_vEffectivePosition = PMONITOR->vecPosition; pWindow->m_vEffectiveSize = PMONITOR->vecSize; - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize); + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.vec()); } g_pCompositor->moveWindowToTop(pWindow); @@ -650,14 +656,20 @@ void CHyprDwindleLayout::toggleWindowGroup(CWindow* pWindow) { if (PGROUPPARENT) { // if there is a parent, release it - for (auto& node : PGROUPPARENT->groupMembers) + const auto INACTIVEBORDERCOL = CColor(g_pConfigManager->getInt("general:col.inactive_border")); + for (auto& node : PGROUPPARENT->groupMembers) { node->pGroupParent = nullptr; + node->pWindow->m_cRealBorderColor.setValueAndWarp(INACTIVEBORDERCOL); // no anim here because they pop in + } PGROUPPARENT->groupMembers.clear(); PGROUPPARENT->isGroup = false; PGROUPPARENT->recalcSizePosRecursive(); + + if (g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) + g_pCompositor->m_pLastWindow->m_cRealBorderColor = CColor(g_pConfigManager->getInt("general:col.active_border")); } else { // if there is no parent, let's make one @@ -675,8 +687,14 @@ void CHyprDwindleLayout::toggleWindowGroup(CWindow* pWindow) { PPARENT->groupMembers = allChildren; - for (auto& c : PPARENT->groupMembers) + const auto GROUPINACTIVEBORDERCOL = CColor(g_pConfigManager->getInt("dwinle:col.group_border")); + for (auto& c : PPARENT->groupMembers) { c->pGroupParent = PPARENT; + c->pWindow->m_cRealBorderColor = GROUPINACTIVEBORDERCOL; + + if (c->pWindow == g_pCompositor->m_pLastWindow) + c->pWindow->m_cRealBorderColor = CColor(g_pConfigManager->getInt("dwindle:col.group_border_active")); + } PPARENT->groupMemberActive = 0; diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index f77c3d7c..d4a71f37 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -8,115 +8,71 @@ void CAnimationManager::tick() { if (!g_pConfigManager->getInt("animations:enabled")) animationsDisabled = true; - 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 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")); - const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); - for (auto& w : g_pCompositor->m_lWindows) { - - // get the box before transforms, for damage tracking later - wlr_box WLRBOXPREV = { w.m_vRealPosition.x - BORDERSIZE - 1, w.m_vRealPosition.y - BORDERSIZE - 1, w.m_vRealSize.x + 2 * BORDERSIZE + 2, w.m_vRealSize.y + 2 * BORDERSIZE + 2}; - bool needsDamage = false; - - // 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); - } - - needsDamage = true; - } - - } else { - const auto GOALALPHA = w.m_bIsMapped ? 255.f : 0.f; - - if (!deltazero(GOALALPHA, w.m_fAlpha)) { - if (w.m_bIsMapped) - w.m_fAlpha = 255.f; - else { - w.m_fAlpha = 0.f; - w.m_bFadingOut = false; - } - - needsDamage = true; - } - } - - // process fadein/out for unmapped windows, but nothing else. - // we can't use windowValidMapped because we want to animate hidden windows too. - if (!g_pCompositor->windowExists(&w) || !w.m_bIsMapped || !g_pXWaylandManager->getWindowSurface(&w)){ - if (needsDamage) { - g_pHyprRenderer->damageWindow(&w); // only window, it didnt move cuz its unmappy - } - + for (auto& av : m_lAnimatedVariables) { + // first, we check if it's disabled, if so, warp + if (av->m_pEnabled == 0 || animationsDisabled) { + av->warp(); continue; } - // process the borders - const auto RENDERHINTS = g_pLayoutManager->getCurrentLayout()->requestRenderHints(&w); - - const auto& COLOR = RENDERHINTS.isBorderColor ? RENDERHINTS.borderColor : g_pCompositor->isWindowActive(&w) ? BORDERACTIVECOL : BORDERINACTIVECOL; + // get speed + const auto SPEED = *av->m_pSpeed == 0 ? ANIMSPEED : *av->m_pSpeed; - if (BORDERSENABLED) { - if (!deltazero(COLOR, w.m_cRealBorderColor)) { - if (deltaSmallToFlip(COLOR, w.m_cRealBorderColor)) { - w.m_cRealBorderColor = COLOR; - } else { - w.m_cRealBorderColor = parabolic(BORDERSPEED, w.m_cRealBorderColor, COLOR); + // window stuff + const auto PWINDOW = (CWindow*)av->m_pWindow; + bool needsDamage = false; + wlr_box WLRBOXPREV = {PWINDOW->m_vRealPosition.vec().x - BORDERSIZE - 1, PWINDOW->m_vRealPosition.vec().y - BORDERSIZE - 1, PWINDOW->m_vRealSize.vec().x + 2 * BORDERSIZE + 2, PWINDOW->m_vRealSize.vec().y + 2 * BORDERSIZE + 2}; + + // TODO: curves + + // parabolic with a switch unforto + // TODO: maybe do something cleaner + switch (av->m_eVarType) { + case AVARTYPE_FLOAT: { + if (!deltazero(av->m_fValue, av->m_fGoal)) { + if (deltaSmallToFlip(av->m_fValue, av->m_fGoal)) { + av->warp(); + } else { + av->m_fValue = parabolic(av->m_fValue, av->m_fGoal, SPEED); + } + + needsDamage = true; } - needsDamage = true; + break; } - } else { - if (!deltazero(w.m_cRealBorderColor, COLOR)) - needsDamage = true; - w.m_cRealBorderColor = COLOR; - } - - // process the window - if (WINDOWSENABLED) { - if (!deltazero(w.m_vRealPosition, w.m_vEffectivePosition) || !deltazero(w.m_vRealSize, w.m_vEffectiveSize)) { - if (deltaSmallToFlip(w.m_vRealPosition, w.m_vEffectivePosition) && deltaSmallToFlip(w.m_vRealSize, w.m_vEffectiveSize)) { - w.m_vRealPosition = w.m_vEffectivePosition; - w.m_vRealSize = w.m_vEffectiveSize; - g_pXWaylandManager->setWindowSize(&w, w.m_vRealSize); - } else { - // if it is to be animated, animate it. - w.m_vRealPosition = Vector2D(parabolic(w.m_vRealPosition.x, w.m_vEffectivePosition.x, WINDOWSPEED), parabolic(w.m_vRealPosition.y, w.m_vEffectivePosition.y, WINDOWSPEED)); - w.m_vRealSize = Vector2D(parabolic(w.m_vRealSize.x, w.m_vEffectiveSize.x, WINDOWSPEED), parabolic(w.m_vRealSize.y, w.m_vEffectiveSize.y, WINDOWSPEED)); + case AVARTYPE_VECTOR: { + if (!deltazero(av->m_vValue, av->m_vGoal)) { + if (deltaSmallToFlip(av->m_vValue, av->m_vGoal)) { + av->warp(); + } else { + av->m_vValue.x = parabolic(av->m_vValue.x, av->m_vGoal.x, SPEED); + av->m_vValue.y = parabolic(av->m_vValue.y, av->m_vGoal.y, SPEED); + } + needsDamage = true; } - - needsDamage = true; + break; + } + case AVARTYPE_COLOR: { + if (!deltazero(av->m_cValue, av->m_cGoal)) { + if (deltaSmallToFlip(av->m_cValue, av->m_cGoal)) { + av->warp(); + } else { + av->m_cValue = parabolic(SPEED, av->m_cValue, av->m_cGoal); + } + needsDamage = true; + } + break; } - } else { - if (!deltazero(w.m_vRealPosition, w.m_vEffectivePosition) || !deltazero(w.m_vRealSize, w.m_vEffectiveSize)) - needsDamage = true; - - w.m_vRealPosition = w.m_vEffectivePosition; - w.m_vRealSize = w.m_vEffectiveSize; } + // invalidate the window if (needsDamage) { g_pHyprRenderer->damageBox(&WLRBOXPREV); - g_pHyprRenderer->damageWindow(&w); + g_pHyprRenderer->damageWindow(PWINDOW); } } } diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 8d2c86b6..14d6c3ac 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -2,12 +2,15 @@ #include "../defines.hpp" #include <list> +#include "../helpers/AnimatedVariable.hpp" class CAnimationManager { public: void tick(); + std::list<CAnimatedVariable*> m_lAnimatedVariables; + private: bool deltaSmallToFlip(const Vector2D& a, const Vector2D& b); bool deltaSmallToFlip(const CColor& a, const CColor& b); diff --git a/src/managers/InputManager.cpp b/src/managers/InputManager.cpp index 219acdac..4166fd22 100644 --- a/src/managers/InputManager.cpp +++ b/src/managers/InputManager.cpp @@ -57,11 +57,11 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); for (auto w = g_pCompositor->m_lWindows.rbegin(); w != g_pCompositor->m_lWindows.rend(); ++w) { - wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y}; + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; if (w->m_iWorkspaceID == pFoundWindow->m_iWorkspaceID && w->m_bIsMapped && w->m_bCreatedOverFullscreen && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) { foundSurface = g_pXWaylandManager->getWindowSurface(&(*w)); if (foundSurface) - surfacePos = w->m_vRealPosition; + surfacePos = w->m_vRealPosition.vec(); break; } } @@ -70,7 +70,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (pFoundWindow->m_bIsX11) { foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow); if (foundSurface) - surfacePos = pFoundWindow->m_vRealPosition; + surfacePos = pFoundWindow->m_vRealPosition.vec(); } else { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); } @@ -91,7 +91,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); } else { foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow); - surfacePos = pFoundWindow->m_vRealPosition; + surfacePos = pFoundWindow->m_vRealPosition.vec(); } } @@ -143,7 +143,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (g_pCompositor->m_pLastWindow == CONSTRAINTWINDOW) { // todo: this is incorrect, but it will work in most cases for now // i made this cuz i wanna play minecraft lol - Vector2D deltaToMiddle = (CONSTRAINTWINDOW->m_vRealPosition + CONSTRAINTWINDOW->m_vRealSize / 2.f) - mouseCoords; + Vector2D deltaToMiddle = (CONSTRAINTWINDOW->m_vRealPosition.vec() + CONSTRAINTWINDOW->m_vRealSize.vec() / 2.f) - mouseCoords; wlr_cursor_move(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, deltaToMiddle.x, deltaToMiddle.y); } } @@ -389,7 +389,7 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { if (PWINDOW) { wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, - constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.x, constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.y); + constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.vec().x, constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.vec().y); wlr_seat_pointer_warp(constraint->seat, constraint->current.cursor_hint.x, constraint->current.cursor_hint.y); } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 06fdf5f4..500b6b88 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -143,8 +143,8 @@ void CKeybindManager::toggleActiveFloating(std::string args) { if (g_pCompositor->windowValidMapped(ACTIVEWINDOW)) { ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating; - ACTIVEWINDOW->m_vRealPosition = ACTIVEWINDOW->m_vRealPosition + Vector2D(5, 5); - ACTIVEWINDOW->m_vSize = ACTIVEWINDOW->m_vRealPosition - Vector2D(10, 10); + ACTIVEWINDOW->m_vRealPosition.setValue(ACTIVEWINDOW->m_vRealPosition.vec() + Vector2D(5, 5)); + ACTIVEWINDOW->m_vSize = ACTIVEWINDOW->m_vRealPosition.vec() - Vector2D(10, 10); g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(ACTIVEWINDOW); } @@ -311,18 +311,18 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { PWINDOW->m_vPosition = Vector2D(-42069, -42069); // Save the real position and size because the layout might set its own - const auto PSAVEDSIZE = PWINDOW->m_vRealSize; - const auto PSAVEDPOS = PWINDOW->m_vRealPosition; + const auto PSAVEDSIZE = PWINDOW->m_vRealSize.vec(); + const auto PSAVEDPOS = PWINDOW->m_vRealPosition.vec(); g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); // and restore it - PWINDOW->m_vRealPosition = PSAVEDPOS; - PWINDOW->m_vRealSize = PSAVEDSIZE; + PWINDOW->m_vRealPosition.setValue(PSAVEDPOS); + PWINDOW->m_vRealSize.setValue(PSAVEDSIZE); if (PWINDOW->m_bIsFloating) { - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition; - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition; - PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition; - PWINDOW->m_vPosition = PWINDOW->m_vRealPosition; + PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition); + PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition); + PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition.vec(); + PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec(); } } diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index fcb72ef5..9efefc75 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -117,7 +117,7 @@ void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) { void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, const Vector2D& size) { if (pWindow->m_bIsX11) - wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.x, pWindow->m_vRealPosition.y, size.x, size.y); + wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.vec().x, pWindow->m_vRealPosition.vec().y, size.x, size.y); else wlr_xdg_toplevel_set_size(pWindow->m_uSurface.xdg->toplevel, size.x, size.y); } @@ -172,7 +172,7 @@ void CHyprXWaylandManager::moveXWaylandWindow(CWindow* pWindow, const Vector2D& return; if (pWindow->m_bIsX11) { - wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.x, pWindow->m_vRealSize.y); + wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.vec().x, pWindow->m_vRealSize.vec().y); } } diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 32e30e7a..4d706e3b 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -625,7 +625,7 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { wlr_box windowBox = {0, 0, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; - renderTextureInternal(it->second.m_cTex, &windowBox, PWINDOW->m_fAlpha, 0); + renderTextureInternal(it->second.m_cTex, &windowBox, PWINDOW->m_fAlpha.fl(), 0); } void CHyprOpenGLImpl::createBGTextureForMonitor(SMonitor* pMonitor) { diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 3315034f..75e42e13 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -30,7 +30,7 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { } bool shouldRenderWindow(CWindow* pWindow, SMonitor* pMonitor) { - wlr_box geometry = {pWindow->m_vRealPosition.x, pWindow->m_vRealPosition.y, pWindow->m_vRealSize.x, pWindow->m_vRealSize.y}; + wlr_box geometry = {pWindow->m_vRealPosition.vec().x, pWindow->m_vRealPosition.vec().y, pWindow->m_vRealSize.vec().x, pWindow->m_vRealSize.vec().y}; if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, &geometry)) return false; @@ -83,13 +83,13 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec* return; } - const auto REALPOS = pWindow->m_vRealPosition; + const auto REALPOS = pWindow->m_vRealPosition.vec(); SRenderData renderdata = {pMonitor->output, time, REALPOS.x, REALPOS.y}; renderdata.surface = g_pXWaylandManager->getWindowSurface(pWindow); - renderdata.w = pWindow->m_vRealSize.x; - renderdata.h = pWindow->m_vRealSize.y; + renderdata.w = pWindow->m_vRealSize.vec().x; + renderdata.h = pWindow->m_vRealSize.vec().y; renderdata.dontRound = pWindow->m_bIsFullscreen; - renderdata.fadeAlpha = pWindow->m_fAlpha; + renderdata.fadeAlpha = pWindow->m_fAlpha.fl(); renderdata.alpha = pWindow == g_pCompositor->m_pLastWindow ? g_pConfigManager->getFloat("decoration:active_opacity") : g_pConfigManager->getFloat("decoration:inactive_opacity"); // apply window special data @@ -99,7 +99,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec* // border if (decorate && !pWindow->m_bX11DoesntWantBorders) - drawBorderForWindow(pWindow, pMonitor, pWindow->m_fAlpha * renderdata.alpha); + drawBorderForWindow(pWindow, pMonitor, pWindow->m_fAlpha.fl() * renderdata.alpha); if (pWindow->m_bIsX11) { if (pWindow->m_uSurface.xwayland->surface) { @@ -411,14 +411,14 @@ void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor, fl if (BORDERSIZE < 1) return; - auto BORDERCOL = pWindow->m_cRealBorderColor; + auto BORDERCOL = pWindow->m_cRealBorderColor.col(); BORDERCOL.a *= (alpha / 255.f); - Vector2D correctPos = pWindow->m_vRealPosition - pMonitor->vecPosition; - Vector2D correctSize = pWindow->m_vRealSize; + Vector2D correctPos = pWindow->m_vRealPosition.vec() - pMonitor->vecPosition; + Vector2D correctSize = pWindow->m_vRealSize.vec(); // top - wlr_box border = {correctPos.x - BORDERSIZE / 2.f, correctPos.y - BORDERSIZE / 2.f, pWindow->m_vRealSize.x + BORDERSIZE, pWindow->m_vRealSize.y + BORDERSIZE}; + wlr_box border = {correctPos.x - BORDERSIZE / 2.f, correctPos.y - BORDERSIZE / 2.f, pWindow->m_vRealSize.vec().x + BORDERSIZE, pWindow->m_vRealSize.vec().y + BORDERSIZE}; g_pHyprOpenGL->renderBorder(&border, BORDERCOL, BORDERSIZE, g_pConfigManager->getInt("decoration:rounding")); } @@ -454,7 +454,7 @@ void CHyprRenderer::damageWindow(CWindow* pWindow) { } else { // damage by real size & pos + border size * 2 (JIC) const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); - wlr_box damageBox = { pWindow->m_vRealPosition.x - BORDERSIZE - 1, pWindow->m_vRealPosition.y - BORDERSIZE - 1, pWindow->m_vRealSize.x + 2 * BORDERSIZE + 2, pWindow->m_vRealSize.y + 2 * BORDERSIZE + 2}; + wlr_box damageBox = { pWindow->m_vRealPosition.vec().x - BORDERSIZE - 1, pWindow->m_vRealPosition.vec().y - BORDERSIZE - 1, pWindow->m_vRealSize.vec().x + 2 * BORDERSIZE + 2, pWindow->m_vRealSize.vec().y + 2 * BORDERSIZE + 2}; for (auto& m : g_pCompositor->m_lMonitors) wlr_output_damage_add_box(m.damage, &damageBox); } |