[libinput] Add the Device to Event

Summary:
The Event class now holds a pointer to the Device and not only to the
native libinput_device.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1666
This commit is contained in:
Martin Gräßlin 2016-05-24 10:01:48 +02:00
parent b72e4ec897
commit 6d090cd263
3 changed files with 15 additions and 4 deletions

View file

@ -214,7 +214,7 @@ void Connection::processEvents()
QScopedPointer<Event> event(m_eventQueue.takeFirst());
switch (event->type()) {
case LIBINPUT_EVENT_DEVICE_ADDED: {
auto device = new Device(event->device(), this);
auto device = new Device(event->nativeDevice(), this);
m_devices << device;
if (device->isKeyboard()) {
m_keyboard++;
@ -245,7 +245,7 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_DEVICE_REMOVED: {
auto it = std::find_if(m_devices.begin(), m_devices.end(), [&event] (Device *d) { return event->device() == d->device(); } );
auto it = std::find_if(m_devices.begin(), m_devices.end(), [&event] (Device *d) { return event->device() == d; } );
if (it == m_devices.end()) {
// we don't know this device
break;

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "events.h"
#include "device.h"
#include <QSize>
@ -56,6 +57,7 @@ Event *Event::create(libinput_event *event)
Event::Event(libinput_event *event, libinput_event_type type)
: m_event(event)
, m_type(type)
, m_device(Device::getDevice(libinput_event_get_device(m_event)))
{
}
@ -64,8 +66,11 @@ Event::~Event()
libinput_event_destroy(m_event);
}
libinput_device *Event::device() const
libinput_device *Event::nativeDevice() const
{
if (m_device) {
return m_device->device();
}
return libinput_event_get_device(m_event);
}

View file

@ -29,13 +29,18 @@ namespace KWin
namespace LibInput
{
class Device;
class Event
{
public:
virtual ~Event();
libinput_event_type type() const;
libinput_device *device() const;
Device *device() const {
return m_device;
}
libinput_device *nativeDevice() const;
operator libinput_event*() {
return m_event;
@ -52,6 +57,7 @@ protected:
private:
libinput_event *m_event;
libinput_event_type m_type;
Device *m_device;
};
class KeyEvent : public Event