mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Add a toy-display object that caches state.
This will be GdkDisplay for GTK+ on Wayland etc. This restores the terminal fullscreen mode.
This commit is contained in:
		
							parent
							
								
									8e438625ae
								
							
						
					
					
						commit
						43c28eee32
					
				
					 5 changed files with 111 additions and 75 deletions
				
			
		
							
								
								
									
										15
									
								
								gears.c
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								gears.c
									
										
									
									
									
								
							| 
						 | 
					@ -46,7 +46,7 @@ static const char socket_name[] = "\0wayland";
 | 
				
			||||||
struct gears {
 | 
					struct gears {
 | 
				
			||||||
	struct window *window;
 | 
						struct window *window;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wl_display *wl_display;
 | 
						struct display *d;
 | 
				
			||||||
	struct wl_compositor *compositor;
 | 
						struct wl_compositor *compositor;
 | 
				
			||||||
	struct rectangle rectangle;
 | 
						struct rectangle rectangle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -337,7 +337,7 @@ static const struct wl_compositor_listener compositor_listener = {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct gears *
 | 
					static struct gears *
 | 
				
			||||||
gears_create(struct wl_display *display, int fd)
 | 
					gears_create(struct display *display)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const int x = 200, y = 200, width = 450, height = 500;
 | 
						const int x = 200, y = 200, width = 450, height = 500;
 | 
				
			||||||
	EGLint major, minor, count;
 | 
						EGLint major, minor, count;
 | 
				
			||||||
| 
						 | 
					@ -352,8 +352,8 @@ gears_create(struct wl_display *display, int fd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gears = malloc(sizeof *gears);
 | 
						gears = malloc(sizeof *gears);
 | 
				
			||||||
	memset(gears, 0, sizeof *gears);
 | 
						memset(gears, 0, sizeof *gears);
 | 
				
			||||||
	gears->wl_display = display;
 | 
						gears->d = display;
 | 
				
			||||||
	gears->window = window_create(display, fd, "Wayland Gears",
 | 
						gears->window = window_create(display, "Wayland Gears",
 | 
				
			||||||
				      x, y, width, height);
 | 
									      x, y, width, height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gears->display = eglCreateDisplayNative(device);
 | 
						gears->display = eglCreateDisplayNative(device);
 | 
				
			||||||
| 
						 | 
					@ -394,7 +394,7 @@ gears_create(struct wl_display *display, int fd)
 | 
				
			||||||
	glEnable(GL_DEPTH_TEST);
 | 
						glEnable(GL_DEPTH_TEST);
 | 
				
			||||||
	glClearColor(0, 0, 0, 0.92);
 | 
						glClearColor(0, 0, 0, 0.92);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gears->compositor = wl_display_get_compositor(display);
 | 
						gears->compositor = display_get_compositor(display);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	draw_gears(gears);
 | 
						draw_gears(gears);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -411,6 +411,7 @@ gears_create(struct wl_display *display, int fd)
 | 
				
			||||||
int main(int argc, char *argv[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct wl_display *display;
 | 
						struct wl_display *display;
 | 
				
			||||||
 | 
						struct display *d;
 | 
				
			||||||
	int fd;
 | 
						int fd;
 | 
				
			||||||
	GMainLoop *loop;
 | 
						GMainLoop *loop;
 | 
				
			||||||
	GSource *source;
 | 
						GSource *source;
 | 
				
			||||||
| 
						 | 
					@ -428,11 +429,13 @@ int main(int argc, char *argv[])
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						d = display_create(display, fd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	loop = g_main_loop_new(NULL, FALSE);
 | 
						loop = g_main_loop_new(NULL, FALSE);
 | 
				
			||||||
	source = wl_glib_source_new(display);
 | 
						source = wl_glib_source_new(display);
 | 
				
			||||||
	g_source_attach(source, NULL);
 | 
						g_source_attach(source, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gears = gears_create(display, fd);
 | 
						gears = gears_create(d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	g_main_loop_run(loop);
 | 
						g_main_loop_run(loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								terminal.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								terminal.c
									
										
									
									
									
								
							| 
						 | 
					@ -53,7 +53,7 @@ static const char socket_name[] = "\0wayland";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct terminal {
 | 
					struct terminal {
 | 
				
			||||||
	struct window *window;
 | 
						struct window *window;
 | 
				
			||||||
	struct wl_display *display;
 | 
						struct display *display;
 | 
				
			||||||
	struct wl_compositor *compositor;
 | 
						struct wl_compositor *compositor;
 | 
				
			||||||
	int redraw_scheduled, redraw_pending;
 | 
						int redraw_scheduled, redraw_pending;
 | 
				
			||||||
	char *data;
 | 
						char *data;
 | 
				
			||||||
| 
						 | 
					@ -540,7 +540,7 @@ key_handler(struct window *window, uint32_t key, uint32_t state, void *data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct terminal *
 | 
					static struct terminal *
 | 
				
			||||||
terminal_create(struct wl_display *display, int fd, int fullscreen)
 | 
					terminal_create(struct display *display, int fullscreen)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct terminal *terminal;
 | 
						struct terminal *terminal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -550,13 +550,13 @@ terminal_create(struct wl_display *display, int fd, int fullscreen)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(terminal, 0, sizeof *terminal);
 | 
						memset(terminal, 0, sizeof *terminal);
 | 
				
			||||||
	terminal->fullscreen = fullscreen;
 | 
						terminal->fullscreen = fullscreen;
 | 
				
			||||||
	terminal->window = window_create(display, fd, "Wayland Terminal",
 | 
						terminal->window = window_create(display, "Wayland Terminal",
 | 
				
			||||||
					 500, 100, 500, 400);
 | 
										 500, 100, 500, 400);
 | 
				
			||||||
	terminal->display = display;
 | 
						terminal->display = display;
 | 
				
			||||||
	terminal->redraw_scheduled = 1;
 | 
						terminal->redraw_scheduled = 1;
 | 
				
			||||||
	terminal->margin = 5;
 | 
						terminal->margin = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	terminal->compositor = wl_display_get_compositor(display);
 | 
						terminal->compositor = display_get_compositor(display);
 | 
				
			||||||
	window_set_fullscreen(terminal->window, terminal->fullscreen);
 | 
						window_set_fullscreen(terminal->window, terminal->fullscreen);
 | 
				
			||||||
	window_set_resize_handler(terminal->window, resize_handler, terminal);
 | 
						window_set_resize_handler(terminal->window, resize_handler, terminal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -628,6 +628,7 @@ int main(int argc, char *argv[])
 | 
				
			||||||
	int fd;
 | 
						int fd;
 | 
				
			||||||
	GMainLoop *loop;
 | 
						GMainLoop *loop;
 | 
				
			||||||
	GSource *source;
 | 
						GSource *source;
 | 
				
			||||||
 | 
						struct display *d;
 | 
				
			||||||
	struct terminal *terminal;
 | 
						struct terminal *terminal;
 | 
				
			||||||
	GOptionContext *context;
 | 
						GOptionContext *context;
 | 
				
			||||||
	GError *error;
 | 
						GError *error;
 | 
				
			||||||
| 
						 | 
					@ -651,11 +652,12 @@ int main(int argc, char *argv[])
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						d = display_create(display, fd);
 | 
				
			||||||
	loop = g_main_loop_new(NULL, FALSE);
 | 
						loop = g_main_loop_new(NULL, FALSE);
 | 
				
			||||||
	source = wl_glib_source_new(display);
 | 
						source = wl_glib_source_new(display);
 | 
				
			||||||
	g_source_attach(source, NULL);
 | 
						g_source_attach(source, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	terminal = terminal_create(display, fd, option_fullscreen);
 | 
						terminal = terminal_create(d, option_fullscreen);
 | 
				
			||||||
	if (terminal_run(terminal, "/bin/bash"))
 | 
						if (terminal_run(terminal, "/bin/bash"))
 | 
				
			||||||
		exit(EXIT_FAILURE);
 | 
							exit(EXIT_FAILURE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -409,9 +409,6 @@ wl_display_create(const char *name, size_t name_size)
 | 
				
			||||||
						   connection_update,
 | 
											   connection_update,
 | 
				
			||||||
						   display);
 | 
											   display);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Process connection events. */
 | 
					 | 
				
			||||||
	wl_display_iterate(display, WL_CONNECTION_READABLE);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return display;
 | 
						return display;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										146
									
								
								window.c
									
										
									
									
									
								
							
							
						
						
									
										146
									
								
								window.c
									
										
									
									
									
								
							| 
						 | 
					@ -38,12 +38,21 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "window.h"
 | 
					#include "window.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct window {
 | 
					struct display {
 | 
				
			||||||
	struct wl_display *display;
 | 
						struct wl_display *display;
 | 
				
			||||||
	struct wl_compositor *compositor;
 | 
						struct wl_compositor *compositor;
 | 
				
			||||||
 | 
						struct wl_output *output;
 | 
				
			||||||
 | 
						struct wl_input_device *input_device;
 | 
				
			||||||
 | 
						struct rectangle screen_allocation;
 | 
				
			||||||
 | 
						cairo_drm_context_t *ctx;
 | 
				
			||||||
 | 
						int fd;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct window {
 | 
				
			||||||
 | 
						struct display *display;
 | 
				
			||||||
	struct wl_surface *surface;
 | 
						struct wl_surface *surface;
 | 
				
			||||||
	const char *title;
 | 
						const char *title;
 | 
				
			||||||
	struct rectangle allocation, saved_allocation, screen_allocation;
 | 
						struct rectangle allocation, saved_allocation;
 | 
				
			||||||
	int minimum_width, minimum_height;
 | 
						int minimum_width, minimum_height;
 | 
				
			||||||
	int margin;
 | 
						int margin;
 | 
				
			||||||
	int drag_x, drag_y;
 | 
						int drag_x, drag_y;
 | 
				
			||||||
| 
						 | 
					@ -51,7 +60,6 @@ struct window {
 | 
				
			||||||
	int fullscreen;
 | 
						int fullscreen;
 | 
				
			||||||
	struct wl_input_device *grab_device;
 | 
						struct wl_input_device *grab_device;
 | 
				
			||||||
	uint32_t name;
 | 
						uint32_t name;
 | 
				
			||||||
	cairo_drm_context_t *ctx;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cairo_surface_t *cairo_surface;
 | 
						cairo_surface_t *cairo_surface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,7 +93,7 @@ window_draw_decorations(struct window *window)
 | 
				
			||||||
	int width, height;
 | 
						int width, height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	window->cairo_surface =
 | 
						window->cairo_surface =
 | 
				
			||||||
		cairo_drm_surface_create(window->ctx,
 | 
							cairo_drm_surface_create(window->display->ctx,
 | 
				
			||||||
					 CAIRO_CONTENT_COLOR_ALPHA,
 | 
										 CAIRO_CONTENT_COLOR_ALPHA,
 | 
				
			||||||
					 window->allocation.width,
 | 
										 window->allocation.width,
 | 
				
			||||||
					 window->allocation.height);
 | 
										 window->allocation.height);
 | 
				
			||||||
| 
						 | 
					@ -170,7 +178,7 @@ window_draw_decorations(struct window *window)
 | 
				
			||||||
	cairo_fill(cr);
 | 
						cairo_fill(cr);
 | 
				
			||||||
	cairo_destroy(cr);
 | 
						cairo_destroy(cr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	visual = wl_display_get_premultiplied_argb_visual(window->display);
 | 
						visual = wl_display_get_premultiplied_argb_visual(window->display->display);
 | 
				
			||||||
	wl_surface_attach(window->surface,
 | 
						wl_surface_attach(window->surface,
 | 
				
			||||||
			  cairo_drm_surface_get_name(window->cairo_surface),
 | 
								  cairo_drm_surface_get_name(window->cairo_surface),
 | 
				
			||||||
			  window->allocation.width,
 | 
								  window->allocation.width,
 | 
				
			||||||
| 
						 | 
					@ -191,12 +199,12 @@ window_draw_fullscreen(struct window *window)
 | 
				
			||||||
	struct wl_visual *visual;
 | 
						struct wl_visual *visual;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	window->cairo_surface =
 | 
						window->cairo_surface =
 | 
				
			||||||
		cairo_drm_surface_create(window->ctx,
 | 
							cairo_drm_surface_create(window->display->ctx,
 | 
				
			||||||
					 CAIRO_CONTENT_COLOR_ALPHA,
 | 
										 CAIRO_CONTENT_COLOR_ALPHA,
 | 
				
			||||||
					 window->allocation.width,
 | 
										 window->allocation.width,
 | 
				
			||||||
					 window->allocation.height);
 | 
										 window->allocation.height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	visual = wl_display_get_premultiplied_argb_visual(window->display);
 | 
						visual = wl_display_get_premultiplied_argb_visual(window->display->display);
 | 
				
			||||||
	wl_surface_attach(window->surface,
 | 
						wl_surface_attach(window->surface,
 | 
				
			||||||
			  cairo_drm_surface_get_name(window->cairo_surface),
 | 
								  cairo_drm_surface_get_name(window->cairo_surface),
 | 
				
			||||||
			  window->allocation.width,
 | 
								  window->allocation.width,
 | 
				
			||||||
| 
						 | 
					@ -287,7 +295,7 @@ window_handle_motion(void *data, struct wl_input_device *input_device,
 | 
				
			||||||
			       window->allocation.y - window->margin,
 | 
								       window->allocation.y - window->margin,
 | 
				
			||||||
			       window->allocation.width,
 | 
								       window->allocation.width,
 | 
				
			||||||
			       window->allocation.height);
 | 
								       window->allocation.height);
 | 
				
			||||||
		wl_compositor_commit(window->compositor, 1);
 | 
							wl_compositor_commit(window->display->compositor, 1);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case WINDOW_RESIZING_LOWER_RIGHT:
 | 
						case WINDOW_RESIZING_LOWER_RIGHT:
 | 
				
			||||||
		if (window->fullscreen)
 | 
							if (window->fullscreen)
 | 
				
			||||||
| 
						 | 
					@ -396,7 +404,7 @@ cairo_surface_t *
 | 
				
			||||||
window_create_surface(struct window *window,
 | 
					window_create_surface(struct window *window,
 | 
				
			||||||
		      struct rectangle *rectangle)
 | 
							      struct rectangle *rectangle)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return cairo_drm_surface_create(window->ctx,
 | 
						return cairo_drm_surface_create(window->display->ctx,
 | 
				
			||||||
					CAIRO_CONTENT_COLOR_ALPHA,
 | 
										CAIRO_CONTENT_COLOR_ALPHA,
 | 
				
			||||||
					rectangle->width,
 | 
										rectangle->width,
 | 
				
			||||||
					rectangle->height);
 | 
										rectangle->height);
 | 
				
			||||||
| 
						 | 
					@ -437,7 +445,7 @@ window_set_fullscreen(struct window *window, int fullscreen)
 | 
				
			||||||
	window->fullscreen = fullscreen;
 | 
						window->fullscreen = fullscreen;
 | 
				
			||||||
	if (window->fullscreen) {
 | 
						if (window->fullscreen) {
 | 
				
			||||||
		window->saved_allocation = window->allocation;
 | 
							window->saved_allocation = window->allocation;
 | 
				
			||||||
		window->allocation = window->screen_allocation;
 | 
							window->allocation = window->display->screen_allocation;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		window->allocation = window->saved_allocation;
 | 
							window->allocation = window->saved_allocation;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -459,50 +467,8 @@ window_set_key_handler(struct window *window,
 | 
				
			||||||
	window->user_data = data;
 | 
						window->user_data = data;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					 | 
				
			||||||
window_handle_geometry(void *data,
 | 
					 | 
				
			||||||
		       struct wl_output *output,
 | 
					 | 
				
			||||||
		       int32_t width, int32_t height)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct window *window = data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	window->screen_allocation.x = 0;
 | 
					 | 
				
			||||||
	window->screen_allocation.y = 0;
 | 
					 | 
				
			||||||
	window->screen_allocation.width = width;
 | 
					 | 
				
			||||||
	window->screen_allocation.height = height;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct wl_output_listener output_listener = {
 | 
					 | 
				
			||||||
	window_handle_geometry,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					 | 
				
			||||||
window_handle_global(struct wl_display *display,
 | 
					 | 
				
			||||||
		     struct wl_object *object, void *data)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct window *window = data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (wl_object_implements(object, "compositor", 1)) { 
 | 
					 | 
				
			||||||
		window->compositor = (struct wl_compositor *) object;
 | 
					 | 
				
			||||||
		wl_compositor_add_listener(window->compositor,
 | 
					 | 
				
			||||||
					   &compositor_listener, window);
 | 
					 | 
				
			||||||
	} else if (wl_object_implements(object, "output", 1)) {
 | 
					 | 
				
			||||||
		struct wl_output *output = (struct wl_output *) object;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		wl_output_add_listener(output,
 | 
					 | 
				
			||||||
				       &output_listener, window);
 | 
					 | 
				
			||||||
	} else if (wl_object_implements(object, "input_device", 1)) {
 | 
					 | 
				
			||||||
		struct wl_input_device *input_device =
 | 
					 | 
				
			||||||
			(struct wl_input_device *) object;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		wl_input_device_add_listener(input_device,
 | 
					 | 
				
			||||||
					     &input_device_listener, window);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct window *
 | 
					struct window *
 | 
				
			||||||
window_create(struct wl_display *display, int fd,
 | 
					window_create(struct display *display, const char *title,
 | 
				
			||||||
	      const char *title,
 | 
					 | 
				
			||||||
	      int32_t x, int32_t y, int32_t width, int32_t height)
 | 
						      int32_t x, int32_t y, int32_t width, int32_t height)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct window *window;
 | 
						struct window *window;
 | 
				
			||||||
| 
						 | 
					@ -514,8 +480,7 @@ window_create(struct wl_display *display, int fd,
 | 
				
			||||||
	memset(window, 0, sizeof *window);
 | 
						memset(window, 0, sizeof *window);
 | 
				
			||||||
	window->display = display;
 | 
						window->display = display;
 | 
				
			||||||
	window->title = strdup(title);
 | 
						window->title = strdup(title);
 | 
				
			||||||
	window->compositor = wl_display_get_compositor(display);
 | 
						window->surface = wl_compositor_create_surface(display->compositor);
 | 
				
			||||||
	window->surface = wl_compositor_create_surface(window->compositor);
 | 
					 | 
				
			||||||
	window->allocation.x = x;
 | 
						window->allocation.x = x;
 | 
				
			||||||
	window->allocation.y = y;
 | 
						window->allocation.y = y;
 | 
				
			||||||
	window->allocation.width = width;
 | 
						window->allocation.width = width;
 | 
				
			||||||
| 
						 | 
					@ -523,14 +488,77 @@ window_create(struct wl_display *display, int fd,
 | 
				
			||||||
	window->saved_allocation = window->allocation;
 | 
						window->saved_allocation = window->allocation;
 | 
				
			||||||
	window->margin = 16;
 | 
						window->margin = 16;
 | 
				
			||||||
	window->state = WINDOW_STABLE;
 | 
						window->state = WINDOW_STABLE;
 | 
				
			||||||
	window->ctx = cairo_drm_context_get_for_fd(fd);
 | 
					
 | 
				
			||||||
	if (window->ctx == NULL) {
 | 
						wl_compositor_add_listener(display->compositor,
 | 
				
			||||||
 | 
									   &compositor_listener, window);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wl_input_device_add_listener(display->input_device,
 | 
				
			||||||
 | 
									     &input_device_listener, window);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return window;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					display_handle_geometry(void *data,
 | 
				
			||||||
 | 
								struct wl_output *output,
 | 
				
			||||||
 | 
								int32_t width, int32_t height)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct display *display = data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						display->screen_allocation.x = 0;
 | 
				
			||||||
 | 
						display->screen_allocation.y = 0;
 | 
				
			||||||
 | 
						display->screen_allocation.width = width;
 | 
				
			||||||
 | 
						display->screen_allocation.height = height;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct wl_output_listener output_listener = {
 | 
				
			||||||
 | 
						display_handle_geometry,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					display_handle_global(struct wl_display *display,
 | 
				
			||||||
 | 
							     struct wl_object *object, void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct display *d = data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (wl_object_implements(object, "compositor", 1)) { 
 | 
				
			||||||
 | 
							d->compositor = (struct wl_compositor *) object;
 | 
				
			||||||
 | 
						} else if (wl_object_implements(object, "output", 1)) {
 | 
				
			||||||
 | 
							d->output = (struct wl_output *) object;
 | 
				
			||||||
 | 
							wl_output_add_listener(d->output, &output_listener, d);
 | 
				
			||||||
 | 
						} else if (wl_object_implements(object, "input_device", 1)) {
 | 
				
			||||||
 | 
							d->input_device =(struct wl_input_device *) object;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct display *
 | 
				
			||||||
 | 
					display_create(struct wl_display *display, int fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct display *d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						d = malloc(sizeof *d);
 | 
				
			||||||
 | 
						if (d == NULL)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						d->display = display;
 | 
				
			||||||
 | 
						d->ctx = cairo_drm_context_get_for_fd(fd);
 | 
				
			||||||
 | 
						if (d->ctx == NULL) {
 | 
				
			||||||
		fprintf(stderr, "failed to get cairo drm context\n");
 | 
							fprintf(stderr, "failed to get cairo drm context\n");
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Set up listener so we'll catch all events. */
 | 
				
			||||||
	wl_display_add_global_listener(display,
 | 
						wl_display_add_global_listener(display,
 | 
				
			||||||
				       window_handle_global, window);
 | 
									       display_handle_global, d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return window;
 | 
						/* Process connection events. */
 | 
				
			||||||
 | 
						wl_display_iterate(display, WL_DISPLAY_READABLE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return d;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct wl_compositor *
 | 
				
			||||||
 | 
					display_get_compositor(struct display *display)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return display->compositor;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								window.h
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								window.h
									
										
									
									
									
								
							| 
						 | 
					@ -32,6 +32,13 @@ struct rectangle {
 | 
				
			||||||
	int32_t height;
 | 
						int32_t height;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct display;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct display *
 | 
				
			||||||
 | 
					display_create(struct wl_display *display, int fd);
 | 
				
			||||||
 | 
					struct wl_compositor *
 | 
				
			||||||
 | 
					display_get_compositor(struct display *display);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef void (*window_resize_handler_t)(struct window *window, void *data);
 | 
					typedef void (*window_resize_handler_t)(struct window *window, void *data);
 | 
				
			||||||
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
 | 
					typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
 | 
				
			||||||
typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, void *data);
 | 
					typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, void *data);
 | 
				
			||||||
| 
						 | 
					@ -39,8 +46,7 @@ typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct window *
 | 
					struct window *
 | 
				
			||||||
window_create(struct wl_display *display, int fd,
 | 
					window_create(struct display *display, const char *title,
 | 
				
			||||||
	      const char *title,
 | 
					 | 
				
			||||||
	      int32_t x, int32_t y, int32_t width, int32_t height);
 | 
						      int32_t x, int32_t y, int32_t width, int32_t height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue