Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/virtual/screens_virtual.cpp
Show All 13 Lines | |||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 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/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "screens_virtual.h" | 20 | #include "screens_virtual.h" | ||
21 | #include "virtual_backend.h" | 21 | #include "virtual_backend.h" | ||
22 | #include "virtual_output.h" | ||||
22 | 23 | | |||
23 | namespace KWin | 24 | namespace KWin | ||
24 | { | 25 | { | ||
25 | 26 | | |||
26 | VirtualScreens::VirtualScreens(VirtualBackend *backend, QObject *parent) | 27 | VirtualScreens::VirtualScreens(VirtualBackend *backend, QObject *parent) | ||
27 | : Screens(parent) | 28 | : Screens(parent) | ||
28 | , m_backend(backend) | 29 | , m_backend(backend) | ||
29 | { | 30 | { | ||
30 | } | 31 | } | ||
31 | 32 | | |||
32 | VirtualScreens::~VirtualScreens() = default; | 33 | VirtualScreens::~VirtualScreens() = default; | ||
33 | 34 | | |||
34 | void VirtualScreens::init() | 35 | void VirtualScreens::init() | ||
35 | { | 36 | { | ||
36 | updateCount(); | 37 | updateCount(); | ||
37 | KWin::Screens::init(); | 38 | KWin::Screens::init(); | ||
38 | connect(m_backend, &VirtualBackend::sizeChanged, | 39 | | ||
39 | this, &VirtualScreens::startChangedTimer); | 40 | connect(m_backend, &VirtualBackend::virtualOutputsSet, this, | ||
40 | connect(m_backend, &VirtualBackend::outputGeometriesChanged, this, | 41 | [this] (bool countChanged) { | ||
41 | [this] (const QVector<QRect> &geometries) { | 42 | if (countChanged) { | ||
42 | const int oldCount = m_geometries.count(); | 43 | setCount(m_backend->outputCount()); | ||
43 | m_geometries = geometries; | | |||
44 | if (oldCount != m_geometries.count()) { | | |||
45 | setCount(m_geometries.count()); | | |||
46 | } else { | 44 | } else { | ||
47 | emit changed(); | 45 | emit changed(); | ||
48 | } | 46 | } | ||
49 | } | 47 | } | ||
50 | ); | 48 | ); | ||
49 | | ||||
51 | emit changed(); | 50 | emit changed(); | ||
52 | } | 51 | } | ||
53 | 52 | | |||
54 | QRect VirtualScreens::geometry(int screen) const | 53 | QRect VirtualScreens::geometry(int screen) const | ||
55 | { | 54 | { | ||
56 | if (screen >= m_geometries.count()) { | 55 | const auto outputs = m_backend->outputs(); | ||
56 | if (screen >= outputs.size()) { | ||||
57 | return QRect(); | 57 | return QRect(); | ||
58 | } | 58 | } | ||
59 | return m_geometries.at(screen); | 59 | return outputs.at(screen).geometry(); | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | QSize VirtualScreens::size(int screen) const | 62 | QSize VirtualScreens::size(int screen) const | ||
63 | { | 63 | { | ||
64 | return geometry(screen).size(); | 64 | return geometry(screen).size(); | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | void VirtualScreens::updateCount() | 67 | void VirtualScreens::updateCount() | ||
68 | { | 68 | { | ||
69 | m_geometries.clear(); | | |||
70 | const QSize size = m_backend->size(); | | |||
71 | for (int i = 0; i < m_backend->outputCount(); ++i) { | | |||
72 | m_geometries.append(QRect(size.width() * i, 0, size.width(), size.height())); | | |||
73 | } | | |||
74 | setCount(m_backend->outputCount()); | 69 | setCount(m_backend->outputCount()); | ||
75 | } | 70 | } | ||
76 | 71 | | |||
77 | int VirtualScreens::number(const QPoint &pos) const | 72 | int VirtualScreens::number(const QPoint &pos) const | ||
78 | { | 73 | { | ||
79 | int bestScreen = 0; | 74 | int bestScreen = 0; | ||
80 | int minDistance = INT_MAX; | 75 | int minDistance = INT_MAX; | ||
81 | for (int i = 0; i < m_geometries.count(); ++i) { | 76 | const auto outputs = m_backend->outputs(); | ||
82 | const QRect &geo = m_geometries.at(i); | 77 | for (int i = 0; i < outputs.size(); ++i) { | ||
78 | const QRect &geo = outputs.at(i).geometry(); | ||||
83 | if (geo.contains(pos)) { | 79 | if (geo.contains(pos)) { | ||
84 | return i; | 80 | return i; | ||
85 | } | 81 | } | ||
86 | int distance = QPoint(geo.topLeft() - pos).manhattanLength(); | 82 | int distance = QPoint(geo.topLeft() - pos).manhattanLength(); | ||
87 | distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength()); | 83 | distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength()); | ||
88 | distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength()); | 84 | distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength()); | ||
89 | distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength()); | 85 | distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength()); | ||
90 | if (distance < minDistance) { | 86 | if (distance < minDistance) { | ||
91 | minDistance = distance; | 87 | minDistance = distance; | ||
92 | bestScreen = i; | 88 | bestScreen = i; | ||
93 | } | 89 | } | ||
94 | } | 90 | } | ||
95 | return bestScreen; | 91 | return bestScreen; | ||
96 | } | 92 | } | ||
97 | 93 | | |||
98 | } | 94 | } |