blob: 5c0a1d5b2630c2e81b81554489cfcad504c95435 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include "qwaylandeventthread.h"
#include <QtCore/QSocketNotifier>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
QWaylandEventThread::QWaylandEventThread(QObject *parent)
: QObject(parent)
, m_display(0)
, m_fileDescriptor(-1)
, m_readNotifier(0)
, m_displayLock(new QMutex)
{
}
QWaylandEventThread::~QWaylandEventThread()
{
delete m_displayLock;
wl_display_disconnect(m_display);
}
void QWaylandEventThread::displayConnect()
{
m_displayLock->lock();
QMetaObject::invokeMethod(this, "waylandDisplayConnect", Qt::QueuedConnection);
}
void QWaylandEventThread::readWaylandEvents()
{
wl_display_dispatch(m_display);
emit newEventsRead();
}
void QWaylandEventThread::waylandDisplayConnect()
{
m_display = wl_display_connect(NULL);
if (m_display == NULL) {
qErrnoWarning(errno, "Failed to create display");
qFatal("No wayland connection available.");
}
m_displayLock->unlock();
m_fileDescriptor = wl_display_get_fd(m_display);
m_readNotifier = new QSocketNotifier(m_fileDescriptor, QSocketNotifier::Read, this);
connect(m_readNotifier, SIGNAL(activated(int)), this, SLOT(readWaylandEvents()));
}
wl_display *QWaylandEventThread::display() const
{
QMutexLocker displayLock(m_displayLock);
return m_display;
}
|