diff --git a/effects/wobblywindows/wobblywindows.h b/effects/wobblywindows/wobblywindows.h --- a/effects/wobblywindows/wobblywindows.h +++ b/effects/wobblywindows/wobblywindows.h @@ -136,11 +136,6 @@ private: - 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; Pair* position; @@ -199,12 +194,18 @@ bool m_moveWobble; // Expands m_moveEffectEnabled bool m_resizeWobble; - void initWobblyInfo(WindowWobblyInfos& wwi, QRect geometry) const; + void cancelWindowGrab(EffectWindow* w, int grabRole); + void startMovedResized(EffectWindow* w); + void stepMovedResized(EffectWindow* w); + bool updateWindowWobblyDatas(WindowWobblyInfos& wwi, const QRectF& rect, qreal time); + void adjustWindowWobblyAbilities(WindowWobblyInfos& wwi, const QRectF& rect); + + 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, Pair point) const; + WobblyWindowsEffect::Pair computeBezierPoint(const WindowWobblyInfos& wwi, const Pair& point) const; static void heightRingLinearMean(Pair** data_pointer, WindowWobblyInfos& wwi); 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,38 @@ // 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) { + if (!windows.empty()) { 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; + static const qreal maxTime = 5; + 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 +306,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 >::iterator it; + if (!(mask & PAINT_SCREEN_TRANSFORMED) && (it = windows.find(w)) != windows.end()) { + WindowWobblyInfos& wwi = it.value(); int tx = w->geometry().x(); int ty = w->geometry().y(); double left = 0.0; @@ -354,29 +355,38 @@ } } +void WobblyWindowsEffect::adjustWindowWobblyAbilities(WindowWobblyInfos& wwi, const QRectF& rect) +{ + 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; + } + if (rect.right() != wwi.resize_original_rect.right()) { + wwi.can_wobble_right = true; + } + if (rect.bottom() != wwi.resize_original_rect.bottom()) { + wwi.can_wobble_bottom = true; + } +} + void WobblyWindowsEffect::slotWindowStepUserMovedResized(EffectWindow *w, const QRect &geometry) { Q_UNUSED(geometry) - if (windows.contains(w)) { - WindowWobblyInfos& wwi = windows[w]; - 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; - if (rect.right() != wwi.resize_original_rect.right()) wwi.can_wobble_right = true; - if (rect.bottom() != wwi.resize_original_rect.bottom()) wwi.can_wobble_bottom = true; + auto it = windows.find(w); + if (it != windows.end()) { + adjustWindowWobblyAbilities(it.value(), w->geometry()); } } 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; - if (rect.x() != wwi.resize_original_rect.x()) wwi.can_wobble_left = true; - if (rect.right() != wwi.resize_original_rect.right()) wwi.can_wobble_right = true; - if (rect.bottom() != wwi.resize_original_rect.bottom()) wwi.can_wobble_bottom = true; + adjustWindowWobblyAbilities(wwi, w->geometry()); } } @@ -389,27 +399,25 @@ if (m_moveWobble && m_resizeWobble) { stepMovedResized(w); - } - - if (windows.contains(w)) { - WindowWobblyInfos& wwi = windows[w]; - 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; - if (rect.right() != wwi.resize_original_rect.right()) wwi.can_wobble_right = true; - if (rect.bottom() != wwi.resize_original_rect.bottom()) wwi.can_wobble_bottom = true; + adjustWindowWobblyAbilities(windows[w], w->geometry()); + } else { + auto it = windows.find(w); + if (it != windows.end()) { + adjustWindowWobblyAbilities(it.value(), w->geometry()); + } } } 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 +453,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 +485,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 +557,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 +624,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 +714,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 +756,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 +778,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 +800,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 +822,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 +847,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 +871,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 +895,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 +919,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 +946,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 +1052,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 +1068,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 +1081,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 +1094,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 +1107,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 +1122,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 +1136,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 +1150,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 +1164,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 +1181,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];