aboutsummaryrefslogtreecommitdiffstats
path: root/include/sway/tree/container.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/sway/tree/container.h')
-rw-r--r--include/sway/tree/container.h192
1 files changed, 192 insertions, 0 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
new file mode 100644
index 00000000..2a8b8aba
--- /dev/null
+++ b/include/sway/tree/container.h
@@ -0,0 +1,192 @@
1#ifndef _SWAY_CONTAINER_H
2#define _SWAY_CONTAINER_H
3#include <stdint.h>
4#include <sys/types.h>
5#include <wlr/types/wlr_box.h>
6#include <wlr/types/wlr_surface.h>
7#include "list.h"
8
9extern struct sway_container root_container;
10
11struct sway_view;
12struct sway_seat;
13
14/**
15 * Different kinds of containers.
16 *
17 * This enum is in order. A container will never be inside of a container below
18 * it on this list.
19 */
20enum sway_container_type {
21 C_ROOT,
22 C_OUTPUT,
23 C_WORKSPACE,
24 C_CONTAINER,
25 C_VIEW,
26
27 // Keep last
28 C_TYPES,
29};
30
31enum sway_container_layout {
32 L_NONE,
33 L_HORIZ,
34 L_VERT,
35 L_STACKED,
36 L_TABBED,
37 L_FLOATING,
38};
39
40enum sway_container_border {
41 B_NONE,
42 B_PIXEL,
43 B_NORMAL,
44};
45
46struct sway_root;
47struct sway_output;
48struct sway_view;
49
50struct sway_container {
51 union {
52 // TODO: Encapsulate state for other node types as well like C_CONTAINER
53 struct sway_root *sway_root;
54 struct sway_output *sway_output;
55 struct sway_view *sway_view;
56 };
57
58 /**
59 * A unique ID to identify this container. Primarily used in the
60 * get_tree JSON output.
61 */
62 size_t id;
63
64 char *name;
65
66 enum sway_container_type type;
67 enum sway_container_layout layout;
68 enum sway_container_layout prev_layout;
69 enum sway_container_layout workspace_layout;
70
71 // For C_ROOT, this has no meaning
72 // For C_OUTPUT, this is the output position in layout coordinates
73 // For other types, this is the position in output-local coordinates
74 double x, y;
75 // does not include borders or gaps.
76 double width, height;
77
78 list_t *children;
79
80 struct sway_container *parent;
81
82 list_t *marks; // list of char*
83
84 float alpha;
85
86 struct {
87 struct wl_signal destroy;
88 // Raised after the tree updates, but before arrange_windows
89 // Passed the previous parent
90 struct wl_signal reparent;
91 } events;
92};
93
94struct sway_container *container_create(enum sway_container_type type);
95
96const char *container_type_to_str(enum sway_container_type type);
97
98struct sway_container *output_create(struct sway_output *sway_output);
99
100/**
101 * Create a new container container. A container container can be a a child of
102 * a workspace container or another container container.
103 */
104struct sway_container *container_container_create();
105
106/**
107 * Create a new output. Outputs are children of the root container and have no
108 * order in the tree structure.
109 */
110struct sway_container *output_create(struct sway_output *sway_output);
111
112/**
113 * Create a new workspace container. Workspaces are children of an output
114 * container and are ordered alphabetically by name.
115 */
116struct sway_container *workspace_create(struct sway_container *output,
117 const char *name);
118
119/*
120 * Create a new view container. A view can be a child of a workspace container
121 * or a container container and are rendered in the order and structure of
122 * how they are attached to the tree.
123 */
124struct sway_container *container_view_create(
125 struct sway_container *sibling, struct sway_view *sway_view);
126
127struct sway_container *container_destroy(struct sway_container *container);
128
129struct sway_container *container_close(struct sway_container *container);
130
131void container_descendants(struct sway_container *root,
132 enum sway_container_type type,
133 void (*func)(struct sway_container *item, void *data), void *data);
134
135/**
136 * Search a container's descendants a container based on test criteria. Returns
137 * the first container that passes the test.
138 */
139struct sway_container *container_find(struct sway_container *container,
140 bool (*test)(struct sway_container *view, void *data), void *data);
141
142/**
143 * Finds a parent container with the given struct sway_containerype.
144 */
145struct sway_container *container_parent(struct sway_container *container,
146 enum sway_container_type type);
147
148/**
149 * Find a container at the given coordinates. Returns the the surface and
150 * surface-local coordinates of the given layout coordinates if the container
151 * is a view and the view contains a surface at those coordinates.
152 */
153struct sway_container *container_at(struct sway_container *container,
154 double lx, double ly, struct wlr_surface **surface,
155 double *sx, double *sy);
156
157/**
158 * Apply the function for each descendant of the container breadth first.
159 */
160void container_for_each_descendant_bfs(struct sway_container *container,
161 void (*f)(struct sway_container *container, void *data), void *data);
162
163/**
164 * Apply the function for each child of the container depth first.
165 */
166void container_for_each_descendant_dfs(struct sway_container *container,
167 void (*f)(struct sway_container *container, void *data), void *data);
168
169/**
170 * Returns true if the given container is an ancestor of this container.
171 */
172bool container_has_anscestor(struct sway_container *container,
173 struct sway_container *anscestor);
174
175/**
176 * Returns true if the given container is a child descendant of this container.
177 */
178bool container_has_child(struct sway_container *con,
179 struct sway_container *child);
180
181void container_create_notify(struct sway_container *container);
182
183void container_damage_whole(struct sway_container *container);
184
185bool container_reap_empty(struct sway_container *con);
186
187struct sway_container *container_reap_empty_recursive(
188 struct sway_container *con);
189
190struct sway_container *container_flatten(struct sway_container *container);
191
192#endif