Exemplo n.º 1
0
static struct resizor *
resizor_create(struct display *display)
{
	struct resizor *resizor;
	int32_t height;

	resizor = malloc(sizeof *resizor);
	if (resizor == NULL)
		return resizor;
	memset(resizor, 0, sizeof *resizor);

	resizor->window = window_create(display, "Wayland Resizor", 500, 400);
	resizor->display = display;

	window_set_key_handler(resizor->window, key_handler);
	window_set_user_data(resizor->window, resizor);
	window_set_redraw_handler(resizor->window, redraw_handler);
	window_set_keyboard_focus_handler(resizor->window,
					  keyboard_focus_handler);

	resizor->width = 300;
	resizor->height.current = 400;
	resizor->height.previous = resizor->height.current;
	resizor->height.target = resizor->height.current;
	height = resizor->height.current + 0.5;

	window_set_child_size(resizor->window, resizor->width, height);

	resizor_draw(resizor);

	return resizor;
}
Exemplo n.º 2
0
static void
frame_callback(void *data, uint32_t time)
{
	struct resizor *resizor = data;
	double force, height;

	height = resizor->height.current;
	force = (resizor->height.target - height) / 10.0 +
		(resizor->height.previous - height);

	resizor->height.current =
		height + (height - resizor->height.previous) + force;
	resizor->height.previous = height;

	if (resizor->height.current >= 400) {
		resizor->height.current = 400;
		resizor->height.previous = 400;
	}

	if (resizor->height.current <= 200) {
		resizor->height.current = 200;
		resizor->height.previous = 200;
	}

	window_set_child_size(resizor->window, resizor->width, height + 0.5);

	window_schedule_redraw(resizor->window);
}
Exemplo n.º 3
0
static void
resize_handler(struct window *window,
	       int32_t width, int32_t height, void *data)
{
	struct gears *gears = data;

	/* Constrain child size to be square and at least 300x300 */
	if (width > height)
		height = width;
	else
		width = height;
	if (width < 300) {
		width = 300;
		height = 300;
	}

	window_set_child_size(gears->window, width, height);
}