kwin/src/xwl/xwayland.h

124 lines
3.3 KiB
C
Raw Normal View History

2020-08-02 22:22:19 +00:00
/*
KWin - the KDE window manager
This file is part of the KDE project.
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>
2020-08-02 22:22:19 +00:00
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KWIN_XWL_XWAYLAND
#define KWIN_XWL_XWAYLAND
#include "xwayland_interface.h"
#include <QProcess>
#include <QSocketNotifier>
#include <QTemporaryFile>
class KSelectionOwner;
namespace KWin
{
class ApplicationWaylandAbstract;
class XwaylandSocket;
namespace Xwl
{
class Xwayland : public XwaylandInterface
{
Q_OBJECT
2019-07-02 19:56:03 +00:00
public:
Xwayland(ApplicationWaylandAbstract *app, QObject *parent = nullptr);
2019-07-02 19:56:03 +00:00
~Xwayland() override;
/**
* Returns the associated Xwayland process or @c null if the Xwayland server is inactive.
*/
QProcess *process() const override;
public Q_SLOTS:
/**
* Starts the Xwayland server.
*
* This method will spawn an Xwayland process and will establish a new XCB connection to it.
* If an error has occurred during the startup, the errorOccurred() signal is going to
* 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();
/**
* Restarts the Xwayland server. This method is equivalent to calling stop() and start().
*/
void restart();
Q_SIGNALS:
/**
* This signal is emitted when the Xwayland server has been started successfully and it is
* ready to accept and manage X11 clients.
*/
void started();
/**
* This signal is emitted when an error occurs with the Xwayland server.
*/
void errorOccurred();
private Q_SLOTS:
void dispatchEvents();
void resetCrashCount();
void handleXwaylandFinished(int exitCode, QProcess::ExitStatus exitStatus);
void handleXwaylandCrashed();
void handleXwaylandError(QProcess::ProcessError error);
void handleXwaylandReady();
private:
void installSocketNotifier();
void uninstallSocketNotifier();
void maybeDestroyReadyNotifier();
bool createX11Connection();
void destroyX11Connection();
bool createXauthorityFile();
bool writeXauthorityEntries();
2019-07-02 19:56:03 +00:00
DragEventReply dragMoveFilter(Toplevel *target, const QPoint &pos) override;
[xwl] Drag and drop between Xwayland and Wayland native clients Summary: Building upon the generic X Selection support this patch establishes another selection class representing the XDND selection and provides interfaces to communicate drags originating from Xwayland windows to the Wayland server KWin and drags originating from Wayland native drags to Xwayland. For Wayland native drags KWin will claim the XDND selection as owner and will simply translate all relevant events to the XDND protocol and receive alike messages by X clients. When an X client claims the XDND selection KWin is notified via the X protocol and it decides if it allows the X drag to transcend into the Wayland protocol. If this is the case the mouse position is tracked and on entering a Wayland native window a proxy X Window is mapped to the top of the window stack. This proxy window acts as a drag destination for the drag origin window and again X messages will be translated into respective Wayland protocol calls. If the cursor leaves the Wayland window geometry before a drop is registered, the proxy window is unmapped, what triggers a subsequent drag leave event. In both directions the necessary core integration is minimal. There is a single call to be done in the drag and drop event filter through the Xwayland interface class. From my tests this patch facilitates drags between any Qt/KDE apps. What needs extra care are the browsers, which use target formats, that are not directly compatible with the Wayland protocol's MIME representation. For Chromium an additional integration step must be done in order to provide it with a net window stack containing the proxy window. Test Plan: Manually. Auto tests planned. Reviewers: #kwin Subscribers: zzag, kwin, alexde Tags: #kwin Maniphest Tasks: T4611 Differential Revision: https://phabricator.kde.org/D15627
2018-08-22 12:56:48 +00:00
int m_xcbConnectionFd = -1;
QProcess *m_xwaylandProcess = nullptr;
QSocketNotifier *m_socketNotifier = nullptr;
QSocketNotifier *m_readyNotifier = nullptr;
QTimer *m_resetCrashCountTimer = nullptr;
ApplicationWaylandAbstract *m_app;
QScopedPointer<KSelectionOwner> m_selectionOwner;
QTemporaryFile m_authorityFile;
QScopedPointer<XwaylandSocket> m_socket;
int m_crashCount = 0;
2019-07-02 19:56:03 +00:00
Q_DISABLE_COPY(Xwayland)
};
2019-07-02 19:56:03 +00:00
} // namespace Xwl
} // namespace KWin
#endif