diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-19 00:04:21 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-19 22:47:54 +1000 |
commit | 9ea71f292b2270f37cf7ca641b7bae628ef41ed7 (patch) | |
tree | fbeb938d3bb175013a0224e95ab50bdf0a678ae8 | |
parent | 28f3b8cb038d54eeef5c6fe568b0ae360b59f96e (diff) |
Introduce cursor_rebase
This function "rebases" the cursor on top of whatever is underneath it,
without triggering any focus changes.
-rw-r--r-- | include/sway/input/cursor.h | 16 | ||||
-rw-r--r-- | sway/commands/border.c | 2 | ||||
-rw-r--r-- | sway/commands/focus.c | 2 | ||||
-rw-r--r-- | sway/commands/seat/cursor.c | 4 | ||||
-rw-r--r-- | sway/input/cursor.c | 96 | ||||
-rw-r--r-- | sway/input/seat.c | 4 | ||||
-rw-r--r-- | sway/tree/view.c | 3 | ||||
-rw-r--r-- | sway/tree/workspace.c | 2 |
8 files changed, 78 insertions, 51 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 299721f0..50ac453b 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -40,8 +40,20 @@ struct sway_cursor { void sway_cursor_destroy(struct sway_cursor *cursor); struct sway_cursor *sway_cursor_create(struct sway_seat *seat); -void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, - bool allow_refocusing); + +/** + * "Rebase" a cursor on top of whatever view is underneath it. + * + * This chooses a cursor icon and sends a motion event to the surface. + */ +void cursor_rebase(struct sway_cursor *cursor); + +/** + * Like cursor_rebase, but also allows focus to change when the cursor enters a + * new container. + */ +void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec); + void dispatch_cursor_button(struct sway_cursor *cursor, struct wlr_input_device *device, uint32_t time_msec, uint32_t button, enum wlr_button_state state); diff --git a/sway/commands/border.c b/sway/commands/border.c index 2eed27bd..a50f7a1c 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c @@ -96,7 +96,7 @@ struct cmd_results *cmd_border(int argc, char **argv) { struct sway_seat *seat = input_manager_current_seat(input_manager); if (seat->cursor) { - cursor_send_pointer_motion(seat->cursor, 0, false); + cursor_rebase(seat->cursor); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/focus.c b/sway/commands/focus.c index b6f29fec..7dfa8814 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -236,7 +236,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { if (argc == 0 && container) { seat_set_focus_container(seat, container); seat_consider_warp_to_focus(seat); - cursor_send_pointer_motion(seat->cursor, 0, true); + cursor_rebase(seat->cursor); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 595e9bc6..1d41a94e 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -36,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { int delta_x = strtol(argv[1], NULL, 10); int delta_y = strtol(argv[2], NULL, 10); wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); - cursor_send_pointer_motion(cursor, 0, true); + cursor_rebase(cursor); } else if (strcasecmp(argv[0], "set") == 0) { if (argc < 3) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); @@ -45,7 +45,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { float x = strtof(argv[1], NULL) / root->width; float y = strtof(argv[2], NULL) / root->height; wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(cursor, 0, true); + cursor_rebase(cursor); } else { if (argc < 2) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 7ac5013d..756f2f8c 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -543,8 +543,57 @@ static void handle_resize_tiling_motion(struct sway_seat *seat, } } -void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, - bool allow_refocusing) { +static void cursor_do_rebase(struct sway_cursor *cursor, uint32_t time_msec, + struct sway_node *node, struct wlr_surface *surface, + double sx, double sy) { + // Handle cursor image + if (surface) { + // Reset cursor if switching between clients + struct wl_client *client = wl_resource_get_client(surface->resource); + if (client != cursor->image_client) { + cursor_set_image(cursor, "left_ptr", client); + } + } else if (node && node->type == N_CONTAINER) { + // Try a node's resize edge + enum wlr_edges edge = find_resize_edge(node->sway_container, cursor); + if (edge == WLR_EDGE_NONE) { + cursor_set_image(cursor, "left_ptr", NULL); + } else if (container_is_floating(node->sway_container)) { + cursor_set_image(cursor, wlr_xcursor_get_resize_name(edge), NULL); + } else { + if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) { + cursor_set_image(cursor, "col-resize", NULL); + } else { + cursor_set_image(cursor, "row-resize", NULL); + } + } + } else { + cursor_set_image(cursor, "left_ptr", NULL); + } + + // Send pointer enter/leave + struct wlr_seat *wlr_seat = cursor->seat->wlr_seat; + if (surface) { + if (seat_is_input_allowed(cursor->seat, surface)) { + wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy); + wlr_seat_pointer_notify_motion(wlr_seat, time_msec, sx, sy); + } + } else { + wlr_seat_pointer_clear_focus(wlr_seat); + } +} + +void cursor_rebase(struct sway_cursor *cursor) { + uint32_t time_msec = get_current_time_msec(); + struct wlr_surface *surface; + double sx, sy; + cursor->previous.node = node_at_coords(cursor->seat, + cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + cursor_do_rebase(cursor, time_msec, cursor->previous.node, surface, sx, sy); +} + +void cursor_send_pointer_motion(struct sway_cursor *cursor, + uint32_t time_msec) { if (time_msec == 0) { time_msec = get_current_time_msec(); } @@ -589,7 +638,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, cursor->previous.y = cursor->cursor->y; cursor->previous.node = node; - if (node && config->focus_follows_mouse && allow_refocusing) { + if (node && config->focus_follows_mouse) { struct sway_node *focus = seat_get_focus(seat); if (focus && node->type == N_WORKSPACE) { // Only follow the mouse if it would move to a new output @@ -620,40 +669,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, } } - // Handle cursor image - if (surface) { - // Reset cursor if switching between clients - struct wl_client *client = wl_resource_get_client(surface->resource); - if (client != cursor->image_client) { - cursor_set_image(cursor, "left_ptr", client); - } - } else if (node && node->type == N_CONTAINER) { - // Try a node's resize edge - enum wlr_edges edge = find_resize_edge(node->sway_container, cursor); - if (edge == WLR_EDGE_NONE) { - cursor_set_image(cursor, "left_ptr", NULL); - } else if (container_is_floating(node->sway_container)) { - cursor_set_image(cursor, wlr_xcursor_get_resize_name(edge), NULL); - } else { - if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) { - cursor_set_image(cursor, "col-resize", NULL); - } else { - cursor_set_image(cursor, "row-resize", NULL); - } - } - } else { - cursor_set_image(cursor, "left_ptr", NULL); - } - - // send pointer enter/leave - if (surface != NULL) { - if (seat_is_input_allowed(seat, surface)) { - wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy); - wlr_seat_pointer_notify_motion(wlr_seat, time_msec, sx, sy); - } - } else { - wlr_seat_pointer_clear_focus(wlr_seat); - } + cursor_do_rebase(cursor, time_msec, node, surface, sx, sy); struct wlr_drag_icon *wlr_drag_icon; wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) { @@ -668,7 +684,7 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { struct wlr_event_pointer_motion *event = data; wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y); - cursor_send_pointer_motion(cursor, event->time_msec, true); + cursor_send_pointer_motion(cursor, event->time_msec); transaction_commit_dirty(); } @@ -679,7 +695,7 @@ static void handle_cursor_motion_absolute( wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); struct wlr_event_pointer_motion_absolute *event = data; wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); - cursor_send_pointer_motion(cursor, event->time_msec, true); + cursor_send_pointer_motion(cursor, event->time_msec); transaction_commit_dirty(); } @@ -1134,7 +1150,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { } wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); - cursor_send_pointer_motion(cursor, event->time_msec, true); + cursor_send_pointer_motion(cursor, event->time_msec); transaction_commit_dirty(); } diff --git a/sway/input/seat.c b/sway/input/seat.c index cffceaae..25f454bd 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1173,7 +1173,7 @@ void seat_end_mouse_operation(struct sway_seat *seat) { seat->cursor->previous.x = seat->op_ref_lx; seat->cursor->previous.y = seat->op_ref_ly; if (seat->op_moved) { - cursor_send_pointer_motion(seat->cursor, 0, true); + cursor_send_pointer_motion(seat->cursor, 0); } } else { cursor_set_image(seat->cursor, "left_ptr", NULL); @@ -1207,5 +1207,5 @@ void seat_consider_warp_to_focus(struct sway_seat *seat) { } else { cursor_warp_to_workspace(seat->cursor, focus->sway_workspace); } - cursor_send_pointer_motion(seat->cursor, 0, false); + cursor_rebase(seat->cursor); } diff --git a/sway/tree/view.c b/sway/tree/view.c index 85998547..43a9d510 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -653,9 +653,8 @@ void view_unmap(struct sway_view *view) { } else if (node && node->type == N_WORKSPACE) { cursor_warp_to_workspace(seat->cursor, node->sway_workspace); } - } else { - cursor_send_pointer_motion(seat->cursor, 0, true); } + cursor_rebase(seat->cursor); } transaction_commit_dirty(); diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index a1282c1e..2a00824d 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -399,7 +399,7 @@ bool workspace_switch(struct sway_workspace *workspace, } seat_set_focus(seat, next); arrange_workspace(workspace); - cursor_send_pointer_motion(seat->cursor, 0, true); + cursor_rebase(seat->cursor); return true; } |