1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
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.
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.
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"
26
DrmScreens::DrmScreens(DrmBackend *backend, QObject *parent)
30
connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::updateCount);
31
connect(backend, &DrmBackend::screensQueried, this, &DrmScreens::changed);
34
DrmScreens::~DrmScreens() = default;
36
void DrmScreens::init()
38
KWin::Screens::init();
43
QRect DrmScreens::geometry(int screen) const
45
const auto outputs = m_backend->outputs();
46
if (screen >= outputs.size()) {
49
return outputs.at(screen)->geometry();
52
QSize DrmScreens::size(int screen) const
54
const auto outputs = m_backend->outputs();
55
if (screen >= outputs.size()) {
58
return outputs.at(screen)->size();
61
void DrmScreens::updateCount()
63
setCount(m_backend->outputs().size());
66
int DrmScreens::number(const QPoint &pos) const
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)) {
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;
88
QString DrmScreens::name(int screen) const
90
const auto outputs = m_backend->outputs();
91
if (screen >= outputs.size()) {
92
return Screens::name(screen);
94
return outputs.at(screen)->name();
97
float DrmScreens::refreshRate(int screen) const
99
const auto outputs = m_backend->outputs();
100
if (screen >= outputs.size()) {
101
return Screens::refreshRate(screen);
103
return outputs.at(screen)->currentRefreshRate() / 1000.0f;