diff options
author | 2016-07-31 18:10:33 -0400 | |
---|---|---|
committer | 2016-07-31 18:10:33 -0400 | |
commit | f78d07d39bb4e401920efb1396cb85d9cadd8adf (patch) | |
tree | 2c53f09455cebea9bf5af0eb5bfaff7858b37efe /sway/focus.c | |
parent | Merge pull request #808 from zandrmartin/document-kill-command (diff) | |
download | sway-f78d07d39bb4e401920efb1396cb85d9cadd8adf.tar.gz sway-f78d07d39bb4e401920efb1396cb85d9cadd8adf.tar.zst sway-f78d07d39bb4e401920efb1396cb85d9cadd8adf.zip |
Implement focus handling for containers
The previous implementation of focus handling assumed that only views can be
focused. Containers can also be focused with a command like `focus parent` or
`focus child`.
Change `set_focused_container()` to handle the case of the given container
being a container with children and update borders accordingly.
Diffstat (limited to 'sway/focus.c')
-rw-r--r-- | sway/focus.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/sway/focus.c b/sway/focus.c index 0f629e1e..576a5e9b 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -115,7 +115,7 @@ bool set_focused_container(swayc_t *c) { | |||
115 | 115 | ||
116 | // Get workspace for c, get that workspaces current focused container. | 116 | // Get workspace for c, get that workspaces current focused container. |
117 | swayc_t *workspace = swayc_active_workspace_for(c); | 117 | swayc_t *workspace = swayc_active_workspace_for(c); |
118 | swayc_t *focused = get_focused_view(workspace); | 118 | swayc_t *focused = get_focused_container(workspace); |
119 | 119 | ||
120 | if (swayc_is_fullscreen(focused) && focused != c) { | 120 | if (swayc_is_fullscreen(focused) && focused != c) { |
121 | // if switching to a workspace with a fullscreen view, | 121 | // if switching to a workspace with a fullscreen view, |
@@ -140,33 +140,32 @@ bool set_focused_container(swayc_t *c) { | |||
140 | } | 140 | } |
141 | 141 | ||
142 | // get new focused view and set focus to it. | 142 | // get new focused view and set focus to it. |
143 | p = get_focused_view(c); | 143 | if (c->type == C_CONTAINER || (c->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP))) { |
144 | if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { | ||
145 | // unactivate previous focus | 144 | // unactivate previous focus |
146 | if (focused->type == C_VIEW) { | 145 | if (focused->type == C_VIEW) { |
147 | wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false); | 146 | wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false); |
148 | update_view_border(focused); | ||
149 | } | 147 | } |
148 | update_container_border(focused); | ||
150 | // activate current focus | 149 | // activate current focus |
151 | if (p->type == C_VIEW) { | 150 | if (c->type == C_VIEW) { |
152 | wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); | 151 | wlc_view_set_state(c->handle, WLC_BIT_ACTIVATED, true); |
153 | // set focus if view_focus is unlocked | 152 | } |
154 | if (!locked_view_focus) { | 153 | // set focus if view_focus is unlocked |
155 | wlc_view_focus(p->handle); | 154 | if (!locked_view_focus) { |
156 | if (p->parent->layout != L_TABBED | 155 | wlc_view_focus(c->handle); |
157 | && p->parent->layout != L_STACKED) { | 156 | if (c->parent->layout != L_TABBED |
158 | update_view_border(p); | 157 | && c->parent->layout != L_STACKED) { |
159 | } | 158 | update_container_border(c); |
160 | } | 159 | } |
161 | } | 160 | } |
162 | 161 | ||
163 | // rearrange if parent container is tabbed/stacked | 162 | // rearrange if parent container is tabbed/stacked |
164 | swayc_t *parent = swayc_tabbed_stacked_ancestor(p); | 163 | swayc_t *parent = swayc_tabbed_stacked_ancestor(c); |
165 | if (parent != NULL) { | 164 | if (parent != NULL) { |
166 | arrange_backgrounds(); | 165 | arrange_backgrounds(); |
167 | arrange_windows(parent, -1, -1); | 166 | arrange_windows(parent, -1, -1); |
168 | } | 167 | } |
169 | } else if (p->type == C_WORKSPACE) { | 168 | } else if (c->type == C_WORKSPACE) { |
170 | // remove previous focus if view_focus is unlocked | 169 | // remove previous focus if view_focus is unlocked |
171 | if (!locked_view_focus) { | 170 | if (!locked_view_focus) { |
172 | wlc_view_focus(0); | 171 | wlc_view_focus(0); |