aboutsummaryrefslogtreecommitdiffstats
path: root/sway/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/sway/layout.c b/sway/layout.c
index 2195863e..377dad47 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -252,18 +252,31 @@ void swap_geometry(swayc_t *a, swayc_t *b) {
252 252
253void move_container(swayc_t *container, enum movement_direction dir) { 253void move_container(swayc_t *container, enum movement_direction dir) {
254 enum swayc_layouts layout = L_NONE; 254 enum swayc_layouts layout = L_NONE;
255 if (container->is_floating 255 swayc_t *parent = container->parent;
256 || (container->type != C_VIEW && container->type != C_CONTAINER)) { 256 if (container->is_floating || (container->type != C_VIEW && container->type != C_CONTAINER)) {
257 return; 257 return;
258 } 258 }
259 if (dir == MOVE_UP || dir == MOVE_DOWN) { 259 if (dir == MOVE_UP || dir == MOVE_DOWN) {
260 layout = L_VERT; 260 layout = L_VERT;
261 } else if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { 261 } else if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
262 layout = L_HORIZ; 262 layout = L_HORIZ;
263 } else if (dir == MOVE_FIRST) {
264 // swap first child in auto layout with currently focused child
265 if (is_auto_layout(parent->layout)) {
266 int focused_idx = index_child(container);
267 swayc_t *first = parent->children->items[0];
268 if (focused_idx > 0) {
269 list_swap(parent->children, 0, focused_idx);
270 swap_geometry(first, container);
271 }
272 arrange_windows(parent->parent, -1, -1);
273 ipc_event_window(container, "move");
274 set_focused_container_for(parent->parent, container);
275 }
276 return;
263 } else if (! (dir == MOVE_NEXT || dir == MOVE_PREV)) { 277 } else if (! (dir == MOVE_NEXT || dir == MOVE_PREV)) {
264 return; 278 return;
265 } 279 }
266 swayc_t *parent = container->parent;
267 swayc_t *child = container; 280 swayc_t *child = container;
268 bool ascended = false; 281 bool ascended = false;
269 282
@@ -309,14 +322,14 @@ void move_container(swayc_t *container, enum movement_direction dir) {
309 // if move command makes container change from master to slave 322 // if move command makes container change from master to slave
310 // (or the contrary), reset its geometry an the one of the replaced item. 323 // (or the contrary), reset its geometry an the one of the replaced item.
311 if (parent->nb_master && 324 if (parent->nb_master &&
312 (uint_fast32_t) parent->children->length > parent->nb_master) { 325 (size_t) parent->children->length > parent->nb_master) {
313 swayc_t *swap_geom = NULL; 326 swayc_t *swap_geom = NULL;
314 // if child is being promoted/demoted, it will swap geometry 327 // if child is being promoted/demoted, it will swap geometry
315 // with the sibling being demoted/promoted. 328 // with the sibling being demoted/promoted.
316 if ((dir == MOVE_NEXT && desired == 0) 329 if ((dir == MOVE_NEXT && desired == 0)
317 || (dir == MOVE_PREV && (uint_fast32_t) desired == parent->nb_master - 1)) { 330 || (dir == MOVE_PREV && (size_t) desired == parent->nb_master - 1)) {
318 swap_geom = parent->children->items[parent->nb_master - 1]; 331 swap_geom = parent->children->items[parent->nb_master - 1];
319 } else if ((dir == MOVE_NEXT && (uint_fast32_t) desired == parent->nb_master) 332 } else if ((dir == MOVE_NEXT && (size_t) desired == parent->nb_master)
320 || (dir == MOVE_PREV && desired == parent->children->length - 1)) { 333 || (dir == MOVE_PREV && desired == parent->children->length - 1)) {
321 swap_geom = parent->children->items[parent->nb_master]; 334 swap_geom = parent->children->items[parent->nb_master];
322 } 335 }
@@ -812,16 +825,16 @@ void update_geometry(swayc_t *container) {
812 * Layout application prototypes 825 * Layout application prototypes
813 */ 826 */
814static void apply_horiz_layout(swayc_t *container, const double x, 827static void apply_horiz_layout(swayc_t *container, const double x,
815 const double y, const double width, 828 const double y, const double width,
816 const double height, const int start, 829 const double height, const int start,
817 const int end); 830 const int end);
818static void apply_vert_layout(swayc_t *container, const double x, 831static void apply_vert_layout(swayc_t *container, const double x,
819 const double y, const double width, 832 const double y, const double width,
820 const double height, const int start, 833 const double height, const int start,
821 const int end); 834 const int end);
822static void apply_tabbed_or_stacked_layout(swayc_t *container, double x, 835static void apply_tabbed_or_stacked_layout(swayc_t *container, double x,
823 double y, double width, 836 double y, double width,
824 double height); 837 double height);
825 838
826static void apply_auto_layout(swayc_t *container, const double x, const double y, 839static void apply_auto_layout(swayc_t *container, const double x, const double y,
827 const double width, const double height, 840 const double width, const double height,
@@ -1150,8 +1163,8 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1150 // a single slave group (containing slave 1 and 2). The master 1163 // a single slave group (containing slave 1 and 2). The master
1151 // group and slave group are layed out using L_VERT. 1164 // group and slave group are layed out using L_VERT.
1152 1165
1153 uint_fast32_t nb_slaves = container->children->length - container->nb_master; 1166 size_t nb_slaves = container->children->length - container->nb_master;
1154 uint_fast32_t nb_groups = (container->nb_master > 0 ? 1 : 0) + 1167 size_t nb_groups = (container->nb_master > 0 ? 1 : 0) +
1155 MIN(container->nb_slave_groups, nb_slaves); 1168 MIN(container->nb_slave_groups, nb_slaves);
1156 1169
1157 // the target dimension of the container along the "major" axis, each 1170 // the target dimension of the container along the "major" axis, each
@@ -1172,9 +1185,9 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1172 // height and width of next group to be laid out. 1185 // height and width of next group to be laid out.
1173 const double *group_h, *group_w; 1186 const double *group_h, *group_w;
1174 1187
1175 switch(group_layout) { 1188 switch (group_layout) {
1176 default: 1189 default:
1177 sway_log(L_ERROR, "Unknown layout type (%d) used in %s()", 1190 sway_log(L_DEBUG, "Unknown layout type (%d) used in %s()",
1178 group_layout, __func__); 1191 group_layout, __func__);
1179 /* fall through */ 1192 /* fall through */
1180 case L_VERT: 1193 case L_VERT:
@@ -1202,7 +1215,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1202 * layout. */ 1215 * layout. */
1203 double old_group_dim[nb_groups]; 1216 double old_group_dim[nb_groups];
1204 double old_dim = 0; 1217 double old_dim = 0;
1205 uint_fast32_t group = 0; 1218 size_t group = 0;
1206 for (int i = 0; i < container->children->length;) { 1219 for (int i = 0; i < container->children->length;) {
1207 swayc_t *child = container->children->items[i]; 1220 swayc_t *child = container->children->items[i];
1208 double *dim = group_layout == L_HORIZ ? &child->height : &child->width; 1221 double *dim = group_layout == L_HORIZ ? &child->height : &child->width;
@@ -1238,7 +1251,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1238 1251
1239 for (group = 0; group < nb_groups; ++group) { 1252 for (group = 0; group < nb_groups; ++group) {
1240 // column to include next by increasing position. 1253 // column to include next by increasing position.
1241 uint_fast32_t layout_group = master_first ? group : (group + 1) % nb_groups; 1254 size_t layout_group = master_first ? group : (group + 1) % nb_groups;
1242 1255
1243 // adjusted size of the group 1256 // adjusted size of the group
1244 group_dim = old_group_dim[layout_group] * scale; 1257 group_dim = old_group_dim[layout_group] * scale;
@@ -1256,8 +1269,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1256 if (group == nb_groups - 1) { 1269 if (group == nb_groups - 1) {
1257 group_dim = pos_maj + dim_maj - pos; // remaining width 1270 group_dim = pos_maj + dim_maj - pos; // remaining width
1258 } 1271 }
1259 sway_log(L_DEBUG, "Arranging container %p column %" PRIuFAST32 1272 sway_log(L_DEBUG, "Arranging container %p column %zu, children [%d,%d[ (%fx%f+%f,%f)",
1260 ", children [%d,%d[ (%fx%f+%f,%f)",
1261 container, group, start, end, *group_w, *group_h, *group_x, *group_y); 1273 container, group, start, end, *group_w, *group_h, *group_x, *group_y);
1262 switch (group_layout) { 1274 switch (group_layout) {
1263 default: 1275 default: