mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
Fix focusing topmost floating windows
Re-focus on the container on which the cursor hovers over. A special case is, if there are menus or other subsurfaces open in the focused container. It will prefer the focused container as long as there are subsurfaces. This commit starts caching the previous node as well as the previous x/y cursor position. Re-calculating the previous focused node by looking at the current state of the cursor position does not work, if the environment changes.
This commit is contained in:
parent
8bec0c90c7
commit
7727d54faf
|
@ -10,6 +10,7 @@ struct sway_cursor {
|
||||||
struct wlr_cursor *cursor;
|
struct wlr_cursor *cursor;
|
||||||
struct {
|
struct {
|
||||||
double x, y;
|
double x, y;
|
||||||
|
struct sway_node *node;
|
||||||
} previous;
|
} previous;
|
||||||
struct wlr_xcursor_manager *xcursor_manager;
|
struct wlr_xcursor_manager *xcursor_manager;
|
||||||
|
|
||||||
|
|
|
@ -567,15 +567,15 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
|
||||||
struct wlr_surface *surface = NULL;
|
struct wlr_surface *surface = NULL;
|
||||||
double sx, sy;
|
double sx, sy;
|
||||||
|
|
||||||
// Find the node beneath the pointer's previous position
|
struct sway_node *prev_node = cursor->previous.node;
|
||||||
struct sway_node *prev_node = node_at_coords(seat,
|
struct sway_node *node = node_at_coords(seat,
|
||||||
cursor->previous.x, cursor->previous.y, &surface, &sx, &sy);
|
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
||||||
|
|
||||||
// Update the stored previous position
|
// Update the stored previous position
|
||||||
cursor->previous.x = cursor->cursor->x;
|
cursor->previous.x = cursor->cursor->x;
|
||||||
cursor->previous.y = cursor->cursor->y;
|
cursor->previous.y = cursor->cursor->y;
|
||||||
|
cursor->previous.node = node;
|
||||||
|
|
||||||
struct sway_node *node = node_at_coords(seat,
|
|
||||||
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
|
||||||
if (node && config->focus_follows_mouse && allow_refocusing) {
|
if (node && config->focus_follows_mouse && allow_refocusing) {
|
||||||
struct sway_node *focus = seat_get_focus(seat);
|
struct sway_node *focus = seat_get_focus(seat);
|
||||||
if (focus && node->type == N_WORKSPACE) {
|
if (focus && node->type == N_WORKSPACE) {
|
||||||
|
|
|
@ -369,6 +369,13 @@ struct sway_container *container_at(struct sway_workspace *workspace,
|
||||||
}
|
}
|
||||||
// If focused is floating, focused view's non-popups
|
// If focused is floating, focused view's non-popups
|
||||||
if (focus && focus->view && is_floating) {
|
if (focus && focus->view && is_floating) {
|
||||||
|
// only switch to unfocused container if focused container has no menus open
|
||||||
|
bool has_subsurfaces = wl_list_length(&focus->view->surface->subsurfaces) > 0;
|
||||||
|
c = floating_container_at(lx, ly, surface, sx, sy);
|
||||||
|
if (!has_subsurfaces && c && c->view && *surface && c != focus) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
surface_at_view(focus, lx, ly, surface, sx, sy);
|
surface_at_view(focus, lx, ly, surface, sx, sy);
|
||||||
if (*surface) {
|
if (*surface) {
|
||||||
return focus;
|
return focus;
|
||||||
|
|
Loading…
Reference in a new issue