From 31b9f34d9b1009b9f267393d8cf8a21d0ecd0883 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 29 Sep 2021 09:38:10 +0300 Subject: [PATCH] libinput: Port to AbstractOutput CCBUG: 443088 --- autotests/libinput/device_test.cpp | 10 ----- src/libinput/connection.cpp | 64 +++++++++++++++--------------- src/libinput/device.cpp | 11 +++++ src/libinput/device.h | 22 ++++------ 4 files changed, 49 insertions(+), 58 deletions(-) diff --git a/autotests/libinput/device_test.cpp b/autotests/libinput/device_test.cpp index ccf1e996fb..99a3d0faf1 100644 --- a/autotests/libinput/device_test.cpp +++ b/autotests/libinput/device_test.cpp @@ -154,7 +154,6 @@ private Q_SLOTS: void testLoadLmrTapButtonMap(); void testLoadLeftHanded_data(); void testLoadLeftHanded(); - void testScreenId(); void testOrientation_data(); void testOrientation(); void testCalibrationWithDefault(); @@ -2324,15 +2323,6 @@ void TestLibinputDevice::testLoadLmrTapButtonMap() } } -void TestLibinputDevice::testScreenId() -{ - libinput_device device; - Device d(&device); - QCOMPARE(d.screenId(), 0); - d.setScreenId(1); - QCOMPARE(d.screenId(), 1); -} - void TestLibinputDevice::testOrientation_data() { QTest::addColumn("orientation"); diff --git a/src/libinput/connection.cpp b/src/libinput/connection.cpp index fa646b26e4..e4c6cdb94c 100644 --- a/src/libinput/connection.cpp +++ b/src/libinput/connection.cpp @@ -18,7 +18,6 @@ #include "platform.h" #include "workspace.h" #include "abstract_client.h" -#include "screens.h" #endif #include "input_event.h" @@ -447,8 +446,7 @@ void Connection::processEvents() case LIBINPUT_EVENT_TOUCH_DOWN: { #ifndef KWIN_BUILD_TESTING TouchEvent *te = static_cast(event.data()); - const auto *output = static_cast( - kwinApp()->platform()->enabledOutputs()[te->device()->screenId()]); + const auto *output = static_cast(te->device()->output()); const QPointF globalPos = devicePointToGlobalPosition(te->absolutePos(output->modeSize()), output); @@ -464,8 +462,7 @@ void Connection::processEvents() case LIBINPUT_EVENT_TOUCH_MOTION: { #ifndef KWIN_BUILD_TESTING TouchEvent *te = static_cast(event.data()); - const auto *output = static_cast( - kwinApp()->platform()->enabledOutputs()[te->device()->screenId()]); + const auto *output = static_cast(te->device()->output()); const QPointF globalPos = devicePointToGlobalPosition(te->absolutePos(output->modeSize()), output); @@ -555,8 +552,7 @@ void Connection::processEvents() if (workspace()) { #ifndef KWIN_BUILD_TESTING auto client = workspace()->activeClient(); - const auto *output = static_cast( - kwinApp()->platform()->enabledOutputs()[client ? client->screen() : tte->device()->screenId()]); + const auto *output = static_cast(client ? client->output() : tte->device()->output()); const QPointF globalPos = devicePointToGlobalPosition(tte->transformedPosition(output->modeSize()), output); @@ -647,60 +643,62 @@ void Connection::applyScreenToDevice(Device *device) if (!device->isTouch()) { return; } - int id = -1; + + AbstractOutput *deviceOutput = nullptr; + const QVector outputs = kwinApp()->platform()->enabledOutputs(); // let's try to find a screen for it - if (screens()->count() == 1) { - id = 0; + if (outputs.count() == 1) { + deviceOutput = outputs.constFirst(); } - if (id == -1 && !device->outputName().isEmpty()) { + if (!deviceOutput && !device->outputName().isEmpty()) { // we have an output name, try to find a screen with matching name - for (int i = 0; i < screens()->count(); i++) { - if (screens()->name(i) == device->outputName()) { - id = i; + for (AbstractOutput *output : outputs) { + if (output->name() == device->outputName()) { + deviceOutput = output; break; } } } - if (id == -1) { + if (!deviceOutput) { // do we have an internal screen? - int internalId = -1; - for (int i = 0; i < screens()->count(); i++) { - if (screens()->isInternal(i)) { - internalId = i; + AbstractOutput *internalOutput = nullptr; + for (AbstractOutput *output : outputs) { + if (output->isInternal()) { + internalOutput = output; break; } } - auto testScreenMatches = [device] (int id) { + auto testScreenMatches = [device] (const AbstractOutput *output) { const auto &size = device->size(); - const auto &screenSize = screens()->physicalSize(id); + const auto &screenSize = output->physicalSize(); return std::round(size.width()) == std::round(screenSize.width()) && std::round(size.height()) == std::round(screenSize.height()); }; - if (internalId != -1 && testScreenMatches(internalId)) { - id = internalId; + if (internalOutput && testScreenMatches(internalOutput)) { + deviceOutput = internalOutput; } // let's compare all screens for size - for (int i = 0; i < screens()->count(); i++) { - if (testScreenMatches(i)) { - id = i; + for (AbstractOutput *output : outputs) { + if (testScreenMatches(output)) { + deviceOutput = output; break; } } - if (id == -1) { + if (!deviceOutput) { // still not found - if (internalId != -1) { + if (internalOutput) { // we have an internal id, so let's use that - id = internalId; - } else { + deviceOutput = internalOutput; + } else if (!outputs.isEmpty()) { // just take first screen, we have no clue - id = 0; + deviceOutput = outputs.constFirst(); } } } - device->setScreenId(id); + device->setOutput(deviceOutput); // TODO: this is currently non-functional even on DRM. Needs orientation() override there. - device->setOrientation(screens()->orientation(id)); + device->setOrientation(Qt::PrimaryOrientation); #else Q_UNUSED(device) #endif diff --git a/src/libinput/device.cpp b/src/libinput/device.cpp index efd50f724c..b2fd5c0e16 100644 --- a/src/libinput/device.cpp +++ b/src/libinput/device.cpp @@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "device.h" +#include "abstract_output.h" #include @@ -544,5 +545,15 @@ void Device::setOrientation(Qt::ScreenOrientation orientation) libinput_device_config_calibration_set_matrix(m_device, m); } +AbstractOutput *Device::output() const +{ + return m_output; +} + +void Device::setOutput(AbstractOutput *output) +{ + m_output = output; +} + } } diff --git a/src/libinput/device.h b/src/libinput/device.h index 380b12b8b7..6dad013b9b 100644 --- a/src/libinput/device.h +++ b/src/libinput/device.h @@ -15,6 +15,7 @@ #include #include +#include #include #include #include "kwin_export.h" @@ -23,6 +24,8 @@ struct libinput_device; namespace KWin { +class AbstractOutput; + namespace LibInput { enum class ConfigKey; @@ -438,20 +441,6 @@ public: m_config = config; } - /** - * The id of the screen in KWin identifiers. Set from KWin through setScreenId. - */ - int screenId() const { - return m_screenId; - } - - /** - * Sets the KWin screen id for the device - */ - void setScreenId(int screenId) { - m_screenId = screenId; - } - void setOrientation(Qt::ScreenOrientation orientation); /** @@ -476,6 +465,9 @@ public: void *groupUserData() const; + AbstractOutput *output() const; + void setOutput(AbstractOutput *output); + /** * All created Devices */ @@ -570,7 +562,7 @@ private: KConfigGroup m_config; bool m_loading = false; - int m_screenId = 0; + QPointer m_output; Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; QMatrix4x4 m_defaultCalibrationMatrix; quint32 m_supportedClickMethods;