diff options
-rw-r--r-- | include/sway/input/seat.h | 8 | ||||
-rw-r--r-- | sway/input/seat.c | 45 | ||||
-rw-r--r-- | sway/tree/layout.c | 4 |
3 files changed, 33 insertions, 24 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index c7be58b5..05fff6f7 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h | |||
@@ -87,8 +87,12 @@ struct sway_container *seat_get_focus(struct sway_seat *seat); | |||
87 | struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, | 87 | struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, |
88 | struct sway_container *container); | 88 | struct sway_container *container); |
89 | 89 | ||
90 | struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, | 90 | /** |
91 | struct sway_container *container, enum sway_container_type type); | 91 | * Descend into the focus stack to find the focus-inactive view. Useful for |
92 | * container placement when they change position in the tree. | ||
93 | */ | ||
94 | struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat, | ||
95 | struct sway_container *container); | ||
92 | 96 | ||
93 | void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config); | 97 | void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config); |
94 | 98 | ||
diff --git a/sway/input/seat.c b/sway/input/seat.c index b94e3291..1a646715 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -86,6 +86,31 @@ static void seat_send_focus(struct sway_seat *seat, | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | static struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, | ||
90 | struct sway_container *container, enum sway_container_type type) { | ||
91 | if (container->type == C_VIEW || container->children->length == 0) { | ||
92 | return container; | ||
93 | } | ||
94 | |||
95 | struct sway_seat_container *current = NULL; | ||
96 | wl_list_for_each(current, &seat->focus_stack, link) { | ||
97 | if (current->container->type != type && type != C_TYPES) { | ||
98 | continue; | ||
99 | } | ||
100 | |||
101 | if (container_has_child(container, current->container)) { | ||
102 | return current->container; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | return NULL; | ||
107 | } | ||
108 | |||
109 | struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat, | ||
110 | struct sway_container *container) { | ||
111 | return seat_get_focus_by_type(seat, container, C_VIEW); | ||
112 | } | ||
113 | |||
89 | static void handle_seat_container_destroy(struct wl_listener *listener, | 114 | static void handle_seat_container_destroy(struct wl_listener *listener, |
90 | void *data) { | 115 | void *data) { |
91 | struct sway_seat_container *seat_con = | 116 | struct sway_seat_container *seat_con = |
@@ -549,26 +574,6 @@ struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { | |||
549 | return seat_get_focus_inactive(seat, &root_container); | 574 | return seat_get_focus_inactive(seat, &root_container); |
550 | } | 575 | } |
551 | 576 | ||
552 | struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, | ||
553 | struct sway_container *container, enum sway_container_type type) { | ||
554 | if (container->type == C_VIEW || container->children->length == 0) { | ||
555 | return container; | ||
556 | } | ||
557 | |||
558 | struct sway_seat_container *current = NULL; | ||
559 | wl_list_for_each(current, &seat->focus_stack, link) { | ||
560 | if (current->container->type != type && type != C_TYPES) { | ||
561 | continue; | ||
562 | } | ||
563 | |||
564 | if (container_has_child(container, current->container)) { | ||
565 | return current->container; | ||
566 | } | ||
567 | } | ||
568 | |||
569 | return NULL; | ||
570 | } | ||
571 | |||
572 | struct sway_container *seat_get_focus(struct sway_seat *seat) { | 577 | struct sway_container *seat_get_focus(struct sway_seat *seat) { |
573 | if (!seat->has_focus) { | 578 | if (!seat->has_focus) { |
574 | return NULL; | 579 | return NULL; |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index e81facc6..ce4457b1 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -872,7 +872,7 @@ struct sway_container *container_get_in_direction( | |||
872 | } | 872 | } |
873 | if (next->children && next->children->length) { | 873 | if (next->children && next->children->length) { |
874 | // TODO consider floating children as well | 874 | // TODO consider floating children as well |
875 | return seat_get_focus_by_type(seat, next, C_VIEW); | 875 | return seat_get_focus_inactive_view(seat, next); |
876 | } else { | 876 | } else { |
877 | return next; | 877 | return next; |
878 | } | 878 | } |
@@ -910,7 +910,7 @@ struct sway_container *container_get_in_direction( | |||
910 | wlr_log(L_DEBUG, | 910 | wlr_log(L_DEBUG, |
911 | "cont %d-%p dir %i sibling %d: %p", idx, | 911 | "cont %d-%p dir %i sibling %d: %p", idx, |
912 | container, dir, desired, desired_con); | 912 | container, dir, desired, desired_con); |
913 | struct sway_container *next = seat_get_focus_by_type(seat, desired_con, C_VIEW); | 913 | struct sway_container *next = seat_get_focus_inactive_view(seat, desired_con); |
914 | return next; | 914 | return next; |
915 | } | 915 | } |
916 | } | 916 | } |