예제 #1
0
파일: transformed.c 프로젝트: bpeel/weston
static void
key_handler(struct window *window, struct input *input, uint32_t time,
	    uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
	    void *data)
{
	int transform, scale;

	if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
		return;

	transform = window_get_buffer_transform (window);
	scale = window_get_buffer_scale (window);
	switch (sym) {
	case XKB_KEY_Left:
		if (transform == 0)
			transform = 3;
		else if (transform == 4)
			transform = 7;
		else
			transform--;
		break;

	case XKB_KEY_Right:
		if (transform == 3)
			transform = 0;
		else if (transform == 7)
			transform = 4;
		else
			transform++;
		break;

	case XKB_KEY_space:
		if (transform >= 4)
			transform -= 4;
		else
			transform += 4;
		break;

	case XKB_KEY_z:
		if (scale == 1)
			scale = 2;
		else
			scale = 1;
		break;
	}

	printf ("setting buffer transform to %d\n", transform);
	printf ("setting buffer scale to %d\n", scale);
	window_set_buffer_transform(window, transform);
	window_set_buffer_scale(window, scale);
	window_schedule_redraw(window);
}
예제 #2
0
static void
key_handler(struct window *window, struct input *input, uint32_t time,
	    uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
	    void *data)
{
	struct fullscreen *fullscreen = data;
	int transform, scale;
	static int current_size = 0;
	struct fs_output *fsout;
	struct wl_output *wl_output;
	int widths[] = { 640, 320, 800, 400 };
	int heights[] = { 480, 240, 600, 300 };

	if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
		return;

	switch (sym) {
	case XKB_KEY_t:
		transform = window_get_buffer_transform (window);
		transform = (transform + 1) % 8;
		window_set_buffer_transform(window, transform);
		window_schedule_redraw(window);
		break;

	case XKB_KEY_s:
		scale = window_get_buffer_scale (window);
		if (scale == 1)
			scale = 2;
		else
			scale = 1;
		window_set_buffer_scale(window, scale);
		window_schedule_redraw(window);
		break;

	case XKB_KEY_z:
		current_size = (current_size + 1) % 4;
		fullscreen->width = widths[current_size];
		fullscreen->height = heights[current_size];
		window_schedule_resize(fullscreen->window,
				       fullscreen->width, fullscreen->height);
		break;

	case XKB_KEY_m:
		if (!fullscreen->fshell)
			break;

		wl_output = NULL;
		if (fullscreen->current_output)
			wl_output = output_get_wl_output(fullscreen->current_output->output);
		fullscreen->present_method = (fullscreen->present_method + 1) % 5;
		_wl_fullscreen_shell_present_surface(fullscreen->fshell,
						     window_get_wl_surface(fullscreen->window),
						     fullscreen->present_method,
						     wl_output);
		window_schedule_redraw(window);
		break;

	case XKB_KEY_o:
		if (!fullscreen->fshell)
			break;

		fsout = fullscreen->current_output;
		wl_output = fsout ? output_get_wl_output(fsout->output) : NULL;

		/* Clear the current presentation */
		_wl_fullscreen_shell_present_surface(fullscreen->fshell, NULL,
						     0, wl_output);

		if (fullscreen->current_output) {
			if (fullscreen->current_output->link.next == &fullscreen->output_list)
				fsout = NULL;
			else
				fsout = wl_container_of(fullscreen->current_output->link.next,
							fsout, link);
		} else {
			fsout = wl_container_of(fullscreen->output_list.next,
						fsout, link);
		}

		fullscreen->current_output = fsout;
		wl_output = fsout ? output_get_wl_output(fsout->output) : NULL;
		_wl_fullscreen_shell_present_surface(fullscreen->fshell,
						     window_get_wl_surface(fullscreen->window),
						     fullscreen->present_method,
						     wl_output);
		window_schedule_redraw(window);
		break;

	case XKB_KEY_w:
		if (!fullscreen->fshell || !fullscreen->current_output)
			break;

		wl_output = NULL;
		if (fullscreen->current_output)
			wl_output = output_get_wl_output(fullscreen->current_output->output);
		_wl_fullscreen_shell_mode_feedback_destroy(
			_wl_fullscreen_shell_present_surface_for_mode(fullscreen->fshell,
								      window_get_wl_surface(fullscreen->window),
								      wl_output, 0));
		window_schedule_redraw(window);
		break;

	case XKB_KEY_f:
		if (fullscreen->fshell)
			break;
		fullscreen->fullscreen ^= 1;
		window_set_fullscreen(window, fullscreen->fullscreen);
		break;

	case XKB_KEY_q:
		exit (0);
		break;
	}
}
예제 #3
0
static void
redraw_handler(struct widget *widget, void *data)
{
	struct fullscreen *fullscreen = data;
	struct rectangle allocation;
	cairo_surface_t *surface;
	cairo_t *cr;
	int i;
	double x, y, border;
	const char *method_name[] = { "default", "center", "zoom", "zoom_crop", "stretch"};

	surface = window_get_surface(fullscreen->window);
	if (surface == NULL ||
	    cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
		fprintf(stderr, "failed to create cairo egl surface\n");
		return;
	}

	widget_get_allocation(fullscreen->widget, &allocation);

	cr = widget_cairo_create(widget);

	cairo_set_source_rgb(cr, 0, 0, 0);
	cairo_paint (cr);

	cairo_set_source_rgb(cr, 0, 0, 1);
	cairo_set_line_width (cr, 10);
	cairo_rectangle(cr, 5, 5, allocation.width - 10, allocation.height - 10);
	cairo_stroke (cr);

	cairo_move_to(cr,
		      allocation.x + 15,
		      allocation.y + 25);
	cairo_set_source_rgb(cr, 1, 1, 1);

	if (fullscreen->fshell) {
		draw_string(cr,
			    "Surface size: %d, %d\n"
			    "Scale: %d, transform: %d\n"
			    "Pointer: %f,%f\n"
			    "Output: %s, present method: %s\n"
			    "Keys: (s)cale, (t)ransform, si(z)e, (m)ethod,\n"
			    "      (o)utput, modes(w)itch, (q)uit\n",
			    fullscreen->width, fullscreen->height,
			    window_get_buffer_scale (fullscreen->window),
			    window_get_buffer_transform (fullscreen->window),
			    fullscreen->pointer_x, fullscreen->pointer_y,
			    method_name[fullscreen->present_method],
			    fullscreen->current_output ? output_get_model(fullscreen->current_output->output): "null");
	} else {
		draw_string(cr,
			    "Surface size: %d, %d\n"
			    "Scale: %d, transform: %d\n"
			    "Pointer: %f,%f\n"
			    "Fullscreen: %d\n"
			    "Keys: (s)cale, (t)ransform, si(z)e, (f)ullscreen, (q)uit\n",
			    fullscreen->width, fullscreen->height,
			    window_get_buffer_scale (fullscreen->window),
			    window_get_buffer_transform (fullscreen->window),
			    fullscreen->pointer_x, fullscreen->pointer_y,
			    fullscreen->fullscreen);
	}

	y = 100;
	i = 0;
	while (y + 60 < fullscreen->height) {
		border = (i++ % 2 == 0) ? 1 : 0.5;

		x = 50;
		cairo_set_line_width (cr, border);
		while (x + 70 < fullscreen->width) {
			if (window_has_focus(fullscreen->window) &&
			    fullscreen->pointer_x >= x && fullscreen->pointer_x < x + 50 &&
			    fullscreen->pointer_y >= y && fullscreen->pointer_y < y + 40) {
				cairo_set_source_rgb(cr, 1, 0, 0);
				cairo_rectangle(cr,
						x, y,
						50, 40);
				cairo_fill(cr);
			}
			cairo_set_source_rgb(cr, 0, 1, 0);
			cairo_rectangle(cr,
					x + border/2.0, y + border/2.0,
					50, 40);
			cairo_stroke(cr);
			x += 60;
		}

		y += 50;
	}

	if (window_has_focus(fullscreen->window) && fullscreen->draw_cursor) {
		cairo_set_source_rgb(cr, 1, 1, 1);
		cairo_set_line_width (cr, 8);
		cairo_move_to(cr,
			      fullscreen->pointer_x - 12,
			      fullscreen->pointer_y - 12);
		cairo_line_to(cr,
			      fullscreen->pointer_x + 12,
			      fullscreen->pointer_y + 12);
		cairo_stroke(cr);

		cairo_move_to(cr,
			      fullscreen->pointer_x + 12,
			      fullscreen->pointer_y - 12);
		cairo_line_to(cr,
			      fullscreen->pointer_x - 12,
			      fullscreen->pointer_y + 12);
		cairo_stroke(cr);

		cairo_set_source_rgb(cr, 0, 0, 0);
		cairo_set_line_width (cr, 4);
		cairo_move_to(cr,
			      fullscreen->pointer_x - 10,
			      fullscreen->pointer_y - 10);
		cairo_line_to(cr,
			      fullscreen->pointer_x + 10,
			      fullscreen->pointer_y + 10);
		cairo_stroke(cr);

		cairo_move_to(cr,
			      fullscreen->pointer_x + 10,
			      fullscreen->pointer_y - 10);
		cairo_line_to(cr,
			      fullscreen->pointer_x - 10,
			      fullscreen->pointer_y + 10);
		cairo_stroke(cr);
	}

	cairo_destroy(cr);
}