window: Create a widget for the window, drop window motion handler
This commit is contained in:
+7
-7
@@ -249,18 +249,17 @@ button_handler(struct window *window, struct input *input, uint32_t time,
|
|||||||
* Demonstrates the use of different cursors
|
* Demonstrates the use of different cursors
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
motion_handler(struct window *window, struct input *input, uint32_t time,
|
motion_handler(struct widget *widget, struct input *input, uint32_t time,
|
||||||
int32_t x, int32_t y, int32_t sx, int32_t sy, void *data)
|
int32_t x, int32_t y, void *data)
|
||||||
{
|
{
|
||||||
struct eventdemo *e = data;
|
struct eventdemo *e = data;
|
||||||
|
|
||||||
if (log_motion) {
|
if (log_motion) {
|
||||||
printf("motion time: %d, x: %d, y: %d, sx: %d, sy: %d\n",
|
printf("motion time: %d, x: %d, y: %d\n", time, x, y);
|
||||||
time, x, y, sx, sy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sx > e->x && sx < e->x + e->w)
|
if (x > e->x && x < e->x + e->w)
|
||||||
if(sy > e->y && sy < e->y + e->h)
|
if (y > e->y && y < e->y + e->h)
|
||||||
return POINTER_HAND1;
|
return POINTER_HAND1;
|
||||||
|
|
||||||
return POINTER_LEFT_PTR;
|
return POINTER_LEFT_PTR;
|
||||||
@@ -318,7 +317,8 @@ eventdemo_create(struct display *d)
|
|||||||
window_set_button_handler(e->window, button_handler);
|
window_set_button_handler(e->window, button_handler);
|
||||||
|
|
||||||
/* Set the callback motion handler for the window */
|
/* 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.
|
/* Demonstrate how to create a borderless window.
|
||||||
Move windows with META + left mouse button.
|
Move windows with META + left mouse button.
|
||||||
|
|||||||
+4
-5
@@ -98,10 +98,8 @@ draw_stuff(cairo_surface_t *surface, int width, int height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
motion_handler(struct window *window,
|
motion_handler(struct widget *widget, struct input *input,
|
||||||
struct input *input, uint32_t time,
|
uint32_t time, int32_t x, int32_t y, void *data)
|
||||||
int32_t x, int32_t y,
|
|
||||||
int32_t sx, int32_t sy, void *data)
|
|
||||||
{
|
{
|
||||||
return POINTER_HAND1;
|
return POINTER_HAND1;
|
||||||
}
|
}
|
||||||
@@ -156,7 +154,8 @@ int main(int argc, char *argv[])
|
|||||||
cairo_surface_destroy(s);
|
cairo_surface_destroy(s);
|
||||||
window_flush(flower.window);
|
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_button_handler(flower.window, button_handler);
|
||||||
window_set_user_data(flower.window, &flower);
|
window_set_user_data(flower.window, &flower);
|
||||||
display_run(d);
|
display_run(d);
|
||||||
|
|||||||
+7
-9
@@ -213,27 +213,25 @@ frame_callback(void *data, struct wl_callback *callback, uint32_t time)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
smoke_motion_handler(struct window *window,
|
smoke_motion_handler(struct widget *widget, struct input *input,
|
||||||
struct input *input, uint32_t time,
|
uint32_t time, int32_t x, int32_t y, void *data)
|
||||||
int32_t x, int32_t y,
|
|
||||||
int32_t surface_x, int32_t surface_y, void *data)
|
|
||||||
{
|
{
|
||||||
struct smoke *smoke = data;
|
struct smoke *smoke = data;
|
||||||
int i, i0, i1, j, j0, j1, k, d = 5;
|
int i, i0, i1, j, j0, j1, k, d = 5;
|
||||||
|
|
||||||
if (surface_x - d < 1)
|
if (x - d < 1)
|
||||||
i0 = 1;
|
i0 = 1;
|
||||||
else
|
else
|
||||||
i0 = surface_x - d;
|
i0 = x - d;
|
||||||
if (i0 + 2 * d > smoke->width - 1)
|
if (i0 + 2 * d > smoke->width - 1)
|
||||||
i1 = smoke->width - 1;
|
i1 = smoke->width - 1;
|
||||||
else
|
else
|
||||||
i1 = i0 + 2 * d;
|
i1 = i0 + 2 * d;
|
||||||
|
|
||||||
if (surface_y - d < 1)
|
if (y - d < 1)
|
||||||
j0 = 1;
|
j0 = 1;
|
||||||
else
|
else
|
||||||
j0 = surface_y - d;
|
j0 = y - d;
|
||||||
if (j0 + 2 * d > smoke->height - 1)
|
if (j0 + 2 * d > smoke->height - 1)
|
||||||
j1 = smoke->height - 1;
|
j1 = smoke->height - 1;
|
||||||
else
|
else
|
||||||
@@ -291,7 +289,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
window_flush(smoke.window);
|
window_flush(smoke.window);
|
||||||
|
|
||||||
window_set_motion_handler(smoke.window,
|
widget_set_motion_handler(window_get_widget(smoke.window),
|
||||||
smoke_motion_handler);
|
smoke_motion_handler);
|
||||||
|
|
||||||
window_set_user_data(smoke.window, &smoke);
|
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,
|
window_set_button_handler(shell->lockscreen,
|
||||||
lockscreen_button_handler);
|
lockscreen_button_handler);
|
||||||
|
|
||||||
|
|
||||||
tablet_shell_set_lockscreen(shell->tablet_shell,
|
tablet_shell_set_lockscreen(shell->tablet_shell,
|
||||||
window_get_wl_surface(shell->lockscreen));
|
window_get_wl_surface(shell->lockscreen));
|
||||||
lockscreen_draw(shell);
|
lockscreen_draw(shell);
|
||||||
|
|||||||
+4
-4
@@ -356,7 +356,6 @@ enum escape_state {
|
|||||||
|
|
||||||
struct terminal {
|
struct terminal {
|
||||||
struct window *window;
|
struct window *window;
|
||||||
struct widget *widget;
|
|
||||||
struct display *display;
|
struct display *display;
|
||||||
union utf8_char *data;
|
union utf8_char *data;
|
||||||
struct task io_task;
|
struct task io_task;
|
||||||
@@ -2253,7 +2252,8 @@ motion_handler(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)
|
||||||
{
|
{
|
||||||
struct terminal *terminal = data;
|
struct window *window = data;
|
||||||
|
struct terminal *terminal = window_get_user_data(window);
|
||||||
|
|
||||||
if (terminal->dragging) {
|
if (terminal->dragging) {
|
||||||
input_get_position(input,
|
input_get_position(input,
|
||||||
@@ -2300,8 +2300,8 @@ terminal_create(struct display *display, int fullscreen)
|
|||||||
keyboard_focus_handler);
|
keyboard_focus_handler);
|
||||||
window_set_button_handler(terminal->window, button_handler);
|
window_set_button_handler(terminal->window, button_handler);
|
||||||
|
|
||||||
terminal->widget = window_add_widget(terminal->window, terminal);
|
widget_set_motion_handler(window_get_widget(terminal->window),
|
||||||
widget_set_motion_handler(terminal->widget, motion_handler);
|
motion_handler);
|
||||||
|
|
||||||
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
|
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
|
||||||
cr = cairo_create(surface);
|
cr = cairo_create(surface);
|
||||||
|
|||||||
+12
-13
@@ -107,6 +107,7 @@ enum {
|
|||||||
struct window {
|
struct window {
|
||||||
struct display *display;
|
struct display *display;
|
||||||
struct window *parent;
|
struct window *parent;
|
||||||
|
struct widget *widget;
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
struct wl_shell_surface *shell_surface;
|
struct wl_shell_surface *shell_surface;
|
||||||
char *title;
|
char *title;
|
||||||
@@ -131,7 +132,6 @@ struct window {
|
|||||||
window_key_handler_t key_handler;
|
window_key_handler_t key_handler;
|
||||||
window_button_handler_t button_handler;
|
window_button_handler_t button_handler;
|
||||||
window_keyboard_focus_handler_t keyboard_focus_handler;
|
window_keyboard_focus_handler_t keyboard_focus_handler;
|
||||||
window_motion_handler_t motion_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;
|
||||||
@@ -919,6 +919,12 @@ window_get_display(struct window *window)
|
|||||||
return window->display;
|
return window->display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct widget *
|
||||||
|
window_get_widget(struct window *window)
|
||||||
|
{
|
||||||
|
return window->widget;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
window_create_surface(struct window *window)
|
window_create_surface(struct window *window)
|
||||||
{
|
{
|
||||||
@@ -1060,7 +1066,7 @@ window_add_widget(struct window *window, void *data)
|
|||||||
memset(widget, 0, sizeof *widget);
|
memset(widget, 0, sizeof *widget);
|
||||||
widget->window = window;
|
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, &widget->link);
|
||||||
|
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
@@ -1298,10 +1304,6 @@ input_handle_motion(void *data, struct wl_input_device *input_device,
|
|||||||
if (widget && widget->motion_handler)
|
if (widget && widget->motion_handler)
|
||||||
pointer = widget->motion_handler(widget, input, time, sx, sy,
|
pointer = widget->motion_handler(widget, input, time, sx, sy,
|
||||||
widget->user_data);
|
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);
|
pointer = input_get_pointer_image_for_location(input, pointer);
|
||||||
input_set_pointer_image(input, time, 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.width = width;
|
||||||
window->allocation.height = height;
|
window->allocation.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window->widget->allocation = window->allocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -2046,13 +2050,6 @@ window_set_button_handler(struct window *window,
|
|||||||
window->button_handler = handler;
|
window->button_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
window_set_motion_handler(struct window *window,
|
|
||||||
window_motion_handler_t handler)
|
|
||||||
{
|
|
||||||
window->motion_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)
|
||||||
@@ -2143,7 +2140,9 @@ window_create_internal(struct display *display, struct window *parent,
|
|||||||
window->margin = 16;
|
window->margin = 16;
|
||||||
window->decoration = 1;
|
window->decoration = 1;
|
||||||
window->transparent = 1;
|
window->transparent = 1;
|
||||||
|
|
||||||
wl_list_init(&window->widget_list);
|
wl_list_init(&window->widget_list);
|
||||||
|
window->widget = window_add_widget(window, window);
|
||||||
|
|
||||||
if (display->dpy)
|
if (display->dpy)
|
||||||
#ifdef HAVE_CAIRO_EGL
|
#ifdef HAVE_CAIRO_EGL
|
||||||
|
|||||||
@@ -230,6 +230,8 @@ struct widget *
|
|||||||
window_get_focus_widget(struct window *window);
|
window_get_focus_widget(struct window *window);
|
||||||
struct display *
|
struct display *
|
||||||
window_get_display(struct window *window);
|
window_get_display(struct window *window);
|
||||||
|
struct widget *
|
||||||
|
window_get_widget(struct window *window);
|
||||||
|
|
||||||
void
|
void
|
||||||
window_move(struct window *window, struct input *input, uint32_t time);
|
window_move(struct window *window, struct input *input, uint32_t time);
|
||||||
|
|||||||
Reference in New Issue
Block a user