diff options
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r-- | sway/commands/resize.c | 98 |
1 files changed, 2 insertions, 96 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 1c052286..c391945f 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -62,100 +62,6 @@ static bool resize_floating(int amount, bool use_width) { | |||
62 | return false; | 62 | return false; |
63 | } | 63 | } |
64 | 64 | ||
65 | /** | ||
66 | * Return the number of children in the slave groups. This corresponds to the children | ||
67 | * that are not members of the master group. | ||
68 | */ | ||
69 | static inline size_t auto_slave_count(swayc_t *container) { | ||
70 | return container->children->length - container->nb_master; | ||
71 | |||
72 | } | ||
73 | |||
74 | /** | ||
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. | ||
77 | */ | ||
78 | static int auto_group_start_index(swayc_t *container, int index) { | ||
79 | if (index < 0 || ! is_auto_layout(container->layout) | ||
80 | || (size_t) index < container->nb_master) { | ||
81 | return 0; | ||
82 | } else { | ||
83 | size_t grp_sz = auto_slave_count(container) / container->nb_slave_groups; | ||
84 | size_t remainder = auto_slave_count(container) % container->nb_slave_groups; | ||
85 | int start_idx; | ||
86 | int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master; | ||
87 | if (index < idx2) { | ||
88 | start_idx = ((index - container->nb_master) / grp_sz) * grp_sz + container->nb_master; | ||
89 | } else { | ||
90 | start_idx = idx2 + ((index - idx2) / (grp_sz + 1)) * (grp_sz + 1); | ||
91 | } | ||
92 | return MIN(start_idx, container->children->length); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * given the index of a container's child, return the index of the first child of the group | ||
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. | ||
100 | */ | ||
101 | static int auto_group_end_index(swayc_t *container, int index) { | ||
102 | if (index < 0 || ! is_auto_layout(container->layout)) { | ||
103 | return container->children->length; | ||
104 | } else { | ||
105 | int nxt_idx; | ||
106 | if ((size_t)index < container->nb_master) { | ||
107 | nxt_idx = container->nb_master; | ||
108 | } else { | ||
109 | size_t grp_sz = auto_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; | ||
112 | if (index < idx2) { | ||
113 | nxt_idx = ((index - container->nb_master) / grp_sz + 1) * grp_sz + container->nb_master; | ||
114 | } else { | ||
115 | nxt_idx = idx2 + ((index - idx2) / (grp_sz + 1) + 1) * (grp_sz + 1); | ||
116 | } | ||
117 | } | ||
118 | return MIN(nxt_idx, container->children->length); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * Return the combined number of master and slave groups in the container. | ||
124 | */ | ||
125 | static inline size_t auto_group_count(swayc_t *container) { | ||
126 | return MIN(container->nb_slave_groups, auto_slave_count(container)) + (container->nb_master ? 1 : 0); | ||
127 | } | ||
128 | |||
129 | /** | ||
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). | ||
132 | */ | ||
133 | static size_t auto_group_index(swayc_t *container, int index) { | ||
134 | if (index < 0) { | ||
135 | return 0; | ||
136 | } | ||
137 | bool master_first = (container->layout == L_AUTO_LEFT || container->layout == L_AUTO_TOP); | ||
138 | int nb_slaves = auto_slave_count(container); | ||
139 | if ((size_t) index < container->nb_master) { | ||
140 | if (master_first || nb_slaves <= 0) { | ||
141 | return 0; | ||
142 | } else { | ||
143 | return MIN(container->nb_slave_groups, nb_slaves); | ||
144 | } | ||
145 | } else { | ||
146 | size_t grp_sz = auto_slave_count(container) / container->nb_slave_groups; | ||
147 | size_t remainder = auto_slave_count(container) % container->nb_slave_groups; | ||
148 | size_t grp_idx; | ||
149 | int idx2 = (container->nb_slave_groups - remainder) * grp_sz + container->nb_master; | ||
150 | if (index < idx2) { | ||
151 | grp_idx = (index - container->nb_master) / grp_sz; | ||
152 | } else { | ||
153 | grp_idx = (container->nb_slave_groups - remainder) + (index - idx2) / (grp_sz + 1) ; | ||
154 | } | ||
155 | return grp_idx + (master_first ? 1 : 0); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | static bool resize_tiled(int amount, bool use_width) { | 65 | static bool resize_tiled(int amount, bool use_width) { |
160 | swayc_t *container = get_focused_view(swayc_active_workspace()); | 66 | swayc_t *container = get_focused_view(swayc_active_workspace()); |
161 | swayc_t *parent = container->parent; | 67 | swayc_t *parent = container->parent; |
@@ -229,8 +135,8 @@ static bool resize_tiled(int amount, bool use_width) { | |||
229 | } | 135 | } |
230 | sway_log(L_DEBUG, "Check container %p: width %g vs %d, height %g vs %d", sibling, sibling->width + pixels, min_sane_w, sibling->height + pixels, min_sane_h); | 136 | sway_log(L_DEBUG, "Check container %p: width %g vs %d, height %g vs %d", sibling, sibling->width + pixels, min_sane_w, sibling->height + pixels, min_sane_h); |
231 | if (use_width ? | 137 | if (use_width ? |
232 | sibling->width + pixels < min_sane_w : | 138 | sibling->width + pixels < min_sane_w : |
233 | sibling->height + pixels < min_sane_h) { | 139 | sibling->height + pixels < min_sane_h) { |
234 | valid = false; | 140 | valid = false; |
235 | sway_log(L_DEBUG, "Container size no longer sane"); | 141 | sway_log(L_DEBUG, "Container size no longer sane"); |
236 | break; | 142 | break; |