2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2013-04-03 10:19:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2013-04-03 10:19:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-04-03 10:19:27 +00:00
|
|
|
#include "screens.h"
|
2015-03-05 13:07:20 +00:00
|
|
|
#include <abstract_client.h>
|
2020-12-17 10:34:04 +00:00
|
|
|
#include "abstract_output.h"
|
2013-04-03 10:19:27 +00:00
|
|
|
#include "cursor.h"
|
2022-01-18 08:35:52 +00:00
|
|
|
#include "utils/common.h"
|
2013-04-03 10:19:27 +00:00
|
|
|
#include "settings.h"
|
2014-09-17 08:29:03 +00:00
|
|
|
#include <workspace.h>
|
2014-09-17 07:05:11 +00:00
|
|
|
#include <config-kwin.h>
|
2016-04-07 07:24:17 +00:00
|
|
|
#include "platform.h"
|
2013-04-03 10:19:27 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2014-02-27 08:55:45 +00:00
|
|
|
Screens *Screens::s_self = nullptr;
|
|
|
|
Screens *Screens::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_self);
|
2020-12-20 13:15:57 +00:00
|
|
|
s_self = new Screens(parent);
|
2015-03-19 07:29:34 +00:00
|
|
|
Q_ASSERT(s_self);
|
2014-02-27 08:55:45 +00:00
|
|
|
s_self->init();
|
|
|
|
return s_self;
|
|
|
|
}
|
2013-04-03 10:19:27 +00:00
|
|
|
|
|
|
|
Screens::Screens(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_count(0)
|
2018-06-23 22:26:54 +00:00
|
|
|
, m_maxScale(1.0)
|
2014-02-27 08:55:45 +00:00
|
|
|
{
|
2020-12-20 13:15:57 +00:00
|
|
|
connect(kwinApp()->platform(), &Platform::screensQueried, this, &Screens::updateCount);
|
|
|
|
connect(kwinApp()->platform(), &Platform::screensQueried, this, &Screens::changed);
|
2014-02-27 08:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Screens::~Screens()
|
|
|
|
{
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
s_self = nullptr;
|
2014-02-27 08:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screens::init()
|
2013-04-03 10:19:27 +00:00
|
|
|
{
|
2020-12-17 10:34:04 +00:00
|
|
|
updateCount();
|
2014-05-26 09:06:20 +00:00
|
|
|
connect(this, &Screens::countChanged, this, &Screens::changed, Qt::QueuedConnection);
|
2014-02-27 08:55:45 +00:00
|
|
|
connect(this, &Screens::changed, this, &Screens::updateSize);
|
|
|
|
connect(this, &Screens::sizeChanged, this, &Screens::geometryChanged);
|
2013-04-03 10:19:27 +00:00
|
|
|
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT changed();
|
2013-04-03 10:19:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 10:34:04 +00:00
|
|
|
QRect Screens::geometry(int screen) const
|
2018-06-23 22:26:54 +00:00
|
|
|
{
|
2020-12-17 10:34:04 +00:00
|
|
|
if (AbstractOutput *output = findOutput(screen)) {
|
|
|
|
return output->geometry();
|
|
|
|
}
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
2016-10-25 23:36:02 +00:00
|
|
|
qreal Screens::scale(int screen) const
|
|
|
|
{
|
2020-12-17 10:34:04 +00:00
|
|
|
if (AbstractOutput *output = findOutput(screen)) {
|
|
|
|
return output->scale();
|
|
|
|
}
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Screens::maxScale() const
|
|
|
|
{
|
|
|
|
return m_maxScale;
|
2016-10-25 23:36:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 08:55:45 +00:00
|
|
|
void Screens::updateSize()
|
|
|
|
{
|
|
|
|
QRect bounding;
|
2018-06-23 22:26:54 +00:00
|
|
|
qreal maxScale = 1.0;
|
2014-02-27 08:55:45 +00:00
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
bounding = bounding.united(geometry(i));
|
2018-06-23 22:26:54 +00:00
|
|
|
maxScale = qMax(maxScale, scale(i));
|
2014-02-27 08:55:45 +00:00
|
|
|
}
|
|
|
|
if (m_boundingSize != bounding.size()) {
|
|
|
|
m_boundingSize = bounding.size();
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT sizeChanged();
|
2014-02-27 08:55:45 +00:00
|
|
|
}
|
2018-06-23 22:26:54 +00:00
|
|
|
if (!qFuzzyCompare(m_maxScale, maxScale)) {
|
|
|
|
m_maxScale = maxScale;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT maxScaleChanged();
|
2018-06-23 22:26:54 +00:00
|
|
|
}
|
2014-02-27 08:55:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 10:34:04 +00:00
|
|
|
void Screens::updateCount()
|
|
|
|
{
|
|
|
|
setCount(kwinApp()->platform()->enabledOutputs().size());
|
|
|
|
}
|
|
|
|
|
2013-04-03 10:19:27 +00:00
|
|
|
void Screens::setCount(int count)
|
|
|
|
{
|
|
|
|
if (m_count == count) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int previous = m_count;
|
|
|
|
m_count = count;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT countChanged(previous, count);
|
2013-04-03 10:19:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 10:34:04 +00:00
|
|
|
int Screens::number(const QPoint &pos) const
|
|
|
|
{
|
2021-08-27 15:49:54 +00:00
|
|
|
return kwinApp()->platform()->enabledOutputs().indexOf(kwinApp()->platform()->outputAt(pos));
|
2020-12-17 10:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractOutput *Screens::findOutput(int screen) const
|
|
|
|
{
|
|
|
|
return kwinApp()->platform()->findOutput(screen);
|
|
|
|
}
|
|
|
|
|
2013-04-03 10:19:27 +00:00
|
|
|
} // namespace
|