app/api: add demo_activate_surface() api_binding
[staging/windowmanager.git] / src / app.cpp
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());
+}
+
 //                  _             _ _            _                 _
 //   ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __ | |__   ___   ___ | | _____
 //  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|| '_ \ / _ \ / _ \| |/ / __|