Lines Matching refs:window

73 struct window {  struct
156 struct window *window = data; in xdg_surface_handle_configure() local
160 if (window->wait_for_configure) { in xdg_surface_handle_configure()
161 redraw(window, NULL, 0); in xdg_surface_handle_configure()
162 window->wait_for_configure = false; in xdg_surface_handle_configure()
195 window_init_game(struct window *window) in window_init_game() argument
203 window->ball.radius = 10; in window_init_game()
205 ax1 = window->border + window->ball.radius; in window_init_game()
206 ay1 = window->border + window->ball.radius; in window_init_game()
207 ax2 = window->width - window->border - window->ball.radius; in window_init_game()
208 ay2 = window->height - window->border - window->ball.radius; in window_init_game()
210 window->ball.x = bounded_randf(ax1, ax2); in window_init_game()
211 window->ball.y = bounded_randf(ay1, ay2); in window_init_game()
213 window->ball.dx = bounded_randf(0, window->width); in window_init_game()
214 window->ball.dy = bounded_randf(0, window->height); in window_init_game()
216 window->ball.prev_time = 0; in window_init_game()
220 window_advance_game(struct window *window, uint32_t timestamp) in window_advance_game() argument
225 if (window->ball.prev_time == 0) { in window_advance_game()
227 window->ball.prev_time = timestamp; in window_advance_game()
232 dt = (float)(timestamp - window->ball.prev_time) / 1000.0f; in window_advance_game()
234 ax1 = window->border + window->ball.radius; in window_advance_game()
235 ay1 = window->border + window->ball.radius; in window_advance_game()
236 ax2 = window->width - window->border - window->ball.radius; in window_advance_game()
237 ay2 = window->height - window->border - window->ball.radius; in window_advance_game()
239 window->ball.x += window->ball.dx * dt; in window_advance_game()
240 while (window->ball.x < ax1 || ax2 < window->ball.x) { in window_advance_game()
241 if (window->ball.x < ax1) in window_advance_game()
242 window->ball.x = 2 * ax1 - window->ball.x; in window_advance_game()
243 if (ax2 <= window->ball.x) in window_advance_game()
244 window->ball.x = 2 * ax2 - window->ball.x; in window_advance_game()
246 window->ball.dx *= -1.0f; in window_advance_game()
249 window->ball.y += window->ball.dy * dt; in window_advance_game()
250 while (window->ball.y < ay1 || ay2 < window->ball.y) { in window_advance_game()
251 if (window->ball.y < ay1) in window_advance_game()
252 window->ball.y = 2 * ay1 - window->ball.y; in window_advance_game()
253 if (ay2 <= window->ball.y) in window_advance_game()
254 window->ball.y = 2 * ay2 - window->ball.y; in window_advance_game()
256 window->ball.dy *= -1.0f; in window_advance_game()
259 window->ball.prev_time = timestamp; in window_advance_game()
262 static struct window *
267 struct window *window; in create_window() local
300 window = zalloc(sizeof *window); in create_window()
301 if (!window) in create_window()
304 window->callback = NULL; in create_window()
305 window->display = display; in create_window()
306 window->width = width; in create_window()
307 window->height = height; in create_window()
308 window->border = 10; in create_window()
309 window->flags = flags; in create_window()
310 window->transform = transform; in create_window()
311 window->scale = scale; in create_window()
313 window_init_game(window); in create_window()
315 window->surface = wl_compositor_create_surface(display->compositor); in create_window()
317 if (window->flags & WINDOW_FLAG_USE_VIEWPORT) in create_window()
318 window->viewport = wp_viewporter_get_viewport(display->viewporter, in create_window()
319 window->surface); in create_window()
322 window->xdg_surface = in create_window()
324 window->surface); in create_window()
326 assert(window->xdg_surface); in create_window()
328 xdg_surface_add_listener(window->xdg_surface, in create_window()
329 &xdg_surface_listener, window); in create_window()
331 window->xdg_toplevel = in create_window()
332 xdg_surface_get_toplevel(window->xdg_surface); in create_window()
334 assert(window->xdg_toplevel); in create_window()
336 xdg_toplevel_add_listener(window->xdg_toplevel, in create_window()
337 &xdg_toplevel_listener, window); in create_window()
339 xdg_toplevel_set_title(window->xdg_toplevel, "simple-damage"); in create_window()
341 window->wait_for_configure = true; in create_window()
342 wl_surface_commit(window->surface); in create_window()
345 window->surface, in create_window()
353 if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) { in create_window()
354 wl_surface_damage_buffer(window->surface, 0, 0, in create_window()
357 wl_surface_damage(window->surface, 0, 0, INT32_MAX, INT32_MAX); in create_window()
359 return window; in create_window()
363 destroy_window(struct window *window) in destroy_window() argument
365 if (window->callback) in destroy_window()
366 wl_callback_destroy(window->callback); in destroy_window()
368 if (window->buffers[0].buffer) in destroy_window()
369 wl_buffer_destroy(window->buffers[0].buffer); in destroy_window()
370 if (window->buffers[1].buffer) in destroy_window()
371 wl_buffer_destroy(window->buffers[1].buffer); in destroy_window()
373 if (window->xdg_toplevel) in destroy_window()
374 xdg_toplevel_destroy(window->xdg_toplevel); in destroy_window()
375 if (window->xdg_surface) in destroy_window()
376 xdg_surface_destroy(window->xdg_surface); in destroy_window()
377 if (window->viewport) in destroy_window()
378 wp_viewport_destroy(window->viewport); in destroy_window()
379 wl_surface_destroy(window->surface); in destroy_window()
380 free(window); in destroy_window()
384 window_next_buffer(struct window *window) in window_next_buffer() argument
389 if (!window->buffers[0].busy) in window_next_buffer()
390 buffer = &window->buffers[0]; in window_next_buffer()
391 else if (!window->buffers[1].busy) in window_next_buffer()
392 buffer = &window->buffers[1]; in window_next_buffer()
396 switch (window->transform) { in window_next_buffer()
402 bwidth = window->width * window->scale; in window_next_buffer()
403 bheight = window->height * window->scale; in window_next_buffer()
409 bwidth = window->height * window->scale; in window_next_buffer()
410 bheight = window->width * window->scale; in window_next_buffer()
415 ret = create_shm_buffer(window->display, buffer, in window_next_buffer()
450 window_get_transformed_ball(struct window *window, float *bx, float *by) in window_get_transformed_ball() argument
454 wx = window->ball.x; in window_get_transformed_ball()
455 wy = window->ball.y; in window_get_transformed_ball()
457 switch (window->transform) { in window_get_transformed_ball()
464 *bx = window->height - wy; in window_get_transformed_ball()
468 *bx = window->width - wx; in window_get_transformed_ball()
469 *by = window->height - wy; in window_get_transformed_ball()
473 *by = window->width - wx; in window_get_transformed_ball()
476 *bx = window->width - wx; in window_get_transformed_ball()
480 *bx = window->height - wy; in window_get_transformed_ball()
481 *by = window->width - wx; in window_get_transformed_ball()
485 *by = window->height - wy; in window_get_transformed_ball()
493 *bx *= window->scale; in window_get_transformed_ball()
494 *by *= window->scale; in window_get_transformed_ball()
496 if (window->viewport) { in window_get_transformed_ball()
508 struct window *window = data; in redraw() local
514 buffer = window_next_buffer(window); in redraw()
524 if (window->flags & WINDOW_FLAG_ROTATING_TRANSFORM) in redraw()
525 window->transform = (window->transform + 2) % 8; in redraw()
527 switch (window->transform) { in redraw()
533 bwidth = window->width * window->scale; in redraw()
534 bheight = window->height * window->scale; in redraw()
540 bwidth = window->height * window->scale; in redraw()
541 bheight = window->width * window->scale; in redraw()
547 bborder = window->border * window->scale; in redraw()
548 bradius = window->ball.radius * window->scale; in redraw()
550 if (window->viewport) { in redraw()
564 tx = (window->width / 3) * window->scale; in redraw()
565 ty = (window->height / 5) * window->scale; in redraw()
566 switch (window->transform) { in redraw()
601 wp_viewport_set_source(window->viewport, in redraw()
602 wl_fixed_from_int(window->width / 3), in redraw()
603 wl_fixed_from_int(window->height / 5), in redraw()
604 wl_fixed_from_int(window->width / 2), in redraw()
605 wl_fixed_from_int(window->height / 2)); in redraw()
623 if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) { in redraw()
624 window_get_transformed_ball(window, &bx, &by); in redraw()
625 wl_surface_damage_buffer(window->surface, in redraw()
631 wl_surface_damage(window->surface, in redraw()
632 window->ball.x - window->ball.radius, in redraw()
633 window->ball.y - window->ball.radius, in redraw()
634 window->ball.radius * 2 + 1, in redraw()
635 window->ball.radius * 2 + 1); in redraw()
637 window_advance_game(window, time); in redraw()
639 window_get_transformed_ball(window, &bx, &by); in redraw()
647 window->ball.x, window->ball.y); in redraw()
659 if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) { in redraw()
660 wl_surface_damage_buffer(window->surface, in redraw()
666 wl_surface_damage(window->surface, in redraw()
667 window->ball.x - window->ball.radius, in redraw()
668 window->ball.y - window->ball.radius, in redraw()
669 window->ball.radius * 2 + 1, in redraw()
670 window->ball.radius * 2 + 1); in redraw()
672 wl_surface_attach(window->surface, buffer->buffer, 0, 0); in redraw()
674 if (window->display->compositor_version >= 2 && in redraw()
675 (window->transform != WL_OUTPUT_TRANSFORM_NORMAL || in redraw()
676 window->flags & WINDOW_FLAG_ROTATING_TRANSFORM)) in redraw()
677 wl_surface_set_buffer_transform(window->surface, in redraw()
678 window->transform); in redraw()
680 if (window->viewport) in redraw()
681 wp_viewport_set_destination(window->viewport, in redraw()
682 window->width, in redraw()
683 window->height); in redraw()
685 if (window->scale != 1) in redraw()
686 wl_surface_set_buffer_scale(window->surface, in redraw()
687 window->scale); in redraw()
692 window->callback = wl_surface_frame(window->surface); in redraw()
693 wl_callback_add_listener(window->callback, &frame_listener, window); in redraw()
694 wl_surface_commit(window->surface); in redraw()
890 struct window *window; in main() local
937 window = create_window(display, width, height, transform, scale, flags); in main()
938 if (!window) in main()
946 if (!window->wait_for_configure) in main()
947 redraw(window, NULL, 0); in main()
953 destroy_window(window); in main()