diff options
author | 2018-03-30 00:02:29 -0400 | |
---|---|---|
committer | 2018-03-30 00:04:04 -0400 | |
commit | f26ecd9f58bb672fe107660ce9b37f4bf0777a8c (patch) | |
tree | 997658454de40db3f8b76b68d658efaf2b686188 /include/sway | |
parent | Early return from render functions if necessary (diff) | |
parent | Merge pull request #1654 from acrisci/refactor-2-electric-boogaloo (diff) | |
download | sway-f26ecd9f58bb672fe107660ce9b37f4bf0777a8c.tar.gz sway-f26ecd9f58bb672fe107660ce9b37f4bf0777a8c.tar.zst sway-f26ecd9f58bb672fe107660ce9b37f4bf0777a8c.zip |
Merge remote-tracking branch 'origin/wlroots' into swaybar-layers
Diffstat (limited to 'include/sway')
-rw-r--r-- | include/sway/config.h | 17 | ||||
-rw-r--r-- | include/sway/container.h | 169 | ||||
-rw-r--r-- | include/sway/criteria.h | 6 | ||||
-rw-r--r-- | include/sway/input/input-manager.h | 4 | ||||
-rw-r--r-- | include/sway/input/seat.h | 13 | ||||
-rw-r--r-- | include/sway/ipc-json.h | 6 | ||||
-rw-r--r-- | include/sway/ipc-server.h | 9 | ||||
-rw-r--r-- | include/sway/layout.h | 43 | ||||
-rw-r--r-- | include/sway/tree/container.h | 143 | ||||
-rw-r--r-- | include/sway/tree/layout.h | 52 | ||||
-rw-r--r-- | include/sway/tree/view.h (renamed from include/sway/view.h) | 4 | ||||
-rw-r--r-- | include/sway/tree/workspace.h | 26 | ||||
-rw-r--r-- | include/sway/workspace.h | 20 |
13 files changed, 251 insertions, 261 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index b7820128..ac1105b4 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -8,8 +8,8 @@ | |||
8 | #include <wlr/types/wlr_box.h> | 8 | #include <wlr/types/wlr_box.h> |
9 | #include <xkbcommon/xkbcommon.h> | 9 | #include <xkbcommon/xkbcommon.h> |
10 | #include "list.h" | 10 | #include "list.h" |
11 | #include "layout.h" | 11 | #include "tree/layout.h" |
12 | #include "container.h" | 12 | #include "tree/container.h" |
13 | #include "wlr-layer-shell-unstable-v1-protocol.h" | 13 | #include "wlr-layer-shell-unstable-v1-protocol.h" |
14 | 14 | ||
15 | // TODO: Refactor this shit | 15 | // TODO: Refactor this shit |
@@ -290,8 +290,8 @@ struct sway_config { | |||
290 | char *floating_scroll_down_cmd; | 290 | char *floating_scroll_down_cmd; |
291 | char *floating_scroll_left_cmd; | 291 | char *floating_scroll_left_cmd; |
292 | char *floating_scroll_right_cmd; | 292 | char *floating_scroll_right_cmd; |
293 | enum swayc_layouts default_orientation; | 293 | enum sway_container_layout default_orientation; |
294 | enum swayc_layouts default_layout; | 294 | enum sway_container_layout default_layout; |
295 | char *font; | 295 | char *font; |
296 | int font_height; | 296 | int font_height; |
297 | 297 | ||
@@ -315,8 +315,8 @@ struct sway_config { | |||
315 | list_t *config_chain; | 315 | list_t *config_chain; |
316 | const char *current_config; | 316 | const char *current_config; |
317 | 317 | ||
318 | enum swayc_border_types border; | 318 | enum sway_container_border border; |
319 | enum swayc_border_types floating_border; | 319 | enum sway_container_border floating_border; |
320 | int border_thickness; | 320 | int border_thickness; |
321 | int floating_border_thickness; | 321 | int floating_border_thickness; |
322 | enum edge_border_types hide_edge_borders; | 322 | enum edge_border_types hide_edge_borders; |
@@ -347,7 +347,7 @@ struct sway_config { | |||
347 | struct input_config *input_config; | 347 | struct input_config *input_config; |
348 | struct seat_config *seat_config; | 348 | struct seat_config *seat_config; |
349 | struct sway_seat *seat; | 349 | struct sway_seat *seat; |
350 | swayc_t *current_container; | 350 | struct sway_container *current_container; |
351 | } handler_context; | 351 | } handler_context; |
352 | }; | 352 | }; |
353 | 353 | ||
@@ -407,7 +407,8 @@ void output_get_identifier(char *identifier, size_t len, | |||
407 | struct sway_output *output); | 407 | struct sway_output *output); |
408 | struct output_config *new_output_config(const char *name); | 408 | struct output_config *new_output_config(const char *name); |
409 | void merge_output_config(struct output_config *dst, struct output_config *src); | 409 | void merge_output_config(struct output_config *dst, struct output_config *src); |
410 | void apply_output_config(struct output_config *oc, swayc_t *output); | 410 | void apply_output_config(struct output_config *oc, |
411 | struct sway_container *output); | ||
411 | void free_output_config(struct output_config *oc); | 412 | void free_output_config(struct output_config *oc); |
412 | 413 | ||
413 | int workspace_output_cmp_workspace(const void *a, const void *b); | 414 | int workspace_output_cmp_workspace(const void *a, const void *b); |
diff --git a/include/sway/container.h b/include/sway/container.h deleted file mode 100644 index f200a1a2..00000000 --- a/include/sway/container.h +++ /dev/null | |||
@@ -1,169 +0,0 @@ | |||
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, /**< The root container. Only one of these ever exists. */ | ||
24 | C_OUTPUT, /**< An output (aka monitor, head, etc). */ | ||
25 | C_WORKSPACE, /**< A workspace. */ | ||
26 | C_CONTAINER, /**< A manually created container. */ | ||
27 | C_VIEW, /**< A view (aka window). */ | ||
28 | |||
29 | C_TYPES, | ||
30 | }; | ||
31 | |||
32 | /** | ||
33 | * Different ways to arrange a container. | ||
34 | */ | ||
35 | enum swayc_layouts { | ||
36 | L_NONE, /**< Used for containers that have no layout (views, root) */ | ||
37 | L_HORIZ, | ||
38 | L_VERT, | ||
39 | L_STACKED, | ||
40 | L_TABBED, | ||
41 | L_FLOATING, /**< A psuedo-container, removed from the tree, to hold floating windows */ | ||
42 | |||
43 | /* Awesome/Monad style auto layouts */ | ||
44 | L_AUTO_LEFT, | ||
45 | L_AUTO_RIGHT, | ||
46 | L_AUTO_TOP, | ||
47 | L_AUTO_BOTTOM, | ||
48 | |||
49 | L_AUTO_FIRST = L_AUTO_LEFT, | ||
50 | L_AUTO_LAST = L_AUTO_BOTTOM, | ||
51 | |||
52 | // Keep last | ||
53 | L_LAYOUTS, | ||
54 | }; | ||
55 | |||
56 | enum swayc_border_types { | ||
57 | B_NONE, /**< No border */ | ||
58 | B_PIXEL, /**< 1px border */ | ||
59 | B_NORMAL, /**< Normal border with title bar */ | ||
60 | }; | ||
61 | |||
62 | struct sway_root; | ||
63 | struct sway_output; | ||
64 | struct sway_view; | ||
65 | |||
66 | /** | ||
67 | * Stores information about a container. | ||
68 | * | ||
69 | * The tree is made of these. Views are containers that cannot have children. | ||
70 | */ | ||
71 | struct sway_container { | ||
72 | union { | ||
73 | // TODO: Encapsulate state for other node types as well like C_CONTAINER | ||
74 | struct sway_root *sway_root; // C_ROOT | ||
75 | struct sway_output *sway_output; // C_OUTPUT | ||
76 | struct sway_view *sway_view; // C_VIEW | ||
77 | }; | ||
78 | |||
79 | /** | ||
80 | * A unique ID to identify this container. Primarily used in the | ||
81 | * get_tree JSON output. | ||
82 | */ | ||
83 | size_t id; | ||
84 | |||
85 | char *name; | ||
86 | |||
87 | enum swayc_types type; | ||
88 | enum swayc_layouts layout; | ||
89 | enum swayc_layouts prev_layout; | ||
90 | enum swayc_layouts workspace_layout; | ||
91 | |||
92 | /** | ||
93 | * The coordinates that this view appear at, relative to the output they | ||
94 | * are located on (output containers have absolute coordinates). | ||
95 | */ | ||
96 | double x, y; | ||
97 | |||
98 | /** | ||
99 | * Width and height of this container, without borders or gaps. | ||
100 | */ | ||
101 | double width, height; | ||
102 | |||
103 | list_t *children; | ||
104 | |||
105 | /** | ||
106 | * The parent of this container. NULL for the root container. | ||
107 | */ | ||
108 | struct sway_container *parent; | ||
109 | |||
110 | /** | ||
111 | * Number of master views in auto layouts. | ||
112 | */ | ||
113 | size_t nb_master; | ||
114 | |||
115 | /** | ||
116 | * Number of slave groups (e.g. columns) in auto layouts. | ||
117 | */ | ||
118 | size_t nb_slave_groups; | ||
119 | |||
120 | /** | ||
121 | * Marks applied to the container, list_t of char*. | ||
122 | */ | ||
123 | list_t *marks; | ||
124 | |||
125 | struct { | ||
126 | struct wl_signal destroy; | ||
127 | } events; | ||
128 | }; | ||
129 | |||
130 | void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | ||
131 | void (*func)(swayc_t *item, void *data), void *data); | ||
132 | |||
133 | swayc_t *new_output(struct sway_output *sway_output); | ||
134 | swayc_t *new_workspace(swayc_t *output, const char *name); | ||
135 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view); | ||
136 | |||
137 | swayc_t *destroy_output(swayc_t *output); | ||
138 | swayc_t *destroy_view(swayc_t *view); | ||
139 | |||
140 | swayc_t *next_view_sibling(struct sway_seat *seat); | ||
141 | |||
142 | /** | ||
143 | * Finds a container based on test criteria. Returns the first container that | ||
144 | * passes the test. | ||
145 | */ | ||
146 | swayc_t *swayc_by_test(swayc_t *container, | ||
147 | bool (*test)(swayc_t *view, void *data), void *data); | ||
148 | /** | ||
149 | * Finds a parent container with the given swayc_type. | ||
150 | */ | ||
151 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type); | ||
152 | /** | ||
153 | * Maps a container's children over a function. | ||
154 | */ | ||
155 | void container_map(swayc_t *container, | ||
156 | void (*f)(swayc_t *view, void *data), void *data); | ||
157 | |||
158 | swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | ||
159 | struct wlr_surface **surface, double *sx, double *sy); | ||
160 | |||
161 | /** | ||
162 | * Apply the function for each child of the container breadth first. | ||
163 | */ | ||
164 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | ||
165 | void *data); | ||
166 | |||
167 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout); | ||
168 | |||
169 | #endif | ||
diff --git a/include/sway/criteria.h b/include/sway/criteria.h index 9b4b4bef..ec256ddb 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h | |||
@@ -1,7 +1,7 @@ | |||
1 | #ifndef _SWAY_CRITERIA_H | 1 | #ifndef _SWAY_CRITERIA_H |
2 | #define _SWAY_CRITERIA_H | 2 | #define _SWAY_CRITERIA_H |
3 | 3 | ||
4 | #include "container.h" | 4 | #include "tree/container.h" |
5 | #include "list.h" | 5 | #include "list.h" |
6 | 6 | ||
7 | /** | 7 | /** |
@@ -31,12 +31,12 @@ char *extract_crit_tokens(list_t *tokens, const char *criteria); | |||
31 | 31 | ||
32 | // Returns list of criteria that match given container. These criteria have | 32 | // Returns list of criteria that match given container. These criteria have |
33 | // been set with `for_window` commands and have an associated cmdlist. | 33 | // been set with `for_window` commands and have an associated cmdlist. |
34 | list_t *criteria_for(swayc_t *cont); | 34 | list_t *criteria_for(struct sway_container *cont); |
35 | 35 | ||
36 | // Returns a list of all containers that match the given list of tokens. | 36 | // Returns a list of all containers that match the given list of tokens. |
37 | list_t *container_for_crit_tokens(list_t *tokens); | 37 | list_t *container_for_crit_tokens(list_t *tokens); |
38 | 38 | ||
39 | // Returns true if any criteria in the given list matches this container | 39 | // Returns true if any criteria in the given list matches this container |
40 | bool criteria_any(swayc_t *cont, list_t *criteria); | 40 | bool criteria_any(struct sway_container *cont, list_t *criteria); |
41 | 41 | ||
42 | #endif | 42 | #endif |
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index eab7dc90..c6c73dba 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h | |||
@@ -31,10 +31,10 @@ struct sway_input_manager *sway_input_manager_create( | |||
31 | struct sway_server *server); | 31 | struct sway_server *server); |
32 | 32 | ||
33 | bool sway_input_manager_has_focus(struct sway_input_manager *input, | 33 | bool sway_input_manager_has_focus(struct sway_input_manager *input, |
34 | swayc_t *container); | 34 | struct sway_container *container); |
35 | 35 | ||
36 | void sway_input_manager_set_focus(struct sway_input_manager *input, | 36 | void sway_input_manager_set_focus(struct sway_input_manager *input, |
37 | swayc_t *container); | 37 | struct sway_container *container); |
38 | 38 | ||
39 | void sway_input_manager_configure_xcursor(struct sway_input_manager *input); | 39 | void sway_input_manager_configure_xcursor(struct sway_input_manager *input); |
40 | 40 | ||
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 1d55bec7..496bfd5d 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h | |||
@@ -14,7 +14,7 @@ struct sway_seat_device { | |||
14 | 14 | ||
15 | struct sway_seat_container { | 15 | struct sway_seat_container { |
16 | struct sway_seat *seat; | 16 | struct sway_seat *seat; |
17 | swayc_t *container; | 17 | struct sway_container *container; |
18 | 18 | ||
19 | struct wl_list link; // sway_seat::focus_stack | 19 | struct wl_list link; // sway_seat::focus_stack |
20 | 20 | ||
@@ -54,9 +54,9 @@ void sway_seat_remove_device(struct sway_seat *seat, | |||
54 | 54 | ||
55 | void sway_seat_configure_xcursor(struct sway_seat *seat); | 55 | void sway_seat_configure_xcursor(struct sway_seat *seat); |
56 | 56 | ||
57 | void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container); | 57 | void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container); |
58 | 58 | ||
59 | swayc_t *sway_seat_get_focus(struct sway_seat *seat); | 59 | struct sway_container *sway_seat_get_focus(struct sway_seat *seat); |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Return the last container to be focused for the seat (or the most recently | 62 | * Return the last container to be focused for the seat (or the most recently |
@@ -67,10 +67,11 @@ swayc_t *sway_seat_get_focus(struct sway_seat *seat); | |||
67 | * is destroyed, or focus moves to a container with children and we need to | 67 | * is destroyed, or focus moves to a container with children and we need to |
68 | * descend into the next leaf in focus order. | 68 | * descend into the next leaf in focus order. |
69 | */ | 69 | */ |
70 | swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container); | 70 | struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, |
71 | struct sway_container *container); | ||
71 | 72 | ||
72 | swayc_t *sway_seat_get_focus_by_type(struct sway_seat *seat, | 73 | struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, |
73 | enum swayc_types type); | 74 | enum sway_container_type type); |
74 | 75 | ||
75 | void sway_seat_set_config(struct sway_seat *seat, struct seat_config *seat_config); | 76 | void sway_seat_set_config(struct sway_seat *seat, struct seat_config *seat_config); |
76 | 77 | ||
diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h index 19c5b5bc..7d87d377 100644 --- a/include/sway/ipc-json.h +++ b/include/sway/ipc-json.h | |||
@@ -1,13 +1,13 @@ | |||
1 | #ifndef _SWAY_IPC_JSON_H | 1 | #ifndef _SWAY_IPC_JSON_H |
2 | #define _SWAY_IPC_JSON_H | 2 | #define _SWAY_IPC_JSON_H |
3 | #include <json-c/json.h> | 3 | #include <json-c/json.h> |
4 | #include "sway/container.h" | 4 | #include "sway/tree/container.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | 6 | ||
7 | json_object *ipc_json_get_version(); | 7 | json_object *ipc_json_get_version(); |
8 | 8 | ||
9 | json_object *ipc_json_describe_container(swayc_t *c); | 9 | json_object *ipc_json_describe_container(struct sway_container *c); |
10 | json_object *ipc_json_describe_container_recursive(swayc_t *c); | 10 | json_object *ipc_json_describe_container_recursive(struct sway_container *c); |
11 | json_object *ipc_json_describe_input(struct sway_input_device *device); | 11 | json_object *ipc_json_describe_input(struct sway_input_device *device); |
12 | json_object *ipc_json_describe_bar_config(struct bar_config *bar); | 12 | json_object *ipc_json_describe_bar_config(struct bar_config *bar); |
13 | 13 | ||
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index b4db75c3..c3389fe8 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h | |||
@@ -1,17 +1,20 @@ | |||
1 | #ifndef _SWAY_IPC_SERVER_H | 1 | #ifndef _SWAY_IPC_SERVER_H |
2 | #define _SWAY_IPC_SERVER_H | 2 | #define _SWAY_IPC_SERVER_H |
3 | #include <sys/socket.h> | 3 | #include <sys/socket.h> |
4 | #include "sway/container.h" | 4 | #include "sway/tree/container.h" |
5 | #include "ipc.h" | 5 | #include "ipc.h" |
6 | 6 | ||
7 | struct sway_server; | 7 | struct sway_server; |
8 | 8 | ||
9 | void ipc_init(struct sway_server *server); | 9 | void ipc_init(struct sway_server *server); |
10 | |||
10 | void ipc_terminate(void); | 11 | void ipc_terminate(void); |
12 | |||
11 | struct sockaddr_un *ipc_user_sockaddr(void); | 13 | struct sockaddr_un *ipc_user_sockaddr(void); |
12 | 14 | ||
13 | void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change); | 15 | void ipc_event_workspace(struct sway_container *old, |
14 | void ipc_event_window(swayc_t *window, const char *change); | 16 | struct sway_container *new, const char *change); |
17 | void ipc_event_window(struct sway_container *window, const char *change); | ||
15 | void ipc_event_barconfig_update(struct bar_config *bar); | 18 | void ipc_event_barconfig_update(struct bar_config *bar); |
16 | void ipc_event_mode(const char *mode); | 19 | void ipc_event_mode(const char *mode); |
17 | 20 | ||
diff --git a/include/sway/layout.h b/include/sway/layout.h deleted file mode 100644 index e82c4442..00000000 --- a/include/sway/layout.h +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | #ifndef _SWAY_LAYOUT_H | ||
2 | #define _SWAY_LAYOUT_H | ||
3 | |||
4 | #include <wlr/types/wlr_output_layout.h> | ||
5 | #include "sway/container.h" | ||
6 | |||
7 | enum movement_direction { | ||
8 | MOVE_LEFT, | ||
9 | MOVE_RIGHT, | ||
10 | MOVE_UP, | ||
11 | MOVE_DOWN, | ||
12 | MOVE_PARENT, | ||
13 | MOVE_CHILD, | ||
14 | MOVE_NEXT, | ||
15 | MOVE_PREV, | ||
16 | MOVE_FIRST | ||
17 | }; | ||
18 | |||
19 | struct sway_container; | ||
20 | |||
21 | struct sway_root { | ||
22 | struct wlr_output_layout *output_layout; | ||
23 | |||
24 | struct wl_listener output_layout_change; | ||
25 | |||
26 | struct wl_list unmanaged_views; // sway_view::unmanaged_view_link | ||
27 | |||
28 | struct { | ||
29 | struct wl_signal new_container; | ||
30 | } events; | ||
31 | }; | ||
32 | |||
33 | void init_layout(void); | ||
34 | void add_child(struct sway_container *parent, struct sway_container *child); | ||
35 | swayc_t *add_sibling(swayc_t *parent, swayc_t *child); | ||
36 | struct sway_container *remove_child(struct sway_container *child); | ||
37 | enum swayc_layouts default_layout(struct sway_container *output); | ||
38 | void sort_workspaces(struct sway_container *output); | ||
39 | void arrange_windows(struct sway_container *container, double width, double height); | ||
40 | swayc_t *get_swayc_in_direction(swayc_t *container, | ||
41 | struct sway_seat *seat, enum movement_direction dir); | ||
42 | |||
43 | #endif | ||
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h new file mode 100644 index 00000000..3bb497db --- /dev/null +++ b/include/sway/tree/container.h | |||
@@ -0,0 +1,143 @@ | |||
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 | extern struct sway_container root_container; | ||
10 | |||
11 | struct sway_view; | ||
12 | struct 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 | */ | ||
20 | enum sway_container_type { | ||
21 | C_ROOT, | ||
22 | C_OUTPUT, | ||
23 | C_WORKSPACE, | ||
24 | C_CONTAINER, | ||
25 | C_VIEW, | ||
26 | |||
27 | C_TYPES, | ||
28 | }; | ||
29 | |||
30 | enum sway_container_layout { | ||
31 | L_NONE, | ||
32 | L_HORIZ, | ||
33 | L_VERT, | ||
34 | L_STACKED, | ||
35 | L_TABBED, | ||
36 | L_FLOATING, | ||
37 | |||
38 | // Keep last | ||
39 | L_LAYOUTS, | ||
40 | }; | ||
41 | |||
42 | enum sway_container_border { | ||
43 | B_NONE, | ||
44 | B_PIXEL, | ||
45 | B_NORMAL, | ||
46 | }; | ||
47 | |||
48 | struct sway_root; | ||
49 | struct sway_output; | ||
50 | struct sway_view; | ||
51 | |||
52 | struct sway_container { | ||
53 | union { | ||
54 | // TODO: Encapsulate state for other node types as well like C_CONTAINER | ||
55 | struct sway_root *sway_root; | ||
56 | struct sway_output *sway_output; | ||
57 | struct sway_view *sway_view; | ||
58 | }; | ||
59 | |||
60 | /** | ||
61 | * A unique ID to identify this container. Primarily used in the | ||
62 | * get_tree JSON output. | ||
63 | */ | ||
64 | size_t id; | ||
65 | |||
66 | char *name; | ||
67 | |||
68 | enum sway_container_type type; | ||
69 | enum sway_container_layout layout; | ||
70 | enum sway_container_layout prev_layout; | ||
71 | enum sway_container_layout workspace_layout; | ||
72 | |||
73 | // TODO convert to layout coordinates | ||
74 | double x, y; | ||
75 | |||
76 | // does not include borders or gaps. | ||
77 | double width, height; | ||
78 | |||
79 | list_t *children; | ||
80 | |||
81 | struct sway_container *parent; | ||
82 | |||
83 | list_t *marks; // list of char* | ||
84 | |||
85 | struct { | ||
86 | struct wl_signal destroy; | ||
87 | } events; | ||
88 | }; | ||
89 | |||
90 | // TODO only one container create function and pass the type? | ||
91 | struct sway_container *container_output_create( | ||
92 | struct sway_output *sway_output); | ||
93 | |||
94 | struct sway_container *container_workspace_create( | ||
95 | struct sway_container *output, const char *name); | ||
96 | |||
97 | struct sway_container *container_view_create( | ||
98 | struct sway_container *sibling, struct sway_view *sway_view); | ||
99 | |||
100 | struct sway_container *container_output_destroy(struct sway_container *output); | ||
101 | |||
102 | struct sway_container *container_view_destroy(struct sway_container *view); | ||
103 | |||
104 | struct sway_container *container_set_layout(struct sway_container *container, | ||
105 | enum sway_container_layout layout); | ||
106 | |||
107 | void container_descendants(struct sway_container *root, | ||
108 | enum sway_container_type type, | ||
109 | void (*func)(struct sway_container *item, void *data), void *data); | ||
110 | |||
111 | /** | ||
112 | * Finds a container based on test criteria. Returns the first container that | ||
113 | * passes the test. | ||
114 | */ | ||
115 | struct sway_container *container_find(struct sway_container *container, | ||
116 | bool (*test)(struct sway_container *view, void *data), void *data); | ||
117 | |||
118 | /** | ||
119 | * Finds a parent container with the given struct sway_containerype. | ||
120 | */ | ||
121 | struct sway_container *container_parent(struct sway_container *container, | ||
122 | enum sway_container_type type); | ||
123 | |||
124 | /** | ||
125 | * Find a container at the given coordinates. | ||
126 | */ | ||
127 | struct sway_container *container_at(struct sway_container *parent, | ||
128 | double lx, double ly, struct wlr_surface **surface, | ||
129 | double *sx, double *sy); | ||
130 | |||
131 | /** | ||
132 | * Apply the function for each child of the container breadth first. | ||
133 | */ | ||
134 | void container_for_each_descendant_bfs(struct sway_container *container, | ||
135 | void (*f)(struct sway_container *container, void *data), void *data); | ||
136 | |||
137 | /** | ||
138 | * Apply the function for each child of the container depth first. | ||
139 | */ | ||
140 | void container_for_each_descendant_dfs(struct sway_container *container, | ||
141 | void (*f)(struct sway_container *container, void *data), void *data); | ||
142 | |||
143 | #endif | ||
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h new file mode 100644 index 00000000..ad52bdb0 --- /dev/null +++ b/include/sway/tree/layout.h | |||
@@ -0,0 +1,52 @@ | |||
1 | #ifndef _SWAY_LAYOUT_H | ||
2 | #define _SWAY_LAYOUT_H | ||
3 | |||
4 | #include <wlr/types/wlr_output_layout.h> | ||
5 | #include "sway/tree/container.h" | ||
6 | |||
7 | enum movement_direction { | ||
8 | MOVE_LEFT, | ||
9 | MOVE_RIGHT, | ||
10 | MOVE_UP, | ||
11 | MOVE_DOWN, | ||
12 | MOVE_PARENT, | ||
13 | MOVE_CHILD, | ||
14 | MOVE_NEXT, | ||
15 | MOVE_PREV, | ||
16 | MOVE_FIRST | ||
17 | }; | ||
18 | |||
19 | struct sway_container; | ||
20 | |||
21 | struct sway_root { | ||
22 | struct wlr_output_layout *output_layout; | ||
23 | |||
24 | struct wl_listener output_layout_change; | ||
25 | |||
26 | struct wl_list unmanaged_views; // sway_view::unmanaged_view_link | ||
27 | |||
28 | struct { | ||
29 | struct wl_signal new_container; | ||
30 | } events; | ||
31 | }; | ||
32 | |||
33 | void layout_init(void); | ||
34 | |||
35 | void container_add_child(struct sway_container *parent, struct sway_container *child); | ||
36 | |||
37 | struct sway_container *container_add_sibling(struct sway_container *parent, | ||
38 | struct sway_container *child); | ||
39 | |||
40 | struct sway_container *container_remove_child(struct sway_container *child); | ||
41 | |||
42 | enum sway_container_layout container_get_default_layout(struct sway_container *output); | ||
43 | |||
44 | void container_sort_workspaces(struct sway_container *output); | ||
45 | |||
46 | void arrange_windows(struct sway_container *container, | ||
47 | double width, double height); | ||
48 | |||
49 | struct sway_container *container_get_in_direction(struct sway_container | ||
50 | *container, struct sway_seat *seat, enum movement_direction dir); | ||
51 | |||
52 | #endif | ||
diff --git a/include/sway/view.h b/include/sway/tree/view.h index b2886211..e5f53f4e 100644 --- a/include/sway/view.h +++ b/include/sway/tree/view.h | |||
@@ -62,10 +62,6 @@ enum sway_view_prop { | |||
62 | VIEW_PROP_INSTANCE, | 62 | VIEW_PROP_INSTANCE, |
63 | }; | 63 | }; |
64 | 64 | ||
65 | /** | ||
66 | * sway_view is a state container for surfaces that are arranged in the sway | ||
67 | * tree (shell surfaces). | ||
68 | */ | ||
69 | struct sway_view { | 65 | struct sway_view { |
70 | enum sway_view_type type; | 66 | enum sway_view_type type; |
71 | struct sway_container *swayc; | 67 | struct sway_container *swayc; |
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h new file mode 100644 index 00000000..d73b29c1 --- /dev/null +++ b/include/sway/tree/workspace.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef _SWAY_WORKSPACE_H | ||
2 | #define _SWAY_WORKSPACE_H | ||
3 | |||
4 | #include "sway/tree/container.h" | ||
5 | |||
6 | extern char *prev_workspace_name; | ||
7 | |||
8 | char *workspace_next_name(const char *output_name); | ||
9 | |||
10 | struct sway_container *workspace_create(const char *name); | ||
11 | |||
12 | bool workspace_switch(struct sway_container *workspace); | ||
13 | |||
14 | struct sway_container *workspace_by_number(const char* name); | ||
15 | |||
16 | struct sway_container *workspace_by_name(const char*); | ||
17 | |||
18 | struct sway_container *workspace_output_next(struct sway_container *current); | ||
19 | |||
20 | struct sway_container *workspace_next(struct sway_container *current); | ||
21 | |||
22 | struct sway_container *workspace_output_prev(struct sway_container *current); | ||
23 | |||
24 | struct sway_container *workspace_prev(struct sway_container *current); | ||
25 | |||
26 | #endif | ||
diff --git a/include/sway/workspace.h b/include/sway/workspace.h deleted file mode 100644 index fee54255..00000000 --- a/include/sway/workspace.h +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | #ifndef _SWAY_WORKSPACE_H | ||
2 | #define _SWAY_WORKSPACE_H | ||
3 | |||
4 | #include "sway/container.h" | ||
5 | |||
6 | extern char *prev_workspace_name; | ||
7 | |||
8 | char *workspace_next_name(const char *output_name); | ||
9 | swayc_t *workspace_create(const char *name); | ||
10 | bool workspace_switch(swayc_t *workspace); | ||
11 | |||
12 | struct sway_container *workspace_by_number(const char* name); | ||
13 | swayc_t *workspace_by_name(const char*); | ||
14 | |||
15 | struct sway_container *workspace_output_next(swayc_t *current); | ||
16 | struct sway_container *workspace_next(swayc_t *current); | ||
17 | struct sway_container *workspace_output_prev(swayc_t *current); | ||
18 | struct sway_container *workspace_prev(swayc_t *current); | ||
19 | |||
20 | #endif | ||