aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.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/commands/resize.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/commands/resize.c')
-rw-r--r--sway/commands/resize.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 9a756e81..1c052286 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -66,7 +66,7 @@ static bool resize_floating(int amount, bool use_width) {
66 * Return the number of children in the slave groups. This corresponds to the children 66 * Return the number of children in the slave groups. This corresponds to the children
67 * that are not members of the master group. 67 * that are not members of the master group.
68 */ 68 */
69static inline uint_fast32_t slave_count(swayc_t *container) { 69static inline size_t auto_slave_count(swayc_t *container) {
70 return container->children->length - container->nb_master; 70 return container->children->length - container->nb_master;
71 71
72} 72}
@@ -75,13 +75,13 @@ static inline uint_fast32_t slave_count(swayc_t *container) {
75 * given the index of a container's child, return the index of the first child of the group 75 * given the index of a container's child, return the index of the first child of the group
76 * which index is a member of. 76 * which index is a member of.
77 */ 77 */
78static int group_start_index(swayc_t *container, int index) { 78static int auto_group_start_index(swayc_t *container, int index) {
79 if ((index < 0) || (! is_auto_layout(container->layout)) || 79 if (index < 0 || ! is_auto_layout(container->layout)
80 ((uint_fast32_t) index < container->nb_master)) { 80 || (size_t) index < container->nb_master) {
81 return 0; 81 return 0;
82 } else { 82 } else {
83 uint_fast32_t grp_sz = slave_count(container) / container->nb_slave_groups; 83 size_t grp_sz = auto_slave_count(container) / container->nb_slave_groups;
84 uint_fast32_t remainder = slave_count(container) % container->nb_slave_groups; 84 size_t remainder = auto_slave_count(container) % container->nb_slave_groups;
85 int start_idx; 85 int start_idx;
86 int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master; 86 int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master;
87 if (index < idx2) { 87 if (index < idx2) {
@@ -98,16 +98,16 @@ static int group_start_index(swayc_t *container, int index) {
98 * that follows the one which index is a member of. 98 * that follows the one which index is a member of.
99 * This makes the function usable to walk through the groups in a container. 99 * This makes the function usable to walk through the groups in a container.
100 */ 100 */
101static int group_end_index(swayc_t *container, int index) { 101static int auto_group_end_index(swayc_t *container, int index) {
102 if (index < 0 || ! is_auto_layout(container->layout)) { 102 if (index < 0 || ! is_auto_layout(container->layout)) {
103 return container->children->length; 103 return container->children->length;
104 } else { 104 } else {
105 int nxt_idx; 105 int nxt_idx;
106 if ((uint_fast32_t)index < container->nb_master) { 106 if ((size_t)index < container->nb_master) {
107 nxt_idx = container->nb_master; 107 nxt_idx = container->nb_master;
108 } else { 108 } else {
109 uint_fast32_t grp_sz = slave_count(container) / container->nb_slave_groups; 109 size_t grp_sz = auto_slave_count(container) / container->nb_slave_groups;
110 uint_fast32_t remainder = slave_count(container) % container->nb_slave_groups; 110 size_t remainder = auto_slave_count(container) % container->nb_slave_groups;
111 int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master; 111 int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master;
112 if (index < idx2) { 112 if (index < idx2) {
113 nxt_idx = ((index - container->nb_master) / grp_sz + 1) * grp_sz + container->nb_master; 113 nxt_idx = ((index - container->nb_master) / grp_sz + 1) * grp_sz + container->nb_master;
@@ -122,30 +122,30 @@ static int group_end_index(swayc_t *container, int index) {
122/** 122/**
123 * Return the combined number of master and slave groups in the container. 123 * Return the combined number of master and slave groups in the container.
124 */ 124 */
125static inline uint_fast32_t group_count(swayc_t *container) { 125static inline size_t auto_group_count(swayc_t *container) {
126 return MIN(container->nb_slave_groups, slave_count(container)) + (container->nb_master ? 1 : 0); 126 return MIN(container->nb_slave_groups, auto_slave_count(container)) + (container->nb_master ? 1 : 0);
127} 127}
128 128
129/** 129/**
130 * return the index of the Group containing <index>th child of <container>. 130 * return the index of the Group containing <index>th child of <container>.
131 * The index is the order of the group along the container's major axis (starting at 0). 131 * The index is the order of the group along the container's major axis (starting at 0).
132 */ 132 */
133static uint_fast32_t group_index(swayc_t *container, int index) { 133static size_t auto_group_index(swayc_t *container, int index) {
134 if (index < 0) { 134 if (index < 0) {
135 return 0; 135 return 0;
136 } 136 }
137 bool master_first = (container->layout == L_AUTO_LEFT || container->layout == L_AUTO_TOP); 137 bool master_first = (container->layout == L_AUTO_LEFT || container->layout == L_AUTO_TOP);
138 int nb_slaves = slave_count(container); 138 int nb_slaves = auto_slave_count(container);
139 if ((uint_fast32_t) index < container->nb_master) { 139 if ((size_t) index < container->nb_master) {
140 if (master_first || nb_slaves <= 0) { 140 if (master_first || nb_slaves <= 0) {
141 return 0; 141 return 0;
142 } else { 142 } else {
143 return MIN(container->nb_slave_groups, nb_slaves); 143 return MIN(container->nb_slave_groups, nb_slaves);
144 } 144 }
145 } else { 145 } else {
146 uint_fast32_t grp_sz = slave_count(container) / container->nb_slave_groups; 146 size_t grp_sz = auto_slave_count(container) / container->nb_slave_groups;
147 uint_fast32_t remainder = slave_count(container) % container->nb_slave_groups; 147 size_t remainder = auto_slave_count(container) % container->nb_slave_groups;
148 uint_fast32_t grp_idx; 148 size_t grp_idx;
149 int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master; 149 int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master;
150 if (index < idx2) { 150 if (index < idx2) {
151 grp_idx = (index - container->nb_master) / grp_sz; 151 grp_idx = (index - container->nb_master) / grp_sz;
@@ -161,16 +161,16 @@ static bool resize_tiled(int amount, bool use_width) {
161 swayc_t *parent = container->parent; 161 swayc_t *parent = container->parent;
162 int idx_focused = 0; 162 int idx_focused = 0;
163 bool use_major = false; 163 bool use_major = false;
164 uint_fast32_t nb_before = 0; 164 size_t nb_before = 0;
165 uint_fast32_t nb_after = 0; 165 size_t nb_after = 0;
166 166
167 // 1. Identify a container ancestor that will allow the focused child to grow in the requested 167 // 1. Identify a container ancestor that will allow the focused child to grow in the requested
168 // direction. 168 // direction.
169 while (container->parent) { 169 while (container->parent) {
170 parent = container->parent; 170 parent = container->parent;
171 if ((parent->children && parent->children->length > 1) && 171 if ((parent->children && parent->children->length > 1)
172 (is_auto_layout(parent->layout) || (use_width ? parent->layout == L_HORIZ : 172 && (is_auto_layout(parent->layout)
173 parent->layout == L_VERT))) { 173 || (use_width ? parent->layout == L_HORIZ : parent->layout == L_VERT))) {
174 // check if container has siblings that can provide/absorb the space needed for 174 // check if container has siblings that can provide/absorb the space needed for
175 // the resize operation. 175 // the resize operation.
176 use_major = use_width 176 use_major = use_width
@@ -185,15 +185,15 @@ static bool resize_tiled(int amount, bool use_width) {
185 continue; 185 continue;
186 } 186 }
187 if (use_major) { 187 if (use_major) {
188 nb_before = group_index(parent, idx_focused); 188 nb_before = auto_group_index(parent, idx_focused);
189 nb_after = group_count(parent) - nb_before - 1; 189 nb_after = auto_group_count(parent) - nb_before - 1;
190 } else { 190 } else {
191 nb_before = idx_focused - group_start_index(parent, idx_focused); 191 nb_before = idx_focused - auto_group_start_index(parent, idx_focused);
192 nb_after = group_end_index(parent, idx_focused) - idx_focused - 1; 192 nb_after = auto_group_end_index(parent, idx_focused) - idx_focused - 1;
193 sway_log(L_DEBUG, "+++ focused: %d, start: %d, end: %d, before: %d, after: %d", 193 sway_log(L_DEBUG, "+++ focused: %d, start: %d, end: %d, before: %d, after: %d",
194 idx_focused, 194 idx_focused,
195 (int)group_start_index(parent, idx_focused), 195 (int)auto_group_start_index(parent, idx_focused),
196 (int)group_end_index(parent, idx_focused), 196 (int)auto_group_end_index(parent, idx_focused),
197 (int)nb_before, (int)nb_after); 197 (int)nb_before, (int)nb_after);
198 198
199 } 199 }
@@ -206,14 +206,14 @@ static bool resize_tiled(int amount, bool use_width) {
206 if (parent == &root_container) { 206 if (parent == &root_container) {
207 return true; 207 return true;
208 } 208 }
209 sway_log(L_DEBUG, "Found the proper parent: %p. It has %" PRIuFAST32 " before conts, and %" 209 sway_log(L_DEBUG, "Found the proper parent: %p. It has %zu before conts, "
210 PRIuFAST32 " after conts", parent, nb_before, nb_after); 210 "and %zu after conts", parent, nb_before, nb_after);
211 // 2. Ensure that the resize operation will not make one of the resized containers drop 211 // 2. Ensure that the resize operation will not make one of the resized containers drop
212 // below the "sane" size threshold. 212 // below the "sane" size threshold.
213 bool valid = true; 213 bool valid = true;
214 swayc_t *focused = parent->children->items[idx_focused]; 214 swayc_t *focused = parent->children->items[idx_focused];
215 int start = use_major ? 0 : group_start_index(parent, idx_focused); 215 int start = use_major ? 0 : auto_group_start_index(parent, idx_focused);
216 int end = use_major ? parent->children->length : group_end_index(parent, idx_focused); 216 int end = use_major ? parent->children->length : auto_group_end_index(parent, idx_focused);
217 sway_log(L_DEBUG, "Check children of container %p [%d,%d[", container, start, end); 217 sway_log(L_DEBUG, "Check children of container %p [%d,%d[", container, start, end);
218 for (int i = start; i < end; ) { 218 for (int i = start; i < end; ) {
219 swayc_t *sibling = parent->children->items[i]; 219 swayc_t *sibling = parent->children->items[i];
@@ -235,13 +235,13 @@ static bool resize_tiled(int amount, bool use_width) {
235 sway_log(L_DEBUG, "Container size no longer sane"); 235 sway_log(L_DEBUG, "Container size no longer sane");
236 break; 236 break;
237 } 237 }
238 i = use_major ? group_end_index(parent, i) : (i + 1); 238 i = use_major ? auto_group_end_index(parent, i) : (i + 1);
239 sway_log(L_DEBUG, "+++++ check %i", i); 239 sway_log(L_DEBUG, "+++++ check %i", i);
240 } 240 }
241 // 3. Apply the size change 241 // 3. Apply the size change
242 if (valid) { 242 if (valid) {
243 for (int i = start; i < end; ) { 243 for (int i = start; i < end; ) {
244 int next_i = use_major ? group_end_index(parent, i) : (i + 1); 244 int next_i = use_major ? auto_group_end_index(parent, i) : (i + 1);
245 swayc_t *sibling = parent->children->items[i]; 245 swayc_t *sibling = parent->children->items[i];
246 double pixels = amount; 246 double pixels = amount;
247 bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y; 247 bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y;