From 8aadccd9e47f57dc076faff295a7b7502aa160a8 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Dec 2021 21:58:20 +0100 Subject: [PATCH] sloppy fix for new windows frozen sometimes if anyone knows a better one feel free --- src/events/events.cpp | 23 ++++++++++++++++++----- src/utilities/AnimationUtil.cpp | 9 ++++----- src/utilities/Util.cpp | 23 ++++++++++++++++++++--- src/utilities/Util.hpp | 3 ++- src/window.cpp | 2 +- src/window.hpp | 3 +++ 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/events/events.cpp b/src/events/events.cpp index 831fcd8..ce0bfdd 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -69,6 +69,12 @@ void Events::eventEnter(xcb_generic_event_t* event) { g_pWindowManager->setFocusedWindow(E->event); PENTERWINDOW->setDirty(true); + + if (PENTERWINDOW->getIsSleeping()) { + // Wake it up, fixes some weird shenaningans + wakeUpEvent(E->event); + PENTERWINDOW->setIsSleeping(false); + } } void Events::eventLeave(xcb_generic_event_t* event) { @@ -76,7 +82,16 @@ void Events::eventLeave(xcb_generic_event_t* event) { RETURNIFBAR; - // + const auto PENTERWINDOW = g_pWindowManager->getWindowFromDrawable(E->event); + + if (!PENTERWINDOW) + return; + + if (PENTERWINDOW->getIsSleeping()) { + // Wake it up, fixes some weird shenaningans + wakeUpEvent(E->event); + PENTERWINDOW->setIsSleeping(false); + } } void Events::eventDestroy(xcb_generic_event_t* event) { @@ -190,16 +205,14 @@ CWindow* Events::remapFloatingWindow(int windowID, int forcemonitor) { window.setSize(window.getDefaultSize()); window.setPosition(window.getDefaultPosition()); + + // The anim util will take care of this. window.setEffectiveSize(window.getDefaultSize()); window.setEffectivePosition(window.getDefaultPosition()); // Also sets the old one g_pWindowManager->calculateNewWindowParams(&window); - // Set real size. No animations in the beginning. Maybe later. TODO? - window.setRealPosition(window.getEffectivePosition()); - window.setRealSize(window.getEffectiveSize()); - // Add to arr g_pWindowManager->addWindowToVectorSafe(window); diff --git a/src/utilities/AnimationUtil.cpp b/src/utilities/AnimationUtil.cpp index b479330..d015ae4 100644 --- a/src/utilities/AnimationUtil.cpp +++ b/src/utilities/AnimationUtil.cpp @@ -5,6 +5,7 @@ void AnimationUtil::move() { static std::chrono::time_point lastFrame = std::chrono::high_resolution_clock::now(); const double DELTA = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - lastFrame).count(); + lastFrame = std::chrono::high_resolution_clock::now(); const double ANIMATIONSPEED = ((double)1 / (double)ConfigManager::getFloat("anim.speed")) * DELTA; @@ -22,10 +23,10 @@ void AnimationUtil::move() { || VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) { window.setDirty(true); updateRequired = true; - } - window.setRealPosition(window.getEffectivePosition()); - window.setRealSize(window.getEffectiveSize()); + window.setRealPosition(window.getEffectivePosition()); + window.setRealSize(window.getEffectiveSize()); + } continue; } @@ -67,6 +68,4 @@ void AnimationUtil::move() { if (updateRequired) emptyEvent(); // send a fake request to update dirty windows - - lastFrame = std::chrono::high_resolution_clock::now(); } \ No newline at end of file diff --git a/src/utilities/Util.cpp b/src/utilities/Util.cpp index cfe12b4..481eb4d 100644 --- a/src/utilities/Util.cpp +++ b/src/utilities/Util.cpp @@ -29,18 +29,35 @@ double parabolic(double from, double to, double incline) { return from + ((to - from) / incline); } -void emptyEvent() { +void emptyEvent(xcb_drawable_t window) { xcb_expose_event_t exposeEvent; - exposeEvent.window = 0; + exposeEvent.window = window; exposeEvent.response_type = 0; exposeEvent.x = 0; exposeEvent.y = 0; exposeEvent.width = g_pWindowManager->Screen->width_in_pixels; exposeEvent.height = g_pWindowManager->Screen->height_in_pixels; - xcb_send_event(g_pWindowManager->DisplayConnection, false, g_pWindowManager->Screen->root, XCB_EVENT_MASK_EXPOSURE, (char*)&exposeEvent); + xcb_send_event(g_pWindowManager->DisplayConnection, false, window, XCB_EVENT_MASK_EXPOSURE, (char*)&exposeEvent); xcb_flush(g_pWindowManager->DisplayConnection); } +void wakeUpEvent(xcb_drawable_t window) { + const auto PWINDOW = g_pWindowManager->getWindowFromDrawable(window); + + if (!PWINDOW) + return; + + PWINDOW->setRealPosition(PWINDOW->getRealPosition() + Vector2D(1, 1)); + PWINDOW->setDirty(true); + + g_pWindowManager->refreshDirtyWindows(); + + xcb_flush(g_pWindowManager->DisplayConnection); + + PWINDOW->setRealPosition(PWINDOW->getRealPosition() - Vector2D(1, 1)); + PWINDOW->setDirty(true); +} + bool xcbContainsAtom(xcb_get_property_reply_t* PROP, xcb_atom_t ATOM) { if (PROP == NULL || xcb_get_property_value_length(PROP) == 0) return false; diff --git a/src/utilities/Util.hpp b/src/utilities/Util.hpp index dc31513..ae50270 100644 --- a/src/utilities/Util.hpp +++ b/src/utilities/Util.hpp @@ -5,7 +5,8 @@ std::string exec(const char* cmd); void clearLogs(); -void emptyEvent(); +void emptyEvent(xcb_drawable_t window = 0); +void wakeUpEvent(xcb_drawable_t window); bool xcbContainsAtom(xcb_get_property_reply_t* PROP, xcb_atom_t ATOM); double parabolic(double from, double to, double incline); diff --git a/src/window.cpp b/src/window.cpp index 6681a53..c6dc0a7 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,7 +1,7 @@ #include "window.hpp" #include "windowManager.hpp" -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() { this->setIsSleeping(true); 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 f2adcc5..c970014 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -80,6 +80,9 @@ public: EXPOSED_MEMBER(IsAnimated, bool, b); EXPOSED_MEMBER(FirstAnimFrame, bool, b); + // Weird shenaningans + EXPOSED_MEMBER(IsSleeping, bool, b); + private: }; \ No newline at end of file