wl_list_insert(&surface->geometry.transformation_list,
&surface->transform.position.link);
weston_matrix_init(&surface->transform.position.matrix);
+ wl_list_init(&surface->geometry.child_list);
pixman_region32_init(&surface->transform.boundingbox);
surface->transform.dirty = 1;
static int
weston_surface_update_transform_enable(struct weston_surface *surface)
{
+ struct weston_surface *parent = surface->geometry.parent;
struct weston_matrix *matrix = &surface->transform.matrix;
struct weston_matrix *inverse = &surface->transform.inverse;
struct weston_transform *tform;
wl_list_for_each(tform, &surface->geometry.transformation_list, link)
weston_matrix_multiply(matrix, &tform->matrix);
+ if (parent)
+ weston_matrix_multiply(matrix, &parent->transform.matrix);
+
if (weston_matrix_invert(inverse, matrix) < 0) {
/* Oops, bad total transformation, not invertible */
weston_log("error: weston_surface %p"
WL_EXPORT void
weston_surface_update_transform(struct weston_surface *surface)
{
+ struct weston_surface *parent = surface->geometry.parent;
+
if (!surface->transform.dirty)
return;
+ if (parent)
+ weston_surface_update_transform(parent);
+
surface->transform.dirty = 0;
weston_surface_damage_below(surface);
if (surface->geometry.transformation_list.next ==
&surface->transform.position.link &&
surface->geometry.transformation_list.prev ==
- &surface->transform.position.link) {
+ &surface->transform.position.link &&
+ !parent) {
weston_surface_update_transform_disable(surface);
} else {
if (weston_surface_update_transform_enable(surface) < 0)
WL_EXPORT void
weston_surface_geometry_dirty(struct weston_surface *surface)
{
+ struct weston_surface *child;
+
+ /*
+ * The invariant: if surface->geometry.dirty, then all surfaces
+ * in surface->geometry.child_list have geometry.dirty too.
+ * Corollary: if not parent->geometry.dirty, then all ancestors
+ * are not dirty.
+ */
+
+ if (surface->transform.dirty)
+ return;
+
surface->transform.dirty = 1;
+
+ wl_list_for_each(child, &surface->geometry.child_list,
+ geometry.parent_link)
+ weston_surface_geometry_dirty(child);
}
WL_EXPORT void
weston_surface_geometry_dirty(surface);
}
+static void
+transform_parent_handle_parent_destroy(struct wl_listener *listener,
+ void *data)
+{
+ struct weston_surface *surface =
+ container_of(listener, struct weston_surface,
+ geometry.parent_destroy_listener);
+
+ weston_surface_set_transform_parent(surface, NULL);
+}
+
+WL_EXPORT void
+weston_surface_set_transform_parent(struct weston_surface *surface,
+ struct weston_surface *parent)
+{
+ if (surface->geometry.parent) {
+ wl_list_remove(&surface->geometry.parent_destroy_listener.link);
+ wl_list_remove(&surface->geometry.parent_link);
+ }
+
+ surface->geometry.parent = parent;
+
+ surface->geometry.parent_destroy_listener.notify =
+ transform_parent_handle_parent_destroy;
+ if (parent) {
+ wl_signal_add(&parent->surface.resource.destroy_signal,
+ &surface->geometry.parent_destroy_listener);
+ wl_list_insert(&parent->geometry.child_list,
+ &surface->geometry.parent_link);
+ }
+
+ weston_surface_geometry_dirty(surface);
+}
+
WL_EXPORT int
weston_surface_is_mapped(struct weston_surface *surface)
{
struct weston_compositor *compositor = surface->compositor;
struct weston_frame_callback *cb, *next;
+ assert(wl_list_empty(&surface->geometry.child_list));
+
if (weston_surface_is_mapped(surface))
weston_surface_unmap(surface);
wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link)
wl_resource_destroy(&cb->resource);
+ weston_surface_set_transform_parent(surface, NULL);
+
free(surface);
}
* If you want to apply a transformation in local coordinates, add your
* weston_transform to the head of the list. If you want to apply a
* transformation in global coordinates, add it to the tail of the list.
+ *
+ * If surface->geometry.parent is set, the total transformation of this
+ * surface will be the parent's total transformation and this transformation
+ * combined:
+ * Mparent * Mn * ... * M2 * M1
*/
struct weston_surface {
/* struct weston_transform */
struct wl_list transformation_list;
+
+ /* managed by weston_surface_set_transform_parent() */
+ struct weston_surface *parent;
+ struct wl_listener parent_destroy_listener;
+ struct wl_list child_list; /* geometry.parent_link */
+ struct wl_list parent_link;
} geometry;
/* State derived from geometry state, read-only.
weston_surface_set_position(struct weston_surface *surface,
float x, float y);
+void
+weston_surface_set_transform_parent(struct weston_surface *surface,
+ struct weston_surface *parent);
+
int
weston_surface_is_mapped(struct weston_surface *surface);
struct {
struct wl_pointer_grab grab;
int32_t x, y;
- struct weston_transform parent_transform;
int32_t initial_up;
struct wl_seat *seat;
uint32_t serial;
struct weston_surface *es = shsurf->surface;
struct weston_surface *parent = shsurf->parent;
- /* Remove the old transform. We don't want to add it twice
- * otherwise Weston will go into an infinite loop when going
- * through the transforms. */
- if (!wl_list_empty(&shsurf->popup.parent_transform.link)) {
- wl_list_remove(&shsurf->popup.parent_transform.link);
- wl_list_init(&shsurf->popup.parent_transform.link);
- }
-
es->output = parent->output;
shsurf->popup.grab.interface = &popup_grab_interface;
- weston_surface_update_transform(parent);
- if (parent->transform.enabled) {
- shsurf->popup.parent_transform.matrix =
- parent->transform.matrix;
- } else {
- /* construct x, y translation matrix */
- weston_matrix_init(&shsurf->popup.parent_transform.matrix);
- shsurf->popup.parent_transform.matrix.type =
- WESTON_MATRIX_TRANSFORM_TRANSLATE;
- shsurf->popup.parent_transform.matrix.d[12] =
- parent->geometry.x;
- shsurf->popup.parent_transform.matrix.d[13] =
- parent->geometry.y;
- }
- wl_list_insert(es->geometry.transformation_list.prev,
- &shsurf->popup.parent_transform.link);
-
shsurf->popup.initial_up = 0;
+ weston_surface_set_transform_parent(es, parent);
weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
weston_surface_update_transform(es);
weston_matrix_init(&shsurf->rotation.rotation);
wl_list_init(&shsurf->workspace_transform.link);
- wl_list_init(&shsurf->popup.parent_transform.link);
shsurf->type = SHELL_SURFACE_NONE;
shsurf->next_type = SHELL_SURFACE_NONE;