Plasma-workspace

mirroredscreenstracker.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "mirroredscreenstracker_p.h"
8
9#include <QGuiApplication>
10#include <QRect>
11#include <QScreen>
12
13#include "debug.h"
14
15using namespace NotificationManager;
16
17MirroredScreensTracker::MirroredScreensTracker()
18 : QObject(nullptr)
19{
20 checkScreensMirrored();
21 const QList<QScreen *> screens = qApp->screens();
22 for (const QScreen *screen : screens) {
23 connect(screen, &QScreen::geometryChanged, this, &MirroredScreensTracker::checkScreensMirrored);
24 }
25
26 connect(qApp, &QGuiApplication::screenAdded, this, [this](QScreen *screen) {
27 connect(screen, &QScreen::geometryChanged, this, &MirroredScreensTracker::checkScreensMirrored);
28 checkScreensMirrored();
29 });
30 connect(qApp, &QGuiApplication::screenRemoved, this, &MirroredScreensTracker::checkScreensMirrored);
31}
32
33MirroredScreensTracker::~MirroredScreensTracker() = default;
34
35MirroredScreensTracker::Ptr MirroredScreensTracker::createTracker()
36{
37 static std::weak_ptr<MirroredScreensTracker> s_instance;
38 if (s_instance.expired()) {
39 std::shared_ptr<MirroredScreensTracker> ptr(new MirroredScreensTracker());
40 s_instance = ptr;
41 return ptr;
42 }
43 return s_instance.lock();
44}
45
46bool MirroredScreensTracker::screensMirrored() const
47{
48 return m_screensMirrored;
49}
50
51void MirroredScreensTracker::setScreensMirrored(bool mirrored)
52{
53 if (m_screensMirrored != mirrored) {
54 m_screensMirrored = mirrored;
55 Q_EMIT screensMirroredChanged(mirrored);
56 }
57}
58
59void MirroredScreensTracker::checkScreensMirrored()
60{
61 const QList<QScreen *> screens = qApp->screens();
62
63 for (const QScreen *screen : screens) {
64 for (const QScreen *checkScreen : screens) {
65 if (screen == checkScreen) {
66 continue;
67 }
68 if (screen->geometry().contains(checkScreen->geometry()) || checkScreen->geometry().contains(screen->geometry())) {
69 qCDebug(NOTIFICATIONMANAGER) << "Screen geometry" << checkScreen->geometry() << "and" << screen->geometry()
70 << "are completely overlapping - considering them to be mirrored";
71 setScreensMirrored(true);
72 return;
73 }
74 }
75 }
76
77 setScreensMirrored(false);
78}
void screenAdded(QScreen *screen)
void screenRemoved(QScreen *screen)
void geometryChanged(const QRect &geometry)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.