From 298ccb539c5f9d538e49364f45e57ff0d88df717 Mon Sep 17 00:00:00 2001 From: Jonathan Buch Date: Tue, 25 Sep 2018 10:22:50 +0200 Subject: Add configuration for raising containers on focus * New configuration option: raise_floating (From the discussion on https://github.com/i3/i3/issues/2990) * By default, it still raises the window on focus, otherwise it will raise the window on click. --- sway/input/seat.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'sway/input') diff --git a/sway/input/seat.c b/sway/input/seat.c index 69bee47e..c747eafc 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -734,7 +734,7 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, // If we've focused a floating container, bring it to the front. // We do this by putting it at the end of the floating list. - if (container) { + if (container && config->raise_floating) { struct sway_container *floater = container; while (floater->parent) { floater = floater->parent; @@ -1017,6 +1017,19 @@ void seat_begin_down(struct sway_seat *seat, struct sway_container *con, seat->op_ref_con_lx = sx; seat->op_ref_con_ly = sy; seat->op_moved = false; + + // If we've focused a floating container, bring it to the front. + // We do this by putting it at the end of the floating list. + if (con && !config->raise_floating) { + struct sway_container *floater = con; + while (floater->parent) { + floater = floater->parent; + } + if (container_is_floating(floater)) { + list_move_to_end(floater->workspace->floating, floater); + node_set_dirty(&floater->workspace->node); + } + } } void seat_begin_move_floating(struct sway_seat *seat, -- cgit v1.2.3 From ec713125c6593b3671dc54e41b90333b42783dff Mon Sep 17 00:00:00 2001 From: Jonathan Buch Date: Tue, 25 Sep 2018 10:29:58 +0200 Subject: Simplify raising a container in seat * Factor out raising a floating window into s separate function to enable reuse. --- sway/input/seat.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'sway/input') diff --git a/sway/input/seat.c b/sway/input/seat.c index c747eafc..15c56a43 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -606,6 +606,18 @@ static int handle_urgent_timeout(void *data) { return 0; } +static void container_raise_floating(struct sway_container *con) { + // Bring container to front by putting it at the end of the floating list. + struct sway_container *floater = con; + while (floater->parent) { + floater = floater->parent; + } + if (container_is_floating(floater)) { + list_move_to_end(floater->workspace->floating, floater); + node_set_dirty(&floater->workspace->node); + } +} + void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, bool warp, bool notify) { if (seat->focused_layer) { @@ -733,16 +745,8 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, } // If we've focused a floating container, bring it to the front. - // We do this by putting it at the end of the floating list. if (container && config->raise_floating) { - struct sway_container *floater = container; - while (floater->parent) { - floater = floater->parent; - } - if (container_is_floating(floater)) { - list_move_to_end(floater->workspace->floating, floater); - node_set_dirty(&floater->workspace->node); - } + container_raise_floating(container); } if (last_focus) { @@ -1018,17 +1022,9 @@ void seat_begin_down(struct sway_seat *seat, struct sway_container *con, seat->op_ref_con_ly = sy; seat->op_moved = false; - // If we've focused a floating container, bring it to the front. - // We do this by putting it at the end of the floating list. + // In case the container was not raised by gaining focus, raise on click if (con && !config->raise_floating) { - struct sway_container *floater = con; - while (floater->parent) { - floater = floater->parent; - } - if (container_is_floating(floater)) { - list_move_to_end(floater->workspace->floating, floater); - node_set_dirty(&floater->workspace->node); - } + container_raise_floating(con); } } -- cgit v1.2.3 From 7727d54faf2939e30f82da562de83dbcda1749db Mon Sep 17 00:00:00 2001 From: Jonathan Buch Date: Thu, 27 Sep 2018 18:32:55 +0200 Subject: 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. --- include/sway/input/cursor.h | 1 + sway/input/cursor.c | 10 +++++----- sway/tree/container.c | 7 +++++++ 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'sway/input') diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 7ec45120..4d47ab42 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -10,6 +10,7 @@ struct sway_cursor { struct wlr_cursor *cursor; struct { double x, y; + struct sway_node *node; } previous; struct wlr_xcursor_manager *xcursor_manager; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index afad6f6f..3c62acb9 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -567,15 +567,15 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, struct wlr_surface *surface = NULL; double sx, sy; - // Find the node beneath the pointer's previous position - struct sway_node *prev_node = node_at_coords(seat, - cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); + struct sway_node *prev_node = cursor->previous.node; + struct sway_node *node = node_at_coords(seat, + cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + // Update the stored previous position cursor->previous.x = cursor->cursor->x; 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) { struct sway_node *focus = seat_get_focus(seat); if (focus && node->type == N_WORKSPACE) { diff --git a/sway/tree/container.c b/sway/tree/container.c index a069b177..f9ddf3d6 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -369,6 +369,13 @@ struct sway_container *container_at(struct sway_workspace *workspace, } // If focused is floating, focused view's non-popups 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); if (*surface) { return focus; -- cgit v1.2.3