Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/virtual/screens_virtual.cpp
Show All 19 Lines | |||||
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 | #include "virtual_output.h" | ||
23 | 23 | | |||
24 | namespace KWin | 24 | namespace KWin | ||
25 | { | 25 | { | ||
26 | 26 | | |||
27 | VirtualScreens::VirtualScreens(VirtualBackend *backend, QObject *parent) | 27 | VirtualScreens::VirtualScreens(VirtualBackend *backend, QObject *parent) | ||
28 | : Screens(parent) | 28 | : OutputScreens(backend, parent) | ||
29 | , m_backend(backend) | 29 | , m_backend(backend) | ||
30 | { | 30 | { | ||
31 | } | 31 | } | ||
32 | 32 | | |||
33 | VirtualScreens::~VirtualScreens() = default; | 33 | VirtualScreens::~VirtualScreens() = default; | ||
34 | 34 | | |||
35 | void VirtualScreens::init() | 35 | void VirtualScreens::init() | ||
36 | { | 36 | { | ||
37 | updateCount(); | 37 | updateCount(); | ||
38 | KWin::Screens::init(); | 38 | KWin::Screens::init(); | ||
39 | 39 | | |||
40 | connect(m_backend, &VirtualBackend::virtualOutputsSet, this, | 40 | connect(m_backend, &VirtualBackend::virtualOutputsSet, this, | ||
41 | [this] (bool countChanged) { | 41 | [this] (bool countChanged) { | ||
42 | if (countChanged) { | 42 | if (countChanged) { | ||
43 | setCount(m_backend->outputCount()); | 43 | setCount(m_backend->outputs().size()); | ||
44 | } else { | 44 | } else { | ||
45 | emit changed(); | 45 | emit changed(); | ||
46 | } | 46 | } | ||
47 | } | 47 | } | ||
48 | ); | 48 | ); | ||
49 | 49 | | |||
50 | emit changed(); | 50 | emit changed(); | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | QRect VirtualScreens::geometry(int screen) const | | |||
54 | { | | |||
55 | const auto outputs = m_backend->outputs(); | | |||
56 | if (screen >= outputs.size()) { | | |||
57 | return QRect(); | | |||
58 | } | | |||
59 | return outputs.at(screen)->geometry(); | | |||
60 | } | | |||
61 | | ||||
62 | QSize VirtualScreens::size(int screen) const | | |||
63 | { | | |||
64 | return geometry(screen).size(); | | |||
65 | } | | |||
66 | | ||||
67 | void VirtualScreens::updateCount() | | |||
68 | { | | |||
69 | setCount(m_backend->outputCount()); | | |||
70 | } | | |||
71 | | ||||
72 | int VirtualScreens::number(const QPoint &pos) const | | |||
73 | { | | |||
74 | int bestScreen = 0; | | |||
75 | int minDistance = INT_MAX; | | |||
76 | const auto outputs = m_backend->outputs(); | | |||
77 | for (int i = 0; i < outputs.size(); ++i) { | | |||
78 | const QRect &geo = outputs.at(i)->geometry(); | | |||
79 | if (geo.contains(pos)) { | | |||
80 | return i; | | |||
81 | } | | |||
82 | int distance = QPoint(geo.topLeft() - pos).manhattanLength(); | | |||
83 | distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength()); | | |||
84 | distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength()); | | |||
85 | distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength()); | | |||
86 | if (distance < minDistance) { | | |||
87 | minDistance = distance; | | |||
88 | bestScreen = i; | | |||
89 | } | | |||
90 | } | | |||
91 | return bestScreen; | | |||
92 | } | | |||
93 | | ||||
94 | } | 53 | } |