When scrolling on a tab titlebar, set focus_inactive if not focused

For example, create layout H[view T[view view view]], focus the view in
the hsplit and scroll the mouse wheel over the tab title bars. Prior to
this patch, focus would be given to a descendant of the tabbed
container. This patch keeps the focus on the hsplit view.

This also renames some of the variables used in this part of the code to
make it be easier to follow.
This commit is contained in:
Ryan Dwyer 2018-10-24 23:51:11 +10:00
parent 46fc4ba4e3
commit 641fbe576e

View file

@ -996,8 +996,9 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
if (on_titlebar) { if (on_titlebar) {
enum sway_container_layout layout = container_parent_layout(cont); enum sway_container_layout layout = container_parent_layout(cont);
if (layout == L_TABBED || layout == L_STACKED) { if (layout == L_TABBED || layout == L_STACKED) {
struct sway_node *tabcontainer = node_get_parent(node);
struct sway_node *active = struct sway_node *active =
seat_get_active_tiling_child(seat, node_get_parent(node)); seat_get_active_tiling_child(seat, tabcontainer);
list_t *siblings = container_get_siblings(cont); list_t *siblings = container_get_siblings(cont);
int desired = list_find(siblings, active->sway_container) + int desired = list_find(siblings, active->sway_container) +
event->delta_discrete; event->delta_discrete;
@ -1006,9 +1007,19 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
} else if (desired >= siblings->length) { } else if (desired >= siblings->length) {
desired = siblings->length - 1; desired = siblings->length - 1;
} }
struct sway_container *new_focus = siblings->items[desired]; struct sway_node *old_focus = seat_get_focus(seat);
node = seat_get_focus_inactive(seat, &new_focus->node); struct sway_container *new_sibling_con = siblings->items[desired];
seat_set_focus(seat, node); struct sway_node *new_sibling = &new_sibling_con->node;
struct sway_node *new_focus =
seat_get_focus_inactive(seat, new_sibling);
if (node_has_ancestor(old_focus, tabcontainer)) {
seat_set_focus(seat, new_focus);
} else {
// Scrolling when focus is not in the tabbed container at all
seat_set_raw_focus(seat, new_sibling);
seat_set_raw_focus(seat, new_focus);
seat_set_raw_focus(seat, old_focus);
}
return; return;
} }
} }