summaryrefslogtreecommitdiffstats
path: root/sway/layout.c
diff options
context:
space:
mode:
authorLibravatar wil <william.barsse@gmail.com>2017-01-01 21:52:49 +0100
committerLibravatar wil <william.barsse@gmail.com>2017-01-01 21:52:49 +0100
commit97f70987d70315c683fd1e16c731b396679f6b96 (patch)
treed8f9649c86010ed5e3c1f109e789af680aad717b /sway/layout.c
parentchanged "layout promote" command to "move first" (diff)
downloadsway-97f70987d70315c683fd1e16c731b396679f6b96.tar.gz
sway-97f70987d70315c683fd1e16c731b396679f6b96.tar.zst
sway-97f70987d70315c683fd1e16c731b396679f6b96.zip
[fix] cleanups suggested by Sway community
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/sway/layout.c b/sway/layout.c
index 6212ec75..faab9196 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -253,8 +253,7 @@ void swap_geometry(swayc_t *a, swayc_t *b) {
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 swayc_t *parent = container->parent; 255 swayc_t *parent = container->parent;
256 if (container->is_floating 256 if (container->is_floating || (container->type != C_VIEW && container->type != C_CONTAINER)) {
257 || (container->type != C_VIEW && container->type != C_CONTAINER)) {
258 return; 257 return;
259 } 258 }
260 if (dir == MOVE_UP || dir == MOVE_DOWN) { 259 if (dir == MOVE_UP || dir == MOVE_DOWN) {
@@ -323,14 +322,14 @@ void move_container(swayc_t *container, enum movement_direction dir) {
323 // if move command makes container change from master to slave 322 // if move command makes container change from master to slave
324 // (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.
325 if (parent->nb_master && 324 if (parent->nb_master &&
326 (uint_fast32_t) parent->children->length > parent->nb_master) { 325 (size_t) parent->children->length > parent->nb_master) {
327 swayc_t *swap_geom = NULL; 326 swayc_t *swap_geom = NULL;
328 // if child is being promoted/demoted, it will swap geometry 327 // if child is being promoted/demoted, it will swap geometry
329 // with the sibling being demoted/promoted. 328 // with the sibling being demoted/promoted.
330 if ((dir == MOVE_NEXT && desired == 0) 329 if ((dir == MOVE_NEXT && desired == 0)
331 || (dir == MOVE_PREV && (uint_fast32_t) desired == parent->nb_master - 1)) { 330 || (dir == MOVE_PREV && (size_t) desired == parent->nb_master - 1)) {
332 swap_geom = parent->children->items[parent->nb_master - 1]; 331 swap_geom = parent->children->items[parent->nb_master - 1];
333 } else if ((dir == MOVE_NEXT && (uint_fast32_t) desired == parent->nb_master) 332 } else if ((dir == MOVE_NEXT && (size_t) desired == parent->nb_master)
334 || (dir == MOVE_PREV && desired == parent->children->length - 1)) { 333 || (dir == MOVE_PREV && desired == parent->children->length - 1)) {
335 swap_geom = parent->children->items[parent->nb_master]; 334 swap_geom = parent->children->items[parent->nb_master];
336 } 335 }
@@ -822,20 +821,24 @@ void update_geometry(swayc_t *container) {
822 } 821 }
823} 822}
824 823
824bool is_auto_layout(enum swayc_layouts layout) {
825 return (layout >= L_AUTO_FIRST) && (layout <= L_AUTO_LAST);
826}
827
825/** 828/**
826 * Layout application prototypes 829 * Layout application prototypes
827 */ 830 */
828static void apply_horiz_layout(swayc_t *container, const double x, 831static void apply_horiz_layout(swayc_t *container, const double x,
829 const double y, const double width, 832 const double y, const double width,
830 const double height, const int start, 833 const double height, const int start,
831 const int end); 834 const int end);
832static void apply_vert_layout(swayc_t *container, const double x, 835static void apply_vert_layout(swayc_t *container, const double x,
833 const double y, const double width, 836 const double y, const double width,
834 const double height, const int start, 837 const double height, const int start,
835 const int end); 838 const int end);
836static void apply_tabbed_or_stacked_layout(swayc_t *container, double x, 839static void apply_tabbed_or_stacked_layout(swayc_t *container, double x,
837 double y, double width, 840 double y, double width,
838 double height); 841 double height);
839 842
840static void apply_auto_layout(swayc_t *container, const double x, const double y, 843static void apply_auto_layout(swayc_t *container, const double x, const double y,
841 const double width, const double height, 844 const double width, const double height,
@@ -1164,8 +1167,8 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1164 // a single slave group (containing slave 1 and 2). The master 1167 // a single slave group (containing slave 1 and 2). The master
1165 // group and slave group are layed out using L_VERT. 1168 // group and slave group are layed out using L_VERT.
1166 1169
1167 uint_fast32_t nb_slaves = container->children->length - container->nb_master; 1170 size_t nb_slaves = container->children->length - container->nb_master;
1168 uint_fast32_t nb_groups = (container->nb_master > 0 ? 1 : 0) + 1171 size_t nb_groups = (container->nb_master > 0 ? 1 : 0) +
1169 MIN(container->nb_slave_groups, nb_slaves); 1172 MIN(container->nb_slave_groups, nb_slaves);
1170 1173
1171 // the target dimension of the container along the "major" axis, each 1174 // the target dimension of the container along the "major" axis, each
@@ -1186,9 +1189,9 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1186 // height and width of next group to be laid out. 1189 // height and width of next group to be laid out.
1187 const double *group_h, *group_w; 1190 const double *group_h, *group_w;
1188 1191
1189 switch(group_layout) { 1192 switch (group_layout) {
1190 default: 1193 default:
1191 sway_log(L_ERROR, "Unknown layout type (%d) used in %s()", 1194 sway_log(L_DEBUG, "Unknown layout type (%d) used in %s()",
1192 group_layout, __func__); 1195 group_layout, __func__);
1193 /* fall through */ 1196 /* fall through */
1194 case L_VERT: 1197 case L_VERT:
@@ -1216,7 +1219,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1216 * layout. */ 1219 * layout. */
1217 double old_group_dim[nb_groups]; 1220 double old_group_dim[nb_groups];
1218 double old_dim = 0; 1221 double old_dim = 0;
1219 uint_fast32_t group = 0; 1222 size_t group = 0;
1220 for (int i = 0; i < container->children->length;) { 1223 for (int i = 0; i < container->children->length;) {
1221 swayc_t *child = container->children->items[i]; 1224 swayc_t *child = container->children->items[i];
1222 double *dim = group_layout == L_HORIZ ? &child->height : &child->width; 1225 double *dim = group_layout == L_HORIZ ? &child->height : &child->width;
@@ -1252,7 +1255,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1252 1255
1253 for (group = 0; group < nb_groups; ++group) { 1256 for (group = 0; group < nb_groups; ++group) {
1254 // column to include next by increasing position. 1257 // column to include next by increasing position.
1255 uint_fast32_t layout_group = master_first ? group : (group + 1) % nb_groups; 1258 size_t layout_group = master_first ? group : (group + 1) % nb_groups;
1256 1259
1257 // adjusted size of the group 1260 // adjusted size of the group
1258 group_dim = old_group_dim[layout_group] * scale; 1261 group_dim = old_group_dim[layout_group] * scale;
@@ -1270,8 +1273,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
1270 if (group == nb_groups - 1) { 1273 if (group == nb_groups - 1) {
1271 group_dim = pos_maj + dim_maj - pos; // remaining width 1274 group_dim = pos_maj + dim_maj - pos; // remaining width
1272 } 1275 }
1273 sway_log(L_DEBUG, "Arranging container %p column %" PRIuFAST32 1276 sway_log(L_DEBUG, "Arranging container %p column %zu, children [%d,%d[ (%fx%f+%f,%f)",
1274 ", children [%d,%d[ (%fx%f+%f,%f)",
1275 container, group, start, end, *group_w, *group_h, *group_x, *group_y); 1277 container, group, start, end, *group_w, *group_h, *group_x, *group_y);
1276 switch (group_layout) { 1278 switch (group_layout) {
1277 default: 1279 default: