Commit 79ca5ccd authored by Vlad Zahorodnii's avatar Vlad Zahorodnii Committed by Aleix Pol Gonzalez

Merge OutputScreens into Screens

Since all platforms have been ported to AbstractOutput, OutputScreens
can be merged into Screens. This simplifies the class hierarchy.
parent 04200484
......@@ -504,7 +504,6 @@ set(kwin_SRCS
options.cpp
osd.cpp
outline.cpp
outputscreens.cpp
overlaywindow.cpp
placement.cpp
platform.cpp
......
......@@ -43,6 +43,11 @@ QSize MockScreens::size(int screen) const
return geometry(screen).size();
}
QSizeF MockScreens::physicalSize(int screen) const
{
return QSizeF(size(screen)) / 3.8;
}
int MockScreens::number(const QPoint &pos) const
{
int bestScreen = 0;
......
......@@ -25,6 +25,7 @@ public:
QString name(int screen) const override;
float refreshRate(int screen) const override;
QSize size(int screen) const override;
QSizeF physicalSize(int screen) const override;
void init() override;
void setGeometries(const QList<QRect> &geometries);
......
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#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
{
if (AbstractOutput *output = findOutput(screen)) {
return output->name();
}
return QString();
}
bool OutputScreens::isInternal(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->isInternal();
}
return false;
}
QRect OutputScreens::geometry(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->geometry();
}
return QRect();
}
QSize OutputScreens::size(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->geometry().size();
}
return QSize();
}
qreal OutputScreens::scale(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->scale();
}
return 1.0;
}
QSizeF OutputScreens::physicalSize(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->physicalSize();
}
return QSizeF();
}
float OutputScreens::refreshRate(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->refreshRate() / 1000.0;
}
return 60.0;
}
void OutputScreens::updateCount()
{
setCount(m_platform->enabledOutputs().size());
}
int OutputScreens::number(const QPoint &pos) const
{
int bestScreen = 0;
int minDistance = INT_MAX;
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;
}
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;
}
AbstractOutput *OutputScreens::findOutput(int screen) const
{
return m_platform->findOutput(screen);
}
} // namespace
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KWIN_OUTPUTSCREENS_H
#define KWIN_OUTPUTSCREENS_H
#include "screens.h"
namespace KWin
{
class AbstractOutput;
/**
* @brief Implementation for backends with Outputs
*/
class KWIN_EXPORT OutputScreens : public Screens
{
Q_OBJECT
public:
OutputScreens(Platform *platform, QObject *parent = nullptr);
~OutputScreens() override;
void init() override;
QString name(int screen) const override;
bool isInternal(int screen) const override;
QSizeF physicalSize(int screen) const override;
QRect geometry(int screen) const override;
QSize size(int screen) const override;
qreal scale(int screen) const override;
float refreshRate(int screen) const override;
void updateCount() override;
int number(const QPoint &pos) const override;
protected:
Platform *m_platform;
private:
AbstractOutput *findOutput(int screen) const;
};
}
#endif // KWIN_OUTPUTSCREENS_H
......@@ -13,12 +13,10 @@ namespace KWin
{
DrmScreens::DrmScreens(DrmBackend *backend, QObject *parent)
: OutputScreens(backend, parent)
: Screens(parent)
{
connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::updateCount);
connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::changed);
}
DrmScreens::~DrmScreens() = default;
}
......@@ -8,18 +8,17 @@
*/
#ifndef KWIN_SCREENS_DRM_H
#define KWIN_SCREENS_DRM_H
#include "outputscreens.h"
#include "screens.h"
namespace KWin
{
class DrmBackend;
class DrmScreens : public OutputScreens
class DrmScreens : public Screens
{
Q_OBJECT
public:
DrmScreens(DrmBackend *backend, QObject *parent = nullptr);
~DrmScreens() override;
};
}
......
......@@ -12,7 +12,7 @@
#include "logging.h"
#include "logind.h"
#include "scene_qpainter_fb_backend.h"
#include "outputscreens.h"
#include "screens.h"
#include "virtual_terminal.h"
#include "udev.h"
// system
......@@ -58,7 +58,7 @@ FramebufferBackend::~FramebufferBackend()
Screens *FramebufferBackend::createScreens(QObject *parent)
{
return new OutputScreens(this, parent);
return Screens::create(parent);
}
QPainterBackend *FramebufferBackend::createQPainterBackend()
......
......@@ -13,11 +13,10 @@ namespace KWin
{
HwcomposerScreens::HwcomposerScreens(HwcomposerBackend *backend, QObject *parent)
: OutputScreens(backend, parent)
, m_backend(backend)
: Screens(parent)
{
connect(m_backend, &HwcomposerBackend::screensQueried, this, &OutputScreens::updateCount);
connect(m_backend, &HwcomposerBackend::screensQueried, this, &OutputScreens::changed);
connect(backend, &HwcomposerBackend::screensQueried, this, &HwcomposerScreens::updateCount);
connect(backend, &HwcomposerBackend::screensQueried, this, &HwcomposerScreens::changed);
}
}
......@@ -8,21 +8,17 @@
*/
#ifndef KWIN_SCREENS_HWCOMPOSER_H
#define KWIN_SCREENS_HWCOMPOSER_H
#include "outputscreens.h"
#include "screens.h"
namespace KWin
{
class HwcomposerBackend;
class HwcomposerScreens : public OutputScreens
class HwcomposerScreens : public Screens
{
Q_OBJECT
public:
HwcomposerScreens(HwcomposerBackend *backend, QObject *parent = nullptr);
virtual ~HwcomposerScreens() = default;
private:
HwcomposerBackend *m_backend;
};
}
......
......@@ -14,7 +14,7 @@ namespace KWin
{
VirtualScreens::VirtualScreens(VirtualBackend *backend, QObject *parent)
: OutputScreens(backend, parent)
: Screens(parent)
, m_backend(backend)
{
}
......@@ -23,7 +23,6 @@ VirtualScreens::~VirtualScreens() = default;
void VirtualScreens::init()
{
updateCount();
KWin::Screens::init();
connect(m_backend, &VirtualBackend::virtualOutputsSet, this,
......@@ -35,8 +34,6 @@ void VirtualScreens::init()
}
}
);
emit changed();
}
}
......@@ -8,14 +8,14 @@
*/
#ifndef KWIN_SCREENS_VIRTUAL_H
#define KWIN_SCREENS_VIRTUAL_H
#include "outputscreens.h"
#include "screens.h"
#include <QVector>
namespace KWin
{
class VirtualBackend;
class VirtualScreens : public OutputScreens
class VirtualScreens : public Screens
{
Q_OBJECT
public:
......
......@@ -25,7 +25,7 @@
#include "cursor.h"
#include "input.h"
#include "main.h"
#include "outputscreens.h"
#include "screens.h"
#include "pointer_input.h"
#include "screens.h"
#include "wayland_server.h"
......@@ -729,7 +729,7 @@ void WaylandBackend::createOutputs()
Screens *WaylandBackend::createScreens(QObject *parent)
{
return new OutputScreens(this, parent);
return Screens::create(parent);
}
OpenGLBackend *WaylandBackend::createOpenGLBackend()
......
......@@ -21,7 +21,7 @@ namespace KWin
{
XRandRScreens::XRandRScreens(X11StandalonePlatform *backend, QObject *parent)
: OutputScreens(backend, parent)
: Screens(parent)
, X11EventFilter(Xcb::Extensions::self()->randrNotifyEvent())
, m_backend(backend)
{
......
......@@ -9,14 +9,14 @@
#ifndef KWIN_SCREENS_XRANDR_H
#define KWIN_SCREENS_XRANDR_H
// kwin
#include "outputscreens.h"
#include "screens.h"
#include "x11eventfilter.h"
namespace KWin
{
class X11StandalonePlatform;
class XRandRScreens : public OutputScreens, public X11EventFilter
class XRandRScreens : public Screens, public X11EventFilter
{
Q_OBJECT
public:
......
......@@ -13,7 +13,7 @@
#include "wayland_server.h"
#include "xcbutils.h"
#include "egl_x11_backend.h"
#include "outputscreens.h"
#include "screens.h"
#include <kwinxrenderutils.h>
#include <cursor.h>
#include <pointer_input.h>
......@@ -501,7 +501,7 @@ xcb_window_t X11WindowedBackend::rootWindow() const
Screens *X11WindowedBackend::createScreens(QObject *parent)
{
return new OutputScreens(this, parent);
return Screens::create(parent);
}
OpenGLBackend *X11WindowedBackend::createOpenGLBackend()
......
......@@ -8,6 +8,7 @@
*/
#include "screens.h"
#include <abstract_client.h>
#include "abstract_output.h"
#include <x11client.h>
#include "cursor.h"
#include "utils.h"
......@@ -54,6 +55,7 @@ Screens::~Screens()
void Screens::init()
{
updateCount();
m_changedTimer->setSingleShot(true);
m_changedTimer->setInterval(100);
connect(m_changedTimer, &QTimer::timeout, this, &Screens::updateCount);
......@@ -65,31 +67,68 @@ void Screens::init()
Settings settings;
settings.setDefaults();
m_currentFollowsMouse = settings.activeMouseScreen();
emit changed();
}
QString Screens::name(int screen) const
{
Q_UNUSED(screen)
qCWarning(KWIN_CORE, "%s::name(int screen) is a stub, please reimplement it!", metaObject()->className());
return QLatin1String("DUMMY");
if (AbstractOutput *output = findOutput(screen)) {
return output->name();
}
return QString();
}
float Screens::refreshRate(int screen) const
bool Screens::isInternal(int screen) const
{
Q_UNUSED(screen)
qCWarning(KWIN_CORE, "%s::refreshRate(int screen) is a stub, please reimplement it!", metaObject()->className());
return 60.0f;
if (AbstractOutput *output = findOutput(screen)) {
return output->isInternal();
}
return false;
}
qreal Screens::maxScale() const
QRect Screens::geometry(int screen) const
{
return m_maxScale;
if (AbstractOutput *output = findOutput(screen)) {
return output->geometry();
}
return QRect();
}
QSize Screens::size(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->geometry().size();
}
return QSize();
}
qreal Screens::scale(int screen) const
{
Q_UNUSED(screen)
return 1;
if (AbstractOutput *output = findOutput(screen)) {
return output->scale();
}
return 1.0;
}
QSizeF Screens::physicalSize(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->physicalSize();
}
return QSizeF();
}
float Screens::refreshRate(int screen) const
{
if (AbstractOutput *output = findOutput(screen)) {
return output->refreshRate() / 1000.0;
}
return 60.0;
}
qreal Screens::maxScale() const
{
return m_maxScale;
}
void Screens::reconfigure()
......@@ -120,6 +159,11 @@ void Screens::updateSize()
}
}
void Screens::updateCount()
{
setCount(kwinApp()->platform()->enabledOutputs().size());
}
void Screens::setCount(int count)
{
if (m_count == count) {
......@@ -190,17 +234,6 @@ QSize Screens::displaySize() const
return size();
}
QSizeF Screens::physicalSize(int screen) const
{
return QSizeF(size(screen)) / 3.8;
}
bool Screens::isInternal(int screen) const
{
Q_UNUSED(screen)
return false;
}
Qt::ScreenOrientation Screens::orientation(int screen) const
{
Q_UNUSED(screen)
......@@ -222,4 +255,43 @@ int Screens::physicalDpiY(int screen) const
return size(screen).height() / physicalSize(screen).height() * qreal(25.4);
}
int Screens::number(const QPoint &pos) const
{
// TODO: Do something about testScreens and other tests that use MockScreens.
// They only make core code more convoluted with ifdefs.
#ifdef KWIN_UNIT_TEST
return -1;
#else
int bestScreen = 0;
int minDistance = INT_MAX;
const auto outputs = kwinApp()->platform()->enabledOutputs();
for (int i = 0; i < outputs.size(); ++i) {
const QRect &geo = outputs[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;
#endif
}
AbstractOutput *Screens::findOutput(int screen) const
{
// TODO: Do something about testScreens and other tests that use MockScreens.
// They only make core code more convoluted with ifdefs.
#ifdef KWIN_UNIT_TEST
return nullptr;
#else
return kwinApp()->platform()->findOutput(screen);
#endif
}
} // namespace
......@@ -23,6 +23,7 @@
namespace KWin
{
class AbstractClient;
class AbstractOutput;
class Platform;
class KWIN_EXPORT Screens : public QObject
......@@ -53,7 +54,7 @@ public:
void setCurrent(const AbstractClient *c);
bool isCurrentFollowsMouse() const;
void setCurrentFollowsMouse(bool follows);
virtual QRect geometry(int screen) const = 0;
virtual QRect geometry(int screen) const;
/**
* The bounding geometry of all screens combined. Overlapping areas
* are not counted multiple times.
......@@ -74,7 +75,7 @@ public:
* To get the size of all screens combined use size().
* @see size()
*/
virtual QSize size(int screen) const = 0;
virtual QSize size(int screen) const;
/**
* The highest scale() of all connected screens
......@@ -96,7 +97,7 @@ public:
* @see sizeChanged()
*/
QSize size() const;
virtual int number(const QPoint &pos) const = 0;
virtual int number(const QPoint &pos) const;
inline bool isChanging() { return m_changedTimer->isActive(); }
......@@ -163,7 +164,7 @@ Q_SIGNALS:
protected Q_SLOTS:
void setCount(int count);
void startChangedTimer();
virtual void updateCount() = 0;
virtual void updateCount();
protected:
/**
......@@ -177,6 +178,8 @@ private Q_SLOTS:
void updateSize();
private:
AbstractOutput *findOutput(int screenId) const;
int m_count;
int m_current;
bool m_currentFollowsMouse;
......