From: Marcus Fritzsch Date: Thu, 3 Aug 2017 08:37:01 +0000 (+0200) Subject: app/api: add demo_activate_surface() api_binding X-Git-Tag: 4.99.1~177 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2Fwindowmanager.git;a=commitdiff_plain;h=04c862b9957ea86959bd533cb1ac497ddb52759d app/api: add demo_activate_surface() api_binding * Added "main_surface" entry to layers.json. * This surface is never made invisible by activate_surface(). Signed-off-by: Marcus Fritzsch --- diff --git a/generate-binding-glue.py b/generate-binding-glue.py index 2a422d2..7aaad36 100644 --- a/generate-binding-glue.py +++ b/generate-binding-glue.py @@ -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', }, diff --git a/layers.json b/layers.json index f7cdfe5..0d31a5b 100644 --- a/layers.json +++ b/layers.json @@ -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", diff --git a/src/app.cpp b/src/app.cpp index 5791f21..713fd1e 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -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 &&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(e); + } + return Ok(json_object_new_object()); +} + // _ _ _ _ _ // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __ | |__ ___ ___ | | _____ // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|| '_ \ / _ \ / _ \| |/ / __| diff --git a/src/app.hpp b/src/app.hpp index 3f899ce..9df1573 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -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 &&f); void execute_pending(); diff --git a/src/layers.cpp b/src/layers.cpp index b5ce2ed..6eae48a 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -71,6 +71,11 @@ struct result to_layer_map(nlohmann::json const &j) { } } + auto msi = j.find("main_surface"); + if (msi != j.end()) { + stl.main_surface = get((*msi)["surface_id"]); + } + // Check lookup auto jtests = j.value("tests", json()); diff --git a/src/layers.hpp b/src/layers.hpp index a6df4a0..a02eb00 100644 --- a/src/layers.hpp +++ b/src/layers.hpp @@ -68,6 +68,7 @@ struct layer_map { storage_type mapping; layers_type layers; + int main_surface; optional get_layer_id(int surface_id); optional get_layer_rect(int surface_id);