diff options
Diffstat (limited to 'include/sway/old/container.h')
-rw-r--r-- | include/sway/old/container.h | 362 |
1 files changed, 362 insertions, 0 deletions
diff --git a/include/sway/old/container.h b/include/sway/old/container.h new file mode 100644 index 00000000..d46ffa63 --- /dev/null +++ b/include/sway/old/container.h | |||
@@ -0,0 +1,362 @@ | |||
1 | #ifndef _SWAY_CONTAINER_H | ||
2 | #define _SWAY_CONTAINER_H | ||
3 | #include <sys/types.h> | ||
4 | #include <wlc/wlc.h> | ||
5 | #include <wlr/types/wlr_output.h> | ||
6 | #include <stdint.h> | ||
7 | #include "list.h" | ||
8 | |||
9 | typedef struct sway_container swayc_t; | ||
10 | |||
11 | extern swayc_t root_container; | ||
12 | extern swayc_t *current_focus; | ||
13 | |||
14 | struct sway_view; | ||
15 | |||
16 | /** | ||
17 | * Different kinds of containers. | ||
18 | * | ||
19 | * This enum is in order. A container will never be inside of a container below | ||
20 | * it on this list. | ||
21 | */ | ||
22 | enum swayc_types { | ||
23 | C_ROOT, /**< The root container. Only one of these ever exists. */ | ||
24 | C_OUTPUT, /**< An output (aka monitor, head, etc). */ | ||
25 | C_WORKSPACE, /**< A workspace. */ | ||
26 | C_CONTAINER, /**< A manually created container. */ | ||
27 | C_VIEW, /**< A view (aka window). */ | ||
28 | // Keep last | ||
29 | C_TYPES, | ||
30 | }; | ||
31 | |||
32 | /** | ||
33 | * Different ways to arrange a container. | ||
34 | */ | ||
35 | enum swayc_layouts { | ||
36 | L_NONE, /**< Used for containers that have no layout (views, root) */ | ||
37 | L_HORIZ, | ||
38 | L_VERT, | ||
39 | L_STACKED, | ||
40 | L_TABBED, | ||
41 | L_FLOATING, /**< A psuedo-container, removed from the tree, to hold floating windows */ | ||
42 | |||
43 | /* Awesome/Monad style auto layouts */ | ||
44 | L_AUTO_LEFT, | ||
45 | L_AUTO_RIGHT, | ||
46 | L_AUTO_TOP, | ||
47 | L_AUTO_BOTTOM, | ||
48 | |||
49 | L_AUTO_FIRST = L_AUTO_LEFT, | ||
50 | L_AUTO_LAST = L_AUTO_BOTTOM, | ||
51 | |||
52 | // Keep last | ||
53 | L_LAYOUTS, | ||
54 | }; | ||
55 | |||
56 | enum swayc_border_types { | ||
57 | B_NONE, /**< No border */ | ||
58 | B_PIXEL, /**< 1px border */ | ||
59 | B_NORMAL /**< Normal border with title bar */ | ||
60 | }; | ||
61 | |||
62 | /** | ||
63 | * Stores information about a container. | ||
64 | * | ||
65 | * The tree is made of these. Views are containers that cannot have children. | ||
66 | */ | ||
67 | struct sway_container { | ||
68 | // TODO WLR: reconcile these | ||
69 | wlc_handle handle; | ||
70 | |||
71 | union { | ||
72 | struct sway_output *output; | ||
73 | struct sway_view *view; | ||
74 | } _handle; | ||
75 | |||
76 | /** | ||
77 | * A unique ID to identify this container. Primarily used in the | ||
78 | * get_tree JSON output. | ||
79 | */ | ||
80 | size_t id; | ||
81 | |||
82 | enum swayc_types type; | ||
83 | enum swayc_layouts layout; | ||
84 | enum swayc_layouts prev_layout; | ||
85 | enum swayc_layouts workspace_layout; | ||
86 | |||
87 | /** | ||
88 | * Width and height of this container, without borders or gaps. | ||
89 | */ | ||
90 | double width, height; | ||
91 | |||
92 | /** | ||
93 | * Views may request geometry, which is stored in this and ignored until | ||
94 | * the views are floated. | ||
95 | */ | ||
96 | int desired_width, desired_height; | ||
97 | |||
98 | /** | ||
99 | * The coordinates that this view appear at, relative to the output they | ||
100 | * are located on (output containers have absolute coordinates). | ||
101 | */ | ||
102 | double x, y; | ||
103 | |||
104 | /** | ||
105 | * Cached geometry used to store view/container geometry when switching | ||
106 | * between tabbed/stacked and horizontal/vertical layouts. | ||
107 | */ | ||
108 | struct wlc_geometry cached_geometry; | ||
109 | |||
110 | /** | ||
111 | * False if this view is invisible. It could be in the scratchpad or on a | ||
112 | * workspace that is not shown. | ||
113 | */ | ||
114 | bool visible; | ||
115 | bool is_floating; | ||
116 | bool is_focused; | ||
117 | bool sticky; // floating view always visible on its output | ||
118 | |||
119 | // Attributes that mostly views have. | ||
120 | char *name; | ||
121 | char *class; | ||
122 | char *instance; | ||
123 | char *app_id; | ||
124 | |||
125 | // Used by output containers to keep track of swaybg child processes. | ||
126 | pid_t bg_pid; | ||
127 | |||
128 | int gaps; | ||
129 | |||
130 | list_t *children; | ||
131 | /** | ||
132 | * Children of this container that are floated. | ||
133 | */ | ||
134 | list_t *floating; | ||
135 | /** | ||
136 | * Unmanaged view handles in this container. | ||
137 | */ | ||
138 | list_t *unmanaged; | ||
139 | |||
140 | /** | ||
141 | * The parent of this container. NULL for the root container. | ||
142 | */ | ||
143 | struct sway_container *parent; | ||
144 | /** | ||
145 | * Which of this container's children has focus. | ||
146 | */ | ||
147 | struct sway_container *focused; | ||
148 | /** | ||
149 | * If this container's children include a fullscreen view, this is that view. | ||
150 | */ | ||
151 | struct sway_container *fullscreen; | ||
152 | /** | ||
153 | * If this container is a view, this may be set to the window's decoration | ||
154 | * buffer (or NULL). | ||
155 | */ | ||
156 | struct border *border; | ||
157 | enum swayc_border_types border_type; | ||
158 | struct wlc_geometry border_geometry; | ||
159 | struct wlc_geometry title_bar_geometry; | ||
160 | struct wlc_geometry actual_geometry; | ||
161 | int border_thickness; | ||
162 | |||
163 | /** | ||
164 | * Number of master views in auto layouts. | ||
165 | */ | ||
166 | size_t nb_master; | ||
167 | |||
168 | /** | ||
169 | * Number of slave groups (e.g. columns) in auto layouts. | ||
170 | */ | ||
171 | size_t nb_slave_groups; | ||
172 | |||
173 | /** | ||
174 | * Marks applied to the container, list_t of char*. | ||
175 | */ | ||
176 | list_t *marks; | ||
177 | }; | ||
178 | |||
179 | enum visibility_mask { | ||
180 | VISIBLE = true | ||
181 | } visible; | ||
182 | |||
183 | struct sway_output; | ||
184 | /** | ||
185 | * Allocates a new output container. | ||
186 | */ | ||
187 | swayc_t *new_output(struct sway_output *sway_output); | ||
188 | /** | ||
189 | * Allocates a new workspace container. | ||
190 | */ | ||
191 | swayc_t *new_workspace(swayc_t *output, const char *name); | ||
192 | /** | ||
193 | * Allocates a new container and places a child into it. | ||
194 | * | ||
195 | * This is used from the split command, which creates a new container with the | ||
196 | * requested layout and replaces the focused container in the tree with the new | ||
197 | * one. Then the removed container is added as a child of the new container. | ||
198 | */ | ||
199 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); | ||
200 | /** | ||
201 | * Allocates a new view container. | ||
202 | * | ||
203 | * Pass in a sibling view, or a workspace to become this container's parent. | ||
204 | */ | ||
205 | swayc_t *new_view(swayc_t *sibling, struct sway_view *view); | ||
206 | /** | ||
207 | * Allocates a new floating view in the active workspace. | ||
208 | */ | ||
209 | swayc_t *new_floating_view(wlc_handle handle); | ||
210 | |||
211 | void floating_view_sane_size(swayc_t *view); | ||
212 | |||
213 | /** | ||
214 | * Frees an output's container. | ||
215 | */ | ||
216 | swayc_t *destroy_output(swayc_t *output); | ||
217 | /** | ||
218 | * Destroys a workspace container and returns the parent pointer, or NULL. | ||
219 | */ | ||
220 | swayc_t *destroy_workspace(swayc_t *workspace); | ||
221 | /** | ||
222 | * Destroys a container and all empty parents. Returns the topmost non-empty | ||
223 | * parent container, or NULL. | ||
224 | */ | ||
225 | swayc_t *destroy_container(swayc_t *container); | ||
226 | /** | ||
227 | * Destroys a view container and all empty parents. Returns the topmost | ||
228 | * non-empty parent container, or NULL. | ||
229 | */ | ||
230 | swayc_t *destroy_view(swayc_t *view); | ||
231 | |||
232 | /** | ||
233 | * Finds a container based on test criteria. Returns the first container that | ||
234 | * passes the test. | ||
235 | */ | ||
236 | swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); | ||
237 | /** | ||
238 | * Finds a parent container with the given swayc_type. | ||
239 | */ | ||
240 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); | ||
241 | /** | ||
242 | * Finds a parent with the given swayc_layout. | ||
243 | */ | ||
244 | swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); | ||
245 | /** | ||
246 | * Finds the bottom-most focused container of a type. | ||
247 | */ | ||
248 | swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types); | ||
249 | /** | ||
250 | * Finds the bottom-most focused container of a layout. | ||
251 | */ | ||
252 | swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts); | ||
253 | |||
254 | /** | ||
255 | * Gets the swayc_t associated with a wlc_handle. | ||
256 | */ | ||
257 | swayc_t *swayc_by_handle(wlc_handle handle); | ||
258 | /** | ||
259 | * Gets the named swayc_t. | ||
260 | */ | ||
261 | swayc_t *swayc_by_name(const char *name); | ||
262 | /** | ||
263 | * Gets the active output's container. | ||
264 | */ | ||
265 | swayc_t *swayc_active_output(void); | ||
266 | /** | ||
267 | * Gets the active workspace's container. | ||
268 | */ | ||
269 | swayc_t *swayc_active_workspace(void); | ||
270 | /** | ||
271 | * Gets the workspace for the given view container. | ||
272 | */ | ||
273 | swayc_t *swayc_active_workspace_for(swayc_t *view); | ||
274 | /** | ||
275 | * Finds the container currently underneath the pointer. | ||
276 | */ | ||
277 | swayc_t *container_under_pointer(void); | ||
278 | /** | ||
279 | * Finds the first container following a callback. | ||
280 | */ | ||
281 | swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data); | ||
282 | |||
283 | /** | ||
284 | * Returns true if a container is fullscreen. | ||
285 | */ | ||
286 | bool swayc_is_fullscreen(swayc_t *view); | ||
287 | /** | ||
288 | * Returns true if this view is focused. | ||
289 | */ | ||
290 | bool swayc_is_active(swayc_t *view); | ||
291 | /** | ||
292 | * Returns true if the parent is an ancestor of the child. | ||
293 | */ | ||
294 | bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); | ||
295 | /** | ||
296 | * Returns true if the child is a desecendant of the parent. | ||
297 | */ | ||
298 | bool swayc_is_child_of(swayc_t *child, swayc_t *parent); | ||
299 | |||
300 | /** | ||
301 | * Returns true if this container is an empty workspace. | ||
302 | */ | ||
303 | bool swayc_is_empty_workspace(swayc_t *container); | ||
304 | |||
305 | /** | ||
306 | * Returns the top most tabbed or stacked parent container. Returns NULL if | ||
307 | * view is not in a tabbed/stacked layout. | ||
308 | */ | ||
309 | swayc_t *swayc_tabbed_stacked_ancestor(swayc_t *view); | ||
310 | |||
311 | /** | ||
312 | * Returns the immediate tabbed or stacked parent container. Returns NULL if | ||
313 | * view is not directly in a tabbed/stacked layout. | ||
314 | */ | ||
315 | swayc_t *swayc_tabbed_stacked_parent(swayc_t *view); | ||
316 | |||
317 | /** | ||
318 | * Returns the gap (padding) of the container. | ||
319 | * | ||
320 | * This returns the inner gaps for a view, the outer gaps for a workspace, and | ||
321 | * 0 otherwise. | ||
322 | */ | ||
323 | int swayc_gap(swayc_t *container); | ||
324 | |||
325 | /** | ||
326 | * Maps a container's children over a function. | ||
327 | */ | ||
328 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | ||
329 | |||
330 | /** | ||
331 | * Set a view as visible or invisible. | ||
332 | * | ||
333 | * This will perform the required wlc calls as well; it is not sufficient to | ||
334 | * simply toggle the boolean in swayc_t. | ||
335 | */ | ||
336 | void set_view_visibility(swayc_t *view, void *data); | ||
337 | /** | ||
338 | * Set the gaps value for a view. | ||
339 | */ | ||
340 | void set_gaps(swayc_t *view, void *amount); | ||
341 | /** | ||
342 | * Add to the gaps value for a view. | ||
343 | */ | ||
344 | void add_gaps(swayc_t *view, void *amount); | ||
345 | |||
346 | /** | ||
347 | * Issue wlc calls to make the visibility of a container consistent. | ||
348 | */ | ||
349 | void update_visibility(swayc_t *container); | ||
350 | |||
351 | /** | ||
352 | * Close all child views of container | ||
353 | */ | ||
354 | void close_views(swayc_t *container); | ||
355 | |||
356 | /** | ||
357 | * Assign layout to a container. Needed due to workspace container specifics. | ||
358 | * Workspace should always have either L_VERT or L_HORIZ layout. | ||
359 | */ | ||
360 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout); | ||
361 | |||
362 | #endif | ||