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