replace a SLOT macro with SIGNAL where a signal is triggered
[staging/HomeScreen.git] / HomeScreen / src / layouthandler.cpp
index 11dd2cb..6aad54b 100644 (file)
@@ -27,6 +27,13 @@ LayoutHandler::LayoutHandler(QObject *parent) :
                                               "/Popup",
                                               QDBusConnection::sessionBus(),
                                               0);
+
+    QDBusConnection::sessionBus().connect("org.agl.windowmanager",
+                                       "/windowmanager",
+                                       "org.agl.windowmanager",
+                                       "surfaceVisibilityChanged",
+                                       this,
+                                       SIGNAL(surfaceVisibilityChanged(int,bool)));
 }
 
 LayoutHandler::~LayoutHandler()
@@ -54,6 +61,7 @@ void LayoutHandler::setUpLayouts()
     const int CONTROLBAR_Y = SCREEN_HEIGHT - CONTROLBAR_HEIGHT;
 
 
+    // only one Layout for CES2017 needed
     // layout 1:
     // one app surface, statusbar, control bar
     surfaceArea.x = 0;
@@ -65,7 +73,7 @@ void LayoutHandler::setUpLayouts()
 
     mp_dBusWindowManagerProxy->addLayout(1, "one app", surfaceAreas);
 
-
+    /*
     surfaceAreas.clear();
 
     // layout 2:
@@ -111,17 +119,19 @@ void LayoutHandler::setUpLayouts()
 
     surfaceAreas.append(surfaceArea);
 
-    mp_dBusWindowManagerProxy->addLayout(3, "side by side", surfaceAreas);
+    mp_dBusWindowManagerProxy->addLayout(3, "side by side", surfaceAreas);*/
 }
 
 void LayoutHandler::showAppLayer()
 {
-    mp_dBusWindowManagerProxy->showLayer(1); //1==app layer
+    // POPUP=0, HOMESCREEN_OVERLAY=1, APPS=2, HOMESCREEN=3
+    mp_dBusWindowManagerProxy->showLayer(2); // TODO: enum
 }
 
 void LayoutHandler::hideAppLayer()
 {
-    mp_dBusWindowManagerProxy->hideLayer(1); //1==app layer
+    // POPUP=0, HOMESCREEN_OVERLAY=1, APPS=2, HOMESCREEN=3
+    mp_dBusWindowManagerProxy->hideLayer(2); // TODO: enum
 }
 
 void LayoutHandler::makeMeVisible(int pid)
@@ -165,35 +175,29 @@ void LayoutHandler::checkToDoQueue()
 
             if (0 != allSurfaces.size())
             {
-                m_requestsToBeVisibleSurfaces.append(allSurfaces.at(0));
+                if (-1 == m_visibleSurfaces.indexOf(allSurfaces.at(0)))
+                {
+                    qDebug("already visible");
+                }
+                if (-1 == m_invisibleSurfaces.indexOf(allSurfaces.at(0)))
+                {
+                    m_invisibleSurfaces.removeAt(m_invisibleSurfaces.indexOf(allSurfaces.at(0)));
+                }
+                if (-1 == m_requestsToBeVisibleSurfaces.indexOf(allSurfaces.at(0)))
+                {
+                    m_requestsToBeVisibleSurfaces.append(allSurfaces.at(0));
+                }
 
                 qDebug("m_visibleSurfaces %d", m_visibleSurfaces.size());
                 qDebug("m_invisibleSurfaces %d", m_invisibleSurfaces.size());
                 qDebug("m_requestsToBeVisibleSurfaces %d", m_requestsToBeVisibleSurfaces.size());
 
-                QList<int> availableLayouts = mp_dBusWindowManagerProxy->getAvailableLayouts(m_visibleSurfaces.size() + m_requestsToBeVisibleSurfaces.size());
-                if (0 == availableLayouts.size())
-                {
-                    // no layout fits the need!
-                    // replace the last app
-                    qDebug("no layout fits the need!");
-                    qDebug("replace the last surface");
-
-                    m_invisibleSurfaces.append(m_visibleSurfaces.last());
-                    m_visibleSurfaces.removeLast();
-
-                    m_visibleSurfaces.append(m_requestsToBeVisibleSurfaces);
-                    m_requestsToBeVisibleSurfaces.clear();
-
-                    for (int i = 0; i < m_visibleSurfaces.size(); ++i)
-                    {
-                        mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(m_visibleSurfaces.at(i), i);
-                    }
-                }
+                QList<int> availableLayouts = mp_dBusWindowManagerProxy->getAvailableLayouts(1); // one app only for CES2017
                 if (1 == availableLayouts.size())
                 {
-                    // switch to new layout
-                    qDebug("switch to new layout %d", availableLayouts.at(0));
+                    qDebug("active layout: %d", availableLayouts.at(0));
+                    m_invisibleSurfaces.append(m_visibleSurfaces);
+                    m_visibleSurfaces.clear();
                     m_visibleSurfaces.append(m_requestsToBeVisibleSurfaces);
                     m_requestsToBeVisibleSurfaces.clear();
 
@@ -203,18 +207,9 @@ void LayoutHandler::checkToDoQueue()
                         mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(m_visibleSurfaces.at(i), i);
                     }
                 }
-                if (1 < availableLayouts.size())
+                else
                 {
-                    // more than one layout possible! Ask user.
-                    qDebug("more than one layout possible! Ask user.");
-
-                    QStringList choices;
-                    for (int i = 0; i < availableLayouts.size(); ++i)
-                    {
-                        choices.append(mp_dBusWindowManagerProxy->getLayoutName(availableLayouts.at(i)));
-                    }
-
-                    mp_dBusPopupProxy->showPopupComboBox("Select Layout", choices);
+                    qDebug("this should not happen!?");
                 }
             }
         }
@@ -248,9 +243,16 @@ int LayoutHandler::requestGetSurfaceStatus(int surfaceId)
     return result;
 }
 
-void LayoutHandler::requestRenderSurfaceToArea(int surfaceId, const QRect &renderArea)
+void LayoutHandler::requestRenderSurfaceToArea(int surfaceId, int layoutArea)
 {
-    qDebug("requestRenderSurfaceToArea %d %d,%d,%d,%d", surfaceId, renderArea.x(), renderArea.y(), renderArea.width(), renderArea.height());
+    qDebug("requestRenderSurfaceToArea %d %d", surfaceId, layoutArea);
+}
+
+bool LayoutHandler::requestRenderSurfaceToAreaAllowed(int surfaceId, int layoutArea)
+{
+    qDebug("requestRenderSurfaceToAreaAllowed %d %d", surfaceId, layoutArea);
+    bool result = true;
+    return result;
 }
 
 void LayoutHandler::requestSurfaceIdToFullScreen(int surfaceId)
@@ -272,6 +274,12 @@ void LayoutHandler::setLayoutByName(QString layoutName)
     }
 }
 
+void LayoutHandler::requestSurfaceVisibilityChanged(int surfaceId, bool visible)
+{
+    qDebug("requestSurfaceVisibilityChanged %d %s", surfaceId, visible ? "true" : "false");
+    emit surfaceVisibilityChanged(surfaceId, visible);
+}
+
 void LayoutHandler::timerEvent(QTimerEvent *e)
 {
     if (e->timerId() == m_secondsTimerId)