window: move 'widget' member into struct surface

Repaint and resizing widget recursions must start from the root widget
of each (sub-)surface, so that buffers and regions get initialized
correctly. Make it easier by moving the widget field from struct window
to struct surface.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Pekka Paalanen 12 years ago committed by Kristian Høgsberg
parent 7bcfeade53
commit ac95f3ee9d
  1. 29
      clients/window.c

@ -190,6 +190,7 @@ struct surface {
struct wl_surface *surface; struct wl_surface *surface;
struct toysurface *toysurface; struct toysurface *toysurface;
struct widget *widget;
struct rectangle allocation; struct rectangle allocation;
struct rectangle server_allocation; struct rectangle server_allocation;
@ -236,7 +237,6 @@ struct window {
struct wl_callback *frame_cb; struct wl_callback *frame_cb;
struct frame *frame; struct frame *frame;
struct widget *widget;
void *user_data; void *user_data;
struct wl_list link; struct wl_list link;
@ -1360,6 +1360,12 @@ widget_find_widget(struct widget *widget, int32_t x, int32_t y)
return NULL; return NULL;
} }
static struct widget *
window_find_widget(struct window *window, int32_t x, int32_t y)
{
return widget_find_widget(window->main_surface->widget, x, y);
}
static struct widget * static struct widget *
widget_create(struct window *window, void *data) widget_create(struct window *window, void *data)
{ {
@ -1382,10 +1388,13 @@ widget_create(struct window *window, void *data)
struct widget * struct widget *
window_add_widget(struct window *window, void *data) window_add_widget(struct window *window, void *data)
{ {
window->widget = widget_create(window, data); struct widget *widget;
wl_list_init(&window->widget->link);
return window->widget; widget = widget_create(window, data);
wl_list_init(&widget->link);
window->main_surface->widget = widget;
return widget;
} }
struct widget * struct widget *
@ -2334,7 +2343,7 @@ input_ungrab(struct input *input)
input->grab = NULL; input->grab = NULL;
if (input->pointer_focus) { if (input->pointer_focus) {
widget = widget_find_widget(input->pointer_focus->widget, widget = window_find_widget(input->pointer_focus,
input->sx, input->sy); input->sx, input->sy);
input_set_focus_widget(input, widget, input->sx, input->sy); input_set_focus_widget(input, widget, input->sx, input->sy);
} }
@ -2384,7 +2393,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
input->sx = sx; input->sx = sx;
input->sy = sy; input->sy = sy;
widget = widget_find_widget(window->widget, sx, sy); widget = window_find_widget(window, sx, sy);
input_set_focus_widget(input, widget, sx, sy); input_set_focus_widget(input, widget, sx, sy);
} }
@ -2416,7 +2425,7 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
return; return;
if (!(input->grab && input->grab_button)) { if (!(input->grab && input->grab_button)) {
widget = widget_find_widget(window->widget, sx, sy); widget = window_find_widget(window, sx, sy);
input_set_focus_widget(input, widget, sx, sy); input_set_focus_widget(input, widget, sx, sy);
} }
@ -3180,7 +3189,7 @@ idle_resize(struct window *window)
struct wl_compositor *compositor = window->display->compositor; struct wl_compositor *compositor = window->display->compositor;
window->resize_needed = 0; window->resize_needed = 0;
widget = window->widget; widget = window->main_surface->widget;
widget_set_allocation(widget, widget_set_allocation(widget,
window->pending_allocation.x, window->pending_allocation.x,
window->pending_allocation.y, window->pending_allocation.y,
@ -3265,7 +3274,7 @@ static void
handle_popup_done(void *data, struct wl_shell_surface *shell_surface) handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
{ {
struct window *window = data; struct window *window = data;
struct menu *menu = window->widget->user_data; struct menu *menu = window->main_surface->widget->user_data;
/* FIXME: Need more context in this event, at least the input /* FIXME: Need more context in this event, at least the input
* device. Or just use wl_callback. And this really needs to * device. Or just use wl_callback. And this really needs to
@ -3327,7 +3336,7 @@ idle_redraw(struct task *task, uint32_t events)
idle_resize(window); idle_resize(window);
window_create_surface(window); window_create_surface(window);
widget_redraw(window->widget); widget_redraw(window->main_surface->widget);
window->redraw_needed = 0; window->redraw_needed = 0;
wl_list_init(&window->redraw_task.link); wl_list_init(&window->redraw_task.link);

Loading…
Cancel
Save