aboutsummaryrefslogtreecommitdiffstats
path: root/include/sway/tree/container.h
blob: 7ed6aab1a5b788b2f70e5c0b34d2fb6c8469c09f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#ifndef _SWAY_CONTAINER_H
#define _SWAY_CONTAINER_H
#include <stdint.h>
#include <sys/types.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_surface.h>
#include "list.h"

extern struct sway_container root_container;

struct sway_view;
struct sway_seat;

#define TITLEBAR_BORDER_THICKNESS 1

// Padding includes titlebar border
#define TITLEBAR_H_PADDING 3
#define TITLEBAR_V_PADDING 4

/**
 * Different kinds of containers.
 *
 * This enum is in order. A container will never be inside of a container below
 * it on this list.
 */
enum sway_container_type {
	C_ROOT,
	C_OUTPUT,
	C_WORKSPACE,
	C_CONTAINER,
	C_VIEW,

	// Keep last
	C_TYPES,
};

enum sway_container_layout {
	L_NONE,
	L_HORIZ,
	L_VERT,
	L_STACKED,
	L_TABBED,
	L_FLOATING,
};

enum sway_container_border {
	B_NONE,
	B_PIXEL,
	B_NORMAL,
};

struct sway_root;
struct sway_output;
struct sway_workspace;
struct sway_view;

struct sway_container {
	union {
		// TODO: Encapsulate state for other node types as well like C_CONTAINER
		struct sway_root *sway_root;
		struct sway_output *sway_output;
		struct sway_workspace *sway_workspace;
		struct sway_view *sway_view;
	};

	/**
	 * A unique ID to identify this container. Primarily used in the
	 * get_tree JSON output.
	 */
	size_t id;

	char *name;            // The view's title (unformatted)
	char *formatted_title; // The title displayed in the title bar

	enum sway_container_type type;
	enum sway_container_layout layout;
	enum sway_container_layout prev_layout;

	bool is_sticky;

	// For C_ROOT, this has no meaning
	// For other types, this is the position in layout coordinates
	// Includes borders
	double x, y;
	double width, height;
	double saved_x, saved_y;
	double saved_width, saved_height;

	list_t *children;

	struct sway_container *parent;

	list_t *marks; // list of char*

	float alpha;

	struct wlr_texture *title_focused;
	struct wlr_texture *title_focused_inactive;
	struct wlr_texture *title_unfocused;
	struct wlr_texture *title_urgent;
	size_t title_height;

	struct {
		struct wl_signal destroy;
		// Raised after the tree updates, but before arrange_windows
		// Passed the previous parent
		struct wl_signal reparent;
	} events;

	struct wl_listener reparent;
};

struct sway_container *container_create(enum sway_container_type type);

const char *container_type_to_str(enum sway_container_type type);

struct sway_container *output_create(struct sway_output *sway_output);

/**
 * Create a new container container. A container container can be a a child of
 * a workspace container or another container container.
 */
struct sway_container *container_container_create();

/**
 * Create a new output. Outputs are children of the root container and have no
 * order in the tree structure.
 */
struct sway_container *output_create(struct sway_output *sway_output);

/**
 * Create a new workspace container. Workspaces are children of an output
 * container and are ordered alphabetically by name.
 */
struct sway_container *workspace_create(struct sway_container *output,
		const char *name);

/*
 * Create a new view container. A view can be a child of a workspace container
 * or a container container and are rendered in the order and structure of
 * how they are attached to the tree.
 */
struct sway_container *container_view_create(
		struct sway_container *sibling, struct sway_view *sway_view);

struct sway_container *container_destroy(struct sway_container *container);

struct sway_container *container_close(struct sway_container *container);

void container_descendants(struct sway_container *root,
		enum sway_container_type type,
		void (*func)(struct sway_container *item, void *data), void *data);

/**
 * Search a container's descendants a container based on test criteria. Returns
 * the first container that passes the test.
 */
struct sway_container *container_find(struct sway_container *container,
		bool (*test)(struct sway_container *view, void *data), void *data);

/**
 * Finds a parent container with the given struct sway_containerype.
 */
struct sway_container *container_parent(struct sway_container *container,
		enum sway_container_type type);

/**
 * Find a container at the given coordinates. Returns the the surface and
 * surface-local coordinates of the given layout coordinates if the container
 * is a view and the view contains a surface at those coordinates.
 */
struct sway_container *container_at(struct sway_container *container,
		double ox, double oy, struct wlr_surface **surface,
		double *sx, double *sy);

/**
 * Same as container_at, but only checks floating views and expects coordinates
 * to be layout coordinates, as that's what floating views use.
 */
struct sway_container *floating_container_at(double lx, double ly,
		struct wlr_surface **surface, double *sx, double *sy);

/**
 * Apply the function for each descendant of the container breadth first.
 */
void container_for_each_descendant_bfs(struct sway_container *container,
		void (*f)(struct sway_container *container, void *data), void *data);

/**
 * Apply the function for each child of the container depth first.
 */
void container_for_each_descendant_dfs(struct sway_container *container,
		void (*f)(struct sway_container *container, void *data), void *data);

/**
 * Returns true if the given container is an ancestor of this container.
 */
bool container_has_ancestor(struct sway_container *container,
		struct sway_container *ancestor);

/**
 * Returns true if the given container is a child descendant of this container.
 */
bool container_has_child(struct sway_container *con,
		struct sway_container *child);

int container_count_descendants_of_type(struct sway_container *con,
		enum sway_container_type type);

void container_create_notify(struct sway_container *container);

void container_damage_whole(struct sway_container *container);

bool container_reap_empty(struct sway_container *con);

struct sway_container *container_reap_empty_recursive(
		struct sway_container *con);

struct sway_container *container_flatten(struct sway_container *container);

void container_update_title_textures(struct sway_container *container);

/**
 * Calculate the container's title_height property.
 */
void container_calculate_title_height(struct sway_container *container);

/**
 * Notify a container that a tree modification has changed in its children,
 * so the container can update its tree representation.
 */
void container_notify_subtree_changed(struct sway_container *container);

/**
 * Return the height of a regular title bar.
 */
size_t container_titlebar_height(void);

void container_set_floating(struct sway_container *container, bool enable);

void container_set_geometry_from_floating_view(struct sway_container *con);

/**
 * Determine if the given container is itself floating.
 * This will return false for any descendants of a floating container.
 */
bool container_is_floating(struct sway_container *container);

#endif