Fix source rectangle changes every state change
[apps/agl-service-windowmanager-2017.git] / src / window_manager.cpp
index 481a5fb..c57ab09 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "window_manager.hpp"
 #include "json_helper.hpp"
+#include "wm_config.hpp"
 #include "applist.hpp"
 
 extern "C"
@@ -29,7 +30,7 @@ extern "C"
 namespace wm
 {
 
-static const unsigned kTimeOut = 3000000UL; /* 3s */
+static const uint64_t kTimeOut = 3ULL; /* 3s */
 
 /* DrawingArea name used by "{layout}.{area}" */
 const char kNameLayoutNormal[] = "normal";
@@ -146,6 +147,7 @@ WindowManager::WindowManager(wl::display *d)
 
 int WindowManager::init()
 {
+    int ret;
     if (!this->display->ok())
     {
         return -1;
@@ -201,7 +203,8 @@ int WindowManager::init()
     // Third level objects
     this->display->roundtrip();
 
-    return init_layers();
+    ret = init_layers();
+    return ret;
 }
 
 int WindowManager::dispatch_pending_events()
@@ -235,7 +238,7 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
         HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role);
         if (!lid)
         {
-            return Err<int>("Drawing name does not match any role, Fallback is disabled");
+            return Err<int>("Drawing name does not match any role, fallback is disabled");
         }
     }
 
@@ -289,7 +292,7 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr
         HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role);
         if (!lid)
         {
-            return "Drawing name does not match any role, Fallback is disabled";
+            return "Drawing name does not match any role, fallback is disabled";
         }
     }
 
@@ -573,6 +576,8 @@ void WindowManager::send_event(char const *evname, char const *label, char const
  */
 void WindowManager::surface_created(uint32_t surface_id)
 {
+    this->controller->get_surface_properties(surface_id, IVI_WM_PARAM_SIZE);
+
     auto layer_id = this->layers.get_layer_id(surface_id);
     if (!layer_id)
     {
@@ -654,12 +659,22 @@ int WindowManager::init_layers()
         return -1;
     }
 
+    WMConfig wm_config;
+    wm_config.loadConfigs();
+
     auto &c = this->controller;
 
     auto &o = this->outputs.front();
     auto &s = c->screens.begin()->second;
     auto &layers = c->layers;
 
+    this->layers.loadAreaDb();
+    const compositor::rect base = this->layers.getAreaSize("fullscreen");
+
+    const std::string aspect_setting = wm_config.getConfigAspect();
+    const compositor::rect scale_rect =
+        this->layers.getScaleDestRect(o->width, o->height, aspect_setting);
+
     // Write output dimensions to ivi controller...
     c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
     c->physical_size = compositor::size{uint32_t(o->physical_width),
@@ -674,9 +689,11 @@ int WindowManager::init_layers()
     // Quick and dirty setup of layers
     for (auto const &i : this->layers.mapping)
     {
-        c->layer_create(i.second.layer_id, o->width, o->height);
+        c->layer_create(i.second.layer_id, scale_rect.w, scale_rect.h);
         auto &l = layers[i.second.layer_id];
-        l->set_destination_rectangle(0, 0, o->width, o->height);
+        l->set_source_rectangle(0, 0, base.w, base.h);
+        l->set_destination_rectangle(
+            scale_rect.x, scale_rect.y, scale_rect.w, scale_rect.h);
         l->set_visibility(1);
         HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
                   i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
@@ -687,8 +704,6 @@ int WindowManager::init_layers()
 
     this->layout_commit();
 
-    this->layers.setupArea(o->width, o->height);
-
     return 0;
 }
 
@@ -721,17 +736,6 @@ void WindowManager::surface_set_layout(int surface_id, const std::string& area)
     int w = rect.w;
     int h = rect.h;
 
-    // less-than-0 values refer to MAX + 1 - $VALUE
-    // e.g. MAX is either screen width or height
-    if (w < 0)
-    {
-        w = this->controller->output_size.w + 1 + w;
-    }
-    if (h < 0)
-    {
-        h = this->controller->output_size.h + 1 + h;
-    }
-
     HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
               layer_id);
 
@@ -1098,6 +1102,15 @@ WMError WindowManager::setInvisibleTask(const std::string &role, bool split)
 {
     unsigned req_num = g_app_list.currentRequestNumber();
     HMI_SEQ_DEBUG(req_num, "set current visible app to invisible task");
+    bool found = false;
+    auto trigger = g_app_list.getRequest(req_num, &found);
+    // I don't check found == true here because this is checked in caller.
+    if(trigger.role == "homescreen")
+    {
+        HMI_SEQ_INFO(req_num, "In case of 'homescreen' visible, don't change app to invisible");
+        return WMError::SUCCESS;
+    }
+
     // This task is copied from original actiavete surface
     const char *drawing_name = this->rolenew2old[role].c_str();
     auto const &surface_id = this->lookup_id(role.c_str());
@@ -1109,7 +1122,6 @@ WMError WindowManager::setInvisibleTask(const std::string &role, bool split)
     int surface;
     TaskVisible task_visible = TaskVisible::INVISIBLE;
     bool end_draw_finished = true;
-    bool found = false;
 
     for (auto const &l : this->layers.mapping)
     {
@@ -1276,6 +1288,7 @@ WMError WindowManager::doEndDraw(unsigned req_num)
         HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str());
         //this->lm_enddraw(act.role.c_str());
     }
+    this->layout_commit();
 
     // Change current state
     this->changeCurrentState(req_num);
@@ -1445,17 +1458,22 @@ void WindowManager::emitScreenUpdated(unsigned req_num)
     {
         HMI_DEBUG("wm", "afb_event_push failed: %m");
     }
-    json_object_put(jarray);
 }
 
 void WindowManager::setTimer()
 {
+    struct timespec ts;
+    if (clock_gettime(CLOCK_BOOTTIME, &ts) != 0) {
+        HMI_ERROR("wm", "Could't set time (clock_gettime() returns with error");
+        return;
+    }
+
     HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Timer set activate");
     if (g_timer_ev_src == nullptr)
     {
         // firsttime set into sd_event
         int ret = sd_event_add_time(afb_daemon_get_event_loop(), &g_timer_ev_src,
-            CLOCK_REALTIME, time(NULL) * (1000000UL) + kTimeOut, 1, processTimerHandler, this);
+            CLOCK_BOOTTIME, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL, 1, processTimerHandler, this);
         if (ret < 0)
         {
             HMI_ERROR("wm", "Could't set timer");
@@ -1464,7 +1482,7 @@ void WindowManager::setTimer()
     else
     {
         // update timer limitation after second time
-        sd_event_source_set_time(g_timer_ev_src, time(NULL) * (1000000UL) + kTimeOut);
+        sd_event_source_set_time(g_timer_ev_src, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL);
         sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_ONESHOT);
     }
 }
@@ -1750,12 +1768,12 @@ const char* WindowManager::kDefaultOldRoleDb = "{ \
  */
 void controller_hooks::surface_created(uint32_t surface_id)
 {
-    this->app->surface_created(surface_id);
+    this->wmgr->surface_created(surface_id);
 }
 
 void controller_hooks::surface_removed(uint32_t surface_id)
 {
-    this->app->surface_removed(surface_id);
+    this->wmgr->surface_removed(surface_id);
 }
 
 void controller_hooks::surface_visibility(uint32_t /*surface_id*/,