2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2018 David Edmundson <davidedmundson@kde.org>
|
2014-08-26 14:07:39 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2021-03-10 16:08:30 +00:00
|
|
|
#pragma once
|
2014-08-26 14:07:39 +00:00
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
#include <QObject>
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
#include <KWaylandServer/kwaylandserver_export.h>
|
2014-09-17 13:10:43 +00:00
|
|
|
|
2014-11-17 15:01:18 +00:00
|
|
|
#include "clientconnection.h"
|
|
|
|
|
|
|
|
struct wl_client;
|
2014-08-26 14:07:39 +00:00
|
|
|
struct wl_display;
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2014-08-26 14:07:39 +00:00
|
|
|
{
|
2015-09-09 16:16:02 +00:00
|
|
|
/**
|
|
|
|
* @short KWayland Server.
|
|
|
|
*
|
|
|
|
* This namespace groups all classes related to the Server module.
|
|
|
|
*
|
2020-04-29 14:56:38 +00:00
|
|
|
* The main entry point into the KWaylandServer API is the Display class.
|
2015-09-09 16:16:02 +00:00
|
|
|
* It allows to create a Wayland server and create various global objects on it.
|
|
|
|
*
|
2020-04-29 14:56:38 +00:00
|
|
|
* KWaylandServer is an API to easily create a head-less Wayland server with a
|
2015-09-09 16:16:02 +00:00
|
|
|
* Qt style API.
|
|
|
|
*
|
|
|
|
* @see Display
|
2021-03-16 08:17:36 +00:00
|
|
|
*/
|
2014-08-26 14:07:39 +00:00
|
|
|
|
2021-07-20 17:02:13 +00:00
|
|
|
class ClientBuffer;
|
2020-12-09 20:13:19 +00:00
|
|
|
class ClientConnection;
|
|
|
|
class DisplayPrivate;
|
2014-08-26 14:07:39 +00:00
|
|
|
class OutputInterface;
|
2021-07-23 14:12:28 +00:00
|
|
|
class OutputDeviceV2Interface;
|
2014-09-02 07:34:31 +00:00
|
|
|
class SeatInterface;
|
2014-08-26 14:07:39 +00:00
|
|
|
|
2015-09-09 11:49:58 +00:00
|
|
|
/**
|
|
|
|
* @brief Class holding the Wayland server display loop.
|
|
|
|
*
|
|
|
|
* @todo Improve documentation
|
2021-03-16 08:17:36 +00:00
|
|
|
*/
|
2014-09-17 13:10:43 +00:00
|
|
|
class KWAYLANDSERVER_EXPORT Display : public QObject
|
2014-08-26 14:07:39 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged)
|
|
|
|
public:
|
|
|
|
explicit Display(QObject *parent = nullptr);
|
|
|
|
virtual ~Display();
|
|
|
|
|
2018-11-23 13:42:18 +00:00
|
|
|
/**
|
2020-10-19 15:52:56 +00:00
|
|
|
* Adds a socket with the given @p fileDescriptor to the Wayland display. This function
|
|
|
|
* returns @c true if the socket has been added successfully; otherwise returns @c false.
|
|
|
|
*
|
|
|
|
* The compositor can call this function even after the display has been started.
|
2021-08-16 16:36:15 +00:00
|
|
|
* @arg socketName can optionally be parsed to store the socket name represented by the given file-descriptor
|
2020-10-19 15:52:56 +00:00
|
|
|
*
|
|
|
|
* @see start()
|
|
|
|
*/
|
2021-08-16 16:36:15 +00:00
|
|
|
bool addSocketFileDescriptor(int fileDescriptor, const QString &socketName = QString());
|
2020-10-19 15:52:56 +00:00
|
|
|
/**
|
|
|
|
* Adds a UNIX socket with the specified @p name to the Wayland display. This function
|
|
|
|
* returns @c true if the socket has been added successfully; otherwise returns @c false.
|
|
|
|
*
|
|
|
|
* If the specified socket name @p name is empty, the display will pick a free socket with
|
|
|
|
* a filename "wayland-%d".
|
|
|
|
*
|
|
|
|
* The compositor can call this function even after the display has been started.
|
|
|
|
*
|
|
|
|
* @see start()
|
|
|
|
*/
|
|
|
|
bool addSocketName(const QString &name = QString());
|
2014-08-26 14:07:39 +00:00
|
|
|
|
2018-11-23 13:42:18 +00:00
|
|
|
/**
|
2020-10-19 15:52:56 +00:00
|
|
|
* Returns the list of socket names that the display listens for client connections.
|
|
|
|
*/
|
|
|
|
QStringList socketNames() const;
|
2018-11-23 13:42:18 +00:00
|
|
|
|
2014-08-29 09:42:57 +00:00
|
|
|
quint32 serial();
|
|
|
|
quint32 nextSerial();
|
|
|
|
|
2020-07-06 09:36:25 +00:00
|
|
|
/**
|
|
|
|
* Start accepting client connections. If the display has started successfully, this
|
|
|
|
* function returns @c true; otherwise @c false is returned.
|
|
|
|
*/
|
2020-10-19 15:52:56 +00:00
|
|
|
bool start();
|
|
|
|
void dispatchEvents();
|
2014-08-26 14:07:39 +00:00
|
|
|
|
2014-11-27 15:16:54 +00:00
|
|
|
/**
|
|
|
|
* Create a client for the given file descriptor.
|
|
|
|
*
|
|
|
|
* The client is created as if it connected through the normal server
|
|
|
|
* socket. This method can be used to create a connection bypassing the
|
|
|
|
* normal socket connection. It's recommended to use together with
|
|
|
|
* socketpair and pass the other side of the socket to the client.
|
|
|
|
*
|
|
|
|
* @param fd The file descriptor for the socket to the client
|
|
|
|
* @returns The new ClientConnection or @c null on failure.
|
2021-03-16 08:17:36 +00:00
|
|
|
*/
|
2014-11-27 15:16:54 +00:00
|
|
|
ClientConnection *createClient(int fd);
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
operator wl_display *();
|
|
|
|
operator wl_display *() const;
|
2014-09-18 13:40:22 +00:00
|
|
|
bool isRunning() const;
|
2014-08-26 14:07:39 +00:00
|
|
|
|
2014-08-28 12:22:53 +00:00
|
|
|
void createShm();
|
2015-12-15 14:47:19 +00:00
|
|
|
/**
|
|
|
|
* @returns All SeatInterface currently managed on the Display.
|
2021-03-16 08:17:36 +00:00
|
|
|
*/
|
2021-07-23 14:12:28 +00:00
|
|
|
QVector<SeatInterface*> seats() const;
|
|
|
|
QList<OutputDeviceV2Interface *> outputDevices() const;
|
2020-12-09 20:13:19 +00:00
|
|
|
QList<OutputInterface *> outputs() const;
|
2021-06-24 08:20:09 +00:00
|
|
|
QVector<OutputInterface *> outputsIntersecting(const QRect &rect) const;
|
2020-08-07 18:41:52 +00:00
|
|
|
|
2014-11-17 15:01:18 +00:00
|
|
|
/**
|
|
|
|
* Gets the ClientConnection for the given @p client.
|
|
|
|
* If there is no ClientConnection yet for the given @p client, it will be created.
|
|
|
|
* @param client The native client for which the ClientConnection is retrieved
|
|
|
|
* @return The ClientConnection for the given native client
|
2021-03-16 08:17:36 +00:00
|
|
|
*/
|
2014-11-17 15:01:18 +00:00
|
|
|
ClientConnection *getConnection(wl_client *client);
|
2021-08-29 05:11:06 +00:00
|
|
|
QVector<ClientConnection *> connections() const;
|
2014-11-17 15:01:18 +00:00
|
|
|
|
2015-03-03 08:43:30 +00:00
|
|
|
/**
|
|
|
|
* Set the EGL @p display for this Wayland display.
|
|
|
|
* The EGLDisplay can only be set once and must be alive as long as the Wayland display
|
|
|
|
* is alive. The user should have set up the binding between the EGLDisplay and the
|
|
|
|
* Wayland display prior to calling this method.
|
|
|
|
*
|
|
|
|
* @see eglDisplay
|
2021-03-16 08:17:36 +00:00
|
|
|
*/
|
2015-03-03 08:43:30 +00:00
|
|
|
void setEglDisplay(void *display);
|
|
|
|
/**
|
|
|
|
* @returns the EGLDisplay used for this Wayland display or EGL_NO_DISPLAY if not set.
|
|
|
|
* @see setEglDisplay
|
2021-03-16 08:17:36 +00:00
|
|
|
*/
|
2015-03-03 08:43:30 +00:00
|
|
|
void *eglDisplay() const;
|
|
|
|
|
2021-07-20 17:02:13 +00:00
|
|
|
/**
|
|
|
|
* Returns the client buffer with the specified @a resource. Returns @c null if there's
|
|
|
|
* no such a buffer.
|
|
|
|
*/
|
|
|
|
ClientBuffer *clientBufferForResource(wl_resource *resource) const;
|
|
|
|
|
2020-10-19 15:52:56 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void flush();
|
|
|
|
|
2014-08-26 14:07:39 +00:00
|
|
|
Q_SIGNALS:
|
2020-10-19 15:52:56 +00:00
|
|
|
void socketNamesChanged();
|
2014-08-26 14:07:39 +00:00
|
|
|
void runningChanged(bool);
|
2021-08-29 05:11:06 +00:00
|
|
|
void clientConnected(KWaylandServer::ClientConnection *);
|
|
|
|
void clientDisconnected(KWaylandServer::ClientConnection *);
|
2014-08-26 14:07:39 +00:00
|
|
|
|
|
|
|
private:
|
2020-12-09 20:13:19 +00:00
|
|
|
friend class DisplayPrivate;
|
|
|
|
QScopedPointer<DisplayPrivate> d;
|
2014-08-26 14:07:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|