2012-01-29 16:32:56 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#ifndef KWIN_SCRIPTEDEFFECT_H
|
|
|
|
#define KWIN_SCRIPTEDEFFECT_H
|
|
|
|
|
|
|
|
#include <kwinanimationeffect.h>
|
|
|
|
|
2013-12-16 08:27:19 +00:00
|
|
|
class KConfigLoader;
|
2015-07-06 14:50:33 +00:00
|
|
|
class KPluginMetaData;
|
2012-01-29 16:32:56 +00:00
|
|
|
class QScriptEngine;
|
|
|
|
class QScriptValue;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2016-02-02 17:25:36 +00:00
|
|
|
class KWIN_EXPORT ScriptedEffect : public KWin::AnimationEffect
|
2012-01-29 16:32:56 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2012-01-31 13:37:28 +00:00
|
|
|
Q_ENUMS(DataRole)
|
2015-03-28 23:15:22 +00:00
|
|
|
Q_ENUMS(Qt::Axis)
|
2012-03-09 12:16:09 +00:00
|
|
|
Q_ENUMS(Anchor)
|
2012-02-10 08:41:30 +00:00
|
|
|
Q_ENUMS(MetaType)
|
2015-03-30 09:38:38 +00:00
|
|
|
Q_ENUMS(EasingCurve)
|
2018-10-03 00:11:59 +00:00
|
|
|
/**
|
|
|
|
* True if we are the active fullscreen effect
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-10-03 00:11:59 +00:00
|
|
|
Q_PROPERTY(bool isActiveFullScreenEffect READ isActiveFullScreenEffect NOTIFY isActiveFullScreenEffectChanged)
|
2012-01-29 16:32:56 +00:00
|
|
|
public:
|
2012-01-31 13:37:28 +00:00
|
|
|
// copied from kwineffects.h
|
|
|
|
enum DataRole {
|
|
|
|
// Grab roles are used to force all other animations to ignore the window.
|
|
|
|
// The value of the data is set to the Effect's `this` value.
|
|
|
|
WindowAddedGrabRole = 1,
|
|
|
|
WindowClosedGrabRole,
|
|
|
|
WindowMinimizedGrabRole,
|
|
|
|
WindowUnminimizedGrabRole,
|
|
|
|
WindowForceBlurRole, ///< For fullscreen effects to enforce blurring of windows,
|
|
|
|
WindowBlurBehindRole, ///< For single windows to blur behind
|
2013-12-03 19:20:45 +00:00
|
|
|
WindowForceBackgroundContrastRole, ///< For fullscreen effects to enforce the background contrast,
|
|
|
|
WindowBackgroundContrastRole, ///< For single windows to enable Background contrast
|
2012-01-31 13:37:28 +00:00
|
|
|
LanczosCacheRole
|
|
|
|
};
|
2015-03-30 09:38:38 +00:00
|
|
|
enum EasingCurve {
|
|
|
|
GaussianCurve = 128
|
|
|
|
};
|
2012-01-29 16:32:56 +00:00
|
|
|
const QString &scriptFile() const {
|
|
|
|
return m_scriptFile;
|
|
|
|
}
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
void reconfigure(ReconfigureFlags flags) override;
|
2014-03-24 10:50:09 +00:00
|
|
|
int requestedEffectChainPosition() const override {
|
|
|
|
return m_chainPosition;
|
|
|
|
}
|
2012-02-01 13:26:54 +00:00
|
|
|
QString activeConfig() const;
|
|
|
|
void setActiveConfig(const QString &name);
|
2014-03-24 10:50:09 +00:00
|
|
|
static ScriptedEffect *create(const QString &effectName, const QString &pathToScript, int chainPosition);
|
2015-07-06 14:50:33 +00:00
|
|
|
static ScriptedEffect *create(const KPluginMetaData &effect);
|
2016-08-10 07:24:53 +00:00
|
|
|
static bool supported();
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
~ScriptedEffect() override;
|
2012-01-31 13:37:28 +00:00
|
|
|
/**
|
|
|
|
* Whether another effect has grabbed the @p w with the given @p grabRole.
|
|
|
|
* @param w The window to check
|
|
|
|
* @param grabRole The grab role to check
|
|
|
|
* @returns @c true if another window has grabbed the effect, @c false otherwise
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-01-31 13:37:28 +00:00
|
|
|
Q_SCRIPTABLE bool isGrabbed(KWin::EffectWindow *w, DataRole grabRole);
|
2018-10-27 20:13:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Grabs the window with the specified role.
|
|
|
|
*
|
|
|
|
* @param w The window.
|
|
|
|
* @param grabRole The grab role.
|
|
|
|
* @param force By default, if the window is already grabbed by another effect,
|
|
|
|
* then that window won't be grabbed by effect that called this method. If you
|
|
|
|
* would like to grab a window even if it's grabbed by another effect, then
|
|
|
|
* pass @c true.
|
|
|
|
* @returns @c true if the window was grabbed successfully, otherwise @c false.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-10-27 20:13:53 +00:00
|
|
|
Q_SCRIPTABLE bool grab(KWin::EffectWindow *w, DataRole grabRole, bool force = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ungrabs the window with the specified role.
|
|
|
|
*
|
|
|
|
* @param w The window.
|
|
|
|
* @param grabRole The grab role.
|
|
|
|
* @returns @c true if the window was ungrabbed successfully, otherwise @c false.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-10-27 20:13:53 +00:00
|
|
|
Q_SCRIPTABLE bool ungrab(KWin::EffectWindow *w, DataRole grabRole);
|
|
|
|
|
2012-02-01 13:26:54 +00:00
|
|
|
/**
|
2012-02-10 08:11:28 +00:00
|
|
|
* Reads the value from the configuration data for the given key.
|
|
|
|
* @param key The key to search for
|
|
|
|
* @param defaultValue The value to return if the key is not found
|
2012-02-01 13:26:54 +00:00
|
|
|
* @returns The config value if present
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-02-10 08:11:28 +00:00
|
|
|
Q_SCRIPTABLE QVariant readConfig(const QString &key, const QVariant defaultValue = QVariant());
|
2012-03-25 07:59:01 +00:00
|
|
|
void registerShortcut(QAction *a, QScriptValue callback);
|
|
|
|
const QHash<QAction*, QScriptValue> &shortcutCallbacks() const {
|
|
|
|
return m_shortcutCallbacks;
|
|
|
|
}
|
2012-05-10 14:09:36 +00:00
|
|
|
QHash<int, QList<QScriptValue > > &screenEdgeCallbacks() {
|
|
|
|
return m_screenEdgeCallbacks;
|
|
|
|
}
|
2012-01-29 16:32:56 +00:00
|
|
|
|
2018-10-03 00:11:59 +00:00
|
|
|
bool isActiveFullScreenEffect() const;
|
|
|
|
|
2017-04-02 13:42:18 +00:00
|
|
|
bool registerTouchScreenCallback(int edge, QScriptValue callback);
|
|
|
|
bool unregisterTouchScreenCallback(int edge);
|
|
|
|
|
2012-01-29 16:32:56 +00:00
|
|
|
public Q_SLOTS:
|
2018-08-07 20:32:53 +00:00
|
|
|
//curve should be of type QEasingCurve::type or ScriptedEffect::EasingCurve
|
[effects/dialogparent] Fix flickering of parent windows
Summary:
If a modal window is closed and some alternative effect that animates
the disappearing of windows is enabled(e.g. the Glide effect, or the
Scale effect), the Dialog Parent effect can cause flickering of the
parent window because its animation duration doesn't match duration of
those alternative effects.
Also, if the Fade effect, the Glide effect, and the Scale effect are
disabled, the Dialog Parent will keep the parent window alive for no
good reason.
This change addresses that problem by adding keepAlive property to
`animate` function so scripted effects have more control over lifetime
of animated windows.
If both a modal window and its parent window are closed at the same time
(and there is no effect that animates the disappearing of windows), the
Dialog Parent will stop immediately(because windowDeleted will be
emitted right after windowClosed signal).
If both a modal window and its parent window are closed at the same time
(and there is effect that animates the disappearing of windows), the
Dialog Parent won't reference the latter window. Thus, it won't cause
flickering. I.e. it will "passively" animate parent windows.
BUG: 355036
FIXED-IN: 5.15.0
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14919
2018-10-10 07:36:45 +00:00
|
|
|
quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint metaData = 0, int curve = QEasingCurve::Linear, int delay = 0, bool fullScreen = false, bool keepAlive = true);
|
|
|
|
quint64 set(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint metaData = 0, int curve = QEasingCurve::Linear, int delay = 0, bool fullScreen = false, bool keepAlive = true);
|
2016-02-03 18:10:00 +00:00
|
|
|
bool retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime = -1);
|
[scripting] Introduce redirect function
Summary:
Consider current implementation of the Squash effect: if a window was
minimized, an animation will be started; if the window is unminimized
and the animation is still active (that can happen when user clicks on
app's icon really fast), the animation will be stopped and a new one will
be created. Such behavior can lead to rapid jumps in the observed
"animation".
A better approach would be first try to **reverse** the already active
animation, and if that attempt wasn't successful, start a new animation.
This patch introduces a new function to the scripted effects API that
lets JavaScript effects to control direction of animations. The
prototype of the function looks as follows:
redirect(<animation id(s)>, <direction>, [<termination policy>])
the first argument is an animation id or a list of animation ids, the
second argument specifies the new direction of the animation or
animations if a list of ids was passed as the first argument. The
third argument specifies whether the animation(s) should be terminated
when it(they) reaches the source position, currently it's relevant only
for animations that are created with set() function. The termination
policy argument is optional, by default it's Effect.TerminateAtSource.
We can use this function to fix issues with rapid jumps in the Squash
effect. Also, redirect() lets us to write effects for simple animations
in slightly different style: first, we have to start the main animation
(e.g. for the Dialog Parent effect, it would be dimming of main windows)
and then change direction of the animation depending on external events,
e.g. when the Desktop Cube effect is activated.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, abetts, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16449
2018-10-24 19:58:29 +00:00
|
|
|
bool redirect(quint64 animationId, Direction direction, TerminationFlags terminationFlags = TerminateAtSource);
|
2018-10-25 18:02:36 +00:00
|
|
|
bool complete(quint64 animationId);
|
2013-02-28 18:52:16 +00:00
|
|
|
bool cancel(quint64 animationId) { return AnimationEffect::cancel(animationId); }
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
bool borderActivated(ElectricBorder border) override;
|
2012-01-29 16:32:56 +00:00
|
|
|
|
2012-02-01 13:26:54 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Signal emitted whenever the effect's config changed.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-02-01 13:26:54 +00:00
|
|
|
void configChanged();
|
2015-03-30 09:38:38 +00:00
|
|
|
void animationEnded(KWin::EffectWindow *w, quint64 animationId);
|
2018-10-03 00:11:59 +00:00
|
|
|
void isActiveFullScreenEffectChanged();
|
2015-03-30 09:38:38 +00:00
|
|
|
|
|
|
|
protected:
|
2018-07-23 21:52:58 +00:00
|
|
|
ScriptedEffect();
|
|
|
|
QScriptEngine *engine() const;
|
|
|
|
bool init(const QString &effectName, const QString &pathToScript);
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
void animationEnded(KWin::EffectWindow *w, Attribute a, uint meta) override;
|
2012-02-01 13:26:54 +00:00
|
|
|
|
2012-01-29 16:32:56 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void signalHandlerException(const QScriptValue &value);
|
2012-03-25 07:59:01 +00:00
|
|
|
void globalShortcutTriggered();
|
2012-01-29 16:32:56 +00:00
|
|
|
private:
|
|
|
|
QScriptEngine *m_engine;
|
2012-02-01 13:26:54 +00:00
|
|
|
QString m_effectName;
|
2012-01-29 16:32:56 +00:00
|
|
|
QString m_scriptFile;
|
2012-03-25 07:59:01 +00:00
|
|
|
QHash<QAction*, QScriptValue> m_shortcutCallbacks;
|
2012-05-10 14:09:36 +00:00
|
|
|
QHash<int, QList<QScriptValue> > m_screenEdgeCallbacks;
|
2013-12-16 08:27:19 +00:00
|
|
|
KConfigLoader *m_config;
|
2014-03-24 10:50:09 +00:00
|
|
|
int m_chainPosition;
|
2017-04-02 13:42:18 +00:00
|
|
|
QHash<int, QAction*> m_touchScreenEdgeCallbacks;
|
2018-10-03 00:11:59 +00:00
|
|
|
Effect *m_activeFullScreenEffect = nullptr;
|
2012-01-29 16:32:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // KWIN_SCRIPTEDEFFECT_H
|