diff options
author | emersion <contact@emersion.fr> | 2017-10-29 11:20:11 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-10-31 12:30:56 +0100 |
commit | 2e2d63a16482135bb61db6a24cd09cd04c068c22 (patch) | |
tree | 387c49103f029b30e7ad24064cef1c48425f3e10 | |
parent | c45f2eef0e0fb805d88b54b65db23bb8a49ebea6 (diff) |
Manage wlr_output_cursor from wlr_cursor
-rw-r--r-- | examples/pointer.c | 5 | ||||
-rw-r--r-- | include/wlr/types/wlr_output_layout.h | 5 | ||||
-rw-r--r-- | types/wlr_cursor.c | 60 | ||||
-rw-r--r-- | types/wlr_output_layout.c | 6 |
4 files changed, 69 insertions, 7 deletions
diff --git a/examples/pointer.c b/examples/pointer.c index b2fef4e8..26d50b95 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -156,9 +156,8 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener, sample->cur_x = event->x_mm; sample->cur_y = event->y_mm; - struct wlr_xcursor_image *image = sample->xcursor->images[0]; - wlr_cursor_warp_absolute(sample->cursor, event->device, - sample->cur_x - image->hotspot_x, sample->cur_y - image->hotspot_y); + wlr_cursor_warp_absolute(sample->cursor, event->device, sample->cur_x, + sample->cur_y); } static void handle_cursor_button(struct wl_listener *listener, void *data) { diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index ea8dbcd2..a99debf6 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -12,6 +12,7 @@ struct wlr_output_layout { struct wlr_output_layout_state *state; struct { + struct wl_signal add; struct wl_signal change; struct wl_signal destroy; } events; @@ -24,6 +25,10 @@ struct wlr_output_layout_output { int x, y; struct wl_list link; struct wlr_output_layout_output_state *state; + + struct { + struct wl_signal destroy; + } events; }; struct wlr_output_layout *wlr_output_layout_create(); diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index f07b57ab..dac290cb 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -37,6 +37,8 @@ struct wlr_cursor_output_cursor { struct wlr_cursor *cursor; struct wlr_output_cursor *output_cursor; struct wl_list link; + + struct wl_listener layout_output_destroy; }; struct wlr_cursor_state { @@ -48,6 +50,7 @@ struct wlr_cursor_state { struct wlr_output *mapped_output; struct wlr_box *mapped_box; + struct wl_listener layout_add; struct wl_listener layout_change; struct wl_listener layout_destroy; }; @@ -70,6 +73,7 @@ struct wlr_cursor *wlr_cursor_create() { cur->state->mapped_output = NULL; wl_list_init(&cur->state->devices); + wl_list_init(&cur->state->output_cursors); // pointer signals wl_signal_init(&cur->events.motion); @@ -102,6 +106,7 @@ static void wlr_cursor_detach_output_layout(struct wlr_cursor *cur) { wl_list_remove(&cur->state->layout_destroy.link); wl_list_remove(&cur->state->layout_change.link); + wl_list_remove(&cur->state->layout_add.link); cur->state->layout = NULL; } @@ -263,12 +268,20 @@ void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev, void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { - // TODO + struct wlr_cursor_output_cursor *output_cursor; + wl_list_for_each(output_cursor, &cur->state->output_cursors, link) { + wlr_output_cursor_set_image(output_cursor->output_cursor, pixels, + stride, width, height, hotspot_x, hotspot_y); + } } void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { - // TODO + struct wlr_cursor_output_cursor *output_cursor; + wl_list_for_each(output_cursor, &cur->state->output_cursors, link) { + wlr_output_cursor_set_surface(output_cursor->output_cursor, surface, + hotspot_x, hotspot_y); + } } static void handle_pointer_motion(struct wl_listener *listener, void *data) { @@ -489,10 +502,50 @@ static void handle_layout_destroy(struct wl_listener *listener, void *data) { wlr_cursor_detach_output_layout(state->cursor); } +static void handle_layout_output_destroy(struct wl_listener *listener, + void *data) { + struct wlr_cursor_output_cursor *output_cursor = + wl_container_of(listener, output_cursor, layout_output_destroy); + //struct wlr_output_layout_output *l_output = data; + + wl_list_remove(&output_cursor->link); + wlr_output_cursor_destroy(output_cursor->output_cursor); + wl_list_remove(&output_cursor->layout_output_destroy.link); + free(output_cursor); +} + +static void handle_layout_add(struct wl_listener *listener, void *data) { + struct wlr_cursor_state *state = + wl_container_of(listener, state, layout_add); + struct wlr_output_layout_output *l_output = data; + + struct wlr_cursor_output_cursor *output_cursor = + calloc(1, sizeof(struct wlr_cursor_output_cursor)); + if (output_cursor == NULL) { + wlr_log(L_ERROR, "Failed to allocate wlr_cursor_output_cursor"); + return; + } + output_cursor->cursor = state->cursor; + + output_cursor->output_cursor = wlr_output_cursor_create(l_output->output); + if (output_cursor->output_cursor == NULL) { + wlr_log(L_ERROR, "Failed to create wlr_output_cursor"); + free(output_cursor); + return; + } + + output_cursor->layout_output_destroy.notify = handle_layout_output_destroy; + wl_signal_add(&l_output->events.destroy, + &output_cursor->layout_output_destroy); + + wl_list_insert(&state->cursor->state->output_cursors, &output_cursor->link); +} + static void handle_layout_change(struct wl_listener *listener, void *data) { struct wlr_cursor_state *state = wl_container_of(listener, state, layout_change); struct wlr_output_layout *layout = data; + if (!wlr_output_layout_contains_point(layout, NULL, state->cursor->x, state->cursor->y)) { // the output we were on has gone away so go to the closest boundary @@ -513,9 +566,10 @@ void wlr_cursor_attach_output_layout(struct wlr_cursor *cur, return; } + wl_signal_add(&l->events.add, &cur->state->layout_add); + cur->state->layout_add.notify = handle_layout_add; wl_signal_add(&l->events.change, &cur->state->layout_change); cur->state->layout_change.notify = handle_layout_change; - wl_signal_add(&l->events.destroy, &cur->state->layout_destroy); cur->state->layout_destroy.notify = handle_layout_destroy; diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 817a03f6..190f2733 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -35,6 +35,7 @@ struct wlr_output_layout *wlr_output_layout_create() { } wl_list_init(&layout->outputs); + wl_signal_init(&layout->events.add); wl_signal_init(&layout->events.change); wl_signal_init(&layout->events.destroy); @@ -43,6 +44,7 @@ struct wlr_output_layout *wlr_output_layout_create() { static void wlr_output_layout_output_destroy( struct wlr_output_layout_output *l_output) { + wl_signal_emit(&l_output->events.destroy, l_output); wl_list_remove(&l_output->state->resolution.link); wl_list_remove(&l_output->state->output_destroy.link); wl_list_remove(&l_output->link); @@ -155,7 +157,7 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create( l_output->state->l_output = l_output; l_output->state->layout = layout; l_output->output = output; - + wl_signal_init(&l_output->events.destroy); wl_list_insert(&layout->outputs, &l_output->link); wl_signal_add(&output->events.resolution, &l_output->state->resolution); @@ -163,6 +165,8 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create( wl_signal_add(&output->events.destroy, &l_output->state->output_destroy); l_output->state->output_destroy.notify = handle_output_destroy; + wl_signal_emit(&layout->events.add, l_output); + return l_output; } |