Manage wlr_output_cursor from wlr_cursor

This commit is contained in:
emersion 2017-10-29 11:20:11 +01:00
parent c45f2eef0e
commit 2e2d63a164
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 69 additions and 7 deletions

View File

@ -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) {

View File

@ -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();

View File

@ -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;

View File

@ -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;
}