* Demonstrates the use of different cursors
*/
static int
-motion_handler(struct window *window, struct input *input, uint32_t time,
- int32_t x, int32_t y, int32_t sx, int32_t sy, void *data)
+motion_handler(struct widget *widget, struct input *input, uint32_t time,
+ int32_t x, int32_t y, void *data)
{
struct eventdemo *e = data;
if (log_motion) {
- printf("motion time: %d, x: %d, y: %d, sx: %d, sy: %d\n",
- time, x, y, sx, sy);
+ printf("motion time: %d, x: %d, y: %d\n", time, x, y);
}
- if(sx > e->x && sx < e->x + e->w)
- if(sy > e->y && sy < e->y + e->h)
+ if (x > e->x && x < e->x + e->w)
+ if (y > e->y && y < e->y + e->h)
return POINTER_HAND1;
return POINTER_LEFT_PTR;
window_set_button_handler(e->window, button_handler);
/* Set the callback motion handler for the window */
- window_set_motion_handler(e->window, motion_handler);
+ widget_set_motion_handler(window_get_widget(e->window),
+ motion_handler);
/* Demonstrate how to create a borderless window.
Move windows with META + left mouse button.
}
static int
-motion_handler(struct window *window,
- struct input *input, uint32_t time,
- int32_t x, int32_t y,
- int32_t sx, int32_t sy, void *data)
+motion_handler(struct widget *widget, struct input *input,
+ uint32_t time, int32_t x, int32_t y, void *data)
{
return POINTER_HAND1;
}
cairo_surface_destroy(s);
window_flush(flower.window);
- window_set_motion_handler(flower.window, motion_handler);
+ widget_set_motion_handler(window_get_widget(flower.window),
+ motion_handler);
window_set_button_handler(flower.window, button_handler);
window_set_user_data(flower.window, &flower);
display_run(d);
}
static int
-smoke_motion_handler(struct window *window,
- struct input *input, uint32_t time,
- int32_t x, int32_t y,
- int32_t surface_x, int32_t surface_y, void *data)
+smoke_motion_handler(struct widget *widget, struct input *input,
+ uint32_t time, int32_t x, int32_t y, void *data)
{
struct smoke *smoke = data;
int i, i0, i1, j, j0, j1, k, d = 5;
- if (surface_x - d < 1)
+ if (x - d < 1)
i0 = 1;
else
- i0 = surface_x - d;
+ i0 = x - d;
if (i0 + 2 * d > smoke->width - 1)
i1 = smoke->width - 1;
else
i1 = i0 + 2 * d;
- if (surface_y - d < 1)
+ if (y - d < 1)
j0 = 1;
else
- j0 = surface_y - d;
+ j0 = y - d;
if (j0 + 2 * d > smoke->height - 1)
j1 = smoke->height - 1;
else
window_flush(smoke.window);
- window_set_motion_handler(smoke.window,
+ widget_set_motion_handler(window_get_widget(smoke.window),
smoke_motion_handler);
window_set_user_data(smoke.window, &smoke);
window_set_button_handler(shell->lockscreen,
lockscreen_button_handler);
-
tablet_shell_set_lockscreen(shell->tablet_shell,
window_get_wl_surface(shell->lockscreen));
lockscreen_draw(shell);
struct terminal {
struct window *window;
- struct widget *widget;
struct display *display;
union utf8_char *data;
struct task io_task;
struct input *input, uint32_t time,
int32_t x, int32_t y, void *data)
{
- struct terminal *terminal = data;
+ struct window *window = data;
+ struct terminal *terminal = window_get_user_data(window);
if (terminal->dragging) {
input_get_position(input,
keyboard_focus_handler);
window_set_button_handler(terminal->window, button_handler);
- terminal->widget = window_add_widget(terminal->window, terminal);
- widget_set_motion_handler(terminal->widget, motion_handler);
+ widget_set_motion_handler(window_get_widget(terminal->window),
+ motion_handler);
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
cr = cairo_create(surface);
struct window {
struct display *display;
struct window *parent;
+ struct widget *widget;
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;
char *title;
window_key_handler_t key_handler;
window_button_handler_t button_handler;
window_keyboard_focus_handler_t keyboard_focus_handler;
- window_motion_handler_t motion_handler;
window_data_handler_t data_handler;
window_drop_handler_t drop_handler;
window_close_handler_t close_handler;
return window->display;
}
+struct widget *
+window_get_widget(struct window *window)
+{
+ return window->widget;
+}
+
void
window_create_surface(struct window *window)
{
memset(widget, 0, sizeof *widget);
widget->window = window;
widget->user_data = data;
- wl_list_insert(window->widget_list.prev, &widget->link);
+ wl_list_insert(&window->widget_list, &widget->link);
return widget;
}
if (widget && widget->motion_handler)
pointer = widget->motion_handler(widget, input, time, sx, sy,
widget->user_data);
- if (window->motion_handler)
- pointer = (*window->motion_handler)(window, input, time,
- x, y, sx, sy,
- window->user_data);
pointer = input_get_pointer_image_for_location(input, pointer);
input_set_pointer_image(input, time, pointer);
window->allocation.width = width;
window->allocation.height = height;
}
+
+ window->widget->allocation = window->allocation;
}
static void
}
void
-window_set_motion_handler(struct window *window,
- window_motion_handler_t handler)
-{
- window->motion_handler = handler;
-}
-
-void
window_set_keyboard_focus_handler(struct window *window,
window_keyboard_focus_handler_t handler)
{
window->margin = 16;
window->decoration = 1;
window->transparent = 1;
+
wl_list_init(&window->widget_list);
+ window->widget = window_add_widget(window, window);
if (display->dpy)
#ifdef HAVE_CAIRO_EGL
window_get_focus_widget(struct window *window);
struct display *
window_get_display(struct window *window);
+struct widget *
+window_get_widget(struct window *window);
void
window_move(struct window *window, struct input *input, uint32_t time);