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>
|
2014-09-17 08:29:03 +00:00
|
|
|
#include <client.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))
|
2014-02-27 08:55:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Screens::~Screens()
|
|
|
|
{
|
|
|
|
s_self = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
bounding = bounding.united(geometry(i));
|
|
|
|
}
|
|
|
|
if (m_boundingSize != bounding.size()) {
|
|
|
|
m_boundingSize = bounding.size();
|
|
|
|
emit sizeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
return number(Cursor::pos());
|
|
|
|
}
|
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-04-07 07:18:10 +00:00
|
|
|
BasicScreens::BasicScreens(Platform *backend, QObject *parent)
|
2015-11-17 09:32:06 +00:00
|
|
|
: Screens(parent)
|
|
|
|
, m_backend(backend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicScreens::~BasicScreens() = default;
|
|
|
|
|
|
|
|
void BasicScreens::init()
|
|
|
|
{
|
2016-08-05 07:41:56 +00:00
|
|
|
updateCount();
|
2015-11-17 09:32:06 +00:00
|
|
|
KWin::Screens::init();
|
|
|
|
#ifndef KWIN_UNIT_TEST
|
2016-04-07 07:18:10 +00:00
|
|
|
connect(m_backend, &Platform::screenSizeChanged,
|
2015-11-17 09:32:06 +00:00
|
|
|
this, &BasicScreens::startChangedTimer);
|
|
|
|
#endif
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect BasicScreens::geometry(int screen) const
|
|
|
|
{
|
2015-11-20 15:11:35 +00:00
|
|
|
if (screen < m_geometries.count()) {
|
|
|
|
return m_geometries.at(screen);
|
2015-11-17 09:32:06 +00:00
|
|
|
}
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize BasicScreens::size(int screen) const
|
|
|
|
{
|
2015-11-20 15:11:35 +00:00
|
|
|
if (screen < m_geometries.count()) {
|
|
|
|
return m_geometries.at(screen).size();
|
2015-11-17 09:32:06 +00:00
|
|
|
}
|
|
|
|
return QSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicScreens::updateCount()
|
|
|
|
{
|
2015-11-20 15:11:35 +00:00
|
|
|
m_geometries = m_backend->screenGeometries();
|
|
|
|
setCount(m_geometries.count());
|
2015-11-17 09:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BasicScreens::number(const QPoint &pos) const
|
|
|
|
{
|
2015-11-20 15:11:35 +00:00
|
|
|
int bestScreen = 0;
|
|
|
|
int minDistance = INT_MAX;
|
|
|
|
for (int i = 0; i < m_geometries.count(); ++i) {
|
|
|
|
const QRect &geo = m_geometries.at(i);
|
|
|
|
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;
|
2015-11-17 09:32:06 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 10:19:27 +00:00
|
|
|
} // namespace
|