Changeset View
Changeset View
Standalone View
Standalone View
libinput/connection.cpp
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | |||||
76 | 76 | | |||
77 | Q_SIGNALS: | 77 | Q_SIGNALS: | ||
78 | void deviceAdded(QString sysName); | 78 | void deviceAdded(QString sysName); | ||
79 | void deviceRemoved(QString sysName); | 79 | void deviceRemoved(QString sysName); | ||
80 | 80 | | |||
81 | }; | 81 | }; | ||
82 | 82 | | |||
83 | Connection *Connection::s_self = nullptr; | 83 | Connection *Connection::s_self = nullptr; | ||
84 | QThread *Connection::s_thread = nullptr; | 84 | QPointer<QThread> Connection::s_thread; | ||
85 | 85 | | |||
86 | static ConnectionAdaptor *s_adaptor = nullptr; | 86 | static ConnectionAdaptor *s_adaptor = nullptr; | ||
87 | static Context *s_context = nullptr; | 87 | static Context *s_context = nullptr; | ||
88 | 88 | | |||
89 | static quint32 toLibinputLEDS(Xkb::LEDs leds) | 89 | static quint32 toLibinputLEDS(Xkb::LEDs leds) | ||
90 | { | 90 | { | ||
91 | quint32 libinputLeds = 0; | 91 | quint32 libinputLeds = 0; | ||
92 | if (leds.testFlag(Xkb::LED::NumLock)) { | 92 | if (leds.testFlag(Xkb::LED::NumLock)) { | ||
Show All 9 Lines | |||||
102 | } | 102 | } | ||
103 | 103 | | |||
104 | Connection::Connection(QObject *parent) | 104 | Connection::Connection(QObject *parent) | ||
105 | : Connection(nullptr, parent) | 105 | : Connection(nullptr, parent) | ||
106 | { | 106 | { | ||
107 | // only here to fix build, using will crash, BUG 343529 | 107 | // only here to fix build, using will crash, BUG 343529 | ||
108 | } | 108 | } | ||
109 | 109 | | |||
110 | void Connection::createThread() | ||||
111 | { | ||||
112 | if (s_thread) { | ||||
113 | return; | ||||
114 | } | ||||
115 | s_thread = new QThread(); | ||||
116 | s_thread->setObjectName(QStringLiteral("libinput-connection")); | ||||
117 | s_thread->start(); | ||||
118 | } | ||||
119 | | ||||
110 | Connection *Connection::create(QObject *parent) | 120 | Connection *Connection::create(QObject *parent) | ||
111 | { | 121 | { | ||
112 | Q_ASSERT(!s_self); | 122 | Q_ASSERT(!s_self); | ||
113 | static Udev s_udev; | 123 | static Udev s_udev; | ||
114 | if (!s_udev.isValid()) { | 124 | if (!s_udev.isValid()) { | ||
115 | qCWarning(KWIN_LIBINPUT) << "Failed to initialize udev"; | 125 | qCWarning(KWIN_LIBINPUT) << "Failed to initialize udev"; | ||
116 | return nullptr; | 126 | return nullptr; | ||
117 | } | 127 | } | ||
118 | if (!s_context) { | 128 | if (!s_context) { | ||
119 | s_context = new Context(s_udev); | 129 | s_context = new Context(s_udev); | ||
120 | if (!s_context->isValid()) { | 130 | if (!s_context->isValid()) { | ||
121 | qCWarning(KWIN_LIBINPUT) << "Failed to create context from udev"; | 131 | qCWarning(KWIN_LIBINPUT) << "Failed to create context from udev"; | ||
122 | delete s_context; | 132 | delete s_context; | ||
123 | s_context = nullptr; | 133 | s_context = nullptr; | ||
124 | return nullptr; | 134 | return nullptr; | ||
125 | } | 135 | } | ||
126 | // TODO: don't hardcode seat name | 136 | // TODO: don't hardcode seat name | ||
127 | if (!s_context->assignSeat("seat0")) { | 137 | if (!s_context->assignSeat("seat0")) { | ||
128 | qCWarning(KWIN_LIBINPUT) << "Failed to assign seat seat0"; | 138 | qCWarning(KWIN_LIBINPUT) << "Failed to assign seat seat0"; | ||
129 | delete s_context; | 139 | delete s_context; | ||
130 | s_context = nullptr; | 140 | s_context = nullptr; | ||
131 | return nullptr; | 141 | return nullptr; | ||
132 | } | 142 | } | ||
133 | } | 143 | } | ||
134 | s_thread = new QThread(); | 144 | Connection::createThread(); | ||
135 | s_self = new Connection(s_context); | 145 | s_self = new Connection(s_context); | ||
136 | s_self->moveToThread(s_thread); | 146 | s_self->moveToThread(s_thread); | ||
137 | s_thread->start(); | | |||
138 | QObject::connect(s_thread, &QThread::finished, s_self, &QObject::deleteLater); | 147 | QObject::connect(s_thread, &QThread::finished, s_self, &QObject::deleteLater); | ||
139 | QObject::connect(s_thread, &QThread::finished, s_thread, &QObject::deleteLater); | 148 | QObject::connect(s_thread, &QThread::finished, s_thread, &QObject::deleteLater); | ||
140 | QObject::connect(parent, &QObject::destroyed, s_thread, &QThread::quit); | 149 | QObject::connect(parent, &QObject::destroyed, s_thread, &QThread::quit); | ||
141 | if (!s_adaptor) { | 150 | if (!s_adaptor) { | ||
142 | s_adaptor = new ConnectionAdaptor(s_self); | 151 | s_adaptor = new ConnectionAdaptor(s_self); | ||
143 | } | 152 | } | ||
144 | 153 | | |||
145 | return s_self; | 154 | return s_self; | ||
▲ Show 20 Lines • Show All 437 Lines • Show Last 20 Lines |