From a38a44cb2a1199c6f23efc72c032203213434697 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 1 Jun 2022 12:13:34 +0200 Subject: [PATCH] libinput: use std::unique_ptr for events --- autotests/libinput/gesture_event_test.cpp | 28 +++++----- autotests/libinput/key_event_test.cpp | 12 ++--- autotests/libinput/pointer_event_test.cpp | 24 ++++----- autotests/libinput/switch_event_test.cpp | 4 +- autotests/libinput/touch_event_test.cpp | 14 ++--- src/backends/libinput/connection.cpp | 59 +++++++++++----------- src/backends/libinput/connection.h | 3 +- src/backends/libinput/context.cpp | 2 +- src/backends/libinput/context.h | 6 +-- src/backends/libinput/events.cpp | 28 +++++----- src/backends/libinput/events.h | 2 +- src/backends/x11/standalone/glxbackend.cpp | 4 +- src/backends/x11/standalone/glxbackend.h | 2 - 13 files changed, 94 insertions(+), 94 deletions(-) diff --git a/autotests/libinput/gesture_event_test.cpp b/autotests/libinput/gesture_event_test.cpp index c3b080d5cb..3657ce57b4 100644 --- a/autotests/libinput/gesture_event_test.cpp +++ b/autotests/libinput/gesture_event_test.cpp @@ -81,15 +81,15 @@ void TestLibinputGestureEvent::testType() gestureEvent->type = type; gestureEvent->device = m_nativeDevice; - QScopedPointer event(Event::create(gestureEvent)); + std::unique_ptr 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(event.data())); - QCOMPARE((libinput_event_gesture *)(*dynamic_cast(event.data())), gestureEvent); + QVERIFY(dynamic_cast(event.get())); + QCOMPARE((libinput_event_gesture *)(*dynamic_cast(event.get())), gestureEvent); } void TestLibinputGestureEvent::testStart_data() @@ -109,15 +109,15 @@ void TestLibinputGestureEvent::testStart() gestureEvent->fingerCount = 3; gestureEvent->time = 100u; - QScopedPointer event(Event::create(gestureEvent)); - auto ge = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(gestureEvent)); + auto ge = dynamic_cast(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(event.data()); + auto pe = dynamic_cast(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::create(gestureEvent)); - auto se = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(gestureEvent)); + auto se = dynamic_cast(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::create(gestureEvent)); - auto pe = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(gestureEvent)); + auto pe = dynamic_cast(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::create(gestureEvent)); - auto ge = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(gestureEvent)); + auto ge = dynamic_cast(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(event.data()); + auto pe = dynamic_cast(event.get()); QCOMPARE(pe->scale(), gestureEvent->scale); QCOMPARE(pe->angleDelta(), 0.0); } diff --git a/autotests/libinput/key_event_test.cpp b/autotests/libinput/key_event_test.cpp index 47b8d8fc1b..0b8e2c38c2 100644 --- a/autotests/libinput/key_event_test.cpp +++ b/autotests/libinput/key_event_test.cpp @@ -57,15 +57,15 @@ void TestLibinputKeyEvent::testCreate() libinput_event_keyboard *keyEvent = new libinput_event_keyboard; keyEvent->device = m_nativeDevice; - QScopedPointer event(Event::create(keyEvent)); + std::unique_ptr 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(event.data())); - QCOMPARE((libinput_event_keyboard *)(*dynamic_cast(event.data())), keyEvent); + QVERIFY(dynamic_cast(event.get())); + QCOMPARE((libinput_event_keyboard *)(*dynamic_cast(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::create(keyEvent)); - auto ke = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(keyEvent)); + auto ke = dynamic_cast(event.get()); QVERIFY(ke); QTEST(ke->state(), "expectedKeyState"); QCOMPARE(ke->key(), key); diff --git a/autotests/libinput/pointer_event_test.cpp b/autotests/libinput/pointer_event_test.cpp index 14d3d8439a..bbc73d0dca 100644 --- a/autotests/libinput/pointer_event_test.cpp +++ b/autotests/libinput/pointer_event_test.cpp @@ -77,15 +77,15 @@ void TestLibinputPointerEvent::testType() pointerEvent->type = type; pointerEvent->device = m_nativeDevice; - QScopedPointer event(Event::create(pointerEvent)); + std::unique_ptr 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(event.data())); - QCOMPARE((libinput_event_pointer *)(*dynamic_cast(event.data())), pointerEvent); + QVERIFY(dynamic_cast(event.get())); + QCOMPARE((libinput_event_pointer *)(*dynamic_cast(event.get())), pointerEvent); } void TestLibinputPointerEvent::testButton_data() @@ -112,8 +112,8 @@ void TestLibinputPointerEvent::testButton() QFETCH(quint32, time); pointerEvent->time = time; - QScopedPointer event(Event::create(pointerEvent)); - auto pe = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(pointerEvent)); + auto pe = dynamic_cast(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::create(pointerEvent)); - auto pe = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(pointerEvent)); + auto pe = dynamic_cast(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::create(pointerEvent)); - auto pe = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(pointerEvent)); + auto pe = dynamic_cast(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::create(pointerEvent)); - auto pe = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(pointerEvent)); + auto pe = dynamic_cast(event.get()); QVERIFY(pe); QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); QCOMPARE(pe->time(), 500u); diff --git a/autotests/libinput/switch_event_test.cpp b/autotests/libinput/switch_event_test.cpp index 2963d0ab95..2d7a150b33 100644 --- a/autotests/libinput/switch_event_test.cpp +++ b/autotests/libinput/switch_event_test.cpp @@ -74,8 +74,8 @@ void TestLibinputSwitchEvent::testToggled() nativeEvent->time = 23; nativeEvent->timeMicroseconds = 23456789; - QScopedPointer event(Event::create(nativeEvent)); - auto se = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(nativeEvent)); + auto se = dynamic_cast(event.get()); QVERIFY(se); QCOMPARE(se->device(), m_device.get()); QCOMPARE(se->nativeDevice(), m_nativeDevice.get()); diff --git a/autotests/libinput/touch_event_test.cpp b/autotests/libinput/touch_event_test.cpp index cc7b628e46..73d88ae06c 100644 --- a/autotests/libinput/touch_event_test.cpp +++ b/autotests/libinput/touch_event_test.cpp @@ -74,18 +74,18 @@ void TestLibinputTouchEvent::testType() touchEvent->device = m_nativeDevice; touchEvent->slot = 0; - QScopedPointer event(Event::create(touchEvent)); + std::unique_ptr 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(event.data())); - QCOMPARE((libinput_event_touch *)(*dynamic_cast(event.data())), touchEvent); + QVERIFY(dynamic_cast(event.get())); + QCOMPARE((libinput_event_touch *)(*dynamic_cast(event.get())), touchEvent); QFETCH(bool, hasId); if (hasId) { - QCOMPARE(dynamic_cast(event.data())->id(), 0); + QCOMPARE(dynamic_cast(event.get())->id(), 0); } } @@ -107,8 +107,8 @@ void TestLibinputTouchEvent::testAbsoluteMotion() touchEvent->time = 500u; touchEvent->slot = 1; - QScopedPointer event(Event::create(touchEvent)); - auto te = dynamic_cast(event.data()); + std::unique_ptr event(Event::create(touchEvent)); + auto te = dynamic_cast(event.get()); QVERIFY(te); QCOMPARE(te->type(), type); QCOMPARE(te->time(), 500u); diff --git a/src/backends/libinput/connection.cpp b/src/backends/libinput/connection.cpp index 37eb23fd90..96996fdb56 100644 --- a/src/backends/libinput/connection.cpp +++ b/src/backends/libinput/connection.cpp @@ -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 = 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(m_eventQueue.takeFirst()); + while (m_eventQueue.size() != 0) { + std::unique_ptr 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(event.data()); + KeyEvent *ke = static_cast(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(event.data()); + PointerEvent *pe = static_cast(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(event.data()); + PointerEvent *pe = static_cast(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(event.data()); + PointerEvent *pe = static_cast(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 p(static_cast(*it)); + std::unique_ptr p{static_cast(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(event.data()); + PointerEvent *pe = static_cast(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(event.data()); + TouchEvent *te = static_cast(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(event.data()); + TouchEvent *te = static_cast(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(event.data()); + TouchEvent *te = static_cast(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(event.data()); + PinchGestureEvent *pe = static_cast(event.get()); Q_EMIT pe->device()->pinchGestureBegin(pe->fingerCount(), pe->time(), pe->device()); break; } case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: { - PinchGestureEvent *pe = static_cast(event.data()); + PinchGestureEvent *pe = static_cast(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(event.data()); + PinchGestureEvent *pe = static_cast(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(event.data()); + SwipeGestureEvent *se = static_cast(event.get()); Q_EMIT se->device()->swipeGestureBegin(se->fingerCount(), se->time(), se->device()); break; } case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: { - SwipeGestureEvent *se = static_cast(event.data()); + SwipeGestureEvent *se = static_cast(event.get()); Q_EMIT se->device()->swipeGestureUpdate(se->delta(), se->time(), se->device()); break; } case LIBINPUT_EVENT_GESTURE_SWIPE_END: { - SwipeGestureEvent *se = static_cast(event.data()); + SwipeGestureEvent *se = static_cast(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(event.data()); + HoldGestureEvent *he = static_cast(event.get()); Q_EMIT he->device()->holdGestureBegin(he->fingerCount(), he->time(), he->device()); break; } case LIBINPUT_EVENT_GESTURE_HOLD_END: { - HoldGestureEvent *he = static_cast(event.data()); + HoldGestureEvent *he = static_cast(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(event.data()); + SwitchEvent *se = static_cast(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(event.data()); + auto *tte = static_cast(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(event.data()); + auto *tabletEvent = static_cast(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(event.data()); + auto *tabletEvent = static_cast(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(event.data()); + auto *tabletEvent = static_cast(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(event.data()); + auto *tabletEvent = static_cast(event.get()); Q_EMIT event->device()->tabletPadStripEvent(tabletEvent->number(), tabletEvent->position(), tabletEvent->source() == LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER, diff --git a/src/backends/libinput/connection.h b/src/backends/libinput/connection.h index c1cf4f6005..1dfec939c1 100644 --- a/src/backends/libinput/connection.h +++ b/src/backends/libinput/connection.h @@ -19,6 +19,7 @@ #include #include #include +#include class QSocketNotifier; class QThread; @@ -69,7 +70,7 @@ private: Context *m_input; QSocketNotifier *m_notifier; QRecursiveMutex m_mutex; - QVector m_eventQueue; + std::deque> m_eventQueue; QVector m_devices; KSharedConfigPtr m_config; diff --git a/src/backends/libinput/context.cpp b/src/backends/libinput/context.cpp index 1c41091d48..998113a721 100644 --- a/src/backends/libinput/context.cpp +++ b/src/backends/libinput/context.cpp @@ -146,7 +146,7 @@ void Context::closeRestricted(int fd) kwinApp()->platform()->session()->closeRestricted(fd); } -Event *Context::event() +std::unique_ptr Context::event() { return Event::create(libinput_get_event(m_libinput)); } diff --git a/src/backends/libinput/context.h b/src/backends/libinput/context.h index 72e96fd805..efcb231cf3 100644 --- a/src/backends/libinput/context.h +++ b/src/backends/libinput/context.h @@ -10,6 +10,7 @@ #define KWIN_LIBINPUT_CONTEXT_H #include +#include 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(); static int openRestrictedCallback(const char *path, int flags, void *user_data); static void closeRestrictedCallBack(int fd, void *user_data); diff --git a/src/backends/libinput/events.cpp b/src/backends/libinput/events.cpp index 2f637ba88c..9de85ae429 100644 --- a/src/backends/libinput/events.cpp +++ b/src/backends/libinput/events.cpp @@ -16,7 +16,7 @@ namespace KWin namespace LibInput { -Event *Event::create(libinput_event *event) +std::unique_ptr 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(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(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(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(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(event, t); case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: case LIBINPUT_EVENT_GESTURE_HOLD_END: - return new HoldGestureEvent(event, t); + return std::make_unique(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(event, t); case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: - return new TabletToolButtonEvent(event, t); + return std::make_unique(event, t); case LIBINPUT_EVENT_TABLET_PAD_RING: - return new TabletPadRingEvent(event, t); + return std::make_unique(event, t); case LIBINPUT_EVENT_TABLET_PAD_STRIP: - return new TabletPadStripEvent(event, t); + return std::make_unique(event, t); case LIBINPUT_EVENT_TABLET_PAD_BUTTON: - return new TabletPadButtonEvent(event, t); + return std::make_unique(event, t); case LIBINPUT_EVENT_SWITCH_TOGGLE: - return new SwitchEvent(event, t); + return std::make_unique(event, t); default: - return new Event(event, t); + return std::unique_ptr{new Event(event, t)}; } } diff --git a/src/backends/libinput/events.h b/src/backends/libinput/events.h index 93d5cd4dcd..6f21b7b964 100644 --- a/src/backends/libinput/events.h +++ b/src/backends/libinput/events.h @@ -38,7 +38,7 @@ public: return m_event; } - static Event *create(libinput_event *event); + static std::unique_ptr create(libinput_event *event); protected: Event(libinput_event *event, libinput_event_type type); diff --git a/src/backends/x11/standalone/glxbackend.cpp b/src/backends/x11/standalone/glxbackend.cpp index ac80835979..9c0006c353 100644 --- a/src/backends/x11/standalone/glxbackend.cpp +++ b/src/backends/x11/standalone/glxbackend.cpp @@ -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{ diff --git a/src/backends/x11/standalone/glxbackend.h b/src/backends/x11/standalone/glxbackend.h index 6452454d87..8656d6a78c 100644 --- a/src/backends/x11/standalone/glxbackend.h +++ b/src/backends/x11/standalone/glxbackend.h @@ -22,8 +22,6 @@ #include #include - -#include #include namespace KWin