File indexing completed on 2024-05-19 05:32:52

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
0006     SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #pragma once
0012 
0013 #include <QList>
0014 #include <QObject>
0015 #include <QProcess>
0016 #include <QSocketNotifier>
0017 #include <QTemporaryFile>
0018 #include <memory>
0019 
0020 #include <kwin_export.h>
0021 
0022 class QTimer;
0023 
0024 namespace KWin
0025 {
0026 class XwaylandSocket;
0027 
0028 namespace Xwl
0029 {
0030 
0031 class KWIN_EXPORT XwaylandLauncher : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     explicit XwaylandLauncher(QObject *parent);
0036     ~XwaylandLauncher();
0037 
0038     /**
0039      * Set file descriptors that xwayland should use for listening
0040      * This is to be used in conjuction with kwin_wayland_wrapper which creates a socket externally
0041      * That external process is responsible for setting up the DISPLAY env with a valid value.
0042      * Ownership of the file descriptor is not transferrred.
0043      */
0044     void setListenFDs(const QList<int> &listenFds);
0045 
0046     /**
0047      * Sets the display name used by XWayland (i.e ':0')
0048      * This is to be used in conjuction with kwin_wayland_wrapper to provide the name of the socket
0049      * created externally
0050      */
0051     void setDisplayName(const QString &displayName);
0052 
0053     /**
0054      * Sets the xauthority file to be used by XWayland
0055      * This is to be used in conjuction with kwin_wayland_wrapper
0056      */
0057     void setXauthority(const QString &xauthority);
0058 
0059     void enable();
0060     void disable();
0061     bool start();
0062     void stop();
0063 
0064     QString displayName() const;
0065     QString xauthority() const;
0066     int xcbConnectionFd() const;
0067 
0068     /**
0069      * @internal
0070      */
0071     QProcess *process() const;
0072 Q_SIGNALS:
0073     /**
0074      * This signal is emitted when the Xwayland server has been started successfully and it is
0075      * ready to accept and manage X11 clients.
0076      * For restarts it may be emitted multiple times
0077      */
0078     void started();
0079     /**
0080      * This signal is emitted when the Xwayland server quits or crashes
0081      */
0082     void finished();
0083     /**
0084      * This signal is emitted when an error occurs with the Xwayland server.
0085      */
0086     void errorOccurred();
0087 
0088 private Q_SLOTS:
0089     void resetCrashCount();
0090     void handleXwaylandFinished(int exitCode, QProcess::ExitStatus exitStatus);
0091     void handleXwaylandError(QProcess::ProcessError error);
0092 
0093 private:
0094     void maybeDestroyReadyNotifier();
0095 
0096 
0097     QProcess *m_xwaylandProcess = nullptr;
0098     QSocketNotifier *m_readyNotifier = nullptr;
0099     QTimer *m_resetCrashCountTimer = nullptr;
0100     // this is only used when kwin is run without kwin_wayland_wrapper
0101     std::unique_ptr<XwaylandSocket> m_socket;
0102     QList<int> m_listenFds;
0103     QString m_displayName;
0104     QString m_xAuthority;
0105 
0106     bool m_enabled = false;
0107     int m_crashCount = 0;
0108     int m_xcbConnectionFd = -1;
0109 };
0110 
0111 }
0112 }