Changeset View
Changeset View
Standalone View
Standalone View
shell/strutmanager.cpp
- This file was added.
1 | #include "strutmanager.h" | ||||
---|---|---|---|---|---|
2 | #include "shellcorona.h" | ||||
3 | #include "screenpool.h" | ||||
4 | | ||||
5 | #include <QDBusMetaType> | ||||
6 | #include <QDBusConnection> | ||||
7 | #include <QDBusServiceWatcher> | ||||
8 | #include <QDBusConnectionInterface> | ||||
9 | | ||||
10 | StrutManager::StrutManager(ShellCorona *plasmashellCorona) : QObject(plasmashellCorona), | ||||
11 | m_plasmashellCorona(plasmashellCorona), | ||||
12 | m_serviceWatcher(new QDBusServiceWatcher(this)) | ||||
13 | { | ||||
14 | qDBusRegisterMetaType<QList<QRect>>(); | ||||
15 | | ||||
16 | QDBusConnection dbus = QDBusConnection::sessionBus(); | ||||
17 | dbus.registerObject("/StrutManager", this, QDBusConnection::ExportAllSlots); | ||||
18 | m_serviceWatcher->setConnection(dbus); | ||||
19 | | ||||
20 | connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, [=](const QString &service) { | ||||
21 | m_availableScreenRects.remove(service); | ||||
22 | m_availableScreenRegions.remove(service); | ||||
23 | m_serviceWatcher->removeWatchedService(service); | ||||
24 | | ||||
25 | emit m_plasmashellCorona->availableScreenRectChanged(); | ||||
26 | }); | ||||
27 | } | ||||
28 | | ||||
29 | QRect StrutManager::availableScreenRect(int id) const | ||||
30 | { | ||||
31 | QRect r = m_plasmashellCorona->_availableScreenRect(id); | ||||
32 | QHash<int, QRect> service; | ||||
33 | foreach (service, m_availableScreenRects) { | ||||
34 | if (!service.value(id).isNull()) { | ||||
35 | r &= service[id]; | ||||
36 | } | ||||
37 | } | ||||
38 | return r; | ||||
39 | } | ||||
40 | | ||||
41 | QRegion StrutManager::availableScreenRegion(int id) const | ||||
42 | { | ||||
43 | QRegion r = m_plasmashellCorona->_availableScreenRegion(id); | ||||
44 | QHash<int, QRegion> service; | ||||
45 | foreach (service, m_availableScreenRegions) { | ||||
46 | if (!service.value(id).isNull()) { | ||||
47 | r &= service[id]; | ||||
48 | } | ||||
49 | } | ||||
50 | return r; | ||||
51 | } | ||||
52 | | ||||
53 | void StrutManager::setAvailableScreenRect(const QString &service, const QString &screenName, const QRect &rect) { | ||||
54 | int id = m_plasmashellCorona->screenPool()->id(screenName); | ||||
55 | if (id == -1 || m_availableScreenRects.value(service).value(id) == rect || !addWatchedService(service)) { | ||||
56 | return; | ||||
57 | } | ||||
58 | m_availableScreenRects[service][id] = rect; | ||||
59 | emit m_plasmashellCorona->availableScreenRectChanged(); | ||||
60 | } | ||||
61 | | ||||
62 | void StrutManager::setAvailableScreenRegion(const QString &service, const QString &screenName, const QList<QRect> &rects) { | ||||
63 | int id = m_plasmashellCorona->screenPool()->id(screenName); | ||||
64 | QRegion region; | ||||
65 | foreach(QRect rect, rects) { | ||||
66 | region += rect; | ||||
67 | } | ||||
68 | | ||||
69 | if (id == -1 || m_availableScreenRegions.value(service).value(id) == region || !addWatchedService(service)) { | ||||
70 | return; | ||||
71 | } | ||||
72 | m_availableScreenRegions[service][id] = region; | ||||
73 | emit m_plasmashellCorona->availableScreenRegionChanged(); | ||||
74 | } | ||||
75 | | ||||
76 | bool StrutManager::addWatchedService(const QString &service) { | ||||
77 | if (!m_serviceWatcher->watchedServices().contains(service)) { | ||||
78 | if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(service)) { | ||||
79 | return false; | ||||
80 | } | ||||
81 | m_serviceWatcher->addWatchedService(service); | ||||
82 | } | ||||
83 | return true; | ||||
84 | } | ||||
85 | | ||||
86 | void StrutManager::test(QString service, QString screenName, int x, int y, int width, int height) { | ||||
87 | setAvailableScreenRect(service, screenName, QRect(x, y, width, height)); | ||||
88 | } |