diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-16 22:18:12 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-16 22:18:12 +1000 |
commit | fc2484095a71206fe82f5042c0d127458a8da3bc (patch) | |
tree | c1d10d53e34eac84a7083db3591de17c5fdcf16e /sway/tree/view.c | |
parent | Merge pull request #2282 from RyanDwyer/fix-tab-split-focus (diff) | |
download | sway-fc2484095a71206fe82f5042c0d127458a8da3bc.tar.gz sway-fc2484095a71206fe82f5042c0d127458a8da3bc.tar.zst sway-fc2484095a71206fe82f5042c0d127458a8da3bc.zip |
Implement no_focus command
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index bf380d98..bc66a701 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -518,6 +518,26 @@ void view_execute_criteria(struct sway_view *view) { | |||
518 | seat_set_focus(seat, prior_focus); | 518 | seat_set_focus(seat, prior_focus); |
519 | } | 519 | } |
520 | 520 | ||
521 | static bool should_focus(struct sway_view *view) { | ||
522 | // If the view is the only one in the focused workspace, it'll get focus | ||
523 | // regardless of any no_focus criteria. | ||
524 | struct sway_container *parent = view->swayc->parent; | ||
525 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
526 | if (parent->type == C_WORKSPACE && seat_get_focus(seat) == parent) { | ||
527 | size_t num_children = parent->children->length + | ||
528 | parent->sway_workspace->floating->children->length; | ||
529 | if (num_children == 1) { | ||
530 | return true; | ||
531 | } | ||
532 | } | ||
533 | |||
534 | // Check no_focus criteria | ||
535 | list_t *criterias = criteria_for_view(view, CT_NO_FOCUS); | ||
536 | size_t len = criterias->length; | ||
537 | list_free(criterias); | ||
538 | return len == 0; | ||
539 | } | ||
540 | |||
521 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | 541 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { |
522 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { | 542 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { |
523 | return; | 543 | return; |
@@ -571,9 +591,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
571 | view_set_tiled(view, true); | 591 | view_set_tiled(view, true); |
572 | } | 592 | } |
573 | 593 | ||
574 | input_manager_set_focus(input_manager, cont); | 594 | if (should_focus(view)) { |
575 | if (workspace) { | 595 | input_manager_set_focus(input_manager, cont); |
576 | workspace_switch(workspace); | 596 | if (workspace) { |
597 | workspace_switch(workspace); | ||
598 | } | ||
577 | } | 599 | } |
578 | 600 | ||
579 | view_update_title(view, false); | 601 | view_update_title(view, false); |