diff options
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 66 | ||||
-rw-r--r-- | rootston/desktop.c | 89 | ||||
-rw-r--r-- | rootston/output.c | 2 | ||||
-rw-r--r-- | rootston/seat.c | 9 |
4 files changed, 83 insertions, 83 deletions
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); } diff --git a/rootston/desktop.c b/rootston/desktop.c index a1e61738..c180c839 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -777,52 +777,59 @@ static void input_inhibit_deactivate(struct wl_listener *listener, void *data) { } } -static void handle_constraint_create( - struct wl_listener *listener, - struct wlr_pointer_constraint_v1 *constraint) { - struct roots_seat* seat = constraint->seat->data; +static void handle_constraint_destroy(struct wl_listener *listener, + void *data) { + struct roots_pointer_constraint *constraint = + wl_container_of(listener, constraint, destroy); + struct wlr_pointer_constraint_v1 *wlr_constraint = data; + struct roots_seat *seat = wlr_constraint->seat->data; - double sx, sy; - struct wlr_surface *surface = desktop_surface_at(seat->input->server->desktop, - seat->cursor->cursor->x, seat->cursor->cursor->y, &sx, &sy, NULL); + wl_list_remove(&constraint->destroy.link); - if (surface == constraint->surface) { - assert(!seat->cursor->active_constraint); - roots_cursor_constrain(seat->cursor, constraint, sx, sy); - } -} + if (seat->cursor->active_constraint == wlr_constraint) { + wl_list_remove(&seat->cursor->constraint_commit.link); + wl_list_init(&seat->cursor->constraint_commit.link); + seat->cursor->active_constraint = NULL; -static void handle_constraint_destroy( - struct wl_listener *listener, - struct wlr_pointer_constraint_v1 *constraint) { - struct roots_seat* seat = constraint->seat->data; - if (seat->cursor->active_constraint == constraint) { - roots_cursor_constrain(seat->cursor, NULL, NAN, NAN); - if (constraint->current.committed & + if (wlr_constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT && seat->cursor->pointer_view) { - double sx = constraint->current.cursor_hint.x; - double sy = constraint->current.cursor_hint.y; + double sx = wlr_constraint->current.cursor_hint.x; + double sy = wlr_constraint->current.cursor_hint.y; struct roots_view *view = seat->cursor->pointer_view->view; + rotate_child_position(&sx, &sy, 0, 0, view->width, view->height, + view->rotation); + double lx = view->x + sx; + double ly = view->y + sy; - 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); + wlr_cursor_warp(seat->cursor->cursor, NULL, lx, ly); + } + } - double center_x = view->width / 2.; - double center_y = view->height / 2.; + free(constraint); +} - 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; - } +static void handle_pointer_constraint(struct wl_listener *listener, + void *data) { + struct wlr_pointer_constraint_v1 *wlr_constraint = data; + struct roots_seat *seat = wlr_constraint->seat->data; - wlr_cursor_warp(seat->cursor->cursor, NULL, lx, ly); - } + struct roots_pointer_constraint *constraint = + calloc(1, sizeof(struct roots_pointer_constraint)); + constraint->constraint = wlr_constraint; + + constraint->destroy.notify = handle_constraint_destroy; + wl_signal_add(&wlr_constraint->events.destroy, &constraint->destroy); + + double sx, sy; + struct wlr_surface *surface = desktop_surface_at( + seat->input->server->desktop, + seat->cursor->cursor->x, seat->cursor->cursor->y, &sx, &sy, NULL); + + if (surface == wlr_constraint->surface) { + assert(!seat->cursor->active_constraint); + roots_cursor_constrain(seat->cursor, wlr_constraint, sx, sy); } } @@ -956,13 +963,11 @@ struct roots_desktop *desktop_create(struct roots_server *server, &desktop->xdg_toplevel_decoration); desktop->xdg_toplevel_decoration.notify = handle_xdg_toplevel_decoration; - desktop->pointer_constraints = wlr_pointer_constraints_v1_create(server->wl_display); - desktop->constraint_destroy.notify = (wl_notify_func_t)handle_constraint_destroy; - wl_signal_add(&desktop->pointer_constraints->events.constraint_destroy, - &desktop->constraint_destroy); - desktop->constraint_create.notify = (wl_notify_func_t)handle_constraint_create; - wl_signal_add(&desktop->pointer_constraints->events.constraint_create, - &desktop->constraint_create); + desktop->pointer_constraints = + wlr_pointer_constraints_v1_create(server->wl_display); + desktop->pointer_constraint.notify = handle_pointer_constraint; + wl_signal_add(&desktop->pointer_constraints->events.new_constraint, + &desktop->pointer_constraint); return desktop; } diff --git a/rootston/output.c b/rootston/output.c index 4207f0d0..e85612fa 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -22,7 +22,7 @@ * Rotate a child's position relative to a parent. The parent size is (pw, ph), * the child position is (*sx, *sy) and its size is (sw, sh). */ -static void rotate_child_position(double *sx, double *sy, double sw, double sh, +void rotate_child_position(double *sx, double *sy, double sw, double sh, double pw, double ph, float rotation) { if (rotation != 0.0) { // Coordinates relative to the center of the subsurface diff --git a/rootston/seat.c b/rootston/seat.c index 466f1429..e3336fde 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -307,14 +307,6 @@ static void handle_pointer_focus_change(struct wl_listener *listener, roots_cursor_handle_focus_change(cursor, event); } -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); -} - static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) { struct wlr_cursor *cursor = seat->cursor->cursor; @@ -456,7 +448,6 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { seat->cursor->focus_change.notify = handle_pointer_focus_change; wl_list_init(&seat->cursor->constraint_commit.link); - seat->cursor->constraint_commit.notify = handle_constraint_commit; } static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener, |