window: Create a widget for the window, drop window motion handler

dev
Kristian Høgsberg 13 years ago
parent 5f190ef96a
commit 87a57bbd73
  1. 14
      clients/eventdemo.c
  2. 9
      clients/flower.c
  3. 16
      clients/smoke.c
  4. 1
      clients/tablet-shell.c
  5. 8
      clients/terminal.c
  6. 25
      clients/window.c
  7. 2
      clients/window.h

@ -249,18 +249,17 @@ button_handler(struct window *window, struct input *input, uint32_t time,
* 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;
@ -318,7 +317,8 @@ eventdemo_create(struct display *d)
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.

@ -98,10 +98,8 @@ draw_stuff(cairo_surface_t *surface, int width, int height)
}
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;
}
@ -156,7 +154,8 @@ int main(int argc, char *argv[])
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);

@ -213,27 +213,25 @@ frame_callback(void *data, struct wl_callback *callback, uint32_t time)
}
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
@ -291,7 +289,7 @@ int main(int argc, char *argv[])
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);

@ -222,7 +222,6 @@ show_lockscreen(void *data, struct tablet_shell *tablet_shell)
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);

@ -356,7 +356,6 @@ enum escape_state {
struct terminal {
struct window *window;
struct widget *widget;
struct display *display;
union utf8_char *data;
struct task io_task;
@ -2253,7 +2252,8 @@ motion_handler(struct widget *widget,
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,
@ -2300,8 +2300,8 @@ terminal_create(struct display *display, int fullscreen)
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);

@ -107,6 +107,7 @@ enum {
struct window {
struct display *display;
struct window *parent;
struct widget *widget;
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;
char *title;
@ -131,7 +132,6 @@ struct window {
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;
@ -919,6 +919,12 @@ window_get_display(struct window *window)
return window->display;
}
struct widget *
window_get_widget(struct window *window)
{
return window->widget;
}
void
window_create_surface(struct window *window)
{
@ -1060,7 +1066,7 @@ window_add_widget(struct window *window, void *data)
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;
}
@ -1298,10 +1304,6 @@ input_handle_motion(void *data, struct wl_input_device *input_device,
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);
@ -1946,6 +1948,8 @@ window_set_child_size(struct window *window, int32_t width, int32_t height)
window->allocation.width = width;
window->allocation.height = height;
}
window->widget->allocation = window->allocation;
}
static void
@ -2046,13 +2050,6 @@ window_set_button_handler(struct window *window,
window->button_handler = handler;
}
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)
@ -2143,7 +2140,9 @@ window_create_internal(struct display *display, struct window *parent,
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

@ -230,6 +230,8 @@ struct widget *
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);

Loading…
Cancel
Save