X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=WindowManager%2Fsrc%2Fwindowmanager.cpp;h=101f5b39c1b141c85e476ecb95116ac7b88ffa3f;hb=36f4818cb31b406715ec0d52a2075611ec6fcdff;hp=dea17a11a369bbb9c92a06a9ee15c34a6689f98a;hpb=824bfd42b0105b0aeffbc33a87285578abda2f3b;p=staging%2FHomeScreen.git diff --git a/WindowManager/src/windowmanager.cpp b/WindowManager/src/windowmanager.cpp index dea17a1..101f5b3 100644 --- a/WindowManager/src/windowmanager.cpp +++ b/WindowManager/src/windowmanager.cpp @@ -15,248 +15,359 @@ */ #include "windowmanager.hpp" -#include -#include + ////////////////////////////////////////// // THIS IS STILL UNDER HEAVY DEVELOPMENT! // DO NOT JUDGE THE SOURCE CODE :) ////////////////////////////////////////// +// three layers will be defined. The HomeScreen will be placed +// full screen in the background. +// On top all applications in one layer. +// On top of that, the popup layer. +#define WINDOWMANAGER_LAYER_POPUP 100 +#define WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY 101 +#define WINDOWMANAGER_LAYER_APPLICATIONS 102 +#define WINDOWMANAGER_LAYER_HOMESCREEN 103 + +#define WINDOWMANAGER_LAYER_NUM 4 + +#define WINDOWMANAGER_LAYER_ID_SHIFT 22 + +// the HomeScreen app has to have the surface id 1000 +#define WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID 1000 + void* WindowManager::myThis = 0; WindowManager::WindowManager(QObject *parent) : QObject(parent), m_layouts(), - m_layoutNames(), + // m_appSurfaces(), + mp_layoutAreaToSurfaceIdAssignment(0), m_currentLayout(-1), - m_homeScreenPid(-1), -#ifdef __arm__ - mp_surfaces(0), - mp_processLayers(0), + m_screenId(0), // use screen "0" + m_screenWidth(0), + m_screenHeight(0) +#ifdef HAVE_IVI_LAYERMANAGEMENT_API + , + m_appLayers(), + m_pending_to_show(-1) #endif - mp_layoutAreaToPidAssignment(0) { - qDebug("-=[WindowManager]=-"); - qDebug("WindowManager"); - // publish windowmanager interface - mp_windowManagerAdaptor = new WindowmanagerAdaptor((QObject*)this); +#ifdef HAVE_IVI_LAYERMANAGEMENT_API + m_showLayers = new t_ilm_layer[WINDOWMANAGER_LAYER_NUM]; - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/windowmanager", this); - dbus.registerService("org.agl.windowmanager"); + m_showLayers[0] = 0; /* POPUP is not shown by default */ + m_showLayers[1] = 0; /* HOMESCREEN_OVERLAY is not shown by default */ + m_showLayers[2] = 0; /* APPLICATIONS is not shown by default */ + m_showLayers[3] = WINDOWMANAGER_LAYER_HOMESCREEN; /* HOMESCREEN is shwon by default */ + +#endif + qDebug("-=[WindowManager]=-"); } void WindowManager::start() { qDebug("-=[start]=-"); - mp_layoutAreaToPidAssignment = new QMap; -#ifdef __arm__ - mp_processLayers = new QList; - mp_surfaces = new QMap; - + mp_layoutAreaToSurfaceIdAssignment = new QMap; +#ifdef HAVE_IVI_LAYERMANAGEMENT_API ilmErrorTypes err; err = ilm_init(); qDebug("ilm_init = %d", err); + if(ILM_SUCCESS != err) + { + qDebug("failed! Exiting!"); + exit(-1); + } myThis = this; - err = ilm_registerNotification(WindowManager::notificationFunc_static, this); + + ilm_getScreenResolution(m_screenId, &m_screenWidth, &m_screenHeight); + + createNewLayer(WINDOWMANAGER_LAYER_POPUP); + createNewLayer(WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY); +// createNewLayer(WINDOWMANAGER_LAYER_APPLICATIONS); + createNewLayer(WINDOWMANAGER_LAYER_HOMESCREEN); + + ilm_registerNotification(WindowManager::notificationFunc_static, this); #endif + + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerObject("/windowmanager", this); + dbus.registerService("org.agl.windowmanager"); + + // publish windowmanager interface + mp_windowManagerAdaptor = new WindowmanagerAdaptor((QObject*)this); } WindowManager::~WindowManager() { qDebug("-=[~WindowManager]=-"); delete mp_windowManagerAdaptor; -#ifdef __arm__ - delete mp_surfaces; - delete mp_processLayers; - +#ifdef HAVE_IVI_LAYERMANAGEMENT_API ilm_destroy(); #endif - delete mp_layoutAreaToPidAssignment; + delete mp_layoutAreaToSurfaceIdAssignment; } +#ifdef HAVE_IVI_LAYERMANAGEMENT_API +int WindowManager::getLayerRenderOrder(t_ilm_layer id_array[]) +{ + int i, j; + + for (i = WINDOWMANAGER_LAYER_NUM - 1, j = 0; i >= 0; i--, j++) { + if (m_showLayers[i] != 0) { + id_array[j] = m_showLayers[i]; + } + } + + return j; +} +#endif + void WindowManager::dumpScene() { qDebug("\n"); qDebug("current layout : %d", m_currentLayout); qDebug("available layouts: %d", m_layouts.size()); - QMap >::iterator i = m_layouts.begin(); + QList::const_iterator i = m_layouts.begin(); - QList result; while (i != m_layouts.constEnd()) { - qDebug("--[id: %d]--[%s]--", i.key(), m_layoutNames.find(i.key()).value().toStdString().c_str()); - qDebug(" %d surface areas", i.value().size()); - for (int j = 0; j < i.value().size(); ++j) + qDebug("--[id: %d]--[%s]--", i->id, i->name.toStdString().c_str()); + qDebug(" %d surface areas", i->layoutAreas.size()); + for (int j = 0; j < i->layoutAreas.size(); ++j) { qDebug(" -area %d", j); - qDebug(" -x : %d", i.value().at(j).x); - qDebug(" -y : %d", i.value().at(j).y); - qDebug(" -width : %d", i.value().at(j).width); - qDebug(" -height: %d", i.value().at(j).height); + qDebug(" -x : %d", i->layoutAreas.at(j).x); + qDebug(" -y : %d", i->layoutAreas.at(j).y); + qDebug(" -width : %d", i->layoutAreas.at(j).width); + qDebug(" -height: %d", i->layoutAreas.at(j).height); } ++i; } } -#ifdef __arm__ +#ifdef HAVE_IVI_LAYERMANAGEMENT_API void WindowManager::createNewLayer(int layerId) { qDebug("-=[createNewLayer]=-"); - qDebug("layerId %d", layerId); - ilmErrorTypes err; - - t_ilm_uint screenID = 0; - t_ilm_uint width; - t_ilm_uint height; - - err = ilm_getScreenResolution(screenID, &width, &height); + qDebug(" layerId %d", layerId); t_ilm_layer newLayerId = layerId; - err = ilm_layerCreateWithDimension(&newLayerId, width, height); - - t_ilm_float opacity = 0.0; - err = ilm_layerSetOpacity(newLayerId, opacity); - - ilm_layerSetVisibility(newLayerId, ILM_FALSE); + ilm_layerCreateWithDimension(&newLayerId, m_screenWidth, m_screenHeight); + ilm_layerSetOpacity(newLayerId, 1.0); + ilm_layerSetVisibility(newLayerId, ILM_TRUE); + ilm_layerSetSourceRectangle(newLayerId, + 0, + 0, + m_screenWidth, + m_screenHeight); + ilm_layerSetDestinationRectangle(newLayerId, + 0, + 0, + m_screenWidth, + m_screenHeight); ilm_commitChanges(); } -void WindowManager::addSurfaceToLayer(int surfaceId, int layerId) +t_ilm_layer WindowManager::getAppLayerID(pid_t pid) { - qDebug("-=[addSurfaceToLayer]=-"); - qDebug("surfaceId %d", surfaceId); - qDebug("layerId %d", layerId); - t_ilm_int length; - t_ilm_layer* pArray; + t_ilm_layer layer_id; - ilm_getLayerIDs(&length, &pArray); - bool layerFound(false); - for (int i = 0; i < length; ++i) - { - if (layerId == pArray[i]) - { - layerFound = true; - } - } +// layer_id = pid + (WINDOWMANAGER_LAYER_APPLICATIONS << WINDOWMANAGER_LAYER_ID_SHIFT); + layer_id = pid + (WINDOWMANAGER_LAYER_APPLICATIONS * 100000); /* for debug */ - if (!layerFound) - { - createNewLayer(layerId); - } + return layer_id; +} +void WindowManager::addSurfaceToAppLayer(int surfaceId) +{ struct ilmSurfaceProperties surfaceProperties; + t_ilm_layer layer_id; + int found = 0; + pid_t pid; + + qDebug("-=[addSurfaceToAppLayer]=-"); + qDebug(" surfaceId %d", surfaceId); + ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties); - //qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth); - //qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight); - - ilm_layerSetSourceRectangle(layerId, - 0, - 0, - surfaceProperties.origSourceWidth, - surfaceProperties.origSourceHeight); - ilm_commitChanges(); + pid = surfaceProperties.creatorPid; + + if (pid < 0) { + /* No process */ + qDebug("addSurfaceToAppLayer(%d) got pid == -1", surfaceId); + return; + } - ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); - ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); - ilm_surfaceSetOpacity(surfaceId, 1.0); - ilm_surfaceSetVisibility(surfaceId, true); + QMap::const_iterator i = m_appLayers.find(pid); + if (i == m_appLayers.end()) { + qDebug("No layer found, create new for app(pid=%d)", pid); - ilm_layerAddSurface(layerId, surfaceId); + /* not found, create new one */ + t_ilm_layer layer_id = getAppLayerID(pid); - ilm_commitChanges(); + createNewLayer(layer_id); + m_appLayers.insert(pid, layer_id); + } } -void WindowManager::updateScreen() +void WindowManager::addSurfaceToLayer(int surfaceId, int layerId) { - qDebug("-=[updateScreen]=-"); - int numberOfLayersToShow = 0; + qDebug("-=[addSurfaceToLayer]=-"); + qDebug(" surfaceId %d", surfaceId); + qDebug(" layerId %d", layerId); - QMap >::iterator i = m_layouts.find(m_currentLayout); - if (m_layouts.end() != i) + if (layerId == WINDOWMANAGER_LAYER_HOMESCREEN) { - numberOfLayersToShow += i.value().size(); - qDebug("the current layout provides %d render areas", i.value().size()); + struct ilmSurfaceProperties surfaceProperties; + ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties); + + // homescreen app always fullscreen in the back + ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, m_screenWidth, m_screenHeight); + //ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, m_screenWidth, m_screenHeight); + ilm_surfaceSetOpacity(surfaceId, 1.0); + ilm_surfaceSetVisibility(surfaceId, ILM_TRUE); + + ilm_layerAddSurface(layerId, surfaceId); } - else +#if 0 + if (layerId == WINDOWMANAGER_LAYER_APPLICATIONS) { - qDebug("the current layout provides no render areas!"); + struct ilmSurfaceProperties surfaceProperties; + ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties); + + //ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); + //ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); + //ilm_surfaceSetOpacity(surfaceId, 0.0); + //ilm_surfaceSetVisibility(surfaceId, ILM_FALSE); + + ilm_layerAddSurface(layerId, surfaceId); } +#endif + if (layerId == WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY) + { + struct ilmSurfaceProperties surfaceProperties; + ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties); + //ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); + //ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); + //ilm_surfaceSetOpacity(surfaceId, 0.5); + //ilm_surfaceSetVisibility(surfaceId, ILM_TRUE); - t_ilm_layer renderOrder[numberOfLayersToShow]; - int renderOrderCounter = 0; + ilm_layerAddSurface(layerId, surfaceId); + } - qDebug("show home screen app"); - if (-1 != m_homeScreenPid) + if (layerId == WINDOWMANAGER_LAYER_POPUP) { - renderOrder[renderOrderCounter] = m_homeScreenPid; - ++renderOrderCounter; + struct ilmSurfaceProperties surfaceProperties; + ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties); - ilm_layerSetVisibility(m_homeScreenPid, ILM_TRUE); - t_ilm_float opacity = 1.0; - ilm_layerSetOpacity(m_homeScreenPid, opacity); + //ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); + //ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); + //ilm_surfaceSetOpacity(surfaceId, 0.0); + //ilm_surfaceSetVisibility(surfaceId, ILM_FALSE); - // homescreen app always fullscreen in the back - t_ilm_uint screenID = 0; - t_ilm_uint width; - t_ilm_uint height; + ilm_layerAddSurface(layerId, surfaceId); + } - ilm_getScreenResolution(screenID, &width, &height); + ilm_commitChanges(); +} - ilm_layerSetDestinationRectangle(m_homeScreenPid, - 0, - 0, - width, - height); - } +#endif +void WindowManager::updateScreen() +{ + qDebug("-=[updateScreen]=-"); - qDebug("show %d apps", numberOfLayersToShow); - for (int j = 0; j < numberOfLayersToShow; ++j) +#if 0 +//#ifdef HAVE_IVI_LAYERMANAGEMENT_API + if (-1 != m_currentLayout) { - int layerToShow = mp_layoutAreaToPidAssignment->find(j).value(); - if (layerToShow != m_homeScreenPid) + // hide all surfaces + for (int i = 0; i < m_appSurfaces.size(); ++i) { - qDebug(" app no. %d: %d", j, layerToShow); - renderOrder[renderOrderCounter] = layerToShow; - ++renderOrderCounter; + ilm_layerRemoveSurface(WINDOWMANAGER_LAYER_APPLICATIONS, m_appSurfaces.at(i)); + //ilm_surfaceSetVisibility(m_appSurfaces.at(i), ILM_FALSE); + //ilm_surfaceSetOpacity(m_appSurfaces.at(i), 0.0); + ilm_commitChanges(); + } - ilm_layerSetVisibility(layerToShow, ILM_TRUE); - t_ilm_float opacity = 1.0; - ilm_layerSetOpacity(layerToShow, opacity); + // find the current used layout + QList::const_iterator ci = m_layouts.begin(); - qDebug(" layout area %d", j); - qDebug(" x: %d", m_layouts.find(m_currentLayout).value()[j].x); - qDebug(" x: %d", m_layouts.find(m_currentLayout).value()[j].y); - qDebug(" w: %d", m_layouts.find(m_currentLayout).value()[j].width); - qDebug(" h: %d", m_layouts.find(m_currentLayout).value()[j].height); - - ilm_layerSetDestinationRectangle(layerToShow, - m_layouts.find(m_currentLayout).value()[j].x, - m_layouts.find(m_currentLayout).value()[j].y, - m_layouts.find(m_currentLayout).value()[j].width, - m_layouts.find(m_currentLayout).value()[j].height); + Layout currentLayout; + while (ci != m_layouts.constEnd()) + { + if (ci->id == m_currentLayout) + { + currentLayout = *ci; + } + + ++ci; } - } - qDebug("renderOrder"); - for (int j = 0; j < renderOrderCounter; ++j) - { - qDebug(" %d: %d", j, renderOrder[j]); - } + qDebug("show %d apps", mp_layoutAreaToSurfaceIdAssignment->size()); + for (int j = 0; j < mp_layoutAreaToSurfaceIdAssignment->size(); ++j) + { + int surfaceToShow = mp_layoutAreaToSurfaceIdAssignment->find(j).value(); + qDebug(" surface no. %d: %d", j, surfaceToShow); + + addSurfaceToLayer(surfaceToShow, WINDOWMANAGER_LAYER_APPLICATIONS); - ilm_displaySetRenderOrder(0, renderOrder, renderOrderCounter); + ilm_surfaceSetVisibility(surfaceToShow, ILM_TRUE); + ilm_surfaceSetOpacity(surfaceToShow, 1.0); + + qDebug(" layout area %d", j); + qDebug(" x: %d", currentLayout.layoutAreas[j].x); + qDebug(" y: %d", currentLayout.layoutAreas[j].y); + qDebug(" w: %d", currentLayout.layoutAreas[j].width); + qDebug(" h: %d", currentLayout.layoutAreas[j].height); + + ilm_surfaceSetDestinationRectangle(surfaceToShow, + currentLayout.layoutAreas[j].x, + currentLayout.layoutAreas[j].y, + currentLayout.layoutAreas[j].width, + currentLayout.layoutAreas[j].height); + ilm_commitChanges(); + } + } + // layer surface render order + t_ilm_int length; + t_ilm_surface* pArray; + ilm_getSurfaceIDsOnLayer(WINDOWMANAGER_LAYER_HOMESCREEN, &length, &pArray); + ilm_layerSetRenderOrder(WINDOWMANAGER_LAYER_HOMESCREEN, pArray, length); + ilm_commitChanges(); + ilm_getSurfaceIDsOnLayer(WINDOWMANAGER_LAYER_APPLICATIONS, &length, &pArray); + ilm_layerSetRenderOrder(WINDOWMANAGER_LAYER_APPLICATIONS, pArray, length); + ilm_commitChanges(); + ilm_getSurfaceIDsOnLayer(WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY, &length, &pArray); + ilm_layerSetRenderOrder(WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY, pArray, length); ilm_commitChanges(); + ilm_getSurfaceIDsOnLayer(WINDOWMANAGER_LAYER_POPUP, &length, &pArray); + ilm_layerSetRenderOrder(WINDOWMANAGER_LAYER_POPUP, pArray, length); + ilm_commitChanges(); +#endif +#ifdef HAVE_IVI_LAYERMANAGEMENT_API + if (m_pending_to_show != -1) { + showAppLayer(m_pending_to_show); + } else { + // display layer render order + t_ilm_layer renderOrder[WINDOWMANAGER_LAYER_NUM]; + int num_layers = getLayerRenderOrder(renderOrder); + ilm_displaySetRenderOrder(m_screenId, renderOrder, num_layers); + ilm_commitChanges(); + } +#endif } +#ifdef HAVE_IVI_LAYERMANAGEMENT_API void WindowManager::notificationFunc_non_static(ilmObjectType object, t_ilm_uint id, t_ilm_bool created) @@ -270,45 +381,35 @@ void WindowManager::notificationFunc_non_static(ilmObjectType object, if (created) { qDebug("Surface created, ID: %d", id); - //qDebug("Surface created, ID: 0x%s", QString(QByteArray::number(id,16)).toStdString().c_str()); ilm_getPropertiesOfSurface(id, &surfaceProperties); qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth); qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight); - SurfaceInfo surfaceInfo; - surfaceInfo.pid = surfaceProperties.creatorPid; - QString procInfoFileName = QString("/proc/") + QString::number(surfaceInfo.pid) + QString("/comm"); - QFile procInfo(procInfoFileName); - if (procInfo.open(QIODevice::ReadOnly)) + + if (WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID == id) { - QTextStream in(&procInfo); - surfaceInfo.processName = in.readLine(); - qDebug(" creator pid %d %s", surfaceInfo.pid, surfaceInfo.processName.toStdString().c_str()); - addSurfaceToLayer(id, surfaceProperties.creatorPid); - - mp_surfaces->insert(id, surfaceInfo); - ilm_surfaceAddNotification(id, surfaceCallbackFunction_static); - - ilm_commitChanges(); - - if (0 == QString::compare("weston-fullscre", surfaceInfo.processName)) - { - qDebug("HomeScreen app detected"); - m_homeScreenPid = surfaceInfo.pid; - updateScreen(); - } + qDebug("HomeScreen app detected"); + addSurfaceToLayer(id, WINDOWMANAGER_LAYER_HOMESCREEN); + updateScreen(); } else { - qDebug("no creator pid found. Ignoring surface!"); + addSurfaceToAppLayer(id); + //addSurfaceToLayer(id, WINDOWMANAGER_LAYER_APPLICATIONS); + //m_appSurfaces.append(id); } + ilm_surfaceAddNotification(id, surfaceCallbackFunction_static); + + ilm_commitChanges(); } else { qDebug("Surface destroyed, ID: %d", id); - mp_surfaces->erase(mp_surfaces->find(id)); +#if 0 + m_appSurfaces.removeAt(m_appSurfaces.indexOf(id)); ilm_surfaceRemoveNotification(id); ilm_commitChanges(); +#endif } } if (ILM_LAYER == object) @@ -325,9 +426,6 @@ void WindowManager::notificationFunc_static(ilmObjectType object, static_cast(WindowManager::myThis)->notificationFunc_non_static(object, id, created); } - - - void WindowManager::surfaceCallbackFunction_non_static(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask mask) @@ -337,27 +435,92 @@ void WindowManager::surfaceCallbackFunction_non_static(t_ilm_surface surface, if (ILM_NOTIFICATION_VISIBILITY & mask) { qDebug("ILM_NOTIFICATION_VISIBILITY"); + surfaceVisibilityChanged(surface, surfaceProperties->visibility); } - if (ILM_NOTIFICATION_OPACITY & mask) { qDebug("ILM_NOTIFICATION_OPACITY"); } - if (ILM_NOTIFICATION_ORIENTATION & mask) { qDebug("ILM_NOTIFICATION_ORIENTATION"); } - if (ILM_NOTIFICATION_SOURCE_RECT & mask) { qDebug("ILM_NOTIFICATION_SOURCE_RECT"); } - if (ILM_NOTIFICATION_DEST_RECT & mask) { qDebug("ILM_NOTIFICATION_DEST_RECT"); } + if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask) + { + qDebug("ILM_NOTIFICATION_CONTENT_AVAILABLE"); + /* add surface to layer for the application */ + + ilmErrorTypes result; + pid_t pid = surfaceProperties->creatorPid; + + QMap::const_iterator i = m_appLayers.find(pid); + if (i != m_appLayers.end()) { + t_ilm_layer layer_id = m_appLayers.value(pid); + + result = ilm_layerAddSurface(layer_id, surface); + + if (result != ILM_SUCCESS) { + qDebug("ilm_layerAddSurface(%d,%d) failed.", layer_id, surface); + } + + /* Dirty hack! cut & paste from HomeScreen/src/layouthandler.cpp */ + const int SCREEN_WIDTH = 1080; + const int SCREEN_HEIGHT = 1920; + + const int TOPAREA_HEIGHT = 218; + const int TOPAREA_WIDTH = SCREEN_WIDTH; + const int TOPAREA_X = 0; + const int TOPAREA_Y = 0; + const int MEDIAAREA_HEIGHT = 215; + const int MEDIAAREA_WIDTH = SCREEN_WIDTH; + const int MEDIAAREA_X = 0; + const int MEDIAAREA_Y = SCREEN_HEIGHT - MEDIAAREA_HEIGHT; + + ilm_surfaceSetDestinationRectangle(surface, + 0, + TOPAREA_HEIGHT, + SCREEN_WIDTH, + SCREEN_HEIGHT - TOPAREA_HEIGHT - MEDIAAREA_HEIGHT); + + ilm_commitChanges(); + } else { + qDebug("No layer for application(pid=%d)", surfaceProperties->creatorPid); + } + } + if (ILM_NOTIFICATION_CONTENT_REMOVED & mask) + { + qDebug("ILM_NOTIFICATION_CONTENT_REMOVED"); + + /* application being down */ + m_appLayers.remove(surfaceProperties->creatorPid); + + updateScreen(); + } + if (ILM_NOTIFICATION_CONFIGURED & mask) + { + qDebug("ILM_NOTIFICATION_CONFIGURED"); + qDebug(" surfaceProperties %d", surface); + qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth); + qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight); + + ilm_surfaceSetSourceRectangle(surface, + 0, + 0, + surfaceProperties->origSourceWidth, + surfaceProperties->origSourceHeight); + + ilm_surfaceSetVisibility(surface, ILM_TRUE); + + updateScreen(); + } } void WindowManager::surfaceCallbackFunction_static(t_ilm_surface surface, @@ -369,29 +532,114 @@ void WindowManager::surfaceCallbackFunction_static(t_ilm_surface surface, } #endif -int WindowManager::addLayout(int layoutId, const QString &layoutName, const QList &surfaceAreas) +int WindowManager::layoutId() const +{ + return m_currentLayout; +} + +QString WindowManager::layoutName() const +{ + QList::const_iterator i = m_layouts.begin(); + + QString result = "not found"; + while (i != m_layouts.constEnd()) + { + if (i->id == m_currentLayout) + { + result = i->name; + } + + ++i; + } + + return result; +} + + +int WindowManager::addLayout(int layoutId, const QString &layoutName, const QList &surfaceAreas) { qDebug("-=[addLayout]=-"); - m_layouts.insert(layoutId, surfaceAreas); - m_layoutNames.insert(layoutId, layoutName); - qDebug("addLayout %d %s, size %d", layoutId, layoutName.toStdString().c_str(), surfaceAreas.size()); + m_layouts.append(Layout(layoutId, layoutName, surfaceAreas)); + + qDebug("addLayout %d %s, size %d", + layoutId, + layoutName.toStdString().c_str(), + surfaceAreas.size()); dumpScene(); - return true; + return WINDOWMANAGER_NO_ERROR; +} + +int WindowManager::deleteLayoutById(int layoutId) +{ + qDebug("-=[deleteLayoutById]=-"); + qDebug("layoutId: %d", layoutId); + int result = WINDOWMANAGER_NO_ERROR; + + if (m_currentLayout == layoutId) + { + result = WINDOWMANAGER_ERROR_ID_IN_USE; + } + else + { + QList::iterator i = m_layouts.begin(); + result = WINDOWMANAGER_ERROR_ID_IN_USE; + while (i != m_layouts.constEnd()) + { + if (i->id == layoutId) + { + m_layouts.erase(i); + result = WINDOWMANAGER_NO_ERROR; + break; + } + + ++i; + } + } + + return result; +} + + +QList WindowManager::getAllLayouts() +{ + qDebug("-=[getAllLayouts]=-"); + + return m_layouts; +} + +#if 0 +QList WindowManager::getAllSurfacesOfProcess(int pid) +{ + QList result; +#ifdef HAVE_IVI_LAYERMANAGEMENT_API + struct ilmSurfaceProperties surfaceProperties; + + for (int i = 0; i < m_appSurfaces.size(); ++i) + { + ilm_getPropertiesOfSurface(m_appSurfaces.at(i), &surfaceProperties); + if (pid == surfaceProperties.creatorPid) + { + result.append(m_appSurfaces.at(i)); + } + } +#endif + return result; } +#endif QList WindowManager::getAvailableLayouts(int numberOfAppSurfaces) { qDebug("-=[getAvailableLayouts]=-"); - QMap >::iterator i = m_layouts.begin(); + QList::const_iterator i = m_layouts.begin(); QList result; while (i != m_layouts.constEnd()) { - if (i.value().size() == numberOfAppSurfaces) + if (i->layoutAreas.size() == numberOfAppSurfaces) { - result.append(i.key()); + result.append(i->id); } ++i; @@ -400,75 +648,172 @@ QList WindowManager::getAvailableLayouts(int numberOfAppSurfaces) return result; } -// maybe not needed anymore -QList WindowManager::getAvailableSurfaces() +#if 0 +QList WindowManager::getAvailableSurfaces() { qDebug("-=[getAvailableSurfaces]=-"); - QList points; - SimplePoint point; - point.x = 1; - point.y = 2; - points.append(point); - point.x = 11; - point.y = 22; - points.append(point); - point.x = 111; - point.y = 222; - points.append(point); - - return points; -} -int WindowManager::getLayout() -{ - qDebug("-=[getLayout]=-"); - return m_currentLayout; + return m_appSurfaces; } +#endif QString WindowManager::getLayoutName(int layoutId) { qDebug("-=[getLayoutName]=-"); - return m_layoutNames.find(layoutId).value(); + QList::const_iterator i = m_layouts.begin(); + + QString result = "not found"; + while (i != m_layouts.constEnd()) + { + if (i->id == layoutId) + { + result = i->name; + } + + ++i; + } + + return result; +} + +void WindowManager::hideLayer(int layer) +{ + qDebug("-=[hideLayer]=-"); + qDebug("layer %d", layer); + +#ifdef HAVE_IVI_LAYERMANAGEMENT_API + // POPUP=0, HOMESCREEN_OVERLAY=1, APPS=2, HOMESCREEN=3 + if (layer >= 0 && layer < WINDOWMANAGER_LAYER_NUM) { + /* hide target layer */ + m_showLayers[layer] = 0; + + if (layer == WINDOWMANAGER_LAYER_APPLICATIONS) { + /* clear pending flag */ + m_pending_to_show = -1; + } else if (m_pending_to_show != -1) { + /* there is a pending application to show */ + showAppLayer(m_pending_to_show); + return; + } + + t_ilm_layer renderOrder[WINDOWMANAGER_LAYER_NUM]; + int num_layers = getLayerRenderOrder(renderOrder); + ilm_displaySetRenderOrder(m_screenId, renderOrder, num_layers); + ilm_commitChanges(); + } +#endif } -void WindowManager::setLayoutById(int layoutId) +int WindowManager::setLayoutById(int layoutId) { qDebug("-=[setLayoutById]=-"); + int result = WINDOWMANAGER_NO_ERROR; m_currentLayout = layoutId; - mp_layoutAreaToPidAssignment->clear(); + mp_layoutAreaToSurfaceIdAssignment->clear(); dumpScene(); + + return result; } -void WindowManager::setLayoutByName(const QString &layoutName) +int WindowManager::setLayoutByName(const QString &layoutName) { qDebug("-=[setLayoutByName]=-"); - QMap::iterator i = m_layoutNames.begin(); - while (i != m_layoutNames.constEnd()) + int result = WINDOWMANAGER_NO_ERROR; + + QList::const_iterator i = m_layouts.begin(); + + while (i != m_layouts.constEnd()) { - if (i.value() == layoutName) + if (i->name == layoutName) { - m_currentLayout = i.key(); + m_currentLayout = i->id; + + mp_layoutAreaToSurfaceIdAssignment->clear(); + + dumpScene(); } + ++i; } - mp_layoutAreaToPidAssignment->clear(); - - dumpScene(); + return result; } -void WindowManager::setPidToLayoutArea(int pid, int layoutAreaId) +int WindowManager::setSurfaceToLayoutArea(int surfaceId, int layoutAreaId) { - qDebug("-=[setPidToLayoutArea]=-"); - qDebug("pid %d", pid); + qDebug("-=[setSurfaceToLayoutArea]=-"); + int result = WINDOWMANAGER_NO_ERROR; + + qDebug("surfaceId %d", surfaceId); qDebug("layoutAreaId %d", layoutAreaId); - mp_layoutAreaToPidAssignment->insert(layoutAreaId, pid); + mp_layoutAreaToSurfaceIdAssignment->insert(layoutAreaId, surfaceId); -#ifdef __arm__ updateScreen(); -#endif dumpScene(); + + return result; +} + +void WindowManager::showLayer(int layer) +{ + qDebug("-=[showLayer]=-"); + qDebug("layer %d", layer); + +#ifdef HAVE_IVI_LAYERMANAGEMENT_API + // POPUP=0, HOMESCREEN_OVERLAY=1, APPS=2, HOMESCREEN=3 + if (layer >= 0 && layer < WINDOWMANAGER_LAYER_NUM) { + static const int layer_id_array[] = { + WINDOWMANAGER_LAYER_POPUP, + WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY, + WINDOWMANAGER_LAYER_APPLICATIONS, + WINDOWMANAGER_LAYER_HOMESCREEN, + }; + + m_showLayers[layer] = layer_id_array[layer]; + + t_ilm_layer renderOrder[WINDOWMANAGER_LAYER_NUM]; + int num_layers = getLayerRenderOrder(renderOrder); + ilm_displaySetRenderOrder(m_screenId, renderOrder, num_layers); + ilm_commitChanges(); + } +#endif +} + +void WindowManager::showAppLayer(int pid) +{ + qDebug("-=[showAppLayer]=-"); + qDebug("pid %d", pid); + + if (pid == -1) { + /* nothing to show */ + return; + } +#ifdef HAVE_IVI_LAYERMANAGEMENT_API + + /* clear pending flag */ + m_pending_to_show = -1; + + /* search layer id for application to show */ + QMap::const_iterator i = m_appLayers.find(pid); + + if (i != m_appLayers.end()) { + m_showLayers[2] = m_appLayers.value(pid); + qDebug("Found layer(%d) to show for app(pid=%d)", m_showLayers[2], pid); + } else { + /* Probably app layer hasn't been made yet */ + m_pending_to_show = pid; + /* hide current app once, back to default screen */ + m_showLayers[2] = 0; + + qDebug("No layer to show for app(pid=%d)", pid); + } + t_ilm_layer renderOrder[WINDOWMANAGER_LAYER_NUM]; + + int num_layers = getLayerRenderOrder(renderOrder); + ilm_displaySetRenderOrder(m_screenId, renderOrder, num_layers); + ilm_commitChanges(); +#endif }