window: Move widget focus handler to the widget
This commit is contained in:
+9
-10
@@ -230,10 +230,9 @@ panel_redraw_handler(struct window *window, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
panel_widget_focus_handler(struct window *window,
|
panel_widget_focus_handler(struct widget *widget, void *data)
|
||||||
struct widget *focus, void *data)
|
|
||||||
{
|
{
|
||||||
window_schedule_redraw(window);
|
widget_schedule_redraw(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -285,7 +284,6 @@ panel_create(struct display *display)
|
|||||||
window_set_custom(panel->window);
|
window_set_custom(panel->window);
|
||||||
window_set_user_data(panel->window, panel);
|
window_set_user_data(panel->window, panel);
|
||||||
window_set_button_handler(panel->window, panel_button_handler);
|
window_set_button_handler(panel->window, panel_button_handler);
|
||||||
window_set_widget_focus_handler(panel->window, panel_widget_focus_handler);
|
|
||||||
|
|
||||||
return panel;
|
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->icon = cairo_image_surface_create_from_png(icon);
|
||||||
widget->path = strdup(path);
|
widget->path = strdup(path);
|
||||||
widget->panel = panel;
|
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
|
static void
|
||||||
@@ -438,10 +438,9 @@ unlock_dialog_keyboard_focus_handler(struct window *window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
unlock_dialog_widget_focus_handler(struct window *window,
|
unlock_dialog_widget_focus_handler(struct widget *widget, void *data)
|
||||||
struct widget *focus, void *data)
|
|
||||||
{
|
{
|
||||||
window_schedule_redraw(window);
|
widget_schedule_redraw(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct unlock_dialog *
|
static struct unlock_dialog *
|
||||||
@@ -464,9 +463,9 @@ unlock_dialog_create(struct desktop *desktop)
|
|||||||
window_set_keyboard_focus_handler(dialog->window,
|
window_set_keyboard_focus_handler(dialog->window,
|
||||||
unlock_dialog_keyboard_focus_handler);
|
unlock_dialog_keyboard_focus_handler);
|
||||||
window_set_button_handler(dialog->window, unlock_dialog_button_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);
|
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,
|
desktop_shell_set_lock_surface(desktop->shell,
|
||||||
window_get_wl_shell_surface(dialog->window));
|
window_get_wl_shell_surface(dialog->window));
|
||||||
|
|||||||
+17
-10
@@ -134,7 +134,6 @@ struct window {
|
|||||||
window_motion_handler_t motion_handler;
|
window_motion_handler_t motion_handler;
|
||||||
window_enter_handler_t enter_handler;
|
window_enter_handler_t enter_handler;
|
||||||
window_leave_handler_t leave_handler;
|
window_leave_handler_t leave_handler;
|
||||||
window_widget_focus_handler_t widget_focus_handler;
|
|
||||||
window_data_handler_t data_handler;
|
window_data_handler_t data_handler;
|
||||||
window_drop_handler_t drop_handler;
|
window_drop_handler_t drop_handler;
|
||||||
window_close_handler_t close_handler;
|
window_close_handler_t close_handler;
|
||||||
@@ -150,8 +149,10 @@ struct window {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct widget {
|
struct widget {
|
||||||
|
struct window *window;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
struct rectangle allocation;
|
struct rectangle allocation;
|
||||||
|
widget_focus_handler_t focus_handler;
|
||||||
void *user_data;
|
void *user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1056,6 +1057,7 @@ window_add_widget(struct window *window, void *data)
|
|||||||
|
|
||||||
widget = malloc(sizeof *widget);
|
widget = malloc(sizeof *widget);
|
||||||
memset(widget, 0, sizeof *widget);
|
memset(widget, 0, sizeof *widget);
|
||||||
|
widget->window = window;
|
||||||
widget->user_data = data;
|
widget->user_data = data;
|
||||||
wl_list_insert(window->widget_list.prev, &widget->link);
|
wl_list_insert(window->widget_list.prev, &widget->link);
|
||||||
|
|
||||||
@@ -1099,6 +1101,18 @@ widget_get_user_data(struct widget *widget)
|
|||||||
return widget->user_data;
|
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
|
void
|
||||||
window_draw(struct window *window)
|
window_draw(struct window *window)
|
||||||
{
|
{
|
||||||
@@ -1232,8 +1246,8 @@ window_set_focus_widget(struct window *window, struct widget *focus)
|
|||||||
|
|
||||||
window->focus_widget = focus;
|
window->focus_widget = focus;
|
||||||
data = focus ? focus->user_data : NULL;
|
data = focus ? focus->user_data : NULL;
|
||||||
if (window->widget_focus_handler)
|
if (focus && focus->focus_handler)
|
||||||
window->widget_focus_handler(window, focus, data);
|
focus->focus_handler(focus, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -2038,13 +2052,6 @@ window_set_keyboard_focus_handler(struct window *window,
|
|||||||
window->keyboard_focus_handler = handler;
|
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
|
void
|
||||||
window_set_data_handler(struct window *window, window_data_handler_t handler)
|
window_set_data_handler(struct window *window, window_data_handler_t handler)
|
||||||
{
|
{
|
||||||
|
|||||||
+8
-6
@@ -194,8 +194,7 @@ typedef void (*window_drop_handler_t)(struct window *window,
|
|||||||
struct input *input,
|
struct input *input,
|
||||||
int32_t x, int32_t y, void *data);
|
int32_t x, int32_t y, void *data);
|
||||||
|
|
||||||
typedef void (*window_widget_focus_handler_t)(struct window *window,
|
typedef void (*widget_focus_handler_t)(struct widget *widget, void *data);
|
||||||
struct widget *focus, void *data);
|
|
||||||
|
|
||||||
typedef void (*window_close_handler_t)(struct window *window, 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_set_keyboard_focus_handler(struct window *window,
|
||||||
window_keyboard_focus_handler_t handler);
|
window_keyboard_focus_handler_t handler);
|
||||||
|
|
||||||
void
|
|
||||||
window_set_widget_focus_handler(struct window *window,
|
|
||||||
window_widget_focus_handler_t handler);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
window_set_data_handler(struct window *window,
|
window_set_data_handler(struct window *window,
|
||||||
window_data_handler_t handler);
|
window_data_handler_t handler);
|
||||||
@@ -366,6 +361,13 @@ widget_set_allocation(struct widget *widget,
|
|||||||
void *
|
void *
|
||||||
widget_get_user_data(struct widget *widget);
|
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
|
void
|
||||||
input_set_pointer_image(struct input *input, uint32_t time, int pointer);
|
input_set_pointer_image(struct input *input, uint32_t time, int pointer);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user