2 * Copyright (C) 2016 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 "windowmanager.hpp"
20 //////////////////////////////////////////
21 // THIS IS STILL UNDER HEAVY DEVELOPMENT!
22 // DO NOT JUDGE THE SOURCE CODE :)
23 //////////////////////////////////////////
25 // three layers will be defined. The HomeScreen will be placed
26 // full screen in the background.
27 // On top all applications in one layer.
28 // On top of that, the popup layer.
29 #define WINDOWMANAGER_LAYER_POPUP 100
30 #define WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY 101
31 #define WINDOWMANAGER_LAYER_APPLICATIONS 102
32 #define WINDOWMANAGER_LAYER_HOMESCREEN 103
34 #define WINDOWMANAGER_LAYER_NUM 4
36 // the HomeScreen app has to have the surface id 1000
37 #define WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID 1000
40 void* WindowManager::myThis = 0;
42 WindowManager::WindowManager(QObject *parent) :
46 mp_layoutAreaToSurfaceIdAssignment(0),
49 qDebug("-=[WindowManager]=-");
52 void WindowManager::start()
54 qDebug("-=[start]=-");
55 mp_layoutAreaToSurfaceIdAssignment = new QMap<int, unsigned int>;
56 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
60 qDebug("ilm_init = %d", err);
61 if(ILM_SUCCESS != err)
63 qDebug("failed! Exiting!");
68 err = ilm_registerNotification(WindowManager::notificationFunc_static, this);
70 createNewLayer(WINDOWMANAGER_LAYER_POPUP);
71 createNewLayer(WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY);
72 createNewLayer(WINDOWMANAGER_LAYER_APPLICATIONS);
73 createNewLayer(WINDOWMANAGER_LAYER_HOMESCREEN);
76 QDBusConnection dbus = QDBusConnection::sessionBus();
77 dbus.registerObject("/windowmanager", this);
78 dbus.registerService("org.agl.windowmanager");
80 // publish windowmanager interface
81 mp_windowManagerAdaptor = new WindowmanagerAdaptor((QObject*)this);
84 WindowManager::~WindowManager()
86 qDebug("-=[~WindowManager]=-");
87 delete mp_windowManagerAdaptor;
88 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
91 delete mp_layoutAreaToSurfaceIdAssignment;
94 void WindowManager::dumpScene()
97 qDebug("current layout : %d", m_currentLayout);
98 qDebug("available layouts: %d", m_layouts.size());
99 QList<Layout>::const_iterator i = m_layouts.begin();
101 while (i != m_layouts.constEnd())
103 qDebug("--[id: %d]--[%s]--", i->id, i->name.toStdString().c_str());
104 qDebug(" %d surface areas", i->layoutAreas.size());
105 for (int j = 0; j < i->layoutAreas.size(); ++j)
107 qDebug(" -area %d", j);
108 qDebug(" -x : %d", i->layoutAreas.at(j).x);
109 qDebug(" -y : %d", i->layoutAreas.at(j).y);
110 qDebug(" -width : %d", i->layoutAreas.at(j).width);
111 qDebug(" -height: %d", i->layoutAreas.at(j).height);
118 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
120 void WindowManager::createNewLayer(int layerId)
122 qDebug("-=[createNewLayer]=-");
123 qDebug("layerId %d", layerId);
125 t_ilm_uint screenID = 0;
129 ilm_getScreenResolution(screenID, &width, &height);
131 t_ilm_layer newLayerId = layerId;
132 ilm_layerCreateWithDimension(&newLayerId, width, height);
133 ilm_layerSetOpacity(newLayerId, 1.0);
134 ilm_layerSetVisibility(newLayerId, ILM_TRUE);
135 ilm_layerSetSourceRectangle(newLayerId,
140 ilm_layerSetDestinationRectangle(newLayerId,
149 void WindowManager::addSurfaceToLayer(int surfaceId, int layerId)
151 qDebug("-=[addSurfaceToLayer]=-");
152 qDebug("surfaceId %d", surfaceId);
153 qDebug("layerId %d", layerId);
155 if (layerId == WINDOWMANAGER_LAYER_HOMESCREEN)
157 struct ilmSurfaceProperties surfaceProperties;
158 ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties);
160 qDebug("sourceX %d", surfaceProperties.sourceX);
161 qDebug("sourceY %d", surfaceProperties.sourceY);
162 qDebug("sourceWidth %d", surfaceProperties.sourceWidth);
163 qDebug("sourceHeight %d", surfaceProperties.sourceHeight);
165 // homescreen app always fullscreen in the back
166 t_ilm_uint screenID = 0;
170 ilm_getScreenResolution(screenID, &width, &height);
172 ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, width, height);
173 ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, width, height);
174 ilm_surfaceSetOpacity(surfaceId, 1.0);
175 ilm_surfaceSetVisibility(surfaceId, ILM_TRUE);
177 ilm_layerAddSurface(layerId, surfaceId);
180 if (layerId == WINDOWMANAGER_LAYER_APPLICATIONS)
182 struct ilmSurfaceProperties surfaceProperties;
183 ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties);
185 ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
186 ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
187 ilm_surfaceSetOpacity(surfaceId, 0.0);
188 ilm_surfaceSetVisibility(surfaceId, ILM_FALSE);
190 ilm_layerAddSurface(layerId, surfaceId);
193 if (layerId == WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY)
195 struct ilmSurfaceProperties surfaceProperties;
196 ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties);
198 ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
199 ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
200 ilm_surfaceSetOpacity(surfaceId, 0.5);
201 ilm_surfaceSetVisibility(surfaceId, ILM_TRUE);
203 ilm_layerAddSurface(layerId, surfaceId);
206 if (layerId == WINDOWMANAGER_LAYER_POPUP)
208 struct ilmSurfaceProperties surfaceProperties;
209 ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties);
211 ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
212 ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
213 ilm_surfaceSetOpacity(surfaceId, 0.0);
214 ilm_surfaceSetVisibility(surfaceId, ILM_FALSE);
216 ilm_layerAddSurface(layerId, surfaceId);
224 void WindowManager::updateScreen()
226 qDebug("-=[updateScreen]=-");
228 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
229 if (-1 != m_currentLayout)
233 for (int i = 0; i < m_surfaces.size(); ++i)
235 ilm_surfaceSetVisibility(m_surfaces.at(i), ILM_FALSE);
236 ilm_surfaceSetOpacity(m_surfaces.at(i), 0.0);
239 // find the current used layout
240 QList<Layout>::const_iterator ci = m_layouts.begin();
242 Layout currentLayout;
243 while (ci != m_layouts.constEnd())
245 if (ci->id == m_currentLayout)
253 qDebug("show %d apps", mp_layoutAreaToSurfaceIdAssignment->size());
254 for (int j = 0; j < mp_layoutAreaToSurfaceIdAssignment->size(); ++j)
256 int surfaceToShow = mp_layoutAreaToSurfaceIdAssignment->find(j).value();
257 qDebug(" surface no. %d: %d", j, surfaceToShow);
259 ilm_surfaceSetVisibility(surfaceToShow, ILM_TRUE);
260 ilm_surfaceSetOpacity(surfaceToShow, 1.0);
262 qDebug(" layout area %d", j);
263 qDebug(" x: %d", currentLayout.layoutAreas[j].x);
264 qDebug(" y: %d", currentLayout.layoutAreas[j].y);
265 qDebug(" w: %d", currentLayout.layoutAreas[j].width);
266 qDebug(" h: %d", currentLayout.layoutAreas[j].height);
268 ilm_surfaceSetDestinationRectangle(surfaceToShow,
269 currentLayout.layoutAreas[j].x,
270 currentLayout.layoutAreas[j].y,
271 currentLayout.layoutAreas[j].width,
272 currentLayout.layoutAreas[j].height);
278 t_ilm_layer renderOrder[WINDOWMANAGER_LAYER_NUM];
279 renderOrder[0] = WINDOWMANAGER_LAYER_HOMESCREEN;
280 renderOrder[1] = WINDOWMANAGER_LAYER_APPLICATIONS;
281 renderOrder[2] = WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY;
282 renderOrder[3] = WINDOWMANAGER_LAYER_POPUP;
284 ilm_displaySetRenderOrder(0, renderOrder, WINDOWMANAGER_LAYER_NUM);
291 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
292 void WindowManager::notificationFunc_non_static(ilmObjectType object,
296 qDebug("-=[notificationFunc_non_static]=-");
297 qDebug("Notification from weston!");
298 if (ILM_SURFACE == object)
300 struct ilmSurfaceProperties surfaceProperties;
304 qDebug("Surface created, ID: %d", id);
305 ilm_getPropertiesOfSurface(id, &surfaceProperties);
306 qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth);
307 qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight);
309 if (WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID == id)
311 qDebug("HomeScreen app detected");
312 addSurfaceToLayer(id, WINDOWMANAGER_LAYER_HOMESCREEN);
317 addSurfaceToLayer(id, WINDOWMANAGER_LAYER_APPLICATIONS);
319 m_surfaces.append(id);
321 ilm_surfaceAddNotification(id, surfaceCallbackFunction_static);
327 qDebug("Surface destroyed, ID: %d", id);
328 m_surfaces.removeAt(m_surfaces.indexOf(id));
329 ilm_surfaceRemoveNotification(id);
334 if (ILM_LAYER == object)
336 //qDebug("Layer.. we don't care...");
340 void WindowManager::notificationFunc_static(ilmObjectType object,
345 static_cast<WindowManager*>(WindowManager::myThis)->notificationFunc_non_static(object, id, created);
348 void WindowManager::surfaceCallbackFunction_non_static(t_ilm_surface surface,
349 struct ilmSurfaceProperties* surfaceProperties,
350 t_ilm_notification_mask mask)
352 qDebug("-=[surfaceCallbackFunction_non_static]=-");
353 qDebug("surfaceCallbackFunction_non_static changes for surface %d", surface);
354 if (ILM_NOTIFICATION_VISIBILITY & mask)
356 qDebug("ILM_NOTIFICATION_VISIBILITY");
357 surfaceVisibilityChanged(surface, surfaceProperties->visibility);
359 if (ILM_NOTIFICATION_OPACITY & mask)
361 qDebug("ILM_NOTIFICATION_OPACITY");
363 if (ILM_NOTIFICATION_ORIENTATION & mask)
365 qDebug("ILM_NOTIFICATION_ORIENTATION");
367 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
369 qDebug("ILM_NOTIFICATION_SOURCE_RECT");
371 if (ILM_NOTIFICATION_DEST_RECT & mask)
373 qDebug("ILM_NOTIFICATION_DEST_RECT");
375 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
377 qDebug("ILM_NOTIFICATION_CONTENT_AVAILABLE");
380 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
382 qDebug("ILM_NOTIFICATION_CONTENT_REMOVED");
384 if (ILM_NOTIFICATION_CONFIGURED & mask)
386 qDebug("ILM_NOTIFICATION_CONFIGURED");
387 qDebug(" surfaceProperties %d", surface);
388 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
389 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
391 ilm_surfaceSetSourceRectangle(surface,
394 surfaceProperties->origSourceWidth,
395 surfaceProperties->origSourceHeight);
402 void WindowManager::surfaceCallbackFunction_static(t_ilm_surface surface,
403 struct ilmSurfaceProperties* surfaceProperties,
404 t_ilm_notification_mask mask)
407 static_cast<WindowManager*>(WindowManager::myThis)->surfaceCallbackFunction_non_static(surface, surfaceProperties, mask);
411 int WindowManager::layoutId() const
413 return m_currentLayout;
416 QString WindowManager::layoutName() const
418 QList<Layout>::const_iterator i = m_layouts.begin();
420 QString result = "not found";
421 while (i != m_layouts.constEnd())
423 if (i->id == m_currentLayout)
435 int WindowManager::addLayout(int layoutId, const QString &layoutName, const QList<LayoutArea> &surfaceAreas)
437 qDebug("-=[addLayout]=-");
438 m_layouts.append(Layout(layoutId, layoutName, surfaceAreas));
440 qDebug("addLayout %d %s, size %d",
442 layoutName.toStdString().c_str(),
443 surfaceAreas.size());
447 return WINDOWMANAGER_NO_ERROR;
450 int WindowManager::deleteLayoutById(int layoutId)
452 qDebug("-=[deleteLayoutById]=-");
453 qDebug("layoutId: %d", layoutId);
454 int result = WINDOWMANAGER_NO_ERROR;
456 if (m_currentLayout == layoutId)
458 result = WINDOWMANAGER_ERROR_ID_IN_USE;
462 QList<Layout>::iterator i = m_layouts.begin();
463 result = WINDOWMANAGER_ERROR_ID_IN_USE;
464 while (i != m_layouts.constEnd())
466 if (i->id == layoutId)
469 result = WINDOWMANAGER_NO_ERROR;
481 QList<Layout> WindowManager::getAllLayouts()
483 qDebug("-=[getAllLayouts]=-");
488 QList<int> WindowManager::getAllSurfacesOfProcess(int pid)
491 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
492 struct ilmSurfaceProperties surfaceProperties;
494 for (int i = 0; i < m_surfaces.size(); ++i)
496 ilm_getPropertiesOfSurface(m_surfaces.at(i), &surfaceProperties);
497 if (pid == surfaceProperties.creatorPid)
499 result.append(m_surfaces.at(i));
506 QList<int> WindowManager::getAvailableLayouts(int numberOfAppSurfaces)
508 qDebug("-=[getAvailableLayouts]=-");
509 QList<Layout>::const_iterator i = m_layouts.begin();
512 while (i != m_layouts.constEnd())
514 if (i->layoutAreas.size() == numberOfAppSurfaces)
516 result.append(i->id);
525 QList<int> WindowManager::getAvailableSurfaces()
527 qDebug("-=[getAvailableSurfaces]=-");
532 QString WindowManager::getLayoutName(int layoutId)
534 qDebug("-=[getLayoutName]=-");
535 QList<Layout>::const_iterator i = m_layouts.begin();
537 QString result = "not found";
538 while (i != m_layouts.constEnd())
540 if (i->id == layoutId)
551 void WindowManager::hideLayer(int layer)
553 qDebug("-=[hideLayer]=-");
554 qDebug("layer %d", layer);
556 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
559 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_POPUP, ILM_FALSE);
563 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY, ILM_FALSE);
567 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_APPLICATIONS, ILM_FALSE);
571 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_HOMESCREEN, ILM_FALSE);
577 int WindowManager::setLayoutById(int layoutId)
579 qDebug("-=[setLayoutById]=-");
580 int result = WINDOWMANAGER_NO_ERROR;
581 m_currentLayout = layoutId;
583 mp_layoutAreaToSurfaceIdAssignment->clear();
590 int WindowManager::setLayoutByName(const QString &layoutName)
592 qDebug("-=[setLayoutByName]=-");
593 int result = WINDOWMANAGER_NO_ERROR;
595 QList<Layout>::const_iterator i = m_layouts.begin();
597 while (i != m_layouts.constEnd())
599 if (i->name == layoutName)
601 m_currentLayout = i->id;
603 mp_layoutAreaToSurfaceIdAssignment->clear();
614 int WindowManager::setSurfaceToLayoutArea(int surfaceId, int layoutAreaId)
616 qDebug("-=[setSurfaceToLayoutArea]=-");
617 int result = WINDOWMANAGER_NO_ERROR;
619 qDebug("surfaceId %d", surfaceId);
620 qDebug("layoutAreaId %d", layoutAreaId);
621 mp_layoutAreaToSurfaceIdAssignment->insert(layoutAreaId, surfaceId);
630 void WindowManager::showLayer(int layer)
632 qDebug("-=[showLayer]=-");
633 qDebug("layer %d", layer);
635 #ifdef HAVE_IVI_LAYERMANAGEMENT_API
638 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_POPUP, ILM_TRUE);
642 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY, ILM_TRUE);
646 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_APPLICATIONS, ILM_TRUE);
650 ilm_layerSetVisibility(WINDOWMANAGER_LAYER_HOMESCREEN, ILM_TRUE);