2 * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "layouthandler.h"
18 #include <QTimerEvent>
20 LayoutHandler::LayoutHandler(QObject *parent) :
23 mp_dBusWindowManagerProxy(0),
26 m_invisibleSurfaces(),
27 m_requestsToBeVisibleSurfaces()
29 qDBusRegisterMetaType<SimplePoint>();
30 qDBusRegisterMetaType<QList<SimplePoint> >();
31 qDBusRegisterMetaType<LayoutArea>();
32 qDBusRegisterMetaType<QList<LayoutArea> >();
33 qDBusRegisterMetaType<Layout>();
34 qDBusRegisterMetaType<QList<Layout> >();
36 qDebug("D-Bus: connect to org.agl.windowmanager /windowmanager");
37 mp_dBusWindowManagerProxy = new org::agl::windowmanager("org.agl.windowmanager",
39 QDBusConnection::sessionBus(),
41 qDebug("D-Bus: connect to org.agl.homescreen /Popup");
42 mp_dBusPopupProxy = new org::agl::popup("org.agl.homescreen",
44 QDBusConnection::sessionBus(),
47 QDBusConnection::sessionBus().connect("org.agl.windowmanager",
49 "org.agl.windowmanager",
50 "surfaceVisibilityChanged",
52 SIGNAL(surfaceVisibilityChanged(int,bool)));
54 QList<LayoutArea> surfaceAreas;
55 LayoutArea surfaceArea;
57 const int SCREEN_WIDTH = 1080;
58 const int SCREEN_HEIGHT = 1920;
60 const int TOPAREA_HEIGHT = 218;
61 const int TOPAREA_WIDTH = SCREEN_WIDTH;
62 const int TOPAREA_X = 0;
63 const int TOPAREA_Y = 0;
64 const int MEDIAAREA_HEIGHT = 215;
65 const int MEDIAAREA_WIDTH = SCREEN_WIDTH;
66 const int MEDIAAREA_X = 0;
67 const int MEDIAAREA_Y = SCREEN_HEIGHT - MEDIAAREA_HEIGHT;
70 // only one Layout for CES2017 needed
72 // one app surface, statusbar, control bar
74 surfaceArea.y = TOPAREA_HEIGHT;
75 surfaceArea.width = SCREEN_WIDTH;
76 surfaceArea.height = SCREEN_HEIGHT - TOPAREA_HEIGHT - MEDIAAREA_HEIGHT;
78 surfaceAreas.append(surfaceArea);
80 mp_dBusWindowManagerProxy->addLayout(1, "one app", surfaceAreas);
83 LayoutHandler::~LayoutHandler()
85 delete mp_dBusPopupProxy;
86 delete mp_dBusWindowManagerProxy;
89 void LayoutHandler::showAppLayer(int pid)
91 mp_dBusWindowManagerProxy->showAppLayer(pid);
94 void LayoutHandler::hideAppLayer()
96 // POPUP=0, HOMESCREEN_OVERLAY=1, APPS=2, HOMESCREEN=3
97 mp_dBusWindowManagerProxy->hideLayer(2); // TODO: enum
100 void LayoutHandler::makeMeVisible(int pid)
102 qDebug("makeMeVisible %d", pid);
105 // if app does not request to be visible
106 if (-1 == m_requestsToBeVisiblePids.indexOf(pid))
108 m_requestsToBeVisiblePids.append(pid);
110 // callback every second
111 if (-1 != m_secondsTimerId)
113 killTimer(m_secondsTimerId);
114 m_secondsTimerId = -1;
116 m_secondsTimerId = startTimer(1000);
125 void LayoutHandler::checkToDoQueue()
128 if ((-1 != m_secondsTimerId) && (0 == m_requestsToBeVisiblePids.size()))
130 killTimer(m_secondsTimerId);
131 m_secondsTimerId = -1;
134 if (0 != m_requestsToBeVisiblePids.size())
136 int pid = m_requestsToBeVisiblePids.at(0);
137 qDebug("pid %d wants to be visible", pid);
139 QList<int> allSurfaces;
140 allSurfaces = mp_dBusWindowManagerProxy->getAllSurfacesOfProcess(pid);
141 if (0 == allSurfaces.size())
143 qDebug("no surfaces for pid %d. retrying!", pid);
147 m_requestsToBeVisiblePids.removeAt(0);
150 if (0 != allSurfaces.size())
152 int firstSurface = allSurfaces.at(0);
154 if (-1 != m_visibleSurfaces.indexOf(firstSurface))
156 qDebug("already visible");
160 if (-1 != m_invisibleSurfaces.indexOf(firstSurface))
162 m_invisibleSurfaces.removeAt(m_invisibleSurfaces.indexOf(firstSurface));
164 if (-1 == m_requestsToBeVisibleSurfaces.indexOf(firstSurface))
166 m_requestsToBeVisibleSurfaces.append(firstSurface);
170 qDebug(" m_visibleSurfaces %d", m_visibleSurfaces.size());
171 qDebug(" m_invisibleSurfaces %d", m_invisibleSurfaces.size());
172 qDebug(" m_requestsToBeVisibleSurfaces %d", m_requestsToBeVisibleSurfaces.size());
174 QList<int> availableLayouts = mp_dBusWindowManagerProxy->getAvailableLayouts(1); // one app only for CES2017
175 if (1 == availableLayouts.size())
177 qDebug("active layout: %d", availableLayouts.at(0));
178 m_invisibleSurfaces.append(m_visibleSurfaces);
179 m_visibleSurfaces.clear();
180 m_visibleSurfaces.append(m_requestsToBeVisibleSurfaces);
181 m_requestsToBeVisibleSurfaces.clear();
183 mp_dBusWindowManagerProxy->setLayoutById(availableLayouts.at(0));
184 for (int i = 0; i < m_visibleSurfaces.size(); ++i)
186 mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(m_visibleSurfaces.at(i), i);
190 qDebug(" m_visibleSurfaces %d", m_visibleSurfaces.size());
191 qDebug(" m_invisibleSurfaces %d", m_invisibleSurfaces.size());
192 qDebug(" m_requestsToBeVisibleSurfaces %d", m_requestsToBeVisibleSurfaces.size());
196 qDebug("this should not happen!?");
206 QList<int> LayoutHandler::requestGetAllSurfacesOfProcess(int pid)
208 qDebug("requestGetAllSurfacesOfProcess %d", pid);
210 return mp_dBusWindowManagerProxy->getAllSurfacesOfProcess(pid);
214 int LayoutHandler::requestGetSurfaceStatus(int surfaceId)
218 if (-1 != m_visibleSurfaces.indexOf(surfaceId))
222 if (-1 != m_invisibleSurfaces.indexOf(surfaceId))
226 if (-1 != m_requestsToBeVisibleSurfaces.indexOf(surfaceId))
234 void LayoutHandler::requestRenderSurfaceToArea(int surfaceId, int layoutArea)
236 qDebug("requestRenderSurfaceToArea %d %d", surfaceId, layoutArea);
237 mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(surfaceId, layoutArea);
240 bool LayoutHandler::requestRenderSurfaceToAreaAllowed(int surfaceId, int layoutArea)
242 qDebug("requestRenderSurfaceToAreaAllowed %d %d", surfaceId, layoutArea);
247 void LayoutHandler::requestSurfaceIdToFullScreen(int surfaceId)
249 qDebug("requestSurfaceIdToFullScreen %d", surfaceId);
252 void LayoutHandler::setLayoutByName(QString layoutName)
254 // switch to new layout
255 qDebug("setLayout: switch to new layout %s", layoutName.toStdString().c_str());
256 m_visibleSurfaces.append(m_requestsToBeVisibleSurfaces);
257 m_requestsToBeVisibleSurfaces.clear();
259 mp_dBusWindowManagerProxy->setLayoutByName(layoutName);
260 for (int i = 0; i < m_visibleSurfaces.size(); ++i)
262 mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(i, i);
266 void LayoutHandler::requestSurfaceVisibilityChanged(int surfaceId, bool visible)
268 qDebug("requestSurfaceVisibilityChanged %d %s", surfaceId, visible ? "true" : "false");
269 emit surfaceVisibilityChanged(surfaceId, visible);
272 void LayoutHandler::timerEvent(QTimerEvent *e)
274 if (e->timerId() == m_secondsTimerId)