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); }
WL_EXPORT int weston_touch_start_drag(struct weston_touch *touch, struct weston_data_source *source, struct weston_surface *icon, struct wl_client *client) { struct weston_touch_drag *drag; drag = zalloc(sizeof *drag); if (drag == NULL) return -1; drag->grab.interface = &touch_drag_grab_interface; drag->base.client = client; drag->base.data_source = source; if (icon) { drag->base.icon = weston_view_create(icon); if (drag->base.icon == NULL) { free(drag); return -1; } drag->base.icon_destroy_listener.notify = handle_drag_icon_destroy; wl_signal_add(&icon->destroy_signal, &drag->base.icon_destroy_listener); icon->configure = touch_drag_surface_configure; icon->configure_private = drag; } else { drag->base.icon = NULL; } if (source) { drag->base.data_source_listener.notify = destroy_touch_data_device_source; wl_signal_add(&source->destroy_signal, &drag->base.data_source_listener); } weston_touch_start_grab(touch, &drag->grab); drag_grab_touch_focus(drag); return 0; }