mirror of
https://github.com/swaywm/sway.git
synced 2024-11-11 04:54:14 +01:00
Replace is_floating boolean with function
This commit is contained in:
parent
34f35f0bad
commit
aaba7642b3
@ -76,8 +76,6 @@ struct sway_container {
|
||||
enum sway_container_layout layout;
|
||||
enum sway_container_layout prev_layout;
|
||||
|
||||
// Saves us from searching the list of children/floating in the parent
|
||||
bool is_floating;
|
||||
bool is_sticky;
|
||||
|
||||
// For C_ROOT, this has no meaning
|
||||
@ -243,8 +241,14 @@ void container_set_floating(struct sway_container *container, bool enable);
|
||||
void container_set_geometry_from_view(struct sway_container *container);
|
||||
|
||||
/**
|
||||
* Determine if the given container is itself floating or has a floating
|
||||
* ancestor.
|
||||
* Determine if the given container is itself floating.
|
||||
* This will return false for any descendants of a floating container.
|
||||
*/
|
||||
bool container_is_floating(struct sway_container *container);
|
||||
|
||||
/**
|
||||
* Determine if the given container is itself floating or is a child of a
|
||||
* floating container.
|
||||
*/
|
||||
bool container_self_or_parent_floating(struct sway_container *container);
|
||||
|
||||
|
@ -28,7 +28,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
|
||||
} else if (strcasecmp(argv[0], "disable") == 0) {
|
||||
wants_floating = false;
|
||||
} else if (strcasecmp(argv[0], "toggle") == 0) {
|
||||
wants_floating = !container->is_floating;
|
||||
wants_floating = !container_is_floating(container);
|
||||
} else {
|
||||
return cmd_results_new(CMD_FAILURE, "floating",
|
||||
"Expected 'floating <enable|disable|toggle>'");
|
||||
|
@ -12,19 +12,15 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
|
||||
}
|
||||
struct sway_container *parent = config->handler_context.current_container;
|
||||
|
||||
// TODO: floating
|
||||
/*
|
||||
if (parent->is_floating) {
|
||||
return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows");
|
||||
if (container_is_floating(parent)) {
|
||||
return cmd_results_new(CMD_FAILURE, "layout",
|
||||
"Unable to change layout of floating windows");
|
||||
}
|
||||
*/
|
||||
|
||||
while (parent->type == C_VIEW) {
|
||||
parent = parent->parent;
|
||||
}
|
||||
|
||||
// TODO: stacks and tabs
|
||||
|
||||
if (strcasecmp(argv[0], "default") == 0) {
|
||||
parent->layout = parent->prev_layout;
|
||||
if (parent->layout == L_NONE) {
|
||||
|
@ -17,7 +17,7 @@ struct cmd_results *cmd_sticky(int argc, char **argv) {
|
||||
}
|
||||
struct sway_container *container =
|
||||
config->handler_context.current_container;
|
||||
if (!container->is_floating) {
|
||||
if (!container_is_floating(container)) {
|
||||
return cmd_results_new(CMD_FAILURE, "sticky",
|
||||
"Can't set sticky on a tiled container");
|
||||
}
|
||||
|
@ -121,13 +121,13 @@ static bool criteria_matches_view(struct criteria *criteria,
|
||||
}
|
||||
|
||||
if (criteria->floating) {
|
||||
if (!view->swayc->is_floating) {
|
||||
if (!container_is_floating(view->swayc)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (criteria->tiling) {
|
||||
if (view->swayc->is_floating) {
|
||||
if (container_is_floating(view->swayc)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1147,7 +1147,7 @@ void output_damage_whole_container(struct sway_output *output,
|
||||
.width = con->width,
|
||||
.height = con->height,
|
||||
};
|
||||
if (con->is_floating) {
|
||||
if (container_is_floating(con)) {
|
||||
box.x -= output->wlr_output->lx;
|
||||
box.y -= output->wlr_output->ly;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
view->natural_width = geometry->width;
|
||||
view->natural_height = geometry->height;
|
||||
}
|
||||
if (view->swayc && view->swayc->is_floating) {
|
||||
if (view->swayc && container_is_floating(view->swayc)) {
|
||||
view_update_size(view, geometry->width, geometry->height);
|
||||
} else {
|
||||
view_update_size(view, xdg_shell_view->pending_width,
|
||||
|
@ -184,7 +184,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
view->natural_width = geometry->width;
|
||||
view->natural_height = geometry->height;
|
||||
}
|
||||
if (view->swayc && view->swayc->is_floating) {
|
||||
if (view->swayc && container_is_floating(view->swayc)) {
|
||||
view_update_size(view, geometry->width, geometry->height);
|
||||
} else {
|
||||
view_update_size(view, xdg_shell_v6_view->pending_width,
|
||||
|
@ -163,7 +163,7 @@ static void configure(struct sway_view *view, double x, double y, int width,
|
||||
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
|
||||
|
||||
double lx, ly;
|
||||
if (view->swayc->is_floating) {
|
||||
if (container_is_floating(view->swayc)) {
|
||||
lx = x;
|
||||
ly = y;
|
||||
} else {
|
||||
@ -288,7 +288,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
view->natural_width = xsurface->width;
|
||||
view->natural_height = xsurface->height;
|
||||
}
|
||||
if (view->swayc && view->swayc->is_floating) {
|
||||
if (view->swayc && container_is_floating(view->swayc)) {
|
||||
view_update_size(view, xsurface->width, xsurface->height);
|
||||
view_update_position(view, xsurface->x, xsurface->y);
|
||||
} else {
|
||||
|
@ -924,7 +924,7 @@ static void configure_floating_view(struct sway_view *view) {
|
||||
}
|
||||
|
||||
void container_set_floating(struct sway_container *container, bool enable) {
|
||||
if (container->is_floating == enable) {
|
||||
if (container_is_floating(container) == enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -935,7 +935,6 @@ void container_set_floating(struct sway_container *container, bool enable) {
|
||||
if (enable) {
|
||||
container_remove_child(container);
|
||||
container_add_child(workspace->sway_workspace->floating, container);
|
||||
container->is_floating = true;
|
||||
if (container->type == C_VIEW) {
|
||||
configure_floating_view(container->sway_view);
|
||||
}
|
||||
@ -950,7 +949,6 @@ void container_set_floating(struct sway_container *container, bool enable) {
|
||||
if (container->type == C_VIEW) {
|
||||
view_set_maximized(container->sway_view, true);
|
||||
}
|
||||
container->is_floating = false;
|
||||
container->is_sticky = false;
|
||||
container_reap_empty_recursive(workspace->sway_workspace->floating);
|
||||
}
|
||||
@ -962,7 +960,8 @@ void container_set_geometry_from_view(struct sway_container *container) {
|
||||
if (!sway_assert(container->type == C_VIEW, "Expected a view")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(container->is_floating, "Expected a floating view")) {
|
||||
if (!sway_assert(container_is_floating(container),
|
||||
"Expected a floating view")) {
|
||||
return;
|
||||
}
|
||||
struct sway_view *view = container->sway_view;
|
||||
@ -977,9 +976,18 @@ void container_set_geometry_from_view(struct sway_container *container) {
|
||||
}
|
||||
|
||||
bool container_self_or_parent_floating(struct sway_container *container) {
|
||||
while (container->parent->type != C_WORKSPACE
|
||||
&& container->parent->parent->type != C_WORKSPACE) {
|
||||
container = container->parent;
|
||||
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
|
||||
if (!workspace) {
|
||||
return false;
|
||||
}
|
||||
return container->is_floating;
|
||||
return container_has_anscestor(container,
|
||||
workspace->sway_workspace->floating);
|
||||
}
|
||||
|
||||
bool container_is_floating(struct sway_container *container) {
|
||||
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
|
||||
if (!workspace) {
|
||||
return false;
|
||||
}
|
||||
return container->parent == workspace->sway_workspace->floating;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ void container_move_to(struct sway_container *container,
|
||||
|| container_has_ancestor(container, destination)) {
|
||||
return;
|
||||
}
|
||||
if (container->is_floating) {
|
||||
if (container_is_floating(container)) {
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
@ -718,7 +718,7 @@ struct sway_container *container_get_in_direction(
|
||||
enum movement_direction dir) {
|
||||
struct sway_container *parent = container->parent;
|
||||
|
||||
if (container->is_floating) {
|
||||
if (container_is_floating(container)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -458,7 +458,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
||||
}
|
||||
// If we're about to launch the view into the floating container, then
|
||||
// launch it as a tiled view in the root of the workspace instead.
|
||||
if (focus->is_floating) {
|
||||
if (container_is_floating(focus)) {
|
||||
focus = focus->parent->parent;
|
||||
}
|
||||
free(criterias);
|
||||
@ -531,7 +531,7 @@ void view_unmap(struct sway_view *view) {
|
||||
}
|
||||
|
||||
void view_update_position(struct sway_view *view, double lx, double ly) {
|
||||
if (!view->swayc->is_floating) {
|
||||
if (!container_is_floating(view->swayc)) {
|
||||
return;
|
||||
}
|
||||
container_damage_whole(view->swayc);
|
||||
@ -548,7 +548,7 @@ void view_update_size(struct sway_view *view, int width, int height) {
|
||||
container_damage_whole(view->swayc);
|
||||
view->width = width;
|
||||
view->height = height;
|
||||
if (view->swayc->is_floating) {
|
||||
if (container_is_floating(view->swayc)) {
|
||||
container_set_geometry_from_view(view->swayc);
|
||||
}
|
||||
container_damage_whole(view->swayc);
|
||||
@ -904,15 +904,15 @@ bool view_is_visible(struct sway_view *view) {
|
||||
container_parent(view->swayc, C_WORKSPACE);
|
||||
// Determine if view is nested inside a floating container which is sticky.
|
||||
// A simple floating view will have this ancestry:
|
||||
// C_VIEW (is_floating=true) -> floating -> workspace
|
||||
// C_VIEW -> floating -> workspace
|
||||
// A more complex ancestry could be:
|
||||
// C_VIEW -> C_CONTAINER (tabbed and is_floating) -> floating -> workspace
|
||||
// C_VIEW -> C_CONTAINER (tabbed) -> floating -> workspace
|
||||
struct sway_container *floater = view->swayc;
|
||||
while (floater->parent->type != C_WORKSPACE
|
||||
&& floater->parent->parent->type != C_WORKSPACE) {
|
||||
floater = floater->parent;
|
||||
}
|
||||
bool is_sticky = floater->is_floating && floater->is_sticky;
|
||||
bool is_sticky = container_is_floating(floater) && floater->is_sticky;
|
||||
// Check view isn't in a tabbed or stacked container on an inactive tab
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *container = view->swayc;
|
||||
|
Loading…
Reference in New Issue
Block a user