Commit graph

64 commits

Author SHA1 Message Date
Vlad Zahorodnii
335d9c4192 xwayland: Generate Xauthority file
This allows running Xwayland apps as root. Xwayland started with an
empty Xauthority file. After kwin has received the display number, the
file is updated with an actual authority entry.

BUG: 432625
2021-02-09 00:14:31 +02:00
Vlad Zahorodnii
8137b8a3ab xwayland: Fix initialization of WM_S0 selection owner
The selection owner must live as long as the X11 connection is valid;
otherwise Xwayland won't catch the corresponding selection ownership
change event, and the initialization sequence will be incomplete.
2021-02-08 22:12:06 +00:00
David Edmundson
ed793dca21 Add option to enable XWayland debug 2021-02-01 09:14:17 +00:00
Aleix Pol
4150c1f047 xwl: No need to delete the source immediately
Prefer replacing then deleting the selection to the other way around.
This way less events need to be reported and the clipboard manager
doesn't get confused.
2020-10-29 15:56:13 +01:00
Aleix Pol
0549c14588 xwl: No need to create createX11Source twice consecutively 2020-10-29 15:56:13 +01:00
Aleix Pol
d335070b80 xwl: Do not refresh the x11 Clipboard while fetching
At the moment there was a race condition when putting something into the
keyboard from XWayland apps. The clipboard manager would announce a new
thing before we'd submitted it all resulting in a broken state.

This change detects when it's fetching and will only refresh the source
after everything has been sent.

BUG: 424754
CCBUG: 412350
2020-10-29 15:56:13 +01:00
Aleix Pol
439dcc4b1f xwl: Include errors and warnings 2020-10-29 15:56:13 +01:00
Laurent Montel
2ac8611523 If include is define in .h remove it if it's defined in .cpp too (scripted) 2020-10-23 21:37:16 +02:00
Aleix Pol
ba1737787a xwl: properly check type inheritance 2020-10-20 02:16:00 +02:00
Aleix Pol
c016f34dee xwl: prefer using local variable than fetching again 2020-10-20 02:14:18 +02:00
Aleix Pol
e81e950693 xwl: simplify logic of boolean function 2020-10-20 02:13:42 +02:00
Aleix Pol
6ec13c41a5 xwl: Remove unnecessary lambda 2020-10-20 02:11:33 +02:00
Vlad Zahorodnii
2093820aba xwayland: Avoid creating a tree query on crash
If Xwayland has crashed, the Workspace will block stacking order updates
and start destroying all X11 clients.

Once stacking order updates are unblocked, the Workspace will mark the X
stacking order as dirty and create a new Xcb::Tree object.

We don't want to create that Xcb::Tree object because accessing it
after the XCB connection has been shut down will lead to a crash.

BUG: 427688
FIXED-IN: 5.20.1
2020-10-14 16:17:42 +00:00
David Edmundson
56f159dded Adapt to DataSource changes 2020-10-01 14:51:05 +00:00
Vlad Zahorodnii
c0da7faa6f xwayland: Don't exit if failed to read DISPLAY
We want the compositor to survive even if something goes wrong when
starting Xwayland.
2020-09-09 15:25:59 +00:00
Vlad Zahorodnii
8697bcd7e9 xwayland: Avoid printing "FATAL ERROR" log messages
Since we want kwin to survive Xwayland crashes, printing "FATAL ERROR"
is highly undesirable.
2020-09-09 15:25:59 +00:00
Vlad Zahorodnii
b13a74c908 xwayland: Replace criticalError() signal with a less fatal signal
If the Xwayland executable can't be found, the whole session will die
because a criticalError() signal will be emitted.

This change replaces the criticalError() signal with a less severe
signal.

If the errorOccurred() signal has been emitted during the startup
sequence, kwin won't die and will just continue with spawning the
session process.
2020-09-09 15:25:59 +00:00
Vlad Zahorodnii
b8a16d4abf xwayland: Properly handle xcb_connect_to_fd() failures
xcb_connect_to_fd() will never return a NULL pointer, even if an error
has occurred.

Right after creating an xcb connection, xcb_connection_has_error() needs
to be called in order to determine if the connection has an error.
2020-09-02 12:49:44 +00:00
Vlad Zahorodnii
f894976e2e xwayland: Don't start Xwayland if it's already running
If the Xwayland server is being started or has already been started, do
nothing in the start() function. Normally, we would never encounter such
situation, but if we do, this check will be very useful in preventing
hitting undefined behavior in the compositor.
2020-09-01 09:39:00 +03:00
Vlad Zahorodnii
a6ff3001c8 xwayland: Send a notification when Xwayland crashes
Send a notification when Xwayland crashes to provide the user some
feedback regarding why all X11 clients have disappeared.
2020-09-01 06:16:02 +00:00
Vlad Zahorodnii
432cfb44c0 xwayland: Restart the Xwayland server after it has crashed
If the Xwayland process has crashed due to some bug, the user should
still be able to start applications in Xwayland mode. There is no reason
to restart the whole session just to be able to launch some application
that doesn't have native support for Wayland.
2020-09-01 06:16:02 +00:00
Adrien Faveraux
788c65d260 Fix Build Warning 2020-08-26 19:24:02 +02:00
Vlad Zahorodnii
f237f273da xwayland: Drop unused method
Xwayland::self() is not used anywhere.
2020-08-12 09:59:16 +03:00
Vlad Zahorodnii
e4f2c30f50 xwayland: Use KWIN_SINGLETON to make DataBridge a singleton
For consistency sake, use the KWIN_SINGLETON macro in order to make the
DataBridge class a singleton.
2020-08-12 09:59:13 +03:00
Vlad Zahorodnii
8baf535a7a xwayland: Make DataBridge a native event filter
With the DataBridge being a native event filter, we can further separate
DataBridge-specific and generic Xwayland bits. In particular, we no
longer have to call DataBridge::filterEvent() from the dispatchEvents()
method, whose main purpose is to dispatch X11 events to kwin.
2020-08-11 16:12:40 +00:00
Vlad Zahorodnii
c86d3b717a xwayland: Call handleXfixesNotify() directly from Selection 2020-08-11 16:12:40 +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
Vlad Zahorodnii
51f926c065 Port Xwayland data bridge to xcbutils
This spares a redundant xcb_prefetch_extension_data() during startup.
2020-08-05 08:48:00 +00:00
Vlad Zahorodnii
e7d02ad355 Introduce X11 default screen property in Application
This spares unnecessary looping through all available X11 screens.
2020-08-05 08:48:00 +00:00
Vlad Zahorodnii
7ec93493c9 Stop Xwayland server when X11 connection breaks
There is no point for processing X11 events if the connection has been
shut down due to a fatal error.
2020-08-05 08:48:00 +00:00
Vlad Zahorodnii
19ad172584 Survive Xwayland crashes
If the Xwayland process crashes, it will bring down the entire session
together with itself. Obviously, we don't want that. At least, Wayland
clients should survive the crash.

This change refactors relevant X11 parts to handle Xwayland crashes in a
less fatal way.

In order to handle Xwayland crashes better, a pair of start() and stop()
methods had been introduced in the Xwayland class to allow starting and
stopping the Xwayland process at any moment.

If we detect that the Xwayland process has crashed, we will immediately
stop the Xwayland server, which in its turn will deactivate the socket
notifier and destroy all connected X11 clients. Unfortunately, a couple
of subtle changes in X11Client::releaseWindow() and Unmanaged::release()
had to be made to ensure that we are left with a valid state after the
Xwayland server has been stopped.
2020-08-05 08:48:00 +00:00
Vlad Zahorodnii
fff2bfe71a Clean up X11 connection setup code
This method removes a code path that we can never hit and fixes some
minor coding style issues.
2020-08-05 08:48:00 +00:00
Vlad Zahorodnii
707a02071e Add a simple test to check Xwayland dying
The new test verifies that we handle Xwayland crashes gracefully.
2020-08-05 08:48:00 +00:00
Vlad Zahorodnii
678944ceb8 xwayland: Remove mysterious Q_FALLTHROUGH macros
We cannot fall through to the next case because `reinterpret_cast`ing
incompatible events is dangerous.
2020-07-29 12:11:57 +00:00
Vlad Zahorodnii
5dbb52de64 Handle delayed start of Xwayland
KWin is supposed to properly handle delayed start of Xwayland, but in
reality it does poor job of that.
2020-07-17 09:10:51 +00:00
David Edmundson
38691aa0e7 [xwl] Fix xcb to wayland clipboard
A seemingly unrelated change to cursors broke xwayland's clipboard
syncing, presumably because of a change in how startup is ordered with
regards to syncing between our internal wayland connection causing a
crash.

It was fixed with a flush, but ultimately guarding things coming up in
the natural order works better.

Long term plans are to finish removing the internal connection.

See xwayland_selections_test in autotests.
2020-06-29 15:06:33 +01:00
Vlad Zahorodnii
68ec39f433 [xwayland] Ensure that DataBridge is initialized prior to PropertyNotify
Since WaylandCursorImage no longer flushes the internal connection
connection and dispatches events, the DataBridge must do it to ensure
that the selections are initialized prior to receiving a ProperyNotify
event.
2020-06-18 07:14:58 +00:00
David Edmundson
83f5362925 [xwl] Fix clipboard clearing after externally changed
1c2f23d31c swapped round things so we
manage a dataSource rather than a dataDevice which may or may not have a
source.

In introduced a bug on clear. We only want to clear the wayland's
clipboard if xwayland owns the current clipboard. Otherwise we reset the
clipboard if some other client sets the selection. There's also no need
to wait for this to go through from our internal client to the server
representation - we can just clear immediately
2020-06-12 09:46:39 +01:00
David Edmundson
1c2f23d31c [xwl] Update to kwaylandserver changes
Summary:
Change so we track track and set a DataSource instead of a DataDevice

This means we have to reverse a connection:
- we need to update Seat with our selection only when our selection is
received by the DataDeviceInterface

- we no longer need to track and watch a dataDevice for changes after
the seat emits selectionChange

Change so that we handle an AbstractDataSource. Meaning we can paste
from clipboard managers.

Testing done:
There is an existing xwayland-selections_test
This still passes.

Copied from:
wl-copy(wlr) to firefox (x)
firefox to wl-paste
firefox to kate (wayland)
kate to firefox

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: cblack, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29332
2020-05-26 12:38:18 +01:00
Aleix Pol
3a9d7a6e9d Port KWin to KWaylandServer
Summary: Away from KWayland::Server and KF5WaylandServer.

Test Plan: Builds, ran nested session

Reviewers: #kwin, #plasma, #frameworks, davidedmundson, zzag

Reviewed By: #kwin, #plasma, davidedmundson, zzag

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29278
2020-04-30 12:56:08 +02:00
David Edmundson
26ce4869a0 [xwl] Fix crash if same data is requested twice
Summary:
m_dataRequests is a list of transfers for a given selection.
It exists primarily as a ref counting mechanism that matches up
transfers with selections.

If the same data is requested twice we would insert two items into the
list with matching timestamps for the original selection. This then
confuses the callback handling.

BUG: 417936

Test Plan:
kwin_wayland + chromium
drag and drop a URL onto desktopview. kwin used to crash here
Now a context menu now appears and I can add a link

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D28630
2020-04-06 23:22:08 +01:00
Aleix Pol
cca0e15b45 Fix compiler warnings
Summary: No need to keep them around for no reason.

Test Plan: Tested the plugins I thought could be affected. Have been using it for a couple of days without problems

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D28062
2020-03-17 15:07:52 +01:00
Vlad Zahorodnii
bc0fbf137d Port away from a deprecated signal
Summary:
QProcess::error() has been deprecated since Qt 5.6. It is highly advised
to use QProcess::errorOccurred() instead.

Test Plan: Compiles.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26922
2020-01-25 23:13:53 +02:00
David Edmundson
7f587d1147 warnings--
Reviewers: apol, zzag

Reviewed By: apol, zzag

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D25667
2019-12-02 09:02:51 +00:00
Yuri Chornoivan
a853e3370a Fix minor typos 2019-11-26 19:48:29 +02:00
David Edmundson
e8fe59323d [xwl] Return c++ version of true in method
Test Plan: Compiles

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D24850
2019-10-22 22:37:11 +01: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
62a7db7028 Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.

This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).

Test Plan: Compiles.

Reviewers: #kwin, davidedmundson, romangg

Reviewed By: #kwin, davidedmundson, romangg

Subscribers: romangg, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 17:48:21 +03:00
Vlad Zagorodniy
4e078b9eaf Revert "wayland: Terminate client connections before Workspace is destroyed"
Commit 826b9742e9 breaks a lot of other
things. Need further investigation before fixing heap-use-after-free.
2019-08-07 11:21:30 +03:00