Add configuration file over-ride mechanism
[apps/agl-service-windowmanager.git] / src / layers.cpp
index 6ffb4e2..21d975d 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ * Copyright (c) 2018 Konsulko Group
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +19,7 @@
 
 #include "layers.hpp"
 #include "json_helper.hpp"
+#include "util.hpp"
 #include "hmi-debug.h"
 
 namespace wm
@@ -181,22 +183,9 @@ json layer_map::to_json() const
     return j;
 }
 
-void layer_map::setupArea(int output_w, int output_h)
+void layer_map::setupArea(double scaling)
 {
     compositor::rect rct;
-    for (auto &i : this->area2size)
-    {
-        rct = i.second;
-
-        // less-than-0 values refer to MAX + 1 - $VALUE
-        // e.g. MAX is either screen width or height
-        if(rct.w < 0)
-            rct.w = output_w + 1 + rct.w;
-        if(rct.h < 0)
-            rct.h = output_h + 1 + rct.h;
-
-        i.second = rct;
-    }
 
     rct = this->area2size["normal.full"];
     this->area2size["normalfull"] = rct;
@@ -204,6 +193,11 @@ void layer_map::setupArea(int output_w, int output_h)
 
     for (auto &i : this->area2size)
     {
+        i.second.x = static_cast<int>(scaling * i.second.x + 0.5);
+        i.second.y = static_cast<int>(scaling * i.second.y + 0.5);
+        i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
+        i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
+
         HMI_DEBUG("wm:lm", "area:%s size(after) : x:%d y:%d w:%d h:%d",
             i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
     }
@@ -218,19 +212,7 @@ int layer_map::loadAreaDb()
 {
     HMI_DEBUG("wm:lm", "Call");
 
-    // Get afm application installed dir
-    char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
-    HMI_DEBUG("wm:lm", "afm_app_install_dir:%s", afm_app_install_dir);
-
-    std::string file_name;
-    if (!afm_app_install_dir)
-    {
-        HMI_ERROR("wm:lm", "AFM_APP_INSTALL_DIR is not defined");
-    }
-    else
-    {
-        file_name = std::string(afm_app_install_dir) + std::string("/etc/areas.db");
-    }
+    std::string file_name(get_file_path("areas.db"));
 
     // Load area.db
     json_object *json_obj;
@@ -308,8 +290,8 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 0, \
-                \"w\": -1, \
-                \"h\": -1 \
+                \"w\": 1080, \
+                \"h\": 1920 \
             } \
         }, \
         { \
@@ -317,8 +299,8 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 218, \
-                \"w\": -1, \
-                \"h\": -433 \
+                \"w\": 1080, \
+                \"h\": 1488 \
             } \
         }, \
         { \
@@ -326,7 +308,7 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 218, \
-                \"w\": -1, \
+                \"w\": 1080, \
                 \"h\": 744 \
             } \
         }, \
@@ -335,7 +317,7 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 962, \
-                \"w\": -1, \
+                \"w\": 1080, \
                 \"h\": 744 \
             } \
         }, \
@@ -344,7 +326,7 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 962, \
-                \"w\": -1, \
+                \"w\": 1080, \
                 \"h\": 744 \
             } \
         }, \
@@ -353,8 +335,8 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 218, \
-                \"w\": -1, \
-                \"h\": -433 \
+                \"w\": 1080, \
+                \"h\": 1488 \
             } \
         }, \
         { \
@@ -362,7 +344,7 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 218, \
-                \"w\": -1, \
+                \"w\": 1080, \
                 \"h\": 744 \
             } \
         }, \
@@ -371,7 +353,7 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 962, \
-                \"w\": -1, \
+                \"w\": 1080, \
                 \"h\": 744 \
             } \
         }, \
@@ -380,8 +362,8 @@ const char* layer_map::kDefaultAreaDb = "{ \
             \"rect\": { \
                 \"x\": 0, \
                 \"y\": 218, \
-                \"w\": -1, \
-                \"h\": -433 \
+                \"w\": 1080, \
+                \"h\": 1488 \
             } \
         } \
     ] \