From: Kristian Høgsberg Date: Tue, 27 Jan 2009 04:42:46 +0000 (-0500) Subject: Add a toy-display object that caches state. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=43c28eee32ae9383d3056e45a8f824710ce4615d;p=platform%2Fupstream%2Fweston.git Add a toy-display object that caches state. This will be GdkDisplay for GTK+ on Wayland etc. This restores the terminal fullscreen mode. --- diff --git a/gears.c b/gears.c index 63085bb..85a73f1 100644 --- a/gears.c +++ b/gears.c @@ -46,7 +46,7 @@ static const char socket_name[] = "\0wayland"; struct gears { struct window *window; - struct wl_display *wl_display; + struct display *d; struct wl_compositor *compositor; struct rectangle rectangle; @@ -337,7 +337,7 @@ static const struct wl_compositor_listener compositor_listener = { }; 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; EGLint major, minor, count; @@ -352,8 +352,8 @@ gears_create(struct wl_display *display, int fd) gears = malloc(sizeof *gears); memset(gears, 0, sizeof *gears); - gears->wl_display = display; - gears->window = window_create(display, fd, "Wayland Gears", + gears->d = display; + gears->window = window_create(display, "Wayland Gears", x, y, width, height); gears->display = eglCreateDisplayNative(device); @@ -394,7 +394,7 @@ gears_create(struct wl_display *display, int fd) glEnable(GL_DEPTH_TEST); glClearColor(0, 0, 0, 0.92); - gears->compositor = wl_display_get_compositor(display); + gears->compositor = display_get_compositor(display); draw_gears(gears); @@ -411,6 +411,7 @@ gears_create(struct wl_display *display, int fd) int main(int argc, char *argv[]) { struct wl_display *display; + struct display *d; int fd; GMainLoop *loop; GSource *source; @@ -428,11 +429,13 @@ int main(int argc, char *argv[]) return -1; } + d = display_create(display, fd); + loop = g_main_loop_new(NULL, FALSE); source = wl_glib_source_new(display); g_source_attach(source, NULL); - gears = gears_create(display, fd); + gears = gears_create(d); g_main_loop_run(loop); diff --git a/terminal.c b/terminal.c index 02a4f79..d380bd8 100644 --- a/terminal.c +++ b/terminal.c @@ -53,7 +53,7 @@ static const char socket_name[] = "\0wayland"; struct terminal { struct window *window; - struct wl_display *display; + struct display *display; struct wl_compositor *compositor; int redraw_scheduled, redraw_pending; char *data; @@ -540,7 +540,7 @@ key_handler(struct window *window, uint32_t key, uint32_t state, void *data) } static struct terminal * -terminal_create(struct wl_display *display, int fd, int fullscreen) +terminal_create(struct display *display, int fullscreen) { struct terminal *terminal; @@ -550,13 +550,13 @@ terminal_create(struct wl_display *display, int fd, int fullscreen) memset(terminal, 0, sizeof *terminal); terminal->fullscreen = fullscreen; - terminal->window = window_create(display, fd, "Wayland Terminal", + terminal->window = window_create(display, "Wayland Terminal", 500, 100, 500, 400); terminal->display = display; terminal->redraw_scheduled = 1; 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_resize_handler(terminal->window, resize_handler, terminal); @@ -628,6 +628,7 @@ int main(int argc, char *argv[]) int fd; GMainLoop *loop; GSource *source; + struct display *d; struct terminal *terminal; GOptionContext *context; GError *error; @@ -651,11 +652,12 @@ int main(int argc, char *argv[]) return -1; } + d = display_create(display, fd); loop = g_main_loop_new(NULL, FALSE); source = wl_glib_source_new(display); g_source_attach(source, NULL); - terminal = terminal_create(display, fd, option_fullscreen); + terminal = terminal_create(d, option_fullscreen); if (terminal_run(terminal, "/bin/bash")) exit(EXIT_FAILURE); diff --git a/wayland-client.c b/wayland-client.c index 5412dcf..5e8f036 100644 --- a/wayland-client.c +++ b/wayland-client.c @@ -409,9 +409,6 @@ wl_display_create(const char *name, size_t name_size) connection_update, display); - /* Process connection events. */ - wl_display_iterate(display, WL_CONNECTION_READABLE); - return display; } diff --git a/window.c b/window.c index 1c318e8..8ec858c 100644 --- a/window.c +++ b/window.c @@ -38,12 +38,21 @@ #include "window.h" -struct window { +struct display { struct wl_display *display; 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; const char *title; - struct rectangle allocation, saved_allocation, screen_allocation; + struct rectangle allocation, saved_allocation; int minimum_width, minimum_height; int margin; int drag_x, drag_y; @@ -51,7 +60,6 @@ struct window { int fullscreen; struct wl_input_device *grab_device; uint32_t name; - cairo_drm_context_t *ctx; cairo_surface_t *cairo_surface; @@ -85,7 +93,7 @@ window_draw_decorations(struct window *window) int width, height; window->cairo_surface = - cairo_drm_surface_create(window->ctx, + cairo_drm_surface_create(window->display->ctx, CAIRO_CONTENT_COLOR_ALPHA, window->allocation.width, window->allocation.height); @@ -170,7 +178,7 @@ window_draw_decorations(struct window *window) cairo_fill(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, cairo_drm_surface_get_name(window->cairo_surface), window->allocation.width, @@ -191,12 +199,12 @@ window_draw_fullscreen(struct window *window) struct wl_visual *visual; window->cairo_surface = - cairo_drm_surface_create(window->ctx, + cairo_drm_surface_create(window->display->ctx, CAIRO_CONTENT_COLOR_ALPHA, window->allocation.width, 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, cairo_drm_surface_get_name(window->cairo_surface), 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.width, window->allocation.height); - wl_compositor_commit(window->compositor, 1); + wl_compositor_commit(window->display->compositor, 1); break; case WINDOW_RESIZING_LOWER_RIGHT: if (window->fullscreen) @@ -396,7 +404,7 @@ cairo_surface_t * window_create_surface(struct window *window, struct rectangle *rectangle) { - return cairo_drm_surface_create(window->ctx, + return cairo_drm_surface_create(window->display->ctx, CAIRO_CONTENT_COLOR_ALPHA, rectangle->width, rectangle->height); @@ -437,7 +445,7 @@ window_set_fullscreen(struct window *window, int fullscreen) window->fullscreen = fullscreen; if (window->fullscreen) { window->saved_allocation = window->allocation; - window->allocation = window->screen_allocation; + window->allocation = window->display->screen_allocation; } else { window->allocation = window->saved_allocation; } @@ -459,78 +467,98 @@ window_set_key_handler(struct window *window, window->user_data = data; } +struct window * +window_create(struct display *display, const char *title, + int32_t x, int32_t y, int32_t width, int32_t height) +{ + struct window *window; + + window = malloc(sizeof *window); + if (window == NULL) + return NULL; + + memset(window, 0, sizeof *window); + window->display = display; + window->title = strdup(title); + window->surface = wl_compositor_create_surface(display->compositor); + window->allocation.x = x; + window->allocation.y = y; + window->allocation.width = width; + window->allocation.height = height; + window->saved_allocation = window->allocation; + window->margin = 16; + window->state = WINDOW_STABLE; + + 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 -window_handle_geometry(void *data, - struct wl_output *output, - int32_t width, int32_t height) +display_handle_geometry(void *data, + struct wl_output *output, + int32_t width, int32_t height) { - struct window *window = data; + struct display *display = data; - window->screen_allocation.x = 0; - window->screen_allocation.y = 0; - window->screen_allocation.width = width; - window->screen_allocation.height = height; + 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 = { - window_handle_geometry, + display_handle_geometry, }; static void -window_handle_global(struct wl_display *display, +display_handle_global(struct wl_display *display, struct wl_object *object, void *data) { - struct window *window = data; + struct display *d = data; if (wl_object_implements(object, "compositor", 1)) { - window->compositor = (struct wl_compositor *) object; - wl_compositor_add_listener(window->compositor, - &compositor_listener, window); + d->compositor = (struct wl_compositor *) object; } else if (wl_object_implements(object, "output", 1)) { - struct wl_output *output = (struct wl_output *) object; - - wl_output_add_listener(output, - &output_listener, window); + d->output = (struct wl_output *) object; + wl_output_add_listener(d->output, &output_listener, d); } 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); + d->input_device =(struct wl_input_device *) object; } } -struct window * -window_create(struct wl_display *display, int fd, - const char *title, - int32_t x, int32_t y, int32_t width, int32_t height) +struct display * +display_create(struct wl_display *display, int fd) { - struct window *window; + struct display *d; - window = malloc(sizeof *window); - if (window == NULL) + d = malloc(sizeof *d); + if (d == NULL) return NULL; - memset(window, 0, sizeof *window); - window->display = display; - window->title = strdup(title); - window->compositor = wl_display_get_compositor(display); - window->surface = wl_compositor_create_surface(window->compositor); - window->allocation.x = x; - window->allocation.y = y; - window->allocation.width = width; - window->allocation.height = height; - window->saved_allocation = window->allocation; - window->margin = 16; - window->state = WINDOW_STABLE; - window->ctx = cairo_drm_context_get_for_fd(fd); - if (window->ctx == 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"); return NULL; } + /* Set up listener so we'll catch all events. */ 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; } diff --git a/window.h b/window.h index 9ec34f0..a8f5853 100644 --- a/window.h +++ b/window.h @@ -32,6 +32,13 @@ struct rectangle { 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_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); @@ -39,8 +46,7 @@ typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32 struct window * -window_create(struct wl_display *display, int fd, - const char *title, +window_create(struct display *display, const char *title, int32_t x, int32_t y, int32_t width, int32_t height); void