mirror of
https://github.com/NickHu/sway
synced 2024-12-28 22:23:30 +01:00
Merge pull request #811 from acrisci/feature/focus-container
Implement focus handling for containers
This commit is contained in:
commit
2d907ef1f6
6 changed files with 52 additions and 34 deletions
|
@ -16,8 +16,12 @@ struct border {
|
||||||
*/
|
*/
|
||||||
void border_clear(struct border *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 render_view_borders(wlc_handle view);
|
||||||
void update_view_border(swayc_t *view);
|
|
||||||
void map_update_view_border(swayc_t *view, void *data);
|
void map_update_view_border(swayc_t *view, void *data);
|
||||||
int get_font_text_height(const char *font);
|
int get_font_text_height(const char *font);
|
||||||
bool should_hide_top_border(swayc_t *con, double y);
|
bool should_hide_top_border(swayc_t *con, double y);
|
||||||
|
|
|
@ -201,12 +201,6 @@ static void render_title_bar(swayc_t *view, cairo_t *cr, struct wlc_geometry *b,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void map_update_view_border(swayc_t *view, void *data) {
|
|
||||||
if (view->type == C_VIEW) {
|
|
||||||
update_view_border(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate nested container title for tabbed/stacked layouts
|
* Generate nested container title for tabbed/stacked layouts
|
||||||
*/
|
*/
|
||||||
|
@ -293,7 +287,7 @@ void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_view_border(swayc_t *view) {
|
static void update_view_border(swayc_t *view) {
|
||||||
if (!view->visible) {
|
if (!view->visible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -308,6 +302,9 @@ void update_view_border(swayc_t *view) {
|
||||||
swayc_t *focused = get_focused_view(&root_container);
|
swayc_t *focused = get_focused_view(&root_container);
|
||||||
swayc_t *container = swayc_parent_by_type(view, C_CONTAINER);
|
swayc_t *container = swayc_parent_by_type(view, C_CONTAINER);
|
||||||
swayc_t *focused_inactive = NULL;
|
swayc_t *focused_inactive = NULL;
|
||||||
|
|
||||||
|
bool is_child_of_focused = swayc_is_parent_of(get_focused_container(&root_container), view);
|
||||||
|
|
||||||
if (container) {
|
if (container) {
|
||||||
focused_inactive = swayc_focus_by_type(container, C_VIEW);
|
focused_inactive = swayc_focus_by_type(container, C_VIEW);
|
||||||
} else {
|
} else {
|
||||||
|
@ -334,7 +331,7 @@ void update_view_border(swayc_t *view) {
|
||||||
cr = create_border_buffer(view, g, &surface);
|
cr = create_border_buffer(view, g, &surface);
|
||||||
|
|
||||||
bool render_top = !should_hide_top_border(view, view->y);
|
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);
|
render_borders(view, cr, &config->border_colors.focused, render_top);
|
||||||
} else {
|
} else {
|
||||||
render_borders(view, cr, &config->border_colors.focused_inactive, render_top);
|
render_borders(view, cr, &config->border_colors.focused_inactive, render_top);
|
||||||
|
@ -360,7 +357,7 @@ void update_view_border(swayc_t *view) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focused == view) {
|
if (focused == view || is_child_of_focused) {
|
||||||
render_borders(view, cr, &config->border_colors.focused, true);
|
render_borders(view, cr, &config->border_colors.focused, true);
|
||||||
} else if (focused_inactive == view) {
|
} else if (focused_inactive == view) {
|
||||||
render_borders(view, cr, &config->border_colors.focused_inactive, true);
|
render_borders(view, cr, &config->border_colors.focused_inactive, true);
|
||||||
|
@ -375,7 +372,7 @@ void update_view_border(swayc_t *view) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focused == view) {
|
if (focused == view || is_child_of_focused) {
|
||||||
render_borders(view, cr, &config->border_colors.focused, false);
|
render_borders(view, cr, &config->border_colors.focused, false);
|
||||||
render_title_bar(view, cr, &view->border_geometry,
|
render_title_bar(view, cr, &view->border_geometry,
|
||||||
&config->border_colors.focused);
|
&config->border_colors.focused);
|
||||||
|
@ -403,6 +400,23 @@ 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 map_update_view_border(swayc_t *view, void *data) {
|
||||||
|
if (view->type == C_VIEW) {
|
||||||
|
update_view_border(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void render_view_borders(wlc_handle view) {
|
void render_view_borders(wlc_handle view) {
|
||||||
swayc_t *c = swayc_by_handle(view);
|
swayc_t *c = swayc_by_handle(view);
|
||||||
|
|
||||||
|
|
|
@ -2340,7 +2340,7 @@ static struct cmd_results *_do_split(int argc, char **argv, int layout) {
|
||||||
|
|
||||||
// update container title if tabbed/stacked
|
// update container title if tabbed/stacked
|
||||||
if (swayc_tabbed_stacked_ancestor(focused)) {
|
if (swayc_tabbed_stacked_ancestor(focused)) {
|
||||||
update_view_border(focused);
|
update_container_border(focused);
|
||||||
swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT);
|
swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT);
|
||||||
// schedule render to make changes take effect right away,
|
// schedule render to make changes take effect right away,
|
||||||
// otherwise we would have to wait for the view to render,
|
// otherwise we would have to wait for the view to render,
|
||||||
|
|
30
sway/focus.c
30
sway/focus.c
|
@ -115,7 +115,7 @@ bool set_focused_container(swayc_t *c) {
|
||||||
|
|
||||||
// Get workspace for c, get that workspaces current focused container.
|
// Get workspace for c, get that workspaces current focused container.
|
||||||
swayc_t *workspace = swayc_active_workspace_for(c);
|
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 (swayc_is_fullscreen(focused) && focused != c) {
|
||||||
// if switching to a workspace with a fullscreen view,
|
// if switching to a workspace with a fullscreen view,
|
||||||
|
@ -140,35 +140,35 @@ bool set_focused_container(swayc_t *c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get new focused view and set focus to it.
|
// get new focused view and set focus to it.
|
||||||
p = get_focused_view(c);
|
if (c->type == C_CONTAINER || (c->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP))) {
|
||||||
if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) {
|
|
||||||
// unactivate previous focus
|
// unactivate previous focus
|
||||||
if (focused->type == C_VIEW) {
|
if (focused->type == C_VIEW) {
|
||||||
wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false);
|
wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false);
|
||||||
update_view_border(focused);
|
|
||||||
}
|
}
|
||||||
|
update_container_border(focused);
|
||||||
// activate current focus
|
// activate current focus
|
||||||
if (p->type == C_VIEW) {
|
if (c->type == C_VIEW) {
|
||||||
wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true);
|
wlc_view_set_state(c->handle, WLC_BIT_ACTIVATED, true);
|
||||||
// set focus if view_focus is unlocked
|
}
|
||||||
if (!locked_view_focus) {
|
// set focus if view_focus is unlocked
|
||||||
wlc_view_focus(p->handle);
|
if (!locked_view_focus) {
|
||||||
if (p->parent->layout != L_TABBED
|
wlc_view_focus(c->handle);
|
||||||
&& p->parent->layout != L_STACKED) {
|
if (c->parent->layout != L_TABBED
|
||||||
update_view_border(p);
|
&& c->parent->layout != L_STACKED) {
|
||||||
}
|
update_container_border(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rearrange if parent container is tabbed/stacked
|
// 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) {
|
if (parent != NULL) {
|
||||||
arrange_backgrounds();
|
arrange_backgrounds();
|
||||||
arrange_windows(parent, -1, -1);
|
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
|
// remove previous focus if view_focus is unlocked
|
||||||
if (!locked_view_focus) {
|
if (!locked_view_focus) {
|
||||||
|
update_container_border(c);
|
||||||
wlc_view_focus(0);
|
wlc_view_focus(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,7 +415,7 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
// we were on one workspace, switched to another to add this view,
|
// we were on one workspace, switched to another to add this view,
|
||||||
// now let's return to where we were
|
// now let's return to where we were
|
||||||
workspace_switch(current_ws);
|
workspace_switch(current_ws);
|
||||||
set_focused_container(current_ws->focused);
|
set_focused_container(get_focused_container(current_ws));
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend_workspace_cleanup = false;
|
suspend_workspace_cleanup = false;
|
||||||
|
@ -553,9 +553,9 @@ static void handle_view_properties_updated(wlc_handle view, uint32_t mask) {
|
||||||
swayc_t *p = swayc_tabbed_stacked_ancestor(c);
|
swayc_t *p = swayc_tabbed_stacked_ancestor(c);
|
||||||
if (p) {
|
if (p) {
|
||||||
// TODO: we only got the topmost tabbed/stacked container, update borders of all containers on the path
|
// TODO: we only got the topmost tabbed/stacked container, update borders of all containers on the path
|
||||||
update_view_border(get_focused_view(p));
|
update_container_border(get_focused_view(p));
|
||||||
} else if (c->border_type == B_NORMAL) {
|
} else if (c->border_type == B_NORMAL) {
|
||||||
update_view_border(c);
|
update_container_border(c);
|
||||||
}
|
}
|
||||||
ipc_event_window(c, "title");
|
ipc_event_window(c, "title");
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,7 +441,7 @@ static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geo
|
||||||
c->border_geometry = g;
|
c->border_geometry = g;
|
||||||
*geometry = c->actual_geometry;
|
*geometry = c->actual_geometry;
|
||||||
|
|
||||||
update_view_border(c);
|
update_container_border(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) {
|
void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) {
|
||||||
|
@ -688,7 +688,7 @@ void update_geometry(swayc_t *container) {
|
||||||
container->actual_geometry = geometry;
|
container->actual_geometry = geometry;
|
||||||
|
|
||||||
if (container->type == C_VIEW) {
|
if (container->type == C_VIEW) {
|
||||||
update_view_border(container);
|
update_container_border(container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,7 +867,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
// update focused view border last because it may
|
// update focused view border last because it may
|
||||||
// depend on the title bar geometry of its siblings.
|
// depend on the title bar geometry of its siblings.
|
||||||
if (focused && container->children->length > 1) {
|
if (focused && container->children->length > 1) {
|
||||||
update_view_border(focused);
|
update_container_border(focused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -911,7 +911,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
// update focused view border last because it may
|
// update focused view border last because it may
|
||||||
// depend on the title bar geometry of its siblings.
|
// depend on the title bar geometry of its siblings.
|
||||||
if (focused && container->children->length > 1) {
|
if (focused && container->children->length > 1) {
|
||||||
update_view_border(focused);
|
update_container_border(focused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue