aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-30 21:00:10 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-05 18:01:43 +1000
commit7586f150c058997d9dde387ea7c091ffa7a3c3c7 (patch)
tree63d19027974c1db62ce3a74ca1d2314eb6d5049b /include
parentMerge pull request #2569 from RyanDwyer/deny-reload-repeat (diff)
downloadsway-7586f150c058997d9dde387ea7c091ffa7a3c3c7.tar.gz
sway-7586f150c058997d9dde387ea7c091ffa7a3c3c7.tar.zst
sway-7586f150c058997d9dde387ea7c091ffa7a3c3c7.zip
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers to layout containers and view containers. Workspaces, outputs and the root are no longer known as containers. Instead, root, outputs, workspaces and containers are all a type of node, and containers come in two types: layout containers and view containers. In addition to the above, this implements type safe variables. This means we use specific types such as sway_output and sway_workspace instead of generic containers or nodes. However, it's worth noting that in a few places places (eg. seat focus and transactions) referring to them in a generic way is unavoidable which is why we still use nodes in some places. If you want a TL;DR, look at node.h, as well as the struct definitions for root, output, workspace and container. Note that sway_output now contains a workspaces list, and workspaces now contain a tiling and floating list, and containers now contain a pointer back to the workspace. There are now functions for seat_get_focused_workspace and seat_get_focused_container. The latter will return NULL if a workspace itself is focused. Most other seat functions like seat_get_focus and seat_set_focus now accept and return nodes. In the config->handler_context struct, current_container has been replaced with three pointers: node, container and workspace. node is the same as what current_container was, while workspace is the workspace that the node resides on and container is the actual container, which may be NULL if a workspace itself is focused. The global root_container variable has been replaced with one simply called root, which is a pointer to the sway_root instance. The way outputs are created, enabled, disabled and destroyed has changed. Previously we'd wrap the sway_output in a container when it is enabled, but as we don't have containers any more it needs a different approach. The output_create and output_destroy functions previously created/destroyed the container, but now they create/destroy the sway_output. There is a new function output_disable to disable an output without destroying it. Containers have a new view property. If this is populated then the container is a view container, otherwise it's a layout container. Like before, this property is immutable for the life of the container. Containers have both a `sway_container *parent` and `sway_workspace *workspace`. As we use specific types now, parent cannot point to a workspace so it'll be NULL for containers which are direct children of the workspace. The workspace property is set for all containers, except those which are hidden in the scratchpad as they have no workspace. In some cases we need to refer to workspaces in a container-like way. For example, workspaces have layout and children, but when using specific types this makes it difficult. Likewise, it's difficult for a container to get its parent's layout when the parent could be another container or a workspace. To make it easier, some helper functions have been created: container_parent_layout and container_get_siblings. container_remove_child has been renamed to container_detach and container_replace_child has been renamed to container_replace. `container_handle_fullscreen_reparent(con, old_parent)` has had the old_parent removed. We now unfullscreen the workspace when detaching the container, so this function is simplified and only needs one argument now. container_notify_subtree_changed has been renamed to container_update_representation. This is more descriptive of its purpose. I also wanted to be able to call it with whatever container was changed rather than the container's parent, which makes bubbling up to the workspace easier. There are now state structs per node thing. ie. sway_output_state, sway_workspace_state and sway_container_state. The focus, move and layout commands have been completely refactored to work with the specific types. I considered making these a separate PR, but I'd be backporting my changes only to replace them again, and it's easier just to test everything at once.
Diffstat (limited to 'include')
-rw-r--r--include/sway/config.h7
-rw-r--r--include/sway/desktop/transaction.h4
-rw-r--r--include/sway/input/input-manager.h4
-rw-r--r--include/sway/input/seat.h35
-rw-r--r--include/sway/ipc-json.h4
-rw-r--r--include/sway/ipc-server.h4
-rw-r--r--include/sway/output.h59
-rw-r--r--include/sway/server.h2
-rw-r--r--include/sway/tree/arrange.h9
-rw-r--r--include/sway/tree/container.h148
-rw-r--r--include/sway/tree/node.h74
-rw-r--r--include/sway/tree/root.h28
-rw-r--r--include/sway/tree/view.h4
-rw-r--r--include/sway/tree/workspace.h105
14 files changed, 286 insertions, 201 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index 6024f0f6..2fef0081 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -407,7 +407,9 @@ struct sway_config {
407 struct output_config *output_config; 407 struct output_config *output_config;
408 struct seat_config *seat_config; 408 struct seat_config *seat_config;
409 struct sway_seat *seat; 409 struct sway_seat *seat;
410 struct sway_container *current_container; 410 struct sway_node *node;
411 struct sway_container *container;
412 struct sway_workspace *workspace;
411 bool using_criteria; 413 bool using_criteria;
412 struct { 414 struct {
413 int argc; 415 int argc;
@@ -486,8 +488,7 @@ struct output_config *new_output_config(const char *name);
486 488
487void merge_output_config(struct output_config *dst, struct output_config *src); 489void merge_output_config(struct output_config *dst, struct output_config *src);
488 490
489void apply_output_config(struct output_config *oc, 491void apply_output_config(struct output_config *oc, struct sway_output *output);
490 struct sway_container *output);
491 492
492struct output_config *store_output_config(struct output_config *oc); 493struct output_config *store_output_config(struct output_config *oc);
493 494
diff --git a/include/sway/desktop/transaction.h b/include/sway/desktop/transaction.h
index 7ac924e7..66e8c9a2 100644
--- a/include/sway/desktop/transaction.h
+++ b/include/sway/desktop/transaction.h
@@ -1,7 +1,6 @@
1#ifndef _SWAY_TRANSACTION_H 1#ifndef _SWAY_TRANSACTION_H
2#define _SWAY_TRANSACTION_H 2#define _SWAY_TRANSACTION_H
3#include <wlr/render/wlr_texture.h> 3#include <stdint.h>
4#include "sway/tree/container.h"
5 4
6/** 5/**
7 * Transactions enable us to perform atomic layout updates. 6 * Transactions enable us to perform atomic layout updates.
@@ -21,6 +20,7 @@
21 */ 20 */
22 21
23struct sway_transaction_instruction; 22struct sway_transaction_instruction;
23struct sway_view;
24 24
25/** 25/**
26 * Find all dirty containers, create and commit a transaction containing them, 26 * Find all dirty containers, create and commit a transaction containing them,
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h
index aa2f6f19..bde3cf46 100644
--- a/include/sway/input/input-manager.h
+++ b/include/sway/input/input-manager.h
@@ -37,10 +37,10 @@ struct sway_input_manager {
37struct sway_input_manager *input_manager_create(struct sway_server *server); 37struct sway_input_manager *input_manager_create(struct sway_server *server);
38 38
39bool input_manager_has_focus(struct sway_input_manager *input, 39bool input_manager_has_focus(struct sway_input_manager *input,
40 struct sway_container *container); 40 struct sway_node *node);
41 41
42void input_manager_set_focus(struct sway_input_manager *input, 42void input_manager_set_focus(struct sway_input_manager *input,
43 struct sway_container *container); 43 struct sway_node *node);
44 44
45void input_manager_configure_xcursor(struct sway_input_manager *input); 45void input_manager_configure_xcursor(struct sway_input_manager *input);
46 46
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index 5c404ecd..8a7e5450 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -13,9 +13,9 @@ struct sway_seat_device {
13 struct wl_list link; // sway_seat::devices 13 struct wl_list link; // sway_seat::devices
14}; 14};
15 15
16struct sway_seat_container { 16struct sway_seat_node {
17 struct sway_seat *seat; 17 struct sway_seat *seat;
18 struct sway_container *container; 18 struct sway_node *node;
19 19
20 struct wl_list link; // sway_seat::focus_stack 20 struct wl_list link; // sway_seat::focus_stack
21 21
@@ -76,7 +76,7 @@ struct sway_seat {
76 uint32_t last_button_serial; 76 uint32_t last_button_serial;
77 77
78 struct wl_listener focus_destroy; 78 struct wl_listener focus_destroy;
79 struct wl_listener new_container; 79 struct wl_listener new_node;
80 struct wl_listener new_drag_icon; 80 struct wl_listener new_drag_icon;
81 81
82 struct wl_list devices; // sway_seat_device::link 82 struct wl_list devices; // sway_seat_device::link
@@ -100,10 +100,10 @@ void seat_remove_device(struct sway_seat *seat,
100 100
101void seat_configure_xcursor(struct sway_seat *seat); 101void seat_configure_xcursor(struct sway_seat *seat);
102 102
103void seat_set_focus(struct sway_seat *seat, struct sway_container *container); 103void seat_set_focus(struct sway_seat *seat, struct sway_node *node);
104 104
105void seat_set_focus_warp(struct sway_seat *seat, 105void seat_set_focus_warp(struct sway_seat *seat,
106 struct sway_container *container, bool warp, bool notify); 106 struct sway_node *node, bool warp, bool notify);
107 107
108void seat_set_focus_surface(struct sway_seat *seat, 108void seat_set_focus_surface(struct sway_seat *seat,
109 struct wlr_surface *surface, bool unfocus); 109 struct wlr_surface *surface, bool unfocus);
@@ -114,7 +114,11 @@ void seat_set_focus_layer(struct sway_seat *seat,
114void seat_set_exclusive_client(struct sway_seat *seat, 114void seat_set_exclusive_client(struct sway_seat *seat,
115 struct wl_client *client); 115 struct wl_client *client);
116 116
117struct sway_container *seat_get_focus(struct sway_seat *seat); 117struct sway_node *seat_get_focus(struct sway_seat *seat);
118
119struct sway_workspace *seat_get_focused_workspace(struct sway_seat *seat);
120
121struct sway_container *seat_get_focused_container(struct sway_seat *seat);
118 122
119/** 123/**
120 * Return the last container to be focused for the seat (or the most recently 124 * Return the last container to be focused for the seat (or the most recently
@@ -125,32 +129,31 @@ struct sway_container *seat_get_focus(struct sway_seat *seat);
125 * is destroyed, or focus moves to a container with children and we need to 129 * is destroyed, or focus moves to a container with children and we need to
126 * descend into the next leaf in focus order. 130 * descend into the next leaf in focus order.
127 */ 131 */
128struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, 132struct sway_node *seat_get_focus_inactive(struct sway_seat *seat,
129 struct sway_container *container); 133 struct sway_node *node);
130 134
131struct sway_container *seat_get_focus_inactive_tiling(struct sway_seat *seat, 135struct sway_container *seat_get_focus_inactive_tiling(struct sway_seat *seat,
132 struct sway_container *container); 136 struct sway_workspace *workspace);
133 137
134/** 138/**
135 * Descend into the focus stack to find the focus-inactive view. Useful for 139 * Descend into the focus stack to find the focus-inactive view. Useful for
136 * container placement when they change position in the tree. 140 * container placement when they change position in the tree.
137 */ 141 */
138struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat, 142struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat,
139 struct sway_container *container); 143 struct sway_node *ancestor);
140 144
141/** 145/**
142 * Return the immediate child of container which was most recently focused. 146 * Return the immediate child of container which was most recently focused.
143 */ 147 */
144struct sway_container *seat_get_active_child(struct sway_seat *seat, 148struct sway_node *seat_get_active_child(struct sway_seat *seat,
145 struct sway_container *container); 149 struct sway_node *parent);
146 150
147/** 151/**
148 * Iterate over the focus-inactive children of the container calling the 152 * Iterate over the focus-inactive children of the container calling the
149 * function on each. 153 * function on each.
150 */ 154 */
151void seat_focus_inactive_children_for_each(struct sway_seat *seat, 155void seat_for_each_node(struct sway_seat *seat,
152 struct sway_container *container, 156 void (*f)(struct sway_node *node, void *data), void *data);
153 void (*f)(struct sway_container *container, void *data), void *data);
154 157
155void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config); 158void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config);
156 159
@@ -173,7 +176,7 @@ void seat_begin_resize_tiling(struct sway_seat *seat,
173 struct sway_container *con, uint32_t button, enum wlr_edges edge); 176 struct sway_container *con, uint32_t button, enum wlr_edges edge);
174 177
175struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat, 178struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat,
176 struct sway_container *container); 179 struct sway_workspace *workspace);
177 180
178void seat_end_mouse_operation(struct sway_seat *seat); 181void seat_end_mouse_operation(struct sway_seat *seat);
179 182
diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h
index eaaa2164..fef243e3 100644
--- a/include/sway/ipc-json.h
+++ b/include/sway/ipc-json.h
@@ -7,8 +7,8 @@
7json_object *ipc_json_get_version(); 7json_object *ipc_json_get_version();
8 8
9json_object *ipc_json_describe_disabled_output(struct sway_output *o); 9json_object *ipc_json_describe_disabled_output(struct sway_output *o);
10json_object *ipc_json_describe_container(struct sway_container *c); 10json_object *ipc_json_describe_node(struct sway_node *node);
11json_object *ipc_json_describe_container_recursive(struct sway_container *c); 11json_object *ipc_json_describe_node_recursive(struct sway_node *node);
12json_object *ipc_json_describe_input(struct sway_input_device *device); 12json_object *ipc_json_describe_input(struct sway_input_device *device);
13json_object *ipc_json_describe_seat(struct sway_seat *seat); 13json_object *ipc_json_describe_seat(struct sway_seat *seat);
14json_object *ipc_json_describe_bar_config(struct bar_config *bar); 14json_object *ipc_json_describe_bar_config(struct bar_config *bar);
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h
index 4b6d0e25..80180ec4 100644
--- a/include/sway/ipc-server.h
+++ b/include/sway/ipc-server.h
@@ -11,8 +11,8 @@ void ipc_init(struct sway_server *server);
11 11
12struct sockaddr_un *ipc_user_sockaddr(void); 12struct sockaddr_un *ipc_user_sockaddr(void);
13 13
14void ipc_event_workspace(struct sway_container *old, 14void ipc_event_workspace(struct sway_workspace *old,
15 struct sway_container *new, const char *change); 15 struct sway_workspace *new, const char *change);
16void ipc_event_window(struct sway_container *window, const char *change); 16void ipc_event_window(struct sway_container *window, const char *change);
17void ipc_event_barconfig_update(struct bar_config *bar); 17void ipc_event_barconfig_update(struct bar_config *bar);
18void ipc_event_mode(const char *mode, bool pango); 18void ipc_event_mode(const char *mode, bool pango);
diff --git a/include/sway/output.h b/include/sway/output.h
index 651fdfe7..540ed8a0 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -6,14 +6,20 @@
6#include <wlr/types/wlr_box.h> 6#include <wlr/types/wlr_box.h>
7#include <wlr/types/wlr_output.h> 7#include <wlr/types/wlr_output.h>
8#include "config.h" 8#include "config.h"
9#include "sway/tree/node.h"
9#include "sway/tree/view.h" 10#include "sway/tree/view.h"
10 11
11struct sway_server; 12struct sway_server;
12struct sway_container; 13struct sway_container;
13 14
15struct sway_output_state {
16 list_t *workspaces;
17 struct sway_workspace *active_workspace;
18};
19
14struct sway_output { 20struct sway_output {
21 struct sway_node node;
15 struct wlr_output *wlr_output; 22 struct wlr_output *wlr_output;
16 struct sway_container *swayc;
17 struct sway_server *server; 23 struct sway_server *server;
18 24
19 struct wl_list layers[4]; // sway_layer_surface::link 25 struct wl_list layers[4]; // sway_layer_surface::link
@@ -22,11 +28,15 @@ struct sway_output {
22 struct timespec last_frame; 28 struct timespec last_frame;
23 struct wlr_output_damage *damage; 29 struct wlr_output_damage *damage;
24 30
31 bool enabled;
32 list_t *workspaces;
33
34 struct sway_output_state current;
35
25 struct wl_listener destroy; 36 struct wl_listener destroy;
26 struct wl_listener mode; 37 struct wl_listener mode;
27 struct wl_listener transform; 38 struct wl_listener transform;
28 struct wl_listener scale; 39 struct wl_listener scale;
29
30 struct wl_listener damage_destroy; 40 struct wl_listener damage_destroy;
31 struct wl_listener damage_frame; 41 struct wl_listener damage_frame;
32 42
@@ -39,13 +49,19 @@ struct sway_output {
39 } events; 49 } events;
40}; 50};
41 51
42struct sway_container *output_create(struct sway_output *sway_output); 52struct sway_output *output_create(struct wlr_output *wlr_output);
53
54void output_destroy(struct sway_output *output);
55
56void output_begin_destroy(struct sway_output *output);
43 57
44void output_destroy(struct sway_container *output); 58struct sway_output *output_from_wlr_output(struct wlr_output *output);
45 59
46void output_begin_destroy(struct sway_container *output); 60struct sway_output *output_get_in_direction(struct sway_output *reference,
61 enum movement_direction direction);
47 62
48struct sway_container *output_from_wlr_output(struct wlr_output *output); 63void output_add_workspace(struct sway_output *output,
64 struct sway_workspace *workspace);
49 65
50typedef void (*sway_surface_iterator_func_t)(struct sway_output *output, 66typedef void (*sway_surface_iterator_func_t)(struct sway_output *output,
51 struct wlr_surface *surface, struct wlr_box *box, float rotation, 67 struct wlr_surface *surface, struct wlr_box *box, float rotation,
@@ -64,15 +80,19 @@ void output_damage_box(struct sway_output *output, struct wlr_box *box);
64void output_damage_whole_container(struct sway_output *output, 80void output_damage_whole_container(struct sway_output *output,
65 struct sway_container *con); 81 struct sway_container *con);
66 82
67struct sway_container *output_by_name(const char *name); 83struct sway_output *output_by_name(const char *name);
68 84
69void output_sort_workspaces(struct sway_container *output); 85void output_sort_workspaces(struct sway_output *output);
70 86
71void output_enable(struct sway_output *output); 87struct output_config *output_find_config(struct sway_output *output);
88
89void output_enable(struct sway_output *output, struct output_config *oc);
90
91void output_disable(struct sway_output *output);
72 92
73bool output_has_opaque_overlay_layer_surface(struct sway_output *output); 93bool output_has_opaque_overlay_layer_surface(struct sway_output *output);
74 94
75struct sway_container *output_get_active_workspace(struct sway_output *output); 95struct sway_workspace *output_get_active_workspace(struct sway_output *output);
76 96
77void output_render(struct sway_output *output, struct timespec *when, 97void output_render(struct sway_output *output, struct timespec *when,
78 pixman_region32_t *damage); 98 pixman_region32_t *damage);
@@ -103,16 +123,23 @@ void output_drag_icons_for_each_surface(struct sway_output *output,
103 struct wl_list *drag_icons, sway_surface_iterator_func_t iterator, 123 struct wl_list *drag_icons, sway_surface_iterator_func_t iterator,
104 void *user_data); 124 void *user_data);
105 125
106void output_for_each_workspace(struct sway_container *output, 126void output_for_each_workspace(struct sway_output *output,
107 void (*f)(struct sway_container *con, void *data), void *data); 127 void (*f)(struct sway_workspace *ws, void *data), void *data);
108 128
109void output_for_each_container(struct sway_container *output, 129void output_for_each_container(struct sway_output *output,
110 void (*f)(struct sway_container *con, void *data), void *data); 130 void (*f)(struct sway_container *con, void *data), void *data);
111 131
112struct sway_container *output_find_workspace(struct sway_container *output, 132struct sway_workspace *output_find_workspace(struct sway_output *output,
113 bool (*test)(struct sway_container *con, void *data), void *data); 133 bool (*test)(struct sway_workspace *ws, void *data), void *data);
114 134
115struct sway_container *output_find_container(struct sway_container *output, 135struct sway_container *output_find_container(struct sway_output *output,
116 bool (*test)(struct sway_container *con, void *data), void *data); 136 bool (*test)(struct sway_container *con, void *data), void *data);
117 137
138void output_get_box(struct sway_output *output, struct wlr_box *box);
139
140enum sway_container_layout output_get_default_layout(
141 struct sway_output *output);
142
143void output_add_listeners(struct sway_output *output);
144
118#endif 145#endif
diff --git a/include/sway/server.h b/include/sway/server.h
index 1e20f2c8..07e0949a 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -56,7 +56,7 @@ struct sway_server {
56 56
57 size_t txn_timeout_ms; 57 size_t txn_timeout_ms;
58 list_t *transactions; 58 list_t *transactions;
59 list_t *dirty_containers; 59 list_t *dirty_nodes;
60}; 60};
61 61
62struct sway_server server; 62struct sway_server server;
diff --git a/include/sway/tree/arrange.h b/include/sway/tree/arrange.h
index f47e8db5..06a2279c 100644
--- a/include/sway/tree/arrange.h
+++ b/include/sway/tree/arrange.h
@@ -1,16 +1,19 @@
1#ifndef _SWAY_ARRANGE_H 1#ifndef _SWAY_ARRANGE_H
2#define _SWAY_ARRANGE_H 2#define _SWAY_ARRANGE_H
3 3
4struct sway_output;
5struct sway_workspace;
4struct sway_container; 6struct sway_container;
7struct sway_node;
5 8
6void arrange_container(struct sway_container *container); 9void arrange_container(struct sway_container *container);
7 10
8void arrange_workspace(struct sway_container *workspace); 11void arrange_workspace(struct sway_workspace *workspace);
9 12
10void arrange_output(struct sway_container *output); 13void arrange_output(struct sway_output *output);
11 14
12void arrange_root(void); 15void arrange_root(void);
13 16
14void arrange_windows(struct sway_container *container); 17void arrange_node(struct sway_node *node);
15 18
16#endif 19#endif
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index e4071cfe..c51425c9 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -5,8 +5,7 @@
5#include <wlr/types/wlr_box.h> 5#include <wlr/types/wlr_box.h>
6#include <wlr/types/wlr_surface.h> 6#include <wlr/types/wlr_surface.h>
7#include "list.h" 7#include "list.h"
8 8#include "sway/tree/node.h"
9extern struct sway_container root_container;
10 9
11struct sway_view; 10struct sway_view;
12struct sway_seat; 11struct sway_seat;
@@ -17,23 +16,6 @@ struct sway_seat;
17#define TITLEBAR_H_PADDING 3 16#define TITLEBAR_H_PADDING 3
18#define TITLEBAR_V_PADDING 4 17#define TITLEBAR_V_PADDING 4
19 18
20/**
21 * Different kinds of containers.
22 *
23 * This enum is in order. A container will never be inside of a container below
24 * it on this list.
25 */
26enum sway_container_type {
27 C_ROOT,
28 C_OUTPUT,
29 C_WORKSPACE,
30 C_CONTAINER,
31 C_VIEW,
32
33 // Keep last
34 C_TYPES,
35};
36
37enum sway_container_layout { 19enum sway_container_layout {
38 L_NONE, 20 L_NONE,
39 L_HORIZ, 21 L_HORIZ,
@@ -57,18 +39,14 @@ enum movement_direction;
57enum wlr_direction; 39enum wlr_direction;
58 40
59struct sway_container_state { 41struct sway_container_state {
60 // Container/swayc properties 42 // Container properties
61 enum sway_container_layout layout; 43 enum sway_container_layout layout;
62 double swayc_x, swayc_y; 44 double con_x, con_y;
63 double swayc_width, swayc_height; 45 double con_width, con_height;
64 46
65 bool is_fullscreen; 47 bool is_fullscreen;
66 48
67 bool has_gaps; 49 struct sway_workspace *workspace;
68 double current_gaps;
69 double gaps_inner;
70 double gaps_outer;
71
72 struct sway_container *parent; 50 struct sway_container *parent;
73 list_t *children; 51 list_t *children;
74 52
@@ -86,35 +64,19 @@ struct sway_container_state {
86 bool border_left; 64 bool border_left;
87 bool border_right; 65 bool border_right;
88 bool using_csd; 66 bool using_csd;
89
90 // Workspace properties
91 struct sway_container *ws_fullscreen;
92 list_t *ws_floating;
93}; 67};
94 68
95struct sway_container { 69struct sway_container {
96 union { 70 struct sway_node node;
97 // TODO: Encapsulate state for other node types as well like C_CONTAINER 71 struct sway_view *view;
98 struct sway_root *sway_root;
99 struct sway_output *sway_output;
100 struct sway_workspace *sway_workspace;
101 struct sway_view *sway_view;
102 };
103
104 /**
105 * A unique ID to identify this container. Primarily used in the
106 * get_tree JSON output.
107 */
108 size_t id;
109 72
110 // The pending state is the main container properties, and the current state is in the below struct. 73 // The pending state is the main container properties, and the current state is in the below struct.
111 // This means most places of the code can refer to the main variables (pending state) and it'll just work. 74 // This means most places of the code can refer to the main variables (pending state) and it'll just work.
112 struct sway_container_state current; 75 struct sway_container_state current;
113 76
114 char *name; // The view's title (unformatted) 77 char *title; // The view's title (unformatted)
115 char *formatted_title; // The title displayed in the title bar 78 char *formatted_title; // The title displayed in the title bar
116 79
117 enum sway_container_type type;
118 enum sway_container_layout layout; 80 enum sway_container_layout layout;
119 enum sway_container_layout prev_split_layout; 81 enum sway_container_layout prev_split_layout;
120 82
@@ -132,14 +94,13 @@ struct sway_container {
132 94
133 // The gaps currently applied to the container. 95 // The gaps currently applied to the container.
134 double current_gaps; 96 double current_gaps;
135
136 bool has_gaps; 97 bool has_gaps;
137 double gaps_inner; 98 double gaps_inner;
138 double gaps_outer; 99 double gaps_outer;
139 100
140 list_t *children; 101 struct sway_workspace *workspace; // NULL when hidden in the scratchpad
141 102 struct sway_container *parent; // NULL if container in root of workspace
142 struct sway_container *parent; 103 list_t *children; // struct sway_container
143 104
144 // Outputs currently being intersected 105 // Outputs currently being intersected
145 list_t *outputs; // struct sway_output 106 list_t *outputs; // struct sway_output
@@ -157,42 +118,17 @@ struct sway_container {
157 struct wlr_texture *title_urgent; 118 struct wlr_texture *title_urgent;
158 size_t title_height; 119 size_t title_height;
159 120
160 // The number of transactions which reference this container.
161 size_t ntxnrefs;
162
163 // If this container is a view and is waiting for the client to respond to a
164 // configure then this will be populated, otherwise NULL.
165 struct sway_transaction_instruction *instruction;
166
167 bool destroying;
168
169 // If true, indicates that the container has pending state that differs from
170 // the current.
171 bool dirty;
172
173 struct { 121 struct {
174 struct wl_signal destroy; 122 struct wl_signal destroy;
175 } events; 123 } events;
176}; 124};
177 125
178struct sway_container *container_create(enum sway_container_type type); 126struct sway_container *container_create(struct sway_view *view);
179
180const char *container_type_to_str(enum sway_container_type type);
181
182/*
183 * Create a new view container. A view can be a child of a workspace container
184 * or a container container and are rendered in the order and structure of
185 * how they are attached to the tree.
186 */
187struct sway_container *container_view_create(
188 struct sway_container *sibling, struct sway_view *sway_view);
189 127
190void container_destroy(struct sway_container *con); 128void container_destroy(struct sway_container *con);
191 129
192void container_begin_destroy(struct sway_container *con); 130void container_begin_destroy(struct sway_container *con);
193 131
194struct sway_container *container_close(struct sway_container *container);
195
196/** 132/**
197 * Search a container's descendants a container based on test criteria. Returns 133 * Search a container's descendants a container based on test criteria. Returns
198 * the first container that passes the test. 134 * the first container that passes the test.
@@ -201,22 +137,16 @@ struct sway_container *container_find_child(struct sway_container *container,
201 bool (*test)(struct sway_container *view, void *data), void *data); 137 bool (*test)(struct sway_container *view, void *data), void *data);
202 138
203/** 139/**
204 * Finds a parent container with the given struct sway_containerype.
205 */
206struct sway_container *container_parent(struct sway_container *container,
207 enum sway_container_type type);
208
209/**
210 * Find a container at the given coordinates. Returns the the surface and 140 * Find a container at the given coordinates. Returns the the surface and
211 * surface-local coordinates of the given layout coordinates if the container 141 * surface-local coordinates of the given layout coordinates if the container
212 * is a view and the view contains a surface at those coordinates. 142 * is a view and the view contains a surface at those coordinates.
213 */ 143 */
214struct sway_container *container_at(struct sway_container *workspace, 144struct sway_container *container_at(struct sway_workspace *workspace,
215 double lx, double ly, struct wlr_surface **surface, 145 double lx, double ly, struct wlr_surface **surface,
216 double *sx, double *sy); 146 double *sx, double *sy);
217 147
218struct sway_container *tiling_container_at( 148struct sway_container *tiling_container_at(
219 struct sway_container *con, double lx, double ly, 149 struct sway_node *parent, double lx, double ly,
220 struct wlr_surface **surface, double *sx, double *sy); 150 struct wlr_surface **surface, double *sx, double *sy);
221 151
222void container_for_each_child(struct sway_container *container, 152void container_for_each_child(struct sway_container *container,
@@ -228,16 +158,11 @@ void container_for_each_child(struct sway_container *container,
228bool container_has_ancestor(struct sway_container *container, 158bool container_has_ancestor(struct sway_container *container,
229 struct sway_container *ancestor); 159 struct sway_container *ancestor);
230 160
231int container_count_descendants_of_type(struct sway_container *con,
232 enum sway_container_type type);
233
234void container_create_notify(struct sway_container *container);
235
236void container_update_textures_recursive(struct sway_container *con); 161void container_update_textures_recursive(struct sway_container *con);
237 162
238void container_damage_whole(struct sway_container *container); 163void container_damage_whole(struct sway_container *container);
239 164
240struct sway_container *container_reap_empty(struct sway_container *con); 165void container_reap_empty(struct sway_container *con);
241 166
242struct sway_container *container_flatten(struct sway_container *container); 167struct sway_container *container_flatten(struct sway_container *container);
243 168
@@ -248,11 +173,10 @@ void container_update_title_textures(struct sway_container *container);
248 */ 173 */
249void container_calculate_title_height(struct sway_container *container); 174void container_calculate_title_height(struct sway_container *container);
250 175
251/** 176size_t container_build_representation(enum sway_container_layout layout,
252 * Notify a container that a tree modification has changed in its children, 177 list_t *children, char *buffer);
253 * so the container can update its tree representation. 178
254 */ 179void container_update_representation(struct sway_container *container);
255void container_notify_subtree_changed(struct sway_container *container);
256 180
257/** 181/**
258 * Return the height of a regular title bar. 182 * Return the height of a regular title bar.
@@ -288,8 +212,7 @@ void container_floating_translate(struct sway_container *con,
288/** 212/**
289 * Choose an output for the floating container's new position. 213 * Choose an output for the floating container's new position.
290 */ 214 */
291struct sway_container *container_floating_find_output( 215struct sway_output *container_floating_find_output(struct sway_container *con);
292 struct sway_container *con);
293 216
294/** 217/**
295 * Move a floating container to a new layout-local position. 218 * Move a floating container to a new layout-local position.
@@ -302,12 +225,6 @@ void container_floating_move_to(struct sway_container *con,
302 */ 225 */
303void container_floating_move_to_center(struct sway_container *con); 226void container_floating_move_to_center(struct sway_container *con);
304 227
305/**
306 * Mark a container as dirty if it isn't already. Dirty containers will be
307 * included in the next transaction then unmarked as dirty.
308 */
309void container_set_dirty(struct sway_container *container);
310
311bool container_has_urgent_child(struct sway_container *container); 228bool container_has_urgent_child(struct sway_container *container);
312 229
313/** 230/**
@@ -342,10 +259,18 @@ void container_remove_gaps(struct sway_container *container);
342 259
343void container_add_gaps(struct sway_container *container); 260void container_add_gaps(struct sway_container *container);
344 261
262enum sway_container_layout container_parent_layout(struct sway_container *con);
263
264enum sway_container_layout container_current_parent_layout(
265 struct sway_container *con);
266
267list_t *container_get_siblings(const struct sway_container *container);
268
345int container_sibling_index(const struct sway_container *child); 269int container_sibling_index(const struct sway_container *child);
346 270
347void container_handle_fullscreen_reparent(struct sway_container *con, 271list_t *container_get_current_siblings(struct sway_container *container);
348 struct sway_container *old_parent); 272
273void container_handle_fullscreen_reparent(struct sway_container *con);
349 274
350void container_add_child(struct sway_container *parent, 275void container_add_child(struct sway_container *parent,
351 struct sway_container *child); 276 struct sway_container *child);
@@ -353,19 +278,16 @@ void container_add_child(struct sway_container *parent,
353void container_insert_child(struct sway_container *parent, 278void container_insert_child(struct sway_container *parent,
354 struct sway_container *child, int i); 279 struct sway_container *child, int i);
355 280
356struct sway_container *container_add_sibling(struct sway_container *parent, 281void container_add_sibling(struct sway_container *parent,
357 struct sway_container *child); 282 struct sway_container *child, int offset);
358 283
359struct sway_container *container_remove_child(struct sway_container *child); 284void container_detach(struct sway_container *child);
360 285
361struct sway_container *container_replace_child(struct sway_container *child, 286void container_replace(struct sway_container *container,
362 struct sway_container *new_child); 287 struct sway_container *replacement);
363 288
364bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out); 289bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out);
365 290
366enum sway_container_layout container_get_default_layout(
367 struct sway_container *con);
368
369struct sway_container *container_split(struct sway_container *child, 291struct sway_container *container_split(struct sway_container *child,
370 enum sway_container_layout layout); 292 enum sway_container_layout layout);
371 293
diff --git a/include/sway/tree/node.h b/include/sway/tree/node.h
new file mode 100644
index 00000000..5b8c1909
--- /dev/null
+++ b/include/sway/tree/node.h
@@ -0,0 +1,74 @@
1#ifndef _SWAY_NODE_H
2#define _SWAY_NODE_H
3#include <stdbool.h>
4#include "list.h"
5
6struct sway_root;
7struct sway_output;
8struct sway_workspace;
9struct sway_container;
10struct sway_transaction_instruction;
11struct wlr_box;
12
13enum sway_node_type {
14 N_ROOT,
15 N_OUTPUT,
16 N_WORKSPACE,
17 N_CONTAINER,
18};
19
20struct sway_node {
21 enum sway_node_type type;
22 union {
23 struct sway_root *sway_root;
24 struct sway_output *sway_output;
25 struct sway_workspace *sway_workspace;
26 struct sway_container *sway_container;
27 };
28
29 /**
30 * A unique ID to identify this node.
31 * Primarily used in the get_tree JSON output.
32 */
33 size_t id;
34
35 struct sway_transaction_instruction *instruction;
36 size_t ntxnrefs;
37 bool destroying;
38
39 // If true, indicates that the container has pending state that differs from
40 // the current.
41 bool dirty;
42
43 struct {
44 struct wl_signal destroy;
45 } events;
46};
47
48void node_init(struct sway_node *node, enum sway_node_type type, void *thing);
49
50const char *node_type_to_str(enum sway_node_type type);
51
52/**
53 * Mark a node as dirty if it isn't already. Dirty nodes will be included in the
54 * next transaction then unmarked as dirty.
55 */
56void node_set_dirty(struct sway_node *node);
57
58bool node_is_view(struct sway_node *node);
59
60char *node_get_name(struct sway_node *node);
61
62void node_get_box(struct sway_node *node, struct wlr_box *box);
63
64struct sway_output *node_get_output(struct sway_node *node);
65
66enum sway_container_layout node_get_layout(struct sway_node *node);
67
68struct sway_node *node_get_parent(struct sway_node *node);
69
70list_t *node_get_children(struct sway_node *node);
71
72bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor);
73
74#endif
diff --git a/include/sway/tree/root.h b/include/sway/tree/root.h
index ec6516c9..a2d464f9 100644
--- a/include/sway/tree/root.h
+++ b/include/sway/tree/root.h
@@ -5,12 +5,14 @@
5#include <wlr/types/wlr_output_layout.h> 5#include <wlr/types/wlr_output_layout.h>
6#include <wlr/render/wlr_texture.h> 6#include <wlr/render/wlr_texture.h>
7#include "sway/tree/container.h" 7#include "sway/tree/container.h"
8#include "sway/tree/node.h"
8#include "config.h" 9#include "config.h"
9#include "list.h" 10#include "list.h"
10 11
11extern struct sway_container root_container; 12extern struct sway_root *root;
12 13
13struct sway_root { 14struct sway_root {
15 struct sway_node node;
14 struct wlr_output_layout *output_layout; 16 struct wlr_output_layout *output_layout;
15 17
16 struct wl_listener output_layout_change; 18 struct wl_listener output_layout_change;
@@ -24,17 +26,21 @@ struct sway_root {
24 // Includes disabled outputs 26 // Includes disabled outputs
25 struct wl_list all_outputs; // sway_output::link 27 struct wl_list all_outputs; // sway_output::link
26 28
29 double x, y;
30 double width, height;
31
32 list_t *outputs; // struct sway_output
27 list_t *scratchpad; // struct sway_container 33 list_t *scratchpad; // struct sway_container
28 list_t *saved_workspaces; // For when there's no connected outputs 34 list_t *saved_workspaces; // For when there's no connected outputs
29 35
30 struct { 36 struct {
31 struct wl_signal new_container; 37 struct wl_signal new_node;
32 } events; 38 } events;
33}; 39};
34 40
35void root_create(void); 41struct sway_root *root_create(void);
36 42
37void root_destroy(void); 43void root_destroy(struct sway_root *root);
38 44
39/** 45/**
40 * Move a container to the scratchpad. 46 * Move a container to the scratchpad.
@@ -56,23 +62,25 @@ void root_scratchpad_show(struct sway_container *con);
56 */ 62 */
57void root_scratchpad_hide(struct sway_container *con); 63void root_scratchpad_hide(struct sway_container *con);
58 64
59struct sway_container *root_workspace_for_pid(pid_t pid); 65struct sway_workspace *root_workspace_for_pid(pid_t pid);
60 66
61void root_record_workspace_pid(pid_t pid); 67void root_record_workspace_pid(pid_t pid);
62 68
63void root_for_each_workspace(void (*f)(struct sway_container *con, void *data), 69void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data),
64 void *data); 70 void *data);
65 71
66void root_for_each_container(void (*f)(struct sway_container *con, void *data), 72void root_for_each_container(void (*f)(struct sway_container *con, void *data),
67 void *data); 73 void *data);
68 74
69struct sway_container *root_find_output( 75struct sway_output *root_find_output(
70 bool (*test)(struct sway_container *con, void *data), void *data); 76 bool (*test)(struct sway_output *output, void *data), void *data);
71 77
72struct sway_container *root_find_workspace( 78struct sway_workspace *root_find_workspace(
73 bool (*test)(struct sway_container *con, void *data), void *data); 79 bool (*test)(struct sway_workspace *ws, void *data), void *data);
74 80
75struct sway_container *root_find_container( 81struct sway_container *root_find_container(
76 bool (*test)(struct sway_container *con, void *data), void *data); 82 bool (*test)(struct sway_container *con, void *data), void *data);
77 83
84void root_get_box(struct sway_root *root, struct wlr_box *box);
85
78#endif 86#endif
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 30d3e742..439dc1bf 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -58,7 +58,7 @@ struct sway_view {
58 enum sway_view_type type; 58 enum sway_view_type type;
59 const struct sway_view_impl *impl; 59 const struct sway_view_impl *impl;
60 60
61 struct sway_container *swayc; // NULL for unmapped views 61 struct sway_container *container; // NULL if unmapped and transactions finished
62 struct wlr_surface *surface; // NULL for unmapped views 62 struct wlr_surface *surface; // NULL for unmapped views
63 63
64 // Geometry of the view itself (excludes borders) in layout coordinates 64 // Geometry of the view itself (excludes borders) in layout coordinates
@@ -254,7 +254,7 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
254 int height); 254 int height);
255 255
256/** 256/**
257 * Configure the view's position and size based on the swayc's position and 257 * Configure the view's position and size based on the container's position and
258 * size, taking borders into consideration. 258 * size, taking borders into consideration.
259 */ 259 */
260void view_autoconfigure(struct sway_view *view); 260void view_autoconfigure(struct sway_view *view);
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h
index 04325919..af9a071a 100644
--- a/include/sway/tree/workspace.h
+++ b/include/sway/tree/workspace.h
@@ -3,66 +3,98 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "sway/tree/container.h" 5#include "sway/tree/container.h"
6#include "sway/tree/node.h"
6 7
7struct sway_view; 8struct sway_view;
8 9
10struct sway_workspace_state {
11 struct sway_container *fullscreen;
12 double x, y;
13 int width, height;
14 enum sway_container_layout layout;
15 struct sway_output *output;
16 list_t *floating;
17 list_t *tiling;
18
19 struct sway_container *focused_inactive_child;
20 bool focused;
21};
22
9struct sway_workspace { 23struct sway_workspace {
10 struct sway_container *swayc; 24 struct sway_node node;
11 struct sway_container *fullscreen; 25 struct sway_container *fullscreen;
12 list_t *floating; // struct sway_container 26
27 char *name;
28 char *representation;
29
30 double x, y;
31 int width, height;
32 enum sway_container_layout layout;
33 enum sway_container_layout prev_split_layout;
34
35 double current_gaps;
36 bool has_gaps;
37 double gaps_inner;
38 double gaps_outer;
39
40 struct sway_output *output; // NULL if no outputs are connected
41 list_t *floating; // struct sway_container
42 list_t *tiling; // struct sway_container
13 list_t *output_priority; 43 list_t *output_priority;
14 bool urgent; 44 bool urgent;
45
46 struct sway_workspace_state current;
15}; 47};
16 48
17extern char *prev_workspace_name; 49extern char *prev_workspace_name;
18 50
19struct sway_container *workspace_get_initial_output(const char *name); 51struct sway_output *workspace_get_initial_output(const char *name);
20 52
21struct sway_container *workspace_create(struct sway_container *output, 53struct sway_workspace *workspace_create(struct sway_output *output,
22 const char *name); 54 const char *name);
23 55
24void workspace_destroy(struct sway_container *workspace); 56void workspace_destroy(struct sway_workspace *workspace);
25 57
26void workspace_begin_destroy(struct sway_container *workspace); 58void workspace_begin_destroy(struct sway_workspace *workspace);
27 59
28void workspace_consider_destroy(struct sway_container *ws); 60void workspace_consider_destroy(struct sway_workspace *ws);
29 61
30char *workspace_next_name(const char *output_name); 62char *workspace_next_name(const char *output_name);
31 63
32bool workspace_switch(struct sway_container *workspace, 64bool workspace_switch(struct sway_workspace *workspace,
33 bool no_auto_back_and_forth); 65 bool no_auto_back_and_forth);
34 66
35struct sway_container *workspace_by_number(const char* name); 67struct sway_workspace *workspace_by_number(const char* name);
36 68
37struct sway_container *workspace_by_name(const char*); 69struct sway_workspace *workspace_by_name(const char*);
38 70
39struct sway_container *workspace_output_next(struct sway_container *current); 71struct sway_workspace *workspace_output_next(struct sway_workspace *current);
40 72
41struct sway_container *workspace_next(struct sway_container *current); 73struct sway_workspace *workspace_next(struct sway_workspace *current);
42 74
43struct sway_container *workspace_output_prev(struct sway_container *current); 75struct sway_workspace *workspace_output_prev(struct sway_workspace *current);
44 76
45struct sway_container *workspace_prev(struct sway_container *current); 77struct sway_workspace *workspace_prev(struct sway_workspace *current);
46 78
47bool workspace_is_visible(struct sway_container *ws); 79bool workspace_is_visible(struct sway_workspace *ws);
48 80
49bool workspace_is_empty(struct sway_container *ws); 81bool workspace_is_empty(struct sway_workspace *ws);
50 82
51void workspace_output_raise_priority(struct sway_container *workspace, 83void workspace_output_raise_priority(struct sway_workspace *workspace,
52 struct sway_container *old_output, struct sway_container *new_output); 84 struct sway_output *old_output, struct sway_output *new_output);
53 85
54void workspace_output_add_priority(struct sway_container *workspace, 86void workspace_output_add_priority(struct sway_workspace *workspace,
55 struct sway_container *output); 87 struct sway_output *output);
56 88
57struct sway_container *workspace_output_get_highest_available( 89struct sway_output *workspace_output_get_highest_available(
58 struct sway_container *ws, struct sway_container *exclude); 90 struct sway_workspace *ws, struct sway_output *exclude);
59 91
60void workspace_detect_urgent(struct sway_container *workspace); 92void workspace_detect_urgent(struct sway_workspace *workspace);
61 93
62void workspace_for_each_container(struct sway_container *ws, 94void workspace_for_each_container(struct sway_workspace *ws,
63 void (*f)(struct sway_container *con, void *data), void *data); 95 void (*f)(struct sway_container *con, void *data), void *data);
64 96
65struct sway_container *workspace_find_container(struct sway_container *ws, 97struct sway_container *workspace_find_container(struct sway_workspace *ws,
66 bool (*test)(struct sway_container *con, void *data), void *data); 98 bool (*test)(struct sway_container *con, void *data), void *data);
67 99
68/** 100/**
@@ -70,13 +102,28 @@ struct sway_container *workspace_find_container(struct sway_container *ws,
70 * The new container will be the only direct tiling child of the workspace. 102 * The new container will be the only direct tiling child of the workspace.
71 * The new container is returned. 103 * The new container is returned.
72 */ 104 */
73struct sway_container *workspace_wrap_children(struct sway_container *ws); 105struct sway_container *workspace_wrap_children(struct sway_workspace *ws);
74 106
75void workspace_add_floating(struct sway_container *workspace, 107void workspace_detach(struct sway_workspace *workspace);
108
109void workspace_add_tiling(struct sway_workspace *workspace,
110 struct sway_container *con);
111
112void workspace_add_floating(struct sway_workspace *workspace,
76 struct sway_container *con); 113 struct sway_container *con);
77 114
78void workspace_remove_gaps(struct sway_container *ws); 115void workspace_insert_tiling(struct sway_workspace *workspace,
116 struct sway_container *con, int index);
117
118void workspace_remove_gaps(struct sway_workspace *ws);
119
120void workspace_add_gaps(struct sway_workspace *ws);
121
122struct sway_container *workspace_split(struct sway_workspace *workspace,
123 enum sway_container_layout layout);
124
125void workspace_update_representation(struct sway_workspace *ws);
79 126
80void workspace_add_gaps(struct sway_container *ws); 127void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box);
81 128
82#endif 129#endif