Introduce OutputScreens class
Summary: Lift high-level properties into new Screens child class for platform plugins using the Output class. Directly make DrmScreens a child class of OutputScreens. Test Plan: Manually and auto tests with 94%. Reviewers: #kwin Differential Revision: https://phabricator.kde.org/D11782
This commit is contained in:
parent
fe63e21f80
commit
3482378278
5 changed files with 198 additions and 119 deletions
|
@ -410,6 +410,7 @@ set(kwin_KDEINIT_SRCS
|
||||||
killwindow.cpp
|
killwindow.cpp
|
||||||
geometrytip.cpp
|
geometrytip.cpp
|
||||||
screens.cpp
|
screens.cpp
|
||||||
|
outputscreens.cpp
|
||||||
shadow.cpp
|
shadow.cpp
|
||||||
sm.cpp
|
sm.cpp
|
||||||
group.cpp
|
group.cpp
|
||||||
|
|
132
outputscreens.cpp
Normal file
132
outputscreens.cpp
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright 2018 Roman Gilg <subdiff@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*********************************************************************/
|
||||||
|
#include "outputscreens.h"
|
||||||
|
#include "platform.h"
|
||||||
|
#include "abstract_output.h"
|
||||||
|
|
||||||
|
namespace KWin
|
||||||
|
{
|
||||||
|
|
||||||
|
OutputScreens::OutputScreens(Platform *platform, QObject *parent)
|
||||||
|
: Screens(parent),
|
||||||
|
m_platform(platform)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputScreens::~OutputScreens() = default;
|
||||||
|
|
||||||
|
void OutputScreens::init()
|
||||||
|
{
|
||||||
|
updateCount();
|
||||||
|
KWin::Screens::init();
|
||||||
|
emit changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString OutputScreens::name(int screen) const
|
||||||
|
{
|
||||||
|
const auto enOuts = m_platform->enabledOutputs();
|
||||||
|
if (screen >= enOuts.size()) {
|
||||||
|
return Screens::name(screen);
|
||||||
|
}
|
||||||
|
return enOuts.at(screen)->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OutputScreens::isInternal(int screen) const
|
||||||
|
{
|
||||||
|
const auto enOuts = m_platform->enabledOutputs();
|
||||||
|
if (screen >= enOuts.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return enOuts.at(screen)->isInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
QRect OutputScreens::geometry(int screen) const
|
||||||
|
{
|
||||||
|
const auto enOuts = m_platform->enabledOutputs();
|
||||||
|
if (screen >= enOuts.size()) {
|
||||||
|
return QRect();
|
||||||
|
}
|
||||||
|
return enOuts.at(screen)->geometry();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize OutputScreens::size(int screen) const
|
||||||
|
{
|
||||||
|
const auto enOuts = m_platform->enabledOutputs();
|
||||||
|
if (screen >= enOuts.size()) {
|
||||||
|
return QSize();
|
||||||
|
}
|
||||||
|
return enOuts.at(screen)->geometry().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal OutputScreens::scale(int screen) const
|
||||||
|
{
|
||||||
|
const auto enOuts = m_platform->enabledOutputs();
|
||||||
|
if (screen >= enOuts.size()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return enOuts.at(screen)->scale();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSizeF OutputScreens::physicalSize(int screen) const
|
||||||
|
{
|
||||||
|
const auto enOuts = m_platform->enabledOutputs();
|
||||||
|
if (screen >= enOuts.size()) {
|
||||||
|
return Screens::physicalSize(screen);
|
||||||
|
}
|
||||||
|
return enOuts.at(screen)->physicalSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ScreenOrientation OutputScreens::orientation(int screen) const
|
||||||
|
{
|
||||||
|
const auto enOuts = m_platform->enabledOutputs();
|
||||||
|
if (screen >= enOuts.size()) {
|
||||||
|
return Qt::PrimaryOrientation;
|
||||||
|
}
|
||||||
|
return enOuts.at(screen)->orientation();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputScreens::updateCount()
|
||||||
|
{
|
||||||
|
setCount(m_platform->enabledOutputs().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
if (geo.contains(pos)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
int distance = QPoint(geo.topLeft() - pos).manhattanLength();
|
||||||
|
distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength());
|
||||||
|
distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength());
|
||||||
|
distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength());
|
||||||
|
if (distance < minDistance) {
|
||||||
|
minDistance = distance;
|
||||||
|
bestScreen = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
55
outputscreens.h
Normal file
55
outputscreens.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright 2018 Roman Gilg <subdiff@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*********************************************************************/
|
||||||
|
#ifndef KWIN_OUTPUTSCREENS_H
|
||||||
|
#define KWIN_OUTPUTSCREENS_H
|
||||||
|
|
||||||
|
#include "screens.h"
|
||||||
|
|
||||||
|
namespace KWin
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Implementation for backends with Outputs
|
||||||
|
**/
|
||||||
|
class KWIN_EXPORT OutputScreens : public Screens
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
OutputScreens(Platform *platform, QObject *parent = nullptr);
|
||||||
|
virtual ~OutputScreens();
|
||||||
|
|
||||||
|
void init() override;
|
||||||
|
QString name(int screen) const override;
|
||||||
|
bool isInternal(int screen) const;
|
||||||
|
QSizeF physicalSize(int screen) const;
|
||||||
|
QRect geometry(int screen) const override;
|
||||||
|
QSize size(int screen) const override;
|
||||||
|
qreal scale(int screen) const override;
|
||||||
|
Qt::ScreenOrientation orientation(int screen) const;
|
||||||
|
void updateCount() override;
|
||||||
|
int number(const QPoint &pos) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Platform *m_platform;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // KWIN_OUTPUTSCREENS_H
|
|
@ -25,7 +25,7 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
DrmScreens::DrmScreens(DrmBackend *backend, QObject *parent)
|
DrmScreens::DrmScreens(DrmBackend *backend, QObject *parent)
|
||||||
: Screens(parent)
|
: OutputScreens(backend, parent)
|
||||||
, m_backend(backend)
|
, m_backend(backend)
|
||||||
{
|
{
|
||||||
connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::updateCount);
|
connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::updateCount);
|
||||||
|
@ -34,120 +34,22 @@ DrmScreens::DrmScreens(DrmBackend *backend, QObject *parent)
|
||||||
|
|
||||||
DrmScreens::~DrmScreens() = default;
|
DrmScreens::~DrmScreens() = default;
|
||||||
|
|
||||||
void DrmScreens::init()
|
|
||||||
{
|
|
||||||
updateCount();
|
|
||||||
KWin::Screens::init();
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect DrmScreens::geometry(int screen) const
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->enabledOutputs();
|
|
||||||
if (screen >= outputs.size()) {
|
|
||||||
return QRect();
|
|
||||||
}
|
|
||||||
return outputs.at(screen)->geometry();
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal DrmScreens::scale(int screen) const
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->enabledOutputs();
|
|
||||||
if (screen >= outputs.size()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return outputs.at(screen)->scale();
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize DrmScreens::size(int screen) const
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->enabledOutputs();
|
|
||||||
if (screen >= outputs.size()) {
|
|
||||||
return QSize();
|
|
||||||
}
|
|
||||||
return outputs.at(screen)->geometry().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrmScreens::updateCount()
|
|
||||||
{
|
|
||||||
setCount(m_backend->drmEnabledOutputs().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int DrmScreens::number(const QPoint &pos) const
|
|
||||||
{
|
|
||||||
int bestScreen = 0;
|
|
||||||
int minDistance = INT_MAX;
|
|
||||||
const auto outputs = m_backend->drmEnabledOutputs();
|
|
||||||
for (int i = 0; i < outputs.size(); ++i) {
|
|
||||||
auto o = outputs.at(i);
|
|
||||||
const QRect &geo = o->geometry();
|
|
||||||
if (geo.contains(pos)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
int distance = QPoint(geo.topLeft() - pos).manhattanLength();
|
|
||||||
distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength());
|
|
||||||
distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength());
|
|
||||||
distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength());
|
|
||||||
if (distance < minDistance) {
|
|
||||||
minDistance = distance;
|
|
||||||
bestScreen = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DrmScreens::name(int screen) const
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->drmEnabledOutputs();
|
|
||||||
if (screen >= outputs.size()) {
|
|
||||||
return Screens::name(screen);
|
|
||||||
}
|
|
||||||
return outputs.at(screen)->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
float DrmScreens::refreshRate(int screen) const
|
float DrmScreens::refreshRate(int screen) const
|
||||||
{
|
{
|
||||||
const auto outputs = m_backend->drmEnabledOutputs();
|
const auto enOuts = m_backend->drmEnabledOutputs();
|
||||||
if (screen >= outputs.size()) {
|
if (screen >= enOuts.size()) {
|
||||||
return Screens::refreshRate(screen);
|
return Screens::refreshRate(screen);
|
||||||
}
|
}
|
||||||
return outputs.at(screen)->currentRefreshRate() / 1000.0f;
|
return enOuts.at(screen)->currentRefreshRate() / 1000.0f;
|
||||||
}
|
|
||||||
|
|
||||||
QSizeF DrmScreens::physicalSize(int screen) const
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->drmEnabledOutputs();
|
|
||||||
if (screen >= outputs.size()) {
|
|
||||||
return Screens::physicalSize(screen);
|
|
||||||
}
|
|
||||||
return outputs.at(screen)->physicalSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DrmScreens::isInternal(int screen) const
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->drmEnabledOutputs();
|
|
||||||
if (screen >= outputs.size()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return outputs.at(screen)->isInternal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrmScreens::supportsTransformations(int screen) const
|
bool DrmScreens::supportsTransformations(int screen) const
|
||||||
{
|
{
|
||||||
const auto outputs = m_backend->drmEnabledOutputs();
|
const auto enOuts = m_backend->drmEnabledOutputs();
|
||||||
if (screen >= outputs.size()) {
|
if (screen >= enOuts.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return outputs.at(screen)->supportsTransformations();
|
return enOuts.at(screen)->supportsTransformations();
|
||||||
}
|
|
||||||
|
|
||||||
Qt::ScreenOrientation DrmScreens::orientation(int screen) const
|
|
||||||
{
|
|
||||||
const auto outputs = m_backend->drmOutputs();
|
|
||||||
if (screen >= outputs.size()) {
|
|
||||||
return Qt::PrimaryOrientation;
|
|
||||||
}
|
|
||||||
return outputs.at(screen)->orientation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,33 +19,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
#ifndef KWIN_SCREENS_DRM_H
|
#ifndef KWIN_SCREENS_DRM_H
|
||||||
#define KWIN_SCREENS_DRM_H
|
#define KWIN_SCREENS_DRM_H
|
||||||
#include "screens.h"
|
#include "outputscreens.h"
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
class DrmBackend;
|
class DrmBackend;
|
||||||
|
|
||||||
class DrmScreens : public Screens
|
class DrmScreens : public OutputScreens
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DrmScreens(DrmBackend *backend, QObject *parent = nullptr);
|
DrmScreens(DrmBackend *backend, QObject *parent = nullptr);
|
||||||
virtual ~DrmScreens();
|
virtual ~DrmScreens();
|
||||||
void init() override;
|
|
||||||
QRect geometry(int screen) const override;
|
|
||||||
int number(const QPoint &pos) const override;
|
|
||||||
qreal scale(int screen) const override;
|
|
||||||
QSize size(int screen) const override;
|
|
||||||
void updateCount() override;
|
|
||||||
QString name(int screen) const override;
|
|
||||||
float refreshRate(int screen) const override;
|
float refreshRate(int screen) const override;
|
||||||
|
|
||||||
QSizeF physicalSize(int screen) const override;
|
|
||||||
bool isInternal(int screen) const override;
|
|
||||||
bool supportsTransformations(int screen) const override;
|
bool supportsTransformations(int screen) const override;
|
||||||
Qt::ScreenOrientation orientation(int screen) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
DrmBackend *m_backend;
|
DrmBackend *m_backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue