2010-09-21 14:31:40 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
|
2011-12-23 10:52:06 +00:00
|
|
|
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
2011-01-01 09:37:08 +00:00
|
|
|
#ifndef KWIN_SCRIPTING_H
|
|
|
|
#define KWIN_SCRIPTING_H
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2012-05-10 14:09:36 +00:00
|
|
|
#include <kwinglobals.h>
|
|
|
|
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QStringList>
|
2012-05-06 13:26:41 +00:00
|
|
|
#include <QtScript/QScriptEngineAgent>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QJSValue>
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2019-02-22 14:40:15 +00:00
|
|
|
#include <QDBusContext>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
|
2013-08-12 11:09:46 +00:00
|
|
|
class QQmlComponent;
|
2014-03-03 12:23:55 +00:00
|
|
|
class QQmlContext;
|
2013-08-12 11:09:46 +00:00
|
|
|
class QQmlEngine;
|
2012-03-25 07:59:01 +00:00
|
|
|
class QAction;
|
2012-06-30 14:13:47 +00:00
|
|
|
class QDBusPendingCallWatcher;
|
2013-03-27 10:37:43 +00:00
|
|
|
class QGraphicsScene;
|
2012-08-31 11:28:31 +00:00
|
|
|
class QMenu;
|
2012-04-28 07:55:11 +00:00
|
|
|
class QMutex;
|
2011-12-23 10:52:06 +00:00
|
|
|
class QScriptEngine;
|
|
|
|
class QScriptValue;
|
2013-11-07 13:10:35 +00:00
|
|
|
class QQuickWindow;
|
2012-02-25 10:30:45 +00:00
|
|
|
class KConfigGroup;
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2012-04-28 07:55:11 +00:00
|
|
|
/// @c true == javascript, @c false == qml
|
|
|
|
typedef QList< QPair<bool, QPair<QString, QString > > > LoadScriptList;
|
|
|
|
|
2010-09-21 14:31:40 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2015-03-06 09:49:37 +00:00
|
|
|
class AbstractClient;
|
2012-05-06 13:26:41 +00:00
|
|
|
class ScriptUnloaderAgent;
|
2016-11-02 21:56:56 +00:00
|
|
|
class QtScriptWorkspaceWrapper;
|
2019-09-24 08:48:08 +00:00
|
|
|
class X11Client;
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2016-08-19 07:12:49 +00:00
|
|
|
class KWIN_EXPORT AbstractScript : public QObject
|
2012-02-19 14:43:24 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-24 15:33:40 +00:00
|
|
|
AbstractScript(int id, QString scriptName, QString pluginName, QObject *parent = nullptr);
|
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
|
|
|
~AbstractScript() override;
|
2012-02-19 14:43:24 +00:00
|
|
|
QString fileName() const {
|
2019-01-09 19:40:09 +00:00
|
|
|
return m_fileName;
|
2012-02-19 14:43:24 +00:00
|
|
|
}
|
2012-03-01 10:29:24 +00:00
|
|
|
const QString &pluginName() {
|
|
|
|
return m_pluginName;
|
|
|
|
}
|
2012-02-19 14:43:24 +00:00
|
|
|
|
2012-03-01 10:28:27 +00:00
|
|
|
void printMessage(const QString &message);
|
2012-03-25 07:59:01 +00:00
|
|
|
void registerShortcut(QAction *a, QScriptValue callback);
|
2012-08-31 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Registers the given @p callback to be invoked whenever the UserActionsMenu is about
|
|
|
|
* to be showed. In the callback the script can create a further sub menu or menu entry to be
|
|
|
|
* added to the UserActionsMenu.
|
|
|
|
*
|
|
|
|
* @param callback Script method to execute when the UserActionsMenu is about to be shown.
|
|
|
|
* @return void
|
|
|
|
* @see actionsForUserActionMenu
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-08-31 11:28:31 +00:00
|
|
|
void registerUseractionsMenuCallback(QScriptValue callback);
|
|
|
|
/**
|
|
|
|
* @brief Creates actions for the UserActionsMenu by invoking the registered callbacks.
|
|
|
|
*
|
|
|
|
* This method invokes all the callbacks previously registered with registerUseractionsMenuCallback.
|
|
|
|
* The Client @p c is passed in as an argument to the invoked method.
|
|
|
|
*
|
|
|
|
* The invoked method is supposed to return a JavaScript object containing either the menu or
|
|
|
|
* menu entry to be added. In case the callback returns a null or undefined or any other invalid
|
|
|
|
* value, it is not considered for adding to the menu.
|
|
|
|
*
|
|
|
|
* The JavaScript object structure for a menu entry looks like the following:
|
|
|
|
* @code
|
|
|
|
* {
|
|
|
|
* title: "My Menu Entry",
|
|
|
|
* checkable: true,
|
|
|
|
* checked: false,
|
|
|
|
* triggered: function (action) {
|
|
|
|
* // callback when the menu entry is triggered with the QAction as argument
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* To construct a complete Menu the JavaScript object looks like the following:
|
|
|
|
* @code
|
|
|
|
* {
|
|
|
|
* title: "My Menu Title",
|
|
|
|
* items: [{...}, {...}, ...] // list of menu entries as described above
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* The returned JavaScript object is introspected and for a menu entry a QAction is created,
|
|
|
|
* while for a menu a QMenu is created and QActions for the individual entries. Of course it
|
|
|
|
* is allowed to have nested structures.
|
|
|
|
*
|
|
|
|
* All created objects are (grand) children to the passed in @p parent menu, so that they get
|
|
|
|
* deleted whenever the menu is destroyed.
|
|
|
|
*
|
|
|
|
* @param c The Client for which the menu is invoked, passed to the callback
|
|
|
|
* @param parent The Parent for the created Menus or Actions
|
|
|
|
* @return QList< QAction* > List of QActions obtained from asking the registered callbacks
|
|
|
|
* @see registerUseractionsMenuCallback
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-03-06 09:49:37 +00:00
|
|
|
QList<QAction*> actionsForUserActionMenu(AbstractClient *c, QMenu *parent);
|
2012-03-01 10:28:27 +00:00
|
|
|
|
2012-02-25 10:30:45 +00:00
|
|
|
KConfigGroup config() const;
|
2012-03-25 07:59:01 +00:00
|
|
|
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-02-25 10:30:45 +00:00
|
|
|
|
2012-06-30 14:13:47 +00:00
|
|
|
int registerCallback(QScriptValue value);
|
|
|
|
|
2012-02-19 14:43:24 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
Q_SCRIPTABLE void stop();
|
|
|
|
Q_SCRIPTABLE virtual void run() = 0;
|
2012-06-30 14:13:47 +00:00
|
|
|
void slotPendingDBusCall(QDBusPendingCallWatcher *watcher);
|
2012-02-19 14:43:24 +00:00
|
|
|
|
2012-03-25 07:59:01 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void globalShortcutTriggered();
|
2013-01-22 11:47:06 +00:00
|
|
|
bool borderActivated(ElectricBorder edge);
|
2012-08-31 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Slot invoked when a menu action is destroyed. Used to remove the action and callback
|
|
|
|
* from the map of actions.
|
|
|
|
*
|
|
|
|
* @param object The destroyed action
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-08-31 11:28:31 +00:00
|
|
|
void actionDestroyed(QObject *object);
|
2012-03-25 07:59:01 +00:00
|
|
|
|
2012-03-01 10:28:27 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
Q_SCRIPTABLE void print(const QString &text);
|
2016-08-19 07:12:49 +00:00
|
|
|
void runningChanged(bool);
|
2012-03-01 10:28:27 +00:00
|
|
|
|
2012-02-19 14:43:24 +00:00
|
|
|
protected:
|
|
|
|
bool running() const {
|
|
|
|
return m_running;
|
|
|
|
}
|
|
|
|
void setRunning(bool running) {
|
2016-08-19 07:12:49 +00:00
|
|
|
if (m_running == running) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-19 14:43:24 +00:00
|
|
|
m_running = running;
|
2016-08-19 07:12:49 +00:00
|
|
|
emit runningChanged(m_running);
|
2012-02-19 14:43:24 +00:00
|
|
|
}
|
|
|
|
int scriptId() const {
|
|
|
|
return m_scriptId;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-31 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Parses the @p value to either a QMenu or QAction.
|
|
|
|
*
|
|
|
|
* @param value The ScriptValue describing either a menu or action
|
|
|
|
* @param parent The parent to use for the created menu or action
|
|
|
|
* @return QAction* The parsed action or menu action, if parsing fails returns @c null.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-08-31 11:28:31 +00:00
|
|
|
QAction *scriptValueToAction(QScriptValue &value, QMenu *parent);
|
|
|
|
/**
|
|
|
|
* @brief Creates a new QAction from the provided data and registers it for invoking the
|
|
|
|
* @p callback when the action is triggered.
|
|
|
|
*
|
|
|
|
* The created action is added to the map of actions and callbacks shared with the global
|
|
|
|
* shortcuts.
|
|
|
|
*
|
|
|
|
* @param title The title of the action
|
|
|
|
* @param checkable Whether the action is checkable
|
|
|
|
* @param checked Whether the checkable action is checked
|
|
|
|
* @param callback The callback to invoke when the action is triggered
|
|
|
|
* @param parent The parent to be used for the new created action
|
|
|
|
* @return QAction* The created action
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-08-31 11:28:31 +00:00
|
|
|
QAction *createAction(const QString &title, bool checkable, bool checked, QScriptValue &callback, QMenu *parent);
|
|
|
|
/**
|
|
|
|
* @brief Parses the @p items and creates a QMenu from it.
|
|
|
|
*
|
|
|
|
* @param title The title of the Menu.
|
|
|
|
* @param items JavaScript Array containing Menu items.
|
|
|
|
* @param parent The parent to use for the new created menu
|
|
|
|
* @return QAction* The menu action for the new Menu
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-08-31 11:28:31 +00:00
|
|
|
QAction *createMenu(const QString &title, QScriptValue &items, QMenu *parent);
|
2012-02-19 14:43:24 +00:00
|
|
|
int m_scriptId;
|
2019-01-09 19:40:09 +00:00
|
|
|
QString m_fileName;
|
2012-02-25 10:30:45 +00:00
|
|
|
QString m_pluginName;
|
2012-02-19 14:43:24 +00:00
|
|
|
bool m_running;
|
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;
|
2012-06-30 14:13:47 +00:00
|
|
|
QHash<int, QScriptValue> m_callbacks;
|
2012-08-31 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* @brief List of registered functions to call when the UserActionsMenu is about to show
|
|
|
|
* to add further entries.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-08-31 11:28:31 +00:00
|
|
|
QList<QScriptValue> m_userActionsMenuCallbacks;
|
2012-02-19 14:43:24 +00:00
|
|
|
};
|
|
|
|
|
2019-02-22 14:40:15 +00:00
|
|
|
class Script : public AbstractScript, QDBusContext
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-12-23 07:49:28 +00:00
|
|
|
Q_OBJECT
|
2011-12-23 10:52:06 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
2011-12-23 07:49:28 +00:00
|
|
|
|
2014-02-24 15:33:40 +00:00
|
|
|
Script(int id, QString scriptName, QString pluginName, QObject *parent = nullptr);
|
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
|
|
|
~Script() override;
|
2012-05-06 13:26:41 +00:00
|
|
|
QScriptEngine *engine() {
|
|
|
|
return m_engine;
|
|
|
|
}
|
2011-12-23 10:52:06 +00:00
|
|
|
|
2017-04-02 13:42:18 +00:00
|
|
|
bool registerTouchScreenCallback(int edge, QScriptValue callback);
|
|
|
|
bool unregisterTouchScreenCallback(int edge);
|
|
|
|
|
2011-12-23 10:52:06 +00:00
|
|
|
public Q_SLOTS:
|
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
|
|
|
Q_SCRIPTABLE void run() override;
|
2011-12-23 10:52:06 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
Q_SCRIPTABLE void printError(const QString &text);
|
2011-12-23 07:49:28 +00:00
|
|
|
|
2013-07-22 14:07:39 +00:00
|
|
|
private Q_SLOTS:
|
2011-12-23 07:49:28 +00:00
|
|
|
/**
|
2019-02-02 18:17:44 +00:00
|
|
|
* A nice clean way to handle exceptions in scripting.
|
|
|
|
* TODO: Log to file, show from notifier..
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-12-23 07:49:28 +00:00
|
|
|
void sigException(const QScriptValue &exception);
|
2012-04-29 17:30:12 +00:00
|
|
|
/**
|
|
|
|
* Callback for when loadScriptFromFile has finished.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-04-29 17:30:12 +00:00
|
|
|
void slotScriptLoadedFromFile();
|
2011-12-23 07:49:28 +00:00
|
|
|
|
|
|
|
private:
|
2013-08-12 11:09:46 +00:00
|
|
|
void installScriptFunctions(QScriptEngine *engine);
|
2012-04-29 17:30:12 +00:00
|
|
|
/**
|
|
|
|
* Read the script from file into a byte array.
|
|
|
|
* If file cannot be read an empty byte array is returned.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-01-09 19:40:09 +00:00
|
|
|
QByteArray loadScriptFromFile(const QString &fileName);
|
2011-12-23 07:49:28 +00:00
|
|
|
QScriptEngine *m_engine;
|
2019-02-22 14:40:15 +00:00
|
|
|
QDBusMessage m_invocationContext;
|
2012-04-29 17:30:12 +00:00
|
|
|
bool m_starting;
|
2012-05-06 13:26:41 +00:00
|
|
|
QScopedPointer<ScriptUnloaderAgent> m_agent;
|
2017-04-02 13:42:18 +00:00
|
|
|
QHash<int, QAction*> m_touchScreenEdgeCallbacks;
|
2012-05-06 13:26:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ScriptUnloaderAgent : public QScriptEngineAgent
|
|
|
|
{
|
|
|
|
public:
|
2012-12-29 06:34:38 +00:00
|
|
|
explicit ScriptUnloaderAgent(Script *script);
|
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 scriptUnload(qint64 id) override;
|
2012-05-06 13:26:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Script *m_script;
|
2012-02-19 14:43:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DeclarativeScript : public AbstractScript
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
|
|
|
|
public:
|
2014-02-24 15:33:40 +00:00
|
|
|
explicit DeclarativeScript(int id, QString scriptName, QString pluginName, QObject *parent = nullptr);
|
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
|
|
|
~DeclarativeScript() override;
|
2012-02-19 14:43:24 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
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
|
|
|
Q_SCRIPTABLE void run() override;
|
2012-02-19 14:43:24 +00:00
|
|
|
|
2013-03-27 10:37:43 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void createComponent();
|
|
|
|
|
2012-02-19 14:43:24 +00:00
|
|
|
private:
|
2014-03-03 12:23:55 +00:00
|
|
|
QQmlContext *m_context;
|
2013-08-12 11:09:46 +00:00
|
|
|
QQmlComponent *m_component;
|
|
|
|
};
|
|
|
|
|
|
|
|
class JSEngineGlobalMethodsWrapper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_ENUMS(ClientAreaOption)
|
|
|
|
public:
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//enums copy&pasted from kwinglobals.h for exporting
|
|
|
|
|
|
|
|
enum ClientAreaOption {
|
|
|
|
///< geometry where a window will be initially placed after being mapped
|
|
|
|
PlacementArea,
|
|
|
|
///< window movement snapping area? ignore struts
|
|
|
|
MovementArea,
|
|
|
|
///< geometry to which a window will be maximized
|
|
|
|
MaximizeArea,
|
|
|
|
///< like MaximizeArea, but ignore struts - used e.g. for topmenu
|
|
|
|
MaximizeFullArea,
|
|
|
|
///< area for fullscreen windows
|
|
|
|
FullScreenArea,
|
|
|
|
///< whole workarea (all screens together)
|
|
|
|
WorkArea,
|
|
|
|
///< whole area (all screens together), ignore struts
|
|
|
|
FullArea,
|
|
|
|
///< one whole screen, ignore struts
|
|
|
|
ScreenArea
|
|
|
|
};
|
|
|
|
explicit JSEngineGlobalMethodsWrapper(DeclarativeScript *parent);
|
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
|
|
|
~JSEngineGlobalMethodsWrapper() override;
|
2013-08-12 11:09:46 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
QVariant readConfig(const QString &key, QVariant defaultValue = QVariant());
|
2013-11-07 13:10:35 +00:00
|
|
|
void registerWindow(QQuickWindow *window);
|
2016-10-30 00:00:22 +00:00
|
|
|
bool registerShortcut(const QString &name, const QString &text, const QKeySequence& keys, QJSValue function);
|
2013-08-12 11:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DeclarativeScript *m_script;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
/**
|
2019-02-02 18:17:44 +00:00
|
|
|
* The heart of KWin::Scripting. Infinite power lies beyond
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-08-02 07:12:57 +00:00
|
|
|
class KWIN_EXPORT Scripting : public QObject
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2011-12-23 10:52:06 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
|
2011-01-30 14:34:42 +00:00
|
|
|
private:
|
2013-04-04 07:11:17 +00:00
|
|
|
explicit Scripting(QObject *parent);
|
2011-01-30 14:34:42 +00:00
|
|
|
QStringList scriptList;
|
2012-02-19 14:43:24 +00:00
|
|
|
QList<KWin::AbstractScript*> scripts;
|
2012-04-28 07:55:11 +00:00
|
|
|
/**
|
|
|
|
* Lock to protect the scripts member variable.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-04-28 07:55:11 +00:00
|
|
|
QScopedPointer<QMutex> m_scriptsLock;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
// Preferably call ONLY at load time
|
|
|
|
void runScripts();
|
|
|
|
|
|
|
|
public:
|
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
|
|
|
~Scripting() override;
|
2012-02-25 10:30:45 +00:00
|
|
|
Q_SCRIPTABLE Q_INVOKABLE int loadScript(const QString &filePath, const QString &pluginName = QString());
|
|
|
|
Q_SCRIPTABLE Q_INVOKABLE int loadDeclarativeScript(const QString &filePath, const QString &pluginName = QString());
|
2012-03-01 10:29:24 +00:00
|
|
|
Q_SCRIPTABLE Q_INVOKABLE bool isScriptLoaded(const QString &pluginName) const;
|
|
|
|
Q_SCRIPTABLE Q_INVOKABLE bool unloadScript(const QString &pluginName);
|
2011-12-23 10:52:06 +00:00
|
|
|
|
2012-08-31 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Invokes all registered callbacks to add actions to the UserActionsMenu.
|
|
|
|
*
|
|
|
|
* @param c The Client for which the UserActionsMenu is about to be shown
|
|
|
|
* @param parent The parent menu to which to add created child menus and items
|
|
|
|
* @return QList< QAction* > List of all actions aggregated from all scripts.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-03-06 09:49:37 +00:00
|
|
|
QList<QAction*> actionsForUserActionMenu(AbstractClient *c, QMenu *parent);
|
2012-08-31 11:28:31 +00:00
|
|
|
|
2014-03-03 12:23:55 +00:00
|
|
|
QQmlEngine *qmlEngine() const;
|
|
|
|
QQmlEngine *qmlEngine();
|
2016-11-02 21:56:56 +00:00
|
|
|
QQmlContext *declarativeScriptSharedContext() const;
|
|
|
|
QQmlContext *declarativeScriptSharedContext();
|
|
|
|
QtScriptWorkspaceWrapper *workspaceWrapper() const;
|
2014-03-03 12:23:55 +00:00
|
|
|
|
2016-08-19 07:12:49 +00:00
|
|
|
AbstractScript *findScript(const QString &pluginName) const;
|
|
|
|
|
2013-04-04 07:11:17 +00:00
|
|
|
static Scripting *self();
|
|
|
|
static Scripting *create(QObject *parent);
|
|
|
|
|
2011-12-23 10:52:06 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
void scriptDestroyed(QObject *object);
|
2012-05-06 17:20:38 +00:00
|
|
|
Q_SCRIPTABLE void start();
|
2012-04-28 07:55:11 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void slotScriptsQueried();
|
|
|
|
|
|
|
|
private:
|
2014-03-03 12:23:55 +00:00
|
|
|
void init();
|
2012-09-14 14:08:45 +00:00
|
|
|
LoadScriptList queryScriptsToLoad();
|
2013-04-04 07:11:17 +00:00
|
|
|
static Scripting *s_self;
|
2014-03-03 12:23:55 +00:00
|
|
|
QQmlEngine *m_qmlEngine;
|
2016-11-02 21:56:56 +00:00
|
|
|
QQmlContext *m_declarativeScriptSharedContext;
|
|
|
|
QtScriptWorkspaceWrapper *m_workspaceWrapper;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2014-03-03 12:23:55 +00:00
|
|
|
inline
|
|
|
|
QQmlEngine *Scripting::qmlEngine() const
|
|
|
|
{
|
|
|
|
return m_qmlEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
QQmlEngine *Scripting::qmlEngine()
|
|
|
|
{
|
|
|
|
return m_qmlEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2016-11-02 21:56:56 +00:00
|
|
|
QQmlContext *Scripting::declarativeScriptSharedContext() const
|
|
|
|
{
|
|
|
|
return m_declarativeScriptSharedContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
QQmlContext *Scripting::declarativeScriptSharedContext()
|
|
|
|
{
|
|
|
|
return m_declarativeScriptSharedContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
QtScriptWorkspaceWrapper *Scripting::workspaceWrapper() const
|
2014-03-03 12:23:55 +00:00
|
|
|
{
|
|
|
|
return m_workspaceWrapper;
|
|
|
|
}
|
|
|
|
|
2013-04-04 07:11:17 +00:00
|
|
|
inline
|
|
|
|
Scripting *Scripting::self()
|
|
|
|
{
|
|
|
|
return s_self;
|
|
|
|
}
|
|
|
|
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
|
|
|
#endif
|