2012-01-29 20:32:56 +04: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 12:27:19 +04:00
|
|
|
class KConfigLoader;
|
2015-07-06 17:50:33 +03:00
|
|
|
class KPluginMetaData;
|
2012-01-29 20:32:56 +04:00
|
|
|
class QScriptEngine;
|
|
|
|
class QScriptValue;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
class ScriptedEffect : public KWin::AnimationEffect
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2012-01-31 17:37:28 +04:00
|
|
|
Q_ENUMS(DataRole)
|
2015-03-29 02:15:22 +03:00
|
|
|
Q_ENUMS(Qt::Axis)
|
2012-03-09 16:16:09 +04:00
|
|
|
Q_ENUMS(Anchor)
|
2012-02-10 12:41:30 +04:00
|
|
|
Q_ENUMS(MetaType)
|
2015-03-30 12:38:38 +03:00
|
|
|
Q_ENUMS(EasingCurve)
|
2012-01-29 20:32:56 +04:00
|
|
|
public:
|
2012-01-31 17:37:28 +04: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 23:20:45 +04:00
|
|
|
WindowForceBackgroundContrastRole, ///< For fullscreen effects to enforce the background contrast,
|
|
|
|
WindowBackgroundContrastRole, ///< For single windows to enable Background contrast
|
2012-01-31 17:37:28 +04:00
|
|
|
LanczosCacheRole
|
|
|
|
};
|
2015-03-30 12:38:38 +03:00
|
|
|
enum EasingCurve {
|
|
|
|
GaussianCurve = 128
|
|
|
|
};
|
2012-01-29 20:32:56 +04:00
|
|
|
const QString &scriptFile() const {
|
|
|
|
return m_scriptFile;
|
|
|
|
}
|
2012-02-01 17:26:54 +04:00
|
|
|
virtual void reconfigure(ReconfigureFlags flags);
|
2014-03-24 14:50:09 +04:00
|
|
|
int requestedEffectChainPosition() const override {
|
|
|
|
return m_chainPosition;
|
|
|
|
}
|
2012-02-01 17:26:54 +04:00
|
|
|
QString activeConfig() const;
|
|
|
|
void setActiveConfig(const QString &name);
|
2014-03-24 14:50:09 +04:00
|
|
|
static ScriptedEffect *create(const QString &effectName, const QString &pathToScript, int chainPosition);
|
2015-07-06 17:50:33 +03:00
|
|
|
static ScriptedEffect *create(const KPluginMetaData &effect);
|
2012-05-10 18:09:36 +04:00
|
|
|
virtual ~ScriptedEffect();
|
2012-01-31 17:37:28 +04: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
|
|
|
|
**/
|
|
|
|
Q_SCRIPTABLE bool isGrabbed(KWin::EffectWindow *w, DataRole grabRole);
|
2012-02-01 17:26:54 +04:00
|
|
|
/**
|
2012-02-10 12:11:28 +04: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 17:26:54 +04:00
|
|
|
* @returns The config value if present
|
|
|
|
**/
|
2012-02-10 12:11:28 +04:00
|
|
|
Q_SCRIPTABLE QVariant readConfig(const QString &key, const QVariant defaultValue = QVariant());
|
2012-03-25 11:59:01 +04:00
|
|
|
void registerShortcut(QAction *a, QScriptValue callback);
|
|
|
|
const QHash<QAction*, QScriptValue> &shortcutCallbacks() const {
|
|
|
|
return m_shortcutCallbacks;
|
|
|
|
}
|
2012-05-10 18:09:36 +04:00
|
|
|
QHash<int, QList<QScriptValue > > &screenEdgeCallbacks() {
|
|
|
|
return m_screenEdgeCallbacks;
|
|
|
|
}
|
2012-01-29 20:32:56 +04:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2015-03-29 02:15:22 +03:00
|
|
|
quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint metaData = 0, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
|
|
|
|
quint64 set(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint metaData = 0, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
|
2013-02-28 22:52:16 +04:00
|
|
|
bool cancel(quint64 animationId) { return AnimationEffect::cancel(animationId); }
|
2013-01-22 15:47:06 +04:00
|
|
|
virtual bool borderActivated(ElectricBorder border);
|
2012-01-29 20:32:56 +04:00
|
|
|
|
2012-02-01 17:26:54 +04:00
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Signal emitted whenever the effect's config changed.
|
|
|
|
**/
|
|
|
|
void configChanged();
|
2015-03-30 12:38:38 +03:00
|
|
|
void animationEnded(KWin::EffectWindow *w, quint64 animationId);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void animationEnded(KWin::EffectWindow *w, Attribute a, uint meta);
|
2012-02-01 17:26:54 +04:00
|
|
|
|
2012-01-29 20:32:56 +04:00
|
|
|
private Q_SLOTS:
|
|
|
|
void signalHandlerException(const QScriptValue &value);
|
2012-03-25 11:59:01 +04:00
|
|
|
void globalShortcutTriggered();
|
2012-01-29 20:32:56 +04:00
|
|
|
private:
|
|
|
|
ScriptedEffect();
|
2012-02-01 17:26:54 +04:00
|
|
|
bool init(const QString &effectName, const QString &pathToScript);
|
2012-01-29 20:32:56 +04:00
|
|
|
QScriptEngine *m_engine;
|
2012-02-01 17:26:54 +04:00
|
|
|
QString m_effectName;
|
2012-01-29 20:32:56 +04:00
|
|
|
QString m_scriptFile;
|
2012-03-25 11:59:01 +04:00
|
|
|
QHash<QAction*, QScriptValue> m_shortcutCallbacks;
|
2012-05-10 18:09:36 +04:00
|
|
|
QHash<int, QList<QScriptValue> > m_screenEdgeCallbacks;
|
2013-12-16 12:27:19 +04:00
|
|
|
KConfigLoader *m_config;
|
2014-03-24 14:50:09 +04:00
|
|
|
int m_chainPosition;
|
2012-01-29 20:32:56 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // KWIN_SCRIPTEDEFFECT_H
|