diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 42c894a4f..5dd109cae 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -6,6 +6,9 @@ struct sway_cursor { struct sway_seat *seat; struct wlr_cursor *cursor; + struct { + double x, y; + } previous; struct wlr_xcursor_manager *xcursor_manager; struct wl_client *image_client; @@ -30,7 +33,7 @@ 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); + bool allow_refocusing); void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, uint32_t button, enum wlr_button_state state); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 1cf432f3c..6751931d0 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -144,6 +144,14 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, struct wlr_seat *seat = cursor->seat->wlr_seat; struct wlr_surface *surface = NULL; double sx, sy; + + // Find the container beneath the pointer's previous position + struct sway_container *prev_c = container_at_coords(cursor->seat, + cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); + // Update the stored previous position + cursor->previous.x = cursor->cursor->x; + cursor->previous.y = cursor->cursor->y; + struct sway_container *c = container_at_coords(cursor->seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); if (c && config->focus_follows_mouse && allow_refocusing) { @@ -162,33 +170,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, seat_set_focus_warp(cursor->seat, c, false); } } else if (c->type == C_VIEW) { - // Don't switch focus on title mouseover for - // stacked and tabbed layouts - // If pointed container is in nested containers which are - // inside tabbed/stacked layout we should skip them - bool do_mouse_focus = true; - bool is_visible = view_is_visible(c->sway_view); - struct sway_container *p = c->parent; - while (p) { - if ((p->layout == L_TABBED || p->layout == L_STACKED) - && !is_visible) { - do_mouse_focus = false; - break; - } - p = p->parent; - } - if (!do_mouse_focus) { - struct sway_container *next_focus = seat_get_focus_inactive( - cursor->seat, p); - if(next_focus && !sway_assert(next_focus->type == C_VIEW, - "focus inactive container is not a view")) { - return; - } - if (next_focus && view_is_visible(next_focus->sway_view)) { + // Focus c if both of the following are true: + // - cursor is over a new view, i.e. entered a new window; and + // - the new view is visible, i.e. not hidden in a stack or tab. + if (c != prev_c && view_is_visible(c->sway_view)) { + seat_set_focus_warp(cursor->seat, c, false); + } else { + struct sway_container *next_focus = + seat_get_focus_inactive(cursor->seat, &root_container); + if (next_focus && next_focus->type == C_VIEW && + view_is_visible(next_focus->sway_view)) { seat_set_focus_warp(cursor->seat, next_focus, false); } - } else { - seat_set_focus_warp(cursor->seat, c, false); } } } diff --git a/sway/input/seat.c b/sway/input/seat.c index 7a3e928a3..6cfbe8d49 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -730,13 +730,6 @@ struct sway_container *seat_get_active_child(struct sway_seat *seat, return focus; } -struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { - if (!seat->has_focus) { - return NULL; - } - return seat_get_focus_inactive(seat, &root_container); -} - struct sway_container *seat_get_focus(struct sway_seat *seat) { if (!seat->has_focus) { return NULL;