From 19970bd63981504bad7fde626644f487b9cf7abc Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 31 Jan 2024 16:22:41 +0100 Subject: [PATCH] plugins/wobblywindows: Use snapping when the window isn't moving disable pixel snapping when the window is moving with some velocity/acceleration, reenable it when is (alsmost) stopped --- src/effect/offscreeneffect.cpp | 2 +- src/plugins/wobblywindows/wobblywindows.cpp | 26 ++++++++++----------- src/plugins/wobblywindows/wobblywindows.h | 1 + 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/effect/offscreeneffect.cpp b/src/effect/offscreeneffect.cpp index f81f3bff0a..c24c88c430 100644 --- a/src/effect/offscreeneffect.cpp +++ b/src/effect/offscreeneffect.cpp @@ -186,7 +186,7 @@ void OffscreenData::paint(const RenderTarget &renderTarget, const RenderViewport const qreal a = data.opacity(); QMatrix4x4 mvp = data.projectionMatrix(); - mvp.translate(window->x() * scale, window->y() * scale); + mvp.translate(std::round(window->x() * scale), std::round(window->y() * scale)); const auto toXYZ = renderTarget.colorDescription().colorimetry().toXYZ(); shader->setUniform(GLShader::Mat4Uniform::ModelViewProjectionMatrix, mvp * data.toMatrix(scale)); diff --git a/src/plugins/wobblywindows/wobblywindows.cpp b/src/plugins/wobblywindows/wobblywindows.cpp index 5fd0074150..a3bab3e77e 100644 --- a/src/plugins/wobblywindows/wobblywindows.cpp +++ b/src/plugins/wobblywindows/wobblywindows.cpp @@ -130,8 +130,6 @@ WobblyWindowsEffect::WobblyWindowsEffect() for (EffectWindow *window : windows) { slotWindowAdded(window); } - - setVertexSnappingMode(RenderGeometry::VertexSnappingMode::None); } WobblyWindowsEffect::~WobblyWindowsEffect() @@ -232,13 +230,6 @@ void WobblyWindowsEffect::setDrag(qreal drag) void WobblyWindowsEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) { - // We need to mark the screen windows as transformed. Otherwise the whole - // screen won't be repainted, resulting in artefacts. - // Could we just set a subset of the screen to be repainted ? - if (windows.count() != 0) { - m_updateRegion = QRegion(); - } - effects->prePaintScreen(data, presentTime); } @@ -266,9 +257,11 @@ void WobblyWindowsEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &da void WobblyWindowsEffect::apply(EffectWindow *w, int mask, WindowPaintData &data, WindowQuadList &quads) { if (!(mask & PAINT_SCREEN_TRANSFORMED) && windows.contains(w)) { - quads = quads.makeRegularGrid(m_xTesselation, m_yTesselation); - WindowWobblyInfos &wwi = windows[w]; + if (!wwi.wobblying) { + return; + } + int tx = w->frameGeometry().x(); int ty = w->frameGeometry().y(); int width = w->frameGeometry().width(); @@ -277,6 +270,8 @@ void WobblyWindowsEffect::apply(EffectWindow *w, int mask, WindowPaintData &data double top = 0.0; double right = w->width(); double bottom = w->height(); + + quads = quads.makeRegularGrid(m_xTesselation, m_yTesselation); for (int i = 0; i < quads.count(); ++i) { for (int j = 0; j < 4; ++j) { WindowVertex &v = quads[i][j]; @@ -302,8 +297,9 @@ void WobblyWindowsEffect::apply(EffectWindow *w, int mask, WindowPaintData &data void WobblyWindowsEffect::postPaintScreen() { - if (!windows.isEmpty()) { + if (!m_updateRegion.isEmpty()) { effects->addRepaint(m_updateRegion); + m_updateRegion = QRegion(); } // Call the next effect. @@ -346,6 +342,7 @@ void WobblyWindowsEffect::slotWindowStepUserMovedResized(EffectWindow *w, const if (rect.bottom() != wwi.resize_original_rect.bottom()) { wwi.can_wobble_bottom = true; } + setVertexSnappingMode(RenderGeometry::VertexSnappingMode::None); } } @@ -944,13 +941,16 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow *w, qreal time) qCDebug(KWIN_WOBBLYWINDOWS) << "sum_acc : " << acc_sum << " *** sum_vel :" << vel_sum; #endif - if (wwi.status != Moving && acc_sum < m_stopAcceleration && vel_sum < m_stopVelocity) { + wwi.wobblying = !(acc_sum < m_stopAcceleration && vel_sum < m_stopVelocity); + if (wwi.status != Moving && !wwi.wobblying) { windows.remove(w); unredirect(w); if (windows.isEmpty()) { effects->addRepaintFull(); } return false; + } else if (!wwi.wobblying) { + setVertexSnappingMode(RenderGeometry::VertexSnappingMode::Round); } return true; diff --git a/src/plugins/wobblywindows/wobblywindows.h b/src/plugins/wobblywindows/wobblywindows.h index 68038d0ffe..96af6669db 100644 --- a/src/plugins/wobblywindows/wobblywindows.h +++ b/src/plugins/wobblywindows/wobblywindows.h @@ -125,6 +125,7 @@ private: unsigned int bezierCount; WindowStatus status; + bool wobblying = false; // for resizing. Only sides that have moved will wobble bool can_wobble_top, can_wobble_left, can_wobble_right, can_wobble_bottom;