2013-04-03 14:19:27 +04: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 16:07:20 +03:00
|
|
|
#include <abstract_client.h>
|
2014-09-17 12:29:03 +04:00
|
|
|
#include <client.h>
|
2013-04-03 14:19:27 +04:00
|
|
|
#include "cursor.h"
|
2015-07-31 11:17:43 +03:00
|
|
|
#include "utils.h"
|
2013-04-03 14:19:27 +04:00
|
|
|
#include "settings.h"
|
2014-09-17 12:29:03 +04:00
|
|
|
#include <workspace.h>
|
2014-09-17 11:05:11 +04:00
|
|
|
#include <config-kwin.h>
|
2016-04-07 10:24:17 +03:00
|
|
|
#include "platform.h"
|
2015-03-23 16:29:07 +03:00
|
|
|
#include "wayland_server.h"
|
2014-09-17 12:29:03 +04:00
|
|
|
#ifdef KWIN_UNIT_TEST
|
|
|
|
#include <mock_screens.h>
|
|
|
|
#endif
|
2013-04-03 14:19:27 +04:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2014-02-27 12:55:45 +04:00
|
|
|
Screens *Screens::s_self = nullptr;
|
|
|
|
Screens *Screens::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_self);
|
2014-09-17 12:29:03 +04:00
|
|
|
#ifdef KWIN_UNIT_TEST
|
|
|
|
s_self = new MockScreens(parent);
|
|
|
|
#else
|
2016-04-08 11:32:37 +03:00
|
|
|
s_self = kwinApp()->platform()->createScreens(parent);
|
2014-09-17 12:29:03 +04:00
|
|
|
#endif
|
2015-03-19 10:29:34 +03:00
|
|
|
Q_ASSERT(s_self);
|
2014-02-27 12:55:45 +04:00
|
|
|
s_self->init();
|
|
|
|
return s_self;
|
|
|
|
}
|
2013-04-03 14:19:27 +04:00
|
|
|
|
|
|
|
Screens::Screens(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_count(0)
|
|
|
|
, m_current(0)
|
|
|
|
, m_currentFollowsMouse(false)
|
2013-07-31 14:55:00 +04:00
|
|
|
, m_changedTimer(new QTimer(this))
|
2014-02-27 12:55:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Screens::~Screens()
|
|
|
|
{
|
|
|
|
s_self = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screens::init()
|
2013-04-03 14:19:27 +04:00
|
|
|
{
|
|
|
|
m_changedTimer->setSingleShot(true);
|
|
|
|
m_changedTimer->setInterval(100);
|
2013-04-21 22:18:18 +04:00
|
|
|
connect(m_changedTimer, SIGNAL(timeout()), SLOT(updateCount()));
|
2013-04-03 14:19:27 +04:00
|
|
|
connect(m_changedTimer, SIGNAL(timeout()), SIGNAL(changed()));
|
2014-05-26 13:06:20 +04:00
|
|
|
connect(this, &Screens::countChanged, this, &Screens::changed, Qt::QueuedConnection);
|
2014-02-27 12:55:45 +04:00
|
|
|
connect(this, &Screens::changed, this, &Screens::updateSize);
|
|
|
|
connect(this, &Screens::sizeChanged, this, &Screens::geometryChanged);
|
2013-04-03 14:19:27 +04:00
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
settings.setDefaults();
|
|
|
|
m_currentFollowsMouse = settings.activeMouseScreen();
|
|
|
|
}
|
|
|
|
|
2015-05-08 23:57:13 +03:00
|
|
|
QString Screens::name(int screen) const
|
|
|
|
{
|
2015-05-19 09:15:30 +03:00
|
|
|
Q_UNUSED(screen)
|
2015-07-31 11:17:43 +03:00
|
|
|
qCWarning(KWIN_CORE, "%s::name(int screen) is a stub, please reimplement it!", metaObject()->className());
|
2015-05-08 23:57:13 +03:00
|
|
|
return QLatin1String("DUMMY");
|
|
|
|
}
|
|
|
|
|
|
|
|
float Screens::refreshRate(int screen) const
|
|
|
|
{
|
2015-05-19 09:15:30 +03:00
|
|
|
Q_UNUSED(screen)
|
2015-07-31 11:17:43 +03:00
|
|
|
qCWarning(KWIN_CORE, "%s::refreshRate(int screen) is a stub, please reimplement it!", metaObject()->className());
|
2015-05-08 23:57:13 +03:00
|
|
|
return 60.0f;
|
|
|
|
}
|
|
|
|
|
2013-04-03 14:19:27 +04:00
|
|
|
void Screens::reconfigure()
|
|
|
|
{
|
|
|
|
if (!m_config) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Settings settings(m_config);
|
2014-03-25 19:29:03 +04:00
|
|
|
settings.read();
|
2013-04-03 14:19:27 +04:00
|
|
|
setCurrentFollowsMouse(settings.activeMouseScreen());
|
|
|
|
}
|
|
|
|
|
2014-02-27 12:55:45 +04: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 14:19:27 +04: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 14:13:47 +04:00
|
|
|
emit currentChanged();
|
2013-04-03 14:19:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screens::setCurrent(const QPoint &pos)
|
|
|
|
{
|
|
|
|
setCurrent(number(pos));
|
|
|
|
}
|
|
|
|
|
2015-03-05 16:07:20 +03:00
|
|
|
void Screens::setCurrent(const AbstractClient *c)
|
2013-04-03 14:19:27 +04: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 15:37:56 +03:00
|
|
|
AbstractClient *client = Workspace::self()->activeClient();
|
2013-04-03 14:19:27 +04:00
|
|
|
if (client && !client->isOnScreen(m_current)) {
|
|
|
|
return client->screen();
|
|
|
|
}
|
|
|
|
return m_current;
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:04:17 +04: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 10:18:10 +03:00
|
|
|
BasicScreens::BasicScreens(Platform *backend, QObject *parent)
|
2015-11-17 12:32:06 +03:00
|
|
|
: Screens(parent)
|
|
|
|
, m_backend(backend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicScreens::~BasicScreens() = default;
|
|
|
|
|
|
|
|
void BasicScreens::init()
|
|
|
|
{
|
|
|
|
KWin::Screens::init();
|
|
|
|
#ifndef KWIN_UNIT_TEST
|
2016-04-07 10:18:10 +03:00
|
|
|
connect(m_backend, &Platform::screenSizeChanged,
|
2015-11-17 12:32:06 +03:00
|
|
|
this, &BasicScreens::startChangedTimer);
|
|
|
|
#endif
|
|
|
|
updateCount();
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect BasicScreens::geometry(int screen) const
|
|
|
|
{
|
2015-11-20 18:11:35 +03:00
|
|
|
if (screen < m_geometries.count()) {
|
|
|
|
return m_geometries.at(screen);
|
2015-11-17 12:32:06 +03:00
|
|
|
}
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize BasicScreens::size(int screen) const
|
|
|
|
{
|
2015-11-20 18:11:35 +03:00
|
|
|
if (screen < m_geometries.count()) {
|
|
|
|
return m_geometries.at(screen).size();
|
2015-11-17 12:32:06 +03:00
|
|
|
}
|
|
|
|
return QSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicScreens::updateCount()
|
|
|
|
{
|
2015-11-20 18:11:35 +03:00
|
|
|
m_geometries = m_backend->screenGeometries();
|
|
|
|
setCount(m_geometries.count());
|
2015-11-17 12:32:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int BasicScreens::number(const QPoint &pos) const
|
|
|
|
{
|
2015-11-20 18:11:35 +03: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 12:32:06 +03:00
|
|
|
}
|
|
|
|
|
2013-04-03 14:19:27 +04:00
|
|
|
} // namespace
|