From 70b9c3651aa5d6acd2bca87dee76e23197de1a08 Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Tue, 16 Apr 2019 00:31:12 +0300 Subject: [PATCH] Refactor getters in OutputScreens Summary: kdelibs coding style recommends to avoid abbreviations, i.e. variable names like compMngr, errStr, and so on are bad. Unfortunately, all getters in OutputScreens don't follow that recommendation. In general, we could address this issue by renaming enOuts but there is a bit simpler approach to implement most of those getters. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: apol, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D20588 --- outputscreens.cpp | 67 ++++++++++++++++++++++------------------------- outputscreens.h | 5 ++++ 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/outputscreens.cpp b/outputscreens.cpp index 5c56a20897..4ac6a31fc4 100644 --- a/outputscreens.cpp +++ b/outputscreens.cpp @@ -41,74 +41,66 @@ void OutputScreens::init() QString OutputScreens::name(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return Screens::name(screen); + if (AbstractOutput *output = findOutput(screen)) { + return output->name(); } - return enOuts.at(screen)->name(); + return QString(); } bool OutputScreens::isInternal(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return false; + if (AbstractOutput *output = findOutput(screen)) { + return output->isInternal(); } - return enOuts.at(screen)->isInternal(); + return false; } QRect OutputScreens::geometry(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return QRect(); + if (AbstractOutput *output = findOutput(screen)) { + return output->geometry(); } - return enOuts.at(screen)->geometry(); + return QRect(); } QSize OutputScreens::size(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return QSize(); + if (AbstractOutput *output = findOutput(screen)) { + return output->geometry().size(); } - return enOuts.at(screen)->geometry().size(); + return QSize(); } qreal OutputScreens::scale(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return 1; + if (AbstractOutput *output = findOutput(screen)) { + return output->scale(); } - return enOuts.at(screen)->scale(); + return 1.0; } QSizeF OutputScreens::physicalSize(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return Screens::physicalSize(screen); + if (AbstractOutput *output = findOutput(screen)) { + return output->physicalSize(); } - return enOuts.at(screen)->physicalSize(); + return QSizeF(); } float OutputScreens::refreshRate(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return Screens::refreshRate(screen); + if (AbstractOutput *output = findOutput(screen)) { + return output->refreshRate() / 1000.0; } - return enOuts.at(screen)->refreshRate() / 1000.0f; + return 60.0; } Qt::ScreenOrientation OutputScreens::orientation(int screen) const { - const auto enOuts = m_platform->enabledOutputs(); - if (screen >= enOuts.size()) { - return Qt::PrimaryOrientation; + if (AbstractOutput *output = findOutput(screen)) { + return output->orientation(); } - return enOuts.at(screen)->orientation(); + return Qt::PrimaryOrientation; } void OutputScreens::updateCount() @@ -120,9 +112,9 @@ int OutputScreens::number(const QPoint &pos) const { int bestScreen = 0; int minDistance = INT_MAX; - const auto enOuts = m_platform->enabledOutputs(); - for (int i = 0; i < enOuts.size(); ++i) { - const QRect &geo = enOuts.at(i)->geometry(); + const auto outputs = m_platform->enabledOutputs(); + for (int i = 0; i < outputs.size(); ++i) { + const QRect &geo = outputs[i]->geometry(); if (geo.contains(pos)) { return i; } @@ -138,4 +130,9 @@ int OutputScreens::number(const QPoint &pos) const return bestScreen; } +AbstractOutput *OutputScreens::findOutput(int screen) const +{ + return m_platform->enabledOutputs().value(screen); +} + } // namespace diff --git a/outputscreens.h b/outputscreens.h index 56f8f4c0dc..55bf2a975b 100644 --- a/outputscreens.h +++ b/outputscreens.h @@ -25,6 +25,8 @@ along with this program. If not, see . namespace KWin { +class AbstractOutput; + /** * @brief Implementation for backends with Outputs **/ @@ -49,6 +51,9 @@ public: protected: Platform *m_platform; + +private: + AbstractOutput *findOutput(int screen) const; }; }