aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seat.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r--sway/input/seat.c74
1 files changed, 53 insertions, 21 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 7b01fe88..467e5087 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -87,6 +87,45 @@ static void seat_send_focus(struct sway_seat *seat,
87 } 87 }
88} 88}
89 89
90static struct sway_container *seat_get_focus_by_type(struct sway_seat *seat,
91 struct sway_container *container, enum sway_container_type type) {
92 if (container->type == C_VIEW || container->children->length == 0) {
93 return container;
94 }
95
96 struct sway_seat_container *current = NULL;
97 wl_list_for_each(current, &seat->focus_stack, link) {
98 if (current->container->type != type && type != C_TYPES) {
99 continue;
100 }
101
102 if (container_has_child(container, current->container)) {
103 return current->container;
104 }
105 }
106
107 return NULL;
108}
109
110void seat_focus_inactive_children_for_each(struct sway_seat *seat,
111 struct sway_container *container,
112 void (*f)(struct sway_container *container, void *data), void *data) {
113 struct sway_seat_container *current = NULL;
114 wl_list_for_each(current, &seat->focus_stack, link) {
115 if (current->container->parent == NULL) {
116 continue;
117 }
118 if (current->container->parent == container) {
119 f(current->container, data);
120 }
121 }
122}
123
124struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat,
125 struct sway_container *container) {
126 return seat_get_focus_by_type(seat, container, C_VIEW);
127}
128
90static void handle_seat_container_destroy(struct wl_listener *listener, 129static void handle_seat_container_destroy(struct wl_listener *listener,
91 void *data) { 130 void *data) {
92 struct sway_seat_container *seat_con = 131 struct sway_seat_container *seat_con =
@@ -412,10 +451,23 @@ void seat_set_focus_warp(struct sway_seat *seat,
412 if (container) { 451 if (container) {
413 struct sway_seat_container *seat_con = 452 struct sway_seat_container *seat_con =
414 seat_container_from_container(seat, container); 453 seat_container_from_container(seat, container);
415 if (!seat_con) { 454 if (seat_con == NULL) {
416 return; 455 return;
417 } 456 }
418 457
458 // put all the anscestors of this container on top of the focus stack
459 struct sway_seat_container *parent =
460 seat_container_from_container(seat,
461 seat_con->container->parent);
462 while (parent) {
463 wl_list_remove(&parent->link);
464 wl_list_insert(&seat->focus_stack, &parent->link);
465
466 parent =
467 seat_container_from_container(seat,
468 parent->container->parent);
469 }
470
419 wl_list_remove(&seat_con->link); 471 wl_list_remove(&seat_con->link);
420 wl_list_insert(&seat->focus_stack, &seat_con->link); 472 wl_list_insert(&seat->focus_stack, &seat_con->link);
421 473
@@ -590,26 +642,6 @@ struct sway_container *sway_seat_get_focus(struct sway_seat *seat) {
590 return seat_get_focus_inactive(seat, &root_container); 642 return seat_get_focus_inactive(seat, &root_container);
591} 643}
592 644
593struct sway_container *seat_get_focus_by_type(struct sway_seat *seat,
594 struct sway_container *container, enum sway_container_type type) {
595 if (container->type == C_VIEW || container->children->length == 0) {
596 return container;
597 }
598
599 struct sway_seat_container *current = NULL;
600 wl_list_for_each(current, &seat->focus_stack, link) {
601 if (current->container->type != type && type != C_TYPES) {
602 continue;
603 }
604
605 if (container_has_child(container, current->container)) {
606 return current->container;
607 }
608 }
609
610 return NULL;
611}
612
613struct sway_container *seat_get_focus(struct sway_seat *seat) { 645struct sway_container *seat_get_focus(struct sway_seat *seat) {
614 if (!seat->has_focus) { 646 if (!seat->has_focus) {
615 return NULL; 647 return NULL;