window: Move button handler to widget

dev
Kristian Høgsberg 14 years ago
parent 19dd1d7eb1
commit a8a0db3497
  1. 49
      clients/desktop-shell.c
  2. 7
      clients/dnd.c
  3. 5
      clients/eventdemo.c
  4. 7
      clients/flower.c
  5. 8
      clients/resizor.c
  6. 7
      clients/tablet-shell.c
  7. 8
      clients/terminal.c
  8. 6
      clients/view.c
  9. 42
      clients/window.c
  10. 24
      clients/window.h

@ -244,24 +244,29 @@ panel_widget_leave_handler(struct widget *widget,
} }
static void static void
panel_button_handler(struct window *window, panel_widget_button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct panel *panel = data; struct panel *panel = data;
struct panel_widget *pi; struct panel_widget *pi;
struct widget *focus;
pi = widget_get_user_data(widget);
focus = window_get_focus_widget(panel->window); widget_schedule_redraw(widget);
if (focus && button == BTN_LEFT) { if (state == 0)
pi = widget_get_user_data(focus); panel_activate_widget(panel, pi);
window_schedule_redraw(panel->window); }
if (state == 0)
panel_activate_widget(panel, pi); static void
} else if (button == BTN_RIGHT) { panel_button_handler(struct widget *widget,
if (state) struct input *input, uint32_t time,
show_menu(panel, input, time); int button, int state, void *data)
} {
struct window *window = data;
struct panel *panel = window_get_user_data(window);
if (button == BTN_RIGHT && state)
show_menu(panel, input, time);
} }
static void static void
@ -291,7 +296,9 @@ panel_create(struct display *display)
window_set_redraw_handler(panel->window, panel_redraw_handler); window_set_redraw_handler(panel->window, panel_redraw_handler);
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);
widget_set_button_handler(window_get_widget(panel->window),
panel_button_handler);
return panel; return panel;
} }
@ -310,6 +317,7 @@ panel_add_widget(struct panel *panel, const char *icon, const char *path)
widget->widget = window_add_widget(panel->window, widget); widget->widget = window_add_widget(panel->window, widget);
widget_set_enter_handler(widget->widget, panel_widget_enter_handler); widget_set_enter_handler(widget->widget, panel_widget_enter_handler);
widget_set_leave_handler(widget->widget, panel_widget_leave_handler); widget_set_leave_handler(widget->widget, panel_widget_leave_handler);
widget_set_button_handler(widget->widget, panel_widget_button_handler);
} }
static void static void
@ -414,16 +422,14 @@ unlock_dialog_draw(struct unlock_dialog *dialog)
} }
static void static void
unlock_dialog_button_handler(struct window *window, unlock_dialog_button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct unlock_dialog *dialog = data; struct unlock_dialog *dialog = data;
struct desktop *desktop = dialog->desktop; struct desktop *desktop = dialog->desktop;
struct widget *focus;
focus = window_get_focus_widget(dialog->window); if (button == BTN_LEFT) {
if (focus && button == BTN_LEFT) {
if (state == 0 && !dialog->closing) { if (state == 0 && !dialog->closing) {
display_defer(desktop->display, &desktop->unlock_task); display_defer(desktop->display, &desktop->unlock_task);
dialog->closing = 1; dialog->closing = 1;
@ -480,12 +486,13 @@ unlock_dialog_create(struct desktop *desktop)
window_set_redraw_handler(dialog->window, unlock_dialog_redraw_handler); window_set_redraw_handler(dialog->window, unlock_dialog_redraw_handler);
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);
dialog->button = window_add_widget(dialog->window, NULL); dialog->button = window_add_widget(dialog->window, NULL);
widget_set_enter_handler(dialog->button, widget_set_enter_handler(dialog->button,
unlock_dialog_widget_enter_handler); unlock_dialog_widget_enter_handler);
widget_set_leave_handler(dialog->button, widget_set_leave_handler(dialog->button,
unlock_dialog_widget_leave_handler); unlock_dialog_widget_leave_handler);
widget_set_button_handler(dialog->button,
unlock_dialog_button_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));

@ -361,11 +361,12 @@ create_drag_cursor(struct dnd_drag *dnd_drag,
} }
static void static void
dnd_button_handler(struct window *window, dnd_button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct dnd *dnd = data; struct window *window = data;
struct dnd *dnd = window_get_user_data(window);
int32_t x, y; int32_t x, y;
struct item *item; struct item *item;
struct rectangle allocation; struct rectangle allocation;
@ -537,13 +538,13 @@ dnd_create(struct display *display)
window_set_redraw_handler(dnd->window, redraw_handler); window_set_redraw_handler(dnd->window, redraw_handler);
window_set_keyboard_focus_handler(dnd->window, window_set_keyboard_focus_handler(dnd->window,
keyboard_focus_handler); keyboard_focus_handler);
window_set_button_handler(dnd->window, dnd_button_handler);
window_set_data_handler(dnd->window, dnd_data_handler); window_set_data_handler(dnd->window, dnd_data_handler);
window_set_drop_handler(dnd->window, dnd_drop_handler); window_set_drop_handler(dnd->window, dnd_drop_handler);
widget = window_get_widget(dnd->window); widget = window_get_widget(dnd->window);
widget_set_enter_handler(widget, dnd_enter_handler); widget_set_enter_handler(widget, dnd_enter_handler);
widget_set_motion_handler(widget, dnd_motion_handler); widget_set_motion_handler(widget, dnd_motion_handler);
widget_set_button_handler(widget, dnd_button_handler);
width = 4 * (item_width + item_padding) + item_padding; width = 4 * (item_width + item_padding) + item_padding;
height = 4 * (item_height + item_padding) + item_padding; height = 4 * (item_height + item_padding) + item_padding;

@ -222,7 +222,7 @@ key_handler(struct window *window, struct input *input, uint32_t time,
* \param data user data associated to the window * \param data user data associated to the window
*/ */
static void static void
button_handler(struct window *window, struct input *input, uint32_t time, button_handler(struct widget *widget, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
int32_t x, y; int32_t x, y;
@ -314,7 +314,8 @@ eventdemo_create(struct display *d)
window_set_key_handler(e->window, key_handler); window_set_key_handler(e->window, key_handler);
/* Set the callback button handler for the window */ /* Set the callback button handler for the window */
window_set_button_handler(e->window, button_handler); widget_set_button_handler(window_get_widget(e->window),
button_handler);
/* Set the callback motion handler for the window */ /* Set the callback motion handler for the window */
widget_set_motion_handler(window_get_widget(e->window), widget_set_motion_handler(window_get_widget(e->window),

@ -105,10 +105,12 @@ motion_handler(struct widget *widget, struct input *input,
} }
static void static void
button_handler(struct window *window, button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct window *window = data;
if (state) if (state)
window_move(window, input, time); window_move(window, input, time);
} }
@ -156,7 +158,8 @@ int main(int argc, char *argv[])
widget_set_motion_handler(window_get_widget(flower.window), widget_set_motion_handler(window_get_widget(flower.window),
motion_handler); motion_handler);
window_set_button_handler(flower.window, button_handler); widget_set_button_handler(window_get_widget(flower.window),
button_handler);
window_set_user_data(flower.window, &flower); window_set_user_data(flower.window, &flower);
display_run(d); display_run(d);

@ -190,11 +190,12 @@ show_menu(struct resizor *resizor, struct input *input, uint32_t time)
} }
static void static void
button_handler(struct window *window, button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct resizor *resizor = data; struct window *window = data;
struct resizor *resizor = window_get_user_data(window);
switch (button) { switch (button) {
case BTN_RIGHT: case BTN_RIGHT:
@ -232,7 +233,8 @@ resizor_create(struct display *display)
height = resizor->height.current + 0.5; height = resizor->height.current + 0.5;
window_set_child_size(resizor->window, resizor->width, height); window_set_child_size(resizor->window, resizor->width, height);
window_set_button_handler(resizor->window, button_handler); widget_set_button_handler(window_get_widget(resizor->window),
button_handler);
resizor_draw(resizor); resizor_draw(resizor);

@ -198,11 +198,12 @@ lockscreen_draw(struct tablet_shell *shell)
} }
static void static void
lockscreen_button_handler(struct window *window, lockscreen_button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct tablet_shell *shell = data; struct window *window = data;
struct tablet_shell *shell = window_get_user_data(window);
window_destroy(shell->lockscreen); window_destroy(shell->lockscreen);
shell->lockscreen = NULL; shell->lockscreen = NULL;
@ -219,7 +220,7 @@ show_lockscreen(void *data, struct tablet_shell *tablet_shell)
window_set_user_data(shell->lockscreen, shell); window_set_user_data(shell->lockscreen, shell);
window_set_decoration(shell->lockscreen, 0); window_set_decoration(shell->lockscreen, 0);
window_set_custom(shell->lockscreen); window_set_custom(shell->lockscreen);
window_set_button_handler(shell->lockscreen, widget_set_button_handler(window_get_widget(shell->lockscreen),
lockscreen_button_handler); lockscreen_button_handler);
tablet_shell_set_lockscreen(shell->tablet_shell, tablet_shell_set_lockscreen(shell->tablet_shell,

@ -2224,11 +2224,12 @@ keyboard_focus_handler(struct window *window,
} }
static void static void
button_handler(struct window *window, button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct terminal *terminal = data; struct window *window = data;
struct terminal *terminal = window_get_user_data(window);
switch (button) { switch (button) {
case 272: case 272:
@ -2298,7 +2299,8 @@ terminal_create(struct display *display, int fullscreen)
window_set_key_handler(terminal->window, key_handler); window_set_key_handler(terminal->window, key_handler);
window_set_keyboard_focus_handler(terminal->window, window_set_keyboard_focus_handler(terminal->window,
keyboard_focus_handler); keyboard_focus_handler);
window_set_button_handler(terminal->window, button_handler); widget_set_button_handler(window_get_widget(terminal->window),
button_handler);
widget_set_motion_handler(window_get_widget(terminal->window), widget_set_motion_handler(window_get_widget(terminal->window),
motion_handler); motion_handler);

@ -154,7 +154,8 @@ static void
button_handler(struct window *window, struct input *input, uint32_t time, button_handler(struct window *window, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct view *view = data; struct window *window = data;
a struct view *view = window_get_user_data(window);
if(!state) if(!state)
return; return;
@ -252,7 +253,8 @@ view_create(struct display *display,
window_set_key_handler(view->window, key_handler); window_set_key_handler(view->window, key_handler);
window_set_keyboard_focus_handler(view->window, window_set_keyboard_focus_handler(view->window,
keyboard_focus_handler); keyboard_focus_handler);
window_set_button_handler(view->window, button_handler); widget_set_button_handler(window_get_widget(view->window),
button_handler);
view->page = 0; view->page = 0;
view->fullscreen = fullscreen; view->fullscreen = fullscreen;

@ -130,7 +130,6 @@ struct window {
window_resize_handler_t resize_handler; window_resize_handler_t resize_handler;
window_redraw_handler_t redraw_handler; window_redraw_handler_t redraw_handler;
window_key_handler_t key_handler; window_key_handler_t key_handler;
window_button_handler_t button_handler;
window_keyboard_focus_handler_t keyboard_focus_handler; window_keyboard_focus_handler_t keyboard_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;
@ -153,6 +152,7 @@ struct widget {
widget_enter_handler_t enter_handler; widget_enter_handler_t enter_handler;
widget_leave_handler_t leave_handler; widget_leave_handler_t leave_handler;
widget_motion_handler_t motion_handler; widget_motion_handler_t motion_handler;
widget_button_handler_t button_handler;
void *user_data; void *user_data;
}; };
@ -1126,6 +1126,13 @@ widget_set_motion_handler(struct widget *widget,
widget->motion_handler = handler; widget->motion_handler = handler;
} }
void
widget_set_button_handler(struct widget *widget,
widget_button_handler_t handler)
{
widget->button_handler = handler;
}
void void
widget_schedule_redraw(struct widget *widget) widget_schedule_redraw(struct widget *widget)
{ {
@ -1349,6 +1356,7 @@ input_handle_button(void *data,
location = get_pointer_location(window, input->sx, input->sy); location = get_pointer_location(window, input->sx, input->sy);
widget = window->focus_widget;
if (window->display->shell && button == BTN_LEFT && state == 1) { if (window->display->shell && button == BTN_LEFT && state == 1) {
switch (location) { switch (location) {
case WINDOW_TITLEBAR: case WINDOW_TITLEBAR:
@ -1373,11 +1381,11 @@ input_handle_button(void *data,
location); location);
break; break;
case WINDOW_CLIENT_AREA: case WINDOW_CLIENT_AREA:
if (window->button_handler) if (widget && widget->button_handler)
(*window->button_handler)(window, (*widget->button_handler)(widget,
input, time, input, time,
button, state, button, state,
window->user_data); widget->user_data);
break; break;
} }
} else if (button == BTN_RIGHT && state == 1) { } else if (button == BTN_RIGHT && state == 1) {
@ -1393,19 +1401,19 @@ input_handle_button(void *data,
window_schedule_redraw(window->menu); window_schedule_redraw(window->menu);
break; break;
case WINDOW_CLIENT_AREA: case WINDOW_CLIENT_AREA:
if (window->button_handler) if (widget && widget->button_handler)
(*window->button_handler)(window, (*widget->button_handler)(widget,
input, time, input, time,
button, state, button, state,
window->user_data); widget->user_data);
break; break;
} }
} else { } else {
if (window->button_handler) if (widget && widget->button_handler)
(*window->button_handler)(window, (*widget->button_handler)(widget,
input, time, input, time,
button, state, button, state,
window->user_data); widget->user_data);
} }
if (window->focus_widget && if (window->focus_widget &&
@ -2042,13 +2050,6 @@ window_set_key_handler(struct window *window,
window->key_handler = handler; window->key_handler = handler;
} }
void
window_set_button_handler(struct window *window,
window_button_handler_t handler)
{
window->button_handler = handler;
}
void 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)
@ -2241,12 +2242,13 @@ menu_leave_handler(struct widget *widget, struct input *input, void *data)
} }
static void static void
menu_button_handler(struct window *window, menu_button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct menu *menu = data; struct window *window = data;
struct menu *menu = window_get_user_data(window);
/* Either relase after press-drag-release or click-motion-click. */ /* Either relase after press-drag-release or click-motion-click. */
if (state == 0 && time - menu->time > 500) { if (state == 0 && time - menu->time > 500) {
@ -2333,13 +2335,13 @@ window_create_menu(struct display *display,
window->parent->shell_surface, window->parent->shell_surface,
window->x, window->y, 0); window->x, window->y, 0);
window_set_button_handler(window, menu_button_handler);
window_set_redraw_handler(window, menu_redraw_handler); window_set_redraw_handler(window, menu_redraw_handler);
window_set_user_data(window, menu); window_set_user_data(window, menu);
widget_set_enter_handler(window->widget, menu_enter_handler); widget_set_enter_handler(window->widget, menu_enter_handler);
widget_set_leave_handler(window->widget, menu_leave_handler); widget_set_leave_handler(window->widget, menu_leave_handler);
widget_set_motion_handler(window->widget, menu_motion_handler); widget_set_motion_handler(window->widget, menu_motion_handler);
widget_set_button_handler(window->widget, menu_button_handler);
return window; return window;
} }

@ -168,15 +168,6 @@ typedef void (*window_key_handler_t)(struct window *window, struct input *input,
typedef void (*window_keyboard_focus_handler_t)(struct window *window, typedef void (*window_keyboard_focus_handler_t)(struct window *window,
struct input *device, void *data); struct input *device, void *data);
typedef void (*window_button_handler_t)(struct window *window,
struct input *input, uint32_t time,
int button, int state, void *data);
typedef int (*window_motion_handler_t)(struct window *window,
struct input *input, uint32_t time,
int32_t x, int32_t y,
int32_t sx, int32_t sy, void *data);
typedef void (*window_data_handler_t)(struct window *window, typedef void (*window_data_handler_t)(struct window *window,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int32_t x, int32_t y, int32_t x, int32_t y,
@ -197,6 +188,9 @@ typedef void (*widget_leave_handler_t)(struct widget *widget,
typedef int (*widget_motion_handler_t)(struct widget *widget, typedef int (*widget_motion_handler_t)(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int32_t x, int32_t y, void *data); int32_t x, int32_t y, void *data);
typedef void (*widget_button_handler_t)(struct widget *widget,
struct input *input, uint32_t time,
int button, int state, void *data);
struct window * struct window *
window_create(struct display *display, int32_t width, int32_t height); window_create(struct display *display, int32_t width, int32_t height);
@ -316,14 +310,6 @@ void
window_set_key_handler(struct window *window, window_set_key_handler(struct window *window,
window_key_handler_t handler); window_key_handler_t handler);
void
window_set_button_handler(struct window *window,
window_button_handler_t handler);
void
window_set_motion_handler(struct window *window,
window_motion_handler_t handler);
void 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);
@ -366,6 +352,10 @@ void
widget_set_motion_handler(struct widget *widget, widget_set_motion_handler(struct widget *widget,
widget_motion_handler_t handler); widget_motion_handler_t handler);
void void
widget_set_button_handler(struct widget *widget,
widget_button_handler_t handler);
void
widget_schedule_redraw(struct widget *widget); widget_schedule_redraw(struct widget *widget);
void void

Loading…
Cancel
Save