Added cheap animations

This commit is contained in:
vaxerski 2021-12-06 19:43:01 +01:00
parent 7d39393cf8
commit 9e759fe39e
8 changed files with 52 additions and 15 deletions

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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)

View file

@ -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() {

View file

@ -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:

View file

@ -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

View file

@ -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);