mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 01:41:30 +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_cursor {
|
||||||
struct sway_seat *seat;
|
struct sway_seat *seat;
|
||||||
struct wlr_cursor *cursor;
|
struct wlr_cursor *cursor;
|
||||||
|
struct {
|
||||||
|
double x, y;
|
||||||
|
} previous;
|
||||||
struct wlr_xcursor_manager *xcursor_manager;
|
struct wlr_xcursor_manager *xcursor_manager;
|
||||||
|
|
||||||
struct wl_client *image_client;
|
struct wl_client *image_client;
|
||||||
|
@ -30,7 +33,7 @@ struct sway_cursor {
|
||||||
void sway_cursor_destroy(struct sway_cursor *cursor);
|
void sway_cursor_destroy(struct sway_cursor *cursor);
|
||||||
struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
|
struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
|
||||||
void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
|
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,
|
void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec,
|
||||||
uint32_t button, enum wlr_button_state state);
|
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_seat *seat = cursor->seat->wlr_seat;
|
||||||
struct wlr_surface *surface = NULL;
|
struct wlr_surface *surface = NULL;
|
||||||
double sx, sy;
|
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,
|
struct sway_container *c = container_at_coords(cursor->seat,
|
||||||
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
||||||
if (c && config->focus_follows_mouse && allow_refocusing) {
|
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);
|
seat_set_focus_warp(cursor->seat, c, false);
|
||||||
}
|
}
|
||||||
} else if (c->type == C_VIEW) {
|
} else if (c->type == C_VIEW) {
|
||||||
// Don't switch focus on title mouseover for
|
// Focus c if both of the following are true:
|
||||||
// stacked and tabbed layouts
|
// - cursor is over a new view, i.e. entered a new window; and
|
||||||
// If pointed container is in nested containers which are
|
// - the new view is visible, i.e. not hidden in a stack or tab.
|
||||||
// inside tabbed/stacked layout we should skip them
|
if (c != prev_c && view_is_visible(c->sway_view)) {
|
||||||
bool do_mouse_focus = true;
|
seat_set_focus_warp(cursor->seat, c, false);
|
||||||
bool is_visible = view_is_visible(c->sway_view);
|
} else {
|
||||||
struct sway_container *p = c->parent;
|
struct sway_container *next_focus =
|
||||||
while (p) {
|
seat_get_focus_inactive(cursor->seat, &root_container);
|
||||||
if ((p->layout == L_TABBED || p->layout == L_STACKED)
|
if (next_focus && next_focus->type == C_VIEW &&
|
||||||
&& !is_visible) {
|
view_is_visible(next_focus->sway_view)) {
|
||||||
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)) {
|
|
||||||
seat_set_focus_warp(cursor->seat, next_focus, false);
|
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;
|
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) {
|
struct sway_container *seat_get_focus(struct sway_seat *seat) {
|
||||||
if (!seat->has_focus) {
|
if (!seat->has_focus) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in a new issue