app/api: add demo_activate_surface() api_binding
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Thu, 3 Aug 2017 08:37:01 +0000 (10:37 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000 (17:24 +0200)
* Added "main_surface" entry to layers.json.
* This surface is never made invisible by activate_surface().

Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
generate-binding-glue.py
layers.json
src/app.cpp
src/app.hpp
src/layers.cpp
src/layers.hpp

index 2a422d2..7aaad36 100644 (file)
@@ -107,6 +107,7 @@ API = {
                     { 'name': 'surfaceid', 'type': 'uint32_t', 'jtype': 'int' },
                 ],
             },
+            { 'name': 'demo_activate_surface', 'args': [ { 'name': 'surfaceid', 'type': 'uint32_t', 'jtype': 'int' } ] },
             { 'name': 'debug_status', },
             { 'name': 'debug_layers', },
             { 'name': 'debug_surfaces', },
index f7cdfe5..0d31a5b 100644 (file)
@@ -1,5 +1,10 @@
 {
    "comment": "Surface ID to Layer ID mapping",
+
+   "main_surface": {
+      "surface_id": "1000",
+      "comment": "This surface should never be made invisible (The HomeScreen)"
+   },
    "mappings": [
       {
          "type": "single",
index 5791f21..713fd1e 100644 (file)
@@ -319,6 +319,36 @@ void App::surface_set_layout(uint32_t surface_id) {
             surface_id, layer_id, x, y, w, h);
 }
 
+char const *App::activate_surface(uint32_t surface_id) {
+   if (! this->controller->surface_exists(surface_id)) {
+      return "Surface does not exist";
+   }
+
+   // This shouild involve a policy check, but as we do not (yet) have
+   // such a thing, we will just switch to this surface.
+   // XXX: input focus missing!!1
+
+   // Make it visible, no (or little effect) if already visible
+   auto &s = this->controller->surfaces[surface_id];
+   s->set_visibility(1);
+
+   // Set all others invisible
+   for (auto &i: this->controller->surfaces) {
+      auto &si = this->controller->sprops[i.second->id];
+      // XXX: filtering out homescreen ID ... set this in a known place!!1
+      if (si.visibility == 1 && si.id != s->id && int(si.id) != this->layers.main_surface) {
+         i.second->set_visibility(0);
+      }
+   }
+
+   // commit changes
+   this->controller->commit_changes();
+   this->display->flush();
+
+   // no error
+   return nullptr;
+}
+
 void App::add_task(char const *name, std::function<void()> &&f) {
    this->pending.emplace_back(std::make_pair(name, f));
 }
@@ -400,6 +430,15 @@ binding_api::result_type binding_api::debug_terminate() {
    return Ok(json_object_new_object());
 }
 
+binding_api::result_type binding_api::demo_activate_surface(
+        uint32_t surfaceid) {
+   char const *e = this->app->activate_surface(surfaceid);
+   if (e) {
+      return Err<json_object *>(e);
+   }
+   return Ok(json_object_new_object());
+}
+
 //                  _             _ _            _                 _
 //   ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __ | |__   ___   ___ | | _____
 //  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|| '_ \ / _ \ / _ \| |/ / __|
index 3f899ce..9df1573 100644 (file)
@@ -70,6 +70,7 @@ struct App {
    int dispatch_events();
    int init_layout();
    void surface_set_layout(uint32_t surface_id);
+   char const *activate_surface(uint32_t surface_id);
 
    void add_task(char const *name, std::function<void()> &&f);
    void execute_pending();
index b5ce2ed..6eae48a 100644 (file)
@@ -71,6 +71,11 @@ struct result<struct layer_map> to_layer_map(nlohmann::json const &j) {
          }
       }
 
+      auto msi = j.find("main_surface");
+      if (msi != j.end()) {
+         stl.main_surface = get<int>((*msi)["surface_id"]);
+      }
+
       // Check lookup
       auto jtests = j.value("tests", json());
 
index a6df4a0..a02eb00 100644 (file)
@@ -68,6 +68,7 @@ struct layer_map {
 
    storage_type mapping;
    layers_type layers;
+   int main_surface;
 
    optional<int> get_layer_id(int surface_id);
    optional<genivi::rect> get_layer_rect(int surface_id);