diff options
author | 2016-07-31 18:10:33 -0400 | |
---|---|---|
committer | 2016-07-31 18:10:33 -0400 | |
commit | f78d07d39bb4e401920efb1396cb85d9cadd8adf (patch) | |
tree | 2c53f09455cebea9bf5af0eb5bfaff7858b37efe /sway/border.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/border.c')
-rw-r--r-- | sway/border.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/sway/border.c b/sway/border.c index c1a62bc6..c3e1004a 100644 --- a/sway/border.c +++ b/sway/border.c | |||
@@ -308,6 +308,9 @@ void update_view_border(swayc_t *view) { | |||
308 | swayc_t *focused = get_focused_view(&root_container); | 308 | swayc_t *focused = get_focused_view(&root_container); |
309 | swayc_t *container = swayc_parent_by_type(view, C_CONTAINER); | 309 | swayc_t *container = swayc_parent_by_type(view, C_CONTAINER); |
310 | swayc_t *focused_inactive = NULL; | 310 | swayc_t *focused_inactive = NULL; |
311 | |||
312 | bool is_child_of_focused = swayc_is_parent_of(get_focused_container(&root_container), view); | ||
313 | |||
311 | if (container) { | 314 | if (container) { |
312 | focused_inactive = swayc_focus_by_type(container, C_VIEW); | 315 | focused_inactive = swayc_focus_by_type(container, C_VIEW); |
313 | } else { | 316 | } else { |
@@ -334,7 +337,7 @@ void update_view_border(swayc_t *view) { | |||
334 | cr = create_border_buffer(view, g, &surface); | 337 | cr = create_border_buffer(view, g, &surface); |
335 | 338 | ||
336 | bool render_top = !should_hide_top_border(view, view->y); | 339 | bool render_top = !should_hide_top_border(view, view->y); |
337 | if (view == focused) { | 340 | if (view == focused || is_child_of_focused) { |
338 | render_borders(view, cr, &config->border_colors.focused, render_top); | 341 | render_borders(view, cr, &config->border_colors.focused, render_top); |
339 | } else { | 342 | } else { |
340 | render_borders(view, cr, &config->border_colors.focused_inactive, render_top); | 343 | render_borders(view, cr, &config->border_colors.focused_inactive, render_top); |
@@ -360,7 +363,7 @@ void update_view_border(swayc_t *view) { | |||
360 | break; | 363 | break; |
361 | } | 364 | } |
362 | 365 | ||
363 | if (focused == view) { | 366 | if (focused == view || is_child_of_focused) { |
364 | render_borders(view, cr, &config->border_colors.focused, true); | 367 | render_borders(view, cr, &config->border_colors.focused, true); |
365 | } else if (focused_inactive == view) { | 368 | } else if (focused_inactive == view) { |
366 | render_borders(view, cr, &config->border_colors.focused_inactive, true); | 369 | render_borders(view, cr, &config->border_colors.focused_inactive, true); |
@@ -375,7 +378,7 @@ void update_view_border(swayc_t *view) { | |||
375 | break; | 378 | break; |
376 | } | 379 | } |
377 | 380 | ||
378 | if (focused == view) { | 381 | if (focused == view || is_child_of_focused) { |
379 | render_borders(view, cr, &config->border_colors.focused, false); | 382 | render_borders(view, cr, &config->border_colors.focused, false); |
380 | render_title_bar(view, cr, &view->border_geometry, | 383 | render_title_bar(view, cr, &view->border_geometry, |
381 | &config->border_colors.focused); | 384 | &config->border_colors.focused); |
@@ -403,6 +406,17 @@ void update_view_border(swayc_t *view) { | |||
403 | } | 406 | } |
404 | } | 407 | } |
405 | 408 | ||
409 | void update_container_border(swayc_t *container) { | ||
410 | if (container->type == C_VIEW) { | ||
411 | update_view_border(container); | ||
412 | return; | ||
413 | } else { | ||
414 | for (int i = 0; i < container->children->length; ++i) { | ||
415 | update_container_border(container->children->items[i]); | ||
416 | } | ||
417 | } | ||
418 | } | ||
419 | |||
406 | void render_view_borders(wlc_handle view) { | 420 | void render_view_borders(wlc_handle view) { |
407 | swayc_t *c = swayc_by_handle(view); | 421 | swayc_t *c = swayc_by_handle(view); |
408 | 422 | ||