mirror of
https://github.com/swaywm/sway.git
synced 2024-11-16 13:13:17 +00:00
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.
This commit is contained in:
parent
a947cb6919
commit
f78d07d39b
|
@ -16,6 +16,11 @@ struct border {
|
|||
*/
|
||||
void border_clear(struct border *border);
|
||||
|
||||
/**
|
||||
* Recursively update all of the borders within a container.
|
||||
*/
|
||||
void update_container_border(swayc_t *container);
|
||||
|
||||
void render_view_borders(wlc_handle view);
|
||||
void update_view_border(swayc_t *view);
|
||||
void map_update_view_border(swayc_t *view, void *data);
|
||||
|
|
|
@ -308,6 +308,9 @@ void update_view_border(swayc_t *view) {
|
|||
swayc_t *focused = get_focused_view(&root_container);
|
||||
swayc_t *container = swayc_parent_by_type(view, C_CONTAINER);
|
||||
swayc_t *focused_inactive = NULL;
|
||||
|
||||
bool is_child_of_focused = swayc_is_parent_of(get_focused_container(&root_container), view);
|
||||
|
||||
if (container) {
|
||||
focused_inactive = swayc_focus_by_type(container, C_VIEW);
|
||||
} else {
|
||||
|
@ -334,7 +337,7 @@ void update_view_border(swayc_t *view) {
|
|||
cr = create_border_buffer(view, g, &surface);
|
||||
|
||||
bool render_top = !should_hide_top_border(view, view->y);
|
||||
if (view == focused) {
|
||||
if (view == focused || is_child_of_focused) {
|
||||
render_borders(view, cr, &config->border_colors.focused, render_top);
|
||||
} else {
|
||||
render_borders(view, cr, &config->border_colors.focused_inactive, render_top);
|
||||
|
@ -360,7 +363,7 @@ void update_view_border(swayc_t *view) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (focused == view) {
|
||||
if (focused == view || is_child_of_focused) {
|
||||
render_borders(view, cr, &config->border_colors.focused, true);
|
||||
} else if (focused_inactive == view) {
|
||||
render_borders(view, cr, &config->border_colors.focused_inactive, true);
|
||||
|
@ -375,7 +378,7 @@ void update_view_border(swayc_t *view) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (focused == view) {
|
||||
if (focused == view || is_child_of_focused) {
|
||||
render_borders(view, cr, &config->border_colors.focused, false);
|
||||
render_title_bar(view, cr, &view->border_geometry,
|
||||
&config->border_colors.focused);
|
||||
|
@ -403,6 +406,17 @@ void update_view_border(swayc_t *view) {
|
|||
}
|
||||
}
|
||||
|
||||
void update_container_border(swayc_t *container) {
|
||||
if (container->type == C_VIEW) {
|
||||
update_view_border(container);
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < container->children->length; ++i) {
|
||||
update_container_border(container->children->items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void render_view_borders(wlc_handle view) {
|
||||
swayc_t *c = swayc_by_handle(view);
|
||||
|
||||
|
|
25
sway/focus.c
25
sway/focus.c
|
@ -115,7 +115,7 @@ bool set_focused_container(swayc_t *c) {
|
|||
|
||||
// Get workspace for c, get that workspaces current focused container.
|
||||
swayc_t *workspace = swayc_active_workspace_for(c);
|
||||
swayc_t *focused = get_focused_view(workspace);
|
||||
swayc_t *focused = get_focused_container(workspace);
|
||||
|
||||
if (swayc_is_fullscreen(focused) && focused != c) {
|
||||
// if switching to a workspace with a fullscreen view,
|
||||
|
@ -140,33 +140,32 @@ bool set_focused_container(swayc_t *c) {
|
|||
}
|
||||
|
||||
// get new focused view and set focus to it.
|
||||
p = get_focused_view(c);
|
||||
if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) {
|
||||
if (c->type == C_CONTAINER || (c->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP))) {
|
||||
// unactivate previous focus
|
||||
if (focused->type == C_VIEW) {
|
||||
wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false);
|
||||
update_view_border(focused);
|
||||
}
|
||||
update_container_border(focused);
|
||||
// activate current focus
|
||||
if (p->type == C_VIEW) {
|
||||
wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true);
|
||||
if (c->type == C_VIEW) {
|
||||
wlc_view_set_state(c->handle, WLC_BIT_ACTIVATED, true);
|
||||
}
|
||||
// set focus if view_focus is unlocked
|
||||
if (!locked_view_focus) {
|
||||
wlc_view_focus(p->handle);
|
||||
if (p->parent->layout != L_TABBED
|
||||
&& p->parent->layout != L_STACKED) {
|
||||
update_view_border(p);
|
||||
}
|
||||
wlc_view_focus(c->handle);
|
||||
if (c->parent->layout != L_TABBED
|
||||
&& c->parent->layout != L_STACKED) {
|
||||
update_container_border(c);
|
||||
}
|
||||
}
|
||||
|
||||
// rearrange if parent container is tabbed/stacked
|
||||
swayc_t *parent = swayc_tabbed_stacked_ancestor(p);
|
||||
swayc_t *parent = swayc_tabbed_stacked_ancestor(c);
|
||||
if (parent != NULL) {
|
||||
arrange_backgrounds();
|
||||
arrange_windows(parent, -1, -1);
|
||||
}
|
||||
} else if (p->type == C_WORKSPACE) {
|
||||
} else if (c->type == C_WORKSPACE) {
|
||||
// remove previous focus if view_focus is unlocked
|
||||
if (!locked_view_focus) {
|
||||
wlc_view_focus(0);
|
||||
|
|
Loading…
Reference in a new issue