Remove QPointer from function prototypes in some input code

As it was pointed out in 6acf35e4cc, it is
better to return raw pointers than qpointers because returning a qpointer
is equivalent to constructing a new one.
This commit is contained in:
Vlad Zahorodnii 2021-01-28 16:45:57 +02:00
parent a78754b695
commit 3788a8285d
4 changed files with 32 additions and 26 deletions

View file

@ -181,7 +181,7 @@ void DecorationInputTest::testAxis()
quint32 timestamp = 1;
MOTION(QPoint(c->frameGeometry().center().x(), c->clientPos().y() / 2));
QVERIFY(!input()->pointer()->decoration().isNull());
QVERIFY(input()->pointer()->decoration());
QCOMPARE(input()->pointer()->decoration()->decoration()->sectionUnderMouse(), Qt::TitleBarArea);
// TODO: mouse wheel direction looks wrong to me
@ -200,7 +200,7 @@ void DecorationInputTest::testAxis()
c->move(0, 0);
QFETCH(QPoint, decoPoint);
MOTION(decoPoint);
QVERIFY(!input()->pointer()->decoration().isNull());
QVERIFY(input()->pointer()->decoration());
QCOMPARE(input()->pointer()->decoration()->client(), c);
QTEST(input()->pointer()->decoration()->decoration()->sectionUnderMouse(), "expectedSection");
kwinApp()->platform()->pointerAxisVertical(5.0, timestamp++);
@ -246,7 +246,7 @@ void KWin::DecorationInputTest::testDoubleClick()
c->move(0, 0);
QFETCH(QPoint, decoPoint);
MOTION(decoPoint);
QVERIFY(!input()->pointer()->decoration().isNull());
QVERIFY(input()->pointer()->decoration());
QCOMPARE(input()->pointer()->decoration()->client(), c);
QTEST(input()->pointer()->decoration()->decoration()->sectionUnderMouse(), "expectedSection");
// double click
@ -300,7 +300,7 @@ void KWin::DecorationInputTest::testDoubleTap()
QFETCH(QPoint, decoPoint);
// double click
kwinApp()->platform()->touchDown(0, decoPoint, timestamp++);
QVERIFY(!input()->touch()->decoration().isNull());
QVERIFY(input()->touch()->decoration());
QCOMPARE(input()->touch()->decoration()->client(), c);
QTEST(input()->touch()->decoration()->decoration()->sectionUnderMouse(), "expectedSection");
kwinApp()->platform()->touchUp(0, timestamp++);

View file

@ -905,7 +905,7 @@ class InternalWindowEventFilter : public InputEventFilter {
event->globalPos(),
event->button(), event->buttons(), event->modifiers());
e.setAccepted(false);
QCoreApplication::sendEvent(internal.data(), &e);
QCoreApplication::sendEvent(internal, &e);
return e.isAccepted();
}
bool wheelEvent(QWheelEvent *event) override {
@ -933,7 +933,7 @@ class InternalWindowEventFilter : public InputEventFilter {
event->buttons(),
event->modifiers());
e.setAccepted(false);
QCoreApplication::sendEvent(internal.data(), &e);
QCoreApplication::sendEvent(internal, &e);
return e.isAccepted();
}
bool keyEvent(QKeyEvent *event) override {
@ -1009,11 +1009,11 @@ class InternalWindowEventFilter : public InputEventFilter {
m_lastLocalTouchPos = pos - QPointF(internal->x(), internal->y());
QEnterEvent enterEvent(m_lastLocalTouchPos, m_lastLocalTouchPos, pos);
QCoreApplication::sendEvent(internal.data(), &enterEvent);
QCoreApplication::sendEvent(internal, &enterEvent);
QMouseEvent e(QEvent::MouseButtonPress, m_lastLocalTouchPos, pos, Qt::LeftButton, Qt::LeftButton, input()->keyboardModifiers());
e.setAccepted(false);
QCoreApplication::sendEvent(internal.data(), &e);
QCoreApplication::sendEvent(internal, &e);
return true;
}
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
@ -1034,7 +1034,7 @@ class InternalWindowEventFilter : public InputEventFilter {
m_lastLocalTouchPos = pos - QPointF(internal->x(), internal->y());
QMouseEvent e(QEvent::MouseMove, m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton, Qt::LeftButton, input()->keyboardModifiers());
QCoreApplication::instance()->sendEvent(internal.data(), &e);
QCoreApplication::instance()->sendEvent(internal, &e);
return true;
}
bool touchUp(qint32 id, quint32 time) override {
@ -1054,10 +1054,10 @@ class InternalWindowEventFilter : public InputEventFilter {
// send mouse up
QMouseEvent e(QEvent::MouseButtonRelease, m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton, Qt::MouseButtons(), input()->keyboardModifiers());
e.setAccepted(false);
QCoreApplication::sendEvent(internal.data(), &e);
QCoreApplication::sendEvent(internal, &e);
QEvent leaveEvent(QEvent::Leave);
QCoreApplication::sendEvent(internal.data(), &leaveEvent);
QCoreApplication::sendEvent(internal, &leaveEvent);
m_lastGlobalTouchPos = QPointF();
m_lastLocalTouchPos = QPointF();
@ -1129,7 +1129,7 @@ public:
event->buttons(),
event->modifiers());
e.setAccepted(false);
QCoreApplication::sendEvent(decoration.data(), &e);
QCoreApplication::sendEvent(decoration, &e);
if (e.isAccepted()) {
return true;
}
@ -2712,7 +2712,7 @@ void InputDeviceHandler::setFocus(Toplevel *toplevel)
//TODO: call focusUpdate?
}
void InputDeviceHandler::setDecoration(QPointer<Decoration::DecoratedClientImpl> decoration)
void InputDeviceHandler::setDecoration(Decoration::DecoratedClientImpl *decoration)
{
auto oldDeco = m_focus.decoration;
m_focus.decoration = decoration;
@ -2841,6 +2841,16 @@ Toplevel *InputDeviceHandler::focus() const
return m_focus.focus.data();
}
Decoration::DecoratedClientImpl *InputDeviceHandler::decoration() const
{
return m_focus.decoration;
}
QWindow *InputDeviceHandler::internalWindow() const
{
return m_focus.internalWindow;
}
QWindow* InputDeviceHandler::findInternalWindow(const QPoint &pos) const
{
if (waylandServer()->isScreenLocked()) {

10
input.h
View file

@ -447,21 +447,17 @@ public:
* @brief The Decoration currently receiving events.
* @return decoration with pointer focus.
*/
QPointer<Decoration::DecoratedClientImpl> decoration() const {
return m_focus.decoration;
}
Decoration::DecoratedClientImpl *decoration() const;
/**
* @brief The internal window currently receiving events.
* @return QWindow with pointer focus.
*/
QPointer<QWindow> internalWindow() const {
return m_focus.internalWindow;
}
QWindow *internalWindow() const;
virtual QPointF position() const = 0;
void setFocus(Toplevel *toplevel);
void setDecoration(QPointer<Decoration::DecoratedClientImpl> decoration);
void setDecoration(Decoration::DecoratedClientImpl *decoration);
void setInternalWindow(QWindow *window);
Q_SIGNALS:

View file

@ -170,7 +170,7 @@ void PointerInputRedirection::updateToReset()
disconnect(m_internalWindowConnection);
m_internalWindowConnection = QMetaObject::Connection();
QEvent event(QEvent::Leave);
QCoreApplication::sendEvent(internalWindow().data(), &event);
QCoreApplication::sendEvent(internalWindow(), &event);
setInternalWindow(nullptr);
}
if (decoration()) {
@ -456,7 +456,7 @@ void PointerInputRedirection::cleanupInternalWindow(QWindow *old, QWindow *now)
}
if (now) {
m_internalWindowConnection = connect(internalWindow().data(), &QWindow::visibleChanged, this,
m_internalWindowConnection = connect(internalWindow(), &QWindow::visibleChanged, this,
[this] (bool visible) {
if (!visible) {
update();
@ -528,7 +528,7 @@ void PointerInputRedirection::focusUpdate(Toplevel *focusOld, Toplevel *focusNow
// enter internal window
const auto pos = at()->pos();
QEnterEvent enterEvent(pos, pos, m_pos);
QCoreApplication::sendEvent(internalWindow().data(), &enterEvent);
QCoreApplication::sendEvent(internalWindow(), &enterEvent);
}
auto seat = waylandServer()->seat();
@ -1025,7 +1025,7 @@ void CursorImage::updateDecoration()
{
disconnect(m_decorationConnection);
auto deco = m_pointer->decoration();
AbstractClient *c = deco.isNull() ? nullptr : deco->client();
AbstractClient *c = deco ? deco->client() : nullptr;
if (c) {
m_decorationConnection = connect(c, &AbstractClient::moveResizeCursorChanged, this, &CursorImage::updateDecorationCursor);
} else {
@ -1038,7 +1038,7 @@ void CursorImage::updateDecorationCursor()
{
m_decorationCursor = {};
auto deco = m_pointer->decoration();
if (AbstractClient *c = deco.isNull() ? nullptr : deco->client()) {
if (AbstractClient *c = deco ? deco->client() : nullptr) {
loadThemeCursor(c->cursor(), &m_decorationCursor);
if (m_currentSource == CursorSource::Decoration) {
emit changed();
@ -1341,7 +1341,7 @@ void CursorImage::reevaluteSource()
setSource(CursorSource::MoveResize);
return;
}
if (!m_pointer->decoration().isNull()) {
if (m_pointer->decoration()) {
setSource(CursorSource::Decoration);
return;
}