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"
18 #include <wayland-client.h>
21 //////////////////////////////////////////
22 // THIS IS STILL UNDER HEAVY DEVELOPMENT!
23 // DO NOT JUDGE THE SOURCE CODE :)
24 //////////////////////////////////////////
26 void* WindowManager::myThis = 0;
28 WindowManager::WindowManager(QObject *parent) :
34 qDebug("WindowManager");
35 // publish windowmanager interface
36 mp_windowManagerAdaptor = new WindowmanagerAdaptor((QObject*)this);
38 QDBusConnection dbus = QDBusConnection::sessionBus();
39 dbus.registerObject("/windowmanager", this);
40 dbus.registerService("org.agl.windowmanager");
43 mp_processLayers = new QList<int>;
44 mp_surfaces = new QMap<t_ilm_uint, SurfaceInfo>;
49 qDebug("ilm_init = %d", err);
52 err = ilm_registerNotification(WindowManager::notificationFunc_static, this);
58 WindowManager::~WindowManager()
60 delete mp_windowManagerAdaptor;
68 void WindowManager::dumpScene()
71 qDebug("current layout : %d", m_currentLayout);
72 qDebug("available layouts: %d", m_layouts.size());
73 QMap<int, QList<SimpleRect> >::iterator i = m_layouts.begin();
76 while (i != m_layouts.constEnd())
78 qDebug("--[id: %d]--[%s]--", i.key(), m_layoutNames.find(i.key()).value().toStdString().c_str());
79 qDebug(" %d surface areas", i.value().size());
80 for (int j = 0; j < i.value().size(); ++j)
82 qDebug(" -area %d", j);
83 qDebug(" -x : %d", i.value().at(j).x);
84 qDebug(" -y : %d", i.value().at(j).y);
85 qDebug(" -width : %d", i.value().at(j).width);
86 qDebug(" -height: %d", i.value().at(j).height);
96 void WindowManager::createNewLayer(int layerId)
100 t_ilm_uint screenID = 0;
104 err = ilm_getScreenResolution(screenID, &width, &height);
106 t_ilm_layer newLayerId = layerId;
107 err = ilm_layerCreateWithDimension(&newLayerId, width, height);
108 qDebug("ilm_layerCreateWithDimension = %d", err);
109 qDebug("layerIdWallpaper = %d", newLayerId);
111 err = ilm_layerSetVisibility(newLayerId, true);
112 qDebug("ilm_layerSetVisibility = %d", err);
114 t_ilm_float opacity = 1.0;
115 err = ilm_layerSetOpacity(newLayerId, opacity);
120 void WindowManager::addSurfaceToLayer(int surfaceId, int layerId)
125 ilm_getLayerIDs(&length, &pArray);
126 bool layerFound(false);
127 for (int i = 0; i< length; ++i)
129 if (layerId == pArray[i])
137 createNewLayer(layerId);
140 struct ilmSurfaceProperties surfaceProperties;
141 ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties);
142 qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth);
143 qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight);
145 ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
146 ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
147 ilm_surfaceSetOpacity(surfaceId, 1.0);
148 ilm_surfaceSetVisibility(surfaceId, true);
150 ilm_layerAddSurface(layerId, surfaceId);
155 void WindowManager::notificationFunc_non_static(ilmObjectType object,
159 if (ILM_SURFACE == object)
161 struct ilmSurfaceProperties surfaceProperties;
165 qDebug("Surface created, ID: %d", id);
166 ilm_getPropertiesOfSurface(id, &surfaceProperties);
167 qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth);
168 qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight);
170 addSurfaceToLayer(id, surfaceProperties.creatorPid);
173 t_ilm_surface* pArray;
174 ilm_getSurfaceIDs(&length, &pArray);
175 ilm_layerSetRenderOrder(42, pArray, length);
179 SurfaceInfo surfaceInfo;
180 surfaceInfo.pid = surfaceProperties.creatorPid;
181 QString procInfoFileName = QString("/proc/") + QString::number(surfaceInfo.pid) + QString("/comm");
182 QFile procInfo(procInfoFileName);
183 if (procInfo.open(QIODevice::ReadOnly))
185 QTextStream in(&procInfo);
186 surfaceInfo.processName = in.readLine();
187 qDebug("surface id %d, pid %d: %s", id, surfaceInfo.pid, surfaceInfo.processName.toStdString().c_str());
190 mp_surfaces->insert(id, surfaceInfo);
191 ilm_surfaceAddNotification(id, surfaceCallbackFunction_static);
195 qDebug("Surface destroyed, ID: %d", id);
196 mp_surfaces->erase(mp_surfaces->find(id));
197 ilm_surfaceRemoveNotification(id);
200 // rearrange surfaces on screen
201 t_ilm_uint screenID = 0;
204 ilm_getScreenResolution(screenID, &width, &height);
206 qDebug("%d surfaces to show", mp_surfaces->count());
208 QMap<t_ilm_uint, SurfaceInfo>::const_iterator i = mp_surfaces->constBegin();
210 while (i != mp_surfaces->constEnd())
212 qDebug("place surface %d at x: %f, y: %d, width: %f, height: %d",
214 counter * (width / (1.0 * mp_surfaces->count())),
216 width / (1.0 * mp_surfaces->count()),
218 ilm_surfaceSetDestinationRectangle(i.key(),
219 counter * (width / (1.0 * mp_surfaces->count())),
221 width / (1.0 * mp_surfaces->count()),
231 if (ILM_LAYER == object)
233 //qDebug("Layer.. we don't care...");
237 void WindowManager::notificationFunc_static(ilmObjectType object,
242 static_cast<WindowManager*>(WindowManager::myThis)->notificationFunc_non_static(object, id, created);
248 void WindowManager::surfaceCallbackFunction_non_static(t_ilm_surface surface,
249 struct ilmSurfaceProperties* surfaceProperties,
250 t_ilm_notification_mask mask)
252 qDebug("surfaceCallbackFunction_non_static changes for surface %d", surface);
253 if (ILM_NOTIFICATION_VISIBILITY & mask)
255 qDebug("ILM_NOTIFICATION_VISIBILITY");
258 if (ILM_NOTIFICATION_OPACITY & mask)
260 qDebug("ILM_NOTIFICATION_OPACITY");
263 if (ILM_NOTIFICATION_ORIENTATION & mask)
265 qDebug("ILM_NOTIFICATION_ORIENTATION");
268 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
270 qDebug("ILM_NOTIFICATION_SOURCE_RECT");
273 if (ILM_NOTIFICATION_DEST_RECT & mask)
275 qDebug("ILM_NOTIFICATION_DEST_RECT");
279 void WindowManager::surfaceCallbackFunction_static(t_ilm_surface surface,
280 struct ilmSurfaceProperties* surfaceProperties,
281 t_ilm_notification_mask mask)
284 static_cast<WindowManager*>(WindowManager::myThis)->surfaceCallbackFunction_non_static(surface, surfaceProperties, mask);
288 int WindowManager::addLayout(int layoutId, const QString &layoutName, const QList<SimpleRect> &surfaceAreas)
290 m_layouts.insert(layoutId, surfaceAreas);
291 m_layoutNames.insert(layoutId, layoutName);
292 qDebug("addLayout %d %s, size %d", layoutId, layoutName.toStdString().c_str(), surfaceAreas.size());
299 QList<int> WindowManager::getAvailableLayouts(int numberOfAppSurfaces)
301 QMap<int, QList<SimpleRect> >::iterator i = m_layouts.begin();
304 while (i != m_layouts.constEnd())
306 if (i.value().size() == numberOfAppSurfaces)
308 result.append(i.key());
317 // maybe not needed anymore
318 QList<SimplePoint> WindowManager::getAvailableSurfaces()
320 QList<SimplePoint> points;
324 points.append(point);
327 points.append(point);
330 points.append(point);
335 int WindowManager::getLayout()
337 return m_currentLayout;
340 QString WindowManager::getLayoutName(int layoutId)
342 return m_layoutNames.find(layoutId).value();
345 void WindowManager::setLayoutById(int layoutId)
347 m_currentLayout = layoutId;
352 void WindowManager::setLayoutByName(const QString &layoutName)
354 QMap<int, QString>::iterator i = m_layoutNames.begin();
355 while (i != m_layoutNames.constEnd())
357 if (i.value() == layoutName)
359 m_currentLayout = i.key();
367 void WindowManager::setSurfaceToLayoutArea(int surfaceId, int layoutAreaId)