Changeset View
Changeset View
Standalone View
Standalone View
screens.cpp
Show First 20 Lines • Show All 240 Lines • ▼ Show 20 Line(s) | |||||
241 | void Screens::setConfig(KSharedConfig::Ptr config) | 241 | void Screens::setConfig(KSharedConfig::Ptr config) | ||
242 | { | 242 | { | ||
243 | m_config = config; | 243 | m_config = config; | ||
244 | if (m_orientationSensor) { | 244 | if (m_orientationSensor) { | ||
245 | m_orientationSensor->setConfig(config); | 245 | m_orientationSensor->setConfig(config); | ||
246 | } | 246 | } | ||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | BasicScreens::BasicScreens(Platform *backend, QObject *parent) | | |||
250 | : Screens(parent) | | |||
251 | , m_backend(backend) | | |||
252 | { | | |||
253 | } | | |||
254 | | ||||
255 | BasicScreens::~BasicScreens() = default; | | |||
256 | | ||||
257 | void BasicScreens::init() | | |||
258 | { | | |||
259 | updateCount(); | | |||
260 | KWin::Screens::init(); | | |||
261 | #ifndef KWIN_UNIT_TEST | | |||
262 | connect(m_backend, &Platform::screenSizeChanged, | | |||
263 | this, &BasicScreens::startChangedTimer); | | |||
264 | #endif | | |||
265 | emit changed(); | | |||
266 | } | | |||
267 | | ||||
268 | QRect BasicScreens::geometry(int screen) const | | |||
269 | { | | |||
270 | if (screen < m_geometries.count()) { | | |||
271 | return m_geometries.at(screen); | | |||
272 | } | | |||
273 | return QRect(); | | |||
274 | } | | |||
275 | | ||||
276 | QSize BasicScreens::size(int screen) const | | |||
277 | { | | |||
278 | if (screen < m_geometries.count()) { | | |||
279 | return m_geometries.at(screen).size(); | | |||
280 | } | | |||
281 | return QSize(); | | |||
282 | } | | |||
283 | | ||||
284 | qreal BasicScreens::scale(int screen) const | | |||
285 | { | | |||
286 | if (screen < m_scales.count()) { | | |||
287 | return m_scales.at(screen); | | |||
288 | } | | |||
289 | return 1; | | |||
290 | } | | |||
291 | | ||||
292 | void BasicScreens::updateCount() | | |||
293 | { | | |||
294 | m_geometries = m_backend->screenGeometries(); | | |||
295 | m_scales = m_backend->screenScales(); | | |||
296 | setCount(m_geometries.count()); | | |||
297 | } | | |||
298 | | ||||
299 | int BasicScreens::number(const QPoint &pos) const | | |||
300 | { | | |||
301 | int bestScreen = 0; | | |||
302 | int minDistance = INT_MAX; | | |||
303 | for (int i = 0; i < m_geometries.count(); ++i) { | | |||
304 | const QRect &geo = m_geometries.at(i); | | |||
305 | if (geo.contains(pos)) { | | |||
306 | return i; | | |||
307 | } | | |||
308 | int distance = QPoint(geo.topLeft() - pos).manhattanLength(); | | |||
309 | distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength()); | | |||
310 | distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength()); | | |||
311 | distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength()); | | |||
312 | if (distance < minDistance) { | | |||
313 | minDistance = distance; | | |||
314 | bestScreen = i; | | |||
315 | } | | |||
316 | } | | |||
317 | return bestScreen; | | |||
318 | } | | |||
319 | | ||||
320 | } // namespace | 249 | } // namespace |