aboutsummaryrefslogtreecommitdiffstats
path: root/include/sway/tree/container.h
blob: 0dfed45558aa77f19d4b93f276afe7c607a9a2f1 (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
#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;

/**
 * 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,

	C_TYPES,
};

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

	// Keep last
	L_LAYOUTS,
};

enum sway_container_border {
	B_NONE,
	B_PIXEL,
	B_NORMAL,
};

struct sway_root;
struct sway_output;
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_view *sway_view;
	};

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

	char *name;

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

    // TODO convert to layout coordinates
	double x, y;

    // does not include borders or gaps.
	double width, height;

	list_t *children;

	struct sway_container *parent;

	list_t *marks; // list of char*

	struct {
		struct wl_signal destroy;
	} events;
};

// TODO only one container create function and pass the type?
struct sway_container *sway_container_output_create(
		struct sway_output *sway_output);

struct sway_container *sway_container_workspace_create(
		struct sway_container *output, const char *name);

struct sway_container *sway_container_view_create(
		struct sway_container *sibling, struct sway_view *sway_view);

struct sway_container *sway_container_output_destroy(
		struct sway_container *output);

struct sway_container *sway_container_view_destroy(struct sway_container *view);

struct sway_container *sway_container_set_layout(
		struct sway_container *container, enum sway_container_layout layout);

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

// XXX: what is this?
struct sway_container *next_view_sibling(struct sway_seat *seat);

/**
 * Finds a container based on test criteria. Returns the first container that
 * passes the test.
 */
struct sway_container *sway_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 *sway_container_parent(struct sway_container *container,
		enum sway_container_type type);

/**
 * Run a function for each child.
 */
void sway_container_for_each(struct sway_container *container,
		void (*f)(struct sway_container *view, void *data), void *data);

/**
 * Find a container at the given coordinates.
 */
struct sway_container *sway_container_at(struct sway_container *parent,
		double lx, double ly, struct wlr_surface **surface,
		double *sx, double *sy);

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

#endif