+char const *App::activate_surface(char const *drawing_name) {
+ auto const &surface_id = this->lookup_id(drawing_name);
+
+ if (!surface_id) {
+ return "Surface does not exist";
+ }
+
+ if (!this->controller->surface_exists(*surface_id)) {
+ return "Surface does not exist in controller!";
+ }
+
+ if (this->state.main == *surface_id || this->state.sub == *surface_id) {
+ 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
+
+ // Make it visible, no (or little effect) if already visible
+ auto &s = this->controller->surfaces[*surface_id];
+
+ //// Set all others invisible
+ //for (auto &i : this->controller->surfaces) {
+ // auto &si = this->controller->sprops[i.second->id];
+ // if (si.id != s->id && si.visibility != 0 &&
+ // int(si.id) != this->layers.main_surface) {
+ // this->deactivate(si.id);
+ // }
+ //}
+
+ if (this->state.main == -1) {
+ this->surface_set_layout_full(*surface_id);
+ this->activate(*surface_id);
+ this->state.main = *surface_id;
+ this->state.sub = -1;
+ this->state.s = LayoutState::Single;
+ } else {
+ bool can_split = this->can_split(*surface_id);
+
+ if (this->state.sub == -1) {
+ if (can_split) {
+ if (this->state.main != *surface_id) {
+ this->surface_set_layout_split(this->state.main, *surface_id);
+ this->activate(*surface_id);
+ this->state.sub = *surface_id;
+ }
+ } else {
+ this->surface_set_layout_full(*surface_id);
+ this->deactivate(this->state.main);
+ this->activate(*surface_id);
+ this->deactivate(this->state.sub);
+ this->state.main = *surface_id;
+ this->state.sub = -1;
+ this->state.s = LayoutState::Single;
+ }
+ }
+ }
+
+ // commit changes
+ this->controller->commit_changes();
+ this->display->flush();
+
+ // no error
+ return nullptr;