~ubuntu-branches/ubuntu/wily/kwin/wily-proposed

« back to all changes in this revision

Viewing changes to backends/drm/screens_drm.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-08-10 23:16:37 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150810231637-5zb2tstjkez93hml
Tags: 4:5.3.95-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
#include "screens_drm.h"
 
21
#include "drm_backend.h"
 
22
 
 
23
namespace KWin
 
24
{
 
25
 
 
26
DrmScreens::DrmScreens(DrmBackend *backend, QObject *parent)
 
27
    : Screens(parent)
 
28
    , m_backend(backend)
 
29
{
 
30
    connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::updateCount);
 
31
    connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::changed);
 
32
}
 
33
 
 
34
DrmScreens::~DrmScreens() = default;
 
35
 
 
36
void DrmScreens::init()
 
37
{
 
38
    KWin::Screens::init();
 
39
    updateCount();
 
40
    emit changed();
 
41
}
 
42
 
 
43
QRect DrmScreens::geometry(int screen) const
 
44
{
 
45
    const auto outputs = m_backend->outputs();
 
46
    if (screen >= outputs.size()) {
 
47
        return QRect();
 
48
    }
 
49
    return outputs.at(screen)->geometry();
 
50
}
 
51
 
 
52
QSize DrmScreens::size(int screen) const
 
53
{
 
54
    const auto outputs = m_backend->outputs();
 
55
    if (screen >= outputs.size()) {
 
56
        return QSize();
 
57
    }
 
58
    return outputs.at(screen)->size();
 
59
}
 
60
 
 
61
void DrmScreens::updateCount()
 
62
{
 
63
    setCount(m_backend->outputs().size());
 
64
}
 
65
 
 
66
int DrmScreens::number(const QPoint &pos) const
 
67
{
 
68
    int bestScreen = 0;
 
69
    int minDistance = INT_MAX;
 
70
    const auto outputs = m_backend->outputs();
 
71
    for (int i = 0; i < outputs.size(); ++i) {
 
72
        const QRect &geo = outputs.at(i)->geometry();
 
73
        if (geo.contains(pos)) {
 
74
            return i;
 
75
        }
 
76
        int distance = QPoint(geo.topLeft() - pos).manhattanLength();
 
77
        distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength());
 
78
        distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength());
 
79
        distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength());
 
80
        if (distance < minDistance) {
 
81
            minDistance = distance;
 
82
            bestScreen = i;
 
83
        }
 
84
    }
 
85
    return bestScreen;
 
86
}
 
87
 
 
88
QString DrmScreens::name(int screen) const
 
89
{
 
90
    const auto outputs = m_backend->outputs();
 
91
    if (screen >= outputs.size()) {
 
92
        return Screens::name(screen);
 
93
    }
 
94
    return outputs.at(screen)->name();
 
95
}
 
96
 
 
97
float DrmScreens::refreshRate(int screen) const
 
98
{
 
99
    const auto outputs = m_backend->outputs();
 
100
    if (screen >= outputs.size()) {
 
101
        return Screens::refreshRate(screen);
 
102
    }
 
103
    return outputs.at(screen)->currentRefreshRate() / 1000.0f;
 
104
}
 
105
 
 
106
}