- if (state.main != *surface_id) {
- std::string main = std::move(*this->lookup_name(state.main));
- this->emit_syncdraw(drawing_name);
- this->emit_syncdraw(main.c_str());
-
- this->surface_set_layout(state.main, surface_id);
- this->activate(*surface_id);
- state.sub = *surface_id;
-
- this->layout_commit();
- this->enqueue_flushdraw(state.main);
- this->enqueue_flushdraw(state.sub);
- }
+ this->try_layout(
+ state,
+ LayoutState{state.main, *surface_id},
+ [&] (LayoutState const &nl) {
+ std::string main =
+ std::move(*this->lookup_name(state.main));
+
+ 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();
+ this->emit_syncdraw(drawing_name);
+ this->emit_syncdraw(main.c_str());
+ this->enqueue_flushdraw(state.main);
+ this->enqueue_flushdraw(state.sub);
+ });