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