2013-04-03 10:19:27 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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 "screens.h"
|
2015-03-05 13:07:20 +00:00
|
|
|
#include <abstract_client.h>
|
2019-09-24 08:48:08 +00:00
|
|
|
#include <x11client.h>
|
2013-04-03 10:19:27 +00:00
|
|
|
#include "cursor.h"
|
2015-07-31 08:17:43 +00:00
|
|
|
#include "utils.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"
|
2015-03-23 13:29:07 +00:00
|
|
|
#include "wayland_server.h"
|
2014-09-17 08:29:03 +00:00
|
|
|
#ifdef KWIN_UNIT_TEST
|
|
|
|
#include <mock_screens.h>
|
|
|
|
#endif
|
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);
|
2014-09-17 08:29:03 +00:00
|
|
|
#ifdef KWIN_UNIT_TEST
|
|
|
|
s_self = new MockScreens(parent);
|
|
|
|
#else
|
2016-04-08 08:32:37 +00:00
|
|
|
s_self = kwinApp()->platform()->createScreens(parent);
|
2014-09-17 08:29:03 +00:00
|
|
|
#endif
|
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)
|
|
|
|
, m_current(0)
|
|
|
|
, m_currentFollowsMouse(false)
|
2013-07-31 10:55:00 +00:00
|
|
|
, m_changedTimer(new QTimer(this))
|
2018-06-23 22:26:54 +00:00
|
|
|
, m_maxScale(1.0)
|
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
|
|
|
{
|
|
|
|
m_changedTimer->setSingleShot(true);
|
|
|
|
m_changedTimer->setInterval(100);
|
2013-04-21 18:18:18 +00:00
|
|
|
connect(m_changedTimer, SIGNAL(timeout()), SLOT(updateCount()));
|
2013-04-03 10:19:27 +00:00
|
|
|
connect(m_changedTimer, SIGNAL(timeout()), SIGNAL(changed()));
|
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
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
settings.setDefaults();
|
|
|
|
m_currentFollowsMouse = settings.activeMouseScreen();
|
|
|
|
}
|
|
|
|
|
2015-05-08 20:57:13 +00:00
|
|
|
QString Screens::name(int screen) const
|
|
|
|
{
|
2015-05-19 06:15:30 +00:00
|
|
|
Q_UNUSED(screen)
|
2015-07-31 08:17:43 +00:00
|
|
|
qCWarning(KWIN_CORE, "%s::name(int screen) is a stub, please reimplement it!", metaObject()->className());
|
2015-05-08 20:57:13 +00:00
|
|
|
return QLatin1String("DUMMY");
|
|
|
|
}
|
|
|
|
|
|
|
|
float Screens::refreshRate(int screen) const
|
|
|
|
{
|
2015-05-19 06:15:30 +00:00
|
|
|
Q_UNUSED(screen)
|
2015-07-31 08:17:43 +00:00
|
|
|
qCWarning(KWIN_CORE, "%s::refreshRate(int screen) is a stub, please reimplement it!", metaObject()->className());
|
2015-05-08 20:57:13 +00:00
|
|
|
return 60.0f;
|
|
|
|
}
|
|
|
|
|
2018-06-23 22:26:54 +00:00
|
|
|
qreal Screens::maxScale() const
|
|
|
|
{
|
|
|
|
return m_maxScale;
|
|
|
|
}
|
|
|
|
|
2016-10-25 23:36:02 +00:00
|
|
|
qreal Screens::scale(int screen) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(screen)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-04-03 10:19:27 +00:00
|
|
|
void Screens::reconfigure()
|
|
|
|
{
|
|
|
|
if (!m_config) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Settings settings(m_config);
|
2014-03-25 15:29:03 +00:00
|
|
|
settings.read();
|
2013-04-03 10:19:27 +00:00
|
|
|
setCurrentFollowsMouse(settings.activeMouseScreen());
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
emit sizeChanged();
|
|
|
|
}
|
2018-06-23 22:26:54 +00:00
|
|
|
if (!qFuzzyCompare(m_maxScale, maxScale)) {
|
|
|
|
m_maxScale = maxScale;
|
|
|
|
emit maxScaleChanged();
|
|
|
|
}
|
2014-02-27 08:55:45 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
emit countChanged(previous, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screens::setCurrent(int current)
|
|
|
|
{
|
|
|
|
if (m_current == current) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_current = current;
|
2013-12-11 10:13:47 +00:00
|
|
|
emit currentChanged();
|
2013-04-03 10:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screens::setCurrent(const QPoint &pos)
|
|
|
|
{
|
|
|
|
setCurrent(number(pos));
|
|
|
|
}
|
|
|
|
|
2015-03-05 13:07:20 +00:00
|
|
|
void Screens::setCurrent(const AbstractClient *c)
|
2013-04-03 10:19:27 +00:00
|
|
|
{
|
|
|
|
if (!c->isActive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!c->isOnScreen(m_current)) {
|
|
|
|
setCurrent(c->screen());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screens::setCurrentFollowsMouse(bool follows)
|
|
|
|
{
|
|
|
|
if (m_currentFollowsMouse == follows) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_currentFollowsMouse = follows;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Screens::current() const
|
|
|
|
{
|
|
|
|
if (m_currentFollowsMouse) {
|
2020-04-02 16:18:01 +00:00
|
|
|
return number(Cursors::self()->mouse()->pos());
|
2013-04-03 10:19:27 +00:00
|
|
|
}
|
2015-03-06 12:37:56 +00:00
|
|
|
AbstractClient *client = Workspace::self()->activeClient();
|
2013-04-03 10:19:27 +00:00
|
|
|
if (client && !client->isOnScreen(m_current)) {
|
|
|
|
return client->screen();
|
|
|
|
}
|
|
|
|
return m_current;
|
|
|
|
}
|
|
|
|
|
2013-09-23 21:04:17 +00:00
|
|
|
int Screens::intersecting(const QRect &r) const
|
|
|
|
{
|
|
|
|
int cnt = 0;
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
if (geometry(i).intersects(r)) {
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2016-06-08 10:46:02 +00:00
|
|
|
QSize Screens::displaySize() const
|
|
|
|
{
|
|
|
|
return size();
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:46:20 +00:00
|
|
|
QSizeF Screens::physicalSize(int screen) const
|
|
|
|
{
|
|
|
|
return QSizeF(size(screen)) / 3.8;
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:00:15 +00:00
|
|
|
bool Screens::isInternal(int screen) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(screen)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Screens::supportsTransformations(int screen) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(screen)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-10 17:07:15 +00:00
|
|
|
Qt::ScreenOrientation Screens::orientation(int screen) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(screen)
|
|
|
|
return Qt::PrimaryOrientation;
|
|
|
|
}
|
|
|
|
|
2017-11-09 17:03:15 +00:00
|
|
|
void Screens::setConfig(KSharedConfig::Ptr config)
|
|
|
|
{
|
|
|
|
m_config = config;
|
|
|
|
}
|
|
|
|
|
2020-03-23 19:26:21 +00:00
|
|
|
int Screens::physicalDpiX(int screen) const
|
|
|
|
{
|
|
|
|
return size(screen).width() / physicalSize(screen).width() * qreal(25.4);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Screens::physicalDpiY(int screen) const
|
|
|
|
{
|
|
|
|
return size(screen).height() / physicalSize(screen).height() * qreal(25.4);
|
|
|
|
}
|
|
|
|
|
2013-04-03 10:19:27 +00:00
|
|
|
} // namespace
|