libinput: use std::unique_ptr for events

This commit is contained in:
Xaver Hugl 2022-06-01 12:13:34 +02:00
parent d2f7f75d39
commit a38a44cb2a
13 changed files with 94 additions and 94 deletions

View file

@ -81,15 +81,15 @@ void TestLibinputGestureEvent::testType()
gestureEvent->type = type;
gestureEvent->device = m_nativeDevice;
QScopedPointer<Event> event(Event::create(gestureEvent));
std::unique_ptr<Event> event(Event::create(gestureEvent));
// API of event
QCOMPARE(event->type(), type);
QCOMPARE(event->device(), m_device);
QCOMPARE(event->nativeDevice(), m_nativeDevice);
QCOMPARE((libinput_event *)(*event.data()), gestureEvent);
QCOMPARE((libinput_event *)(*event.get()), gestureEvent);
// verify it's a pointer event
QVERIFY(dynamic_cast<GestureEvent *>(event.data()));
QCOMPARE((libinput_event_gesture *)(*dynamic_cast<GestureEvent *>(event.data())), gestureEvent);
QVERIFY(dynamic_cast<GestureEvent *>(event.get()));
QCOMPARE((libinput_event_gesture *)(*dynamic_cast<GestureEvent *>(event.get())), gestureEvent);
}
void TestLibinputGestureEvent::testStart_data()
@ -109,15 +109,15 @@ void TestLibinputGestureEvent::testStart()
gestureEvent->fingerCount = 3;
gestureEvent->time = 100u;
QScopedPointer<Event> event(Event::create(gestureEvent));
auto ge = dynamic_cast<GestureEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(gestureEvent));
auto ge = dynamic_cast<GestureEvent *>(event.get());
QVERIFY(ge);
QCOMPARE(ge->fingerCount(), gestureEvent->fingerCount);
QVERIFY(!ge->isCancelled());
QCOMPARE(ge->time(), gestureEvent->time);
QCOMPARE(ge->delta(), QSizeF(0, 0));
if (ge->type() == LIBINPUT_EVENT_GESTURE_PINCH_BEGIN) {
auto pe = dynamic_cast<PinchGestureEvent *>(event.data());
auto pe = dynamic_cast<PinchGestureEvent *>(event.get());
QCOMPARE(pe->scale(), 1.0);
QCOMPARE(pe->angleDelta(), 0.0);
}
@ -132,8 +132,8 @@ void TestLibinputGestureEvent::testSwipeUpdate()
gestureEvent->time = 200u;
gestureEvent->delta = QSizeF(2, 3);
QScopedPointer<Event> event(Event::create(gestureEvent));
auto se = dynamic_cast<SwipeGestureEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(gestureEvent));
auto se = dynamic_cast<SwipeGestureEvent *>(event.get());
QVERIFY(se);
QCOMPARE(se->fingerCount(), gestureEvent->fingerCount);
QVERIFY(!se->isCancelled());
@ -152,8 +152,8 @@ void TestLibinputGestureEvent::testPinchUpdate()
gestureEvent->scale = 2;
gestureEvent->angleDelta = -30;
QScopedPointer<Event> event(Event::create(gestureEvent));
auto pe = dynamic_cast<PinchGestureEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(gestureEvent));
auto pe = dynamic_cast<PinchGestureEvent *>(event.get());
QVERIFY(pe);
QCOMPARE(pe->fingerCount(), gestureEvent->fingerCount);
QVERIFY(!pe->isCancelled());
@ -186,15 +186,15 @@ void TestLibinputGestureEvent::testEnd()
gestureEvent->time = 300u;
gestureEvent->scale = 3;
QScopedPointer<Event> event(Event::create(gestureEvent));
auto ge = dynamic_cast<GestureEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(gestureEvent));
auto ge = dynamic_cast<GestureEvent *>(event.get());
QVERIFY(ge);
QCOMPARE(ge->fingerCount(), gestureEvent->fingerCount);
QCOMPARE(ge->isCancelled(), cancelled);
QCOMPARE(ge->time(), gestureEvent->time);
QCOMPARE(ge->delta(), QSizeF(0, 0));
if (ge->type() == LIBINPUT_EVENT_GESTURE_PINCH_END) {
auto pe = dynamic_cast<PinchGestureEvent *>(event.data());
auto pe = dynamic_cast<PinchGestureEvent *>(event.get());
QCOMPARE(pe->scale(), gestureEvent->scale);
QCOMPARE(pe->angleDelta(), 0.0);
}

View file

@ -57,15 +57,15 @@ void TestLibinputKeyEvent::testCreate()
libinput_event_keyboard *keyEvent = new libinput_event_keyboard;
keyEvent->device = m_nativeDevice;
QScopedPointer<Event> event(Event::create(keyEvent));
std::unique_ptr<Event> event{Event::create(keyEvent)};
// API of event
QCOMPARE(event->type(), LIBINPUT_EVENT_KEYBOARD_KEY);
QCOMPARE(event->device(), m_device);
QCOMPARE(event->nativeDevice(), m_nativeDevice);
QCOMPARE((libinput_event *)(*event.data()), keyEvent);
QCOMPARE((libinput_event *)(*event.get()), keyEvent);
// verify it's a key event
QVERIFY(dynamic_cast<KeyEvent *>(event.data()));
QCOMPARE((libinput_event_keyboard *)(*dynamic_cast<KeyEvent *>(event.data())), keyEvent);
QVERIFY(dynamic_cast<KeyEvent *>(event.get()));
QCOMPARE((libinput_event_keyboard *)(*dynamic_cast<KeyEvent *>(event.get())), keyEvent);
// verify that a nullptr passed to Event::create returns a nullptr
QVERIFY(!Event::create(nullptr));
@ -94,8 +94,8 @@ void TestLibinputKeyEvent::testEvent()
QFETCH(quint32, time);
keyEvent->time = time;
QScopedPointer<Event> event(Event::create(keyEvent));
auto ke = dynamic_cast<KeyEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(keyEvent));
auto ke = dynamic_cast<KeyEvent *>(event.get());
QVERIFY(ke);
QTEST(ke->state(), "expectedKeyState");
QCOMPARE(ke->key(), key);

View file

@ -77,15 +77,15 @@ void TestLibinputPointerEvent::testType()
pointerEvent->type = type;
pointerEvent->device = m_nativeDevice;
QScopedPointer<Event> event(Event::create(pointerEvent));
std::unique_ptr<Event> event(Event::create(pointerEvent));
// API of event
QCOMPARE(event->type(), type);
QCOMPARE(event->device(), m_device);
QCOMPARE(event->nativeDevice(), m_nativeDevice);
QCOMPARE((libinput_event *)(*event.data()), pointerEvent);
QCOMPARE((libinput_event *)(*event.get()), pointerEvent);
// verify it's a pointer event
QVERIFY(dynamic_cast<PointerEvent *>(event.data()));
QCOMPARE((libinput_event_pointer *)(*dynamic_cast<PointerEvent *>(event.data())), pointerEvent);
QVERIFY(dynamic_cast<PointerEvent *>(event.get()));
QCOMPARE((libinput_event_pointer *)(*dynamic_cast<PointerEvent *>(event.get())), pointerEvent);
}
void TestLibinputPointerEvent::testButton_data()
@ -112,8 +112,8 @@ void TestLibinputPointerEvent::testButton()
QFETCH(quint32, time);
pointerEvent->time = time;
QScopedPointer<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.get());
QVERIFY(pe);
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_BUTTON);
QTEST(pe->buttonState(), "expectedButtonState");
@ -169,8 +169,8 @@ void TestLibinputPointerEvent::testAxis()
pointerEvent->axisSource = axisSource;
pointerEvent->time = time;
QScopedPointer<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.get());
QVERIFY(pe);
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_AXIS);
QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisHorizontal), horizontal);
@ -192,8 +192,8 @@ void TestLibinputPointerEvent::testMotion()
pointerEvent->delta = QSizeF(2.1, 4.5);
pointerEvent->time = 500u;
QScopedPointer<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.get());
QVERIFY(pe);
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION);
QCOMPARE(pe->time(), 500u);
@ -209,8 +209,8 @@ void TestLibinputPointerEvent::testAbsoluteMotion()
pointerEvent->absolutePos = QPointF(6.25, 6.9);
pointerEvent->time = 500u;
QScopedPointer<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(pointerEvent));
auto pe = dynamic_cast<PointerEvent *>(event.get());
QVERIFY(pe);
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
QCOMPARE(pe->time(), 500u);

View file

@ -74,8 +74,8 @@ void TestLibinputSwitchEvent::testToggled()
nativeEvent->time = 23;
nativeEvent->timeMicroseconds = 23456789;
QScopedPointer<Event> event(Event::create(nativeEvent));
auto se = dynamic_cast<SwitchEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(nativeEvent));
auto se = dynamic_cast<SwitchEvent *>(event.get());
QVERIFY(se);
QCOMPARE(se->device(), m_device.get());
QCOMPARE(se->nativeDevice(), m_nativeDevice.get());

View file

@ -74,18 +74,18 @@ void TestLibinputTouchEvent::testType()
touchEvent->device = m_nativeDevice;
touchEvent->slot = 0;
QScopedPointer<Event> event(Event::create(touchEvent));
std::unique_ptr<Event> event(Event::create(touchEvent));
// API of event
QCOMPARE(event->type(), type);
QCOMPARE(event->device(), m_device);
QCOMPARE(event->nativeDevice(), m_nativeDevice);
QCOMPARE((libinput_event *)(*event.data()), touchEvent);
QCOMPARE((libinput_event *)(*event.get()), touchEvent);
// verify it's a pointer event
QVERIFY(dynamic_cast<TouchEvent *>(event.data()));
QCOMPARE((libinput_event_touch *)(*dynamic_cast<TouchEvent *>(event.data())), touchEvent);
QVERIFY(dynamic_cast<TouchEvent *>(event.get()));
QCOMPARE((libinput_event_touch *)(*dynamic_cast<TouchEvent *>(event.get())), touchEvent);
QFETCH(bool, hasId);
if (hasId) {
QCOMPARE(dynamic_cast<TouchEvent *>(event.data())->id(), 0);
QCOMPARE(dynamic_cast<TouchEvent *>(event.get())->id(), 0);
}
}
@ -107,8 +107,8 @@ void TestLibinputTouchEvent::testAbsoluteMotion()
touchEvent->time = 500u;
touchEvent->slot = 1;
QScopedPointer<Event> event(Event::create(touchEvent));
auto te = dynamic_cast<TouchEvent *>(event.data());
std::unique_ptr<Event> event(Event::create(touchEvent));
auto te = dynamic_cast<TouchEvent *>(event.get());
QVERIFY(te);
QCOMPARE(te->type(), type);
QCOMPARE(te->time(), 500u);

View file

@ -183,16 +183,16 @@ void Connection::deactivate()
void Connection::handleEvent()
{
QMutexLocker locker(&m_mutex);
const bool wasEmpty = m_eventQueue.isEmpty();
const bool wasEmpty = m_eventQueue.empty();
do {
m_input->dispatch();
Event *event = m_input->event();
std::unique_ptr<Event> event = m_input->event();
if (!event) {
break;
}
m_eventQueue << event;
m_eventQueue.push_back(std::move(event));
} while (true);
if (wasEmpty && !m_eventQueue.isEmpty()) {
if (wasEmpty && !m_eventQueue.empty()) {
Q_EMIT eventsRead();
}
}
@ -285,8 +285,9 @@ KWin::TabletToolId createTabletId(libinput_tablet_tool *tool, void *userData)
void Connection::processEvents()
{
QMutexLocker locker(&m_mutex);
while (!m_eventQueue.isEmpty()) {
QScopedPointer<Event> event(m_eventQueue.takeFirst());
while (m_eventQueue.size() != 0) {
std::unique_ptr<Event> event = std::move(m_eventQueue.front());
m_eventQueue.pop_front();
switch (event->type()) {
case LIBINPUT_EVENT_DEVICE_ADDED: {
auto device = new Device(event->nativeDevice());
@ -314,12 +315,12 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_KEYBOARD_KEY: {
KeyEvent *ke = static_cast<KeyEvent *>(event.data());
KeyEvent *ke = static_cast<KeyEvent *>(event.get());
Q_EMIT ke->device()->keyChanged(ke->key(), ke->state(), ke->time(), ke->device());
break;
}
case LIBINPUT_EVENT_POINTER_AXIS: {
PointerEvent *pe = static_cast<PointerEvent *>(event.data());
PointerEvent *pe = static_cast<PointerEvent *>(event.get());
const auto axes = pe->axis();
for (const InputRedirection::PointerAxis &axis : axes) {
Q_EMIT pe->device()->pointerAxisChanged(axis, pe->axisValue(axis), pe->discreteAxisValue(axis),
@ -328,12 +329,12 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_POINTER_BUTTON: {
PointerEvent *pe = static_cast<PointerEvent *>(event.data());
PointerEvent *pe = static_cast<PointerEvent *>(event.get());
Q_EMIT pe->device()->pointerButtonChanged(pe->button(), pe->buttonState(), pe->time(), pe->device());
break;
}
case LIBINPUT_EVENT_POINTER_MOTION: {
PointerEvent *pe = static_cast<PointerEvent *>(event.data());
PointerEvent *pe = static_cast<PointerEvent *>(event.get());
auto delta = pe->delta();
auto deltaNonAccel = pe->deltaUnaccelerated();
quint32 latestTime = pe->time();
@ -341,7 +342,7 @@ void Connection::processEvents()
auto it = m_eventQueue.begin();
while (it != m_eventQueue.end()) {
if ((*it)->type() == LIBINPUT_EVENT_POINTER_MOTION) {
QScopedPointer<PointerEvent> p(static_cast<PointerEvent *>(*it));
std::unique_ptr<PointerEvent> p{static_cast<PointerEvent *>(it->release())};
delta += p->delta();
deltaNonAccel += p->deltaUnaccelerated();
latestTime = p->time();
@ -355,13 +356,13 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: {
PointerEvent *pe = static_cast<PointerEvent *>(event.data());
PointerEvent *pe = static_cast<PointerEvent *>(event.get());
Q_EMIT pe->device()->pointerMotionAbsolute(pe->absolutePos(workspace()->geometry().size()), pe->time(), pe->device());
break;
}
case LIBINPUT_EVENT_TOUCH_DOWN: {
#ifndef KWIN_BUILD_TESTING
TouchEvent *te = static_cast<TouchEvent *>(event.data());
TouchEvent *te = static_cast<TouchEvent *>(event.get());
const auto *output = te->device()->output();
const QPointF globalPos = devicePointToGlobalPosition(te->absolutePos(output->modeSize()), output);
Q_EMIT te->device()->touchDown(te->id(), globalPos, te->time(), te->device());
@ -369,13 +370,13 @@ void Connection::processEvents()
#endif
}
case LIBINPUT_EVENT_TOUCH_UP: {
TouchEvent *te = static_cast<TouchEvent *>(event.data());
TouchEvent *te = static_cast<TouchEvent *>(event.get());
Q_EMIT te->device()->touchUp(te->id(), te->time(), te->device());
break;
}
case LIBINPUT_EVENT_TOUCH_MOTION: {
#ifndef KWIN_BUILD_TESTING
TouchEvent *te = static_cast<TouchEvent *>(event.data());
TouchEvent *te = static_cast<TouchEvent *>(event.get());
const auto *output = te->device()->output();
const QPointF globalPos = devicePointToGlobalPosition(te->absolutePos(output->modeSize()), output);
Q_EMIT te->device()->touchMotion(te->id(), globalPos, te->time(), te->device());
@ -391,17 +392,17 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: {
PinchGestureEvent *pe = static_cast<PinchGestureEvent *>(event.data());
PinchGestureEvent *pe = static_cast<PinchGestureEvent *>(event.get());
Q_EMIT pe->device()->pinchGestureBegin(pe->fingerCount(), pe->time(), pe->device());
break;
}
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: {
PinchGestureEvent *pe = static_cast<PinchGestureEvent *>(event.data());
PinchGestureEvent *pe = static_cast<PinchGestureEvent *>(event.get());
Q_EMIT pe->device()->pinchGestureUpdate(pe->scale(), pe->angleDelta(), pe->delta(), pe->time(), pe->device());
break;
}
case LIBINPUT_EVENT_GESTURE_PINCH_END: {
PinchGestureEvent *pe = static_cast<PinchGestureEvent *>(event.data());
PinchGestureEvent *pe = static_cast<PinchGestureEvent *>(event.get());
if (pe->isCancelled()) {
Q_EMIT pe->device()->pinchGestureCancelled(pe->time(), pe->device());
} else {
@ -410,17 +411,17 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: {
SwipeGestureEvent *se = static_cast<SwipeGestureEvent *>(event.data());
SwipeGestureEvent *se = static_cast<SwipeGestureEvent *>(event.get());
Q_EMIT se->device()->swipeGestureBegin(se->fingerCount(), se->time(), se->device());
break;
}
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: {
SwipeGestureEvent *se = static_cast<SwipeGestureEvent *>(event.data());
SwipeGestureEvent *se = static_cast<SwipeGestureEvent *>(event.get());
Q_EMIT se->device()->swipeGestureUpdate(se->delta(), se->time(), se->device());
break;
}
case LIBINPUT_EVENT_GESTURE_SWIPE_END: {
SwipeGestureEvent *se = static_cast<SwipeGestureEvent *>(event.data());
SwipeGestureEvent *se = static_cast<SwipeGestureEvent *>(event.get());
if (se->isCancelled()) {
Q_EMIT se->device()->swipeGestureCancelled(se->time(), se->device());
} else {
@ -429,12 +430,12 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: {
HoldGestureEvent *he = static_cast<HoldGestureEvent *>(event.data());
HoldGestureEvent *he = static_cast<HoldGestureEvent *>(event.get());
Q_EMIT he->device()->holdGestureBegin(he->fingerCount(), he->time(), he->device());
break;
}
case LIBINPUT_EVENT_GESTURE_HOLD_END: {
HoldGestureEvent *he = static_cast<HoldGestureEvent *>(event.data());
HoldGestureEvent *he = static_cast<HoldGestureEvent *>(event.get());
if (he->isCancelled()) {
Q_EMIT he->device()->holdGestureCancelled(he->time(), he->device());
} else {
@ -443,7 +444,7 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_SWITCH_TOGGLE: {
SwitchEvent *se = static_cast<SwitchEvent *>(event.data());
SwitchEvent *se = static_cast<SwitchEvent *>(event.get());
switch (se->state()) {
case SwitchEvent::State::Off:
Q_EMIT se->device()->switchToggledOff(se->time(), se->timeMicroseconds(), se->device());
@ -459,7 +460,7 @@ void Connection::processEvents()
case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
case LIBINPUT_EVENT_TABLET_TOOL_TIP: {
auto *tte = static_cast<TabletToolEvent *>(event.data());
auto *tte = static_cast<TabletToolEvent *>(event.get());
KWin::InputRedirection::TabletEventType tabletEventType;
switch (event->type()) {
@ -498,21 +499,21 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: {
auto *tabletEvent = static_cast<TabletToolButtonEvent *>(event.data());
auto *tabletEvent = static_cast<TabletToolButtonEvent *>(event.get());
Q_EMIT event->device()->tabletToolButtonEvent(tabletEvent->buttonId(),
tabletEvent->isButtonPressed(),
createTabletId(tabletEvent->tool(), event->device()->groupUserData()));
break;
}
case LIBINPUT_EVENT_TABLET_PAD_BUTTON: {
auto *tabletEvent = static_cast<TabletPadButtonEvent *>(event.data());
auto *tabletEvent = static_cast<TabletPadButtonEvent *>(event.get());
Q_EMIT event->device()->tabletPadButtonEvent(tabletEvent->buttonId(),
tabletEvent->isButtonPressed(),
{event->device()->groupUserData()});
break;
}
case LIBINPUT_EVENT_TABLET_PAD_RING: {
auto *tabletEvent = static_cast<TabletPadRingEvent *>(event.data());
auto *tabletEvent = static_cast<TabletPadRingEvent *>(event.get());
tabletEvent->position();
Q_EMIT event->device()->tabletPadRingEvent(tabletEvent->number(),
tabletEvent->position(),
@ -521,7 +522,7 @@ void Connection::processEvents()
break;
}
case LIBINPUT_EVENT_TABLET_PAD_STRIP: {
auto *tabletEvent = static_cast<TabletPadStripEvent *>(event.data());
auto *tabletEvent = static_cast<TabletPadStripEvent *>(event.get());
Q_EMIT event->device()->tabletPadStripEvent(tabletEvent->number(),
tabletEvent->position(),
tabletEvent->source() == LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER,

View file

@ -19,6 +19,7 @@
#include <QSize>
#include <QStringList>
#include <QVector>
#include <deque>
class QSocketNotifier;
class QThread;
@ -69,7 +70,7 @@ private:
Context *m_input;
QSocketNotifier *m_notifier;
QRecursiveMutex m_mutex;
QVector<Event *> m_eventQueue;
std::deque<std::unique_ptr<Event>> m_eventQueue;
QVector<Device *> m_devices;
KSharedConfigPtr m_config;

View file

@ -146,7 +146,7 @@ void Context::closeRestricted(int fd)
kwinApp()->platform()->session()->closeRestricted(fd);
}
Event *Context::event()
std::unique_ptr<Event> Context::event()
{
return Event::create(libinput_get_event(m_libinput));
}

View file

@ -10,6 +10,7 @@
#define KWIN_LIBINPUT_CONTEXT_H
#include <libinput.h>
#include <memory>
namespace KWin
{
@ -51,10 +52,9 @@ public:
}
/**
* Gets the next event, if there is no new event @c null is returned.
* The caller takes ownership of the returned pointer.
* Gets the next event, if there is no new event @c nullptr is returned
*/
Event *event();
std::unique_ptr<Event> event();
static int openRestrictedCallback(const char *path, int flags, void *user_data);
static void closeRestrictedCallBack(int fd, void *user_data);

View file

@ -16,7 +16,7 @@ namespace KWin
namespace LibInput
{
Event *Event::create(libinput_event *event)
std::unique_ptr<Event> Event::create(libinput_event *event)
{
if (!event) {
return nullptr;
@ -26,45 +26,45 @@ Event *Event::create(libinput_event *event)
// TODO: add device notify events
switch (t) {
case LIBINPUT_EVENT_KEYBOARD_KEY:
return new KeyEvent(event);
return std::make_unique<KeyEvent>(event);
case LIBINPUT_EVENT_POINTER_AXIS:
case LIBINPUT_EVENT_POINTER_BUTTON:
case LIBINPUT_EVENT_POINTER_MOTION:
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
return new PointerEvent(event, t);
return std::make_unique<PointerEvent>(event, t);
case LIBINPUT_EVENT_TOUCH_DOWN:
case LIBINPUT_EVENT_TOUCH_UP:
case LIBINPUT_EVENT_TOUCH_MOTION:
case LIBINPUT_EVENT_TOUCH_CANCEL:
case LIBINPUT_EVENT_TOUCH_FRAME:
return new TouchEvent(event, t);
return std::make_unique<TouchEvent>(event, t);
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
case LIBINPUT_EVENT_GESTURE_SWIPE_END:
return new SwipeGestureEvent(event, t);
return std::make_unique<SwipeGestureEvent>(event, t);
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
case LIBINPUT_EVENT_GESTURE_PINCH_END:
return new PinchGestureEvent(event, t);
return std::make_unique<PinchGestureEvent>(event, t);
case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN:
case LIBINPUT_EVENT_GESTURE_HOLD_END:
return new HoldGestureEvent(event, t);
return std::make_unique<HoldGestureEvent>(event, t);
case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
case LIBINPUT_EVENT_TABLET_TOOL_TIP:
return new TabletToolEvent(event, t);
return std::make_unique<TabletToolEvent>(event, t);
case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
return new TabletToolButtonEvent(event, t);
return std::make_unique<TabletToolButtonEvent>(event, t);
case LIBINPUT_EVENT_TABLET_PAD_RING:
return new TabletPadRingEvent(event, t);
return std::make_unique<TabletPadRingEvent>(event, t);
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
return new TabletPadStripEvent(event, t);
return std::make_unique<TabletPadStripEvent>(event, t);
case LIBINPUT_EVENT_TABLET_PAD_BUTTON:
return new TabletPadButtonEvent(event, t);
return std::make_unique<TabletPadButtonEvent>(event, t);
case LIBINPUT_EVENT_SWITCH_TOGGLE:
return new SwitchEvent(event, t);
return std::make_unique<SwitchEvent>(event, t);
default:
return new Event(event, t);
return std::unique_ptr<Event>{new Event(event, t)};
}
}

View file

@ -38,7 +38,7 @@ public:
return m_event;
}
static Event *create(libinput_event *event);
static std::unique_ptr<Event> create(libinput_event *event);
protected:
Event(libinput_event *event, libinput_event_type type);

View file

@ -570,8 +570,8 @@ static inline int bitCount(uint32_t mask)
const FBConfigInfo &GlxBackend::infoForVisual(xcb_visualid_t visual)
{
auto it = m_fbconfigHash.find(visual);
if (it != m_fbconfigHash.cend()) {
auto it = m_fbconfigHash.constFind(visual);
if (it != m_fbconfigHash.constEnd()) {
return *it;
}
m_fbconfigHash[visual] = FBConfigInfo{

View file

@ -22,8 +22,6 @@
#include <kwingltexture_p.h>
#include <QHash>
#include <map>
#include <memory>
namespace KWin