static void surface_transform(void *data) { struct weston_compositor *compositor = data; struct weston_surface *surface; struct weston_view *view; float x, y; surface = weston_surface_create(compositor); assert(surface); view = weston_view_create(surface); assert(view); surface->width = 200; surface->height = 200; weston_view_set_position(view, 100, 100); weston_view_update_transform(view); weston_view_to_global_float(view, 20, 20, &x, &y); fprintf(stderr, "20,20 maps to %f, %f\n", x, y); assert(x == 120 && y == 120); weston_view_set_position(view, 150, 300); weston_view_update_transform(view); weston_view_to_global_float(view, 50, 40, &x, &y); assert(x == 200 && y == 340); wl_display_terminate(compositor->wl_display); }
WL_EXPORT int wet_shell_init(struct weston_compositor *ec, int *argc, char *argv[]) { struct desktest_shell *dts; dts = zalloc(sizeof *dts); if (!dts) return -1; dts->compositor_destroy_listener.notify = shell_destroy; wl_signal_add(&ec->destroy_signal, &dts->compositor_destroy_listener); weston_layer_init(&dts->layer, ec); weston_layer_init(&dts->background_layer, ec); weston_layer_set_position(&dts->layer, WESTON_LAYER_POSITION_NORMAL); weston_layer_set_position(&dts->background_layer, WESTON_LAYER_POSITION_BACKGROUND); dts->background_surface = weston_surface_create(ec); if (dts->background_surface == NULL) goto out_free; dts->background_view = weston_view_create(dts->background_surface); if (dts->background_view == NULL) goto out_surface; weston_surface_set_color(dts->background_surface, 0.16, 0.32, 0.48, 1.); pixman_region32_fini(&dts->background_surface->opaque); pixman_region32_init_rect(&dts->background_surface->opaque, 0, 0, 2000, 2000); pixman_region32_fini(&dts->background_surface->input); pixman_region32_init_rect(&dts->background_surface->input, 0, 0, 2000, 2000); weston_surface_set_size(dts->background_surface, 2000, 2000); weston_view_set_position(dts->background_view, 0, 0); weston_layer_entry_insert(&dts->background_layer.view_list, &dts->background_view->layer_link); weston_view_update_transform(dts->background_view); dts->desktop = weston_desktop_create(ec, &shell_desktop_api, dts); if (dts->desktop == NULL) goto out_view; return 0; out_view: weston_view_destroy(dts->background_view); out_surface: weston_surface_destroy(dts->background_surface); out_free: free(dts); return -1; }
static void surface_to_from_global(void *data) { struct weston_compositor *compositor = data; struct weston_surface *surface; struct weston_view *view; float x, y; wl_fixed_t fx, fy; int32_t ix, iy; surface = weston_surface_create(compositor); assert(surface); view = weston_view_create(surface); assert(view); surface->width = 50; surface->height = 50; weston_view_set_position(view, 5, 10); weston_view_update_transform(view); weston_view_to_global_float(view, 33, 22, &x, &y); assert(x == 38 && y == 32); weston_view_to_global_float(view, -8, -2, &x, &y); assert(x == -3 && y == 8); weston_view_to_global_fixed(view, wl_fixed_from_int(12), wl_fixed_from_int(5), &fx, &fy); assert(fx == wl_fixed_from_int(17) && fy == wl_fixed_from_int(15)); weston_view_from_global_float(view, 38, 32, &x, &y); assert(x == 33 && y == 22); weston_view_from_global_float(view, 42, 5, &x, &y); assert(x == 37 && y == -5); weston_view_from_global_fixed(view, wl_fixed_from_int(21), wl_fixed_from_int(100), &fx, &fy); assert(fx == wl_fixed_from_int(16) && fy == wl_fixed_from_int(90)); weston_view_from_global(view, 0, 0, &ix, &iy); assert(ix == -5 && iy == -10); weston_view_from_global(view, 5, 10, &ix, &iy); assert(ix == 0 && iy == 0); wl_display_terminate(compositor->wl_display); }
static void desktop_surface_committed(struct weston_desktop_surface *desktop_surface, int32_t sx, int32_t sy, void *shell) { struct desktest_shell *dts = shell; struct weston_surface *surface = weston_desktop_surface_get_surface(desktop_surface); struct weston_geometry geometry = weston_desktop_surface_get_geometry(desktop_surface); assert(dts->view); if (weston_surface_is_mapped(surface)) return; surface->is_mapped = true; weston_layer_entry_insert(&dts->layer.view_list, &dts->view->layer_link); weston_view_set_position(dts->view, 0 - geometry.x, 0 - geometry.y); weston_view_update_transform(dts->view); dts->view->is_mapped = true; }
static void drag_surface_configure(struct weston_drag *drag, struct weston_pointer *pointer, struct weston_touch *touch, struct weston_surface *es, int32_t sx, int32_t sy) { struct wl_list *list; float fx, fy; assert((pointer != NULL && touch == NULL) || (pointer == NULL && touch != NULL)); if (!weston_surface_is_mapped(es) && es->buffer_ref.buffer) { if (pointer && pointer->sprite && weston_view_is_mapped(pointer->sprite)) list = &pointer->sprite->layer_link; else list = &es->compositor->cursor_layer.view_list; wl_list_remove(&drag->icon->layer_link); wl_list_insert(list, &drag->icon->layer_link); weston_view_update_transform(drag->icon); empty_region(&es->pending.input); } drag->dx += sx; drag->dy += sy; /* init to 0 for avoiding a compile warning */ fx = fy = 0; if (pointer) { fx = wl_fixed_to_double(pointer->x) + drag->dx; fy = wl_fixed_to_double(pointer->y) + drag->dy; } else if (touch) { fx = wl_fixed_to_double(touch->grab_x) + drag->dx; fy = wl_fixed_to_double(touch->grab_y) + drag->dy; } weston_view_set_position(drag->icon, fx, fy); }