mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 07:56:31 +01:00
Introduce cursor_rebase
This function "rebases" the cursor on top of whatever is underneath it, without triggering any focus changes.
This commit is contained in:
parent
28f3b8cb03
commit
9ea71f292b
8 changed files with 78 additions and 51 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue