aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/tree/container.h12
-rw-r--r--sway/commands/floating.c2
-rw-r--r--sway/commands/layout.c10
-rw-r--r--sway/commands/sticky.c2
-rw-r--r--sway/criteria.c4
-rw-r--r--sway/desktop/output.c2
-rw-r--r--sway/desktop/xdg_shell.c2
-rw-r--r--sway/desktop/xdg_shell_v6.c2
-rw-r--r--sway/desktop/xwayland.c4
-rw-r--r--sway/tree/container.c24
-rw-r--r--sway/tree/layout.c4
-rw-r--r--sway/tree/view.c12
12 files changed, 44 insertions, 36 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 906088f0..71935697 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -76,8 +76,6 @@ struct sway_container {
76 enum sway_container_layout layout; 76 enum sway_container_layout layout;
77 enum sway_container_layout prev_layout; 77 enum sway_container_layout prev_layout;
78 78
79 // Saves us from searching the list of children/floating in the parent
80 bool is_floating;
81 bool is_sticky; 79 bool is_sticky;
82 80
83 // For C_ROOT, this has no meaning 81 // For C_ROOT, this has no meaning
@@ -243,8 +241,14 @@ void container_set_floating(struct sway_container *container, bool enable);
243void container_set_geometry_from_view(struct sway_container *container); 241void container_set_geometry_from_view(struct sway_container *container);
244 242
245/** 243/**
246 * Determine if the given container is itself floating or has a floating 244 * Determine if the given container is itself floating.
247 * ancestor. 245 * This will return false for any descendants of a floating container.
246 */
247bool container_is_floating(struct sway_container *container);
248
249/**
250 * Determine if the given container is itself floating or is a child of a
251 * floating container.
248 */ 252 */
249bool container_self_or_parent_floating(struct sway_container *container); 253bool container_self_or_parent_floating(struct sway_container *container);
250 254
diff --git a/sway/commands/floating.c b/sway/commands/floating.c
index 38a4e1da..46b761da 100644
--- a/sway/commands/floating.c
+++ b/sway/commands/floating.c
@@ -28,7 +28,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
28 } else if (strcasecmp(argv[0], "disable") == 0) { 28 } else if (strcasecmp(argv[0], "disable") == 0) {
29 wants_floating = false; 29 wants_floating = false;
30 } else if (strcasecmp(argv[0], "toggle") == 0) { 30 } else if (strcasecmp(argv[0], "toggle") == 0) {
31 wants_floating = !container->is_floating; 31 wants_floating = !container_is_floating(container);
32 } else { 32 } else {
33 return cmd_results_new(CMD_FAILURE, "floating", 33 return cmd_results_new(CMD_FAILURE, "floating",
34 "Expected 'floating <enable|disable|toggle>'"); 34 "Expected 'floating <enable|disable|toggle>'");
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
index 6b44b001..a009e38f 100644
--- a/sway/commands/layout.c
+++ b/sway/commands/layout.c
@@ -12,19 +12,15 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
12 } 12 }
13 struct sway_container *parent = config->handler_context.current_container; 13 struct sway_container *parent = config->handler_context.current_container;
14 14
15 // TODO: floating 15 if (container_is_floating(parent)) {
16 /* 16 return cmd_results_new(CMD_FAILURE, "layout",
17 if (parent->is_floating) { 17 "Unable to change layout of floating windows");
18 return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows");
19 } 18 }
20 */
21 19
22 while (parent->type == C_VIEW) { 20 while (parent->type == C_VIEW) {
23 parent = parent->parent; 21 parent = parent->parent;
24 } 22 }
25 23
26 // TODO: stacks and tabs
27
28 if (strcasecmp(argv[0], "default") == 0) { 24 if (strcasecmp(argv[0], "default") == 0) {
29 parent->layout = parent->prev_layout; 25 parent->layout = parent->prev_layout;
30 if (parent->layout == L_NONE) { 26 if (parent->layout == L_NONE) {
diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c
index 4bb4bd39..732ccb98 100644
--- a/sway/commands/sticky.c
+++ b/sway/commands/sticky.c
@@ -17,7 +17,7 @@ struct cmd_results *cmd_sticky(int argc, char **argv) {
17 } 17 }
18 struct sway_container *container = 18 struct sway_container *container =
19 config->handler_context.current_container; 19 config->handler_context.current_container;
20 if (!container->is_floating) { 20 if (!container_is_floating(container)) {
21 return cmd_results_new(CMD_FAILURE, "sticky", 21 return cmd_results_new(CMD_FAILURE, "sticky",
22 "Can't set sticky on a tiled container"); 22 "Can't set sticky on a tiled container");
23 } 23 }
diff --git a/sway/criteria.c b/sway/criteria.c
index e97b12f8..a263485a 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -121,13 +121,13 @@ static bool criteria_matches_view(struct criteria *criteria,
121 } 121 }
122 122
123 if (criteria->floating) { 123 if (criteria->floating) {
124 if (!view->swayc->is_floating) { 124 if (!container_is_floating(view->swayc)) {
125 return false; 125 return false;
126 } 126 }
127 } 127 }
128 128
129 if (criteria->tiling) { 129 if (criteria->tiling) {
130 if (view->swayc->is_floating) { 130 if (container_is_floating(view->swayc)) {
131 return false; 131 return false;
132 } 132 }
133 } 133 }
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index e91be4d4..4e5d106f 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -1147,7 +1147,7 @@ void output_damage_whole_container(struct sway_output *output,
1147 .width = con->width, 1147 .width = con->width,
1148 .height = con->height, 1148 .height = con->height,
1149 }; 1149 };
1150 if (con->is_floating) { 1150 if (container_is_floating(con)) {
1151 box.x -= output->wlr_output->lx; 1151 box.x -= output->wlr_output->lx;
1152 box.y -= output->wlr_output->ly; 1152 box.y -= output->wlr_output->ly;
1153 } 1153 }
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index e1a73b20..ebb12211 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -185,7 +185,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
185 view->natural_width = geometry->width; 185 view->natural_width = geometry->width;
186 view->natural_height = geometry->height; 186 view->natural_height = geometry->height;
187 } 187 }
188 if (view->swayc && view->swayc->is_floating) { 188 if (view->swayc && container_is_floating(view->swayc)) {
189 view_update_size(view, geometry->width, geometry->height); 189 view_update_size(view, geometry->width, geometry->height);
190 } else { 190 } else {
191 view_update_size(view, xdg_shell_view->pending_width, 191 view_update_size(view, xdg_shell_view->pending_width,
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 47e4162a..f3df2fe8 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -184,7 +184,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
184 view->natural_width = geometry->width; 184 view->natural_width = geometry->width;
185 view->natural_height = geometry->height; 185 view->natural_height = geometry->height;
186 } 186 }
187 if (view->swayc && view->swayc->is_floating) { 187 if (view->swayc && container_is_floating(view->swayc)) {
188 view_update_size(view, geometry->width, geometry->height); 188 view_update_size(view, geometry->width, geometry->height);
189 } else { 189 } else {
190 view_update_size(view, xdg_shell_v6_view->pending_width, 190 view_update_size(view, xdg_shell_v6_view->pending_width,
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 56cac1bd..1373d968 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -163,7 +163,7 @@ static void configure(struct sway_view *view, double x, double y, int width,
163 struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; 163 struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
164 164
165 double lx, ly; 165 double lx, ly;
166 if (view->swayc->is_floating) { 166 if (container_is_floating(view->swayc)) {
167 lx = x; 167 lx = x;
168 ly = y; 168 ly = y;
169 } else { 169 } else {
@@ -288,7 +288,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
288 view->natural_width = xsurface->width; 288 view->natural_width = xsurface->width;
289 view->natural_height = xsurface->height; 289 view->natural_height = xsurface->height;
290 } 290 }
291 if (view->swayc && view->swayc->is_floating) { 291 if (view->swayc && container_is_floating(view->swayc)) {
292 view_update_size(view, xsurface->width, xsurface->height); 292 view_update_size(view, xsurface->width, xsurface->height);
293 view_update_position(view, xsurface->x, xsurface->y); 293 view_update_position(view, xsurface->x, xsurface->y);
294 } else { 294 } else {
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 17d29d92..c16f1748 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -924,7 +924,7 @@ static void configure_floating_view(struct sway_view *view) {
924} 924}
925 925
926void container_set_floating(struct sway_container *container, bool enable) { 926void container_set_floating(struct sway_container *container, bool enable) {
927 if (container->is_floating == enable) { 927 if (container_is_floating(container) == enable) {
928 return; 928 return;
929 } 929 }
930 930
@@ -935,7 +935,6 @@ void container_set_floating(struct sway_container *container, bool enable) {
935 if (enable) { 935 if (enable) {
936 container_remove_child(container); 936 container_remove_child(container);
937 container_add_child(workspace->sway_workspace->floating, container); 937 container_add_child(workspace->sway_workspace->floating, container);
938 container->is_floating = true;
939 if (container->type == C_VIEW) { 938 if (container->type == C_VIEW) {
940 configure_floating_view(container->sway_view); 939 configure_floating_view(container->sway_view);
941 } 940 }
@@ -950,7 +949,6 @@ void container_set_floating(struct sway_container *container, bool enable) {
950 if (container->type == C_VIEW) { 949 if (container->type == C_VIEW) {
951 view_set_maximized(container->sway_view, true); 950 view_set_maximized(container->sway_view, true);
952 } 951 }
953 container->is_floating = false;
954 container->is_sticky = false; 952 container->is_sticky = false;
955 container_reap_empty_recursive(workspace->sway_workspace->floating); 953 container_reap_empty_recursive(workspace->sway_workspace->floating);
956 } 954 }
@@ -962,7 +960,8 @@ void container_set_geometry_from_view(struct sway_container *container) {
962 if (!sway_assert(container->type == C_VIEW, "Expected a view")) { 960 if (!sway_assert(container->type == C_VIEW, "Expected a view")) {
963 return; 961 return;
964 } 962 }
965 if (!sway_assert(container->is_floating, "Expected a floating view")) { 963 if (!sway_assert(container_is_floating(container),
964 "Expected a floating view")) {
966 return; 965 return;
967 } 966 }
968 struct sway_view *view = container->sway_view; 967 struct sway_view *view = container->sway_view;
@@ -977,9 +976,18 @@ void container_set_geometry_from_view(struct sway_container *container) {
977} 976}
978 977
979bool container_self_or_parent_floating(struct sway_container *container) { 978bool container_self_or_parent_floating(struct sway_container *container) {
980 while (container->parent->type != C_WORKSPACE 979 struct sway_container *workspace = container_parent(container, C_WORKSPACE);
981 && container->parent->parent->type != C_WORKSPACE) { 980 if (!workspace) {
982 container = container->parent; 981 return false;
982 }
983 return container_has_anscestor(container,
984 workspace->sway_workspace->floating);
985}
986
987bool container_is_floating(struct sway_container *container) {
988 struct sway_container *workspace = container_parent(container, C_WORKSPACE);
989 if (!workspace) {
990 return false;
983 } 991 }
984 return container->is_floating; 992 return container->parent == workspace->sway_workspace->floating;
985} 993}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 59ad0b53..28775253 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -154,7 +154,7 @@ void container_move_to(struct sway_container *container,
154 || container_has_ancestor(container, destination)) { 154 || container_has_ancestor(container, destination)) {
155 return; 155 return;
156 } 156 }
157 if (container->is_floating) { 157 if (container_is_floating(container)) {
158 // TODO 158 // TODO
159 return; 159 return;
160 } 160 }
@@ -718,7 +718,7 @@ struct sway_container *container_get_in_direction(
718 enum movement_direction dir) { 718 enum movement_direction dir) {
719 struct sway_container *parent = container->parent; 719 struct sway_container *parent = container->parent;
720 720
721 if (container->is_floating) { 721 if (container_is_floating(container)) {
722 return NULL; 722 return NULL;
723 } 723 }
724 724
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 651a2be6..8548d9b8 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -458,7 +458,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
458 } 458 }
459 // If we're about to launch the view into the floating container, then 459 // If we're about to launch the view into the floating container, then
460 // launch it as a tiled view in the root of the workspace instead. 460 // launch it as a tiled view in the root of the workspace instead.
461 if (focus->is_floating) { 461 if (container_is_floating(focus)) {
462 focus = focus->parent->parent; 462 focus = focus->parent->parent;
463 } 463 }
464 free(criterias); 464 free(criterias);
@@ -531,7 +531,7 @@ void view_unmap(struct sway_view *view) {
531} 531}
532 532
533void view_update_position(struct sway_view *view, double lx, double ly) { 533void view_update_position(struct sway_view *view, double lx, double ly) {
534 if (!view->swayc->is_floating) { 534 if (!container_is_floating(view->swayc)) {
535 return; 535 return;
536 } 536 }
537 container_damage_whole(view->swayc); 537 container_damage_whole(view->swayc);
@@ -548,7 +548,7 @@ void view_update_size(struct sway_view *view, int width, int height) {
548 container_damage_whole(view->swayc); 548 container_damage_whole(view->swayc);
549 view->width = width; 549 view->width = width;
550 view->height = height; 550 view->height = height;
551 if (view->swayc->is_floating) { 551 if (container_is_floating(view->swayc)) {
552 container_set_geometry_from_view(view->swayc); 552 container_set_geometry_from_view(view->swayc);
553 } 553 }
554 container_damage_whole(view->swayc); 554 container_damage_whole(view->swayc);
@@ -904,15 +904,15 @@ bool view_is_visible(struct sway_view *view) {
904 container_parent(view->swayc, C_WORKSPACE); 904 container_parent(view->swayc, C_WORKSPACE);
905 // Determine if view is nested inside a floating container which is sticky. 905 // Determine if view is nested inside a floating container which is sticky.
906 // A simple floating view will have this ancestry: 906 // A simple floating view will have this ancestry:
907 // C_VIEW (is_floating=true) -> floating -> workspace 907 // C_VIEW -> floating -> workspace
908 // A more complex ancestry could be: 908 // A more complex ancestry could be:
909 // C_VIEW -> C_CONTAINER (tabbed and is_floating) -> floating -> workspace 909 // C_VIEW -> C_CONTAINER (tabbed) -> floating -> workspace
910 struct sway_container *floater = view->swayc; 910 struct sway_container *floater = view->swayc;
911 while (floater->parent->type != C_WORKSPACE 911 while (floater->parent->type != C_WORKSPACE
912 && floater->parent->parent->type != C_WORKSPACE) { 912 && floater->parent->parent->type != C_WORKSPACE) {
913 floater = floater->parent; 913 floater = floater->parent;
914 } 914 }
915 bool is_sticky = floater->is_floating && floater->is_sticky; 915 bool is_sticky = container_is_floating(floater) && floater->is_sticky;
916 // Check view isn't in a tabbed or stacked container on an inactive tab 916 // Check view isn't in a tabbed or stacked container on an inactive tab
917 struct sway_seat *seat = input_manager_current_seat(input_manager); 917 struct sway_seat *seat = input_manager_current_seat(input_manager);
918 struct sway_container *container = view->swayc; 918 struct sway_container *container = view->swayc;