From dac4f8e19ffd19dfeee2c65270476a52c13d0f8f Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 27 Sep 2018 10:25:59 +0200 Subject: pointer-constraints: refactoring * Rename the constraint_create signal to new_constraint for consistency * Move the constraint_destroy signal to the constraint itself * Use rotate_child_position instead of duplicating logic * Fix inert constraint resource handling * Style fixes --- rootston/cursor.c | 66 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 31 deletions(-) (limited to 'rootston/cursor.c') diff --git a/rootston/cursor.c b/rootston/cursor.c index 4ec600e1..08a71ec4 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -572,32 +572,45 @@ void roots_cursor_handle_constraint_commit(struct roots_cursor *cursor) { } } +static void handle_constraint_commit(struct wl_listener *listener, + void *data) { + struct roots_cursor *cursor = + wl_container_of(listener, cursor, constraint_commit); + assert(cursor->active_constraint->surface == data); + roots_cursor_handle_constraint_commit(cursor); +} + void roots_cursor_constrain(struct roots_cursor *cursor, struct wlr_pointer_constraint_v1 *constraint, double sx, double sy) { - if (cursor->active_constraint != constraint) { - wlr_log(WLR_DEBUG, "roots_cursor_constrain(%p, %p)", cursor, constraint); - wlr_log(WLR_DEBUG, "cursor->active_constraint: %p", cursor->active_constraint); - - if (cursor->active_constraint) { - wlr_pointer_constraint_v1_send_deactivated(cursor->active_constraint); - if (cursor->constraint_commit.link.next) { - wl_list_remove(&cursor->constraint_commit.link); - } - } + if (cursor->active_constraint == constraint) { + return; + } - cursor->active_constraint = constraint; + wlr_log(WLR_DEBUG, "roots_cursor_constrain(%p, %p)", + cursor, constraint); + wlr_log(WLR_DEBUG, "cursor->active_constraint: %p", + cursor->active_constraint); - if (!constraint) { - return; - } + wl_list_remove(&cursor->constraint_commit.link); + wl_list_init(&cursor->constraint_commit.link); + if (cursor->active_constraint) { + wlr_pointer_constraint_v1_send_deactivated( + cursor->active_constraint); + } - wlr_pointer_constraint_v1_send_activated(constraint); - wl_signal_add(&constraint->surface->events.commit, - &cursor->constraint_commit); - } else if (constraint == NULL) { + cursor->active_constraint = constraint; + + if (constraint == NULL) { return; } + wlr_pointer_constraint_v1_send_activated(constraint); + + wl_list_remove(&cursor->constraint_commit.link); + wl_signal_add(&constraint->surface->events.commit, + &cursor->constraint_commit); + cursor->constraint_commit.notify = handle_constraint_commit; + pixman_region32_clear(&cursor->confine); pixman_region32_t *region = &constraint->region; @@ -612,20 +625,11 @@ void roots_cursor_constrain(struct roots_cursor *cursor, double sx = (boxes[0].x1 + boxes[0].x2) / 2.; double sy = (boxes[0].y1 + boxes[0].y2) / 2.; - double lx, ly; - if (view->rotation == 0.0) { - lx = sx + view->x; - ly = sy + view->y; - } else { - double c = cos(view->rotation); - double s = sin(view->rotation); - - double center_x = view->width / 2.; - double center_y = view->height / 2.; + rotate_child_position(&sx, &sy, 0, 0, view->width, view->height, + view->rotation); - lx = c * (sx - center_x) - s * (sy - center_y) + center_x + view->x; - ly = s * (sx - center_x) + c * (sy - center_y) + center_y + view->y; - } + double lx = view->x + sx; + double ly = view->y + sy; wlr_cursor_warp_closest(cursor->cursor, NULL, lx, ly); } -- cgit v1.2.3