diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-29 23:29:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-29 23:29:29 -0400 |
commit | d0c7f66e950689b70196a890b62b82ff3c66e103 (patch) | |
tree | b8b52173a9791e3b13a0316ab9d316a80a6adc20 | |
parent | Merge pull request #1647 from acrisci/refactor-tree (diff) | |
download | sway-d0c7f66e950689b70196a890b62b82ff3c66e103.tar.gz sway-d0c7f66e950689b70196a890b62b82ff3c66e103.tar.zst sway-d0c7f66e950689b70196a890b62b82ff3c66e103.zip |
Revert "Refactor tree"
39 files changed, 588 insertions, 593 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 7fdd0be0..48a8b0ab 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 "tree/layout.h" | 13 | #include "layout.h" |
14 | #include "tree/container.h" | 14 | #include "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 sway_container_layout default_orientation; | 302 | enum swayc_layouts default_orientation; |
303 | enum sway_container_layout default_layout; | 303 | enum swayc_layouts 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 sway_container_border border; | 327 | enum swayc_border_types border; |
328 | enum sway_container_border floating_border; | 328 | enum swayc_border_types 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 | struct sway_container *current_container; | 359 | swayc_t *current_container; |
360 | } handler_context; | 360 | } handler_context; |
361 | }; | 361 | }; |
362 | 362 | ||
@@ -416,8 +416,7 @@ 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, | 419 | void apply_output_config(struct output_config *oc, swayc_t *output); |
420 | struct sway_container *output); | ||
421 | void free_output_config(struct output_config *oc); | 420 | void free_output_config(struct output_config *oc); |
422 | 421 | ||
423 | /** | 422 | /** |
diff --git a/include/sway/container.h b/include/sway/container.h new file mode 100644 index 00000000..f200a1a2 --- /dev/null +++ b/include/sway/container.h | |||
@@ -0,0 +1,169 @@ | |||
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 ec256ddb..9b4b4bef 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 "tree/container.h" | 4 | #include "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(struct sway_container *cont); | 34 | list_t *criteria_for(swayc_t *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(struct sway_container *cont, list_t *criteria); | 40 | bool criteria_any(swayc_t *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 c6c73dba..eab7dc90 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 | struct sway_container *container); | 34 | swayc_t *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 | struct sway_container *container); | 37 | swayc_t *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 496bfd5d..1d55bec7 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 | struct sway_container *container; | 17 | swayc_t *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, struct sway_container *container); | 57 | void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container); |
58 | 58 | ||
59 | struct sway_container *sway_seat_get_focus(struct sway_seat *seat); | 59 | swayc_t *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,11 +67,10 @@ struct sway_container *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 | struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, | 70 | swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container); |
71 | struct sway_container *container); | ||
72 | 71 | ||
73 | struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, | 72 | swayc_t *sway_seat_get_focus_by_type(struct sway_seat *seat, |
74 | enum sway_container_type type); | 73 | enum swayc_types type); |
75 | 74 | ||
76 | void sway_seat_set_config(struct sway_seat *seat, struct seat_config *seat_config); | 75 | void sway_seat_set_config(struct sway_seat *seat, struct seat_config *seat_config); |
77 | 76 | ||
diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h index 3d2fdc4f..eef5a018 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/tree/container.h" | 4 | #include "sway/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(struct sway_container *c); | 9 | json_object *ipc_json_describe_container(swayc_t *c); |
10 | json_object *ipc_json_describe_container_recursive(struct sway_container *c); | 10 | json_object *ipc_json_describe_container_recursive(swayc_t *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 d73006dc..bcf1c433 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h | |||
@@ -1,17 +1,15 @@ | |||
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/tree/container.h" | 4 | #include "sway/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 | |||
11 | void ipc_terminate(void); | 10 | void ipc_terminate(void); |
12 | |||
13 | struct sockaddr_un *ipc_user_sockaddr(void); | 11 | struct sockaddr_un *ipc_user_sockaddr(void); |
14 | 12 | ||
15 | void ipc_event_window(struct sway_container *window, const char *change); | 13 | void ipc_event_window(swayc_t *window, const char *change); |
16 | 14 | ||
17 | #endif | 15 | #endif |
diff --git a/include/sway/layout.h b/include/sway/layout.h new file mode 100644 index 00000000..e82c4442 --- /dev/null +++ b/include/sway/layout.h | |||
@@ -0,0 +1,43 @@ | |||
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 deleted file mode 100644 index 16df3ee7..00000000 --- a/include/sway/tree/container.h +++ /dev/null | |||
@@ -1,137 +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 | 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 deleted file mode 100644 index ad52bdb0..00000000 --- a/include/sway/tree/layout.h +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
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/tree/workspace.h b/include/sway/tree/workspace.h deleted file mode 100644 index d73b29c1..00000000 --- a/include/sway/tree/workspace.h +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
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/tree/view.h b/include/sway/view.h index e5f53f4e..b2886211 100644 --- a/include/sway/tree/view.h +++ b/include/sway/view.h | |||
@@ -62,6 +62,10 @@ 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 | */ | ||
65 | struct sway_view { | 69 | struct sway_view { |
66 | enum sway_view_type type; | 70 | enum sway_view_type type; |
67 | struct sway_container *swayc; | 71 | struct sway_container *swayc; |
diff --git a/include/sway/workspace.h b/include/sway/workspace.h new file mode 100644 index 00000000..fee54255 --- /dev/null +++ b/include/sway/workspace.h | |||
@@ -0,0 +1,20 @@ | |||
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 954950e7..61870c51 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/tree/container.h" | 9 | #include "sway/container.h" |
10 | #include "sway/tree/workspace.h" | 10 | #include "sway/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 64f079f4..f1a8078f 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -3,11 +3,10 @@ | |||
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/tree/view.h" | 6 | #include "sway/view.h" |
7 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
8 | 8 | ||
9 | static bool parse_movement_direction(const char *name, | 9 | static bool parse_movement_direction(const char *name, enum movement_direction *out) { |
10 | enum movement_direction *out) { | ||
11 | if (strcasecmp(name, "left") == 0) { | 10 | if (strcasecmp(name, "left") == 0) { |
12 | *out = MOVE_LEFT; | 11 | *out = MOVE_LEFT; |
13 | } else if (strcasecmp(name, "right") == 0) { | 12 | } else if (strcasecmp(name, "right") == 0) { |
@@ -32,7 +31,7 @@ static bool parse_movement_direction(const char *name, | |||
32 | } | 31 | } |
33 | 32 | ||
34 | struct cmd_results *cmd_focus(int argc, char **argv) { | 33 | struct cmd_results *cmd_focus(int argc, char **argv) { |
35 | struct sway_container *con = config->handler_context.current_container; | 34 | swayc_t *con = config->handler_context.current_container; |
36 | struct sway_seat *seat = config->handler_context.seat; | 35 | struct sway_seat *seat = config->handler_context.seat; |
37 | if (con->type < C_WORKSPACE) { | 36 | if (con->type < C_WORKSPACE) { |
38 | return cmd_results_new(CMD_FAILURE, "focus", | 37 | return cmd_results_new(CMD_FAILURE, "focus", |
@@ -51,7 +50,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { | |||
51 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); | 50 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); |
52 | } | 51 | } |
53 | 52 | ||
54 | struct sway_container *next_focus = container_get_in_direction(con, seat, direction); | 53 | swayc_t *next_focus = get_swayc_in_direction(con, seat, direction); |
55 | if (next_focus) { | 54 | if (next_focus) { |
56 | sway_seat_set_focus(seat, next_focus); | 55 | sway_seat_set_focus(seat, next_focus); |
57 | } | 56 | } |
diff --git a/sway/commands/kill.c b/sway/commands/kill.c index f6774767..f408ce2a 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/tree/view.h" | 5 | #include "sway/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 sway_container_type type = config->handler_context.current_container->type; | 9 | enum swayc_types 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 ebab2a48..b0fc5d66 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/tree/container.h" | 4 | #include "sway/container.h" |
5 | #include "sway/tree/layout.h" | 5 | #include "sway/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 | struct sway_container *parent = config->handler_context.current_container; | 13 | swayc_t *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 | container_set_layout(parent, parent->prev_layout); | 29 | swayc_change_layout(parent, parent->prev_layout); |
30 | if (parent->layout == L_NONE) { | 30 | if (parent->layout == L_NONE) { |
31 | struct sway_container *output = container_parent(parent, C_OUTPUT); | 31 | swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); |
32 | container_set_layout(parent, container_get_default_layout(output)); | 32 | swayc_change_layout(parent, 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 | container_set_layout(parent, L_HORIZ); | 40 | swayc_change_layout(parent, L_HORIZ); |
41 | } else if (strcasecmp(argv[0], "splitv") == 0) { | 41 | } else if (strcasecmp(argv[0], "splitv") == 0) { |
42 | container_set_layout(parent, L_VERT); | 42 | swayc_change_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 | container_set_layout(parent, L_VERT); | 46 | swayc_change_layout(parent, L_VERT); |
47 | } else { | 47 | } else { |
48 | container_set_layout(parent, L_HORIZ); | 48 | swayc_change_layout(parent, L_HORIZ); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | } | 51 | } |
diff --git a/sway/commands/output.c b/sway/commands/output.c index f7e3372c..35bc8099 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 | struct sway_container *cont = root_container.children->items[i]; | 299 | swayc_t *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 8cef789b..d54d40db 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/tree/layout.h" | 3 | #include "sway/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 8f39e5fc..fa891398 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/tree/workspace.h" | 7 | #include "sway/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 | struct sway_container *current_container = config->handler_context.current_container; | 20 | swayc_t *current_container = config->handler_context.current_container; |
21 | struct sway_container *old_workspace = NULL, *old_output = NULL; | 21 | swayc_t *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 = container_parent(current_container, C_WORKSPACE); | 26 | old_workspace = swayc_parent_by_type(current_container, C_WORKSPACE); |
27 | } | 27 | } |
28 | old_output = container_parent(current_container, C_OUTPUT); | 28 | old_output = swayc_parent_by_type(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 | struct sway_container *ws = NULL; | 60 | swayc_t *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 | struct sway_container *new_output = container_parent(current_container, C_OUTPUT); | 95 | swayc_t *new_output = swayc_parent_by_type(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 0b29735a..213e7680 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/tree/layout.h" | 27 | #include "sway/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 7fc79739..9e211861 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, struct sway_container *output) { | 123 | void apply_output_config(struct output_config *oc, swayc_t *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 | container_output_destroy(output); | 130 | destroy_output(output); |
131 | return; | 131 | return; |
132 | } | 132 | } |
133 | 133 | ||
diff --git a/sway/criteria.c b/sway/criteria.c index 247f6b75..2eee331c 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/tree/container.h" | 7 | #include "sway/container.h" |
8 | #include "sway/config.h" | 8 | #include "sway/config.h" |
9 | #include "sway/tree/view.h" | 9 | #include "sway/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(struct sway_container *cont, list_t *tokens) { | 275 | static bool criteria_test(swayc_t *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(struct sway_container *cont, list_t *criteria) { | 401 | bool criteria_any(swayc_t *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(struct sway_container *cont, list_t *criteria) { | |||
408 | return false; | 408 | return false; |
409 | } | 409 | } |
410 | 410 | ||
411 | list_t *criteria_for(struct sway_container *cont) { | 411 | list_t *criteria_for(swayc_t *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(struct sway_container *container, | 427 | static void container_match_add(swayc_t *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_for_each_descendent(&root_container, | 438 | container_map(&root_container, |
439 | (void (*)(struct sway_container *, void *))container_match_add, | 439 | (void (*)(swayc_t *, 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 137b3260..bd62f84a 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/tree/layout.h" | 10 | #include "sway/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 ba778f4c..b8253ace 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/tree/container.h" | 14 | #include "sway/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/tree/layout.h" | 18 | #include "sway/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/tree/view.h" | 21 | #include "sway/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(struct sway_container *view, void *data) { | 148 | static void output_frame_view(swayc_t *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 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); | 222 | swayc_t *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); |
223 | struct sway_container *workspace = (focus->type == C_WORKSPACE ? | 223 | swayc_t *workspace = (focus->type == C_WORKSPACE ? |
224 | focus : | 224 | focus : |
225 | container_parent(focus, C_WORKSPACE)); | 225 | swayc_parent_by_type(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 | container_descendents(workspace, C_VIEW, output_frame_view, &rdata); | 231 | swayc_descendants_of_type(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 | container_output_destroy(output->swayc); | 262 | destroy_output(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 = container_output_create(output); | 290 | output->swayc = new_output(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 4d4d1ed7..0356aa81 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/tree/container.h" | 6 | #include "sway/container.h" |
7 | #include "sway/tree/layout.h" | 7 | #include "sway/layout.h" |
8 | #include "sway/server.h" | 8 | #include "sway/server.h" |
9 | #include "sway/tree/view.h" | 9 | #include "sway/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 | struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); | 77 | swayc_t *parent = destroy_view(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 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); | 135 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); |
136 | struct sway_container *cont = container_view_create(focus, sway_view); | 136 | swayc_t *cont = new_view(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 25c0cbca..18e7d399 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/tree/container.h" | 6 | #include "sway/container.h" |
7 | #include "sway/tree/layout.h" | 7 | #include "sway/layout.h" |
8 | #include "sway/server.h" | 8 | #include "sway/server.h" |
9 | #include "sway/tree/view.h" | 9 | #include "sway/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 | struct sway_container *parent = container_view_destroy(sway_xdg_surface->view->swayc); | 86 | swayc_t *parent = destroy_view(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 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); | 140 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); |
141 | struct sway_container *cont = container_view_create(focus, sway_view); | 141 | swayc_t *cont = new_view(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 fd0bcaca..f9b5242b 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/tree/container.h" | 8 | #include "sway/container.h" |
9 | #include "sway/tree/layout.h" | 9 | #include "sway/layout.h" |
10 | #include "sway/server.h" | 10 | #include "sway/server.h" |
11 | #include "sway/tree/view.h" | 11 | #include "sway/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 | struct sway_container *output = container_parent(view->swayc, C_OUTPUT); | 52 | swayc_t *output = swayc_parent_by_type(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 | struct sway_container *root = container_parent(output, C_ROOT); | 56 | swayc_t *root = swayc_parent_by_type(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 | struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); | 117 | swayc_t *parent = destroy_view(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 | struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); | 135 | swayc_t *parent = destroy_view(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 | container_view_destroy(view->swayc); | 158 | destroy_view(view->swayc); |
159 | 159 | ||
160 | struct sway_container *parent = root_container.children->items[0]; | 160 | swayc_t *parent = root_container.children->items[0]; |
161 | parent = parent->children->items[0]; // workspace | 161 | parent = parent->children->items[0]; // workspace |
162 | 162 | ||
163 | struct sway_container *cont = container_view_create(parent, view); | 163 | swayc_t *cont = new_view(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 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); | 241 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); |
242 | struct sway_container *cont = container_view_create(focus, sway_view); | 242 | swayc_t *cont = new_view(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 d57ac3e3..8a0d1df5 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/tree/view.h" | 10 | #include "sway/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 | struct sway_container *swayc = | 52 | swayc_t *swayc = |
53 | container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); | 53 | swayc_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 | struct sway_container *swayc = | 90 | swayc_t *swayc = |
91 | container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); | 91 | swayc_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 d421a03f..27c2c72e 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 | struct sway_container *container) { | 281 | swayc_t *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 | struct sway_container *container) { | 293 | swayc_t *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 76d29b52..648e7914 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/tree/container.h" | 4 | #include "sway/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/tree/view.h" | 10 | #include "sway/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 | struct sway_container *con = seat_con->container; | 40 | swayc_t *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 | struct sway_container *next = sway_seat_get_focus_inactive(seat, con->parent); | 49 | swayc_t *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, struct sway_container *con) { | 62 | struct sway_seat *seat, swayc_t *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 | struct sway_container *con = data; | 92 | swayc_t *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(struct sway_container *con, void *data) { | 96 | static void collect_focus_iter(swayc_t *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_descendent(&root_container, collect_focus_iter, seat); | 133 | container_for_each_bfs(&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 | struct sway_container *focus = sway_seat_get_focus(seat); | 169 | swayc_t *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 | struct sway_container *output_container = root_container.children->items[i]; | 273 | swayc_t *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, struct sway_container *container) { | 292 | void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { |
293 | struct sway_container *last_focus = sway_seat_get_focus(seat); | 293 | swayc_t *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, struct sway_container *containe | |||
330 | seat->has_focus = (container != NULL); | 330 | seat->has_focus = (container != NULL); |
331 | } | 331 | } |
332 | 332 | ||
333 | struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) { | 333 | swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container) { |
334 | struct sway_seat_container *current = NULL; | 334 | struct sway_seat_container *current = NULL; |
335 | struct sway_container *parent = NULL; | 335 | swayc_t *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 @@ struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, stru | |||
351 | return NULL; | 351 | return NULL; |
352 | } | 352 | } |
353 | 353 | ||
354 | struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { | 354 | swayc_t *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 | struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, | 361 | swayc_t *sway_seat_get_focus_by_type(struct sway_seat *seat, |
362 | enum sway_container_type type) { | 362 | enum swayc_types type) { |
363 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); | 363 | swayc_t *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 container_parent(focus, type); | 368 | return swayc_parent_by_type(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 7caa2457..977f1ecb 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/tree/container.h" | 6 | #include "sway/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(struct sway_container *c) { | 28 | static json_object *ipc_json_create_rect(swayc_t *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(struct sway_container *c) { | |||
36 | return rect; | 36 | return rect; |
37 | } | 37 | } |
38 | 38 | ||
39 | static void ipc_json_describe_root(struct sway_container *root, json_object *object) { | 39 | static void ipc_json_describe_root(swayc_t *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(struct sway_container *container, json_object *object) { | 66 | static void ipc_json_describe_output(swayc_t *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(struct sway_container *container, json_obje | |||
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(struct sway_container *workspace, json_object *object) { | 97 | static void ipc_json_describe_workspace(swayc_t *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(struct sway_container *workspace, json_o | |||
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(struct sway_container *c, json_object *object) { | 105 | static void ipc_json_describe_view(swayc_t *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(struct sway_container *c) { | 109 | json_object *ipc_json_describe_container(swayc_t *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(struct sway_container *c) { | |||
147 | return object; | 147 | return object; |
148 | } | 148 | } |
149 | 149 | ||
150 | json_object *ipc_json_describe_container_recursive(struct sway_container *c) { | 150 | json_object *ipc_json_describe_container_recursive(swayc_t *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 50d0bcf3..156de380 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(struct sway_container *window, const char *change) { | 282 | void ipc_event_window(swayc_t *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 | struct sway_container *container = root_container.children->items[i]; | 403 | swayc_t *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 ded922ee..f2f24be3 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/tree/layout.h" | 21 | #include "sway/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 | layout_init(); | 385 | init_layout(); |
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 40047dcf..bbafe9ec 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/tree/container.h" | 10 | #include "sway/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/tree/layout.h" | 13 | #include "sway/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/tree/view.h" | 16 | #include "sway/view.h" |
17 | #include "sway/tree/workspace.h" | 17 | #include "sway/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,15 +33,48 @@ static list_t *get_bfs_queue() { | |||
33 | return bfs_queue; | 33 | return bfs_queue; |
34 | } | 34 | } |
35 | 35 | ||
36 | static void notify_new_container(struct sway_container *container) { | 36 | static void notify_new_container(swayc_t *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 | static struct sway_container *container_create(enum sway_container_type type) { | 41 | swayc_t *swayc_by_test(swayc_t *container, |
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) { | ||
42 | // next id starts at 1 because 0 is assigned to root_container in layout.c | 75 | // next id starts at 1 because 0 is assigned to root_container in layout.c |
43 | static size_t next_id = 1; | 76 | static size_t next_id = 1; |
44 | struct sway_container *c = calloc(1, sizeof(struct sway_container)); | 77 | swayc_t *c = calloc(1, sizeof(swayc_t)); |
45 | if (!c) { | 78 | if (!c) { |
46 | return NULL; | 79 | return NULL; |
47 | } | 80 | } |
@@ -49,6 +82,8 @@ static struct sway_container *container_create(enum sway_container_type type) { | |||
49 | c->layout = L_NONE; | 82 | c->layout = L_NONE; |
50 | c->workspace_layout = L_NONE; | 83 | c->workspace_layout = L_NONE; |
51 | c->type = type; | 84 | c->type = type; |
85 | c->nb_master = 1; | ||
86 | c->nb_slave_groups = 1; | ||
52 | if (type != C_VIEW) { | 87 | if (type != C_VIEW) { |
53 | c->children = create_list(); | 88 | c->children = create_list(); |
54 | } | 89 | } |
@@ -58,18 +93,18 @@ static struct sway_container *container_create(enum sway_container_type type) { | |||
58 | return c; | 93 | return c; |
59 | } | 94 | } |
60 | 95 | ||
61 | static void container_destroy(struct sway_container *cont) { | 96 | static void free_swayc(swayc_t *cont) { |
62 | if (cont == NULL) { | 97 | if (!sway_assert(cont, "free_swayc passed NULL")) { |
63 | return; | 98 | return; |
64 | } | 99 | } |
65 | 100 | ||
66 | wl_signal_emit(&cont->events.destroy, cont); | 101 | wl_signal_emit(&cont->events.destroy, cont); |
67 | 102 | ||
68 | if (cont->children) { | 103 | if (cont->children) { |
69 | // remove children until there are no more, container_destroy calls | 104 | // remove children until there are no more, free_swayc calls |
70 | // container_remove_child, which removes child from this container | 105 | // remove_child, which removes child from this container |
71 | while (cont->children->length) { | 106 | while (cont->children->length) { |
72 | container_destroy(cont->children->items[0]); | 107 | free_swayc(cont->children->items[0]); |
73 | } | 108 | } |
74 | list_free(cont->children); | 109 | list_free(cont->children); |
75 | } | 110 | } |
@@ -78,7 +113,7 @@ static void container_destroy(struct sway_container *cont) { | |||
78 | list_free(cont->marks); | 113 | list_free(cont->marks); |
79 | } | 114 | } |
80 | if (cont->parent) { | 115 | if (cont->parent) { |
81 | container_remove_child(cont); | 116 | remove_child(cont); |
82 | } | 117 | } |
83 | if (cont->name) { | 118 | if (cont->name) { |
84 | free(cont->name); | 119 | free(cont->name); |
@@ -86,8 +121,7 @@ static void container_destroy(struct sway_container *cont) { | |||
86 | free(cont); | 121 | free(cont); |
87 | } | 122 | } |
88 | 123 | ||
89 | struct sway_container *container_output_create( | 124 | swayc_t *new_output(struct sway_output *sway_output) { |
90 | struct sway_output *sway_output) { | ||
91 | struct wlr_box size; | 125 | struct wlr_box size; |
92 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, | 126 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, |
93 | &size.height); | 127 | &size.height); |
@@ -122,22 +156,22 @@ struct sway_container *container_output_create( | |||
122 | return NULL; | 156 | return NULL; |
123 | } | 157 | } |
124 | 158 | ||
125 | struct sway_container *output = container_create(C_OUTPUT); | 159 | swayc_t *output = new_swayc(C_OUTPUT); |
126 | output->sway_output = sway_output; | 160 | output->sway_output = sway_output; |
127 | output->name = strdup(name); | 161 | output->name = strdup(name); |
128 | if (output->name == NULL) { | 162 | if (output->name == NULL) { |
129 | container_destroy(output); | 163 | free_swayc(output); |
130 | return NULL; | 164 | return NULL; |
131 | } | 165 | } |
132 | 166 | ||
133 | apply_output_config(oc, output); | 167 | apply_output_config(oc, output); |
134 | 168 | ||
135 | container_add_child(&root_container, output); | 169 | add_child(&root_container, output); |
136 | 170 | ||
137 | // Create workspace | 171 | // Create workspace |
138 | char *ws_name = workspace_next_name(output->name); | 172 | char *ws_name = workspace_next_name(output->name); |
139 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); | 173 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); |
140 | struct sway_container *ws = container_workspace_create(output, ws_name); | 174 | swayc_t *ws = new_workspace(output, ws_name); |
141 | // Set each seat's focus if not already set | 175 | // Set each seat's focus if not already set |
142 | struct sway_seat *seat = NULL; | 176 | struct sway_seat *seat = NULL; |
143 | wl_list_for_each(seat, &input_manager->seats, link) { | 177 | wl_list_for_each(seat, &input_manager->seats, link) { |
@@ -151,14 +185,12 @@ struct sway_container *container_output_create( | |||
151 | return output; | 185 | return output; |
152 | } | 186 | } |
153 | 187 | ||
154 | struct sway_container *container_workspace_create( | 188 | swayc_t *new_workspace(swayc_t *output, const char *name) { |
155 | struct sway_container *output, const char *name) { | 189 | if (!sway_assert(output, "new_workspace called with null output")) { |
156 | if (!sway_assert(output, | ||
157 | "container_workspace_create called with null output")) { | ||
158 | return NULL; | 190 | return NULL; |
159 | } | 191 | } |
160 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); | 192 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); |
161 | struct sway_container *workspace = container_create(C_WORKSPACE); | 193 | swayc_t *workspace = new_swayc(C_WORKSPACE); |
162 | 194 | ||
163 | workspace->x = output->x; | 195 | workspace->x = output->x; |
164 | workspace->y = output->y; | 196 | workspace->y = output->y; |
@@ -166,23 +198,21 @@ struct sway_container *container_workspace_create( | |||
166 | workspace->height = output->height; | 198 | workspace->height = output->height; |
167 | workspace->name = !name ? NULL : strdup(name); | 199 | workspace->name = !name ? NULL : strdup(name); |
168 | workspace->prev_layout = L_NONE; | 200 | workspace->prev_layout = L_NONE; |
169 | workspace->layout = container_get_default_layout(output); | 201 | workspace->layout = default_layout(output); |
170 | workspace->workspace_layout = container_get_default_layout(output); | 202 | workspace->workspace_layout = default_layout(output); |
171 | 203 | ||
172 | container_add_child(output, workspace); | 204 | add_child(output, workspace); |
173 | container_sort_workspaces(output); | 205 | sort_workspaces(output); |
174 | notify_new_container(workspace); | 206 | notify_new_container(workspace); |
175 | return workspace; | 207 | return workspace; |
176 | } | 208 | } |
177 | 209 | ||
178 | struct sway_container *container_view_create(struct sway_container *sibling, | 210 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { |
179 | struct sway_view *sway_view) { | 211 | if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { |
180 | if (!sway_assert(sibling, | ||
181 | "container_view_create called with NULL sibling/parent")) { | ||
182 | return NULL; | 212 | return NULL; |
183 | } | 213 | } |
184 | const char *title = view_get_title(sway_view); | 214 | const char *title = view_get_title(sway_view); |
185 | struct sway_container *swayc = container_create(C_VIEW); | 215 | swayc_t *swayc = new_swayc(C_VIEW); |
186 | wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", | 216 | wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", |
187 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); | 217 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); |
188 | // Setup values | 218 | // Setup values |
@@ -193,18 +223,17 @@ struct sway_container *container_view_create(struct sway_container *sibling, | |||
193 | 223 | ||
194 | if (sibling->type == C_WORKSPACE) { | 224 | if (sibling->type == C_WORKSPACE) { |
195 | // Case of focused workspace, just create as child of it | 225 | // Case of focused workspace, just create as child of it |
196 | container_add_child(sibling, swayc); | 226 | add_child(sibling, swayc); |
197 | } else { | 227 | } else { |
198 | // Regular case, create as sibling of current container | 228 | // Regular case, create as sibling of current container |
199 | container_add_sibling(sibling, swayc); | 229 | add_sibling(sibling, swayc); |
200 | } | 230 | } |
201 | notify_new_container(swayc); | 231 | notify_new_container(swayc); |
202 | return swayc; | 232 | return swayc; |
203 | } | 233 | } |
204 | 234 | ||
205 | struct sway_container *container_output_destroy(struct sway_container *output) { | 235 | swayc_t *destroy_output(swayc_t *output) { |
206 | if (!sway_assert(output, | 236 | if (!sway_assert(output, "null output passed to destroy_output")) { |
207 | "null output passed to container_output_destroy")) { | ||
208 | return NULL; | 237 | return NULL; |
209 | } | 238 | } |
210 | 239 | ||
@@ -216,13 +245,12 @@ struct sway_container *container_output_destroy(struct sway_container *output) { | |||
216 | int p = root_container.children->items[0] == output; | 245 | int p = root_container.children->items[0] == output; |
217 | // Move workspace from this output to another output | 246 | // Move workspace from this output to another output |
218 | while (output->children->length) { | 247 | while (output->children->length) { |
219 | struct sway_container *child = output->children->items[0]; | 248 | swayc_t *child = output->children->items[0]; |
220 | container_remove_child(child); | 249 | remove_child(child); |
221 | container_add_child(root_container.children->items[p], child); | 250 | add_child(root_container.children->items[p], child); |
222 | } | 251 | } |
223 | container_sort_workspaces(root_container.children->items[p]); | 252 | sort_workspaces(root_container.children->items[p]); |
224 | arrange_windows(root_container.children->items[p], | 253 | arrange_windows(root_container.children->items[p], -1, -1); |
225 | -1, -1); | ||
226 | } | 254 | } |
227 | } | 255 | } |
228 | 256 | ||
@@ -231,18 +259,18 @@ struct sway_container *container_output_destroy(struct sway_container *output) { | |||
231 | wl_list_remove(&output->sway_output->mode.link); | 259 | wl_list_remove(&output->sway_output->mode.link); |
232 | 260 | ||
233 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | 261 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); |
234 | container_destroy(output); | 262 | free_swayc(output); |
235 | 263 | ||
236 | return &root_container; | 264 | return &root_container; |
237 | } | 265 | } |
238 | 266 | ||
239 | struct sway_container *container_view_destroy(struct sway_container *view) { | 267 | swayc_t *destroy_view(swayc_t *view) { |
240 | if (!view) { | 268 | if (!view) { |
241 | return NULL; | 269 | return NULL; |
242 | } | 270 | } |
243 | wlr_log(L_DEBUG, "Destroying view '%s'", view->name); | 271 | wlr_log(L_DEBUG, "Destroying view '%s'", view->name); |
244 | struct sway_container *parent = view->parent; | 272 | swayc_t *parent = view->parent; |
245 | container_destroy(view); | 273 | free_swayc(view); |
246 | 274 | ||
247 | // TODO WLR: Destroy empty containers | 275 | // TODO WLR: Destroy empty containers |
248 | /* | 276 | /* |
@@ -253,55 +281,7 @@ struct sway_container *container_view_destroy(struct sway_container *view) { | |||
253 | return parent; | 281 | return parent; |
254 | } | 282 | } |
255 | 283 | ||
256 | struct sway_container *container_set_layout(struct sway_container *container, | 284 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { |
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) { | ||
305 | if (!sway_assert(container, "container is NULL")) { | 285 | if (!sway_assert(container, "container is NULL")) { |
306 | return NULL; | 286 | return NULL; |
307 | } | 287 | } |
@@ -314,8 +294,7 @@ struct sway_container *container_parent(struct sway_container *container, | |||
314 | return container; | 294 | return container; |
315 | } | 295 | } |
316 | 296 | ||
317 | struct sway_container *container_at(struct sway_container *parent, | 297 | swayc_t *swayc_at(swayc_t *parent, double lx, double ly, |
318 | double lx, double ly, | ||
319 | struct wlr_surface **surface, double *sx, double *sy) { | 298 | struct wlr_surface **surface, double *sx, double *sy) { |
320 | list_t *queue = get_bfs_queue(); | 299 | list_t *queue = get_bfs_queue(); |
321 | if (!queue) { | 300 | if (!queue) { |
@@ -324,13 +303,13 @@ struct sway_container *container_at(struct sway_container *parent, | |||
324 | 303 | ||
325 | list_add(queue, parent); | 304 | list_add(queue, parent); |
326 | 305 | ||
327 | struct sway_container *swayc = NULL; | 306 | swayc_t *swayc = NULL; |
328 | while (queue->length) { | 307 | while (queue->length) { |
329 | swayc = queue->items[0]; | 308 | swayc = queue->items[0]; |
330 | list_del(queue, 0); | 309 | list_del(queue, 0); |
331 | if (swayc->type == C_VIEW) { | 310 | if (swayc->type == C_VIEW) { |
332 | struct sway_view *sview = swayc->sway_view; | 311 | struct sway_view *sview = swayc->sway_view; |
333 | struct sway_container *soutput = container_parent(swayc, C_OUTPUT); | 312 | swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); |
334 | struct wlr_box *output_box = | 313 | struct wlr_box *output_box = |
335 | wlr_output_layout_get_box( | 314 | wlr_output_layout_get_box( |
336 | root_container.sway_root->output_layout, | 315 | root_container.sway_root->output_layout, |
@@ -400,8 +379,30 @@ struct sway_container *container_at(struct sway_container *parent, | |||
400 | return NULL; | 379 | return NULL; |
401 | } | 380 | } |
402 | 381 | ||
403 | void container_for_each_descendent(struct sway_container *con, | 382 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { |
404 | void (*f)(struct sway_container *con, void *data), void *data) { | 383 | if (container) { |
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) { | ||
405 | list_t *queue = get_bfs_queue(); | 406 | list_t *queue = get_bfs_queue(); |
406 | if (!queue) { | 407 | if (!queue) { |
407 | return; | 408 | return; |
@@ -414,7 +415,7 @@ void container_for_each_descendent(struct sway_container *con, | |||
414 | 415 | ||
415 | list_add(queue, con); | 416 | list_add(queue, con); |
416 | 417 | ||
417 | struct sway_container *current = NULL; | 418 | swayc_t *current = NULL; |
418 | while (queue->length) { | 419 | while (queue->length) { |
419 | current = queue->items[0]; | 420 | current = queue->items[0]; |
420 | list_del(queue, 0); | 421 | list_del(queue, 0); |
@@ -423,3 +424,15 @@ void container_for_each_descendent(struct sway_container *con, | |||
423 | list_cat(queue, current->children); | 424 | list_cat(queue, current->children); |
424 | } | 425 | } |
425 | } | 426 | } |
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 dc0ee5b4..de9e7b58 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -6,26 +6,24 @@ | |||
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/tree/container.h" | 9 | #include "sway/container.h" |
10 | #include "sway/tree/layout.h" | 10 | #include "sway/layout.h" |
11 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/tree/view.h" | 12 | #include "sway/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 | struct sway_container root_container; | 17 | swayc_t root_container; |
18 | 18 | ||
19 | static void output_layout_change_notify(struct wl_listener *listener, | 19 | static void output_layout_change_notify(struct wl_listener *listener, void *data) { |
20 | void *data) { | ||
21 | struct wlr_box *layout_box = wlr_output_layout_get_box( | 20 | struct wlr_box *layout_box = wlr_output_layout_get_box( |
22 | root_container.sway_root->output_layout, NULL); | 21 | root_container.sway_root->output_layout, NULL); |
23 | root_container.width = layout_box->width; | 22 | root_container.width = layout_box->width; |
24 | root_container.height = layout_box->height; | 23 | root_container.height = layout_box->height; |
25 | 24 | ||
26 | for (int i = 0 ; i < root_container.children->length; ++i) { | 25 | for (int i = 0 ; i < root_container.children->length; ++i) { |
27 | struct sway_container *output_container = | 26 | swayc_t *output_container = root_container.children->items[i]; |
28 | root_container.children->items[i]; | ||
29 | if (output_container->type != C_OUTPUT) { | 27 | if (output_container->type != C_OUTPUT) { |
30 | continue; | 28 | continue; |
31 | } | 29 | } |
@@ -45,7 +43,7 @@ static void output_layout_change_notify(struct wl_listener *listener, | |||
45 | arrange_windows(&root_container, -1, -1); | 43 | arrange_windows(&root_container, -1, -1); |
46 | } | 44 | } |
47 | 45 | ||
48 | void layout_init(void) { | 46 | void init_layout(void) { |
49 | root_container.id = 0; // normally assigned in new_swayc() | 47 | root_container.id = 0; // normally assigned in new_swayc() |
50 | root_container.type = C_ROOT; | 48 | root_container.type = C_ROOT; |
51 | root_container.layout = L_NONE; | 49 | root_container.layout = L_NONE; |
@@ -64,9 +62,9 @@ void layout_init(void) { | |||
64 | &root_container.sway_root->output_layout_change); | 62 | &root_container.sway_root->output_layout_change); |
65 | } | 63 | } |
66 | 64 | ||
67 | static int index_child(const struct sway_container *child) { | 65 | static int index_child(const swayc_t *child) { |
68 | // TODO handle floating | 66 | // TODO handle floating |
69 | struct sway_container *parent = child->parent; | 67 | swayc_t *parent = child->parent; |
70 | int i, len; | 68 | int i, len; |
71 | len = parent->children->length; | 69 | len = parent->children->length; |
72 | for (i = 0; i < len; ++i) { | 70 | for (i = 0; i < len; ++i) { |
@@ -81,18 +79,16 @@ static int index_child(const struct sway_container *child) { | |||
81 | return i; | 79 | return i; |
82 | } | 80 | } |
83 | 81 | ||
84 | struct sway_container *container_add_sibling(struct sway_container *fixed, | 82 | swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { |
85 | struct sway_container *active) { | ||
86 | // TODO handle floating | 83 | // TODO handle floating |
87 | struct sway_container *parent = fixed->parent; | 84 | swayc_t *parent = fixed->parent; |
88 | int i = index_child(fixed); | 85 | int i = index_child(fixed); |
89 | list_insert(parent->children, i + 1, active); | 86 | list_insert(parent->children, i + 1, active); |
90 | active->parent = parent; | 87 | active->parent = parent; |
91 | return active->parent; | 88 | return active->parent; |
92 | } | 89 | } |
93 | 90 | ||
94 | void container_add_child(struct sway_container *parent, | 91 | void add_child(swayc_t *parent, swayc_t *child) { |
95 | struct sway_container *child) { | ||
96 | wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", | 92 | wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", |
97 | child, child->type, child->width, child->height, | 93 | child, child->type, child->width, child->height, |
98 | parent, parent->type, parent->width, parent->height); | 94 | parent, parent->type, parent->width, parent->height); |
@@ -100,17 +96,15 @@ void container_add_child(struct sway_container *parent, | |||
100 | child->parent = parent; | 96 | child->parent = parent; |
101 | // set focus for this container | 97 | // set focus for this container |
102 | /* TODO WLR | 98 | /* TODO WLR |
103 | if (parent->type == C_WORKSPACE && child->type == C_VIEW && | 99 | if (parent->type == C_WORKSPACE && child->type == C_VIEW && (parent->workspace_layout == L_TABBED || parent->workspace_layout == L_STACKED)) { |
104 | (parent->workspace_layout == L_TABBED || parent->workspace_layout == | ||
105 | L_STACKED)) { | ||
106 | child = new_container(child, parent->workspace_layout); | 100 | child = new_container(child, parent->workspace_layout); |
107 | } | 101 | } |
108 | */ | 102 | */ |
109 | } | 103 | } |
110 | 104 | ||
111 | struct sway_container *container_remove_child(struct sway_container *child) { | 105 | swayc_t *remove_child(swayc_t *child) { |
112 | int i; | 106 | int i; |
113 | struct sway_container *parent = child->parent; | 107 | swayc_t *parent = child->parent; |
114 | for (i = 0; i < parent->children->length; ++i) { | 108 | for (i = 0; i < parent->children->length; ++i) { |
115 | if (parent->children->items[i] == child) { | 109 | if (parent->children->items[i] == child) { |
116 | list_del(parent->children, i); | 110 | list_del(parent->children, i); |
@@ -121,8 +115,7 @@ struct sway_container *container_remove_child(struct sway_container *child) { | |||
121 | return parent; | 115 | return parent; |
122 | } | 116 | } |
123 | 117 | ||
124 | enum sway_container_layout container_get_default_layout( | 118 | enum swayc_layouts default_layout(swayc_t *output) { |
125 | struct sway_container *output) { | ||
126 | /* TODO WLR | 119 | /* TODO WLR |
127 | if (config->default_layout != L_NONE) { | 120 | if (config->default_layout != L_NONE) { |
128 | //return config->default_layout; | 121 | //return config->default_layout; |
@@ -136,8 +129,8 @@ enum sway_container_layout container_get_default_layout( | |||
136 | } | 129 | } |
137 | 130 | ||
138 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | 131 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { |
139 | struct sway_container *a = *(void **)_a; | 132 | swayc_t *a = *(void **)_a; |
140 | struct sway_container *b = *(void **)_b; | 133 | swayc_t *b = *(void **)_b; |
141 | int retval = 0; | 134 | int retval = 0; |
142 | 135 | ||
143 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { | 136 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { |
@@ -153,22 +146,21 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | |||
153 | return retval; | 146 | return retval; |
154 | } | 147 | } |
155 | 148 | ||
156 | void container_sort_workspaces(struct sway_container *output) { | 149 | void sort_workspaces(swayc_t *output) { |
157 | list_stable_sort(output->children, sort_workspace_cmp_qsort); | 150 | list_stable_sort(output->children, sort_workspace_cmp_qsort); |
158 | } | 151 | } |
159 | 152 | ||
160 | static void apply_horiz_layout(struct sway_container *container, const double x, | 153 | static void apply_horiz_layout(swayc_t *container, const double x, |
161 | const double y, const double width, | 154 | const double y, const double width, |
162 | const double height, const int start, | 155 | const double height, const int start, |
163 | const int end); | 156 | const int end); |
164 | 157 | ||
165 | static void apply_vert_layout(struct sway_container *container, const double x, | 158 | static void apply_vert_layout(swayc_t *container, const double x, |
166 | const double y, const double width, | 159 | const double y, const double width, |
167 | const double height, const int start, | 160 | const double height, const int start, |
168 | const int end); | 161 | const int end); |
169 | 162 | ||
170 | void arrange_windows(struct sway_container *container, | 163 | void arrange_windows(swayc_t *container, double width, double height) { |
171 | double width, double height) { | ||
172 | int i; | 164 | int i; |
173 | if (width == -1 || height == -1) { | 165 | if (width == -1 || height == -1) { |
174 | width = container->width; | 166 | width = container->width; |
@@ -189,7 +181,7 @@ void arrange_windows(struct sway_container *container, | |||
189 | case C_ROOT: | 181 | case C_ROOT: |
190 | // TODO: wlr_output_layout probably | 182 | // TODO: wlr_output_layout probably |
191 | for (i = 0; i < container->children->length; ++i) { | 183 | for (i = 0; i < container->children->length; ++i) { |
192 | struct sway_container *output = container->children->items[i]; | 184 | swayc_t *output = container->children->items[i]; |
193 | wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", | 185 | wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", |
194 | output->name, output->x, output->y); | 186 | output->name, output->x, output->y); |
195 | arrange_windows(output, -1, -1); | 187 | arrange_windows(output, -1, -1); |
@@ -205,14 +197,13 @@ void arrange_windows(struct sway_container *container, | |||
205 | } | 197 | } |
206 | // arrange all workspaces: | 198 | // arrange all workspaces: |
207 | for (i = 0; i < container->children->length; ++i) { | 199 | for (i = 0; i < container->children->length; ++i) { |
208 | struct sway_container *child = container->children->items[i]; | 200 | swayc_t *child = container->children->items[i]; |
209 | arrange_windows(child, -1, -1); | 201 | arrange_windows(child, -1, -1); |
210 | } | 202 | } |
211 | return; | 203 | return; |
212 | case C_WORKSPACE: | 204 | case C_WORKSPACE: |
213 | { | 205 | { |
214 | struct sway_container *output = | 206 | swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); |
215 | container_parent(container, C_OUTPUT); | ||
216 | struct wlr_box *area = &output->sway_output->usable_area; | 207 | struct wlr_box *area = &output->sway_output->usable_area; |
217 | wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", | 208 | wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", |
218 | area->width, area->height, area->x, area->y); | 209 | area->width, area->height, area->x, area->y); |
@@ -261,15 +252,14 @@ void arrange_windows(struct sway_container *container, | |||
261 | } | 252 | } |
262 | } | 253 | } |
263 | 254 | ||
264 | static void apply_horiz_layout(struct sway_container *container, | 255 | static void apply_horiz_layout(swayc_t *container, |
265 | const double x, const double y, | 256 | const double x, const double y, |
266 | const double width, const double height, | 257 | const double width, const double height, |
267 | const int start, const int end) { | 258 | const int start, const int end) { |
268 | double scale = 0; | 259 | double scale = 0; |
269 | // Calculate total width | 260 | // Calculate total width |
270 | for (int i = start; i < end; ++i) { | 261 | for (int i = start; i < end; ++i) { |
271 | double *old_width = | 262 | double *old_width = &((swayc_t *)container->children->items[i])->width; |
272 | &((struct sway_container *)container->children->items[i])->width; | ||
273 | if (*old_width <= 0) { | 263 | if (*old_width <= 0) { |
274 | if (end - start > 1) { | 264 | if (end - start > 1) { |
275 | *old_width = width / (end - start - 1); | 265 | *old_width = width / (end - start - 1); |
@@ -286,7 +276,7 @@ static void apply_horiz_layout(struct sway_container *container, | |||
286 | if (scale > 0.1) { | 276 | if (scale > 0.1) { |
287 | wlr_log(L_DEBUG, "Arranging %p horizontally", container); | 277 | wlr_log(L_DEBUG, "Arranging %p horizontally", container); |
288 | for (int i = start; i < end; ++i) { | 278 | for (int i = start; i < end; ++i) { |
289 | struct sway_container *child = container->children->items[i]; | 279 | swayc_t *child = container->children->items[i]; |
290 | wlr_log(L_DEBUG, | 280 | wlr_log(L_DEBUG, |
291 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 281 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
292 | child, child->type, width, scale); | 282 | child, child->type, width, scale); |
@@ -311,7 +301,7 @@ static void apply_horiz_layout(struct sway_container *container, | |||
311 | } | 301 | } |
312 | } | 302 | } |
313 | 303 | ||
314 | void apply_vert_layout(struct sway_container *container, | 304 | void apply_vert_layout(swayc_t *container, |
315 | const double x, const double y, | 305 | const double x, const double y, |
316 | const double width, const double height, const int start, | 306 | const double width, const double height, const int start, |
317 | const int end) { | 307 | const int end) { |
@@ -319,8 +309,7 @@ void apply_vert_layout(struct sway_container *container, | |||
319 | double scale = 0; | 309 | double scale = 0; |
320 | // Calculate total height | 310 | // Calculate total height |
321 | for (i = start; i < end; ++i) { | 311 | for (i = start; i < end; ++i) { |
322 | double *old_height = | 312 | double *old_height = &((swayc_t *)container->children->items[i])->height; |
323 | &((struct sway_container *)container->children->items[i])->height; | ||
324 | if (*old_height <= 0) { | 313 | if (*old_height <= 0) { |
325 | if (end - start > 1) { | 314 | if (end - start > 1) { |
326 | *old_height = height / (end - start - 1); | 315 | *old_height = height / (end - start - 1); |
@@ -337,7 +326,7 @@ void apply_vert_layout(struct sway_container *container, | |||
337 | if (scale > 0.1) { | 326 | if (scale > 0.1) { |
338 | wlr_log(L_DEBUG, "Arranging %p vertically", container); | 327 | wlr_log(L_DEBUG, "Arranging %p vertically", container); |
339 | for (i = start; i < end; ++i) { | 328 | for (i = start; i < end; ++i) { |
340 | struct sway_container *child = container->children->items[i]; | 329 | swayc_t *child = container->children->items[i]; |
341 | wlr_log(L_DEBUG, | 330 | wlr_log(L_DEBUG, |
342 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 331 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
343 | child, child->type, height, scale); | 332 | child, child->type, height, scale); |
@@ -365,16 +354,15 @@ void apply_vert_layout(struct sway_container *container, | |||
365 | /** | 354 | /** |
366 | * Get swayc in the direction of newly entered output. | 355 | * Get swayc in the direction of newly entered output. |
367 | */ | 356 | */ |
368 | static struct sway_container *get_swayc_in_output_direction( | 357 | static swayc_t *get_swayc_in_output_direction(swayc_t *output, |
369 | struct sway_container *output, enum movement_direction dir, | 358 | enum movement_direction dir, struct sway_seat *seat) { |
370 | struct sway_seat *seat) { | ||
371 | if (!output) { | 359 | if (!output) { |
372 | return NULL; | 360 | return NULL; |
373 | } | 361 | } |
374 | 362 | ||
375 | struct sway_container *ws = sway_seat_get_focus_inactive(seat, output); | 363 | swayc_t *ws = sway_seat_get_focus_inactive(seat, output); |
376 | if (ws->type != C_WORKSPACE) { | 364 | if (ws->type != C_WORKSPACE) { |
377 | ws = container_parent(ws, C_WORKSPACE); | 365 | ws = swayc_parent_by_type(ws, C_WORKSPACE); |
378 | } | 366 | } |
379 | 367 | ||
380 | if (ws == NULL) { | 368 | if (ws == NULL) { |
@@ -392,15 +380,13 @@ static struct sway_container *get_swayc_in_output_direction( | |||
392 | return ws->children->items[0]; | 380 | return ws->children->items[0]; |
393 | case MOVE_UP: | 381 | case MOVE_UP: |
394 | case MOVE_DOWN: { | 382 | case MOVE_DOWN: { |
395 | struct sway_container *focused = | 383 | swayc_t *focused = sway_seat_get_focus_inactive(seat, ws); |
396 | sway_seat_get_focus_inactive(seat, ws); | ||
397 | if (focused && focused->parent) { | 384 | if (focused && focused->parent) { |
398 | struct sway_container *parent = focused->parent; | 385 | swayc_t *parent = focused->parent; |
399 | if (parent->layout == L_VERT) { | 386 | if (parent->layout == L_VERT) { |
400 | if (dir == MOVE_UP) { | 387 | if (dir == MOVE_UP) { |
401 | // get child furthest down on new output | 388 | // get child furthest down on new output |
402 | int idx = parent->children->length - 1; | 389 | return parent->children->items[parent->children->length-1]; |
403 | return parent->children->items[idx]; | ||
404 | } else if (dir == MOVE_DOWN) { | 390 | } else if (dir == MOVE_DOWN) { |
405 | // get child furthest up on new output | 391 | // get child furthest up on new output |
406 | return parent->children->items[0]; | 392 | return parent->children->items[0]; |
@@ -418,14 +404,13 @@ static struct sway_container *get_swayc_in_output_direction( | |||
418 | return ws; | 404 | return ws; |
419 | } | 405 | } |
420 | 406 | ||
421 | static void get_layout_center_position(struct sway_container *container, | 407 | static void get_layout_center_position(swayc_t *container, int *x, int *y) { |
422 | int *x, int *y) { | ||
423 | // FIXME view coords are inconsistently referred to in layout/output systems | 408 | // FIXME view coords are inconsistently referred to in layout/output systems |
424 | if (container->type == C_OUTPUT) { | 409 | if (container->type == C_OUTPUT) { |
425 | *x = container->x + container->width/2; | 410 | *x = container->x + container->width/2; |
426 | *y = container->y + container->height/2; | 411 | *y = container->y + container->height/2; |
427 | } else { | 412 | } else { |
428 | struct sway_container *output = container_parent(container, C_OUTPUT); | 413 | swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); |
429 | if (container->type == C_WORKSPACE) { | 414 | if (container->type == C_WORKSPACE) { |
430 | // Workspace coordinates are actually wrong/arbitrary, but should | 415 | // Workspace coordinates are actually wrong/arbitrary, but should |
431 | // be same as output. | 416 | // be same as output. |
@@ -438,8 +423,7 @@ static void get_layout_center_position(struct sway_container *container, | |||
438 | } | 423 | } |
439 | } | 424 | } |
440 | 425 | ||
441 | static bool sway_dir_to_wlr(enum movement_direction dir, | 426 | static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) { |
442 | enum wlr_direction *out) { | ||
443 | switch (dir) { | 427 | switch (dir) { |
444 | case MOVE_UP: | 428 | case MOVE_UP: |
445 | *out = WLR_DIRECTION_UP; | 429 | *out = WLR_DIRECTION_UP; |
@@ -460,12 +444,12 @@ static bool sway_dir_to_wlr(enum movement_direction dir, | |||
460 | return true; | 444 | return true; |
461 | } | 445 | } |
462 | 446 | ||
463 | static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { | 447 | static swayc_t *sway_output_from_wlr(struct wlr_output *output) { |
464 | if (output == NULL) { | 448 | if (output == NULL) { |
465 | return NULL; | 449 | return NULL; |
466 | } | 450 | } |
467 | for (int i = 0; i < root_container.children->length; ++i) { | 451 | for (int i = 0; i < root_container.children->length; ++i) { |
468 | struct sway_container *o = root_container.children->items[i]; | 452 | swayc_t *o = root_container.children->items[i]; |
469 | if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { | 453 | if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { |
470 | return o; | 454 | return o; |
471 | } | 455 | } |
@@ -473,14 +457,13 @@ static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { | |||
473 | return NULL; | 457 | return NULL; |
474 | } | 458 | } |
475 | 459 | ||
476 | static struct sway_container *get_swayc_in_direction_under( | 460 | static swayc_t *get_swayc_in_direction_under(swayc_t *container, |
477 | struct sway_container *container, enum movement_direction dir, | 461 | enum movement_direction dir, struct sway_seat *seat, swayc_t *limit) { |
478 | struct sway_seat *seat, struct sway_container *limit) { | ||
479 | if (dir == MOVE_CHILD) { | 462 | if (dir == MOVE_CHILD) { |
480 | return sway_seat_get_focus_inactive(seat, container); | 463 | return sway_seat_get_focus_inactive(seat, container); |
481 | } | 464 | } |
482 | 465 | ||
483 | struct sway_container *parent = container->parent; | 466 | swayc_t *parent = container->parent; |
484 | if (dir == MOVE_PARENT) { | 467 | if (dir == MOVE_PARENT) { |
485 | if (parent->type == C_OUTPUT) { | 468 | if (parent->type == C_OUTPUT) { |
486 | return NULL; | 469 | return NULL; |
@@ -513,10 +496,9 @@ static struct sway_container *get_swayc_in_direction_under( | |||
513 | /* | 496 | /* |
514 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { | 497 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { |
515 | wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); | 498 | wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); |
516 | container = container_parent(container, C_OUTPUT); | 499 | container = swayc_parent_by_type(container, C_OUTPUT); |
517 | get_layout_center_position(container, &abs_pos); | 500 | get_layout_center_position(container, &abs_pos); |
518 | struct sway_container *output = | 501 | swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); |
519 | swayc_adjacent_output(container, dir, &abs_pos, true); | ||
520 | return get_swayc_in_output_direction(output, dir); | 502 | return get_swayc_in_output_direction(output, dir); |
521 | } | 503 | } |
522 | if (container->type == C_WORKSPACE && container->fullscreen) { | 504 | if (container->type == C_WORKSPACE && container->fullscreen) { |
@@ -525,7 +507,7 @@ static struct sway_container *get_swayc_in_direction_under( | |||
525 | } | 507 | } |
526 | */ | 508 | */ |
527 | 509 | ||
528 | struct sway_container *wrap_candidate = NULL; | 510 | swayc_t *wrap_candidate = NULL; |
529 | while (true) { | 511 | while (true) { |
530 | // Test if we can even make a difference here | 512 | // Test if we can even make a difference here |
531 | bool can_move = false; | 513 | bool can_move = false; |
@@ -539,19 +521,16 @@ static struct sway_container *get_swayc_in_direction_under( | |||
539 | } | 521 | } |
540 | int lx, ly; | 522 | int lx, ly; |
541 | get_layout_center_position(container, &lx, &ly); | 523 | get_layout_center_position(container, &lx, &ly); |
542 | struct wlr_output_layout *layout = | 524 | struct wlr_output_layout *layout = root_container.sway_root->output_layout; |
543 | root_container.sway_root->output_layout; | ||
544 | struct wlr_output *wlr_adjacent = | 525 | struct wlr_output *wlr_adjacent = |
545 | wlr_output_layout_adjacent_output(layout, wlr_dir, | 526 | wlr_output_layout_adjacent_output(layout, wlr_dir, |
546 | container->sway_output->wlr_output, lx, ly); | 527 | container->sway_output->wlr_output, lx, ly); |
547 | struct sway_container *adjacent = | 528 | swayc_t *adjacent = sway_output_from_wlr(wlr_adjacent); |
548 | sway_output_from_wlr(wlr_adjacent); | ||
549 | 529 | ||
550 | if (!adjacent || adjacent == container) { | 530 | if (!adjacent || adjacent == container) { |
551 | return wrap_candidate; | 531 | return wrap_candidate; |
552 | } | 532 | } |
553 | struct sway_container *next = | 533 | swayc_t *next = get_swayc_in_output_direction(adjacent, dir, seat); |
554 | get_swayc_in_output_direction(adjacent, dir, seat); | ||
555 | if (next == NULL) { | 534 | if (next == NULL) { |
556 | return NULL; | 535 | return NULL; |
557 | } | 536 | } |
@@ -591,9 +570,8 @@ static struct sway_container *get_swayc_in_direction_under( | |||
591 | } | 570 | } |
592 | } | 571 | } |
593 | } else { | 572 | } else { |
594 | wlr_log(L_DEBUG, | 573 | wlr_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__, |
595 | "cont %d-%p dir %i sibling %d: %p", idx, | 574 | idx, container, dir, desired, parent->children->items[desired]); |
596 | container, dir, desired, parent->children->items[desired]); | ||
597 | return parent->children->items[desired]; | 575 | return parent->children->items[desired]; |
598 | } | 576 | } |
599 | } | 577 | } |
@@ -609,8 +587,7 @@ static struct sway_container *get_swayc_in_direction_under( | |||
609 | } | 587 | } |
610 | } | 588 | } |
611 | 589 | ||
612 | struct sway_container *container_get_in_direction( | 590 | swayc_t *get_swayc_in_direction(swayc_t *container, struct sway_seat *seat, |
613 | struct sway_container *container, struct sway_seat *seat, | ||
614 | enum movement_direction dir) { | 591 | enum movement_direction dir) { |
615 | return get_swayc_in_direction_under(container, dir, seat, NULL); | 592 | return get_swayc_in_direction_under(container, dir, seat, NULL); |
616 | } | 593 | } |
diff --git a/sway/tree/view.c b/sway/tree/view.c index d5325c31..9499adca 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/tree/container.h" | 3 | #include "sway/container.h" |
4 | #include "sway/tree/layout.h" | 4 | #include "sway/layout.h" |
5 | #include "sway/tree/view.h" | 5 | #include "sway/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,7 +45,6 @@ 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 | ||
49 | void view_set_position(struct sway_view *view, double ox, double oy) { | 48 | void view_set_position(struct sway_view *view, double ox, double oy) { |
50 | if (view->iface.set_position) { | 49 | if (view->iface.set_position) { |
51 | struct wlr_box box = { | 50 | struct wlr_box box = { |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index ba04c55c..861fda4d 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/tree/container.h" | 6 | #include "sway/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/tree/workspace.h" | 9 | #include "sway/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(struct sway_container *ws, void *data) { | 20 | void next_name_map(swayc_t *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(struct sway_container *view, void *data) { | 40 | static bool _workspace_by_number(swayc_t *view, void *data) { |
41 | if (view->type != C_WORKSPACE) { | 41 | if (view->type != C_WORKSPACE) { |
42 | return false; | 42 | return false; |
43 | } | 43 | } |
@@ -46,28 +46,27 @@ static bool _workspace_by_number(struct sway_container *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 | struct sway_container *workspace_by_number(const char* name) { | 49 | swayc_t *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 container_find(&root_container, | 55 | return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd); |
56 | _workspace_by_number, (void *) &wbnd); | ||
57 | } | 56 | } |
58 | 57 | ||
59 | static bool _workspace_by_name(struct sway_container *view, void *data) { | 58 | static bool _workspace_by_name(swayc_t *view, void *data) { |
60 | return (view->type == C_WORKSPACE) && | 59 | return (view->type == C_WORKSPACE) && |
61 | (strcasecmp(view->name, (char *) data) == 0); | 60 | (strcasecmp(view->name, (char *) data) == 0); |
62 | } | 61 | } |
63 | 62 | ||
64 | struct sway_container *workspace_by_name(const char *name) { | 63 | swayc_t *workspace_by_name(const char *name) { |
65 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 64 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
66 | struct sway_container *current_workspace = NULL, *current_output = NULL; | 65 | swayc_t *current_workspace = NULL, *current_output = NULL; |
67 | struct sway_container *focus = sway_seat_get_focus(seat); | 66 | swayc_t *focus = sway_seat_get_focus(seat); |
68 | if (focus) { | 67 | if (focus) { |
69 | current_workspace = container_parent(focus, C_WORKSPACE); | 68 | current_workspace = swayc_parent_by_type(focus, C_WORKSPACE); |
70 | current_output = container_parent(focus, C_OUTPUT); | 69 | current_output = swayc_parent_by_type(focus, C_OUTPUT); |
71 | } | 70 | } |
72 | if (strcmp(name, "prev") == 0) { | 71 | if (strcmp(name, "prev") == 0) { |
73 | return workspace_prev(current_workspace); | 72 | return workspace_prev(current_workspace); |
@@ -80,13 +79,12 @@ struct sway_container *workspace_by_name(const char *name) { | |||
80 | } else if (strcmp(name, "current") == 0) { | 79 | } else if (strcmp(name, "current") == 0) { |
81 | return current_workspace; | 80 | return current_workspace; |
82 | } else { | 81 | } else { |
83 | return container_find(&root_container, _workspace_by_name, | 82 | return swayc_by_test(&root_container, _workspace_by_name, (void *) name); |
84 | (void *)name); | ||
85 | } | 83 | } |
86 | } | 84 | } |
87 | 85 | ||
88 | struct sway_container *workspace_create(const char *name) { | 86 | swayc_t *workspace_create(const char *name) { |
89 | struct sway_container *parent; | 87 | swayc_t *parent; |
90 | // Search for workspace<->output pair | 88 | // Search for workspace<->output pair |
91 | int i, e = config->workspace_outputs->length; | 89 | int i, e = config->workspace_outputs->length; |
92 | for (i = 0; i < e; ++i) { | 90 | for (i = 0; i < e; ++i) { |
@@ -97,7 +95,7 @@ struct sway_container *workspace_create(const char *name) { | |||
97 | for (i = 0; i < e; ++i) { | 95 | for (i = 0; i < e; ++i) { |
98 | parent = root_container.children->items[i]; | 96 | parent = root_container.children->items[i]; |
99 | if (strcmp(parent->name, wso->output) == 0) { | 97 | if (strcmp(parent->name, wso->output) == 0) { |
100 | return container_workspace_create(parent, name); | 98 | return new_workspace(parent, name); |
101 | } | 99 | } |
102 | } | 100 | } |
103 | break; | 101 | break; |
@@ -105,11 +103,10 @@ struct sway_container *workspace_create(const char *name) { | |||
105 | } | 103 | } |
106 | // Otherwise create a new one | 104 | // Otherwise create a new one |
107 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 105 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
108 | struct sway_container *focus = | 106 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); |
109 | sway_seat_get_focus_inactive(seat, &root_container); | ||
110 | parent = focus; | 107 | parent = focus; |
111 | parent = container_parent(parent, C_OUTPUT); | 108 | parent = swayc_parent_by_type(parent, C_OUTPUT); |
112 | return container_workspace_create(parent, name); | 109 | return new_workspace(parent, name); |
113 | } | 110 | } |
114 | 111 | ||
115 | /** | 112 | /** |
@@ -117,18 +114,17 @@ struct sway_container *workspace_create(const char *name) { | |||
117 | * the end and beginning. If next is false, the previous workspace is returned, | 114 | * the end and beginning. If next is false, the previous workspace is returned, |
118 | * otherwise the next one is returned. | 115 | * otherwise the next one is returned. |
119 | */ | 116 | */ |
120 | struct sway_container *workspace_output_prev_next_impl( | 117 | swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { |
121 | struct sway_container *output, bool next) { | ||
122 | if (!sway_assert(output->type == C_OUTPUT, | 118 | if (!sway_assert(output->type == C_OUTPUT, |
123 | "Argument must be an output, is %d", output->type)) { | 119 | "Argument must be an output, is %d", output->type)) { |
124 | return NULL; | 120 | return NULL; |
125 | } | 121 | } |
126 | 122 | ||
127 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 123 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
128 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, output); | 124 | swayc_t *focus = sway_seat_get_focus_inactive(seat, output); |
129 | struct sway_container *workspace = (focus->type == C_WORKSPACE ? | 125 | swayc_t *workspace = (focus->type == C_WORKSPACE ? |
130 | focus : | 126 | focus : |
131 | container_parent(focus, C_WORKSPACE)); | 127 | swayc_parent_by_type(focus, C_WORKSPACE)); |
132 | 128 | ||
133 | int i; | 129 | int i; |
134 | for (i = 0; i < output->children->length; i++) { | 130 | for (i = 0; i < output->children->length; i++) { |
@@ -138,8 +134,7 @@ struct sway_container *workspace_output_prev_next_impl( | |||
138 | } | 134 | } |
139 | } | 135 | } |
140 | 136 | ||
141 | // Doesn't happen, at worst the for loop returns the previously active | 137 | // Doesn't happen, at worst the for loop returns the previously active workspace |
142 | // workspace | ||
143 | return NULL; | 138 | return NULL; |
144 | } | 139 | } |
145 | 140 | ||
@@ -149,14 +144,13 @@ struct sway_container *workspace_output_prev_next_impl( | |||
149 | * next is false, the previous workspace is returned, otherwise the next one is | 144 | * next is false, the previous workspace is returned, otherwise the next one is |
150 | * returned. | 145 | * returned. |
151 | */ | 146 | */ |
152 | struct sway_container *workspace_prev_next_impl( | 147 | swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { |
153 | struct sway_container *workspace, bool next) { | ||
154 | if (!sway_assert(workspace->type == C_WORKSPACE, | 148 | if (!sway_assert(workspace->type == C_WORKSPACE, |
155 | "Argument must be a workspace, is %d", workspace->type)) { | 149 | "Argument must be a workspace, is %d", workspace->type)) { |
156 | return NULL; | 150 | return NULL; |
157 | } | 151 | } |
158 | 152 | ||
159 | struct sway_container *current_output = workspace->parent; | 153 | swayc_t *current_output = workspace->parent; |
160 | int offset = next ? 1 : -1; | 154 | int offset = next ? 1 : -1; |
161 | int start = next ? 0 : 1; | 155 | int start = next ? 0 : 1; |
162 | int end; | 156 | int end; |
@@ -172,57 +166,54 @@ struct sway_container *workspace_prev_next_impl( | |||
172 | } | 166 | } |
173 | } | 167 | } |
174 | 168 | ||
175 | // Given workspace is the first/last on the output, jump to the | 169 | // Given workspace is the first/last on the output, jump to the previous/next output |
176 | // previous/next output | ||
177 | int num_outputs = root_container.children->length; | 170 | int num_outputs = root_container.children->length; |
178 | for (i = 0; i < num_outputs; i++) { | 171 | for (i = 0; i < num_outputs; i++) { |
179 | if (root_container.children->items[i] == current_output) { | 172 | if (root_container.children->items[i] == current_output) { |
180 | struct sway_container *next_output = root_container.children->items[ | 173 | swayc_t *next_output = root_container.children->items[ |
181 | wrap(i + offset, num_outputs)]; | 174 | wrap(i + offset, num_outputs)]; |
182 | return workspace_output_prev_next_impl(next_output, next); | 175 | return workspace_output_prev_next_impl(next_output, next); |
183 | } | 176 | } |
184 | } | 177 | } |
185 | 178 | ||
186 | // Doesn't happen, at worst the for loop returns the previously active | 179 | // Doesn't happen, at worst the for loop returns the previously active workspace on the active output |
187 | // workspace on the active output | ||
188 | return NULL; | 180 | return NULL; |
189 | } | 181 | } |
190 | 182 | ||
191 | struct sway_container *workspace_output_next(struct sway_container *current) { | 183 | swayc_t *workspace_output_next(swayc_t *current) { |
192 | return workspace_output_prev_next_impl(current, true); | 184 | return workspace_output_prev_next_impl(current, true); |
193 | } | 185 | } |
194 | 186 | ||
195 | struct sway_container *workspace_next(struct sway_container *current) { | 187 | swayc_t *workspace_next(swayc_t *current) { |
196 | return workspace_prev_next_impl(current, true); | 188 | return workspace_prev_next_impl(current, true); |
197 | } | 189 | } |
198 | 190 | ||
199 | struct sway_container *workspace_output_prev(struct sway_container *current) { | 191 | swayc_t *workspace_output_prev(swayc_t *current) { |
200 | return workspace_output_prev_next_impl(current, false); | 192 | return workspace_output_prev_next_impl(current, false); |
201 | } | 193 | } |
202 | 194 | ||
203 | struct sway_container *workspace_prev(struct sway_container *current) { | 195 | swayc_t *workspace_prev(swayc_t *current) { |
204 | return workspace_prev_next_impl(current, false); | 196 | return workspace_prev_next_impl(current, false); |
205 | } | 197 | } |
206 | 198 | ||
207 | bool workspace_switch(struct sway_container *workspace) { | 199 | bool workspace_switch(swayc_t *workspace) { |
208 | if (!workspace) { | 200 | if (!workspace) { |
209 | return false; | 201 | return false; |
210 | } | 202 | } |
211 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 203 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
212 | struct sway_container *focus = | 204 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); |
213 | sway_seat_get_focus_inactive(seat, &root_container); | ||
214 | if (!seat || !focus) { | 205 | if (!seat || !focus) { |
215 | return false; | 206 | return false; |
216 | } | 207 | } |
217 | struct sway_container *active_ws = focus; | 208 | swayc_t *active_ws = focus; |
218 | if (active_ws->type != C_WORKSPACE) { | 209 | if (active_ws->type != C_WORKSPACE) { |
219 | container_parent(focus, C_WORKSPACE); | 210 | swayc_parent_by_type(focus, C_WORKSPACE); |
220 | } | 211 | } |
221 | 212 | ||
222 | if (config->auto_back_and_forth | 213 | if (config->auto_back_and_forth |
223 | && active_ws == workspace | 214 | && active_ws == workspace |
224 | && prev_workspace_name) { | 215 | && prev_workspace_name) { |
225 | struct sway_container *new_ws = workspace_by_name(prev_workspace_name); | 216 | swayc_t *new_ws = workspace_by_name(prev_workspace_name); |
226 | workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); | 217 | workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); |
227 | } | 218 | } |
228 | 219 | ||
@@ -239,14 +230,13 @@ bool workspace_switch(struct sway_container *workspace) { | |||
239 | 230 | ||
240 | // TODO: Deal with sticky containers | 231 | // TODO: Deal with sticky containers |
241 | 232 | ||
242 | wlr_log(L_DEBUG, "Switching to workspace %p:%s", | 233 | wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); |
243 | workspace, workspace->name); | 234 | swayc_t *next = sway_seat_get_focus_inactive(seat, workspace); |
244 | struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace); | ||
245 | if (next == NULL) { | 235 | if (next == NULL) { |
246 | next = workspace; | 236 | next = workspace; |
247 | } | 237 | } |
248 | sway_seat_set_focus(seat, next); | 238 | sway_seat_set_focus(seat, next); |
249 | struct sway_container *output = container_parent(workspace, C_OUTPUT); | 239 | swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); |
250 | arrange_windows(output, -1, -1); | 240 | arrange_windows(output, -1, -1); |
251 | return true; | 241 | return true; |
252 | } | 242 | } |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 2d2b3b69..93d1219c 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 = container_output_create(name); | 355 | struct output *bar_output = new_output(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 | } |