2013-11-25 08:26:17 +00:00
|
|
|
include(ECMMarkAsTest)
|
|
|
|
|
|
|
|
macro(KWINEFFECTS_UNIT_TESTS)
|
|
|
|
foreach(_testname ${ARGN})
|
|
|
|
add_executable(${_testname} ${_testname}.cpp)
|
2017-08-25 16:18:20 +00:00
|
|
|
add_test(NAME kwineffects-${_testname} COMMAND ${_testname})
|
2021-01-30 16:18:21 +00:00
|
|
|
target_link_libraries(${_testname} Qt::Test kwineffects)
|
2013-11-25 08:26:17 +00:00
|
|
|
ecm_mark_as_test(${_testname})
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
kwineffects_unit_tests(
|
|
|
|
windowquadlisttest
|
[libkwineffects] Add TimeLine helper
Summary:
Most effects use QTimeLine in the following manner
```lang=cpp
if (...) {
m_timeline->setCurrentTime(m_timeline->currentTime() + time);
} else {
m_timeline->setCurrentTime(m_timeline->currentTime() - time);
}
```
Because effects do not rely on a timer that QTimeLine has, they can't
toggle direction of the QTimeLine, which makes somewhat harder to write
effects. In some cases that's obvious what condition to use to figure
out whether to add or subtract `time`, but there are cases when it's
not. In addition to that, setCurrentTime allows to have negative
currentTime, which in some cases causes bugs.
And overall, the way effects use QTimeLine is really hack-ish. It makes
more sense just to use an integer accumulator(like the Fall Apart
effect is doing) than to use QTimeLine.
Another problem with QTimeLine is that it's a QObject and some effects
do
```lang=cpp
class WindowInfo
{
public:
~WindowInfo();
QTimeLine *timeLine;
};
WindowInfo::~WindowInfo()
{
delete timeLine;
}
// ...
QHash<EffectWindow*, WindowInfo> m_windows;
```
which is unsafe.
This change adds the TimeLine class. The TimeLine class is a timeline
helper that designed specifically for needs of effects.
Demo
```lang=cpp
TimeLine timeLine(1000, TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // false
timeLine.update(420);
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.toggleDirection();
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(100);
timeLine.value(); // 0.32
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(1000);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // true
```
Test Plan: Ran tests.
Reviewers: #kwin, davidedmundson, graesslin
Reviewed By: #kwin, davidedmundson, graesslin
Subscribers: romangg, graesslin, anthonyfieroni, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D13740
2018-06-28 18:13:43 +00:00
|
|
|
timelinetest
|
2013-11-25 08:26:17 +00:00
|
|
|
)
|
2016-08-05 06:47:32 +00:00
|
|
|
|
2021-02-09 19:31:40 +00:00
|
|
|
add_executable(kwinglplatformtest kwinglplatformtest.cpp mock_gl.cpp ../../src/libkwineffects/kwinglplatform.cpp)
|
2017-08-25 16:18:20 +00:00
|
|
|
add_test(NAME kwineffects-kwinglplatformtest COMMAND kwinglplatformtest)
|
2023-02-24 18:22:37 +00:00
|
|
|
target_link_libraries(kwinglplatformtest Qt::Test Qt::Gui KF6::ConfigCore XCB::XCB)
|
2016-08-05 06:47:32 +00:00
|
|
|
ecm_mark_as_test(kwinglplatformtest)
|