mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 11:21:28 +00:00
Merge pull request #2050 from smlx/focus-fix
Focus containers only on entry.
This commit is contained in:
commit
b2c0ba5b18
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue