diff options
Diffstat (limited to 'sway/resize.c')
-rw-r--r-- | sway/resize.c | 261 |
1 files changed, 0 insertions, 261 deletions
diff --git a/sway/resize.c b/sway/resize.c index 31cd66e8..22d520af 100644 --- a/sway/resize.c +++ b/sway/resize.c | |||
@@ -6,267 +6,6 @@ | |||
6 | #include "input_state.h" | 6 | #include "input_state.h" |
7 | #include "handlers.h" | 7 | #include "handlers.h" |
8 | 8 | ||
9 | bool mouse_resize_tiled(struct wlc_origin prev_pos) { | ||
10 | swayc_t *view = container_under_pointer(); | ||
11 | bool valid = true; | ||
12 | bool changed_tiling = false; | ||
13 | double dx = pointer_state.origin.x - prev_pos.x; | ||
14 | double dy = pointer_state.origin.y - prev_pos.y; | ||
15 | if (view != pointer_state.tiling.init_view) { | ||
16 | changed_tiling = true; | ||
17 | valid = false; | ||
18 | if (view->type != C_WORKSPACE) { | ||
19 | if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_LEFT) == view) { | ||
20 | pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20; | ||
21 | pointer_state.lock.temp_left = true; | ||
22 | } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_RIGHT) == view) { | ||
23 | pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20; | ||
24 | pointer_state.lock.temp_right = true; | ||
25 | } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_UP) == view) { | ||
26 | pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; | ||
27 | pointer_state.lock.temp_up = true; | ||
28 | } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_DOWN) == view) { | ||
29 | pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; | ||
30 | pointer_state.lock.temp_down = true; | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | if ((dx < 0 || pointer_state.origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) { | ||
36 | changed_tiling = true; | ||
37 | valid = false; | ||
38 | } else if (dx > 0 && pointer_state.lock.temp_left) { | ||
39 | pointer_state.lock.temp_left = false; | ||
40 | pointer_state.tiling.lock_pos.x = 0; | ||
41 | } | ||
42 | |||
43 | if ((dx > 0 || pointer_state.origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) { | ||
44 | changed_tiling = true; | ||
45 | valid = false; | ||
46 | } else if (dx < 0 && pointer_state.lock.temp_right) { | ||
47 | pointer_state.lock.temp_right = false; | ||
48 | pointer_state.tiling.lock_pos.x = 0; | ||
49 | } | ||
50 | |||
51 | if ((dy < 0 || pointer_state.origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) { | ||
52 | changed_tiling = true; | ||
53 | valid = false; | ||
54 | } else if (dy > 0 && pointer_state.lock.temp_up) { | ||
55 | pointer_state.lock.temp_up = false; | ||
56 | pointer_state.tiling.lock_pos.y = 0; | ||
57 | } | ||
58 | |||
59 | if ((dy > 0 || pointer_state.origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) { | ||
60 | changed_tiling = true; | ||
61 | valid = false; | ||
62 | } else if (dy < 0 && pointer_state.lock.temp_down) { | ||
63 | pointer_state.lock.temp_down = false; | ||
64 | pointer_state.tiling.lock_pos.y = 0; | ||
65 | } | ||
66 | |||
67 | if (!view->is_floating && valid) { | ||
68 | // Handle layout resizes -- Find the biggest parent container then apply resizes to that | ||
69 | // and its bordering siblings | ||
70 | swayc_t *parent = view; | ||
71 | if (!pointer_state.lock.bottom) { | ||
72 | while (parent->type != C_WORKSPACE) { | ||
73 | // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better | ||
74 | // way of doing this. | ||
75 | if (fabs(parent->parent->y + parent->parent->height - (view->y + view->height)) <= 1) { | ||
76 | parent = parent->parent; | ||
77 | } else { | ||
78 | break; | ||
79 | } | ||
80 | } | ||
81 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { | ||
82 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); | ||
83 | if (sibling) { | ||
84 | if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) { | ||
85 | recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); | ||
86 | recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); | ||
87 | changed_tiling = true; | ||
88 | } else { | ||
89 | if (parent->height < min_sane_h) { | ||
90 | //pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; | ||
91 | pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; | ||
92 | pointer_state.lock.temp_up = true; | ||
93 | } else if (sibling->height < min_sane_h) { | ||
94 | pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; | ||
95 | pointer_state.lock.temp_down = true; | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | } else if (!pointer_state.lock.top) { | ||
101 | while (parent->type != C_WORKSPACE) { | ||
102 | if (fabs(parent->parent->y - view->y) <= 1) { | ||
103 | parent = parent->parent; | ||
104 | } else { | ||
105 | break; | ||
106 | } | ||
107 | } | ||
108 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { | ||
109 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); | ||
110 | if (sibling) { | ||
111 | if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) { | ||
112 | recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); | ||
113 | recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); | ||
114 | changed_tiling = true; | ||
115 | } else { | ||
116 | if (parent->height < min_sane_h) { | ||
117 | //pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20; | ||
118 | pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; | ||
119 | pointer_state.lock.temp_down = true; | ||
120 | } else if (sibling->height < min_sane_h) { | ||
121 | pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20; | ||
122 | pointer_state.lock.temp_up = true; | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | parent = view; | ||
130 | if (!pointer_state.lock.right) { | ||
131 | while (parent->type != C_WORKSPACE) { | ||
132 | if (fabs(parent->parent->x + parent->parent->width - (view->x + view->width)) <= 1) { | ||
133 | parent = parent->parent; | ||
134 | } else { | ||
135 | sway_log(L_DEBUG, "view: %f vs parent: %f", view->x + view->width, parent->parent->x + parent->parent->width); | ||
136 | break; | ||
137 | } | ||
138 | } | ||
139 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { | ||
140 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); | ||
141 | if (sibling) { | ||
142 | if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) { | ||
143 | recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); | ||
144 | recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); | ||
145 | changed_tiling = true; | ||
146 | } else { | ||
147 | if (parent->width < min_sane_w) { | ||
148 | pointer_state.lock.temp_left = true; | ||
149 | pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20; | ||
150 | } else if (sibling->width < min_sane_w) { | ||
151 | pointer_state.lock.temp_right = true; | ||
152 | pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20; | ||
153 | } | ||
154 | } | ||
155 | } | ||
156 | } | ||
157 | } else if (!pointer_state.lock.left) { | ||
158 | while (parent->type != C_WORKSPACE) { | ||
159 | if (fabs(parent->parent->x - view->x) <= 1 && parent->parent) { | ||
160 | parent = parent->parent; | ||
161 | } else { | ||
162 | break; | ||
163 | } | ||
164 | } | ||
165 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { | ||
166 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); | ||
167 | if (sibling) { | ||
168 | if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) { | ||
169 | recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); | ||
170 | recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); | ||
171 | changed_tiling = true; | ||
172 | } else { | ||
173 | if (parent->width < min_sane_w) { | ||
174 | pointer_state.lock.temp_right = true; | ||
175 | pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20; | ||
176 | } else if (sibling->width < min_sane_w) { | ||
177 | pointer_state.lock.temp_left = true; | ||
178 | pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20; | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
185 | } | ||
186 | return changed_tiling; | ||
187 | } | ||
188 | |||
189 | bool resize_floating(struct wlc_origin prev_pos) { | ||
190 | bool changed = false; | ||
191 | swayc_t *view = container_under_pointer(); | ||
192 | uint32_t edge = 0; | ||
193 | int dx = pointer_state.origin.x - prev_pos.x; | ||
194 | int dy = pointer_state.origin.y - prev_pos.y; | ||
195 | |||
196 | // Move and resize the view based on the dx/dy and mouse position | ||
197 | int midway_x = view->x + view->width/2; | ||
198 | int midway_y = view->y + view->height/2; | ||
199 | if (dx < 0) { | ||
200 | if (!pointer_state.lock.right) { | ||
201 | if (view->width > min_sane_w) { | ||
202 | changed = true; | ||
203 | view->width += dx; | ||
204 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
205 | } | ||
206 | } else if (pointer_state.origin.x < midway_x && !pointer_state.lock.left) { | ||
207 | changed = true; | ||
208 | view->x += dx; | ||
209 | view->width -= dx; | ||
210 | edge += WLC_RESIZE_EDGE_LEFT; | ||
211 | } | ||
212 | } else if (dx > 0) { | ||
213 | if (pointer_state.origin.x > midway_x && !pointer_state.lock.right) { | ||
214 | changed = true; | ||
215 | view->width += dx; | ||
216 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
217 | } else if (!pointer_state.lock.left) { | ||
218 | if (view->width > min_sane_w) { | ||
219 | changed = true; | ||
220 | view->x += dx; | ||
221 | view->width -= dx; | ||
222 | edge += WLC_RESIZE_EDGE_LEFT; | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | if (dy < 0) { | ||
228 | if (!pointer_state.lock.bottom) { | ||
229 | if (view->height > min_sane_h) { | ||
230 | changed = true; | ||
231 | view->height += dy; | ||
232 | edge += WLC_RESIZE_EDGE_BOTTOM; | ||
233 | } | ||
234 | } else if (pointer_state.origin.y < midway_y && !pointer_state.lock.top) { | ||
235 | changed = true; | ||
236 | view->y += dy; | ||
237 | view->height -= dy; | ||
238 | edge += WLC_RESIZE_EDGE_TOP; | ||
239 | } | ||
240 | } else if (dy > 0) { | ||
241 | if (pointer_state.origin.y > midway_y && !pointer_state.lock.bottom) { | ||
242 | changed = true; | ||
243 | view->height += dy; | ||
244 | edge += WLC_RESIZE_EDGE_BOTTOM; | ||
245 | } else if (!pointer_state.lock.top) { | ||
246 | if (view->height > min_sane_h) { | ||
247 | changed = true; | ||
248 | view->y += dy; | ||
249 | view->height -= dy; | ||
250 | edge += WLC_RESIZE_EDGE_TOP; | ||
251 | } | ||
252 | } | ||
253 | } | ||
254 | if (changed) { | ||
255 | struct wlc_geometry geometry = { | ||
256 | .origin = { | ||
257 | .x = view->x, | ||
258 | .y = view->y | ||
259 | }, | ||
260 | .size = { | ||
261 | .w = view->width, | ||
262 | .h = view->height | ||
263 | } | ||
264 | }; | ||
265 | wlc_view_set_geometry(view->handle, edge, &geometry); | ||
266 | } | ||
267 | return changed; | ||
268 | } | ||
269 | |||
270 | bool resize_tiled(int amount, bool use_width) { | 9 | bool resize_tiled(int amount, bool use_width) { |
271 | swayc_t *parent = get_focused_view(swayc_active_workspace()); | 10 | swayc_t *parent = get_focused_view(swayc_active_workspace()); |
272 | swayc_t *focused = parent; | 11 | swayc_t *focused = parent; |