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"
|
2014-09-17 08:29:03 +00:00
|
|
|
#include <client.h>
|
2013-04-03 10:19:27 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#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>
|
2014-04-17 15:33:11 +00:00
|
|
|
#include "screens_xrandr.h"
|
2013-07-05 09:26:48 +00:00
|
|
|
#if HAVE_WAYLAND
|
2014-09-17 07:05:11 +00:00
|
|
|
#include "screens_wayland.h"
|
2013-07-05 09:26:48 +00:00
|
|
|
#endif
|
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
|
2013-07-05 09:26:48 +00:00
|
|
|
#if HAVE_WAYLAND
|
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeWaylandAndX11) {
|
|
|
|
s_self = new WaylandScreens(parent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
2014-04-17 15:33:11 +00:00
|
|
|
s_self = new XRandRScreens(parent);
|
2013-07-05 09:26:48 +00:00
|
|
|
}
|
2014-09-17 08:29:03 +00:00
|
|
|
#endif
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screens::setCurrent(const Client *c)
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
Client *client = Workspace::self()->activeClient();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-03 10:19:27 +00:00
|
|
|
} // namespace
|