From 9e759fe39e66542d89e4eeade8429d91c3f1384f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 6 Dec 2021 19:43:01 +0100 Subject: [PATCH] Added cheap animations --- example/hypr.conf | 5 +++-- src/config/ConfigManager.cpp | 3 ++- src/events/events.cpp | 4 ++++ src/utilities/AnimationUtil.cpp | 9 ++++++++ src/window.cpp | 2 +- src/window.hpp | 3 +++ src/windowManager.cpp | 38 ++++++++++++++++++++++++--------- src/windowManager.hpp | 3 ++- 8 files changed, 52 insertions(+), 15 deletions(-) diff --git a/example/hypr.conf b/example/hypr.conf index efbcb26..3674ea9 100644 --- a/example/hypr.conf +++ b/example/hypr.conf @@ -45,8 +45,9 @@ col.inactive_border=0x77222222 # # animations -anim.enabled=0 -anim.speed=8 +anim.enabled=1 +anim.speed=5 +anim.cheap=1 # highly recommended # keybinds bind=SUPER,R,exec,dmenu_run diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index ff76e6b..3a6c921 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -38,7 +38,8 @@ void ConfigManager::init() { // animations configValues["anim.speed"].floatValue = 1; - configValues["anim.enabled"].intValue = 1; + configValues["anim.enabled"].intValue = 0; + configValues["anim.cheap"].intValue = 1; if (!g_pWindowManager->statusBar) { isFirstLaunch = true; diff --git a/src/events/events.cpp b/src/events/events.cpp index 2a8a184..831fcd8 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -328,6 +328,10 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating, int forcemonitor) { g_pWindowManager->Values[0] = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE; xcb_change_window_attributes_checked(g_pWindowManager->DisplayConnection, windowID, XCB_CW_EVENT_MASK, g_pWindowManager->Values); + // make the last window top (animations look better) + g_pWindowManager->setAWindowTop(g_pWindowManager->LastWindow); + + // Focus g_pWindowManager->setFocusedWindow(windowID); // Make all floating windows above diff --git a/src/utilities/AnimationUtil.cpp b/src/utilities/AnimationUtil.cpp index 32824c9..b479330 100644 --- a/src/utilities/AnimationUtil.cpp +++ b/src/utilities/AnimationUtil.cpp @@ -13,6 +13,7 @@ void AnimationUtil::move() { // Now we are (or should be, lul) thread-safe. for (auto& window : g_pWindowManager->windows) { // check if window needs an animation. + window.setIsAnimated(false); if (ConfigManager::getInt("anim.enabled") == 0 || window.getIsFloating()) { // Disabled animations. instant warps. @@ -31,6 +32,7 @@ void AnimationUtil::move() { if (VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition())) { Debug::log(LOG, "Updating position animations for " + std::to_string(window.getDrawable()) + " delta: " + std::to_string(ANIMATIONSPEED)); + window.setIsAnimated(true); // we need to update it. window.setDirty(true); @@ -44,6 +46,7 @@ void AnimationUtil::move() { if (VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) { Debug::log(LOG, "Updating size animations for " + std::to_string(window.getDrawable()) + " delta: " + std::to_string(ANIMATIONSPEED)); + window.setIsAnimated(true); // we need to update it. window.setDirty(true); @@ -54,6 +57,12 @@ void AnimationUtil::move() { window.setRealSize(Vector2D(parabolic(REALSIZ.x, EFFSIZ.x, ANIMATIONSPEED), parabolic(REALSIZ.y, EFFSIZ.y, ANIMATIONSPEED))); } + + // set not animated if already done here + if (!VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition()) + && !VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) { + window.setIsAnimated(false); + } } if (updateRequired) diff --git a/src/window.cpp b/src/window.cpp index 74fb3f2..6681a53 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,7 +1,7 @@ #include "window.hpp" #include "windowManager.hpp" -CWindow::CWindow() { this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); } +CWindow::CWindow() { this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); } CWindow::~CWindow() { } void CWindow::generateNodeID() { diff --git a/src/window.hpp b/src/window.hpp index dc74fbb..f2adcc5 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -76,6 +76,9 @@ public: EXPOSED_MEMBER(MasterChildIndex, int, i); EXPOSED_MEMBER(Dead, bool, b); + // Animating cheaply + EXPOSED_MEMBER(IsAnimated, bool, b); + EXPOSED_MEMBER(FirstAnimFrame, bool, b); private: diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 919b343..4d72bec 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -380,15 +380,11 @@ void CWindowManager::refreshDirtyWindows() { xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values); // Apply rounded corners, does all the checks inside - applyRoundedCornersToWindow(&window); + applyShapeToWindow(&window); continue; } - Values[0] = (int)window.getRealSize().x; - Values[1] = (int)window.getRealSize().y; - xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values); - // Update the position because the border makes the window jump // I have added the bordersize vec2d before in the setEffectiveSizePosUsingConfig function. Values[0] = (int)window.getRealPosition().x - ConfigManager::getInt("border_size"); @@ -407,8 +403,25 @@ void CWindowManager::refreshDirtyWindows() { xcb_change_window_attributes(DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values); } - // Apply rounded corners, does all the checks inside - applyRoundedCornersToWindow(&window); + // If it isn't animated or we have non-cheap animations, update the real size + if (!window.getIsAnimated() || ConfigManager::getInt("anim.cheap") == 0) { + Values[0] = (int)window.getRealSize().x; + Values[1] = (int)window.getRealSize().y; + xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values); + window.setFirstAnimFrame(true); + } + + if (ConfigManager::getInt("anim.cheap") == 1 && window.getFirstAnimFrame() && window.getIsAnimated()) { + // first frame, fix the size if smaller + window.setFirstAnimFrame(false); + if (window.getRealSize().x < window.getEffectiveSize().x || window.getRealSize().y < window.getEffectiveSize().y) { + Values[0] = (int)window.getEffectiveSize().x; + Values[1] = (int)window.getEffectiveSize().y; + xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values); + } + } + + applyShapeToWindow(&window); Debug::log(LOG, "Refreshed dirty window, with an ID of " + std::to_string(window.getDrawable())); } @@ -432,11 +445,11 @@ void CWindowManager::setFocusedWindow(xcb_drawable_t window) { // Apply rounded corners, does all the checks inside. // The border changed so let's not make it rectangular maybe - applyRoundedCornersToWindow(g_pWindowManager->getWindowFromDrawable(window)); + applyShapeToWindow(g_pWindowManager->getWindowFromDrawable(window)); LastWindow = window; - applyRoundedCornersToWindow(g_pWindowManager->getWindowFromDrawable(window)); + applyShapeToWindow(g_pWindowManager->getWindowFromDrawable(window)); // set focus in X11 xcb_set_input_focus(DisplayConnection, XCB_INPUT_FOCUS_POINTER_ROOT, window, XCB_CURRENT_TIME); @@ -600,7 +613,7 @@ void CWindowManager::removeWindowFromVectorSafe(int64_t window) { } } -void CWindowManager::applyRoundedCornersToWindow(CWindow* pWindow) { +void CWindowManager::applyShapeToWindow(CWindow* pWindow) { if (!pWindow) return; @@ -1513,6 +1526,11 @@ void CWindowManager::setAllFloatingWindowsTop() { } } +void CWindowManager::setAWindowTop(xcb_window_t window) { + Values[0] = XCB_STACK_MODE_ABOVE; + xcb_configure_window(g_pWindowManager->DisplayConnection, window, XCB_CONFIG_WINDOW_STACK_MODE, Values); +} + bool CWindowManager::shouldBeFloatedOnInit(int64_t window) { // Should be floated also sets some properties diff --git a/src/windowManager.hpp b/src/windowManager.hpp index 87d80b7..deea619 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -90,6 +90,7 @@ public: void setAllWindowsDirty(); void setAllFloatingWindowsTop(); + void setAWindowTop(xcb_window_t); SMonitor* getMonitorFromWindow(CWindow*); SMonitor* getMonitorFromCursor(); @@ -130,7 +131,7 @@ private: void cleanupUnusedWorkspaces(); xcb_visualtype_t* setupColors(const int&); void updateRootCursor(); - void applyRoundedCornersToWindow(CWindow* pWindow); + void applyShapeToWindow(CWindow* pWindow); SMonitor* getMonitorFromWorkspace(const int&); void recalcEntireWorkspace(const int&); void fixMasterWorkspaceOnClosed(CWindow* pWindow);