tree/container: prevent floating windows from inheriting workspace focus

When switching to an empty workspace, the workspace itself receives
keyboard focus. Previously, being children of the workspace, unfocused
floating sticky windows would inherit this visual focus state and render
with active titlebars and borders, despite not having keyboard focus.

This change ensures floating windows are excluded from inheriting a
workspace's visual focus state.
This commit is contained in:
Scott Leggett 2026-05-27 01:08:09 +08:00
parent f1b40bc288
commit e14176106d
No known key found for this signature in database

View file

@ -126,6 +126,17 @@ static bool container_is_focused(struct sway_container *con, void *data) {
return con->current.focused; return con->current.focused;
} }
static bool container_is_current_floating(struct sway_container *container) {
if (!container->current.parent && container->current.workspace &&
list_find(container->current.workspace->floating, container) != -1) {
return true;
}
if (container->scratchpad) {
return true;
}
return false;
}
static bool container_has_focused_child(struct sway_container *con) { static bool container_has_focused_child(struct sway_container *con) {
return container_find_child(con, container_is_focused, NULL); return container_find_child(con, container_is_focused, NULL);
} }
@ -134,7 +145,7 @@ static bool container_is_current_parent_focused(struct sway_container *con) {
if (con->current.parent) { if (con->current.parent) {
struct sway_container *parent = con->current.parent; struct sway_container *parent = con->current.parent;
return parent->current.focused || container_is_current_parent_focused(parent); return parent->current.focused || container_is_current_parent_focused(parent);
} else if (con->current.workspace) { } else if (con->current.workspace && !container_is_current_floating(con)) {
struct sway_workspace *ws = con->current.workspace; struct sway_workspace *ws = con->current.workspace;
return ws->current.focused; return ws->current.focused;
} }
@ -173,17 +184,6 @@ static struct border_colors *container_get_current_colors(
return colors; return colors;
} }
static bool container_is_current_floating(struct sway_container *container) {
if (!container->current.parent && container->current.workspace &&
list_find(container->current.workspace->floating, container) != -1) {
return true;
}
if (container->scratchpad) {
return true;
}
return false;
}
// scene rect wants premultiplied colors // scene rect wants premultiplied colors
static void scene_rect_set_color(struct wlr_scene_rect *rect, static void scene_rect_set_color(struct wlr_scene_rect *rect,
const float color[4], float opacity) { const float color[4], float opacity) {