Commit Graph

102 Commits (90b53f416cf56aa8b78033f5aa0f524de735def8)

Author SHA1 Message Date
Vlad Zahorodnii 90b53f416c Use universal helper for writing toplevels to QDebug streams
Toplevel::debug() is one of annoyances that you need to deal with when
implementing a new client type. It can be tempting to just write "this"
to the stream, but it will result in a crash.

In order to make implementing new client types easier, this change
introduces a debug stream insertion operator overload that works for all
kinds of the Toplevel class.
2020-08-21 11:42:53 +00:00
Vlad Zahorodnii 4ce853e8e4 Prettify license headers 2020-08-07 19:57:56 +00:00
Vlad Zahorodnii 1fb9f6f13a Switch to SPDX license markers
The main advantage of SPDX license identifiers over the traditional
license headers is that it's more difficult to overlook inappropriate
licenses for kwin, for example GPL 3. We also don't have to copy a
lot of boilerplate text.

In order to create this change, I ran licensedigger -r -c from the
toplevel source directory.
2020-08-07 19:57:56 +00:00
Tiago Corrêa 45c6e4b811 scripting: Introduce ClientModelByScreenAndActivity
Summary: Provide for KWin scripts the possibility to work with a activities aware ClientModel. In the same way that the ClientModelByScreenAndDesktop works with virtual desktops.

Reviewers: #kwin, mart, zzag

Reviewed By: #kwin, zzag

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29284
2020-05-11 14:27:00 +03:00
Vlad Zahorodnii ffcbe24e2b Rename Client to X11Client
Summary:
Currently each managed X11 client is represented with an instance of
Client class, however the name of that class is very generic and the
only reason why it's called that way is because historically kwin
was created as an x11 window manager, so "Client" was a sensible choice.

With introduction of wayland support, things had changed and therefore
Client needs to be renamed to X11Client in order to better reflect what
that class stands for.

Renaming of Client to X11Client was agreed upon during the last KWin
sprint.

Test Plan: Compiles, the test suite is still green.

Reviewers: #kwin, romangg

Reviewed By: #kwin, romangg

Subscribers: romangg, davidedmundson, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D24184
2019-09-25 21:11:37 +03:00
Vlad Zahorodnii 5ad3c0ee13 Port away from deprecated qVariantFromValue
Summary:
qVariantFromValue is deprecated since Qt 5.14. It's advised to use
QVariant::fromValue instead.

Test Plan: Compiles.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D24042
2019-09-18 16:20:06 +03:00
David Edmundson 47be4be020 [scripting] Make DBus invokable run method return result after execution
Summary:
In 403038 the user expected the DBus call to run to finish before
processing the next request. For a singleshot script that makes a lot of
sense, otherwise you have no idea when it finishes.

This also allows us to return errors.

CCBUG: 403038

Test Plan:
NUM=$(qdbus org.kde.KWin /Scripting org.kde.kwin.Scripting.loadScript /noFile.js Minimize)
qdbus org.kde.KWin /$NUM org.kde.kwin.Scripting.run
  Error: org.kde.kwin.Scripting.FileError
  Could not open /noFile.js

Running a real script behaved effectively the same as before.

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18127
2019-02-22 14:40:15 +00:00
Martin Flöser cfecb1e077 Fix reorder warning in AbstractScript
Summary:
scripting/scripting.h:205:13: warning: ‘KWin::AbstractScript::m_pluginName’ will be initialized after [-Wreorder]
     QString m_pluginName;
             ^~~~~~~~~~~~
scripting/scripting.h:204:13: warning:   ‘QString KWin::AbstractScript::m_fileName’ [-Wreorder]
     QString m_fileName;
             ^~~~~~~~~~
scripting/scripting.cpp:230:1: warning:   when initialized here [-Wreorder]
 KWin::AbstractScript::AbstractScript(int id, QString scriptName, QString pluginName, QObject *parent)
 ^~~~

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18560
2019-01-27 13:25:40 +01:00
David Edmundson ba7aecfe53 [scripting] Avoid threading issues when loading from a file
Summary:
KWin::Script::loadScriptFromFile ran in it's own thread and accessed
member variables of KWin::Script without any guards.

Potentially script could be destroyed whilst the file is loading.

Rather than adding mutexes everywhere, this patch scopes the QFile
object to be local to the threaded function making it independent.

BUG: 403038

Test Plan: Ran a script from a file

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18126
2019-01-09 23:37:37 +00:00
David Edmundson d485dfe7ef Avoid crash with on scripted window teardown with threaded quick render loop
Summary:
Qt render loops behave quite differently to each other.

KWin scripting as a workaround for another situation cleans
(17553e5a1f) handles tracking of script
windows by deleting the underlying window handle on hide.

This currently happens before the window gets the hideEvent.

Arguably this is a quirk with Qt, but in the current state:

- QSGThreadedRenderLoop deletes the platform window and cleans up
- We then get the hide() event. This no-ops because there's no window.
   (else branch of     case WM_TryRelease in qsgthreadedrenderloop.cpp)
- We carry on rendering animations despite having no platform
- undefined behaviour

Normally this isn't a problem as typically destruction of the platform window
happens only when a window is being deleted, we're messing with Qt
internals here.

If we make sure the QHideEvent is processed by the render loop first,
things seem fine.

BUG: 397767

Test Plan:
Ran QSG_RENDER_LOOP=threaded
Read output with scenegraph logging rules on

Reviewers: #kwin, broulik

Reviewed By: broulik

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D15025
2018-09-13 10:19:12 +01:00
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
Andreas Hartmetz 90a33a4bc2 Fix two more const / non-const iterator mismatches.
I did some research with the result that such comparisons are indeed
not standardized to be legal before C++14. In C++14 they are.
These microoptimizations can thus be re-enabled when C++14 becomes
the required version.
2017-04-07 20:38:19 +02: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
Martin Gräßlin d1076fc5b9 Merge branch 'Plasma/5.8' 2016-11-03 08:51:49 +01:00
Martin Gräßlin be9ee989b1 [scripting] Fix export of WorkspaceWrapper in QtScript
The export of the WorkspaceWrapper was changed to be a subclass with all
the elements still being in the parent class. But the "workspace" was
exported with QScriptEngine::ExcludeSuperClassContents. Thus all usages
of workspace were broken and our tests started to fail on build.kde.org.

This change removes the ExcludeSuperClassContents which means that also
the QObject properties and slots are now exposed which was previously
not the case.

CCMAIL: github@chilon.net
2016-11-03 08:13:25 +01: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
Martin Gräßlin 13f142b1bf Merge branch 'Plasma/5.8' 2016-10-31 11:52:43 +01: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
David Edmundson 1ca9390253 Fix typo in method name
Summary:
It was consistently wrong so it worked before, but not having a typo is
better.

Test Plan: Compiles, grepped that it's not invokable/public

Reviewers: #plasma, graesslin

Reviewed By: #plasma, graesslin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D2266
2016-10-07 13:30:32 +01:00
David Edmundson b32cdc5653 Add method unregisterScreenEdge to scripting
Test Plan: Used in a script. Works.

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: graesslin, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D2261
2016-10-07 13:29:29 +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
Kevin Funk 8ea4f4dae7 Port to CMake AUTOMOC
Summary: Run convert-to-cmake-automoc.pl over all .cpp files

Differential Revision: https://phabricator.kde.org/D882
2016-02-01 21:05:36 +01:00
Martin Gräßlin 757523a324 Use kwinApp()->config() instead of KSharedConfig::openConfig()
That way all over kwin we can inject a custom config in the autotests.
2016-01-29 11:24:18 +01:00
Nick Shaforostoff 3a8d7d866a optimize string operations
-use qstringliteral only when necessary (i.e. not in concat or comparison)
-use qbytearray instead of qstring when dealing with latin1 input and output (glplatform)
-use qstringref to extract numbers from strings (glplatform)
-define qt_use_qstringbuilder to optimize all string concatenations
-anidata: use ctor init lists, add windowType member initialization

REVIEW: 125933
2015-11-05 14:14:06 +00:00
Martin Gräßlin bffbbce172 [scripting] Add dedicated logging category 2015-07-31 13:25:51 +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 51bb4cf2a1 [scripting] Register KWin::AbstractClient in declarative scripts 2015-05-12 11:32:05 +02:00
Martin Gräßlin 4eb9a98f1a [scripting] actionsForUserActionMenu operates on AbstractClient 2015-05-08 12:43:45 +02:00
Martin Gräßlin c00c67bf29 [scripting] Drop qmlRegisterType for QQuickWindow
Not needed as one can just do:
import QtQuick.Window;

This fixes a build problem with Qt 5.4.

BUG: 338277
2014-09-03 09:47:21 +02:00
Martin Gräßlin 645e1cf775 [scripting] Reparent the created QML object
According to the documentation the ownership of a QObject created by
QQmlComponent::create is transferred to the caller.

This fixes a crash on KWin tear down.

REVIEW: 118345
2014-05-30 15:47:24 +02:00
Martin Gräßlin c6da593dc9 Do not register dbus service org.kde.kwin.Scripting
Just use org.kde.KWin - there's object and interface to differentiate.

REVIEW: 118139
2014-05-15 10:55:29 +02:00
Aleix Pol c72e519d9c Remove KDE/ prefix in include directories
It's unneeded and deprecated since KF5.
2014-03-17 16:24:10 +01:00
Martin Gräßlin 869c087e21 [kwin] Use QQmlEngine from Scripting in TabBox
Instead of having it's own QQmlEngine TabBox just uses the newly
exposed engine from Scripting and creates a new context for it's
own usage.

REVIEW: 116565
2014-03-10 09:09:01 +01: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
Martin Gräßlin 95ab9d05aa [kwin] Remove dependency on KF5Declarative
It's a runtime dependency as PlasmaCore pulls it in automatically,
so we don't it as all the QML we currently ship uses PlasmaCore.
2014-02-26 08:30:52 +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
Marco Martin d21121e236 adapt to KDeclarative namespace
the classes in the KDeclarative framework now use the KDeclarative
namespace
2014-01-14 22:32:36 +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 139201a2e2 KGlobal::config() -> KSharedConfig::openConfig()
KWin Core says good bye to KGlobal. We will not miss the threading
issues.
2013-09-04 16:11:40 +02:00
Martin Gräßlin 57905c0cc2 And we got rid of KDebug
Usages of kBacktrace got dropped.
2013-09-02 13:14:39 +02:00
Anselmo L. S. Melo d97069590a Porting kwin scripting to Qt5/KF5: QStandardPaths
REVIEW: 111974
2013-08-13 17:55:25 -03:00
Martin Gräßlin 5007a19062 Add a ScreenEdgeItem to reserve a screen edge from QML
Usage:
ScreenEdgeItem {
    edge: ScreenEdgeItem.LeftEdge
    onActivated: doSomething()
}
2013-08-13 09:57:51 +02:00
Martin Gräßlin 96bde02b38 New QML Type DBusCall
The DBusCall is exported as a QObject to the QML environment. It is
intended as a declarative replacement for the callDBus method which used
to be exported on global scope in the QtQuick 1 world.

Example usage:
DBusCall {
    id: dbus
    service: "org.kde.KWin"
    path: "/KWin"
    method: "setCurrentDesktop"
    arguments: [1]
    Component.onCompleted: dbus.call()
}
2013-08-13 09:57:51 +02: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 69b109b5b9 Adjust the ThumbnailItems to QtQuick2
AbstractThumbnailItem inherits from QQuickPaintedItem using QPainter to
do the fallback painting of icons.

The scene is adjusted to get the information from QQuickItem instead of
QDeclarativeItem. Clipping got a little bit more complex as the clip
path does not exist any more. To get it right the ThumbnailItem needs to
specify the parent it wants to be clipped to with the clipTo property.
E.g.:
clipTo: listView

The scene uses this clipTo parent item to correctly calculate the clip
region. Also the ThumbnailItem needs to have clipping enabled.

Note: this commit currently breaks TabBox as the qml and view are not
yet adjusted. In scripting the export of the item is disabled, but any
qml script using a ThumbnailItem would obviously also fail.
2013-08-09 11:47:17 +02:00
Eike Hein 5435568f86 Fix build.
Not sure why kdeclarative gets its own subdir, nor why
there is no CMake module to to add it to the include dirs
on find_package, but this matches what plasma-framework
does at the moment.
2013-08-06 03:03:57 +02:00
Martin Gräßlin bbaefd2f68 Disable KDeclarative for the port 2013-07-24 09:58:42 +02:00
Martin Gräßlin 330d40f425 Fix no cast to/from ASCII intrduced issues
* "" needs to be wrapped in QStringLiteral
* QString::fromUtf8 needed for const char* and QByteArray
* QByteArray::constData() needed to get to the const char*
2013-07-24 09:58:33 +02:00
Oliver Henshaw 47acf4ee9a Merge remote-tracking branch 'origin/KDE/4.10' into master
Conflicts:
	kwin/scripting/scripting.cpp
	powerdevil/daemon/actions/bundled/powerdevildimdisplayaction.desktop
	solid-actions-kcm/device-actions/solid-device-SerialInterface.desktop
2013-05-28 17:36:53 +01:00
Oliver Henshaw bf044bf509 Drop unneeded duplicate addImportPath
Let KDeclarative::setupBindings() add the import paths: it too takes
paths from KGlobal::dirs()->findDirs("module", "imports"); it adds paths
in the correct (reverse) order [1].

[1] See kdelibs 400b9f2e9d10386bb175b6123fe0cdaafeaffe61 for further
details.

REVIEW: 110670
2013-05-28 17:21:48 +01:00