App: be more thorough on (de)activate()
[staging/windowmanager.git] / src / app.cpp
index a4b22f5..4feeb03 100644 (file)
@@ -80,7 +80,6 @@ App::App(wl::display *d)
      controller{},
      outputs(),
      config(),
-     layouts(),
      layers(),
      id_alloc{},
      pending_events(false),
@@ -230,7 +229,6 @@ int App::init_layers() {
       logdebug(
          "Setting up layer %s (%d) for surfaces %d-%d and role match \"%s\"",
          i.name.c_str(), i.layer_id, i.id_min, i.id_max, i.role.c_str());
-      this->layouts[l->id] = LayoutState{};
    }
 
    // Add layers to screen (XXX: are they sorted correctly?)
@@ -413,9 +411,6 @@ char const *App::api_activate_surface(char const *drawing_name) {
       return "Surface already active";
    }
 
-   // This should 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
 
    if (state.main == -1) {
       this->try_layout(
@@ -431,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,
@@ -442,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();
@@ -456,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();
@@ -464,7 +463,6 @@ char const *App::api_activate_surface(char const *drawing_name) {
                   this->enqueue_flushdraw(state.main);
                });
          }
-      }
    }
 
    // no error
@@ -680,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();
@@ -690,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();