Commit Graph

51 Commits (dfec59c60e55ca2bb49295da0932560d424b8b49)

Author SHA1 Message Date
Martin Gräßlin c4b3d11261 Reparse configuration before (un)loading scripts
When the scripting KCM triggered a loading of a script it did not work
because the scripting code was operating on an old data set.

Reparsing the configuration before evaluating which scripts to (un)load
solves this problem.

Cherry-picked from 4.10 branch: dd5b4bdec8e24359d4715c078e2f442967a3f873

CCBUG: 319767
2013-05-13 08:26:39 +02:00
Martin Gräßlin 466bef3a6d Adding a DesktopThumbnailItem declarative item
Similar to WindowThumbnailItem for rendering a desktop thumbnail.
Uses the new paintDesktop hook.

FEATURE: 296067
FIXED-IN: 4.11.0
REVIEW: 104441
2013-04-24 11:45:47 +02:00
Martin Gräßlin 8037e6529c Rename ThumbnailItem to WindowThumbnailItem
This is for discrimination from the to be added DesktopThumbnailItem.
The name for QML is unchanged to keep the public API stable.
2013-04-24 11:43:22 +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 8fa3f8daa8 Model to provide easy access to KWin's Clients from QML
A new ClientModel is added which provides multiple different views on
KWin's Clients. The model is organized as a tree model supporting the
following levels:
* activities
* virtual desktops
* screens
* none

The levels can be ordered in whatever way one wants. That is the tree
structure can have an ordering of activities then virtual desktops or
the other way around.

In addition the model provides Exclusion flags  to exclude clients of
certain types. E.g. it's possible to exclude all windows which are not on
the current desktop or all windows which are of type dock.

The model gets automatically updated whenever a Client is added/removed
or changes a state in a way that it should be excluded/included.

The ClientModel is not directly exported to QML. Instead there are
specific sub classes for certain common orderings. This solutions is
chosen to workaround some limitations of QML. The initial idea was to
use a property taking a list of the levels, but this doesn't work because
we are not notified when the QDeclarativeListProperty changes.

Currently the following models are provided to QML:
* ClientModel -> no restrictions
* ClientModelByScreen -> ordering by screen
* ClientModelByScreenAndDesktop -> screen, then desktop

These can be used to get all Clients:
ClientModel {
}

Or to get the classic Present Windows on current desktop:
ClientModelByScreen {
    exclusions: ClientModel.OtherDesktopsExclusion | ClientModel.NotAcceptingFocusExclusion | ...
}

Or to get the classic Present Windows on all desktops:
ClientModelByScreen {
    exclusions: ClientModel.NotAcceptingFocusExclusion | ...
}

Or our well known desktop grid:
ClientModelByScreenAndDesktop {
    id: desktopGrid
    exclusions: ClientModel.NotAcceptingFocusExclusion | ...
}

To support filtering as known by the Present Windows effect one can use
a ClientFilterModel, which is a QSortFilterProxyModel filtering on
window caption, role and class:
ClientFilterModel {
    id: filterModel
    clientModel: desktopGrid
    filter: filterItem.text
}

In case it's a tree level obviously QML does not support this correctly.
So we need to use a VisualDataModel:
VisualDataModel {
    id: clientModel
    model: filterModel
    Component.onCompleted: {
        clientModel.rootIndex = modelIndex(0);
        clientModel.rootIndex = modelIndex(0);
        clientModel.delegate = thumbnailDelegate;
    }
}

As we can see, the rootIndex has to be set to the level which contains
the Clients. Also it seems to be important to create the delegate after
the model index has been set. The idea is to have only one ClientModel
and multiple VisualDataModels if multiple views on the data is needed.

The model has been tested with a painful modeltest session. It looks good
so far modulo the listed limitations and that modeltest is not liking
closing Yakuake in the ClientModelByScreenAndDesktop setup, though it
works fine in real world testing.

REVIEW: 109604
2013-04-08 10:30:45 +02:00
Martin Gräßlin 0ccc060218 Include KGlobal were needed
With KF5 some includes which used to include KGlobal, e.g. KStandardDirs
do no longer include KGlobal. So if we use KGlobal we should include it.
2013-03-07 13:59:15 +01: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 3389d68c50 Print useful information for a Client in scripting
Reusing the debug information already specified for QDebug.

FEATURE: 314402
FIXED-IN: 4.11
REVIEW: 108959
2013-02-18 09:16:31 +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 debb71285f Support arrays in callDBus method of KWin Scripting
Thanks to Jan Palus for providing the patch.

BUG: 311896
FIXED-IN: 4.10
2013-01-17 09:30:09 +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 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 895af61e47 Add missing Q_UNUSED
SVN_SILENT
2012-05-10 21:03:35 +02:00
Martin Gräßlin f3443a6b07 Add CMake variable to rename kwin binaries
A CMake variable is used to specify the name of the binary.
By default this is "kwin" but building for PA changes the
name to "kwinactive". The variable adjusts all names, e.g.
kwinnvidiahack becomes kwinactivenvidiahack.

The remaining usage of kwinrc in core and libs is replaced
by a cmakedefine for the configuration name and all data
installations are moved to the defined name. Dynamic loading
for scripts & co is adjusted for loading based on defined name.

This change allows the side-by-side installation of both kwin
for desktop and kwin for Plasma Desktop without the known
issues like conflicts in config files or missing build options
if kwin desktop is used for Plasma Active.

Likewise the KCMs are not adjusted as they are not intended to
be used for kwinactive.

REVIEW: 104299
BUG: 296084
FIXED-IN: 4.9.0
CCMAIL: active@kde.org
2012-05-10 10:25:15 +02:00
Martin Gräßlin 1f97345e35 Asserts for KWin scripts
Further debugging functionality for KWin scripts. Added assert
methods validate the to be tested parameter and throw a script
error if the value is not valid.

Following methods are available:
* assert(value)
* assertTrue(boolean)
* assertFalse(boolean)
* assertEquals(expected, actual)
* assertNull(nullValue)
* assertNotNull(notNullValue)

All methods take an additional optional parameter which is used
as the error message if provided.

Methods to validate the number of arguments and types of the
parameters are added and throw syntax or type errors.

REVIEW: 104870
2012-05-10 10:00:54 +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
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 be55ac5c60 Introduce post Workspace init phase
Workspace emits a signal when the initialization finished and
interested parties can connect to this signal to perform post
init actions. That is everything that does not have to be
performed to have a completely working Window Manager.

As an example loading the scripts is moved into this post init
phase.

REVIEW: 104580
2012-04-27 19:02:21 +02:00
Martin Gräßlin 7073b0af40 Export workspace as global property on ScriptEngine in QML bindings
If workspace is exported as a context property there seem to be
issues with the signals which are not bound to a property of
WorkspaceWrapper.

This problems seems to be fixable by exporting the workspace
property as a global property on the script engine.

As a side-effect this also resolves the issue with the clientList,
so we can drop the hack again.

REVIEW: 104682
2012-04-21 15:34:37 +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 dab146422a Make KWin::Client known to QML 2012-03-24 10:49:21 +01: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 3f1ef8bb8d Export KWin::Options to KWin scripts 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 651a0cca47 Export clientArea methods to scripting
For this a new MetaObject "KWin" is exported to have the
enum ClientAreaOption available in scripts. Unfortunately this
requires duplicating the enum from kwinglobals.h.
2012-01-26 22:56:24 +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 03e892fcc9 Workspace Wrapper uses Q_PROPERTIES
The idea is to extend the wrapper to have it wrapping even more
functions provided by Workspace. Of course it would be possible to
just add the properties to Workspace itself and export this. But I
think complete Workspace is just too powerful to fully expose to
scripts. So a small wrapper around the parts which are usefull for
scripts might make more sense.

This breaks now also the API for Workspace and again it is already
more powerful with less code than before.
2012-01-21 17:48:07 +01:00
Martin Gräßlin 49b24e4940 Clean-up Scripting Wrapper for Workspace
No need to manually convert everything to script values.
2012-01-21 10:04:47 +01:00
Martin Gräßlin 698eb631cd ClientGroup becomes scriptable (again)
For this properties are defined in ClientGroup and several methods
are changed to be slots (to be invokable from scripts). On Client
the clientGroup is exported as a property.

The existing wrapper around ClientGroup is dropped as it is no
longer needed. Interestingly it was wrong anyway as it allowed to
construct a new ClientGroup, which has to be done internally.

At the same time the meta declarations get cleaned up a little bit.
2012-01-01 14:43:32 +01:00
Martin Gräßlin d00655fbcc Use single quoted char instead of double qouted
Fixes Krazy issu "Check single-char QString operations for efficiency".
SVN_SILENT
2012-01-01 09:19:46 +01:00
Martin Gräßlin 1953deab15 Drop "Chelate"
Whatever it was, we cannot need a "Lazy Logic (TM)" which is not
documented. And even if it were useful, KWin is not the right place
to develop language extensions to ECMAScript.
2011-12-31 14:22: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
Montel Laurent 62c5a5e276 normalize signal/slots 2011-08-17 23:51:55 +02: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