diff options
Diffstat (limited to 'include/sway/tree/container.h')
-rw-r--r-- | include/sway/tree/container.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h new file mode 100644 index 00000000..5a2ae349 --- /dev/null +++ b/include/sway/tree/container.h | |||
@@ -0,0 +1,136 @@ | |||
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 | |||
9 | typedef struct sway_container swayc_t; | ||
10 | |||
11 | extern swayc_t root_container; | ||
12 | |||
13 | struct sway_view; | ||
14 | struct sway_seat; | ||
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, | ||
24 | C_OUTPUT, | ||
25 | C_WORKSPACE, | ||
26 | C_CONTAINER, | ||
27 | C_VIEW, | ||
28 | |||
29 | C_TYPES, | ||
30 | }; | ||
31 | |||
32 | enum swayc_layouts { | ||
33 | L_NONE, | ||
34 | L_HORIZ, | ||
35 | L_VERT, | ||
36 | L_STACKED, | ||
37 | L_TABBED, | ||
38 | L_FLOATING, | ||
39 | |||
40 | // Keep last | ||
41 | L_LAYOUTS, | ||
42 | }; | ||
43 | |||
44 | enum swayc_border_types { | ||
45 | B_NONE, | ||
46 | B_PIXEL, | ||
47 | B_NORMAL, | ||
48 | }; | ||
49 | |||
50 | struct sway_root; | ||
51 | struct sway_output; | ||
52 | struct sway_view; | ||
53 | |||
54 | struct sway_container { | ||
55 | union { | ||
56 | // TODO: Encapsulate state for other node types as well like C_CONTAINER | ||
57 | struct sway_root *sway_root; | ||
58 | struct sway_output *sway_output; | ||
59 | struct sway_view *sway_view; | ||
60 | }; | ||
61 | |||
62 | /** | ||
63 | * A unique ID to identify this container. Primarily used in the | ||
64 | * get_tree JSON output. | ||
65 | */ | ||
66 | size_t id; | ||
67 | |||
68 | char *name; | ||
69 | |||
70 | enum swayc_types type; | ||
71 | enum swayc_layouts layout; | ||
72 | enum swayc_layouts prev_layout; | ||
73 | enum swayc_layouts workspace_layout; | ||
74 | |||
75 | // TODO convert to layout coordinates | ||
76 | double x, y; | ||
77 | |||
78 | // does not include borders or gaps. | ||
79 | double width, height; | ||
80 | |||
81 | list_t *children; | ||
82 | |||
83 | struct sway_container *parent; | ||
84 | |||
85 | list_t *marks; // list of char* | ||
86 | |||
87 | struct { | ||
88 | struct wl_signal destroy; | ||
89 | } events; | ||
90 | }; | ||
91 | |||
92 | void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | ||
93 | void (*func)(swayc_t *item, void *data), void *data); | ||
94 | |||
95 | // TODO only one container create function and pass the type? | ||
96 | swayc_t *new_output(struct sway_output *sway_output); | ||
97 | |||
98 | swayc_t *new_workspace(swayc_t *output, const char *name); | ||
99 | |||
100 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view); | ||
101 | |||
102 | swayc_t *destroy_output(swayc_t *output); | ||
103 | swayc_t *destroy_view(swayc_t *view); | ||
104 | |||
105 | swayc_t *next_view_sibling(struct sway_seat *seat); | ||
106 | |||
107 | /** | ||
108 | * Finds a container based on test criteria. Returns the first container that | ||
109 | * passes the test. | ||
110 | */ | ||
111 | swayc_t *swayc_by_test(swayc_t *container, | ||
112 | bool (*test)(swayc_t *view, void *data), void *data); | ||
113 | |||
114 | /** | ||
115 | * Finds a parent container with the given swayc_type. | ||
116 | */ | ||
117 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type); | ||
118 | |||
119 | /** | ||
120 | * Maps a container's children over a function. | ||
121 | */ | ||
122 | void container_map(swayc_t *container, | ||
123 | void (*f)(swayc_t *view, void *data), void *data); | ||
124 | |||
125 | swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | ||
126 | struct wlr_surface **surface, double *sx, double *sy); | ||
127 | |||
128 | /** | ||
129 | * Apply the function for each child of the container breadth first. | ||
130 | */ | ||
131 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | ||
132 | void *data); | ||
133 | |||
134 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout); | ||
135 | |||
136 | #endif | ||