Commit Graph

47 Commits (99804e0233cbb1054b1b1f5148dc5c7a6833a709)

Author SHA1 Message Date
David Edmundson a3cff85e7a Remove Qt module declarations in includes
Summary:
Test Plan: Compiles

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D13359
2018-06-05 18:07:23 +01:00
Martin Gräßlin 2be1625822 Add support for new touch screen callbacks to KWin scripts and scripted effects
Summary:
Exposes two new global JS functions to register and unregister touch
screen edges.

Test Plan: Added test case

Reviewers: #kwin, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D5277
2017-04-07 16:18:09 +02:00
James Pike 4730be084c Support for workspace.clientList() in declarative script
Summary:
The version provided is only compatible with QtScript so it became
necessary to split WorkspaceWrapper into a base class and two child
classes, one for QtScript and one for QmlScript.

BUG: 340125
FIXED-IN: 5.8.4
REVIEW: D3185
2016-11-02 23:31:06 +00:00
James Pike 0c4c529d68 Support for KWin.registerShortcut() in declarative script
Summary:
registerShortcut is available to javascript KWin scripts but was not
available to those written in declarative script.

BUG: 340225
FIXED-IN: 5.8.4
REVIEW: 129250
2016-10-30 01:15:02 +01:00
Martin Gräßlin c3dfacc3dc Improve introspection into Scripting for KWin core/testing
Summary:
This change introduces a Scripting::findScript method which returns
the AbstractScript. Thus a test can load a script, retrieve it and
trigger run on it. As the test would also need to know when finally
the test is running a signal is introduced to notify about it.

This makes the scripting ScreenEdgeTest way more reliable. The test
had been failing on both build.kde.org and build.neon.kde.org due to
not knowing when the script is loaded.

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D2497
2016-08-22 14:37:46 +02:00
Martin Gräßlin 17abac9db3 [autotest/integration] Add a test case for screenedge usage in Scripts
A new sub-directory scripting is added in autotests/integration to
gather all test cases related to scripting.

The first added test case verifies the activation of screen edges. For
that it loads a helper script, which reserves an edge based on config.
When the edge is triggered showing desktop is activated.
2016-08-02 09:12:57 +02:00
Martin Gräßlin b01b03aa84 [scripting] Find scripts through KPackage
Another sycoca usage gone.
2015-07-07 08:48:24 +02:00
Martin Gräßlin 4eb9a98f1a [scripting] actionsForUserActionMenu operates on AbstractClient 2015-05-08 12:43:45 +02:00
Martin Gräßlin adf485c261 [kwin] Share QQmlEngine between all declarative KWin Scripts
Instead of having each declarative script create it's own qml engine
there is one hold by the Scripting singleton. The engine's root context
gets populated in Scripting and each script just gets a new child
context. Thus also the WorkspaceWrapper instance is shared between the
declarative scripts.
2014-03-10 09:08:38 +01:00
Matteo De Carlo c01446583e Replace NULL with nullptr in scripting folder
Replacing all NULL to nullptr in all the files in scripting folder
(also substituting some "0" used as nullptr with nullptr)

REVIEW: 115915
2014-02-24 16:33:40 +01:00
Martin Gräßlin 17553e5a1f Work around problem of restored QQuickWindows not being visible
A declarative KWin script needs to register the QQuickWindows it is
using in the KWin object. This method ensures that the QQuickWindow
will destroy the platfrom window once it gets hidden. So the next
time the QQuickWindow is shown a new platform window is created.

As can be seen in the OSD this is not really nice, therefore a
KWin.Dialog should be created which takes care of these steps.
2013-11-07 14:10:35 +01:00
Martin Gräßlin abbe84bab4 Port declarative scripting to QtQuick
Getting all functionality from old solution into new one is not really
possible. Main problems are that QtScript provided more functionality
than the QJSEngine. For example it's no longer possible to just export
functions to the engine. We need to have a Qt wrapper object. At the
moment this wrapper object doesn't export all functions as the callbacks
are tricky. A solution might be to create specific QML types
encapsulating functionality which used to be exported on the functions.

Nevertheless a basic QML script loads and works and the ported readConfig
function works, too.
2013-08-13 09:57:51 +02:00
Martin Gräßlin 1d2c2d5982 Use Q_SLOTS and Q_SIGNALS instead of slots and signals
Fixes compilation with Qt5/KF5 setup.
2013-07-24 09:46:54 +02:00
Martin Gräßlin b88f7ad8ce Remove QDeclarativeView from DeclarativeScript
The view is never shown or used in any way except to create the
QDeclarativeEngine. So instead of using a view as a wrapper, let's create
a QDeclarativeEngine and a Component and create the script from the
Component.

To have Plasma.Dialog working we also need to add the created script item
to a QGraphicsScene.
2013-04-16 08:10:15 +02:00
Martin Gräßlin 6f113d84d3 Turn Scripting into a proper singleton
There is only one instance hold by Workspace which means it should follow
the common approach with ::self and ::create.

REVIEW: 109850
2013-04-11 14:01:39 +02:00
Martin Gräßlin 32b6ef42b9 Strip module path from all Qt #include <>
Done with:
fixqt4headers.pl --strip-modules

REVIEW: 109176
2013-03-06 10:26:56 +01:00
Martin Gräßlin 7a7f9d1a34 Change the way how screen edges interact with Effects/Scripts
The main difference is that the activation of an edge is no longer
broadcasted to all effects and scripts, but instead a passed in slot of
the Effect/Script is invoked.

For this the EffectsHandler API is changed to take the Effect as an
argument to (un)reserveElectricBorder. As callback slot the existing
borderActivated is used.

In addition the ScreenEdge monitors the object for beeing destroyed and
unregisters the the edge automatically. This removes the need from the
Effect to call unregister in the dtor.

BUG: 309695
FIXED-IN: 4.11
2013-02-07 09:46:52 +01:00
Martin Gräßlin 533d57da60 Mark most ctors as explicit as reported by Krazy2 checker 2013-01-02 18:35:46 +01:00
Thomas Lübking 24cf0e75f3 Merge branch 'KDE/4.9'
Conflicts:
	kwin/scene.cpp
	plasma/generic/applets/batterymonitor/metadata.desktop
	plasma/generic/applets/lock_logout/metadata.desktop
2012-09-19 20:21:18 +02:00
Thomas Lübking cb265d96fc Sync script loading, KConfGroup is not thread safe
REVIEW: 106377
BUG: 305361
FIXED-IN: 4.9.2
2012-09-19 20:16:34 +02:00
Martin Gräßlin 2764565f9d Allow Scripts to add menus to the UserActionsMenu
A script can register a callback through registerUserActionsMenu to be
informed when the UserActionsMenu is about to be shown. This menu calls
the Scripting component to gather actions to add to a Scripts submenu.

The Scripting component now asks all scripts for the actions, which will
invoke the registered callbacks with the Client for which the menu is to
be shown as argument.

The callback is supposed to return a JSON structure describing how the
menu should look like. The returned object can either be a menu item or
a complete menu. If multiple menu items or menus are supposed to be added
by the script it should just register multiple callbacks.

The structure for an item looks like the following:
{
    text: "My caption",
    checkable: true,
    checked: false,
    triggered: function (action) {
       print("The triggered action as parameter");
    }
}

The structure for a complete menu looks quite similar:
{
    text: "My menu caption",
    items: [
         {...}, {...} // items as described above
    ]
}

The C++ part of the script parses the returned object and generates
either QAction or QMenu from it. All objects become children of the
scripts QMenu provided by the UserActionsMenu.

Before the menu is shown again the existing menu is deleted to ensure
that no outdated values from no longer existing scripts are around. This
means the scripts are queried each time the menu is shown.

FEATURE: 303756
FIXED-IN: 4.10
REVIEW: 106285
2012-09-07 07:32:00 +02:00
Thomas Lübking 498783c66b move KServiceTypeTrader::query() to main thread
KConfigGroup is not the least thread safe and unfortunately
the KServiceTypeTrader::self()->query() will in doubt create
one if the sycoca database was damaged.

BUG: 303713
REVIEW: 105608
(cherry picked from commit e3edcbcf66b324febcc2014ca4c1fbfa383d8972)
2012-07-21 19:59:36 +02:00
Thomas Lübking 6a934502b8 move KServiceTypeTrader::query() to main thread
KConfigGroup is not the least thread safe and unfortunately
the KServiceTypeTrader::self()->query() will in doubt create
one if the sycoca database was damaged.

BUG: 303713
REVIEW: 105608
2012-07-21 19:59:08 +02:00
Martin Gräßlin d2a9199cd9 Support for calling D-Bus methods from scripts
A new global method is exported to perform a remote method call
through D-Bus. The call is always performed async invoking a
callback once the call completed passing through the arguments
received from D-Bus.

Possible code looks like the following:
callDBus("org.kde.kwin", "/KWin", "org.kde.KWin", "currentDesktop", function (desktop) {
  print("Current Desktop through D-Bus: ", desktop);
});

REVIEW: 105396
2012-07-05 15:19:42 +02:00
Thomas Lübking 3b6d52549d don't use kconfiggroup in threaded script loading at all
BUG: 300934
FIXED-IN: 4.9
REVIEW: 105128
2012-06-02 09:33:25 +02:00
Martin Gräßlin 36932d3f2e Reload scripts after saving in scripts KCM
DBus call to start scripting again. This should adjust the
state of loaded scripts to the saved selection in the
KPluginSelector.

REVIEW: 104876
2012-05-17 21:28:10 +02:00
Martin Gräßlin c9c4e020e2 Screen Edge bindings for Scripts and Scripted Effects
ScreenEdge is changed to emit a signal whenever a screen edge
got activated without an action or effect taking care of it.

A Script can reserve one to many callbacks for an edge and the
callback get's triggered whenever the signal is emitted. On
deconstruction of the Script the edge is unreserved again.

FEATURE: 299275
FIXED-IN: 4.9.0
REVIEW: 104904
2012-05-15 17:54:31 +02:00
Martin Gräßlin c3fce865ee Unload script on end execution and error
A ScriptEngineAgent is added to monitor the execution of a
script. If it ends it stops the script to free resources.

The same is done in case of an exception, just that in this
case the script takes care of unloading itself.

REVIEW: 104871
2012-05-10 09:58:59 +02:00
Martin Gräßlin 54ecbc6b6a Ensure declarative view gets deleted when script is unloaded
Using a scoped pointer to ensure that the view is deleted in
the DeclarativeScript's dtor.

REVIEW: 104846
2012-05-06 12:57:10 +02:00
Thomas Lübking e274c297b9 fix threaded queryScriptsToLoad()
REVIEW: 104866
2012-05-06 12:24:32 +02:00
Martin Gräßlin abd3808574 Read KWin Script from file moved into thread
The I/O intensive reading of the complete KWin Script
file into a QByteArray is moved into a thread.

Evaluating and setting up the script engine is still
performed in the main thread.

REVIEW: 104782
2012-04-29 22:23:44 +02:00
Martin Gräßlin 6cbdfd3cd5 Move KServiceTypeTrader query for Scripts into a thread
Searching for the scripts to load is performed in an own
thread including unloading of already loaded scripts which
no longer should be loaded.

To ensure that two threads are not trying to load/unload
at the same time a mutex is added to protect the list of
loaded scripts.

REVIEW: 104768
2012-04-29 22:23:44 +02:00
Martin Gräßlin 42dfdb63b0 Global Shortcut support for KWin scripts and scripted Effects
A global method "registerShortcut" is exported to the scripts which
can be used to register a callback to be called when the global
shortcut is triggered.

The shared code between Scripts and Effects is moved into template
functions defined in a new file scriptingutils.h.

REVIEW: 104400
2012-03-30 08:20:10 +02:00
Martin Gräßlin 3600fe5ed8 Support loading/unloading of scripts on config change
Whenever the KWin configuration is changed, scripting has to unload
scripts no longer loaded and load the scripts which have been added.
For this new methods are introduced to check whether the script is
loaded.

REVIEW: 104037
2012-03-02 09:10:21 +01:00
Martin Gräßlin b7d95a1b09 Fix global script methods
The callee is an AbstractScript and we should make sure that
the script is not already deleted.
2012-03-02 09:10:11 +01:00
Martin Gräßlin 87fede97a1 Configuration support for KWin scripts
New global method readConfig is exported to QtScript and declarative scripts.
Config is read from a config group stored in kwinrc called "Script-<pluginname>".
For this the ctors of the AbstractScript and derived classes are changed to also
take the pluginname.
2012-03-02 09:10:10 +01:00
Martin Gräßlin 6a8b79f699 Support declarative KWin scripts
For this the Script class is slightly refactored to have a common
base for JavaScript and QML based scripts.

Why QML bindings? This allows to use QML for example for the
desktop change OSD or for fullscreen effects like Present Windows.
2012-03-02 09:10:10 +01:00
Martin Gräßlin f9ad0621d5 Drop script dir variable
Not needed any more.
2012-03-02 09:10:10 +01:00
Martin Gräßlin db04ab7f36 KWin scripts use Plasma package structure
Scripts are found by the KServiceTypeTrader and can now be
enabled/disabled. Loading of config is currently disabled. Will
be made available again after scripted effects are merged.
2012-02-18 10:40:39 +01:00
Martin Gräßlin 20d8d727ca Rename SWrapper::Workspace to KWin::WorkspaceWrapper
Resolves the problem of having two workspace.(h|cpp). The scripting
workspace is in fact just a wrapper, so having that clear is a plus.
2012-01-22 12:38:03 +01:00
Martin Gräßlin 507ff411d6 Drop the WorkspaceProxy in Scripting
Unlike stated at several places in the code it is not difficult to
setup the connections to all Clients.

It would have been nice if the failed attempts to connect the Clients
would not have made it into the code as emitted signals which are
nowhere used. Not to mention that like in all places the signals to
inform that a state changed were emitted before the state changed was
performed.
2012-01-21 10:51:22 +01:00
Martin Gräßlin ab253cd178 Scripting meets D-Bus
Each KWin Script is also exported as a D-Bus object and can be
stopped (destroyed) and started through D-Bus. Output and errors
are emitted as D-Bus signals. That allows external applications
(e.g. Plasma desktop scripting console) to load a script and print
out the output.

The general interface is exported as /Scripting and allows to load
a new script by file. The script is not directly executed but only
loaded. To execute it the run method on the script object has to be
invoked.
2011-12-31 13:41:00 +01:00
Martin Gräßlin 0420ecd649 Scripting does not need to inherit ScriptEngine 2011-12-31 13:41:00 +01:00
Martin Gräßlin c56e70ca7c Make Script a proper class 2011-12-31 13:40:59 +01:00
Martin Gräßlin 0a7e48f7aa KWin uses kdelibs coding style. 2011-01-31 20:07:03 +01:00
Martin Gräßlin fd09961b8e Fix Krazy issues in scripting.
Let's start the new year with some good deeds and improve the code quality.
SVN_SILENT

svn path=/trunk/KDE/kdebase/workspace/; revision=1210594
2011-01-01 09:37:08 +00:00
Rohan Ramdas Prabhu 2aec750ebf Trembles the weave as the clock ticks, attain another microstate.
Every disorder causes every duration, which ensures the one that stays.
reality is relative. natural is disorder.
[R]obinhood[P]andey

Merging scripting from
^/branches/work/kwin_scripting TO
^/trunk

svn path=/trunk/KDE/kdebase/workspace/; revision=1177865
2010-09-21 14:31:40 +00:00