diff --git a/effects/wobblywindows/wobblywindows.h b/effects/wobblywindows/wobblywindows.h --- a/effects/wobblywindows/wobblywindows.h +++ b/effects/wobblywindows/wobblywindows.h @@ -139,7 +139,6 @@ void cancelWindowGrab(KWin::EffectWindow *w, int grabRole); void startMovedResized(EffectWindow* w); void stepMovedResized(EffectWindow* w); - bool updateWindowWobblyDatas(EffectWindow* w, qreal time); struct WindowWobblyInfos { Pair* origin; @@ -171,6 +170,19 @@ QRect resize_original_rect; }; + bool updateWindowWobblyDatas(WindowWobblyInfos& wwi, const QRectF& rect, qreal time); + + void initWobblyInfo(WindowWobblyInfos& wwi, const QRectF& geometry) const; + void freeWobblyInfo(WindowWobblyInfos& wwi) const; + void wobblyOpenInit(WindowWobblyInfos& wwi) const; + void wobblyCloseInit(WindowWobblyInfos& wwi, EffectWindow* w) const; + + WobblyWindowsEffect::Pair computeBezierPoint(const WindowWobblyInfos& wwi, const Pair& point) const; + + static void heightRingLinearMean(Pair** data_pointer, WindowWobblyInfos& wwi); + + void setParameterSet(const ParameterSet& pset); + QHash< const EffectWindow*, WindowWobblyInfos > windows; QRegion m_updateRegion; @@ -198,17 +210,6 @@ bool m_moveWobble; // Expands m_moveEffectEnabled bool m_resizeWobble; - - void initWobblyInfo(WindowWobblyInfos& wwi, QRect geometry) const; - void freeWobblyInfo(WindowWobblyInfos& wwi) const; - void wobblyOpenInit(WindowWobblyInfos& wwi) const; - void wobblyCloseInit(WindowWobblyInfos& wwi, EffectWindow* w) const; - - WobblyWindowsEffect::Pair computeBezierPoint(const WindowWobblyInfos& wwi, Pair point) const; - - static void heightRingLinearMean(Pair** data_pointer, WindowWobblyInfos& wwi); - - void setParameterSet(const ParameterSet& pset); }; } // namespace KWin diff --git a/effects/wobblywindows/wobblywindows.cpp b/effects/wobblywindows/wobblywindows.cpp --- a/effects/wobblywindows/wobblywindows.cpp +++ b/effects/wobblywindows/wobblywindows.cpp @@ -57,93 +57,85 @@ bool closeEffectEnabled; }; -static const ParameterSet set_0 = { - 0.15, - 0.80, - 0.10, - 20.0, - 20.0, - 0.0, - 1000.0, - 0.5, - 0.0, - 1000.0, - 0.5, - true, - false, - false -}; - -static const ParameterSet set_1 = { - 0.10, - 0.85, - 0.10, - 20.0, - 20.0, - 0.0, - 1000.0, - 0.5, - 0.0, - 1000.0, - 0.5, - true, - false, - false -}; - -static const ParameterSet set_2 = { - 0.06, - 0.90, - 0.10, - 20.0, - 20.0, - 0.0, - 1000.0, - 0.5, - 0.0, - 1000.0, - 0.5, - true, - false, - false -}; - -static const ParameterSet set_3 = { - 0.03, - 0.92, - 0.20, - 20.0, - 20.0, - 0.0, - 1000.0, - 0.5, - 0.0, - 1000.0, - 0.5, - true, - false, - false -}; - -static const ParameterSet set_4 = { - 0.01, - 0.97, - 0.25, - 20.0, - 20.0, - 0.0, - 1000.0, - 0.5, - 0.0, - 1000.0, - 0.5, - true, - false, - false +static const ParameterSet pset[] = { + { + 0.15, + 0.80, + 0.10, + 20.0, + 20.0, + 0.0, + 1000.0, + 0.5, + 0.0, + 1000.0, + 0.5, + true, + false, + false +}, { + 0.10, + 0.85, + 0.10, + 20.0, + 20.0, + 0.0, + 1000.0, + 0.5, + 0.0, + 1000.0, + 0.5, + true, + false, + false +}, { + 0.06, + 0.90, + 0.10, + 20.0, + 20.0, + 0.0, + 1000.0, + 0.5, + 0.0, + 1000.0, + 0.5, + true, + false, + false +}, { + 0.03, + 0.92, + 0.20, + 20.0, + 20.0, + 0.0, + 1000.0, + 0.5, + 0.0, + 1000.0, + 0.5, + true, + false, + false +}, { + 0.01, + 0.97, + 0.25, + 20.0, + 20.0, + 0.0, + 1000.0, + 0.5, + 0.0, + 1000.0, + 0.5, + true, + false, + false +} }; -static const ParameterSet pset[5] = { set_0, set_1, set_2, set_3, set_4 }; - WobblyWindowsEffect::WobblyWindowsEffect() { initConfig(); @@ -274,30 +266,34 @@ // 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(); - } - + m_updateRegion = QRegion(); effects->prePaintScreen(data, time); } const qreal maxTime = 10.0; void WobblyWindowsEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) { - if (windows.contains(w)) { + auto it = windows.find(w); + if (it != windows.end()) { data.setTransformed(); data.quads = data.quads.makeRegularGrid(m_xTesselation, m_yTesselation); bool stop = false; qreal updateTime = time; + const QRectF rect = w->geometry(); + WindowWobblyInfos& wwi = it.value(); - while (!stop && (updateTime > maxTime)) { + while (!stop && updateTime > 0) { #if defined VERBOSE_MODE qCDebug(KWINEFFECTS) << "loop time " << updateTime << " / " << time; #endif - stop = !updateWindowWobblyDatas(w, maxTime); + stop = !updateWindowWobblyDatas(wwi, rect, maxTime); updateTime -= maxTime; } - if (!stop && updateTime > 0) { - updateWindowWobblyDatas(w, updateTime); + if (stop) { + if (wwi.status == Closing) { + w->unrefWindow(); + } + freeWobblyInfo(wwi); + windows.erase(it); } } @@ -306,8 +302,9 @@ void WobblyWindowsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) { - if (!(mask & PAINT_SCREEN_TRANSFORMED) && windows.contains(w)) { - WindowWobblyInfos& wwi = windows[w]; + QHash< const EffectWindow*, WindowWobblyInfos >::const_iterator it; + if (!(mask & PAINT_SCREEN_TRANSFORMED) && (it = windows.find(w)) != windows.end()) { + const WindowWobblyInfos& wwi = it.value(); int tx = w->geometry().x(); int ty = w->geometry().y(); double left = 0.0; @@ -336,10 +333,7 @@ void WobblyWindowsEffect::postPaintScreen() { - if (!windows.isEmpty()) { - effects->addRepaint(m_updateRegion); - } - + effects->addRepaint(m_updateRegion); // Call the next effect. effects->postPaintScreen(); } @@ -357,8 +351,9 @@ void WobblyWindowsEffect::slotWindowStepUserMovedResized(EffectWindow *w, const QRect &geometry) { Q_UNUSED(geometry) - if (windows.contains(w)) { - WindowWobblyInfos& wwi = windows[w]; + auto it = windows.find(w); + if (it != windows.end()) { + WindowWobblyInfos& wwi = it.value(); QRect rect = w->geometry(); if (rect.y() != wwi.resize_original_rect.y()) wwi.can_wobble_top = true; if (rect.x() != wwi.resize_original_rect.x()) wwi.can_wobble_left = true; @@ -369,8 +364,9 @@ void WobblyWindowsEffect::slotWindowFinishUserMovedResized(EffectWindow *w) { - if (windows.contains(w)) { - WindowWobblyInfos& wwi = windows[w]; + auto it = windows.find(w); + if (it != windows.end()) { + WindowWobblyInfos& wwi = it.value(); wwi.status = Free; QRect rect = w->geometry(); if (rect.y() != wwi.resize_original_rect.y()) wwi.can_wobble_top = true; @@ -391,8 +387,9 @@ stepMovedResized(w); } - if (windows.contains(w)) { - WindowWobblyInfos& wwi = windows[w]; + auto it = windows.find(w); + if (it != windows.end()) { + WindowWobblyInfos& wwi = it.value(); QRect rect = w->geometry(); if (rect.y() != wwi.resize_original_rect.y()) wwi.can_wobble_top = true; if (rect.x() != wwi.resize_original_rect.x()) wwi.can_wobble_left = true; @@ -403,13 +400,14 @@ void WobblyWindowsEffect::startMovedResized(EffectWindow* w) { - if (!windows.contains(w)) { + auto it = windows.find(w); + if (it == windows.end()) { WindowWobblyInfos new_wwi; initWobblyInfo(new_wwi, w->geometry()); - windows[w] = new_wwi; + it = windows.insert(w, new_wwi); } - WindowWobblyInfos& wwi = windows[w]; + WindowWobblyInfos& wwi = it.value(); wwi.status = Moving; const QRectF& rect = w->geometry(); @@ -445,13 +443,14 @@ void WobblyWindowsEffect::stepMovedResized(EffectWindow* w) { QRect new_geometry = w->geometry(); - if (!windows.contains(w)) { + auto it = windows.find(w); + if (it == windows.end()) { WindowWobblyInfos new_wwi; initWobblyInfo(new_wwi, new_geometry); - windows[w] = new_wwi; + it = windows.insert(w, new_wwi); } - WindowWobblyInfos& wwi = windows[w]; + WindowWobblyInfos& wwi = it.value(); wwi.status = Free; QRect maximized_area = effects->clientArea(MaximizeArea, w); @@ -476,37 +475,38 @@ void WobblyWindowsEffect::slotWindowAdded(EffectWindow* w) { if (m_openEffectEnabled && w->data(WindowAddedGrabRole).value() == nullptr) { - if (windows.contains(w)) { + auto it = windows.find(w); + if (it != windows.end()) { // could this happen ?? - WindowWobblyInfos& wwi = windows[w]; + WindowWobblyInfos& wwi = it.value(); wobblyOpenInit(wwi); } else { WindowWobblyInfos new_wwi; initWobblyInfo(new_wwi, w->geometry()); wobblyOpenInit(new_wwi); - windows[w] = new_wwi; + windows.insert(w, new_wwi); } } } void WobblyWindowsEffect::slotWindowClosed(EffectWindow* w) { - if (windows.contains(w)) { - WindowWobblyInfos& wwi = windows[w]; + auto it = windows.find(w); + if (it != windows.end()) { + WindowWobblyInfos& wwi = it.value(); if (m_closeEffectEnabled) { wobblyCloseInit(wwi, w); w->refWindow(); } else { freeWobblyInfo(wwi); - windows.remove(w); - if (windows.isEmpty()) - effects->addRepaintFull(); + windows.erase(it); + w->unrefWindow(); } } else if (m_closeEffectEnabled && w->data(WindowClosedGrabRole).value() == nullptr) { WindowWobblyInfos new_wwi; initWobblyInfo(new_wwi, w->geometry()); wobblyCloseInit(new_wwi, w); - windows[w] = new_wwi; + windows.insert(w, new_wwi); w->refWindow(); } } @@ -547,7 +547,7 @@ wwi.status = Closing; } -void WobblyWindowsEffect::initWobblyInfo(WindowWobblyInfos& wwi, QRect geometry) const +void WobblyWindowsEffect::initWobblyInfo(WindowWobblyInfos& wwi, const QRectF& geometry) const { wwi.count = 4 * 4; wwi.width = 4; @@ -614,11 +614,11 @@ delete[] wwi.bezierSurface; } -WobblyWindowsEffect::Pair WobblyWindowsEffect::computeBezierPoint(const WindowWobblyInfos& wwi, Pair point) const +WobblyWindowsEffect::Pair WobblyWindowsEffect::computeBezierPoint(const WindowWobblyInfos& wwi, const Pair& point) const { // compute the input value - Pair topleft = wwi.origin[0]; - Pair bottomright = wwi.origin[wwi.count-1]; + const Pair& topleft = wwi.origin[0]; + const Pair& bottomright = wwi.origin[wwi.count-1]; // ASSERT1(point.x >= topleft.x); // ASSERT1(point.y >= topleft.y); @@ -704,15 +704,8 @@ } // close the anonymous namespace -bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow* w, qreal time) +bool WobblyWindowsEffect::updateWindowWobblyDatas(WindowWobblyInfos& wwi, const QRectF& rect, qreal time) { - QRectF rect = w->geometry(); - WindowWobblyInfos& wwi = windows[w]; - - if (wwi.status == Closing) { - rect = wwi.closeRect; - } - qreal x_length = rect.width() / (wwi.width - 1.0); qreal y_length = rect.height() / (wwi.height - 1.0); @@ -753,13 +746,13 @@ // top-left if (wwi.constraint[0]) { - Pair window_pos = wwi.origin[0]; - Pair current_pos = wwi.position[0]; + const Pair& window_pos = wwi.origin[0]; + const Pair& current_pos = wwi.position[0]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[0] = accel; } else { - Pair& pos = wwi.position[0]; + const Pair& pos = wwi.position[0]; neibourgs[0] = wwi.position[1]; neibourgs[1] = wwi.position[wwi.width]; @@ -775,13 +768,13 @@ // top-right if (wwi.constraint[wwi.width-1]) { - Pair window_pos = wwi.origin[wwi.width-1]; - Pair current_pos = wwi.position[wwi.width-1]; + const Pair& window_pos = wwi.origin[wwi.width-1]; + const Pair& current_pos = wwi.position[wwi.width-1]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[wwi.width-1] = accel; } else { - Pair& pos = wwi.position[wwi.width-1]; + const Pair& pos = wwi.position[wwi.width-1]; neibourgs[0] = wwi.position[wwi.width-2]; neibourgs[1] = wwi.position[2*wwi.width-1]; @@ -797,13 +790,13 @@ // bottom-left if (wwi.constraint[wwi.width*(wwi.height-1)]) { - Pair window_pos = wwi.origin[wwi.width*(wwi.height-1)]; - Pair current_pos = wwi.position[wwi.width*(wwi.height-1)]; + const Pair& window_pos = wwi.origin[wwi.width*(wwi.height-1)]; + const Pair& current_pos = wwi.position[wwi.width*(wwi.height-1)]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[wwi.width*(wwi.height-1)] = accel; } else { - Pair& pos = wwi.position[wwi.width*(wwi.height-1)]; + const Pair& pos = wwi.position[wwi.width*(wwi.height-1)]; neibourgs[0] = wwi.position[wwi.width*(wwi.height-1)+1]; neibourgs[1] = wwi.position[wwi.width*(wwi.height-2)]; @@ -819,13 +812,13 @@ // bottom-right if (wwi.constraint[wwi.count-1]) { - Pair window_pos = wwi.origin[wwi.count-1]; - Pair current_pos = wwi.position[wwi.count-1]; + const Pair& window_pos = wwi.origin[wwi.count-1]; + const Pair& current_pos = wwi.position[wwi.count-1]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[wwi.count-1] = accel; } else { - Pair& pos = wwi.position[wwi.count-1]; + const Pair& pos = wwi.position[wwi.count-1]; neibourgs[0] = wwi.position[wwi.count-2]; neibourgs[1] = wwi.position[wwi.width*(wwi.height-1)-1]; @@ -844,13 +837,13 @@ // top border for (unsigned int i = 1; i < wwi.width - 1; ++i) { if (wwi.constraint[i]) { - Pair window_pos = wwi.origin[i]; - Pair current_pos = wwi.position[i]; + const Pair& window_pos = wwi.origin[i]; + const Pair& current_pos = wwi.position[i]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[i] = accel; } else { - Pair& pos = wwi.position[i]; + const Pair& pos = wwi.position[i]; neibourgs[0] = wwi.position[i-1]; neibourgs[1] = wwi.position[i+1]; neibourgs[2] = wwi.position[i+wwi.width]; @@ -868,13 +861,13 @@ // bottom border for (unsigned int i = wwi.width * (wwi.height - 1) + 1; i < wwi.count - 1; ++i) { if (wwi.constraint[i]) { - Pair window_pos = wwi.origin[i]; - Pair current_pos = wwi.position[i]; + const Pair& window_pos = wwi.origin[i]; + const Pair& current_pos = wwi.position[i]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[i] = accel; } else { - Pair& pos = wwi.position[i]; + const Pair& pos = wwi.position[i]; neibourgs[0] = wwi.position[i-1]; neibourgs[1] = wwi.position[i+1]; neibourgs[2] = wwi.position[i-wwi.width]; @@ -892,13 +885,13 @@ // left border for (unsigned int i = wwi.width; i < wwi.width*(wwi.height - 1); i += wwi.width) { if (wwi.constraint[i]) { - Pair window_pos = wwi.origin[i]; - Pair current_pos = wwi.position[i]; + const Pair& window_pos = wwi.origin[i]; + const Pair& current_pos = wwi.position[i]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[i] = accel; } else { - Pair& pos = wwi.position[i]; + const Pair& pos = wwi.position[i]; neibourgs[0] = wwi.position[i+1]; neibourgs[1] = wwi.position[i-wwi.width]; neibourgs[2] = wwi.position[i+wwi.width]; @@ -916,13 +909,13 @@ // right border for (unsigned int i = 2 * wwi.width - 1; i < wwi.count - 1; i += wwi.width) { if (wwi.constraint[i]) { - Pair window_pos = wwi.origin[i]; - Pair current_pos = wwi.position[i]; + const Pair& window_pos = wwi.origin[i]; + const Pair& current_pos = wwi.position[i]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[i] = accel; } else { - Pair& pos = wwi.position[i]; + const Pair& pos = wwi.position[i]; neibourgs[0] = wwi.position[i-1]; neibourgs[1] = wwi.position[i-wwi.width]; neibourgs[2] = wwi.position[i+wwi.width]; @@ -943,13 +936,13 @@ unsigned int index = i + j * wwi.width; if (wwi.constraint[index]) { - Pair window_pos = wwi.origin[index]; - Pair current_pos = wwi.position[index]; + const Pair& window_pos = wwi.origin[index]; + const Pair& current_pos = wwi.position[index]; Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y}; Pair accel = {move.x*m_stiffness, move.y*m_stiffness}; wwi.acceleration[index] = accel; } else { - Pair& pos = wwi.position[index]; + const Pair& pos = wwi.position[index]; neibourgs[0] = wwi.position[index-1]; neibourgs[1] = wwi.position[index+1]; neibourgs[2] = wwi.position[index-wwi.width]; @@ -1049,13 +1042,6 @@ #endif if (wwi.status != Moving && acc_sum < m_stopAcceleration && vel_sum < m_stopVelocity) { - if (wwi.status == Closing) { - w->unrefWindow(); - } - freeWobblyInfo(wwi); - windows.remove(w); - if (windows.isEmpty()) - effects->addRepaintFull(); return false; } @@ -1072,7 +1058,7 @@ // top-left { Pair& res = wwi.buffer[0]; - Pair vit = data[0]; + const Pair& vit = data[0]; neibourgs[0] = data[1]; neibourgs[1] = data[wwi.width]; neibourgs[2] = data[wwi.width+1]; @@ -1085,7 +1071,7 @@ // top-right { Pair& res = wwi.buffer[wwi.width-1]; - Pair vit = data[wwi.width-1]; + const Pair& vit = data[wwi.width-1]; neibourgs[0] = data[wwi.width-2]; neibourgs[1] = data[2*wwi.width-1]; neibourgs[2] = data[2*wwi.width-2]; @@ -1098,7 +1084,7 @@ // bottom-left { Pair& res = wwi.buffer[wwi.width*(wwi.height-1)]; - Pair vit = data[wwi.width*(wwi.height-1)]; + const Pair& vit = data[wwi.width*(wwi.height-1)]; neibourgs[0] = data[wwi.width*(wwi.height-1)+1]; neibourgs[1] = data[wwi.width*(wwi.height-2)]; neibourgs[2] = data[wwi.width*(wwi.height-2)+1]; @@ -1111,7 +1097,7 @@ // bottom-right { Pair& res = wwi.buffer[wwi.count-1]; - Pair vit = data[wwi.count-1]; + const Pair& vit = data[wwi.count-1]; neibourgs[0] = data[wwi.count-2]; neibourgs[1] = data[wwi.width*(wwi.height-1)-1]; neibourgs[2] = data[wwi.width*(wwi.height-1)-2]; @@ -1126,7 +1112,7 @@ // top border for (unsigned int i = 1; i < wwi.width - 1; ++i) { Pair& res = wwi.buffer[i]; - Pair vit = data[i]; + const Pair& vit = data[i]; neibourgs[0] = data[i-1]; neibourgs[1] = data[i+1]; neibourgs[2] = data[i+wwi.width]; @@ -1140,7 +1126,7 @@ // bottom border for (unsigned int i = wwi.width * (wwi.height - 1) + 1; i < wwi.count - 1; ++i) { Pair& res = wwi.buffer[i]; - Pair vit = data[i]; + const Pair& vit = data[i]; neibourgs[0] = data[i-1]; neibourgs[1] = data[i+1]; neibourgs[2] = data[i-wwi.width]; @@ -1154,7 +1140,7 @@ // left border for (unsigned int i = wwi.width; i < wwi.width*(wwi.height - 1); i += wwi.width) { Pair& res = wwi.buffer[i]; - Pair vit = data[i]; + const Pair& vit = data[i]; neibourgs[0] = data[i+1]; neibourgs[1] = data[i-wwi.width]; neibourgs[2] = data[i+wwi.width]; @@ -1168,7 +1154,7 @@ // right border for (unsigned int i = 2 * wwi.width - 1; i < wwi.count - 1; i += wwi.width) { Pair& res = wwi.buffer[i]; - Pair vit = data[i]; + const Pair& vit = data[i]; neibourgs[0] = data[i-1]; neibourgs[1] = data[i-wwi.width]; neibourgs[2] = data[i+wwi.width]; @@ -1185,7 +1171,7 @@ unsigned int index = i + j * wwi.width; Pair& res = wwi.buffer[index]; - Pair& vit = data[index]; + const Pair& vit = data[index]; neibourgs[0] = data[index-1]; neibourgs[1] = data[index+1]; neibourgs[2] = data[index-wwi.width];