window: Move widget focus handler to the widget

dev
Kristian Høgsberg 13 years ago
parent c51f79954b
commit 9a13dab8a9
  1. 19
      clients/desktop-shell.c
  2. 27
      clients/window.c
  3. 14
      clients/window.h

@ -230,10 +230,9 @@ panel_redraw_handler(struct window *window, void *data)
}
static void
panel_widget_focus_handler(struct window *window,
struct widget *focus, void *data)
panel_widget_focus_handler(struct widget *widget, void *data)
{
window_schedule_redraw(window);
widget_schedule_redraw(widget);
}
static void
@ -285,7 +284,6 @@ panel_create(struct display *display)
window_set_custom(panel->window);
window_set_user_data(panel->window, panel);
window_set_button_handler(panel->window, panel_button_handler);
window_set_widget_focus_handler(panel->window, panel_widget_focus_handler);
return panel;
}
@ -300,7 +298,9 @@ panel_add_widget(struct panel *panel, const char *icon, const char *path)
widget->icon = cairo_image_surface_create_from_png(icon);
widget->path = strdup(path);
widget->panel = panel;
window_add_widget(panel->window, widget);
widget->widget = window_add_widget(panel->window, widget);
widget_set_focus_handler(widget->widget, panel_widget_focus_handler);
}
static void
@ -438,10 +438,9 @@ unlock_dialog_keyboard_focus_handler(struct window *window,
}
static void
unlock_dialog_widget_focus_handler(struct window *window,
struct widget *focus, void *data)
unlock_dialog_widget_focus_handler(struct widget *widget, void *data)
{
window_schedule_redraw(window);
widget_schedule_redraw(widget);
}
static struct unlock_dialog *
@ -464,9 +463,9 @@ unlock_dialog_create(struct desktop *desktop)
window_set_keyboard_focus_handler(dialog->window,
unlock_dialog_keyboard_focus_handler);
window_set_button_handler(dialog->window, unlock_dialog_button_handler);
window_set_widget_focus_handler(dialog->window,
unlock_dialog_widget_focus_handler);
dialog->button = window_add_widget(dialog->window, NULL);
widget_set_focus_handler(dialog->button,
unlock_dialog_widget_focus_handler);
desktop_shell_set_lock_surface(desktop->shell,
window_get_wl_shell_surface(dialog->window));

@ -134,7 +134,6 @@ struct window {
window_motion_handler_t motion_handler;
window_enter_handler_t enter_handler;
window_leave_handler_t leave_handler;
window_widget_focus_handler_t widget_focus_handler;
window_data_handler_t data_handler;
window_drop_handler_t drop_handler;
window_close_handler_t close_handler;
@ -150,8 +149,10 @@ struct window {
};
struct widget {
struct window *window;
struct wl_list link;
struct rectangle allocation;
widget_focus_handler_t focus_handler;
void *user_data;
};
@ -1056,6 +1057,7 @@ window_add_widget(struct window *window, void *data)
widget = malloc(sizeof *widget);
memset(widget, 0, sizeof *widget);
widget->window = window;
widget->user_data = data;
wl_list_insert(window->widget_list.prev, &widget->link);
@ -1099,6 +1101,18 @@ widget_get_user_data(struct widget *widget)
return widget->user_data;
}
void
widget_set_focus_handler(struct widget *widget, widget_focus_handler_t handler)
{
widget->focus_handler = handler;
}
void
widget_schedule_redraw(struct widget *widget)
{
window_schedule_redraw(widget->window);
}
void
window_draw(struct window *window)
{
@ -1232,8 +1246,8 @@ window_set_focus_widget(struct window *window, struct widget *focus)
window->focus_widget = focus;
data = focus ? focus->user_data : NULL;
if (window->widget_focus_handler)
window->widget_focus_handler(window, focus, data);
if (focus && focus->focus_handler)
focus->focus_handler(focus, data);
}
static void
@ -2038,13 +2052,6 @@ window_set_keyboard_focus_handler(struct window *window,
window->keyboard_focus_handler = handler;
}
void
window_set_widget_focus_handler(struct window *window,
window_widget_focus_handler_t handler)
{
window->widget_focus_handler = handler;
}
void
window_set_data_handler(struct window *window, window_data_handler_t handler)
{

@ -194,8 +194,7 @@ typedef void (*window_drop_handler_t)(struct window *window,
struct input *input,
int32_t x, int32_t y, void *data);
typedef void (*window_widget_focus_handler_t)(struct window *window,
struct widget *focus, void *data);
typedef void (*widget_focus_handler_t)(struct widget *widget, void *data);
typedef void (*window_close_handler_t)(struct window *window, void *data);
@ -334,10 +333,6 @@ void
window_set_keyboard_focus_handler(struct window *window,
window_keyboard_focus_handler_t handler);
void
window_set_widget_focus_handler(struct window *window,
window_widget_focus_handler_t handler);
void
window_set_data_handler(struct window *window,
window_data_handler_t handler);
@ -366,6 +361,13 @@ widget_set_allocation(struct widget *widget,
void *
widget_get_user_data(struct widget *widget);
void
widget_set_focus_handler(struct widget *widget,
widget_focus_handler_t handler);
void
widget_schedule_redraw(struct widget *widget);
void
input_set_pointer_image(struct input *input, uint32_t time, int pointer);

Loading…
Cancel
Save