App: be a little more thorough when activating a surface
[staging/windowmanager.git] / src / app.cpp
index e4a4c4d..f76ebbd 100644 (file)
@@ -386,7 +386,8 @@ char const *App::activate_surface(char const *drawing_name) {
    // Set all others invisible
    for (auto &i : this->controller->surfaces) {
       auto &si = this->controller->sprops[i.second->id];
-      if (si.visibility != 0 && int(si.id) != this->layers.main_surface) {
+      if (si.visibility != 0 &&
+          int(si.id) != this->layers.main_surface) {
          this->deactivate(i.second->id);
       }
    }
@@ -431,16 +432,12 @@ char const *App::deactivate_surface(char const *drawing_name) {
 // | .__/|_|  \___/_/\_\_|\___|\__,_| |_____| \_/ \___|_| |_|\__|___/
 // |_|
 void App::surface_created(uint32_t surface_id) {
-   //surface_id >>= id_allocator::id_shift;
-
    logdebug("surface_id is %u", surface_id);
 
    this->surface_init_layout(surface_id);
 }
 
 void App::surface_removed(uint32_t surface_id) {
-   //surface_id >>= id_allocator::id_shift;
-
    logdebug("surface_id is %u", surface_id);
 
    this->id_alloc.remove_id(surface_id);
@@ -495,13 +492,19 @@ result<int> App::request_surface(char const *drawing_name) {
 }
 
 void App::activate(unsigned id) {
-   this->controller->surfaces[id]->set_visibility(1);
-   this->emit_activated(this->lookup_name(id).value_or("unknown-name").c_str());
+   if (this->controller->sprops[id].visibility == 0) {
+      this->controller->surfaces[id]->set_visibility(1);
+      this->emit_activated(
+              this->lookup_name(id).value_or("unknown-name").c_str());
+   }
 }
 
 void App::deactivate(unsigned id) {
-   this->controller->surfaces[id]->set_visibility(0);
-   this->emit_deactivated(this->lookup_name(id).value_or("unknown-name").c_str());
+   if (this->controller->sprops[id].visibility != 0) {
+      this->controller->surfaces[id]->set_visibility(0);
+      this->emit_deactivated(
+              this->lookup_name(id).value_or("unknown-name").c_str());
+   }
 }
 
 //  _     _           _ _                            _   _                 _
@@ -524,6 +527,7 @@ binding_api::result_type binding_api::activate_surface(
    logdebug("%s drawing_name %s", __func__, drawing_name);
    auto r = this->app->activate_surface(drawing_name);
    if (r != nullptr) {
+      logdebug("%s failed with error: %s", __func__, r);
       return Err<json_object *>(r);
    }
    return Ok(json_object_new_object());
@@ -533,6 +537,7 @@ binding_api::result_type binding_api::deactivate_surface(char const* drawing_nam
    logdebug("%s drawing_name %s", __func__, drawing_name);
    auto r = this->app->deactivate_surface(drawing_name);
    if (r != nullptr) {
+      logdebug("%s failed with error: %s", __func__, r);
       return Err<json_object *>(r);
    }
    return Ok(json_object_new_object());
@@ -575,14 +580,6 @@ 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 s) {
-   return Err<json_object *>("not implemented");
-}
-
-binding_api::result_type binding_api::demo_activate_all() {
-   return Err<json_object *>("not implemented");
-}
-
 //                  _             _ _            _                 _
 //   ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __ | |__   ___   ___ | | _____
 //  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|| '_ \ / _ \ / _ \| |/ / __|