window: Move widget focus handler to the widget
authorKristian Høgsberg <krh@bitplanet.net>
Sun, 8 Jan 2012 20:18:19 +0000 (15:18 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Sun, 8 Jan 2012 20:18:19 +0000 (15:18 -0500)
clients/desktop-shell.c
clients/window.c
clients/window.h

index 05c444c..febac78 100644 (file)
@@ -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));
index 33b7b95..6f1c65b 100644 (file)
@@ -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);
 
@@ -1100,6 +1102,18 @@ widget_get_user_data(struct widget *widget)
 }
 
 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)
 {
        if (!window->decoration)
@@ -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
@@ -2039,13 +2053,6 @@ window_set_keyboard_focus_handler(struct window *window,
 }
 
 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)
 {
        window->data_handler = handler;
index 2fa0a80..483ed20 100644 (file)
@@ -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);
 
@@ -335,10 +334,6 @@ 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);
 
@@ -367,6 +362,13 @@ 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);
 
 void