From 04c862b9957ea86959bd533cb1ac497ddb52759d Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Thu, 3 Aug 2017 10:37:01 +0200 Subject: 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 --- src/app.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/app.hpp | 1 + src/layers.cpp | 5 +++++ src/layers.hpp | 1 + 4 files changed, 46 insertions(+) (limited to 'src') 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); -- cgit