1 #include "layouthandler.h"
4 LayoutHandler::LayoutHandler(QObject *parent) :
7 mp_dBusWindowManagerProxy(0),
10 m_invisibleSurfaces(),
11 m_requestsToBeVisibleSurfaces()
13 qDBusRegisterMetaType<SimplePoint>();
14 qDBusRegisterMetaType<QList<SimplePoint> >();
15 qDBusRegisterMetaType<LayoutArea>();
16 qDBusRegisterMetaType<QList<LayoutArea> >();
17 qDBusRegisterMetaType<Layout>();
18 qDBusRegisterMetaType<QList<Layout> >();
20 qDebug("D-Bus: connect to org.agl.windowmanager /windowmanager");
21 mp_dBusWindowManagerProxy = new org::agl::windowmanager("org.agl.windowmanager",
23 QDBusConnection::sessionBus(),
25 qDebug("D-Bus: connect to org.agl.homescreen /Popup");
26 mp_dBusPopupProxy = new org::agl::popup("org.agl.homescreen",
28 QDBusConnection::sessionBus(),
31 QDBusConnection::sessionBus().connect("org.agl.windowmanager",
33 "org.agl.windowmanager",
34 "surfaceVisibilityChanged",
36 SIGNAL(surfaceVisibilityChanged(int,bool)));
39 LayoutHandler::~LayoutHandler()
41 delete mp_dBusPopupProxy;
42 delete mp_dBusWindowManagerProxy;
45 void LayoutHandler::setUpLayouts()
47 qDebug("setUpLayouts");
48 QList<LayoutArea> surfaceAreas;
49 LayoutArea surfaceArea;
51 const int SCREEN_WIDTH = 1080;
52 const int SCREEN_HEIGHT = 1920;
54 const int STATUSBAR_HEIGHT = 60;
55 const int STATUSBAR_WIDTH = SCREEN_WIDTH;
56 const int STATUSBAR_X = 0;
57 const int STATUSBAR_Y = 0;
58 const int CONTROLBAR_HEIGHT = 60;
59 const int CONTROLBAR_WIDTH = SCREEN_WIDTH;
60 const int CONTROLBAR_X = 0;
61 const int CONTROLBAR_Y = SCREEN_HEIGHT - CONTROLBAR_HEIGHT;
64 // only one Layout for CES2017 needed
66 // one app surface, statusbar, control bar
68 surfaceArea.y = STATUSBAR_HEIGHT;
69 surfaceArea.width = SCREEN_WIDTH;
70 surfaceArea.height = SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT;
72 surfaceAreas.append(surfaceArea);
74 mp_dBusWindowManagerProxy->addLayout(1, "one app", surfaceAreas);
80 // two app surfaces (one on top of the other), statusbar, control bar
84 surfaceArea.y = STATUSBAR_HEIGHT;
85 surfaceArea.width = SCREEN_WIDTH;
86 surfaceArea.height = (SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT) / 2;
88 surfaceAreas.append(surfaceArea);
92 surfaceArea.y = SCREEN_HEIGHT / 2;
93 surfaceArea.width = SCREEN_WIDTH;
94 surfaceArea.height = (SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT) / 2;
96 surfaceAreas.append(surfaceArea);
98 mp_dBusWindowManagerProxy->addLayout(2, "top on bottom", surfaceAreas);
101 surfaceAreas.clear();
104 // two app surfaces (one besides the other), statusbar, control bar
108 surfaceArea.y = STATUSBAR_HEIGHT;
109 surfaceArea.width = SCREEN_WIDTH / 2;
110 surfaceArea.height = SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT;
112 surfaceAreas.append(surfaceArea);
115 surfaceArea.x = SCREEN_WIDTH / 2;
116 surfaceArea.y = STATUSBAR_HEIGHT;
117 surfaceArea.width = SCREEN_WIDTH / 2;
118 surfaceArea.height = SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT;
120 surfaceAreas.append(surfaceArea);
122 mp_dBusWindowManagerProxy->addLayout(3, "side by side", surfaceAreas);*/
125 void LayoutHandler::showAppLayer()
127 // POPUP=0, HOMESCREEN_OVERLAY=1, APPS=2, HOMESCREEN=3
128 mp_dBusWindowManagerProxy->showLayer(2); // TODO: enum
131 void LayoutHandler::hideAppLayer()
133 // POPUP=0, HOMESCREEN_OVERLAY=1, APPS=2, HOMESCREEN=3
134 mp_dBusWindowManagerProxy->hideLayer(2); // TODO: enum
137 void LayoutHandler::makeMeVisible(int pid)
139 qDebug("makeMeVisible %d", pid);
141 m_requestsToBeVisiblePids.append(pid);
143 // callback every second
144 if (-1 != m_secondsTimerId)
146 killTimer(m_secondsTimerId);
147 m_secondsTimerId = -1;
149 m_secondsTimerId = startTimer(1000);
152 void LayoutHandler::checkToDoQueue()
154 if ((-1 != m_secondsTimerId) && (0 == m_requestsToBeVisiblePids.size()))
156 killTimer(m_secondsTimerId);
157 m_secondsTimerId = -1;
160 if (0 != m_requestsToBeVisiblePids.size())
162 int pid = m_requestsToBeVisiblePids.at(0);
163 qDebug("pid %d wants to be visible", pid);
165 QList<int> allSurfaces;
166 allSurfaces = mp_dBusWindowManagerProxy->getAllSurfacesOfProcess(pid);
167 if (0 == allSurfaces.size())
169 qDebug("no surfaces for pid %d. retrying!", pid);
173 m_requestsToBeVisiblePids.removeAt(0);
176 if (0 != allSurfaces.size())
178 if (-1 == m_visibleSurfaces.indexOf(allSurfaces.at(0)))
180 qDebug("already visible");
182 if (-1 == m_invisibleSurfaces.indexOf(allSurfaces.at(0)))
184 m_invisibleSurfaces.removeAt(m_invisibleSurfaces.indexOf(allSurfaces.at(0)));
186 if (-1 == m_requestsToBeVisibleSurfaces.indexOf(allSurfaces.at(0)))
188 m_requestsToBeVisibleSurfaces.append(allSurfaces.at(0));
191 qDebug("m_visibleSurfaces %d", m_visibleSurfaces.size());
192 qDebug("m_invisibleSurfaces %d", m_invisibleSurfaces.size());
193 qDebug("m_requestsToBeVisibleSurfaces %d", m_requestsToBeVisibleSurfaces.size());
195 QList<int> availableLayouts = mp_dBusWindowManagerProxy->getAvailableLayouts(1); // one app only for CES2017
196 if (1 == availableLayouts.size())
198 qDebug("active layout: %d", availableLayouts.at(0));
199 m_invisibleSurfaces.append(m_visibleSurfaces);
200 m_visibleSurfaces.clear();
201 m_visibleSurfaces.append(m_requestsToBeVisibleSurfaces);
202 m_requestsToBeVisibleSurfaces.clear();
204 mp_dBusWindowManagerProxy->setLayoutById(availableLayouts.at(0));
205 for (int i = 0; i < m_visibleSurfaces.size(); ++i)
207 mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(m_visibleSurfaces.at(i), i);
212 qDebug("this should not happen!?");
219 QList<int> LayoutHandler::requestGetAllSurfacesOfProcess(int pid)
221 qDebug("requestGetAllSurfacesOfProcess %d", pid);
223 return mp_dBusWindowManagerProxy->getAllSurfacesOfProcess(pid);
226 int LayoutHandler::requestGetSurfaceStatus(int surfaceId)
230 if (-1 != m_visibleSurfaces.indexOf(surfaceId))
234 if (-1 != m_invisibleSurfaces.indexOf(surfaceId))
238 if (-1 != m_requestsToBeVisibleSurfaces.indexOf(surfaceId))
246 void LayoutHandler::requestRenderSurfaceToArea(int surfaceId, int layoutArea)
248 qDebug("requestRenderSurfaceToArea %d %d", surfaceId, layoutArea);
251 bool LayoutHandler::requestRenderSurfaceToAreaAllowed(int surfaceId, int layoutArea)
253 qDebug("requestRenderSurfaceToAreaAllowed %d %d", surfaceId, layoutArea);
258 void LayoutHandler::requestSurfaceIdToFullScreen(int surfaceId)
260 qDebug("requestSurfaceIdToFullScreen %d", surfaceId);
263 void LayoutHandler::setLayoutByName(QString layoutName)
265 // switch to new layout
266 qDebug("setLayout: switch to new layout %s", layoutName.toStdString().c_str());
267 m_visibleSurfaces.append(m_requestsToBeVisibleSurfaces);
268 m_requestsToBeVisibleSurfaces.clear();
270 mp_dBusWindowManagerProxy->setLayoutByName(layoutName);
271 for (int i = 0; i < m_visibleSurfaces.size(); ++i)
273 mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(i, i);
277 void LayoutHandler::requestSurfaceVisibilityChanged(int surfaceId, bool visible)
279 qDebug("requestSurfaceVisibilityChanged %d %s", surfaceId, visible ? "true" : "false");
280 emit surfaceVisibilityChanged(surfaceId, visible);
283 void LayoutHandler::timerEvent(QTimerEvent *e)
285 if (e->timerId() == m_secondsTimerId)