App: be more thorough on (de)activate()
[staging/windowmanager.git] / src / app.cpp
index 80637a4..4feeb03 100644 (file)
@@ -426,7 +426,6 @@ char const *App::api_activate_surface(char const *drawing_name) {
    } else {
       bool can_split = this->can_split(state, *surface_id);
 
-      if (state.sub == -1) {
          if (can_split) {
             this->try_layout(
                state,
@@ -437,6 +436,9 @@ char const *App::api_activate_surface(char const *drawing_name) {
 
                   this->surface_set_layout(state.main, surface_id);
                   this->activate(*surface_id);
+                  if (state.sub != -1) {
+                     this->deactivate(state.sub);
+                  }
                   state = nl;
 
                   this->layout_commit();
@@ -451,7 +453,9 @@ char const *App::api_activate_surface(char const *drawing_name) {
                   this->surface_set_layout(*surface_id);
                   this->deactivate(state.main);
                   this->activate(*surface_id);
-                  this->deactivate(state.sub);
+                  if (state.sub != -1) {
+                     this->deactivate(state.sub);
+                  }
                   state = nl;
 
                   this->layout_commit();
@@ -459,7 +463,6 @@ char const *App::api_activate_surface(char const *drawing_name) {
                   this->enqueue_flushdraw(state.main);
                });
          }
-      }
    }
 
    // no error
@@ -675,7 +678,8 @@ result<int> App::api_request_surface(char const *drawing_name) {
 }
 
 void App::activate(int id) {
-   if (this->controller->sprops[id].visibility == 0) {
+   auto ip = this->controller->sprops.find(id);
+   if (ip != this->controller->sprops.end() && ip->second.visibility == 0) {
       this->controller->surfaces[id]->set_visibility(1);
       char const *label =
          this->lookup_name(id).value_or("unknown-name").c_str();
@@ -685,7 +689,8 @@ void App::activate(int id) {
 }
 
 void App::deactivate(int id) {
-   if (this->controller->sprops[id].visibility != 0) {
+   auto ip = this->controller->sprops.find(id);
+   if (ip != this->controller->sprops.end() && ip->second.visibility != 0) {
       this->controller->surfaces[id]->set_visibility(0);
       char const *label =
          this->lookup_name(id).value_or("unknown-name").c_str();