Commit graph

482 commits

Author SHA1 Message Date
Martin Gräßlin
89a4c2f0e1 Properly handle destroying a Pointer resource
Summary:
On client side the newer wl_pointer_release is used which is a
destructor call. On server side the shared destroy callback is used
and it's ensured that KWayland doesn't crash if called into the
PointerInterface between unbound and destroyed.

Test Plan:
Test case extended to cover the condition of an unbound
PointerInterface.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D2037
2016-06-28 18:58:41 +02:00
Martin Gräßlin
0b208fcd63 [autotests] Get Server::Cursor::pointer under coverage
Just verifying that it's returning the expected value.
2016-06-28 18:39:19 +02:00
Martin Gräßlin
594665c1df [server] Delete dead code: KeyboardInterface::Private::sendKeymap
Not called from anywhere.
2016-06-28 17:26:28 +02:00
Martin Gräßlin
782f036c0d Properly handle destroying a Keyboard resource
Summary:
On client side the newer wl_keyboard_release is used which is a
destructor call. On server side the shared destroy callback is used
and it's ensured that KWayland doesn't crash if called into the
KeyboardInterface between unbound and destroyed.

Test Plan:
Test case extended to cover the condition of an unbound
KeyboardInterface.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D2036
2016-06-28 17:14:36 +02:00
Martin Gräßlin
34df9d8b2e Properly handle release of a touch resource
Summary:
On client side use wl_touch_release to get into the proper destroy
handler on server side. There the shared destroy implementation is
used.

The test case is extended to verify the condition and ensure that
our code doesn't crash in case SeatInterface calls into the already
unbound TouchInterface.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D2035
2016-06-28 17:06:49 +02:00
Martin Gräßlin
f53bc666eb [autotests] Extend test case for SeatInterface::setSelection
Verifies the condition that the currentSelection is the same as the
DataDeviceInterface passed to setSelection.
2016-06-28 14:57:42 +02:00
Martin Gräßlin
1c16f881e2 [autotests] Bring SeatInterface::focusedTextInputSurface under coverage 2016-06-28 14:53:45 +02:00
Martin Gräßlin
59bfac50ba [server] Add support for setting the clipboard selection DataDeviceInterface manually
Summary:
So far SeatInterface handled automatically which DataDeviceInterface
holds the current clipboard selection. While this works fine and is
correct it doesn't support use cases like a clipboard manager where
the clipboard is hold by a different ClientConnection than the one
from the focused keyboard.

This change allows to manually set the selected DataDeviceInterface
to override the automatic selection, though the automatic selection
is still in place. Thus the next update of a selection will override
the manually set selection again.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1972
2016-06-28 10:48:30 +02:00
Martin Gräßlin
db602b8188 [server] Ensure that Resource::Private::get returns nullptr if passed a nullptr
Summary:
A Resource might be unbound, but not yet destroyed. In that case this
return a Resource instead of nullptr.

This change adds an explicit nullptr check.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1938
2016-06-27 08:21:10 +02:00
Martin Gräßlin
b612251015 [tests] Add a test application for PlasmaShellSurface
Summary:
Creates a PlasmaShellSurface and allows to set the different roles
through command line argument.

Needed to verify that KWin properly handles the notification type.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1932
2016-06-27 08:20:43 +02:00
Martin Gräßlin
52eeb16156 Add a notification role to PlasmaShellSurface
Summary:
Plasma needs to be able to mark windows as Notifications, so that KWin
can put them into the right layer.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1928
2016-06-27 08:20:01 +02:00
Martin Gräßlin
7844e38e79 [autotests] Add test for showing desktop in PlasmaWindowManagement 2016-06-25 21:04:48 +02:00
Martin Gräßlin
c9ec19d522 [autotest] Extend testing for the requests in PlasmaWindowInterface 2016-06-25 11:41:19 +02:00
Martin Gräßlin
3f69ab1bf0 [server] Add resource check in QtExtendedSurfaceInterface::close
Summary:
The QtExtendedSurfaceInterface might be unbound and thus the resource
might be null when calling into close. Thus we need to do a nullptr
check.

Hit a crash there.

Test Plan:
Unfortunately no test case as we don't have a client side
implementation for this.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1961
2016-06-20 16:27:13 +02:00
Martin Gräßlin
262b49d713 [server] Unset SurfaceInterface pointer in referenced objects when being destroyed
Summary:
This is a gotcha moment:
1. Create Surface with id 1
2. destroy that Surface
3. Create another Surface

Now if in step 3 the id is by pure chance getting reused and also 1, the
wl_resource pointer of the SurfaceInterface of step 1 and step 3 are
the same. This is rather unexpected and causes problems.

When creating a ShellSurface in step 1 and step 3 it would fail. KWayland
finds a ShellSurface which was already created for the Surface. The same
can happen with QtSurfaceExtensionInterface and PlasmaShellInterface which
also go into error state.

On client side this would trigger a protocol error and terminate the
application. An easy way to reproduce is opening the file open dialog
from within Kate multiple times.

This change addresses this problem by setting the surface pointer in
those classes to null when the parent Surface gets destroyed. Thus
creating a new ShellSurface won't find the old referenced Surface any
more.

For ShellSurface and PlasmaShellSurface a test case is added which hit
the condition without this change. For QtSurfaceExtension we don't have
the client side, so we cannot really simulate the condition.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1937
2016-06-20 10:30:08 +02:00
Martin Gräßlin
aa5cf3143a [server] Fix error message in QtSurfaceExtension Interface
If a SurfaceExtension is already created for a Surface we should say
that and not that a PlasmaShellSurface is already created.
2016-06-17 15:25:03 +02:00
Martin Gräßlin
2417faff4d [autotests] Extend TestDataDevice for unbound check in createDataOffer
Extends the test case for checking that the nullptr check is taken
when trying to send a selection on an already unbound DataDevice.
2016-06-15 09:33:10 +02:00
Martin Gräßlin
e2d46c574c [server] Introduce a Resource::unbound signal emitted from unbind handler
Summary:
So far for internal cleanup we mostly listen to QObject::destroyed.
When a Resource gets unbind the wl_resource is set to null and the
Resource gets deleteLater. This creates a short time frame when the
Resource is still there, but the wl_resource is null. For most internal
usages the Resource is completely useless at that point and should no
longer be considered. So far it was still considered and could hit
crashers, if a code path did not nullptr check. Unfortunately
libwayland-server is not nullptr safe: if called with a null value it
tends to crash.

So this check introduces a new signal unbound which can be listend to
in addition to the destroyed signal. It's used in SeatInterface for
DataDeviceInterface, where we experienced a crash related to that.

A test case is added which exposes the crash, but it already needs
the unbound signal to get into the crashy condition. The actual crash
is fixed twice - with the help of the unbound signal, but also by
introducing the nullptr check where it's needed.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1868
2016-06-15 09:05:13 +02:00
Martin Gräßlin
07e0f92d80 [autotests] Fix build with older compiler
We cannot create a QSignalSpy on a QPointer.
2016-06-14 11:22:58 +02:00
Martin Gräßlin
9a44631c24 [server] Don't assert when destroying a still referenced BufferInterface
Summary:
The fact that the buffer is still referenced - that is used - when the
BufferInterface gets destroyed is an error, but it is not fatal.

Unfortunately KWin/Wayland is still hitting this assert from time to
time and the assert is not helping to find the cause as a backtrace
does not show where a reference is still hold.

This change removes the hard assert by a soft warning. The advantage
of the warning is that the compositor is not killed and that we can
observe the reason and find a usage pattern which triggers the condition.

With that we will hopefully be able to find the case where the buffer
is still referenced when being destroyed and fix that.

Reviewers: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D1783
2016-06-14 07:44:09 +02:00
Martin Gräßlin
acb0e85bb6 Add destructor request to org_kde_kwin_shadow and org_kde_kwin_shadow_manager
Summary:
This improves the cleanup of a shadow from client side. The server now
notices when the client destroyed the shadow.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Differential Revision: https://phabricator.kde.org/D1789
2016-06-14 07:37:11 +02:00
Martin Gräßlin
37f5256688 [autotests] Extend test for OutputInterface
Just adds more test conditions to the already existing test.
2016-06-13 19:19:06 +02:00
Martin Gräßlin
c11b1f1217 [autotest] Improve test for ShellSurface
Just verifying a few more conditions.
2016-06-13 16:49:31 +02:00
Martin Gräßlin
268f2ef6ff [autotests] Add test for error case of two PlasmaShellSurfaces for same Surface
Tricky to test as our client implementation is too smart to go into it.
Thus the Surface needs to be created with normal Wayland functionality.
2016-06-13 16:26:27 +02:00
Martin Gräßlin
57148c4bae [autotests] Extend test for PlasmaShellSurface::setRole
If the role is set to the same as before it should not emit the changed
signal.
2016-06-13 16:01:54 +02:00
Martin Gräßlin
65b7fd68d2 [autotests] Try to fix the flaky TestWayalndSurface::disconnect
Sometimes the test is failing due to a wait on the signalspy not
working and then the cleanup triggers a heap-use-after-free.

This change tries to address the problem by using a QTRY_COMPARE
instead of a wait on signalspy.
2016-06-13 14:55:36 +02:00
Martin Gräßlin
33c8634c00 [autotests] Add test for PlasmaShellSurface::setPanelBehavior
Also adds the metatypes on client and server side.
2016-06-13 14:01:49 +02:00
Martin Gräßlin
8e28a6c1c2 [autotest] Extend test for PlasmaShellSurface on server side
Verifies that the shell is returned correctly and the static getter
for wl_resource works as expected.
2016-06-13 13:31:00 +02:00
Martin Gräßlin
ee5e92fe14 [autotests] Add test for PlasmaShellSurface::setSkipTaskbar
Test exposes that the changed signal gets emitted even if the value
did not change.
2016-06-13 11:32:05 +02:00
Martin Gräßlin
19f8ca8376 [autotests] Verfiy setting the position in PlasmaShellSurface 2016-06-10 16:44:29 +02:00
Martin Gräßlin
597e0104fc [autotests] Extend the TestPlasmaShell::testRole to test change to Normal
Test case changes back to Normal and verifies that this is correct in
both client and server.
2016-06-10 15:50:20 +02:00
Martin Gräßlin
41ac06747e [autotest] Verify the static getter on PlasmaShellSurface
Extends the test to verify that the PlasmaShellSurface::get returns
the PlasmaShellSurface for a given Surface.
2016-06-10 15:46:40 +02:00
Martin Gräßlin
c89ae2105e [autotests] Verify that PlasmaShell::createSurface returns from cache
If a PlasmaShellSurface got already created for a Surface, the
PlasmaShell::createSurface should return that one. This change justs
adds a check to an autotest to verify this condition.
2016-06-10 15:38:05 +02:00
Martin Gräßlin
2120d13632 Introduce an initial state event into Plasma Window protocol
Summary:
The event is sent to the client once all initial state is transmitted.
This means the client is able to see the PlasmaWindow completely created
and not in the intermediate state with further updates being pushed after
being created.

The client side API is adjusted to emit the windowCreated signal after
the initial state event is received. In addition if the window is already
unmapped, the signal will never be emitted which means the not valid
windows are not exposed to the client at all.

The tests are adjusted to reflect the new reality, which in most cases
just means removing the comment that this needs to be improved.

There is one kind of unrelated change included: when an empty icon is
set, the client side now creates a QIcon() instead of going through
QIcon::fromTheme. This wrong behavior was exposed now by the auto tests.

Reviewers: #plasma, hein

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1773
2016-06-06 13:07:35 +02:00
Martin Gräßlin
076e8ba253 [server] Trigger error if a transient request tries to parent to itself
Summary:
If the surface passed in the transient request is to the surface of the
shell surface, KWin aborts. It's an obvious invalid request, so handle
it properly by sending an error.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1755
2016-06-03 12:45:05 +02:00
Martin Gräßlin
b3ccc12b75 [client] Detect errors in ConnectionThread
Summary:
So far ConnectionThread dispatched events without checking for (protocol)
errors. But Wayland errors are considered fatal. We do need to consider
them.

This change introduces a way to detect errors and expose them in
ConnectionThread. Errors are handled gracefully, they are exposed, but
not considered application fatal. E.g. a new ConnectionThread could be
created afterwards.

This allows to add tests to verify error conditions.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1753
2016-06-03 11:27:04 +02:00
Martin Gräßlin
682652714d Introduce a test server
Summary:
The idea of shipping a test server is to have something like Xvfb for
Wayland. To be able to run a test application with a fake Wayland server.

To make this super easy the test server binary is installed into libexec
directory and provides a cmake function to run a test application with
the test server.

The test server takes full control over the process. It's a guiless
application and starts the passed test application once it is fully
set up. The environment is setup to have the test application connect
to the fake server (WAYLAND_SOCKET env variable and QT_QPA_PLATFORM).

When the started application finishes the test server goes down and
exits with the exit value of the test application. This allows a good
integration with ctest.

The test server is a virtual server which supports the following
interfaces:
* Shm
* Compositor
* Shell
* Seat
* DataDeviceManager
* Idle
* SubCompositor
* Output (1280x1024 at 60 Hz with 96 dpi)
* FakeInput

This is sufficient to bring up a QtWayland based application and
allows some basic interactions from a test application (e.g. fake
input).

So far the server fakes a repaint every 16 msec, but does not yet
pass events to the test applications.

To integrate this into an application for testing use:
    find_package(KF5Wayland CONFIG)
    add_executable(myTest myTest.cpp)
    target_link_libraries(myTest Qt5::Gui Qt5::Test)
    kwaylandtest(myTest)

When now running ctest in the build directory the test server gets
started and will start the myTest binary and report the passed/failed
in the expected and normal way.

This way a test case can easily be run against both X11 and Wayland.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1726

Changelog: Virtual framebuffer server for auto tests
2016-06-01 16:15:08 +02:00
Martin Gräßlin
151a910f4c [server] Properly handle the case that a PlasmaWindow is unmapped before client bound it
Summary:
So far we directly destroyed the resource on the server side. But this
causes a wayland error when the client tries to cleanup. This results in
the client being destroyed. A problem which brings down plasmashell
regularly when short living windows are shown. This happens e.g. in
Dolphin with the adress auto complete.

This change addresses the problem by creating a temporary
PlasmaWindowInterface for the already unmapped window. It doesn't get
added to the list of known windows and it's only purpose is to properly
handle the unmap and the destroy of the just created resource.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1734
2016-06-01 15:43:21 +02:00
Martin Gräßlin
92c379d474 [autotests] Make PlasmaWindowModel Test a little bit more stable
This change ensures that when the PlasmaWindow got created on client
side is also processed on the server side before we go into unmap.
2016-06-01 14:53:38 +02:00
Martin Gräßlin
0b19734dd0 [server] Don't destroy SlideInterface when parent SurfaceInterface is destroyed
Summary:
Destroying the SlideInterface on the server side before the client has a
chance to cleanup results in a protocol error:
wl_display@1: error 0: invalid object 7

Which would terminate the client. If we would not destroy the resource,
but only delete the SlideInterface it could result in heap-use-after-free.

So just don't do anything, the client needs to cleanup which will result
in the SlideInterface being deleted.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1714
2016-06-01 07:34:10 +02:00
Martin Gräßlin
555ef7f15a [server] Properly handle destructor in SlideInterface
Summary:
The destructor was not properly implement. Let's use the generic one
from Resource.

Test case is adjusted to verify that the SlideInterface gets cleaned up.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1713
2016-06-01 07:33:43 +02:00
Martin Gräßlin
1f48daea1e [server] Don't destroy ShadowInterface when SurfaceInterface gets destroyed
Summary:
Unlike the other cases this one is not as dangerous as the shadow
protocol doesn't have a destructor request (yet).

Once that is added the problem would be the same: destroying the
ShadowInterface when the parent SurfaceInterface gets destroyed would
result in a protocol error on client side.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1711
2016-06-01 07:33:12 +02:00
Martin Gräßlin
33e802913f [server] Don't destroy ServerSideDecorationInterface when parent SurfaceInterface is destroyed
Summary:
Destroying the ServerSideDecorationInterface on the server side before
the client has a chance to cleanup results in a protocol error:
wl_display@1: error 0: invalid object 7

Which would terminate the client. If we would not destroy the resource,
but only delete the ServerSideDecorationInterface it could result in
heap-use-after-free.

So just don't do anything, the client needs to cleanup which will result
in the ServerSideDecorationInterface being deleted.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1710
2016-06-01 07:32:38 +02:00
Martin Gräßlin
5232dc5f0f [server] Don't destroy ContrastInterface when parent SurfaceInterface is destroyed
Summary:
Destroying the ContrastInterface on the server side before the client has
a chance to cleanup results in a protocol error:
wl_display@1: error 0: invalid object 7

Which would terminate the client. If we would not destroy the resource,
but only delete the ContrastInterface it could result in
heap-use-after-free.

So just don't do anything, the client needs to cleanup which will result
in the ContrastInterface being deleted.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1709
2016-06-01 07:32:03 +02:00
Martin Gräßlin
3f1db0cfde [server] Don't destroy BlurInterface when parent SurfaceInterface is destroyed
Summary:
Destroying the BlurInterface on the server side before the client has a
chance to cleanup results in a protocol error:
wl_display@1: error 0: invalid object 7

Which would terminate the client. If we would not destroy the resource,
but only delete the BlurInterface it could result in heap-use-after-free.

So just don't do anything, the client needs to cleanup which will result
in the BlurInterface being deleted.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1708
2016-06-01 07:31:25 +02:00
Bhavisha Dhruve
08bc189f8d Add support for touch events in fakeinput protocol and interface.
Summary:
This adds support for following in fakeinput interface:

- touch_down
- touch_motion
- touch_up
- touch_cancel
- touch_frame

Test Plan: added autotests passes

Reviewers: #plasma, bshah, graesslin

Reviewed By: #plasma, bshah, graesslin

Subscribers: bshah, graesslin, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1672
2016-05-31 16:43:54 +05:30
Martin Gräßlin
aef650df51 [autotest] Prepare TestSlide for multiple test cases
Registry was not per test case, cleanup didn't clean up everything,
etc. Basically adding a second test case resulted in a crash.
2016-05-30 11:55:10 +02:00
Martin Gräßlin
b0b5e16667 [autotest] Prepare TestContrast for multiple test cases
Registry was not per test case, cleanup didn't clean up everything,
etc. Basically adding a second test case resulted in a crash.
2016-05-30 10:03:19 +02:00
Martin Gräßlin
08ef2642ba [autotest] Prepare TestBlur for multiple test cases
Registry was not per test case, cleanup didn't clean up everything,
etc. Basically adding a second test case resulted in a crash.
2016-05-30 09:49:38 +02:00
Martin Gräßlin
72f35fa7db [autotests] Try to stabialize TextInputTest::testEnterLeave
We saw it fail on build.kde.org a few times and it looks like a
entered spy gets triggered timing dependent (no surprise it's on
client side). So better check whether the entered spy got delivered
already and if not wait for the event.
2016-05-30 08:54:46 +02:00
Martin Gräßlin
ab98448fec [server] Standardize the destructor request handling for Resources
Summary:
This change standardizes the behavior regarding the destructor request.

The destructor should destroy the resource and nothing else. The
Wayland library invokes the static unbind method once the resource is
destroyed. The implementation provided by Resource::Private::unbind
triggers a delete later on the Resource. So there is no need to trigger
a deleteLater from the destructor request callback.

This change adds a generic implementation to Resource::Private which is
now used by all inheriting classes replacing the custom implementations.

Test Plan:
For a few Resources the test is extended to ensure that the Resource
gets deleted on server side.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1679
2016-05-30 08:16:07 +02:00
Martin Gräßlin
908f86f299 [server] Don't destroy resource from dtor of a Resource sub class
Summary:
Not needed as the dtor of the Resource ensures that the wl_resource
gets destroyed.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1680
2016-05-30 08:15:33 +02:00
Martin Gräßlin
a7d5013573 [autotest] Adjust Seat test for changes in 990e88ac
The text input change creates an additional serial, so the check
for last generated serial on the Display fails. The test is now
adjusted to the new semantics. A more reliable way would be to
verify the serial on the SeatInterface, though.
2016-05-25 15:32:59 +02:00
Martin Gräßlin
990e88ac1a Implement wl_text_input and zwp_text_input_v2 interfaces
Summary:
This change introduces support for text input. Text input allows to
compose text on the server (e.g. through a virtual keyboard) and sent
the composed text to the client.

There are multiple interfaces for text input. QtWayland 5.6 uses
wl_text_input, QtWayland 5.7 uses zwp_text_input_v2.

wl_text_input is from pre Wayland-Protocols times and considered as
UnstableV0 in this implementation. The other interface is UnstableV2.
Unfortunately the V2 variant is not yet part of Wayland-Protocols, but
used in Qt.

The implementation hides the different interfaces as good as possible.
The general idea is the same, the differences are rather minor.

This means changes to how interfaces are wrapped normally. On client
side in the Registry a manager is factored which represent either of
the two interfaces. Similar on the server side Display's factory method
takes an argument to decide which interface should be factored. This
way a user of the library can expose both interfaces and thus be
compatible with Qt 5.6 and Qt 5.7 onwards.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1631
2016-05-25 15:10:42 +02:00
Martin Gräßlin
1834dde31a [autotest] Further tries on hardening the TestWaylandOutputDevice
* add event queue to the registry
* in testId ensure that the signal spy catches the right signal
2016-05-25 14:03:02 +02:00
Martin Gräßlin
5e8bffbdfc [autotest] Harden TestWaylandOutputDevice against random failures
This change ensures that Registry has processed all events before
continueing with the further processing.
2016-05-25 13:42:26 +02:00
Martin Gräßlin
d1a09838e1 [server] Prevent double delete of callback resources in SurfaceInterface
Summary:
When destroying a SurfaceInterface all callbacks are getting destroyed.
This used to iterate over the callbacks and performing
wl_resource_destroy on them. This triggered the destroy handler which
removes the resource from the callback list. Which means removing from
the list we are iterating on. This could result in a double delete or
accessing invalid memory.

This change copies all callbacks to a temporary list and clears the
normal lists. So the destroy handler does no longer modify the lists
currently being iterated on.

Test Plan: Added a test case which crashed with previous code

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1677
2016-05-25 09:03:10 +02:00
Martin Gräßlin
46cf9fc36c [server] Add resource nullptr check to ShellSurfaceInterface
The ShellSurface might have the resource destroyed, before being deleted,
so there is a short time frame where resource might be null.

Crash was caught by KWin.

Reviewed-By: sebas and notmart
2016-05-23 14:20:54 +02:00
Martin Gräßlin
5f5dbc5155 [server] Compare ClientConnection instead of wl_client in SeatInterface
A downstream KWin test shows a possible heap-use-after-free if we
access the wl_client pointer. Basically we get the client disconnected
just before the focused surface gets unbind. Thus for a short moment
the ClientConnection pointer is gone. This needs to be extended with
a test case, but for the moment it should be good enough to get KWin
green again.
2016-05-23 10:43:45 +02:00
Martin Gräßlin
f4f2725132 [server] Improve the handling when clients disconnect
Summary:
So far the server component performed manual cleanup in some cases
when a client disconnects. But this is not needed: the Wayland library
calls the static unbind methods which do cleanup. If we cleanup ourselves
this can result in double deletes in the worst case, so let's only use
the Wayland functionality.

Adjusted:
* RegionInterface
* SurfaceInterface
* ShellSurfaceInterface (doesn't take a parent anymore)
* DpmsInterface
* QtSurfaceExtensionInterface
* KeyboardInterface
* PointerInterface
* TouchInterface
* DataOfferInterface
* PlasmaShellSurfaceInterface

For each adjusted case a test case is added to verify that the cleanup
works. Exceptions are DpmsInterface as the actual Resource is not exposed
at all in the Server component and DataOfferInterface as that is server
side created.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1640
2016-05-19 16:21:27 +02:00
Martin Gräßlin
81f3a7d2e5 [autotests] Longer wait in TestWaylandOutputDevice::testId
Looks like the wait of 200 msec failed on build.kde.org and thus
triggered a heap-use-after-free.
2016-05-18 08:30:44 +02:00
Martin Gräßlin
b70402bec7 [autotest] Further try to make TestWaylandOutputDevice more robust
Following the idea from f99492a616
to add more done signal spies instead of changed.
2016-05-18 08:18:53 +02:00
Martin Gräßlin
ffb91b031c [autotest] Try to make TestWaylandOutputDevice::testEnabled more stable
The test failed on build.kde.org. Let's try to make the part which failed
more robust.
2016-05-18 07:59:58 +02:00
Allen Winter
700d519476 server/plasmawindowmanagement_interface.cpp - fix -Wreorder warning 2016-05-17 16:24:44 -04:00
Martin Gräßlin
f99492a616 [autotest] Try to make TestWaylandOutputDevice a little bit more robust
From time to time the test is failing on build.kde.org with an ASAN
heap-use-after-free error. From my investigation this seems to be caused
by the OutputDevice being constructed on the stack and being destroyed
while handling Wayland events, but before all are handled.

The test mostly operates on the changed signal. There is also a done
signal emitted later on. Wayland sends the done after a set of changes
is transmitted. Thus the test is adjusted to wait for done instead of
changed. So we can ensure that all events are handled before the object
gets destroyed.

I have never been able to reproduce the problem locally, so I cannot
guarantee that the issue is solved for good. If it still happens more
investigation will be needed.
2016-05-17 13:36:56 +02:00
Martin Gräßlin
32eae0863c [client] Add context pointer to connects in PlasmaWindowModel
Summary:
When the model gets destroyed the lambda connections were still invoked
and could cause crashers.

Test Plan: Test case added and each one verified that it crashed

Reviewers: #plasma, hein

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1624
2016-05-17 12:47:14 +02:00
Martin Gräßlin
3fda8376b6 [client] Ensure PlasmaWindowModel removes deleted windows
Summary:
There is a possibility that a PlasmaWindow is unmapped when the
PlasmaWindowModel gets created. In this situation the unmapped
PlasmaWindow will be deleted in the next event cycle. So far
PlasmaWindowModel didn't handle this situation and the model might
hold deleted objects due to this.

This change addresses this potential problem and ensures the model
gets updated when a PlasmaWindow is deleted.

Test Plan: Test case which exposes the problem is added

Reviewers: #plasma, hein

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1622
2016-05-17 12:42:34 +02:00
Martin Gräßlin
2c5bc69d1d [client] Ensure PlasmaWindowManagement updates active window if it goes away
Summary:
So far when the active PlasmaWindow got unmapped or destroyed, the
PlasmaWindowManagement didn't update the activeWindow. This means it
could expose a deleted object through it's API which could result in
a crash.

This change addresses the problem by updating the active window when
a window gets unmapped or destroyed.

Test Plan: Tests added which exposed the problem

Reviewers: #plasma, hein

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1621
2016-05-17 09:02:10 +02:00
Martin Gräßlin
372955bf05 Improve the deconstruction of PlasmaWindows
Summary:
The protocol is extended by a dedicated destructor request. When a
PlasmaWindow is umapped we no longer destroy the resource directly,
but only send the unmap. The client is then supposed to clean up
(which it already did in that case) and will invoke the destructor.

The PlasmaWindowInterface object will be automatically deleted after
the unmap once all resources bound for it are destroyed.

The tests are extended by two new test cases which triggered protocol
errors on the client side prior to this change.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1594
2016-05-12 10:55:07 +02:00
Tobias C. Berner
f790973375 pid_t is defined in sys/types.h
Summary: To use pid_t one should include sys/types.h -- else the build fails on FreeBSD.

Reviewers: graesslin

Reviewed By: graesslin

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1579
2016-05-10 08:47:20 +02:00
Michael Pyne
3e6bc3621b Initialize Interface factory pointer to fix Coverity warning.
Coverity complains (in CID 1335150) about `Generator::parseInterface()`
since the default copy-ctor for `Interface` will end up copying
uninitialized memory (the unset `m_factory` member). Fixed by
initializing the m_factory.

REVIEW:127836
2016-05-04 21:14:07 -04:00
Allen Winter
c306d60d8f compiler warnings--
REVIEW: 127810
2016-05-02 09:53:12 -04:00
Martin Gräßlin
f2406ffec5 Version 5.7 becomes version 5.22
With KWayland becoming a framework the next version is going to be 5.22.
2016-04-27 07:43:43 +02:00
Eike Hein
ffdd37370b Add missing data role for closable state.
Summary:
Exposes closable state in the window model and adds tests. This was
included in the protocol and interface, but missing from the model.

Test Plan: Autotest extended.

Reviewers: graesslin

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1435
2016-04-21 19:46:54 +09:00
Eike Hein
9d3cea7092 Add a virtual_desktop_changable state to the window protocol.
Summary:
Analogous to NET::ActionChangeDesktop.

KWindowInfo::actionSupported(NET::ActionChangeDesktop) is hardcoded
to return true in kwin, but that's not how it should be; as this will
be fixed later the Wayland protocol needs this state bit as well for
parity.

Test Plan: PlasmaWindowModel test is extended.

Reviewers: graesslin

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1448
2016-04-20 01:16:35 +09:00
Eike Hein
90e80a548c Add states and request methods for move and resize.
Summary:
Adds states and request methods to determine whether a window can be put into
move or resize modes, and request move and resize modes, respectively.

request* naming pre-discussed with Martin. I chose to add *Mode to be more
explicit as well as avoid namespace conflicts with possible other Move/Resize
methods in the future.

Since these are not toggleable states, there is no requestToggle* methods.

Protocol version is not bumped (also pre-discussed with Martin) since we have
pending changes already bumping to 3.

Depends on D1417.

Test Plan: PlasmaWindowModel test extended.

Reviewers: graesslin

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1432
2016-04-19 20:50:28 +09:00
Eike Hein
f47e2f7b31 Switch to naming suggested by native speakers. 2016-04-19 18:40:57 +09:00
Eike Hein
dcc9c00ce5 Add API version info; fix references to protocol version. 2016-04-15 21:10:37 +09:00
Eike Hein
d812978f1c Add window shade support to protocol, interfaces and test.
Summary:
This adds support for 'shadable' and 'shaded' states to the protocol and
to the client and server classes, as well as the window model.

Test Plan: The PlasmaWindowModel test has been extended to test the new states.

Reviewers: graesslin

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1417
2016-04-15 20:39:14 +09:00
Martin Gräßlin
a41f18edfd [autotest] Add test for PlasmaWindowModel
Reviewers: #plasma, hein

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1409
2016-04-14 17:23:24 +02:00
Martin Gräßlin
67f5d375cc [autotest] Extend test to verify the code which handles buffer deletions
Summary:
Surface/SubSurface and Shadow handle the case that an attached buffer
gets destroyed by the client. So far we didn't have this code covered,
but it's rather important as incorrect reference counting can hit
asserts.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1403
2016-04-13 16:10:41 +02:00
Martin Gräßlin
c5a16a535d [autotest] Add a test case for QtSurfaceExtensionInterface
Summary:
KWayland does not have a client implementation of the QtSurfaceExtension
protocol. Thus the test is different: it starts a helper binary which
creates a QWindow. The test closes that one which should terminate the
started applications.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1388
2016-04-13 14:20:48 +02:00
Martin Gräßlin
9e3cd3bf7b [autotests] Add test case for FakeInputInterface
Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1400
2016-04-13 13:04:21 +02:00
Martin Gräßlin
9c10316991 [autotest] Add a test case for the shadow interface
Summary:
Basic functionality is covered. Changing of shadow elements not covered,
there seems to be lacking server API for that - no change signal.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1398
2016-04-13 09:59:23 +02:00
Martin Gräßlin
6e4391d01b [autotest] Add a test case for Idle interface
Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1389
2016-04-12 11:40:52 +02:00
Martin Gräßlin
194e359b9d [autotest] Extend tests for Dpms modes
Summary:
Now also tests:
* requesting mode from client side
* update supported change on server side

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1357
2016-04-08 11:43:35 +02:00
Martin Gräßlin
6fe14f73d2 [server] Pass keyboard focus to child surface on pointer click
If the focused pointer and keyboard surface is the same we use pointer
clicks as a hint to which child surface should have keyboard focus.

Keyboard focus handling for sub surfaces is rather limited overall.
We just don't have a good model on how to determine which child surface
should get the keyboard focus. When passing focus to a surface there
is no way to know which of the sub-surfaces should get the focus.
Ideally the client should handle this, but that's just not the case.

The best we have is a reference through the pointer. But that's of
course also limited. Keyboard focus passed to the surface for another
reason (Alt+Tab) cannot select the proper sub-surface without interaction
from another input device.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1330
2016-04-07 07:57:00 +02:00
Martin Gräßlin
2066d9bc17 [server] Split KeyboardInterface::Private into dedicated header 2016-04-06 11:36:03 +02:00
Martin Gräßlin
031abb9722 [server] Split PoointerInterface::Private into dedicated header 2016-04-06 11:27:42 +02:00
Martin Gräßlin
84a1d5eadc [server] Support sub-surfaces from PointerInterface
Summary:
The idea behind this change is to make the existance of sub-surfaces
an implementation detail for pointer events. The user of the library
does not need to care about on which sub-surface the pointer is on.
It only needs to care about the main surface and passes the focus to
the main surface.

Internally the PointerInterface takes care of sending the enter to
the sub-surface at the current pointer position. Also whenever the
pointer position changes, the PointerInterface evaluates whether it
triggered a change for the focused sub-surface and sends enter/leave
events accordingly. If the focused sub-surface does not change, it
sends motion events as normally, but of course under consideration
of the sub-surface position.

Overall this means that from pointer usage perspective a user of the
library doesn't need to care about the fact that there are sub-surfaces
at all. The library does the correct thing for it.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1329
2016-04-06 09:58:30 +02:00
Martin Gräßlin
37851e2e08 [server] Add a method SurfaceInterface::surfaceAt(const QPointF&) -> SurfaceInterface*
Summary:
The new method returns the (child) surface at a given surface position
taking care of stacking order, whether surfaces are mapped, etc.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1319
2016-04-05 14:29:21 +02:00
Martin Gräßlin
a2a888bc76 [server] Add damage tracking feature to SurfaceInterface
Summary:
This change introduces a damage tracking feature in SurfaceInterface.
So far the SurfaceInterface only exposes the damage compared to the
last attached buffer. But this is not always usefull for the user of
the library. E.g. if:
* server renders
* client damages buffer and commits
* client damages buffer and commits
* server wants render

In this situation the last damage information is not helpful to the
user of the library. It would need the combined damage information over
all attached buffers.

The new API combines the damage of the two commits in the example above.
The user of the library can then call resetTrackedDamage once it
processed the current damage (e.g. by updating the OpenGL texture).

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1281
2016-04-04 08:59:27 +02:00
Martin Gräßlin
d727d2e477 [server] Workaround for QtWayland bug https://bugreports.qt.io/browse/QTBUG-52192
Summary:
QtWayland doesn't map the parent sub-surfaces in a sub-surface tree.
According to the spec this would mean also the child sub-surface is not
mapped. But being strict according to the spec will make applications
like SystemSettings fail badly. Embedded child windows will not be
rendered and QtWayland is going to hard freeze. This is not acceptable,
thus we need to workaround this QtWayland bug till it's fixed.

It's worth mentioning that Weston as the reference compositor also
doesn't handle this situation according to spec and renders the
sub-surface. See https://bugs.freedesktop.org/show_bug.cgi?id=94735

The difficult part for the workaround is to determine whether a surface
should be considered unmapped. E.g. when the parent gets unmapped we need
to really unmap it. But what's the difference between an unmapped parent
surface which should be considered mapped and an unmapped parent surface
which should be considered unmapped?

The implementation goes with considering a new sub-surface always as
mapped - independently of whether it ever got a buffer attached. As soon
as it had a buffer attached and it gets unmapped again, it will go back
to a standard conform way.

The behavior now is not standard conform, thus the autotest is adjusted
to have QEXPECT_FAIL for the now no longer standard conform areas.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1250
2016-04-04 08:55:59 +02:00
Martin Gräßlin
7053e4fce6 [server] Don't emit unmapped if the Surface wasn't mapped
Summary:
If a Surface doesn't have a buffer attached and a null buffer gets
attached the buffer state doesn't really change. Thus neither the
unmapped signal nor the damaged signal should not be emitted.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1261
2016-04-04 08:55:17 +02:00
Martin Gräßlin
e616ade18e [autotest] Add test case for mapping/unmapping surfaces in a sub-surface tree
Summary:
New test case which verifies the behavior when a surface is considered
mapped or unmapped in a sub-surface tree.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1248
2016-04-04 08:54:31 +02:00
Hrvoje Senjan
cce8090787 Fix compilation with gcc 4.8
Reviewers: graesslin

Reviewed By: graesslin

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1237
2016-03-29 16:33:44 +02:00
Martin Gräßlin
d44b2ee30d [server] Add a convenient method to check whether a Surface is mapped
Summary:
In a SubSurface tree a Surface is only considered mapped if the Surface
has a buffer applied and the parent Surface is mapped.

The added method implements this check. It's useful for the compositor
to easily check this condition as it allows to easily figure out whether
a SubSurface needs to be rendered and it's also useful for implementing
the input handling as a not mapped sub-surface should not get any input
events.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1247
2016-03-29 12:08:10 +02:00
Martin Gräßlin
0551a39ab6 [server] Apply position change directly for desync sub-surfaces
Summary:
This is a workaround for https://bugreports.qt.io/browse/QTBUG-52118

It should take effect whenever the parent surface's state is applied,
but QtWayland never commits the parent surface. Thus the position is
always wrong.

Having a workaround for that in our server code is not good, but better
than completely broken applications such as Systemsettings.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1212
2016-03-24 16:11:48 +01:00
Martin Gräßlin
6d529abf8e [server] Remove sub-surface from parent when it's surface is destroyed
Summary:
From spec:
If the wl_surface associated with the wl_subsurface is destroyed,
the wl_subsurface object becomes inert. Note, that destroying either
object takes effect immediately.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1211
2016-03-24 16:05:00 +01:00
Martin Gräßlin
37f65cf186 [server] Add const variants to methods in SubSurfaceInterface
Summary: Fixes errors in API of methods which should be const not being const.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1214
2016-03-24 15:59:56 +01:00