+ s->set_render_order(this->layers.layers);
+
+ this->layout_commit();
+
+ return 0;
+}
+
+namespace {
+
+#ifdef WE_LIKE_NOT_TO_USE_THIS
+// This can fix the HomeScreen...
+void redraw_fix(App *app, std::unique_ptr<genivi::surface> &s, int x, int y,
+ int w, int h) {
+ { // XXX: Work around weston redraw issues
+ // trigger an update by changing the source dimensions!
+ s->set_configuration(w + 1, h);
+ s->set_source_rectangle(0, 0, w + 1, h);
+ s->set_destination_rectangle(x, y, w + 1, h);
+ app->controller->commit_changes();
+ app->display->roundtrip();
+
+ // wait some time, for the process to do its thing...
+ using namespace std::chrono_literals;
+ std::this_thread::sleep_for(100ms);
+
+ // Set a different size then what we actually want.
+ s->set_configuration(w, h);
+ s->set_source_rectangle(0, 0, w, h);
+ s->set_destination_rectangle(x, y, w, h);
+ app->controller->commit_changes();
+ app->display->roundtrip();
+ }
+}
+#endif
+
+} // namespace
+
+void App::surface_set_layout(int surface_id, optional<int> sub_surface_id) {
+ if (!this->controller->surface_exists(surface_id)) {
+ logerror("Surface %d does not exist", surface_id);
+ return;
+ }
+
+ auto o_layer_id = this->layers.get_layer_id(surface_id);
+
+ if (!o_layer_id) {
+ logerror("Surface %d is not associated with any layer!", surface_id);
+ return;
+ }
+
+ uint32_t layer_id = *o_layer_id;
+
+ auto const &layer = this->layers.get_layer(layer_id);
+ auto rect = layer.value().rect;
+ auto &s = this->controller->surfaces[surface_id];
+
+ int x = rect.x;
+ int y = rect.y;
+ int w = rect.w;
+ int h = rect.h;
+
+ // less-than-0 values refer to MAX + 1 - $VALUE
+ // e.g. MAX is either screen width or height
+ if (w < 0) {
+ w = this->controller->output_size.w + 1 + w;
+ }
+ if (h < 0) {
+ h = this->controller->output_size.h + 1 + h;
+ }
+
+ if (sub_surface_id) {
+ if (o_layer_id != this->layers.get_layer_id(*sub_surface_id)) {
+ logerror(
+ "surface_set_layout: layers of surfaces (%d and %d) don't match!",
+ surface_id, *sub_surface_id);
+ return;
+ }
+
+ int x_off = 0;
+ int y_off = 0;
+
+ // split along major axis
+ if (w > h) {
+ w /= 2;
+ x_off = w;
+ } else {
+ h /= 2;
+ y_off = h;
+ }
+
+ auto &ss = this->controller->surfaces[*sub_surface_id];
+
+ logdebug("surface_set_layout for sub surface %u on layer %u",
+ *sub_surface_id, layer_id);
+
+ // configure surface to wxh dimensions
+ ss->set_configuration(w, h);
+ // set source reactangle, even if we should not need to set it.
+ ss->set_source_rectangle(0, 0, w, h);
+ // set destination to the display rectangle
+ ss->set_destination_rectangle(x + x_off, y + y_off, w, h);
+ }
+
+ logdebug("surface_set_layout for surface %u on layer %u", surface_id,
+ layer_id);
+
+ // configure surface to wxh dimensions
+ s->set_configuration(w, h);
+ // set source reactangle, even if we should not need to set it.
+ s->set_source_rectangle(0, 0, w, h);
+ // set destination to the display rectangle
+ s->set_destination_rectangle(x, y, w, h);