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.
master
Vlad Zahorodnii 2020-08-11 19:36:48 +03:00
parent a15966c723
commit e4f2c30f50
4 changed files with 12 additions and 14 deletions

View File

@ -33,11 +33,11 @@ namespace KWin
namespace Xwl
{
static DataBridge *s_self = nullptr;
KWIN_SINGLETON_FACTORY(DataBridge)
DataBridge *DataBridge::self()
void DataBridge::destroy()
{
return s_self;
delete s_self;
}
DataBridge::DataBridge(QObject *parent)

View File

@ -9,6 +9,8 @@
#ifndef KWIN_XWL_DATABRIDGE
#define KWIN_XWL_DATABRIDGE
#include "kwinglobals.h"
#include <QAbstractNativeEventFilter>
#include <QObject>
#include <QPoint>
@ -32,7 +34,6 @@ class Toplevel;
namespace Xwl
{
class Xwayland;
class Clipboard;
class Dnd;
enum class DragEventReply;
@ -48,9 +49,8 @@ class DataBridge : public QObject, public QAbstractNativeEventFilter
Q_OBJECT
public:
static DataBridge *self();
static void destroy();
explicit DataBridge(QObject *parent = nullptr);
~DataBridge() override;
DragEventReply dragMoveFilter(Toplevel *target, const QPoint &pos);
@ -80,7 +80,7 @@ private:
KWayland::Client::DataDevice *m_dataDevice = nullptr;
KWaylandServer::DataDeviceInterface *m_dataDeviceInterface = nullptr;
Q_DISABLE_COPY(DataBridge)
KWIN_SINGLETON(DataBridge)
};
} // namespace Xwl

View File

@ -152,8 +152,7 @@ void Xwayland::stop()
// events will be dispatched before blocking; otherwise we will simply hang...
uninstallSocketNotifier();
delete m_dataBridge;
m_dataBridge = nullptr;
DataBridge::destroy();
destroyX11Connection();
@ -321,7 +320,7 @@ void Xwayland::continueStartupWithX()
KSelectionOwner owner("WM_S0", xcbConn, m_app->x11RootWindow());
owner.claim(true);
m_dataBridge = new DataBridge;
DataBridge::create(this);
auto env = m_app->processStartupEnvironment();
env.insert(QStringLiteral("DISPLAY"), QString::fromUtf8(qgetenv("DISPLAY")));
@ -334,10 +333,11 @@ void Xwayland::continueStartupWithX()
DragEventReply Xwayland::dragMoveFilter(Toplevel *target, const QPoint &pos)
{
if (!m_dataBridge) {
DataBridge *bridge = DataBridge::self();
if (!bridge) {
return DragEventReply::Wayland;
}
return m_dataBridge->dragMoveFilter(target, pos);
return bridge->dragMoveFilter(target, pos);
}
} // namespace Xwl

View File

@ -21,7 +21,6 @@ class ApplicationWaylandAbstract;
namespace Xwl
{
class DataBridge;
class Xwayland : public XwaylandInterface
{
@ -93,7 +92,6 @@ private:
int m_displayFileDescriptor = -1;
int m_xcbConnectionFd = -1;
QProcess *m_xwaylandProcess = nullptr;
DataBridge *m_dataBridge = nullptr;
QSocketNotifier *m_socketNotifier = nullptr;
ApplicationWaylandAbstract *m_app;