Expose Cursor position to DeclarativeScripting
AbandonedPublic

Authored by davidedmundson on Aug 15 2017, 11:27 AM.

Details

Reviewers
graesslin
Group Reviewers
Plasma
Summary

This allows us to write scripts like mousemark, trackmouse, etc. as
declarative scripts.

It's exposed as a new object rather than just making the existing Cursor
a context property so that we can do RAII on enabling mouse polling.

Test Plan

Attached unit test
Also used in a real world script that moves a window around the cursor position

Diff Detail

Repository
R108 KWin
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Restricted Application added a project: KWin. · View Herald TranscriptAug 15 2017, 11:27 AM
Restricted Application added subscribers: KWin, kwin, plasma-devel. · View Herald Transcript
anthonyfieroni added inline comments.
scripting/cursorwrapper.cpp
29–30

https://phabricator.kde.org/source/kwin/browse/master/cursor.cpp;f50fbde1a9edae2eb9dd2947e457687dc94b41a7$207
startCursorTracking is written as recursive counter i.e. if external script enable mouse tracking - signal still emits. I'm not sure this is desired effect.

davidedmundson added a comment.EditedAug 15 2017, 2:53 PM

In retrospect, I don't even want cursor tracking - I was thinking of mousePolling, but that no-ops here anyway.

In retrospect, I don't even want cursor tracking - I was thinking of mousePolling, but that no-ops here anyway.

KWin doesn't do mousePolling anymore in "normal" situations. On X11 with XInput2 and on Wayland in general. So nothing to worry about.

graesslin requested changes to this revision.Aug 15 2017, 4:56 PM

I'm very concerned about this from a security perspective. This would allow to globally get notifications about the cursor positions and thus destroy one of the design goals of Wayland. I'm not against it in general, but I think we need to come up with a good solution to address the security implication.

Why do you want to do things like MouseMark, Trackmouse with a declarative KWin script? This would be very bad from performance consideration. If you want to do these effects in a scripted approach we need to extend the scripting API.

autotests/integration/scripting/scripts/cursortest.qml
9

?

This revision now requires changes to proceed.Aug 15 2017, 4:56 PM

Just some more thinking: if the aim is better trackmouse or mousemark extending scripts or effects is the wrong approach. Ideally one would want to use the DRM cursor layer for this. The big disadvantage of trackmouse currently is that it causes repaints in the compositor. Doing it through QtQuick would make this worse (these are the performance implications mentioned in the previous comment). We would have the rendering of QtQuick which is not synced in any way to the rendering of the compositor. Plus the overhead of getting QtQuick into the compositor scene.

But also effects are not well suited for it in a Wayland world as it just doesn't make use of what we have now: drm layers. By using drm layers we would get the rendering for free without affecting the compositor performance at all. The compositor could even stay idle and not be woken up at all. This was btw. how I envisioned something like the mouse cursor enlargement which @broulik talked about would work. We just render larger in the drm platform plugin.

2¢ - you don't have to expose the cursor position for those effects, just a signal that the cursor position changed and the ability to "do some" at the "current" cursor position (which is then resolved by the core)

2¢ - you don't have to expose the cursor position for those effects, just a signal that the cursor position changed and the ability to "do some" at the "current" cursor position (which is then resolved by the core)

that would be an elegant solution to my security concerns.

Security in scripts/effects is an existing problem, Scripts already can do literally anything, from manipulating workspace windows to low level DBus calls...as kwin. It needs solving regardless at a much higher level than restricting what API is available.

I could write my thing as C++, but I was very much under the impression you wanted to move scripts away from that?

If you want to do these effects in a scripted approach we need to extend the scripting API.

That's what I am doing...unless scripting API and the declarative scripting API are conceptually different?

Something something planes

This is something I want to to do too. But declarative and using planes aren't in any way exclusive. A DRM buffer still needs content from somewhere.

For the thing I was doing (some obscure accessibility thing for someone) the cursor plane wouldn't really work. Nor for mousemark, where the content remains static.

Given how many effects are simply overlays - having platforms provide a plane for all overlays (with some compositior fallback) is something that IMHO would make sense, that I would happily work on. I don't think throwing it into the DRM backend itself is a system that will scale.

Security in scripts/effects is an existing problem, Scripts already can do literally anything, from manipulating workspace windows to low level DBus calls...as kwin. It needs solving regardless at a much higher level than restricting what API is available.

Only partially. E.g. Wayland windows are not exposed to scripting for security concerns. So scripting currently only allows X11 which does not reduce the overall security.

Yes it needs a better solution, but a few years ago I decided to not expose anything Wayland related till we have a solution in place.

I could write my thing as C++, but I was very much under the impression you wanted to move scripts away from that?

If you want to do these effects in a scripted approach we need to extend the scripting API.

That's what I am doing...unless scripting API and the declarative scripting API are conceptually different?

We have three APIs:

  • effects (QScript based)
  • kwin scripts (QScript based)
  • kwin declarative scripts

The latter two are the same thing with different languages, the first one is a different beast. Effects cannot use QML. Code wise the effect scripts live in effects/ subdir, the two scripted in scripts/ subdir.

Something something planes

This is something I want to to do too. But declarative and using planes aren't in any way exclusive. A DRM buffer still needs content from somewhere.

True, but we need to get the content. If it's done by QtQuick we don't get the content (c.f. in Aurorae we do an expensive to QImage copy, for normal QWindows (on Wayland) we use an FBO which we cannot share at all with the DRM buffer). If we have the data as QImage we can relatively easy get it into a DRM layer, even if we do it in OpenGL not using QtQuick we could get it into a layer (with some serious engeneering work). Just with QtQuick - well difficult.

For the thing I was doing (some obscure accessibility thing for someone) the cursor plane wouldn't really work. Nor for mousemark, where the content remains static.

Given how many effects are simply overlays - having platforms provide a plane for all overlays (with some compositior fallback) is something that IMHO would make sense, that I would happily work on. I don't think throwing it into the DRM backend itself is a system that will scale.

Nah, of course not everything in DRM platform plugin. An abstraction which would allow to move it to into the platform is what we need. E.g. like we can do software rendering of cursor or doing it in the platform. Or the invert of screen which can either be done by an effect or through the platform (except it's in core).

davidedmundson abandoned this revision.Aug 23 2017, 2:14 PM

I'm not particularly convinced by the arguments, but also don't care enough to argue.
Might try solving this a different way at a later date.