window: create new struct surface with wl_surface

Struct window has many fields that are directly related to the
wl_surface, more than to the window as a whole. When we start composing
a window from several wl_surfaces, these fields need to be per
wl_surface, not per window.

Start separating such fields from struct window into struct surface by
moving the wl_surface.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
Pekka Paalanen 2013-02-13 16:17:13 +02:00 committed by Kristian Høgsberg
parent 550d66bcb1
commit 4e37374875

View File

@ -1,6 +1,6 @@
/* /*
* Copyright © 2008 Kristian Høgsberg * Copyright © 2008 Kristian Høgsberg
* Copyright © 2012 Collabora, Ltd. * Copyright © 2012-2013 Collabora, Ltd.
* *
* Permission to use, copy, modify, distribute, and sell this software and its * Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that * documentation for any purpose is hereby granted without fee, provided that
@ -189,12 +189,16 @@ struct toysurface {
void (*destroy)(struct toysurface *base); void (*destroy)(struct toysurface *base);
}; };
struct surface {
struct window *window;
struct wl_surface *surface;
};
struct window { struct window {
struct display *display; struct display *display;
struct window *parent; struct window *parent;
struct wl_list window_output_list; struct wl_list window_output_list;
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;
struct wl_region *input_region; struct wl_region *input_region;
struct wl_region *opaque_region; struct wl_region *opaque_region;
char *title; char *title;
@ -227,6 +231,8 @@ struct window {
window_fullscreen_handler_t fullscreen_handler; window_fullscreen_handler_t fullscreen_handler;
window_output_handler_t output_handler; window_output_handler_t output_handler;
struct surface *main_surface;
struct wl_shell_surface *shell_surface;
struct wl_callback *frame_cb; struct wl_callback *frame_cb;
struct frame *frame; struct frame *frame;
@ -1163,14 +1169,14 @@ window_attach_surface(struct window *window)
} }
if (window->opaque_region) { if (window->opaque_region) {
wl_surface_set_opaque_region(window->surface, wl_surface_set_opaque_region(window->main_surface->surface,
window->opaque_region); window->opaque_region);
wl_region_destroy(window->opaque_region); wl_region_destroy(window->opaque_region);
window->opaque_region = NULL; window->opaque_region = NULL;
} }
if (window->input_region) { if (window->input_region) {
wl_surface_set_input_region(window->surface, wl_surface_set_input_region(window->main_surface->surface,
window->input_region); window->input_region);
wl_region_destroy(window->input_region); wl_region_destroy(window->input_region);
window->input_region = NULL; window->input_region = NULL;
@ -1230,14 +1236,15 @@ window_create_surface(struct window *window)
window->display->dpy) { window->display->dpy) {
window->toysurface = window->toysurface =
egl_window_surface_create(window->display, egl_window_surface_create(window->display,
window->surface, flags, window->main_surface->surface,
flags,
&allocation); &allocation);
} }
if (!window->toysurface) if (!window->toysurface)
window->toysurface = shm_surface_create(window->display, window->toysurface = shm_surface_create(window->display,
window->surface, flags, window->main_surface->surface,
&allocation); flags, &allocation);
if (window->resizing) if (window->resizing)
flags = SURFACE_HINT_RESIZE; flags = SURFACE_HINT_RESIZE;
@ -1263,11 +1270,19 @@ window_set_buffer_transform(struct window *window,
enum wl_output_transform transform) enum wl_output_transform transform)
{ {
window->buffer_transform = transform; window->buffer_transform = transform;
wl_surface_set_buffer_transform(window->surface, transform); wl_surface_set_buffer_transform(window->main_surface->surface,
transform);
} }
static void frame_destroy(struct frame *frame); static void frame_destroy(struct frame *frame);
static void
surface_destroy(struct surface *surface)
{
wl_surface_destroy(surface->surface);
free(surface);
}
void void
window_destroy(struct window *window) window_destroy(struct window *window)
{ {
@ -1304,7 +1319,9 @@ window_destroy(struct window *window)
if (window->shell_surface) if (window->shell_surface)
wl_shell_surface_destroy(window->shell_surface); wl_shell_surface_destroy(window->shell_surface);
wl_surface_destroy(window->surface);
surface_destroy(window->main_surface);
wl_list_remove(&window->link); wl_list_remove(&window->link);
if (window->toysurface) if (window->toysurface)
@ -1498,7 +1515,7 @@ window_get_surface(struct window *window)
struct wl_surface * struct wl_surface *
window_get_wl_surface(struct window *window) window_get_wl_surface(struct window *window)
{ {
return window->surface; return window->main_surface->surface;
} }
struct wl_shell_surface * struct wl_shell_surface *
@ -2076,16 +2093,18 @@ frame_menu_func(struct window *window, int index, void *data)
case 1: /* move to workspace above */ case 1: /* move to workspace above */
display = window->display; display = window->display;
if (display->workspace > 0) if (display->workspace > 0)
workspace_manager_move_surface(display->workspace_manager, workspace_manager_move_surface(
window->surface, display->workspace_manager,
display->workspace - 1); window->main_surface->surface,
display->workspace - 1);
break; break;
case 2: /* move to workspace below */ case 2: /* move to workspace below */
display = window->display; display = window->display;
if (display->workspace < display->workspace_count - 1) if (display->workspace < display->workspace_count - 1)
workspace_manager_move_surface(display->workspace_manager, workspace_manager_move_surface(
window->surface, display->workspace_manager,
display->workspace + 1); window->main_surface->surface,
display->workspace + 1);
break; break;
case 3: /* fullscreen */ case 3: /* fullscreen */
/* we don't have a way to get out of fullscreen for now */ /* we don't have a way to get out of fullscreen for now */
@ -3300,7 +3319,7 @@ idle_redraw(struct task *task, uint32_t events)
window->redraw_needed = 0; window->redraw_needed = 0;
wl_list_init(&window->redraw_task.link); wl_list_init(&window->redraw_task.link);
window->frame_cb = wl_surface_frame(window->surface); window->frame_cb = wl_surface_frame(window->main_surface->surface);
wl_callback_add_listener(window->frame_cb, &listener, window); wl_callback_add_listener(window->frame_cb, &listener, window);
window_flush(window); window_flush(window);
} }
@ -3465,16 +3484,16 @@ window_set_text_cursor_position(struct window *window, int32_t x, int32_t y)
return; return;
text_cursor_position_notify(text_cursor_position, text_cursor_position_notify(text_cursor_position,
window->surface, window->main_surface->surface,
wl_fixed_from_int(x), wl_fixed_from_int(x),
wl_fixed_from_int(y)); wl_fixed_from_int(y));
} }
void void
window_damage(struct window *window, int32_t x, int32_t y, window_damage(struct window *window, int32_t x, int32_t y,
int32_t width, int32_t height) int32_t width, int32_t height)
{ {
wl_surface_damage(window->surface, x, y, width, height); wl_surface_damage(window->main_surface->surface, x, y, width, height);
} }
static void static void
@ -3537,6 +3556,23 @@ static const struct wl_surface_listener surface_listener = {
surface_leave surface_leave
}; };
static struct surface *
surface_create(struct window *window)
{
struct display *display = window->display;
struct surface *surface;
surface = calloc(1, sizeof *surface);
if (!surface)
return NULL;
surface->window = window;
surface->surface = wl_compositor_create_surface(display->compositor);
wl_surface_add_listener(surface->surface, &surface_listener, window);
return surface;
}
static struct window * static struct window *
window_create_internal(struct display *display, window_create_internal(struct display *display,
struct window *parent, int type) struct window *parent, int type)
@ -3550,12 +3586,11 @@ window_create_internal(struct display *display,
memset(window, 0, sizeof *window); memset(window, 0, sizeof *window);
window->display = display; window->display = display;
window->parent = parent; window->parent = parent;
window->surface = wl_compositor_create_surface(display->compositor); window->main_surface = surface_create(window);
wl_surface_add_listener(window->surface, &surface_listener, window);
if (type != TYPE_CUSTOM && display->shell) { if (type != TYPE_CUSTOM && display->shell) {
window->shell_surface = window->shell_surface =
wl_shell_get_shell_surface(display->shell, wl_shell_get_shell_surface(display->shell,
window->surface); window->main_surface->surface);
} }
window->allocation.x = 0; window->allocation.x = 0;
window->allocation.y = 0; window->allocation.y = 0;
@ -3577,7 +3612,7 @@ window_create_internal(struct display *display,
else else
window->buffer_type = WINDOW_BUFFER_TYPE_SHM; window->buffer_type = WINDOW_BUFFER_TYPE_SHM;
wl_surface_set_user_data(window->surface, window); wl_surface_set_user_data(window->main_surface->surface, window);
wl_list_insert(display->window_list.prev, &window->link); wl_list_insert(display->window_list.prev, &window->link);
wl_list_init(&window->redraw_task.link); wl_list_init(&window->redraw_task.link);
@ -3631,9 +3666,10 @@ window_create_transient(struct display *display, struct window *parent,
window->y = y; window->y = y;
if (display->shell) if (display->shell)
wl_shell_surface_set_transient(window->shell_surface, wl_shell_surface_set_transient(
window->parent->surface, window->shell_surface,
window->x, window->y, flags); window->parent->main_surface->surface,
window->x, window->y, flags);
return window; return window;
} }
@ -3783,7 +3819,7 @@ window_show_menu(struct display *display,
input_ungrab(input); input_ungrab(input);
wl_shell_surface_set_popup(window->shell_surface, input->seat, wl_shell_surface_set_popup(window->shell_surface, input->seat,
display_get_serial(window->display), display_get_serial(window->display),
window->parent->surface, window->parent->main_surface->surface,
window->x, window->y, 0); window->x, window->y, 0);
widget_set_redraw_handler(menu->widget, menu_redraw_handler); widget_set_redraw_handler(menu->widget, menu_redraw_handler);