Commit graph

61 commits

Author SHA1 Message Date
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
Vlad Zagorodniy
826b9742e9 wayland: Terminate client connections before Workspace is destroyed
Summary:
When ShellClient tears down, it needs to access RuleBook in order to
discard temporary rules. The problem is that WaylandServer outlives
Workspace and therefore so does ShellClient.

We can't guard against the case when RuleBook::self() is nullptr as it
is vital to discard temporary rules.

This change adjusts termination sequence so all shell clients are
destroyed before Workspace(and thus RuleBook) is gone.

ASAN output:
    ==19922==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000142060 at pc 0x7fbc0fb878bb bp 0x7ffd7d464520 sp 0x7ffd7d464518
    READ of size 8 at 0x606000142060 thread T0
        #0 0x7fbc0fb878ba in QList<KWin::Rules*>::detach() /usr/include/qt5/QtCore/qlist.h:172
        #1 0x7fbc0fb8538d in QList<KWin::Rules*>::begin() /usr/include/qt5/QtCore/qlist.h:324
        #2 0x7fbc0fb808b6 in KWin::RuleBook::discardUsed(KWin::AbstractClient*, bool) /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/rules.cpp:1144
        #3 0x7fbc0fe36e32 in KWin::ShellClient::destroyClient() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/shell_client.cpp:435
        #4 0x7fbc0fe7a726 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (KWin::ShellClient::*)()>::call(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
        #5 0x7fbc0fe784c3 in void QtPrivate::FunctionPointer<void (KWin::ShellClient::*)()>::call<QtPrivate::List<>, void>(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
        #6 0x7fbc0fe74de9 in QtPrivate::QSlotObject<void (KWin::ShellClient::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (/home/jenkins/install-prefix/lib64/libkwin.so.5+0x1677de9)
        #7 0x7fbc04f27357 in QMetaObject::activate(QObject*, int, int, void**) (/usr/lib64/libQt5Core.so.5+0x2b3357)
        #8 0x7fbc074e1970 in KWayland::Server::Resource::unbound() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/build/src/server/KF5WaylandServer_autogen/EWIEGA46WW/moc_resource.cpp:142
        #9 0x7fbc0766b4b4 in KWayland::Server::Resource::Private::unbind(wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:68
        #10 0x7fbc00bdc2ae  (/usr/lib64/libwayland-server.so.0+0x92ae)
        #11 0x7fbc00bdc32f in wl_resource_destroy (/usr/lib64/libwayland-server.so.0+0x932f)
        #12 0x7fbc0766b53f in KWayland::Server::Resource::Private::resourceDestroyedCallback(wl_client*, wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:76
        #13 0x7fbbff481d8c  (/usr/lib64/libffi.so.7+0x6d8c)
        #14 0x7fbbff481179  (/usr/lib64/libffi.so.7+0x6179)
        #15 0x7fbc00bdfa5f  (/usr/lib64/libwayland-server.so.0+0xca5f)
        #16 0x7fbc00bdc6d1  (/usr/lib64/libwayland-server.so.0+0x96d1)
        #17 0x7fbc00bddc71 in wl_event_loop_dispatch (/usr/lib64/libwayland-server.so.0+0xac71)
        #18 0x7fbc07541e50 in KWayland::Server::Display::Private::dispatch() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:148
        #19 0x7fbc075432de in KWayland::Server::Display::dispatchEvents(int) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:220
        #20 0x7fbc0fe864ca in KWin::WaylandServer::dispatch() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/wayland_server.cpp:616
        #21 0x451ce0 in KWin::WaylandTestApplication::~WaylandTestApplication() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/kwin_wayland_test.cpp:91
        #22 0x42faa1 in main /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/globalshortcuts_test.cpp:381
        #23 0x7fbc04796bca in __libc_start_main (/lib64/libc.so.6+0x26bca)
        #24 0x413ea9 in _start (/home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/build/bin/testGlobalShortcuts+0x413ea9)

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D22821
2019-07-31 20:08:50 +03:00
Vlad Zagorodniy
684b4b635e Use more traditional doxygen style
Summary:
So far we were following a bit unique and rare doxygen comment style:

    /**
     * Contents of the comment.
     **/

Doxygen comments with this style look balanced and neat, but many people
that contribute to KWin don't follow this style. Instead, they prefer
more traditional doxygen comment style, i.e.

    /**
     * Contents of the comment.
     */

Reviewing such changes has been a bit frustrating for me (so selfish!)
and for other contributors.

This change switches doxygen comment style in KWin to a more traditional
style. The main reason for doing this is to make code review process easier
for new contributors as well us.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D22812
2019-07-29 22:06:19 +03:00
Vlad Zagorodniy
8af2fa73dc Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.

The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.

Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.

A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!

The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.

The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.

Test Plan: Compiles.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, apol, romangg, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 20:03:22 +03:00