diff options
39 files changed, 593 insertions, 588 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 48a8b0ab..7fdd0be0 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -10,8 +10,8 @@ | |||
10 | #include <xkbcommon/xkbcommon.h> | 10 | #include <xkbcommon/xkbcommon.h> |
11 | #include <time.h> | 11 | #include <time.h> |
12 | #include "list.h" | 12 | #include "list.h" |
13 | #include "layout.h" | 13 | #include "tree/layout.h" |
14 | #include "container.h" | 14 | #include "tree/container.h" |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * Describes a variable created via the `set` command. | 17 | * Describes a variable created via the `set` command. |
@@ -299,8 +299,8 @@ struct sway_config { | |||
299 | char *floating_scroll_down_cmd; | 299 | char *floating_scroll_down_cmd; |
300 | char *floating_scroll_left_cmd; | 300 | char *floating_scroll_left_cmd; |
301 | char *floating_scroll_right_cmd; | 301 | char *floating_scroll_right_cmd; |
302 | enum swayc_layouts default_orientation; | 302 | enum sway_container_layout default_orientation; |
303 | enum swayc_layouts default_layout; | 303 | enum sway_container_layout default_layout; |
304 | char *font; | 304 | char *font; |
305 | int font_height; | 305 | int font_height; |
306 | 306 | ||
@@ -324,8 +324,8 @@ struct sway_config { | |||
324 | list_t *config_chain; | 324 | list_t *config_chain; |
325 | const char *current_config; | 325 | const char *current_config; |
326 | 326 | ||
327 | enum swayc_border_types border; | 327 | enum sway_container_border border; |
328 | enum swayc_border_types floating_border; | 328 | enum sway_container_border floating_border; |
329 | int border_thickness; | 329 | int border_thickness; |
330 | int floating_border_thickness; | 330 | int floating_border_thickness; |
331 | enum edge_border_types hide_edge_borders; | 331 | enum edge_border_types hide_edge_borders; |
@@ -356,7 +356,7 @@ struct sway_config { | |||
356 | struct input_config *input_config; | 356 | struct input_config *input_config; |
357 | struct seat_config *seat_config; | 357 | struct seat_config *seat_config; |
358 | struct sway_seat *seat; | 358 | struct sway_seat *seat; |
359 | swayc_t *current_container; | 359 | struct sway_container *current_container; |
360 | } handler_context; | 360 | } handler_context; |
361 | }; | 361 | }; |
362 | 362 | ||
@@ -416,7 +416,8 @@ void output_get_identifier(char *identifier, size_t len, | |||
416 | struct sway_output *output); | 416 | struct sway_output *output); |
417 | struct output_config *new_output_config(const char *name); | 417 | struct output_config *new_output_config(const char *name); |
418 | void merge_output_config(struct output_config *dst, struct output_config *src); | 418 | void merge_output_config(struct output_config *dst, struct output_config *src); |
419 | void apply_output_config(struct output_config *oc, swayc_t *output); | 419 | void apply_output_config(struct output_config *oc, |
420 | struct sway_container *output); | ||
420 | void free_output_config(struct output_config *oc); | 421 | void free_output_config(struct output_config *oc); |
421 | 422 | ||
422 | /** | 423 | /** |
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 eef5a018..3d2fdc4f 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 | 12 | ||
13 | #endif | 13 | #endif |
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index bcf1c433..d73006dc 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h | |||
@@ -1,15 +1,17 @@ | |||
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_window(swayc_t *window, const char *change); | 15 | void ipc_event_window(struct sway_container *window, const char *change); |
14 | 16 | ||
15 | #endif | 17 | #endif |
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..16df3ee7 --- /dev/null +++ b/include/sway/tree/container.h | |||
@@ -0,0 +1,137 @@ | |||
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_descendents(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_descendent(struct sway_container *container, | ||
135 | void (*f)(struct sway_container *container, void *data), void *data); | ||
136 | |||
137 | #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 | ||
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 61870c51..954950e7 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c | |||
@@ -6,8 +6,8 @@ | |||
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
8 | #include "sway/config.h" | 8 | #include "sway/config.h" |
9 | #include "sway/container.h" | 9 | #include "sway/tree/container.h" |
10 | #include "sway/workspace.h" | 10 | #include "sway/tree/workspace.h" |
11 | #include "log.h" | 11 | #include "log.h" |
12 | #include "stringop.h" | 12 | #include "stringop.h" |
13 | 13 | ||
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index f1a8078f..64f079f4 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -3,10 +3,11 @@ | |||
3 | #include "log.h" | 3 | #include "log.h" |
4 | #include "sway/input/input-manager.h" | 4 | #include "sway/input/input-manager.h" |
5 | #include "sway/input/seat.h" | 5 | #include "sway/input/seat.h" |
6 | #include "sway/view.h" | 6 | #include "sway/tree/view.h" |
7 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
8 | 8 | ||
9 | static bool parse_movement_direction(const char *name, enum movement_direction *out) { | 9 | static bool parse_movement_direction(const char *name, |
10 | enum movement_direction *out) { | ||
10 | if (strcasecmp(name, "left") == 0) { | 11 | if (strcasecmp(name, "left") == 0) { |
11 | *out = MOVE_LEFT; | 12 | *out = MOVE_LEFT; |
12 | } else if (strcasecmp(name, "right") == 0) { | 13 | } else if (strcasecmp(name, "right") == 0) { |
@@ -31,7 +32,7 @@ static bool parse_movement_direction(const char *name, enum movement_direction * | |||
31 | } | 32 | } |
32 | 33 | ||
33 | struct cmd_results *cmd_focus(int argc, char **argv) { | 34 | struct cmd_results *cmd_focus(int argc, char **argv) { |
34 | swayc_t *con = config->handler_context.current_container; | 35 | struct sway_container *con = config->handler_context.current_container; |
35 | struct sway_seat *seat = config->handler_context.seat; | 36 | struct sway_seat *seat = config->handler_context.seat; |
36 | if (con->type < C_WORKSPACE) { | 37 | if (con->type < C_WORKSPACE) { |
37 | return cmd_results_new(CMD_FAILURE, "focus", | 38 | return cmd_results_new(CMD_FAILURE, "focus", |
@@ -50,7 +51,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { | |||
50 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); | 51 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); |
51 | } | 52 | } |
52 | 53 | ||
53 | swayc_t *next_focus = get_swayc_in_direction(con, seat, direction); | 54 | struct sway_container *next_focus = container_get_in_direction(con, seat, direction); |
54 | if (next_focus) { | 55 | if (next_focus) { |
55 | sway_seat_set_focus(seat, next_focus); | 56 | sway_seat_set_focus(seat, next_focus); |
56 | } | 57 | } |
diff --git a/sway/commands/kill.c b/sway/commands/kill.c index f408ce2a..f6774767 100644 --- a/sway/commands/kill.c +++ b/sway/commands/kill.c | |||
@@ -2,11 +2,11 @@ | |||
2 | #include "log.h" | 2 | #include "log.h" |
3 | #include "sway/input/input-manager.h" | 3 | #include "sway/input/input-manager.h" |
4 | #include "sway/input/seat.h" | 4 | #include "sway/input/seat.h" |
5 | #include "sway/view.h" | 5 | #include "sway/tree/view.h" |
6 | #include "sway/commands.h" | 6 | #include "sway/commands.h" |
7 | 7 | ||
8 | struct cmd_results *cmd_kill(int argc, char **argv) { | 8 | struct cmd_results *cmd_kill(int argc, char **argv) { |
9 | enum swayc_types type = config->handler_context.current_container->type; | 9 | enum sway_container_type type = config->handler_context.current_container->type; |
10 | if (type != C_VIEW && type != C_CONTAINER) { | 10 | if (type != C_VIEW && type != C_CONTAINER) { |
11 | return cmd_results_new(CMD_INVALID, NULL, | 11 | return cmd_results_new(CMD_INVALID, NULL, |
12 | "Can only kill views and containers with this command"); | 12 | "Can only kill views and containers with this command"); |
diff --git a/sway/commands/layout.c b/sway/commands/layout.c index b0fc5d66..ebab2a48 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c | |||
@@ -1,8 +1,8 @@ | |||
1 | #include <string.h> | 1 | #include <string.h> |
2 | #include <strings.h> | 2 | #include <strings.h> |
3 | #include "sway/commands.h" | 3 | #include "sway/commands.h" |
4 | #include "sway/container.h" | 4 | #include "sway/tree/container.h" |
5 | #include "sway/layout.h" | 5 | #include "sway/tree/layout.h" |
6 | #include "log.h" | 6 | #include "log.h" |
7 | 7 | ||
8 | struct cmd_results *cmd_layout(int argc, char **argv) { | 8 | struct cmd_results *cmd_layout(int argc, char **argv) { |
@@ -10,7 +10,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { | 10 | if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | swayc_t *parent = config->handler_context.current_container; | 13 | struct sway_container *parent = config->handler_context.current_container; |
14 | 14 | ||
15 | // TODO: floating | 15 | // TODO: floating |
16 | /* | 16 | /* |
@@ -26,10 +26,10 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
26 | // TODO: stacks and tabs | 26 | // TODO: stacks and tabs |
27 | 27 | ||
28 | if (strcasecmp(argv[0], "default") == 0) { | 28 | if (strcasecmp(argv[0], "default") == 0) { |
29 | swayc_change_layout(parent, parent->prev_layout); | 29 | container_set_layout(parent, parent->prev_layout); |
30 | if (parent->layout == L_NONE) { | 30 | if (parent->layout == L_NONE) { |
31 | swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); | 31 | struct sway_container *output = container_parent(parent, C_OUTPUT); |
32 | swayc_change_layout(parent, default_layout(output)); | 32 | container_set_layout(parent, container_get_default_layout(output)); |
33 | } | 33 | } |
34 | } else { | 34 | } else { |
35 | if (parent->layout != L_TABBED && parent->layout != L_STACKED) { | 35 | if (parent->layout != L_TABBED && parent->layout != L_STACKED) { |
@@ -37,15 +37,15 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | if (strcasecmp(argv[0], "splith") == 0) { | 39 | if (strcasecmp(argv[0], "splith") == 0) { |
40 | swayc_change_layout(parent, L_HORIZ); | 40 | container_set_layout(parent, L_HORIZ); |
41 | } else if (strcasecmp(argv[0], "splitv") == 0) { | 41 | } else if (strcasecmp(argv[0], "splitv") == 0) { |
42 | swayc_change_layout(parent, L_VERT); | 42 | container_set_layout(parent, L_VERT); |
43 | } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { | 43 | } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { |
44 | if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE | 44 | if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE |
45 | || parent->workspace_layout == L_HORIZ)) { | 45 | || parent->workspace_layout == L_HORIZ)) { |
46 | swayc_change_layout(parent, L_VERT); | 46 | container_set_layout(parent, L_VERT); |
47 | } else { | 47 | } else { |
48 | swayc_change_layout(parent, L_HORIZ); | 48 | container_set_layout(parent, L_HORIZ); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | } | 51 | } |
diff --git a/sway/commands/output.c b/sway/commands/output.c index 35bc8099..f7e3372c 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -296,7 +296,7 @@ struct cmd_results *cmd_output(int argc, char **argv) { | |||
296 | char identifier[128]; | 296 | char identifier[128]; |
297 | bool all = strcmp(output->name, "*") == 0; | 297 | bool all = strcmp(output->name, "*") == 0; |
298 | for (int i = 0; i < root_container.children->length; ++i) { | 298 | for (int i = 0; i < root_container.children->length; ++i) { |
299 | swayc_t *cont = root_container.children->items[i]; | 299 | struct sway_container *cont = root_container.children->items[i]; |
300 | if (cont->type != C_OUTPUT) { | 300 | if (cont->type != C_OUTPUT) { |
301 | continue; | 301 | continue; |
302 | } | 302 | } |
diff --git a/sway/commands/reload.c b/sway/commands/reload.c index d54d40db..8cef789b 100644 --- a/sway/commands/reload.c +++ b/sway/commands/reload.c | |||
@@ -1,6 +1,6 @@ | |||
1 | #include "sway/commands.h" | 1 | #include "sway/commands.h" |
2 | #include "sway/config.h" | 2 | #include "sway/config.h" |
3 | #include "sway/layout.h" | 3 | #include "sway/tree/layout.h" |
4 | 4 | ||
5 | struct cmd_results *cmd_reload(int argc, char **argv) { | 5 | struct cmd_results *cmd_reload(int argc, char **argv) { |
6 | struct cmd_results *error = NULL; | 6 | struct cmd_results *error = NULL; |
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index fa891398..8f39e5fc 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -4,7 +4,7 @@ | |||
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/config.h" | 5 | #include "sway/config.h" |
6 | #include "sway/input/seat.h" | 6 | #include "sway/input/seat.h" |
7 | #include "sway/workspace.h" | 7 | #include "sway/tree/workspace.h" |
8 | #include "list.h" | 8 | #include "list.h" |
9 | #include "log.h" | 9 | #include "log.h" |
10 | #include "stringop.h" | 10 | #include "stringop.h" |
@@ -17,15 +17,15 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
17 | 17 | ||
18 | int output_location = -1; | 18 | int output_location = -1; |
19 | 19 | ||
20 | swayc_t *current_container = config->handler_context.current_container; | 20 | struct sway_container *current_container = config->handler_context.current_container; |
21 | swayc_t *old_workspace = NULL, *old_output = NULL; | 21 | struct sway_container *old_workspace = NULL, *old_output = NULL; |
22 | if (current_container) { | 22 | if (current_container) { |
23 | if (current_container->type == C_WORKSPACE) { | 23 | if (current_container->type == C_WORKSPACE) { |
24 | old_workspace = current_container; | 24 | old_workspace = current_container; |
25 | } else { | 25 | } else { |
26 | old_workspace = swayc_parent_by_type(current_container, C_WORKSPACE); | 26 | old_workspace = container_parent(current_container, C_WORKSPACE); |
27 | } | 27 | } |
28 | old_output = swayc_parent_by_type(current_container, C_OUTPUT); | 28 | old_output = container_parent(current_container, C_OUTPUT); |
29 | } | 29 | } |
30 | 30 | ||
31 | for (int i = 0; i < argc; ++i) { | 31 | for (int i = 0; i < argc; ++i) { |
@@ -57,7 +57,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
57 | if (config->reading || !config->active) { | 57 | if (config->reading || !config->active) { |
58 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | 58 | return cmd_results_new(CMD_DEFER, "workspace", NULL); |
59 | } | 59 | } |
60 | swayc_t *ws = NULL; | 60 | struct sway_container *ws = NULL; |
61 | if (strcasecmp(argv[0], "number") == 0) { | 61 | if (strcasecmp(argv[0], "number") == 0) { |
62 | if (!(ws = workspace_by_number(argv[1]))) { | 62 | if (!(ws = workspace_by_number(argv[1]))) { |
63 | char *name = join_args(argv + 1, argc - 1); | 63 | char *name = join_args(argv + 1, argc - 1); |
@@ -92,7 +92,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
92 | workspace_switch(ws); | 92 | workspace_switch(ws); |
93 | current_container = | 93 | current_container = |
94 | sway_seat_get_focus(config->handler_context.seat); | 94 | sway_seat_get_focus(config->handler_context.seat); |
95 | swayc_t *new_output = swayc_parent_by_type(current_container, C_OUTPUT); | 95 | struct sway_container *new_output = container_parent(current_container, C_OUTPUT); |
96 | 96 | ||
97 | if (config->mouse_warping && old_output != new_output) { | 97 | if (config->mouse_warping && old_output != new_output) { |
98 | // TODO: Warp mouse | 98 | // TODO: Warp mouse |
diff --git a/sway/config.c b/sway/config.c index 213e7680..0b29735a 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "sway/input/seat.h" | 24 | #include "sway/input/seat.h" |
25 | #include "sway/commands.h" | 25 | #include "sway/commands.h" |
26 | #include "sway/config.h" | 26 | #include "sway/config.h" |
27 | #include "sway/layout.h" | 27 | #include "sway/tree/layout.h" |
28 | #include "readline.h" | 28 | #include "readline.h" |
29 | #include "stringop.h" | 29 | #include "stringop.h" |
30 | #include "list.h" | 30 | #include "list.h" |
diff --git a/sway/config/output.c b/sway/config/output.c index 9e211861..7fc79739 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -120,14 +120,14 @@ void terminate_swaybg(pid_t pid) { | |||
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | void apply_output_config(struct output_config *oc, swayc_t *output) { | 123 | void apply_output_config(struct output_config *oc, struct sway_container *output) { |
124 | assert(output->type == C_OUTPUT); | 124 | assert(output->type == C_OUTPUT); |
125 | 125 | ||
126 | struct wlr_output *wlr_output = output->sway_output->wlr_output; | 126 | struct wlr_output *wlr_output = output->sway_output->wlr_output; |
127 | if (oc && oc->enabled == 0) { | 127 | if (oc && oc->enabled == 0) { |
128 | wlr_output_layout_remove(root_container.sway_root->output_layout, | 128 | wlr_output_layout_remove(root_container.sway_root->output_layout, |
129 | wlr_output); | 129 | wlr_output); |
130 | destroy_output(output); | 130 | container_output_destroy(output); |
131 | return; | 131 | return; |
132 | } | 132 | } |
133 | 133 | ||
diff --git a/sway/criteria.c b/sway/criteria.c index 2eee331c..247f6b75 100644 --- a/sway/criteria.c +++ b/sway/criteria.c | |||
@@ -4,9 +4,9 @@ | |||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include <pcre.h> | 5 | #include <pcre.h> |
6 | #include "sway/criteria.h" | 6 | #include "sway/criteria.h" |
7 | #include "sway/container.h" | 7 | #include "sway/tree/container.h" |
8 | #include "sway/config.h" | 8 | #include "sway/config.h" |
9 | #include "sway/view.h" | 9 | #include "sway/tree/view.h" |
10 | #include "stringop.h" | 10 | #include "stringop.h" |
11 | #include "list.h" | 11 | #include "list.h" |
12 | #include "log.h" | 12 | #include "log.h" |
@@ -272,7 +272,7 @@ static int regex_cmp(const char *item, const pcre *regex) { | |||
272 | } | 272 | } |
273 | 273 | ||
274 | // test a single view if it matches list of criteria tokens (all of them). | 274 | // test a single view if it matches list of criteria tokens (all of them). |
275 | static bool criteria_test(swayc_t *cont, list_t *tokens) { | 275 | static bool criteria_test(struct sway_container *cont, list_t *tokens) { |
276 | if (cont->type != C_VIEW) { | 276 | if (cont->type != C_VIEW) { |
277 | return false; | 277 | return false; |
278 | } | 278 | } |
@@ -398,7 +398,7 @@ void free_criteria(struct criteria *crit) { | |||
398 | free(crit); | 398 | free(crit); |
399 | } | 399 | } |
400 | 400 | ||
401 | bool criteria_any(swayc_t *cont, list_t *criteria) { | 401 | bool criteria_any(struct sway_container *cont, list_t *criteria) { |
402 | for (int i = 0; i < criteria->length; i++) { | 402 | for (int i = 0; i < criteria->length; i++) { |
403 | struct criteria *bc = criteria->items[i]; | 403 | struct criteria *bc = criteria->items[i]; |
404 | if (criteria_test(cont, bc->tokens)) { | 404 | if (criteria_test(cont, bc->tokens)) { |
@@ -408,7 +408,7 @@ bool criteria_any(swayc_t *cont, list_t *criteria) { | |||
408 | return false; | 408 | return false; |
409 | } | 409 | } |
410 | 410 | ||
411 | list_t *criteria_for(swayc_t *cont) { | 411 | list_t *criteria_for(struct sway_container *cont) { |
412 | list_t *criteria = config->criteria, *matches = create_list(); | 412 | list_t *criteria = config->criteria, *matches = create_list(); |
413 | for (int i = 0; i < criteria->length; i++) { | 413 | for (int i = 0; i < criteria->length; i++) { |
414 | struct criteria *bc = criteria->items[i]; | 414 | struct criteria *bc = criteria->items[i]; |
@@ -424,7 +424,7 @@ struct list_tokens { | |||
424 | list_t *tokens; | 424 | list_t *tokens; |
425 | }; | 425 | }; |
426 | 426 | ||
427 | static void container_match_add(swayc_t *container, | 427 | static void container_match_add(struct sway_container *container, |
428 | struct list_tokens *list_tokens) { | 428 | struct list_tokens *list_tokens) { |
429 | if (criteria_test(container, list_tokens->tokens)) { | 429 | if (criteria_test(container, list_tokens->tokens)) { |
430 | list_add(list_tokens->list, container); | 430 | list_add(list_tokens->list, container); |
@@ -435,8 +435,8 @@ list_t *container_for_crit_tokens(list_t *tokens) { | |||
435 | struct list_tokens list_tokens = | 435 | struct list_tokens list_tokens = |
436 | (struct list_tokens){create_list(), tokens}; | 436 | (struct list_tokens){create_list(), tokens}; |
437 | 437 | ||
438 | container_map(&root_container, | 438 | container_for_each_descendent(&root_container, |
439 | (void (*)(swayc_t *, void *))container_match_add, | 439 | (void (*)(struct sway_container *, void *))container_match_add, |
440 | &list_tokens); | 440 | &list_tokens); |
441 | 441 | ||
442 | // TODO look in the scratchpad | 442 | // TODO look in the scratchpad |
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index bd62f84a..137b3260 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c | |||
@@ -7,7 +7,7 @@ | |||
7 | #include <wlr/types/wlr_output.h> | 7 | #include <wlr/types/wlr_output.h> |
8 | #include <wlr/util/log.h> | 8 | #include <wlr/util/log.h> |
9 | #include "sway/layers.h" | 9 | #include "sway/layers.h" |
10 | #include "sway/layout.h" | 10 | #include "sway/tree/layout.h" |
11 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/server.h" | 12 | #include "sway/server.h" |
13 | 13 | ||
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index b8253ace..ba778f4c 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -11,14 +11,14 @@ | |||
11 | #include <wlr/types/wlr_surface.h> | 11 | #include <wlr/types/wlr_surface.h> |
12 | #include <wlr/types/wlr_wl_shell.h> | 12 | #include <wlr/types/wlr_wl_shell.h> |
13 | #include "log.h" | 13 | #include "log.h" |
14 | #include "sway/container.h" | 14 | #include "sway/tree/container.h" |
15 | #include "sway/input/input-manager.h" | 15 | #include "sway/input/input-manager.h" |
16 | #include "sway/input/seat.h" | 16 | #include "sway/input/seat.h" |
17 | #include "sway/layers.h" | 17 | #include "sway/layers.h" |
18 | #include "sway/layout.h" | 18 | #include "sway/tree/layout.h" |
19 | #include "sway/output.h" | 19 | #include "sway/output.h" |
20 | #include "sway/server.h" | 20 | #include "sway/server.h" |
21 | #include "sway/view.h" | 21 | #include "sway/tree/view.h" |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Rotate a child's position relative to a parent. The parent size is (pw, ph), | 24 | * Rotate a child's position relative to a parent. The parent size is (pw, ph), |
@@ -145,7 +145,7 @@ struct render_data { | |||
145 | struct timespec *now; | 145 | struct timespec *now; |
146 | }; | 146 | }; |
147 | 147 | ||
148 | static void output_frame_view(swayc_t *view, void *data) { | 148 | static void output_frame_view(struct sway_container *view, void *data) { |
149 | struct render_data *rdata = data; | 149 | struct render_data *rdata = data; |
150 | struct sway_output *output = rdata->output; | 150 | struct sway_output *output = rdata->output; |
151 | struct timespec *now = rdata->now; | 151 | struct timespec *now = rdata->now; |
@@ -219,16 +219,16 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { | |||
219 | &soutput->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); | 219 | &soutput->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); |
220 | 220 | ||
221 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 221 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
222 | swayc_t *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); | 222 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); |
223 | swayc_t *workspace = (focus->type == C_WORKSPACE ? | 223 | struct sway_container *workspace = (focus->type == C_WORKSPACE ? |
224 | focus : | 224 | focus : |
225 | swayc_parent_by_type(focus, C_WORKSPACE)); | 225 | container_parent(focus, C_WORKSPACE)); |
226 | 226 | ||
227 | struct render_data rdata = { | 227 | struct render_data rdata = { |
228 | .output = soutput, | 228 | .output = soutput, |
229 | .now = &now, | 229 | .now = &now, |
230 | }; | 230 | }; |
231 | swayc_descendants_of_type(workspace, C_VIEW, output_frame_view, &rdata); | 231 | container_descendents(workspace, C_VIEW, output_frame_view, &rdata); |
232 | 232 | ||
233 | // render unmanaged views on top | 233 | // render unmanaged views on top |
234 | struct sway_view *view; | 234 | struct sway_view *view; |
@@ -259,7 +259,7 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { | |||
259 | struct wlr_output *wlr_output = data; | 259 | struct wlr_output *wlr_output = data; |
260 | wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); | 260 | wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); |
261 | 261 | ||
262 | destroy_output(output->swayc); | 262 | container_output_destroy(output->swayc); |
263 | } | 263 | } |
264 | 264 | ||
265 | static void handle_output_mode(struct wl_listener *listener, void *data) { | 265 | static void handle_output_mode(struct wl_listener *listener, void *data) { |
@@ -287,7 +287,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { | |||
287 | wlr_output_set_mode(wlr_output, mode); | 287 | wlr_output_set_mode(wlr_output, mode); |
288 | } | 288 | } |
289 | 289 | ||
290 | output->swayc = new_output(output); | 290 | output->swayc = container_output_create(output); |
291 | if (!output->swayc) { | 291 | if (!output->swayc) { |
292 | free(output); | 292 | free(output); |
293 | return; | 293 | return; |
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index 0356aa81..4d4d1ed7 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c | |||
@@ -3,10 +3,10 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <wayland-server.h> | 4 | #include <wayland-server.h> |
5 | #include <wlr/types/wlr_wl_shell.h> | 5 | #include <wlr/types/wlr_wl_shell.h> |
6 | #include "sway/container.h" | 6 | #include "sway/tree/container.h" |
7 | #include "sway/layout.h" | 7 | #include "sway/tree/layout.h" |
8 | #include "sway/server.h" | 8 | #include "sway/server.h" |
9 | #include "sway/view.h" | 9 | #include "sway/tree/view.h" |
10 | #include "sway/input/seat.h" | 10 | #include "sway/input/seat.h" |
11 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
12 | #include "log.h" | 12 | #include "log.h" |
@@ -74,7 +74,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { | |||
74 | wl_container_of(listener, sway_surface, destroy); | 74 | wl_container_of(listener, sway_surface, destroy); |
75 | wl_list_remove(&sway_surface->commit.link); | 75 | wl_list_remove(&sway_surface->commit.link); |
76 | wl_list_remove(&sway_surface->destroy.link); | 76 | wl_list_remove(&sway_surface->destroy.link); |
77 | swayc_t *parent = destroy_view(sway_surface->view->swayc); | 77 | struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); |
78 | free(sway_surface->view); | 78 | free(sway_surface->view); |
79 | free(sway_surface); | 79 | free(sway_surface); |
80 | arrange_windows(parent, -1, -1); | 80 | arrange_windows(parent, -1, -1); |
@@ -132,8 +132,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { | |||
132 | wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy); | 132 | wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy); |
133 | 133 | ||
134 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 134 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
135 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 135 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); |
136 | swayc_t *cont = new_view(focus, sway_view); | 136 | struct sway_container *cont = container_view_create(focus, sway_view); |
137 | sway_view->swayc = cont; | 137 | sway_view->swayc = cont; |
138 | 138 | ||
139 | arrange_windows(cont->parent, -1, -1); | 139 | arrange_windows(cont->parent, -1, -1); |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 18e7d399..25c0cbca 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -3,10 +3,10 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <wayland-server.h> | 4 | #include <wayland-server.h> |
5 | #include <wlr/types/wlr_xdg_shell_v6.h> | 5 | #include <wlr/types/wlr_xdg_shell_v6.h> |
6 | #include "sway/container.h" | 6 | #include "sway/tree/container.h" |
7 | #include "sway/layout.h" | 7 | #include "sway/tree/layout.h" |
8 | #include "sway/server.h" | 8 | #include "sway/server.h" |
9 | #include "sway/view.h" | 9 | #include "sway/tree/view.h" |
10 | #include "sway/input/seat.h" | 10 | #include "sway/input/seat.h" |
11 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
12 | #include "log.h" | 12 | #include "log.h" |
@@ -83,7 +83,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { | |||
83 | wl_container_of(listener, sway_xdg_surface, destroy); | 83 | wl_container_of(listener, sway_xdg_surface, destroy); |
84 | wl_list_remove(&sway_xdg_surface->commit.link); | 84 | wl_list_remove(&sway_xdg_surface->commit.link); |
85 | wl_list_remove(&sway_xdg_surface->destroy.link); | 85 | wl_list_remove(&sway_xdg_surface->destroy.link); |
86 | swayc_t *parent = destroy_view(sway_xdg_surface->view->swayc); | 86 | struct sway_container *parent = container_view_destroy(sway_xdg_surface->view->swayc); |
87 | free(sway_xdg_surface->view); | 87 | free(sway_xdg_surface->view); |
88 | free(sway_xdg_surface); | 88 | free(sway_xdg_surface); |
89 | arrange_windows(parent, -1, -1); | 89 | arrange_windows(parent, -1, -1); |
@@ -137,8 +137,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
137 | wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy); | 137 | wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy); |
138 | 138 | ||
139 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 139 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
140 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 140 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); |
141 | swayc_t *cont = new_view(focus, sway_view); | 141 | struct sway_container *cont = container_view_create(focus, sway_view); |
142 | sway_view->swayc = cont; | 142 | sway_view->swayc = cont; |
143 | 143 | ||
144 | arrange_windows(cont->parent, -1, -1); | 144 | arrange_windows(cont->parent, -1, -1); |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index f9b5242b..fd0bcaca 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -5,10 +5,10 @@ | |||
5 | #include <wlr/xwayland.h> | 5 | #include <wlr/xwayland.h> |
6 | #include <wlr/types/wlr_output_layout.h> | 6 | #include <wlr/types/wlr_output_layout.h> |
7 | #include <wlr/types/wlr_output.h> | 7 | #include <wlr/types/wlr_output.h> |
8 | #include "sway/container.h" | 8 | #include "sway/tree/container.h" |
9 | #include "sway/layout.h" | 9 | #include "sway/tree/layout.h" |
10 | #include "sway/server.h" | 10 | #include "sway/server.h" |
11 | #include "sway/view.h" | 11 | #include "sway/tree/view.h" |
12 | #include "sway/output.h" | 12 | #include "sway/output.h" |
13 | #include "sway/input/seat.h" | 13 | #include "sway/input/seat.h" |
14 | #include "sway/input/input-manager.h" | 14 | #include "sway/input/input-manager.h" |
@@ -49,11 +49,11 @@ static void set_position(struct sway_view *view, double ox, double oy) { | |||
49 | if (!assert_xwayland(view)) { | 49 | if (!assert_xwayland(view)) { |
50 | return; | 50 | return; |
51 | } | 51 | } |
52 | swayc_t *output = swayc_parent_by_type(view->swayc, C_OUTPUT); | 52 | struct sway_container *output = container_parent(view->swayc, C_OUTPUT); |
53 | if (!sway_assert(output, "view must be within tree to set position")) { | 53 | if (!sway_assert(output, "view must be within tree to set position")) { |
54 | return; | 54 | return; |
55 | } | 55 | } |
56 | swayc_t *root = swayc_parent_by_type(output, C_ROOT); | 56 | struct sway_container *root = container_parent(output, C_ROOT); |
57 | if (!sway_assert(root, "output must be within tree to set position")) { | 57 | if (!sway_assert(root, "output must be within tree to set position")) { |
58 | return; | 58 | return; |
59 | } | 59 | } |
@@ -114,7 +114,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { | |||
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | swayc_t *parent = destroy_view(sway_surface->view->swayc); | 117 | struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); |
118 | if (parent) { | 118 | if (parent) { |
119 | arrange_windows(parent, -1, -1); | 119 | arrange_windows(parent, -1, -1); |
120 | } | 120 | } |
@@ -132,7 +132,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { | |||
132 | } | 132 | } |
133 | 133 | ||
134 | // take it out of the tree | 134 | // take it out of the tree |
135 | swayc_t *parent = destroy_view(sway_surface->view->swayc); | 135 | struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); |
136 | if (parent) { | 136 | if (parent) { |
137 | arrange_windows(parent, -1, -1); | 137 | arrange_windows(parent, -1, -1); |
138 | } | 138 | } |
@@ -155,12 +155,12 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { | |||
155 | &sway_surface->view->unmanaged_view_link); | 155 | &sway_surface->view->unmanaged_view_link); |
156 | } else { | 156 | } else { |
157 | struct sway_view *view = sway_surface->view; | 157 | struct sway_view *view = sway_surface->view; |
158 | destroy_view(view->swayc); | 158 | container_view_destroy(view->swayc); |
159 | 159 | ||
160 | swayc_t *parent = root_container.children->items[0]; | 160 | struct sway_container *parent = root_container.children->items[0]; |
161 | parent = parent->children->items[0]; // workspace | 161 | parent = parent->children->items[0]; // workspace |
162 | 162 | ||
163 | swayc_t *cont = new_view(parent, view); | 163 | struct sway_container *cont = container_view_create(parent, view); |
164 | view->swayc = cont; | 164 | view->swayc = cont; |
165 | 165 | ||
166 | arrange_windows(cont->parent, -1, -1); | 166 | arrange_windows(cont->parent, -1, -1); |
@@ -238,8 +238,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
238 | } | 238 | } |
239 | 239 | ||
240 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 240 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
241 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 241 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); |
242 | swayc_t *cont = new_view(focus, sway_view); | 242 | struct sway_container *cont = container_view_create(focus, sway_view); |
243 | sway_view->swayc = cont; | 243 | sway_view->swayc = cont; |
244 | 244 | ||
245 | arrange_windows(cont->parent, -1, -1); | 245 | arrange_windows(cont->parent, -1, -1); |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 8a0d1df5..d57ac3e3 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -7,7 +7,7 @@ | |||
7 | #include <wlr/types/wlr_cursor.h> | 7 | #include <wlr/types/wlr_cursor.h> |
8 | #include <wlr/types/wlr_xcursor_manager.h> | 8 | #include <wlr/types/wlr_xcursor_manager.h> |
9 | #include "sway/input/cursor.h" | 9 | #include "sway/input/cursor.h" |
10 | #include "sway/view.h" | 10 | #include "sway/tree/view.h" |
11 | #include "list.h" | 11 | #include "list.h" |
12 | #include "log.h" | 12 | #include "log.h" |
13 | 13 | ||
@@ -49,8 +49,8 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | swayc_t *swayc = | 52 | struct sway_container *swayc = |
53 | swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); | 53 | container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); |
54 | if (swayc) { | 54 | if (swayc) { |
55 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); | 55 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); |
56 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); | 56 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); |
@@ -87,8 +87,8 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { | |||
87 | if (event->button == BTN_LEFT) { | 87 | if (event->button == BTN_LEFT) { |
88 | struct wlr_surface *surface = NULL; | 88 | struct wlr_surface *surface = NULL; |
89 | double sx, sy; | 89 | double sx, sy; |
90 | swayc_t *swayc = | 90 | struct sway_container *swayc = |
91 | swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); | 91 | container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); |
92 | 92 | ||
93 | sway_seat_set_focus(cursor->seat, swayc); | 93 | sway_seat_set_focus(cursor->seat, swayc); |
94 | } | 94 | } |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 27c2c72e..d421a03f 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -278,7 +278,7 @@ struct sway_input_manager *sway_input_manager_create( | |||
278 | } | 278 | } |
279 | 279 | ||
280 | bool sway_input_manager_has_focus(struct sway_input_manager *input, | 280 | bool sway_input_manager_has_focus(struct sway_input_manager *input, |
281 | swayc_t *container) { | 281 | struct sway_container *container) { |
282 | struct sway_seat *seat = NULL; | 282 | struct sway_seat *seat = NULL; |
283 | wl_list_for_each(seat, &input->seats, link) { | 283 | wl_list_for_each(seat, &input->seats, link) { |
284 | if (sway_seat_get_focus(seat) == container) { | 284 | if (sway_seat_get_focus(seat) == container) { |
@@ -290,7 +290,7 @@ bool sway_input_manager_has_focus(struct sway_input_manager *input, | |||
290 | } | 290 | } |
291 | 291 | ||
292 | void sway_input_manager_set_focus(struct sway_input_manager *input, | 292 | void sway_input_manager_set_focus(struct sway_input_manager *input, |
293 | swayc_t *container) { | 293 | struct sway_container *container) { |
294 | struct sway_seat *seat ; | 294 | struct sway_seat *seat ; |
295 | wl_list_for_each(seat, &input->seats, link) { | 295 | wl_list_for_each(seat, &input->seats, link) { |
296 | sway_seat_set_focus(seat, container); | 296 | sway_seat_set_focus(seat, container); |
diff --git a/sway/input/seat.c b/sway/input/seat.c index 648e7914..76d29b52 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -1,13 +1,13 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _XOPEN_SOURCE 700 |
2 | #include <wlr/types/wlr_cursor.h> | 2 | #include <wlr/types/wlr_cursor.h> |
3 | #include <wlr/types/wlr_xcursor_manager.h> | 3 | #include <wlr/types/wlr_xcursor_manager.h> |
4 | #include "sway/container.h" | 4 | #include "sway/tree/container.h" |
5 | #include "sway/input/seat.h" | 5 | #include "sway/input/seat.h" |
6 | #include "sway/input/cursor.h" | 6 | #include "sway/input/cursor.h" |
7 | #include "sway/input/input-manager.h" | 7 | #include "sway/input/input-manager.h" |
8 | #include "sway/input/keyboard.h" | 8 | #include "sway/input/keyboard.h" |
9 | #include "sway/output.h" | 9 | #include "sway/output.h" |
10 | #include "sway/view.h" | 10 | #include "sway/tree/view.h" |
11 | #include "log.h" | 11 | #include "log.h" |
12 | 12 | ||
13 | static void seat_device_destroy(struct sway_seat_device *seat_device) { | 13 | static void seat_device_destroy(struct sway_seat_device *seat_device) { |
@@ -37,7 +37,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, | |||
37 | struct sway_seat_container *seat_con = | 37 | struct sway_seat_container *seat_con = |
38 | wl_container_of(listener, seat_con, destroy); | 38 | wl_container_of(listener, seat_con, destroy); |
39 | struct sway_seat *seat = seat_con->seat; | 39 | struct sway_seat *seat = seat_con->seat; |
40 | swayc_t *con = seat_con->container; | 40 | struct sway_container *con = seat_con->container; |
41 | 41 | ||
42 | bool is_focus = (sway_seat_get_focus(seat) == con); | 42 | bool is_focus = (sway_seat_get_focus(seat) == con); |
43 | 43 | ||
@@ -46,7 +46,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, | |||
46 | if (is_focus) { | 46 | if (is_focus) { |
47 | // pick next focus | 47 | // pick next focus |
48 | sway_seat_set_focus(seat, NULL); | 48 | sway_seat_set_focus(seat, NULL); |
49 | swayc_t *next = sway_seat_get_focus_inactive(seat, con->parent); | 49 | struct sway_container *next = sway_seat_get_focus_inactive(seat, con->parent); |
50 | if (next == NULL) { | 50 | if (next == NULL) { |
51 | next = con->parent; | 51 | next = con->parent; |
52 | } | 52 | } |
@@ -59,7 +59,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, | |||
59 | } | 59 | } |
60 | 60 | ||
61 | static struct sway_seat_container *seat_container_from_container( | 61 | static struct sway_seat_container *seat_container_from_container( |
62 | struct sway_seat *seat, swayc_t *con) { | 62 | struct sway_seat *seat, struct sway_container *con) { |
63 | if (con->type < C_WORKSPACE) { | 63 | if (con->type < C_WORKSPACE) { |
64 | // these don't get seat containers ever | 64 | // these don't get seat containers ever |
65 | return NULL; | 65 | return NULL; |
@@ -89,11 +89,11 @@ static struct sway_seat_container *seat_container_from_container( | |||
89 | 89 | ||
90 | static void handle_new_container(struct wl_listener *listener, void *data) { | 90 | static void handle_new_container(struct wl_listener *listener, void *data) { |
91 | struct sway_seat *seat = wl_container_of(listener, seat, new_container); | 91 | struct sway_seat *seat = wl_container_of(listener, seat, new_container); |
92 | swayc_t *con = data; | 92 | struct sway_container *con = data; |
93 | seat_container_from_container(seat, con); | 93 | seat_container_from_container(seat, con); |
94 | } | 94 | } |
95 | 95 | ||
96 | static void collect_focus_iter(swayc_t *con, void *data) { | 96 | static void collect_focus_iter(struct sway_container *con, void *data) { |
97 | struct sway_seat *seat = data; | 97 | struct sway_seat *seat = data; |
98 | if (con->type > C_WORKSPACE) { | 98 | if (con->type > C_WORKSPACE) { |
99 | return; | 99 | return; |
@@ -130,7 +130,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input, | |||
130 | // init the focus stack | 130 | // init the focus stack |
131 | wl_list_init(&seat->focus_stack); | 131 | wl_list_init(&seat->focus_stack); |
132 | 132 | ||
133 | container_for_each_bfs(&root_container, collect_focus_iter, seat); | 133 | container_for_each_descendent(&root_container, collect_focus_iter, seat); |
134 | 134 | ||
135 | wl_signal_add(&root_container.sway_root->events.new_container, | 135 | wl_signal_add(&root_container.sway_root->events.new_container, |
136 | &seat->new_container); | 136 | &seat->new_container); |
@@ -166,7 +166,7 @@ static void seat_configure_keyboard(struct sway_seat *seat, | |||
166 | sway_keyboard_configure(seat_device->keyboard); | 166 | sway_keyboard_configure(seat_device->keyboard); |
167 | wlr_seat_set_keyboard(seat->wlr_seat, | 167 | wlr_seat_set_keyboard(seat->wlr_seat, |
168 | seat_device->input_device->wlr_device); | 168 | seat_device->input_device->wlr_device); |
169 | swayc_t *focus = sway_seat_get_focus(seat); | 169 | struct sway_container *focus = sway_seat_get_focus(seat); |
170 | if (focus && focus->type == C_VIEW) { | 170 | if (focus && focus->type == C_VIEW) { |
171 | // force notify reenter to pick up the new configuration | 171 | // force notify reenter to pick up the new configuration |
172 | wlr_seat_keyboard_clear_focus(seat->wlr_seat); | 172 | wlr_seat_keyboard_clear_focus(seat->wlr_seat); |
@@ -270,7 +270,7 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { | |||
270 | } | 270 | } |
271 | 271 | ||
272 | for (int i = 0; i < root_container.children->length; ++i) { | 272 | for (int i = 0; i < root_container.children->length; ++i) { |
273 | swayc_t *output_container = root_container.children->items[i]; | 273 | struct sway_container *output_container = root_container.children->items[i]; |
274 | struct wlr_output *output = | 274 | struct wlr_output *output = |
275 | output_container->sway_output->wlr_output; | 275 | output_container->sway_output->wlr_output; |
276 | bool result = | 276 | bool result = |
@@ -289,8 +289,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { | |||
289 | seat->cursor->cursor->y); | 289 | seat->cursor->cursor->y); |
290 | } | 290 | } |
291 | 291 | ||
292 | void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { | 292 | void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container) { |
293 | swayc_t *last_focus = sway_seat_get_focus(seat); | 293 | struct sway_container *last_focus = sway_seat_get_focus(seat); |
294 | 294 | ||
295 | if (container && last_focus == container) { | 295 | if (container && last_focus == container) { |
296 | return; | 296 | return; |
@@ -330,9 +330,9 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { | |||
330 | seat->has_focus = (container != NULL); | 330 | seat->has_focus = (container != NULL); |
331 | } | 331 | } |
332 | 332 | ||
333 | swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container) { | 333 | struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) { |
334 | struct sway_seat_container *current = NULL; | 334 | struct sway_seat_container *current = NULL; |
335 | swayc_t *parent = NULL; | 335 | struct sway_container *parent = NULL; |
336 | wl_list_for_each(current, &seat->focus_stack, link) { | 336 | wl_list_for_each(current, &seat->focus_stack, link) { |
337 | parent = current->container->parent; | 337 | parent = current->container->parent; |
338 | 338 | ||
@@ -351,21 +351,21 @@ swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container | |||
351 | return NULL; | 351 | return NULL; |
352 | } | 352 | } |
353 | 353 | ||
354 | swayc_t *sway_seat_get_focus(struct sway_seat *seat) { | 354 | struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { |
355 | if (!seat->has_focus) { | 355 | if (!seat->has_focus) { |
356 | return NULL; | 356 | return NULL; |
357 | } | 357 | } |
358 | return sway_seat_get_focus_inactive(seat, &root_container); | 358 | return sway_seat_get_focus_inactive(seat, &root_container); |
359 | } | 359 | } |
360 | 360 | ||
361 | swayc_t *sway_seat_get_focus_by_type(struct sway_seat *seat, | 361 | struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, |
362 | enum swayc_types type) { | 362 | enum sway_container_type type) { |
363 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 363 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); |
364 | if (focus->type == type) { | 364 | if (focus->type == type) { |
365 | return focus; | 365 | return focus; |
366 | } | 366 | } |
367 | 367 | ||
368 | return swayc_parent_by_type(focus, type); | 368 | return container_parent(focus, type); |
369 | } | 369 | } |
370 | 370 | ||
371 | void sway_seat_set_config(struct sway_seat *seat, | 371 | void sway_seat_set_config(struct sway_seat *seat, |
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 977f1ecb..7caa2457 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -3,7 +3,7 @@ | |||
3 | #include <ctype.h> | 3 | #include <ctype.h> |
4 | #include "log.h" | 4 | #include "log.h" |
5 | #include "sway/ipc-json.h" | 5 | #include "sway/ipc-json.h" |
6 | #include "sway/container.h" | 6 | #include "sway/tree/container.h" |
7 | #include "sway/output.h" | 7 | #include "sway/output.h" |
8 | #include "sway/input/input-manager.h" | 8 | #include "sway/input/input-manager.h" |
9 | #include "sway/input/seat.h" | 9 | #include "sway/input/seat.h" |
@@ -25,7 +25,7 @@ json_object *ipc_json_get_version() { | |||
25 | return version; | 25 | return version; |
26 | } | 26 | } |
27 | 27 | ||
28 | static json_object *ipc_json_create_rect(swayc_t *c) { | 28 | static json_object *ipc_json_create_rect(struct sway_container *c) { |
29 | json_object *rect = json_object_new_object(); | 29 | json_object *rect = json_object_new_object(); |
30 | 30 | ||
31 | json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x)); | 31 | json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x)); |
@@ -36,7 +36,7 @@ static json_object *ipc_json_create_rect(swayc_t *c) { | |||
36 | return rect; | 36 | return rect; |
37 | } | 37 | } |
38 | 38 | ||
39 | static void ipc_json_describe_root(swayc_t *root, json_object *object) { | 39 | static void ipc_json_describe_root(struct sway_container *root, json_object *object) { |
40 | json_object_object_add(object, "type", json_object_new_string("root")); | 40 | json_object_object_add(object, "type", json_object_new_string("root")); |
41 | json_object_object_add(object, "layout", json_object_new_string("splith")); | 41 | json_object_object_add(object, "layout", json_object_new_string("splith")); |
42 | } | 42 | } |
@@ -63,7 +63,7 @@ static const char *ipc_json_get_output_transform(enum wl_output_transform transf | |||
63 | return NULL; | 63 | return NULL; |
64 | } | 64 | } |
65 | 65 | ||
66 | static void ipc_json_describe_output(swayc_t *container, json_object *object) { | 66 | static void ipc_json_describe_output(struct sway_container *container, json_object *object) { |
67 | struct wlr_output *wlr_output = container->sway_output->wlr_output; | 67 | struct wlr_output *wlr_output = container->sway_output->wlr_output; |
68 | json_object_object_add(object, "type", json_object_new_string("output")); | 68 | json_object_object_add(object, "type", json_object_new_string("output")); |
69 | json_object_object_add(object, "active", json_object_new_boolean(true)); | 69 | json_object_object_add(object, "active", json_object_new_boolean(true)); |
@@ -94,7 +94,7 @@ static void ipc_json_describe_output(swayc_t *container, json_object *object) { | |||
94 | json_object_object_add(object, "modes", modes_array); | 94 | json_object_object_add(object, "modes", modes_array); |
95 | } | 95 | } |
96 | 96 | ||
97 | static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) { | 97 | static void ipc_json_describe_workspace(struct sway_container *workspace, json_object *object) { |
98 | int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1; | 98 | int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1; |
99 | 99 | ||
100 | json_object_object_add(object, "num", json_object_new_int(num)); | 100 | json_object_object_add(object, "num", json_object_new_int(num)); |
@@ -102,11 +102,11 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) | |||
102 | json_object_object_add(object, "type", json_object_new_string("workspace")); | 102 | json_object_object_add(object, "type", json_object_new_string("workspace")); |
103 | } | 103 | } |
104 | 104 | ||
105 | static void ipc_json_describe_view(swayc_t *c, json_object *object) { | 105 | static void ipc_json_describe_view(struct sway_container *c, json_object *object) { |
106 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); | 106 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); |
107 | } | 107 | } |
108 | 108 | ||
109 | json_object *ipc_json_describe_container(swayc_t *c) { | 109 | json_object *ipc_json_describe_container(struct sway_container *c) { |
110 | if (!(sway_assert(c, "Container must not be null."))) { | 110 | if (!(sway_assert(c, "Container must not be null."))) { |
111 | return NULL; | 111 | return NULL; |
112 | } | 112 | } |
@@ -147,7 +147,7 @@ json_object *ipc_json_describe_container(swayc_t *c) { | |||
147 | return object; | 147 | return object; |
148 | } | 148 | } |
149 | 149 | ||
150 | json_object *ipc_json_describe_container_recursive(swayc_t *c) { | 150 | json_object *ipc_json_describe_container_recursive(struct sway_container *c) { |
151 | json_object *object = ipc_json_describe_container(c); | 151 | json_object *object = ipc_json_describe_container(c); |
152 | int i; | 152 | int i; |
153 | 153 | ||
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 156de380..50d0bcf3 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -279,7 +279,7 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event) | |||
279 | } | 279 | } |
280 | } | 280 | } |
281 | 281 | ||
282 | void ipc_event_window(swayc_t *window, const char *change) { | 282 | void ipc_event_window(struct sway_container *window, const char *change) { |
283 | wlr_log(L_DEBUG, "Sending window::%s event", change); | 283 | wlr_log(L_DEBUG, "Sending window::%s event", change); |
284 | json_object *obj = json_object_new_object(); | 284 | json_object *obj = json_object_new_object(); |
285 | json_object_object_add(obj, "change", json_object_new_string(change)); | 285 | json_object_object_add(obj, "change", json_object_new_string(change)); |
@@ -400,7 +400,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
400 | { | 400 | { |
401 | json_object *outputs = json_object_new_array(); | 401 | json_object *outputs = json_object_new_array(); |
402 | for (int i = 0; i < root_container.children->length; ++i) { | 402 | for (int i = 0; i < root_container.children->length; ++i) { |
403 | swayc_t *container = root_container.children->items[i]; | 403 | struct sway_container *container = root_container.children->items[i]; |
404 | if (container->type == C_OUTPUT) { | 404 | if (container->type == C_OUTPUT) { |
405 | json_object_array_add(outputs, | 405 | json_object_array_add(outputs, |
406 | ipc_json_describe_container(container)); | 406 | ipc_json_describe_container(container)); |
diff --git a/sway/main.c b/sway/main.c index f2f24be3..ded922ee 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <wlr/util/log.h> | 18 | #include <wlr/util/log.h> |
19 | #include "sway/config.h" | 19 | #include "sway/config.h" |
20 | #include "sway/server.h" | 20 | #include "sway/server.h" |
21 | #include "sway/layout.h" | 21 | #include "sway/tree/layout.h" |
22 | #include "sway/ipc-server.h" | 22 | #include "sway/ipc-server.h" |
23 | #include "ipc-client.h" | 23 | #include "ipc-client.h" |
24 | #include "readline.h" | 24 | #include "readline.h" |
@@ -382,7 +382,7 @@ int main(int argc, char **argv) { | |||
382 | 382 | ||
383 | wlr_log(L_INFO, "Starting sway version " SWAY_VERSION); | 383 | wlr_log(L_INFO, "Starting sway version " SWAY_VERSION); |
384 | 384 | ||
385 | init_layout(); | 385 | layout_init(); |
386 | 386 | ||
387 | if (!server_init(&server)) { | 387 | if (!server_init(&server)) { |
388 | return 1; | 388 | return 1; |
diff --git a/sway/tree/container.c b/sway/tree/container.c index bbafe9ec..40047dcf 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -7,14 +7,14 @@ | |||
7 | #include <wlr/types/wlr_output_layout.h> | 7 | #include <wlr/types/wlr_output_layout.h> |
8 | #include <wlr/types/wlr_wl_shell.h> | 8 | #include <wlr/types/wlr_wl_shell.h> |
9 | #include "sway/config.h" | 9 | #include "sway/config.h" |
10 | #include "sway/container.h" | 10 | #include "sway/tree/container.h" |
11 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
12 | #include "sway/input/seat.h" | 12 | #include "sway/input/seat.h" |
13 | #include "sway/layout.h" | 13 | #include "sway/tree/layout.h" |
14 | #include "sway/output.h" | 14 | #include "sway/output.h" |
15 | #include "sway/server.h" | 15 | #include "sway/server.h" |
16 | #include "sway/view.h" | 16 | #include "sway/tree/view.h" |
17 | #include "sway/workspace.h" | 17 | #include "sway/tree/workspace.h" |
18 | #include "sway/ipc-server.h" | 18 | #include "sway/ipc-server.h" |
19 | #include "log.h" | 19 | #include "log.h" |
20 | 20 | ||
@@ -33,48 +33,15 @@ static list_t *get_bfs_queue() { | |||
33 | return bfs_queue; | 33 | return bfs_queue; |
34 | } | 34 | } |
35 | 35 | ||
36 | static void notify_new_container(swayc_t *container) { | 36 | static void notify_new_container(struct sway_container *container) { |
37 | wl_signal_emit(&root_container.sway_root->events.new_container, container); | 37 | wl_signal_emit(&root_container.sway_root->events.new_container, container); |
38 | ipc_event_window(container, "new"); | 38 | ipc_event_window(container, "new"); |
39 | } | 39 | } |
40 | 40 | ||
41 | swayc_t *swayc_by_test(swayc_t *container, | 41 | static struct sway_container *container_create(enum sway_container_type type) { |
42 | bool (*test)(swayc_t *view, void *data), void *data) { | ||
43 | if (!container->children) { | ||
44 | return NULL; | ||
45 | } | ||
46 | // TODO: floating windows | ||
47 | for (int i = 0; i < container->children->length; ++i) { | ||
48 | swayc_t *child = container->children->items[i]; | ||
49 | if (test(child, data)) { | ||
50 | return child; | ||
51 | } else { | ||
52 | swayc_t *res = swayc_by_test(child, test, data); | ||
53 | if (res) { | ||
54 | return res; | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | return NULL; | ||
59 | } | ||
60 | |||
61 | void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | ||
62 | void (*func)(swayc_t *item, void *data), void *data) { | ||
63 | for (int i = 0; i < root->children->length; ++i) { | ||
64 | swayc_t *item = root->children->items[i]; | ||
65 | if (item->type == type) { | ||
66 | func(item, data); | ||
67 | } | ||
68 | if (item->children && item->children->length) { | ||
69 | swayc_descendants_of_type(item, type, func, data); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | |||
74 | static swayc_t *new_swayc(enum swayc_types type) { | ||
75 | // next id starts at 1 because 0 is assigned to root_container in layout.c | 42 | // next id starts at 1 because 0 is assigned to root_container in layout.c |
76 | static size_t next_id = 1; | 43 | static size_t next_id = 1; |
77 | swayc_t *c = calloc(1, sizeof(swayc_t)); | 44 | struct sway_container *c = calloc(1, sizeof(struct sway_container)); |
78 | if (!c) { | 45 | if (!c) { |
79 | return NULL; | 46 | return NULL; |
80 | } | 47 | } |
@@ -82,8 +49,6 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
82 | c->layout = L_NONE; | 49 | c->layout = L_NONE; |
83 | c->workspace_layout = L_NONE; | 50 | c->workspace_layout = L_NONE; |
84 | c->type = type; | 51 | c->type = type; |
85 | c->nb_master = 1; | ||
86 | c->nb_slave_groups = 1; | ||
87 | if (type != C_VIEW) { | 52 | if (type != C_VIEW) { |
88 | c->children = create_list(); | 53 | c->children = create_list(); |
89 | } | 54 | } |
@@ -93,18 +58,18 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
93 | return c; | 58 | return c; |
94 | } | 59 | } |
95 | 60 | ||
96 | static void free_swayc(swayc_t *cont) { | 61 | static void container_destroy(struct sway_container *cont) { |
97 | if (!sway_assert(cont, "free_swayc passed NULL")) { | 62 | if (cont == NULL) { |
98 | return; | 63 | return; |
99 | } | 64 | } |
100 | 65 | ||
101 | wl_signal_emit(&cont->events.destroy, cont); | 66 | wl_signal_emit(&cont->events.destroy, cont); |
102 | 67 | ||
103 | if (cont->children) { | 68 | if (cont->children) { |
104 | // remove children until there are no more, free_swayc calls | 69 | // remove children until there are no more, container_destroy calls |
105 | // remove_child, which removes child from this container | 70 | // container_remove_child, which removes child from this container |
106 | while (cont->children->length) { | 71 | while (cont->children->length) { |
107 | free_swayc(cont->children->items[0]); | 72 | container_destroy(cont->children->items[0]); |
108 | } | 73 | } |
109 | list_free(cont->children); | 74 | list_free(cont->children); |
110 | } | 75 | } |
@@ -113,7 +78,7 @@ static void free_swayc(swayc_t *cont) { | |||
113 | list_free(cont->marks); | 78 | list_free(cont->marks); |
114 | } | 79 | } |
115 | if (cont->parent) { | 80 | if (cont->parent) { |
116 | remove_child(cont); | 81 | container_remove_child(cont); |
117 | } | 82 | } |
118 | if (cont->name) { | 83 | if (cont->name) { |
119 | free(cont->name); | 84 | free(cont->name); |
@@ -121,7 +86,8 @@ static void free_swayc(swayc_t *cont) { | |||
121 | free(cont); | 86 | free(cont); |
122 | } | 87 | } |
123 | 88 | ||
124 | swayc_t *new_output(struct sway_output *sway_output) { | 89 | struct sway_container *container_output_create( |
90 | struct sway_output *sway_output) { | ||
125 | struct wlr_box size; | 91 | struct wlr_box size; |
126 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, | 92 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, |
127 | &size.height); | 93 | &size.height); |
@@ -156,22 +122,22 @@ swayc_t *new_output(struct sway_output *sway_output) { | |||
156 | return NULL; | 122 | return NULL; |
157 | } | 123 | } |
158 | 124 | ||
159 | swayc_t *output = new_swayc(C_OUTPUT); | 125 | struct sway_container *output = container_create(C_OUTPUT); |
160 | output->sway_output = sway_output; | 126 | output->sway_output = sway_output; |
161 | output->name = strdup(name); | 127 | output->name = strdup(name); |
162 | if (output->name == NULL) { | 128 | if (output->name == NULL) { |
163 | free_swayc(output); | 129 | container_destroy(output); |
164 | return NULL; | 130 | return NULL; |
165 | } | 131 | } |
166 | 132 | ||
167 | apply_output_config(oc, output); | 133 | apply_output_config(oc, output); |
168 | 134 | ||
169 | add_child(&root_container, output); | 135 | container_add_child(&root_container, output); |
170 | 136 | ||
171 | // Create workspace | 137 | // Create workspace |
172 | char *ws_name = workspace_next_name(output->name); | 138 | char *ws_name = workspace_next_name(output->name); |
173 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); | 139 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); |
174 | swayc_t *ws = new_workspace(output, ws_name); | 140 | struct sway_container *ws = container_workspace_create(output, ws_name); |
175 | // Set each seat's focus if not already set | 141 | // Set each seat's focus if not already set |
176 | struct sway_seat *seat = NULL; | 142 | struct sway_seat *seat = NULL; |
177 | wl_list_for_each(seat, &input_manager->seats, link) { | 143 | wl_list_for_each(seat, &input_manager->seats, link) { |
@@ -185,12 +151,14 @@ swayc_t *new_output(struct sway_output *sway_output) { | |||
185 | return output; | 151 | return output; |
186 | } | 152 | } |
187 | 153 | ||
188 | swayc_t *new_workspace(swayc_t *output, const char *name) { | 154 | struct sway_container *container_workspace_create( |
189 | if (!sway_assert(output, "new_workspace called with null output")) { | 155 | struct sway_container *output, const char *name) { |
156 | if (!sway_assert(output, | ||
157 | "container_workspace_create called with null output")) { | ||
190 | return NULL; | 158 | return NULL; |
191 | } | 159 | } |
192 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); | 160 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); |
193 | swayc_t *workspace = new_swayc(C_WORKSPACE); | 161 | struct sway_container *workspace = container_create(C_WORKSPACE); |
194 | 162 | ||
195 | workspace->x = output->x; | 163 | workspace->x = output->x; |
196 | workspace->y = output->y; | 164 | workspace->y = output->y; |
@@ -198,21 +166,23 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
198 | workspace->height = output->height; | 166 | workspace->height = output->height; |
199 | workspace->name = !name ? NULL : strdup(name); | 167 | workspace->name = !name ? NULL : strdup(name); |
200 | workspace->prev_layout = L_NONE; | 168 | workspace->prev_layout = L_NONE; |
201 | workspace->layout = default_layout(output); | 169 | workspace->layout = container_get_default_layout(output); |
202 | workspace->workspace_layout = default_layout(output); | 170 | workspace->workspace_layout = container_get_default_layout(output); |
203 | 171 | ||
204 | add_child(output, workspace); | 172 | container_add_child(output, workspace); |
205 | sort_workspaces(output); | 173 | container_sort_workspaces(output); |
206 | notify_new_container(workspace); | 174 | notify_new_container(workspace); |
207 | return workspace; | 175 | return workspace; |
208 | } | 176 | } |
209 | 177 | ||
210 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { | 178 | struct sway_container *container_view_create(struct sway_container *sibling, |
211 | if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { | 179 | struct sway_view *sway_view) { |
180 | if (!sway_assert(sibling, | ||
181 | "container_view_create called with NULL sibling/parent")) { | ||
212 | return NULL; | 182 | return NULL; |
213 | } | 183 | } |
214 | const char *title = view_get_title(sway_view); | 184 | const char *title = view_get_title(sway_view); |
215 | swayc_t *swayc = new_swayc(C_VIEW); | 185 | struct sway_container *swayc = container_create(C_VIEW); |
216 | wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", | 186 | wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", |
217 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); | 187 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); |
218 | // Setup values | 188 | // Setup values |
@@ -223,17 +193,18 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { | |||
223 | 193 | ||
224 | if (sibling->type == C_WORKSPACE) { | 194 | if (sibling->type == C_WORKSPACE) { |
225 | // Case of focused workspace, just create as child of it | 195 | // Case of focused workspace, just create as child of it |
226 | add_child(sibling, swayc); | 196 | container_add_child(sibling, swayc); |
227 | } else { | 197 | } else { |
228 | // Regular case, create as sibling of current container | 198 | // Regular case, create as sibling of current container |
229 | add_sibling(sibling, swayc); | 199 | container_add_sibling(sibling, swayc); |
230 | } | 200 | } |
231 | notify_new_container(swayc); | 201 | notify_new_container(swayc); |
232 | return swayc; | 202 | return swayc; |
233 | } | 203 | } |
234 | 204 | ||
235 | swayc_t *destroy_output(swayc_t *output) { | 205 | struct sway_container *container_output_destroy(struct sway_container *output) { |
236 | if (!sway_assert(output, "null output passed to destroy_output")) { | 206 | if (!sway_assert(output, |
207 | "null output passed to container_output_destroy")) { | ||
237 | return NULL; | 208 | return NULL; |
238 | } | 209 | } |
239 | 210 | ||
@@ -245,12 +216,13 @@ swayc_t *destroy_output(swayc_t *output) { | |||
245 | int p = root_container.children->items[0] == output; | 216 | int p = root_container.children->items[0] == output; |
246 | // Move workspace from this output to another output | 217 | // Move workspace from this output to another output |
247 | while (output->children->length) { | 218 | while (output->children->length) { |
248 | swayc_t *child = output->children->items[0]; | 219 | struct sway_container *child = output->children->items[0]; |
249 | remove_child(child); | 220 | container_remove_child(child); |
250 | add_child(root_container.children->items[p], child); | 221 | container_add_child(root_container.children->items[p], child); |
251 | } | 222 | } |
252 | sort_workspaces(root_container.children->items[p]); | 223 | container_sort_workspaces(root_container.children->items[p]); |
253 | arrange_windows(root_container.children->items[p], -1, -1); | 224 | arrange_windows(root_container.children->items[p], |
225 | -1, -1); | ||
254 | } | 226 | } |
255 | } | 227 | } |
256 | 228 | ||
@@ -259,18 +231,18 @@ swayc_t *destroy_output(swayc_t *output) { | |||
259 | wl_list_remove(&output->sway_output->mode.link); | 231 | wl_list_remove(&output->sway_output->mode.link); |
260 | 232 | ||
261 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | 233 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); |
262 | free_swayc(output); | 234 | container_destroy(output); |
263 | 235 | ||
264 | return &root_container; | 236 | return &root_container; |
265 | } | 237 | } |
266 | 238 | ||
267 | swayc_t *destroy_view(swayc_t *view) { | 239 | struct sway_container *container_view_destroy(struct sway_container *view) { |
268 | if (!view) { | 240 | if (!view) { |
269 | return NULL; | 241 | return NULL; |
270 | } | 242 | } |
271 | wlr_log(L_DEBUG, "Destroying view '%s'", view->name); | 243 | wlr_log(L_DEBUG, "Destroying view '%s'", view->name); |
272 | swayc_t *parent = view->parent; | 244 | struct sway_container *parent = view->parent; |
273 | free_swayc(view); | 245 | container_destroy(view); |
274 | 246 | ||
275 | // TODO WLR: Destroy empty containers | 247 | // TODO WLR: Destroy empty containers |
276 | /* | 248 | /* |
@@ -281,7 +253,55 @@ swayc_t *destroy_view(swayc_t *view) { | |||
281 | return parent; | 253 | return parent; |
282 | } | 254 | } |
283 | 255 | ||
284 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | 256 | struct sway_container *container_set_layout(struct sway_container *container, |
257 | enum sway_container_layout layout) { | ||
258 | if (container->type == C_WORKSPACE) { | ||
259 | container->workspace_layout = layout; | ||
260 | if (layout == L_HORIZ || layout == L_VERT) { | ||
261 | container->layout = layout; | ||
262 | } | ||
263 | } else { | ||
264 | container->layout = layout; | ||
265 | } | ||
266 | return container; | ||
267 | } | ||
268 | |||
269 | void container_descendents(struct sway_container *root, | ||
270 | enum sway_container_type type, | ||
271 | void (*func)(struct sway_container *item, void *data), void *data) { | ||
272 | for (int i = 0; i < root->children->length; ++i) { | ||
273 | struct sway_container *item = root->children->items[i]; | ||
274 | if (item->type == type) { | ||
275 | func(item, data); | ||
276 | } | ||
277 | if (item->children && item->children->length) { | ||
278 | container_descendents(item, type, func, data); | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | struct sway_container *container_find(struct sway_container *container, | ||
284 | bool (*test)(struct sway_container *view, void *data), void *data) { | ||
285 | if (!container->children) { | ||
286 | return NULL; | ||
287 | } | ||
288 | // TODO: floating windows | ||
289 | for (int i = 0; i < container->children->length; ++i) { | ||
290 | struct sway_container *child = container->children->items[i]; | ||
291 | if (test(child, data)) { | ||
292 | return child; | ||
293 | } else { | ||
294 | struct sway_container *res = container_find(child, test, data); | ||
295 | if (res) { | ||
296 | return res; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | return NULL; | ||
301 | } | ||
302 | |||
303 | struct sway_container *container_parent(struct sway_container *container, | ||
304 | enum sway_container_type type) { | ||
285 | if (!sway_assert(container, "container is NULL")) { | 305 | if (!sway_assert(container, "container is NULL")) { |
286 | return NULL; | 306 | return NULL; |
287 | } | 307 | } |
@@ -294,7 +314,8 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | |||
294 | return container; | 314 | return container; |
295 | } | 315 | } |
296 | 316 | ||
297 | swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | 317 | struct sway_container *container_at(struct sway_container *parent, |
318 | double lx, double ly, | ||
298 | struct wlr_surface **surface, double *sx, double *sy) { | 319 | struct wlr_surface **surface, double *sx, double *sy) { |
299 | list_t *queue = get_bfs_queue(); | 320 | list_t *queue = get_bfs_queue(); |
300 | if (!queue) { | 321 | if (!queue) { |
@@ -303,13 +324,13 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | |||
303 | 324 | ||
304 | list_add(queue, parent); | 325 | list_add(queue, parent); |
305 | 326 | ||
306 | swayc_t *swayc = NULL; | 327 | struct sway_container *swayc = NULL; |
307 | while (queue->length) { | 328 | while (queue->length) { |
308 | swayc = queue->items[0]; | 329 | swayc = queue->items[0]; |
309 | list_del(queue, 0); | 330 | list_del(queue, 0); |
310 | if (swayc->type == C_VIEW) { | 331 | if (swayc->type == C_VIEW) { |
311 | struct sway_view *sview = swayc->sway_view; | 332 | struct sway_view *sview = swayc->sway_view; |
312 | swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); | 333 | struct sway_container *soutput = container_parent(swayc, C_OUTPUT); |
313 | struct wlr_box *output_box = | 334 | struct wlr_box *output_box = |
314 | wlr_output_layout_get_box( | 335 | wlr_output_layout_get_box( |
315 | root_container.sway_root->output_layout, | 336 | root_container.sway_root->output_layout, |
@@ -379,30 +400,8 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | |||
379 | return NULL; | 400 | return NULL; |
380 | } | 401 | } |
381 | 402 | ||
382 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { | 403 | void container_for_each_descendent(struct sway_container *con, |
383 | if (container) { | 404 | void (*f)(struct sway_container *con, void *data), void *data) { |
384 | int i; | ||
385 | if (container->children) { | ||
386 | for (i = 0; i < container->children->length; ++i) { | ||
387 | swayc_t *child = container->children->items[i]; | ||
388 | container_map(child, f, data); | ||
389 | } | ||
390 | } | ||
391 | // TODO | ||
392 | /* | ||
393 | if (container->floating) { | ||
394 | for (i = 0; i < container->floating->length; ++i) { | ||
395 | swayc_t *child = container->floating->items[i]; | ||
396 | container_map(child, f, data); | ||
397 | } | ||
398 | } | ||
399 | */ | ||
400 | f(container, data); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | ||
405 | void *data) { | ||
406 | list_t *queue = get_bfs_queue(); | 405 | list_t *queue = get_bfs_queue(); |
407 | if (!queue) { | 406 | if (!queue) { |
408 | return; | 407 | return; |
@@ -415,7 +414,7 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | |||
415 | 414 | ||
416 | list_add(queue, con); | 415 | list_add(queue, con); |
417 | 416 | ||
418 | swayc_t *current = NULL; | 417 | struct sway_container *current = NULL; |
419 | while (queue->length) { | 418 | while (queue->length) { |
420 | current = queue->items[0]; | 419 | current = queue->items[0]; |
421 | list_del(queue, 0); | 420 | list_del(queue, 0); |
@@ -424,15 +423,3 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | |||
424 | list_cat(queue, current->children); | 423 | list_cat(queue, current->children); |
425 | } | 424 | } |
426 | } | 425 | } |
427 | |||
428 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { | ||
429 | if (container->type == C_WORKSPACE) { | ||
430 | container->workspace_layout = layout; | ||
431 | if (layout == L_HORIZ || layout == L_VERT) { | ||
432 | container->layout = layout; | ||
433 | } | ||
434 | } else { | ||
435 | container->layout = layout; | ||
436 | } | ||
437 | return container; | ||
438 | } | ||
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index de9e7b58..dc0ee5b4 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -6,24 +6,26 @@ | |||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <wlr/types/wlr_output.h> | 7 | #include <wlr/types/wlr_output.h> |
8 | #include <wlr/types/wlr_output_layout.h> | 8 | #include <wlr/types/wlr_output_layout.h> |
9 | #include "sway/container.h" | 9 | #include "sway/tree/container.h" |
10 | #include "sway/layout.h" | 10 | #include "sway/tree/layout.h" |
11 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/view.h" | 12 | #include "sway/tree/view.h" |
13 | #include "sway/input/seat.h" | 13 | #include "sway/input/seat.h" |
14 | #include "list.h" | 14 | #include "list.h" |
15 | #include "log.h" | 15 | #include "log.h" |
16 | 16 | ||
17 | swayc_t root_container; | 17 | struct sway_container root_container; |
18 | 18 | ||
19 | static void output_layout_change_notify(struct wl_listener *listener, void *data) { | 19 | static void output_layout_change_notify(struct wl_listener *listener, |
20 | void *data) { | ||
20 | struct wlr_box *layout_box = wlr_output_layout_get_box( | 21 | struct wlr_box *layout_box = wlr_output_layout_get_box( |
21 | root_container.sway_root->output_layout, NULL); | 22 | root_container.sway_root->output_layout, NULL); |
22 | root_container.width = layout_box->width; | 23 | root_container.width = layout_box->width; |
23 | root_container.height = layout_box->height; | 24 | root_container.height = layout_box->height; |
24 | 25 | ||
25 | for (int i = 0 ; i < root_container.children->length; ++i) { | 26 | for (int i = 0 ; i < root_container.children->length; ++i) { |
26 | swayc_t *output_container = root_container.children->items[i]; | 27 | struct sway_container *output_container = |
28 | root_container.children->items[i]; | ||
27 | if (output_container->type != C_OUTPUT) { | 29 | if (output_container->type != C_OUTPUT) { |
28 | continue; | 30 | continue; |
29 | } | 31 | } |
@@ -43,7 +45,7 @@ static void output_layout_change_notify(struct wl_listener *listener, void *data | |||
43 | arrange_windows(&root_container, -1, -1); | 45 | arrange_windows(&root_container, -1, -1); |
44 | } | 46 | } |
45 | 47 | ||
46 | void init_layout(void) { | 48 | void layout_init(void) { |
47 | root_container.id = 0; // normally assigned in new_swayc() | 49 | root_container.id = 0; // normally assigned in new_swayc() |
48 | root_container.type = C_ROOT; | 50 | root_container.type = C_ROOT; |
49 | root_container.layout = L_NONE; | 51 | root_container.layout = L_NONE; |
@@ -62,9 +64,9 @@ void init_layout(void) { | |||
62 | &root_container.sway_root->output_layout_change); | 64 | &root_container.sway_root->output_layout_change); |
63 | } | 65 | } |
64 | 66 | ||
65 | static int index_child(const swayc_t *child) { | 67 | static int index_child(const struct sway_container *child) { |
66 | // TODO handle floating | 68 | // TODO handle floating |
67 | swayc_t *parent = child->parent; | 69 | struct sway_container *parent = child->parent; |
68 | int i, len; | 70 | int i, len; |
69 | len = parent->children->length; | 71 | len = parent->children->length; |
70 | for (i = 0; i < len; ++i) { | 72 | for (i = 0; i < len; ++i) { |
@@ -79,16 +81,18 @@ static int index_child(const swayc_t *child) { | |||
79 | return i; | 81 | return i; |
80 | } | 82 | } |
81 | 83 | ||
82 | swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { | 84 | struct sway_container *container_add_sibling(struct sway_container *fixed, |
85 | struct sway_container *active) { | ||
83 | // TODO handle floating | 86 | // TODO handle floating |
84 | swayc_t *parent = fixed->parent; | 87 | struct sway_container *parent = fixed->parent; |
85 | int i = index_child(fixed); | 88 | int i = index_child(fixed); |
86 | list_insert(parent->children, i + 1, active); | 89 | list_insert(parent->children, i + 1, active); |
87 | active->parent = parent; | 90 | active->parent = parent; |
88 | return active->parent; | 91 | return active->parent; |
89 | } | 92 | } |
90 | 93 | ||
91 | void add_child(swayc_t *parent, swayc_t *child) { | 94 | void container_add_child(struct sway_container *parent, |
95 | struct sway_container *child) { | ||
92 | wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", | 96 | wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", |
93 | child, child->type, child->width, child->height, | 97 | child, child->type, child->width, child->height, |
94 | parent, parent->type, parent->width, parent->height); | 98 | parent, parent->type, parent->width, parent->height); |
@@ -96,15 +100,17 @@ void add_child(swayc_t *parent, swayc_t *child) { | |||
96 | child->parent = parent; | 100 | child->parent = parent; |
97 | // set focus for this container | 101 | // set focus for this container |
98 | /* TODO WLR | 102 | /* TODO WLR |
99 | if (parent->type == C_WORKSPACE && child->type == C_VIEW && (parent->workspace_layout == L_TABBED || parent->workspace_layout == L_STACKED)) { | 103 | if (parent->type == C_WORKSPACE && child->type == C_VIEW && |
104 | (parent->workspace_layout == L_TABBED || parent->workspace_layout == | ||
105 | L_STACKED)) { | ||
100 | child = new_container(child, parent->workspace_layout); | 106 | child = new_container(child, parent->workspace_layout); |
101 | } | 107 | } |
102 | */ | 108 | */ |
103 | } | 109 | } |
104 | 110 | ||
105 | swayc_t *remove_child(swayc_t *child) { | 111 | struct sway_container *container_remove_child(struct sway_container *child) { |
106 | int i; | 112 | int i; |
107 | swayc_t *parent = child->parent; | 113 | struct sway_container *parent = child->parent; |
108 | for (i = 0; i < parent->children->length; ++i) { | 114 | for (i = 0; i < parent->children->length; ++i) { |
109 | if (parent->children->items[i] == child) { | 115 | if (parent->children->items[i] == child) { |
110 | list_del(parent->children, i); | 116 | list_del(parent->children, i); |
@@ -115,7 +121,8 @@ swayc_t *remove_child(swayc_t *child) { | |||
115 | return parent; | 121 | return parent; |
116 | } | 122 | } |
117 | 123 | ||
118 | enum swayc_layouts default_layout(swayc_t *output) { | 124 | enum sway_container_layout container_get_default_layout( |
125 | struct sway_container *output) { | ||
119 | /* TODO WLR | 126 | /* TODO WLR |
120 | if (config->default_layout != L_NONE) { | 127 | if (config->default_layout != L_NONE) { |
121 | //return config->default_layout; | 128 | //return config->default_layout; |
@@ -129,8 +136,8 @@ enum swayc_layouts default_layout(swayc_t *output) { | |||
129 | } | 136 | } |
130 | 137 | ||
131 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | 138 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { |
132 | swayc_t *a = *(void **)_a; | 139 | struct sway_container *a = *(void **)_a; |
133 | swayc_t *b = *(void **)_b; | 140 | struct sway_container *b = *(void **)_b; |
134 | int retval = 0; | 141 | int retval = 0; |
135 | 142 | ||
136 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { | 143 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { |
@@ -146,21 +153,22 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | |||
146 | return retval; | 153 | return retval; |
147 | } | 154 | } |
148 | 155 | ||
149 | void sort_workspaces(swayc_t *output) { | 156 | void container_sort_workspaces(struct sway_container *output) { |
150 | list_stable_sort(output->children, sort_workspace_cmp_qsort); | 157 | list_stable_sort(output->children, sort_workspace_cmp_qsort); |
151 | } | 158 | } |
152 | 159 | ||
153 | static void apply_horiz_layout(swayc_t *container, const double x, | 160 | static void apply_horiz_layout(struct sway_container *container, const double x, |
154 | const double y, const double width, | 161 | const double y, const double width, |
155 | const double height, const int start, | 162 | const double height, const int start, |
156 | const int end); | 163 | const int end); |
157 | 164 | ||
158 | static void apply_vert_layout(swayc_t *container, const double x, | 165 | static void apply_vert_layout(struct sway_container *container, const double x, |
159 | const double y, const double width, | 166 | const double y, const double width, |
160 | const double height, const int start, | 167 | const double height, const int start, |
161 | const int end); | 168 | const int end); |
162 | 169 | ||
163 | void arrange_windows(swayc_t *container, double width, double height) { | 170 | void arrange_windows(struct sway_container *container, |
171 | double width, double height) { | ||
164 | int i; | 172 | int i; |
165 | if (width == -1 || height == -1) { | 173 | if (width == -1 || height == -1) { |
166 | width = container->width; | 174 | width = container->width; |
@@ -181,7 +189,7 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
181 | case C_ROOT: | 189 | case C_ROOT: |
182 | // TODO: wlr_output_layout probably | 190 | // TODO: wlr_output_layout probably |
183 | for (i = 0; i < container->children->length; ++i) { | 191 | for (i = 0; i < container->children->length; ++i) { |
184 | swayc_t *output = container->children->items[i]; | 192 | struct sway_container *output = container->children->items[i]; |
185 | wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", | 193 | wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", |
186 | output->name, output->x, output->y); | 194 | output->name, output->x, output->y); |
187 | arrange_windows(output, -1, -1); | 195 | arrange_windows(output, -1, -1); |
@@ -197,13 +205,14 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
197 | } | 205 | } |
198 | // arrange all workspaces: | 206 | // arrange all workspaces: |
199 | for (i = 0; i < container->children->length; ++i) { | 207 | for (i = 0; i < container->children->length; ++i) { |
200 | swayc_t *child = container->children->items[i]; | 208 | struct sway_container *child = container->children->items[i]; |
201 | arrange_windows(child, -1, -1); | 209 | arrange_windows(child, -1, -1); |
202 | } | 210 | } |
203 | return; | 211 | return; |
204 | case C_WORKSPACE: | 212 | case C_WORKSPACE: |
205 | { | 213 | { |
206 | swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); | 214 | struct sway_container *output = |
215 | container_parent(container, C_OUTPUT); | ||
207 | struct wlr_box *area = &output->sway_output->usable_area; | 216 | struct wlr_box *area = &output->sway_output->usable_area; |
208 | wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", | 217 | wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", |
209 | area->width, area->height, area->x, area->y); | 218 | area->width, area->height, area->x, area->y); |
@@ -252,14 +261,15 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
252 | } | 261 | } |
253 | } | 262 | } |
254 | 263 | ||
255 | static void apply_horiz_layout(swayc_t *container, | 264 | static void apply_horiz_layout(struct sway_container *container, |
256 | const double x, const double y, | 265 | const double x, const double y, |
257 | const double width, const double height, | 266 | const double width, const double height, |
258 | const int start, const int end) { | 267 | const int start, const int end) { |
259 | double scale = 0; | 268 | double scale = 0; |
260 | // Calculate total width | 269 | // Calculate total width |
261 | for (int i = start; i < end; ++i) { | 270 | for (int i = start; i < end; ++i) { |
262 | double *old_width = &((swayc_t *)container->children->items[i])->width; | 271 | double *old_width = |
272 | &((struct sway_container *)container->children->items[i])->width; | ||
263 | if (*old_width <= 0) { | 273 | if (*old_width <= 0) { |
264 | if (end - start > 1) { | 274 | if (end - start > 1) { |
265 | *old_width = width / (end - start - 1); | 275 | *old_width = width / (end - start - 1); |
@@ -276,7 +286,7 @@ static void apply_horiz_layout(swayc_t *container, | |||
276 | if (scale > 0.1) { | 286 | if (scale > 0.1) { |
277 | wlr_log(L_DEBUG, "Arranging %p horizontally", container); | 287 | wlr_log(L_DEBUG, "Arranging %p horizontally", container); |
278 | for (int i = start; i < end; ++i) { | 288 | for (int i = start; i < end; ++i) { |
279 | swayc_t *child = container->children->items[i]; | 289 | struct sway_container *child = container->children->items[i]; |
280 | wlr_log(L_DEBUG, | 290 | wlr_log(L_DEBUG, |
281 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 291 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
282 | child, child->type, width, scale); | 292 | child, child->type, width, scale); |
@@ -301,7 +311,7 @@ static void apply_horiz_layout(swayc_t *container, | |||
301 | } | 311 | } |
302 | } | 312 | } |
303 | 313 | ||
304 | void apply_vert_layout(swayc_t *container, | 314 | void apply_vert_layout(struct sway_container *container, |
305 | const double x, const double y, | 315 | const double x, const double y, |
306 | const double width, const double height, const int start, | 316 | const double width, const double height, const int start, |
307 | const int end) { | 317 | const int end) { |
@@ -309,7 +319,8 @@ void apply_vert_layout(swayc_t *container, | |||
309 | double scale = 0; | 319 | double scale = 0; |
310 | // Calculate total height | 320 | // Calculate total height |
311 | for (i = start; i < end; ++i) { | 321 | for (i = start; i < end; ++i) { |
312 | double *old_height = &((swayc_t *)container->children->items[i])->height; | 322 | double *old_height = |
323 | &((struct sway_container *)container->children->items[i])->height; | ||
313 | if (*old_height <= 0) { | 324 | if (*old_height <= 0) { |
314 | if (end - start > 1) { | 325 | if (end - start > 1) { |
315 | *old_height = height / (end - start - 1); | 326 | *old_height = height / (end - start - 1); |
@@ -326,7 +337,7 @@ void apply_vert_layout(swayc_t *container, | |||
326 | if (scale > 0.1) { | 337 | if (scale > 0.1) { |
327 | wlr_log(L_DEBUG, "Arranging %p vertically", container); | 338 | wlr_log(L_DEBUG, "Arranging %p vertically", container); |
328 | for (i = start; i < end; ++i) { | 339 | for (i = start; i < end; ++i) { |
329 | swayc_t *child = container->children->items[i]; | 340 | struct sway_container *child = container->children->items[i]; |
330 | wlr_log(L_DEBUG, | 341 | wlr_log(L_DEBUG, |
331 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 342 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
332 | child, child->type, height, scale); | 343 | child, child->type, height, scale); |
@@ -354,15 +365,16 @@ void apply_vert_layout(swayc_t *container, | |||
354 | /** | 365 | /** |
355 | * Get swayc in the direction of newly entered output. | 366 | * Get swayc in the direction of newly entered output. |
356 | */ | 367 | */ |
357 | static swayc_t *get_swayc_in_output_direction(swayc_t *output, | 368 | static struct sway_container *get_swayc_in_output_direction( |
358 | enum movement_direction dir, struct sway_seat *seat) { | 369 | struct sway_container *output, enum movement_direction dir, |
370 | struct sway_seat *seat) { | ||
359 | if (!output) { | 371 | if (!output) { |
360 | return NULL; | 372 | return NULL; |
361 | } | 373 | } |
362 | 374 | ||
363 | swayc_t *ws = sway_seat_get_focus_inactive(seat, output); | 375 | struct sway_container *ws = sway_seat_get_focus_inactive(seat, output); |
364 | if (ws->type != C_WORKSPACE) { | 376 | if (ws->type != C_WORKSPACE) { |
365 | ws = swayc_parent_by_type(ws, C_WORKSPACE); | 377 | ws = container_parent(ws, C_WORKSPACE); |
366 | } | 378 | } |
367 | 379 | ||
368 | if (ws == NULL) { | 380 | if (ws == NULL) { |
@@ -380,13 +392,15 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, | |||
380 | return ws->children->items[0]; | 392 | return ws->children->items[0]; |
381 | case MOVE_UP: | 393 | case MOVE_UP: |
382 | case MOVE_DOWN: { | 394 | case MOVE_DOWN: { |
383 | swayc_t *focused = sway_seat_get_focus_inactive(seat, ws); | 395 | struct sway_container *focused = |
396 | sway_seat_get_focus_inactive(seat, ws); | ||
384 | if (focused && focused->parent) { | 397 | if (focused && focused->parent) { |
385 | swayc_t *parent = focused->parent; | 398 | struct sway_container *parent = focused->parent; |
386 | if (parent->layout == L_VERT) { | 399 | if (parent->layout == L_VERT) { |
387 | if (dir == MOVE_UP) { | 400 | if (dir == MOVE_UP) { |
388 | // get child furthest down on new output | 401 | // get child furthest down on new output |
389 | return parent->children->items[parent->children->length-1]; | 402 | int idx = parent->children->length - 1; |
403 | return parent->children->items[idx]; | ||
390 | } else if (dir == MOVE_DOWN) { | 404 | } else if (dir == MOVE_DOWN) { |
391 | // get child furthest up on new output | 405 | // get child furthest up on new output |
392 | return parent->children->items[0]; | 406 | return parent->children->items[0]; |
@@ -404,13 +418,14 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, | |||
404 | return ws; | 418 | return ws; |
405 | } | 419 | } |
406 | 420 | ||
407 | static void get_layout_center_position(swayc_t *container, int *x, int *y) { | 421 | static void get_layout_center_position(struct sway_container *container, |
422 | int *x, int *y) { | ||
408 | // FIXME view coords are inconsistently referred to in layout/output systems | 423 | // FIXME view coords are inconsistently referred to in layout/output systems |
409 | if (container->type == C_OUTPUT) { | 424 | if (container->type == C_OUTPUT) { |
410 | *x = container->x + container->width/2; | 425 | *x = container->x + container->width/2; |
411 | *y = container->y + container->height/2; | 426 | *y = container->y + container->height/2; |
412 | } else { | 427 | } else { |
413 | swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); | 428 | struct sway_container *output = container_parent(container, C_OUTPUT); |
414 | if (container->type == C_WORKSPACE) { | 429 | if (container->type == C_WORKSPACE) { |
415 | // Workspace coordinates are actually wrong/arbitrary, but should | 430 | // Workspace coordinates are actually wrong/arbitrary, but should |
416 | // be same as output. | 431 | // be same as output. |
@@ -423,7 +438,8 @@ static void get_layout_center_position(swayc_t *container, int *x, int *y) { | |||
423 | } | 438 | } |
424 | } | 439 | } |
425 | 440 | ||
426 | static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) { | 441 | static bool sway_dir_to_wlr(enum movement_direction dir, |
442 | enum wlr_direction *out) { | ||
427 | switch (dir) { | 443 | switch (dir) { |
428 | case MOVE_UP: | 444 | case MOVE_UP: |
429 | *out = WLR_DIRECTION_UP; | 445 | *out = WLR_DIRECTION_UP; |
@@ -444,12 +460,12 @@ static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out | |||
444 | return true; | 460 | return true; |
445 | } | 461 | } |
446 | 462 | ||
447 | static swayc_t *sway_output_from_wlr(struct wlr_output *output) { | 463 | static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { |
448 | if (output == NULL) { | 464 | if (output == NULL) { |
449 | return NULL; | 465 | return NULL; |
450 | } | 466 | } |
451 | for (int i = 0; i < root_container.children->length; ++i) { | 467 | for (int i = 0; i < root_container.children->length; ++i) { |
452 | swayc_t *o = root_container.children->items[i]; | 468 | struct sway_container *o = root_container.children->items[i]; |
453 | if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { | 469 | if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { |
454 | return o; | 470 | return o; |
455 | } | 471 | } |
@@ -457,13 +473,14 @@ static swayc_t *sway_output_from_wlr(struct wlr_output *output) { | |||
457 | return NULL; | 473 | return NULL; |
458 | } | 474 | } |
459 | 475 | ||
460 | static swayc_t *get_swayc_in_direction_under(swayc_t *container, | 476 | static struct sway_container *get_swayc_in_direction_under( |
461 | enum movement_direction dir, struct sway_seat *seat, swayc_t *limit) { | 477 | struct sway_container *container, enum movement_direction dir, |
478 | struct sway_seat *seat, struct sway_container *limit) { | ||
462 | if (dir == MOVE_CHILD) { | 479 | if (dir == MOVE_CHILD) { |
463 | return sway_seat_get_focus_inactive(seat, container); | 480 | return sway_seat_get_focus_inactive(seat, container); |
464 | } | 481 | } |
465 | 482 | ||
466 | swayc_t *parent = container->parent; | 483 | struct sway_container *parent = container->parent; |
467 | if (dir == MOVE_PARENT) { | 484 | if (dir == MOVE_PARENT) { |
468 | if (parent->type == C_OUTPUT) { | 485 | if (parent->type == C_OUTPUT) { |
469 | return NULL; | 486 | return NULL; |
@@ -496,9 +513,10 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
496 | /* | 513 | /* |
497 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { | 514 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { |
498 | wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); | 515 | wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); |
499 | container = swayc_parent_by_type(container, C_OUTPUT); | 516 | container = container_parent(container, C_OUTPUT); |
500 | get_layout_center_position(container, &abs_pos); | 517 | get_layout_center_position(container, &abs_pos); |
501 | swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); | 518 | struct sway_container *output = |
519 | swayc_adjacent_output(container, dir, &abs_pos, true); | ||
502 | return get_swayc_in_output_direction(output, dir); | 520 | return get_swayc_in_output_direction(output, dir); |
503 | } | 521 | } |
504 | if (container->type == C_WORKSPACE && container->fullscreen) { | 522 | if (container->type == C_WORKSPACE && container->fullscreen) { |
@@ -507,7 +525,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
507 | } | 525 | } |
508 | */ | 526 | */ |
509 | 527 | ||
510 | swayc_t *wrap_candidate = NULL; | 528 | struct sway_container *wrap_candidate = NULL; |
511 | while (true) { | 529 | while (true) { |
512 | // Test if we can even make a difference here | 530 | // Test if we can even make a difference here |
513 | bool can_move = false; | 531 | bool can_move = false; |
@@ -521,16 +539,19 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
521 | } | 539 | } |
522 | int lx, ly; | 540 | int lx, ly; |
523 | get_layout_center_position(container, &lx, &ly); | 541 | get_layout_center_position(container, &lx, &ly); |
524 | struct wlr_output_layout *layout = root_container.sway_root->output_layout; | 542 | struct wlr_output_layout *layout = |
543 | root_container.sway_root->output_layout; | ||
525 | struct wlr_output *wlr_adjacent = | 544 | struct wlr_output *wlr_adjacent = |
526 | wlr_output_layout_adjacent_output(layout, wlr_dir, | 545 | wlr_output_layout_adjacent_output(layout, wlr_dir, |
527 | container->sway_output->wlr_output, lx, ly); | 546 | container->sway_output->wlr_output, lx, ly); |
528 | swayc_t *adjacent = sway_output_from_wlr(wlr_adjacent); | 547 | struct sway_container *adjacent = |
548 | sway_output_from_wlr(wlr_adjacent); | ||
529 | 549 | ||
530 | if (!adjacent || adjacent == container) { | 550 | if (!adjacent || adjacent == container) { |
531 | return wrap_candidate; | 551 | return wrap_candidate; |
532 | } | 552 | } |
533 | swayc_t *next = get_swayc_in_output_direction(adjacent, dir, seat); | 553 | struct sway_container *next = |
554 | get_swayc_in_output_direction(adjacent, dir, seat); | ||
534 | if (next == NULL) { | 555 | if (next == NULL) { |
535 | return NULL; | 556 | return NULL; |
536 | } | 557 | } |
@@ -570,8 +591,9 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
570 | } | 591 | } |
571 | } | 592 | } |
572 | } else { | 593 | } else { |
573 | wlr_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__, | 594 | wlr_log(L_DEBUG, |
574 | idx, container, dir, desired, parent->children->items[desired]); | 595 | "cont %d-%p dir %i sibling %d: %p", idx, |
596 | container, dir, desired, parent->children->items[desired]); | ||
575 | return parent->children->items[desired]; | 597 | return parent->children->items[desired]; |
576 | } | 598 | } |
577 | } | 599 | } |
@@ -587,7 +609,8 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
587 | } | 609 | } |
588 | } | 610 | } |
589 | 611 | ||
590 | swayc_t *get_swayc_in_direction(swayc_t *container, struct sway_seat *seat, | 612 | struct sway_container *container_get_in_direction( |
613 | struct sway_container *container, struct sway_seat *seat, | ||
591 | enum movement_direction dir) { | 614 | enum movement_direction dir) { |
592 | return get_swayc_in_direction_under(container, dir, seat, NULL); | 615 | return get_swayc_in_direction_under(container, dir, seat, NULL); |
593 | } | 616 | } |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 9499adca..d5325c31 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -1,8 +1,8 @@ | |||
1 | #include <wayland-server.h> | 1 | #include <wayland-server.h> |
2 | #include <wlr/types/wlr_output_layout.h> | 2 | #include <wlr/types/wlr_output_layout.h> |
3 | #include "sway/container.h" | 3 | #include "sway/tree/container.h" |
4 | #include "sway/layout.h" | 4 | #include "sway/tree/layout.h" |
5 | #include "sway/view.h" | 5 | #include "sway/tree/view.h" |
6 | 6 | ||
7 | const char *view_get_title(struct sway_view *view) { | 7 | const char *view_get_title(struct sway_view *view) { |
8 | if (view->iface.get_prop) { | 8 | if (view->iface.get_prop) { |
@@ -45,6 +45,7 @@ void view_set_size(struct sway_view *view, int width, int height) { | |||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | // TODO make view coordinates in layout coordinates | ||
48 | void view_set_position(struct sway_view *view, double ox, double oy) { | 49 | void view_set_position(struct sway_view *view, double ox, double oy) { |
49 | if (view->iface.set_position) { | 50 | if (view->iface.set_position) { |
50 | struct wlr_box box = { | 51 | struct wlr_box box = { |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 861fda4d..ba04c55c 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -3,10 +3,10 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <strings.h> | 5 | #include <strings.h> |
6 | #include "sway/container.h" | 6 | #include "sway/tree/container.h" |
7 | #include "sway/input/input-manager.h" | 7 | #include "sway/input/input-manager.h" |
8 | #include "sway/input/seat.h" | 8 | #include "sway/input/seat.h" |
9 | #include "sway/workspace.h" | 9 | #include "sway/tree/workspace.h" |
10 | #include "log.h" | 10 | #include "log.h" |
11 | #include "util.h" | 11 | #include "util.h" |
12 | 12 | ||
@@ -17,7 +17,7 @@ struct workspace_by_number_data { | |||
17 | const char *name; | 17 | const char *name; |
18 | }; | 18 | }; |
19 | 19 | ||
20 | void next_name_map(swayc_t *ws, void *data) { | 20 | void next_name_map(struct sway_container *ws, void *data) { |
21 | int *count = data; | 21 | int *count = data; |
22 | ++count; | 22 | ++count; |
23 | } | 23 | } |
@@ -37,7 +37,7 @@ char *workspace_next_name(const char *output_name) { | |||
37 | return name; | 37 | return name; |
38 | } | 38 | } |
39 | 39 | ||
40 | static bool _workspace_by_number(swayc_t *view, void *data) { | 40 | static bool _workspace_by_number(struct sway_container *view, void *data) { |
41 | if (view->type != C_WORKSPACE) { | 41 | if (view->type != C_WORKSPACE) { |
42 | return false; | 42 | return false; |
43 | } | 43 | } |
@@ -46,27 +46,28 @@ static bool _workspace_by_number(swayc_t *view, void *data) { | |||
46 | return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; | 46 | return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; |
47 | } | 47 | } |
48 | 48 | ||
49 | swayc_t *workspace_by_number(const char* name) { | 49 | struct sway_container *workspace_by_number(const char* name) { |
50 | struct workspace_by_number_data wbnd = {0, "1234567890", name}; | 50 | struct workspace_by_number_data wbnd = {0, "1234567890", name}; |
51 | wbnd.len = strspn(name, wbnd.cset); | 51 | wbnd.len = strspn(name, wbnd.cset); |
52 | if (wbnd.len <= 0) { | 52 | if (wbnd.len <= 0) { |
53 | return NULL; | 53 | return NULL; |
54 | } | 54 | } |
55 | return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd); | 55 | return container_find(&root_container, |
56 | _workspace_by_number, (void *) &wbnd); | ||
56 | } | 57 | } |
57 | 58 | ||
58 | static bool _workspace_by_name(swayc_t *view, void *data) { | 59 | static bool _workspace_by_name(struct sway_container *view, void *data) { |
59 | return (view->type == C_WORKSPACE) && | 60 | return (view->type == C_WORKSPACE) && |
60 | (strcasecmp(view->name, (char *) data) == 0); | 61 | (strcasecmp(view->name, (char *) data) == 0); |
61 | } | 62 | } |
62 | 63 | ||
63 | swayc_t *workspace_by_name(const char *name) { | 64 | struct sway_container *workspace_by_name(const char *name) { |
64 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 65 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
65 | swayc_t *current_workspace = NULL, *current_output = NULL; | 66 | struct sway_container *current_workspace = NULL, *current_output = NULL; |
66 | swayc_t *focus = sway_seat_get_focus(seat); | 67 | struct sway_container *focus = sway_seat_get_focus(seat); |
67 | if (focus) { | 68 | if (focus) { |
68 | current_workspace = swayc_parent_by_type(focus, C_WORKSPACE); | 69 | current_workspace = container_parent(focus, C_WORKSPACE); |
69 | current_output = swayc_parent_by_type(focus, C_OUTPUT); | 70 | current_output = container_parent(focus, C_OUTPUT); |
70 | } | 71 | } |
71 | if (strcmp(name, "prev") == 0) { | 72 | if (strcmp(name, "prev") == 0) { |
72 | return workspace_prev(current_workspace); | 73 | return workspace_prev(current_workspace); |
@@ -79,12 +80,13 @@ swayc_t *workspace_by_name(const char *name) { | |||
79 | } else if (strcmp(name, "current") == 0) { | 80 | } else if (strcmp(name, "current") == 0) { |
80 | return current_workspace; | 81 | return current_workspace; |
81 | } else { | 82 | } else { |
82 | return swayc_by_test(&root_container, _workspace_by_name, (void *) name); | 83 | return container_find(&root_container, _workspace_by_name, |
84 | (void *)name); | ||
83 | } | 85 | } |
84 | } | 86 | } |
85 | 87 | ||
86 | swayc_t *workspace_create(const char *name) { | 88 | struct sway_container *workspace_create(const char *name) { |
87 | swayc_t *parent; | 89 | struct sway_container *parent; |
88 | // Search for workspace<->output pair | 90 | // Search for workspace<->output pair |
89 | int i, e = config->workspace_outputs->length; | 91 | int i, e = config->workspace_outputs->length; |
90 | for (i = 0; i < e; ++i) { | 92 | for (i = 0; i < e; ++i) { |
@@ -95,7 +97,7 @@ swayc_t *workspace_create(const char *name) { | |||
95 | for (i = 0; i < e; ++i) { | 97 | for (i = 0; i < e; ++i) { |
96 | parent = root_container.children->items[i]; | 98 | parent = root_container.children->items[i]; |
97 | if (strcmp(parent->name, wso->output) == 0) { | 99 | if (strcmp(parent->name, wso->output) == 0) { |
98 | return new_workspace(parent, name); | 100 | return container_workspace_create(parent, name); |
99 | } | 101 | } |
100 | } | 102 | } |
101 | break; | 103 | break; |
@@ -103,10 +105,11 @@ swayc_t *workspace_create(const char *name) { | |||
103 | } | 105 | } |
104 | // Otherwise create a new one | 106 | // Otherwise create a new one |
105 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 107 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
106 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 108 | struct sway_container *focus = |
109 | sway_seat_get_focus_inactive(seat, &root_container); | ||
107 | parent = focus; | 110 | parent = focus; |
108 | parent = swayc_parent_by_type(parent, C_OUTPUT); | 111 | parent = container_parent(parent, C_OUTPUT); |
109 | return new_workspace(parent, name); | 112 | return container_workspace_create(parent, name); |
110 | } | 113 | } |
111 | 114 | ||
112 | /** | 115 | /** |
@@ -114,17 +117,18 @@ swayc_t *workspace_create(const char *name) { | |||
114 | * the end and beginning. If next is false, the previous workspace is returned, | 117 | * the end and beginning. If next is false, the previous workspace is returned, |
115 | * otherwise the next one is returned. | 118 | * otherwise the next one is returned. |
116 | */ | 119 | */ |
117 | swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { | 120 | struct sway_container *workspace_output_prev_next_impl( |
121 | struct sway_container *output, bool next) { | ||
118 | if (!sway_assert(output->type == C_OUTPUT, | 122 | if (!sway_assert(output->type == C_OUTPUT, |
119 | "Argument must be an output, is %d", output->type)) { | 123 | "Argument must be an output, is %d", output->type)) { |
120 | return NULL; | 124 | return NULL; |
121 | } | 125 | } |
122 | 126 | ||
123 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 127 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
124 | swayc_t *focus = sway_seat_get_focus_inactive(seat, output); | 128 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, output); |
125 | swayc_t *workspace = (focus->type == C_WORKSPACE ? | 129 | struct sway_container *workspace = (focus->type == C_WORKSPACE ? |
126 | focus : | 130 | focus : |
127 | swayc_parent_by_type(focus, C_WORKSPACE)); | 131 | container_parent(focus, C_WORKSPACE)); |
128 | 132 | ||
129 | int i; | 133 | int i; |
130 | for (i = 0; i < output->children->length; i++) { | 134 | for (i = 0; i < output->children->length; i++) { |
@@ -134,7 +138,8 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { | |||
134 | } | 138 | } |
135 | } | 139 | } |
136 | 140 | ||
137 | // Doesn't happen, at worst the for loop returns the previously active workspace | 141 | // Doesn't happen, at worst the for loop returns the previously active |
142 | // workspace | ||
138 | return NULL; | 143 | return NULL; |
139 | } | 144 | } |
140 | 145 | ||
@@ -144,13 +149,14 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { | |||
144 | * next is false, the previous workspace is returned, otherwise the next one is | 149 | * next is false, the previous workspace is returned, otherwise the next one is |
145 | * returned. | 150 | * returned. |
146 | */ | 151 | */ |
147 | swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { | 152 | struct sway_container *workspace_prev_next_impl( |
153 | struct sway_container *workspace, bool next) { | ||
148 | if (!sway_assert(workspace->type == C_WORKSPACE, | 154 | if (!sway_assert(workspace->type == C_WORKSPACE, |
149 | "Argument must be a workspace, is %d", workspace->type)) { | 155 | "Argument must be a workspace, is %d", workspace->type)) { |
150 | return NULL; | 156 | return NULL; |
151 | } | 157 | } |
152 | 158 | ||
153 | swayc_t *current_output = workspace->parent; | 159 | struct sway_container *current_output = workspace->parent; |
154 | int offset = next ? 1 : -1; | 160 | int offset = next ? 1 : -1; |
155 | int start = next ? 0 : 1; | 161 | int start = next ? 0 : 1; |
156 | int end; | 162 | int end; |
@@ -166,54 +172,57 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { | |||
166 | } | 172 | } |
167 | } | 173 | } |
168 | 174 | ||
169 | // Given workspace is the first/last on the output, jump to the previous/next output | 175 | // Given workspace is the first/last on the output, jump to the |
176 | // previous/next output | ||
170 | int num_outputs = root_container.children->length; | 177 | int num_outputs = root_container.children->length; |
171 | for (i = 0; i < num_outputs; i++) { | 178 | for (i = 0; i < num_outputs; i++) { |
172 | if (root_container.children->items[i] == current_output) { | 179 | if (root_container.children->items[i] == current_output) { |
173 | swayc_t *next_output = root_container.children->items[ | 180 | struct sway_container *next_output = root_container.children->items[ |
174 | wrap(i + offset, num_outputs)]; | 181 | wrap(i + offset, num_outputs)]; |
175 | return workspace_output_prev_next_impl(next_output, next); | 182 | return workspace_output_prev_next_impl(next_output, next); |
176 | } | 183 | } |
177 | } | 184 | } |
178 | 185 | ||
179 | // Doesn't happen, at worst the for loop returns the previously active workspace on the active output | 186 | // Doesn't happen, at worst the for loop returns the previously active |
187 | // workspace on the active output | ||
180 | return NULL; | 188 | return NULL; |
181 | } | 189 | } |
182 | 190 | ||
183 | swayc_t *workspace_output_next(swayc_t *current) { | 191 | struct sway_container *workspace_output_next(struct sway_container *current) { |
184 | return workspace_output_prev_next_impl(current, true); | 192 | return workspace_output_prev_next_impl(current, true); |
185 | } | 193 | } |
186 | 194 | ||
187 | swayc_t *workspace_next(swayc_t *current) { | 195 | struct sway_container *workspace_next(struct sway_container *current) { |
188 | return workspace_prev_next_impl(current, true); | 196 | return workspace_prev_next_impl(current, true); |
189 | } | 197 | } |
190 | 198 | ||
191 | swayc_t *workspace_output_prev(swayc_t *current) { | 199 | struct sway_container *workspace_output_prev(struct sway_container *current) { |
192 | return workspace_output_prev_next_impl(current, false); | 200 | return workspace_output_prev_next_impl(current, false); |
193 | } | 201 | } |
194 | 202 | ||
195 | swayc_t *workspace_prev(swayc_t *current) { | 203 | struct sway_container *workspace_prev(struct sway_container *current) { |
196 | return workspace_prev_next_impl(current, false); | 204 | return workspace_prev_next_impl(current, false); |
197 | } | 205 | } |
198 | 206 | ||
199 | bool workspace_switch(swayc_t *workspace) { | 207 | bool workspace_switch(struct sway_container *workspace) { |
200 | if (!workspace) { | 208 | if (!workspace) { |
201 | return false; | 209 | return false; |
202 | } | 210 | } |
203 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 211 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
204 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 212 | struct sway_container *focus = |
213 | sway_seat_get_focus_inactive(seat, &root_container); | ||
205 | if (!seat || !focus) { | 214 | if (!seat || !focus) { |
206 | return false; | 215 | return false; |
207 | } | 216 | } |
208 | swayc_t *active_ws = focus; | 217 | struct sway_container *active_ws = focus; |
209 | if (active_ws->type != C_WORKSPACE) { | 218 | if (active_ws->type != C_WORKSPACE) { |
210 | swayc_parent_by_type(focus, C_WORKSPACE); | 219 | container_parent(focus, C_WORKSPACE); |
211 | } | 220 | } |
212 | 221 | ||
213 | if (config->auto_back_and_forth | 222 | if (config->auto_back_and_forth |
214 | && active_ws == workspace | 223 | && active_ws == workspace |
215 | && prev_workspace_name) { | 224 | && prev_workspace_name) { |
216 | swayc_t *new_ws = workspace_by_name(prev_workspace_name); | 225 | struct sway_container *new_ws = workspace_by_name(prev_workspace_name); |
217 | workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); | 226 | workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); |
218 | } | 227 | } |
219 | 228 | ||
@@ -230,13 +239,14 @@ bool workspace_switch(swayc_t *workspace) { | |||
230 | 239 | ||
231 | // TODO: Deal with sticky containers | 240 | // TODO: Deal with sticky containers |
232 | 241 | ||
233 | wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); | 242 | wlr_log(L_DEBUG, "Switching to workspace %p:%s", |
234 | swayc_t *next = sway_seat_get_focus_inactive(seat, workspace); | 243 | workspace, workspace->name); |
244 | struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace); | ||
235 | if (next == NULL) { | 245 | if (next == NULL) { |
236 | next = workspace; | 246 | next = workspace; |
237 | } | 247 | } |
238 | sway_seat_set_focus(seat, next); | 248 | sway_seat_set_focus(seat, next); |
239 | swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); | 249 | struct sway_container *output = container_parent(workspace, C_OUTPUT); |
240 | arrange_windows(output, -1, -1); | 250 | arrange_windows(output, -1, -1); |
241 | return true; | 251 | return true; |
242 | } | 252 | } |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 93d1219c..2d2b3b69 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -352,7 +352,7 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) { | |||
352 | } | 352 | } |
353 | 353 | ||
354 | // add bar to the output | 354 | // add bar to the output |
355 | struct output *bar_output = new_output(name); | 355 | struct output *bar_output = container_output_create(name); |
356 | bar_output->idx = i; | 356 | bar_output->idx = i; |
357 | list_add(bar->outputs, bar_output); | 357 | list_add(bar->outputs, bar_output); |
358 | } | 358 | } |