2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2019-02-19 08:50:20 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2019-02-19 08:50:20 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-02-19 08:50:20 +00:00
|
|
|
#ifndef KWIN_XWL_XWAYLAND
|
|
|
|
#define KWIN_XWL_XWAYLAND
|
|
|
|
|
2018-08-22 12:36:11 +00:00
|
|
|
#include "xwayland_interface.h"
|
2019-02-19 08:50:20 +00:00
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QSocketNotifier>
|
2021-02-08 11:57:12 +00:00
|
|
|
#include <QTemporaryFile>
|
2020-07-20 08:07:08 +00:00
|
|
|
|
2021-02-08 22:00:08 +00:00
|
|
|
class KSelectionOwner;
|
|
|
|
|
2019-02-19 08:50:20 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2018-08-22 00:20:16 +00:00
|
|
|
class ApplicationWaylandAbstract;
|
2021-02-08 15:36:41 +00:00
|
|
|
class XwaylandSocket;
|
2019-02-19 08:50:20 +00:00
|
|
|
|
|
|
|
namespace Xwl
|
|
|
|
{
|
|
|
|
|
2018-08-22 12:36:11 +00:00
|
|
|
class Xwayland : public XwaylandInterface
|
2019-02-19 08:50:20 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2019-07-02 19:56:03 +00:00
|
|
|
|
2019-02-19 08:50:20 +00:00
|
|
|
public:
|
2018-08-22 00:20:16 +00:00
|
|
|
Xwayland(ApplicationWaylandAbstract *app, QObject *parent = nullptr);
|
2019-07-02 19:56:03 +00:00
|
|
|
~Xwayland() override;
|
2019-02-19 08:50:20 +00:00
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the associated Xwayland process or @c null if the Xwayland server is inactive.
|
|
|
|
*/
|
2020-07-20 07:44:13 +00:00
|
|
|
QProcess *process() const override;
|
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Starts the Xwayland server.
|
|
|
|
*
|
|
|
|
* This method will spawn an Xwayland process and will establish a new XCB connection to it.
|
2020-09-08 08:18:31 +00:00
|
|
|
* If an error has occurred during the startup, the errorOccurred() signal is going to
|
2020-07-20 08:07:08 +00:00
|
|
|
* be emitted. If the Xwayland server has started successfully, the started() signal will be
|
|
|
|
* emitted.
|
|
|
|
*
|
|
|
|
* @see started(), stop()
|
|
|
|
*/
|
|
|
|
void start();
|
|
|
|
/**
|
|
|
|
* Stops the Xwayland server.
|
|
|
|
*
|
|
|
|
* This method will destroy the existing XCB connection as well all connected X11 clients.
|
|
|
|
*
|
|
|
|
* A SIGTERM signal will be sent to the Xwayland process. If Xwayland doesn't shut down
|
|
|
|
* within a reasonable amount of time (5 seconds), a SIGKILL signal will be sent and thus
|
|
|
|
* the process will be killed for good.
|
|
|
|
*
|
|
|
|
* If the Xwayland process crashes, the server will be stopped automatically.
|
|
|
|
*
|
|
|
|
* @see start()
|
|
|
|
*/
|
|
|
|
void stop();
|
2020-08-27 09:05:28 +00:00
|
|
|
/**
|
|
|
|
* Restarts the Xwayland server. This method is equivalent to calling stop() and start().
|
|
|
|
*/
|
|
|
|
void restart();
|
2020-07-20 08:07:08 +00:00
|
|
|
|
2019-02-19 08:50:20 +00:00
|
|
|
Q_SIGNALS:
|
2020-07-20 08:07:08 +00:00
|
|
|
/**
|
|
|
|
* This signal is emitted when the Xwayland server has been started successfully and it is
|
|
|
|
* ready to accept and manage X11 clients.
|
|
|
|
*/
|
|
|
|
void started();
|
2020-09-08 08:18:31 +00:00
|
|
|
/**
|
|
|
|
* This signal is emitted when an error occurs with the Xwayland server.
|
|
|
|
*/
|
|
|
|
void errorOccurred();
|
2019-02-19 08:50:20 +00:00
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void dispatchEvents();
|
2020-08-27 09:05:28 +00:00
|
|
|
void resetCrashCount();
|
2020-07-20 08:07:08 +00:00
|
|
|
|
2020-08-27 09:05:28 +00:00
|
|
|
void handleXwaylandFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
|
|
|
void handleXwaylandCrashed();
|
2020-07-20 08:07:08 +00:00
|
|
|
void handleXwaylandError(QProcess::ProcessError error);
|
2020-09-08 09:35:47 +00:00
|
|
|
void handleXwaylandReady();
|
2020-07-20 08:07:08 +00:00
|
|
|
|
2019-02-19 08:50:20 +00:00
|
|
|
private:
|
2020-07-20 08:07:08 +00:00
|
|
|
void installSocketNotifier();
|
|
|
|
void uninstallSocketNotifier();
|
2021-02-08 15:36:41 +00:00
|
|
|
void maybeDestroyReadyNotifier();
|
2020-07-20 08:07:08 +00:00
|
|
|
|
2020-09-01 16:01:19 +00:00
|
|
|
bool createX11Connection();
|
2020-07-07 10:05:39 +00:00
|
|
|
void destroyX11Connection();
|
2019-02-19 08:50:20 +00:00
|
|
|
|
2021-02-08 11:57:12 +00:00
|
|
|
bool createXauthorityFile();
|
2021-02-10 13:09:02 +00:00
|
|
|
bool writeXauthorityEntries();
|
2021-02-08 11:57:12 +00:00
|
|
|
|
2019-07-02 19:56:03 +00:00
|
|
|
DragEventReply dragMoveFilter(Toplevel *target, const QPoint &pos) override;
|
2018-08-22 12:56:48 +00:00
|
|
|
|
2019-02-19 08:50:20 +00:00
|
|
|
int m_xcbConnectionFd = -1;
|
|
|
|
QProcess *m_xwaylandProcess = nullptr;
|
2020-07-20 08:07:08 +00:00
|
|
|
QSocketNotifier *m_socketNotifier = nullptr;
|
2021-02-08 15:36:41 +00:00
|
|
|
QSocketNotifier *m_readyNotifier = nullptr;
|
2020-08-27 09:05:28 +00:00
|
|
|
QTimer *m_resetCrashCountTimer = nullptr;
|
2018-08-22 00:20:16 +00:00
|
|
|
ApplicationWaylandAbstract *m_app;
|
2021-02-08 22:00:08 +00:00
|
|
|
QScopedPointer<KSelectionOwner> m_selectionOwner;
|
2021-02-10 12:52:38 +00:00
|
|
|
QTemporaryFile m_authorityFile;
|
2021-02-08 15:36:41 +00:00
|
|
|
QScopedPointer<XwaylandSocket> m_socket;
|
2020-08-27 09:05:28 +00:00
|
|
|
int m_crashCount = 0;
|
2019-07-02 19:56:03 +00:00
|
|
|
|
|
|
|
Q_DISABLE_COPY(Xwayland)
|
2019-02-19 08:50:20 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 19:56:03 +00:00
|
|
|
} // namespace Xwl
|
|
|
|
} // namespace KWin
|
2019-02-19 08:50:20 +00:00
|
|
|
|
|
|
|
#endif
|