summaryrefslogtreecommitdiffstats
path: root/include/sway
diff options
context:
space:
mode:
Diffstat (limited to 'include/sway')
-rw-r--r--include/sway/desktop/transaction.h60
-rw-r--r--include/sway/output.h2
-rw-r--r--include/sway/server.h7
-rw-r--r--include/sway/tree/arrange.h30
-rw-r--r--include/sway/tree/container.h48
-rw-r--r--include/sway/tree/view.h29
6 files changed, 151 insertions, 25 deletions
diff --git a/include/sway/desktop/transaction.h b/include/sway/desktop/transaction.h
new file mode 100644
index 00000000..d6adc609
--- /dev/null
+++ b/include/sway/desktop/transaction.h
@@ -0,0 +1,60 @@
1#ifndef _SWAY_TRANSACTION_H
2#define _SWAY_TRANSACTION_H
3#include <wlr/render/wlr_texture.h>
4#include "sway/tree/container.h"
5
6/**
7 * Transactions enable us to perform atomic layout updates.
8 *
9 * When we want to make adjustments to the layout, we create a transaction.
10 * A transaction contains a list of affected containers and their new state.
11 * A state might contain a new size, or new border settings, or new parent/child
12 * relationships.
13 *
14 * Calling transaction_commit() makes sway notify of all the affected clients
15 * with their new sizes. We then wait for all the views to respond with their
16 * new surface sizes. When all are ready, or when a timeout has passed, we apply
17 * the updates all at the same time.
18 */
19
20struct sway_transaction;
21
22/**
23 * Create a new transaction.
24 */
25struct sway_transaction *transaction_create(void);
26
27/**
28 * Add a container's pending state to the transaction.
29 */
30void transaction_add_container(struct sway_transaction *transaction,
31 struct sway_container *container);
32
33/**
34 * Add a box to be damaged when the transaction is applied.
35 * The box should be in layout coordinates.
36 */
37void transaction_add_damage(struct sway_transaction *transaction,
38 struct wlr_box *box);
39
40/**
41 * Submit a transaction to the client views for configuration.
42 */
43void transaction_commit(struct sway_transaction *transaction);
44
45/**
46 * Notify the transaction system that a view is ready for the new layout.
47 *
48 * When all views in the transaction are ready, the layout will be applied.
49 */
50void transaction_notify_view_ready(struct sway_view *view, uint32_t serial);
51
52/**
53 * Get the texture that should be rendered for a view.
54 *
55 * In most cases this will return the normal live texture for a view, but if the
56 * view is in a transaction then it'll return a saved texture.
57 */
58struct wlr_texture *transaction_get_texture(struct sway_view *view);
59
60#endif
diff --git a/include/sway/output.h b/include/sway/output.h
index 70f746dc..e6ca0d02 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -42,6 +42,8 @@ void output_damage_surface(struct sway_output *output, double ox, double oy,
42void output_damage_from_view(struct sway_output *output, 42void output_damage_from_view(struct sway_output *output,
43 struct sway_view *view); 43 struct sway_view *view);
44 44
45void output_damage_box(struct sway_output *output, struct wlr_box *box);
46
45void output_damage_whole_container(struct sway_output *output, 47void output_damage_whole_container(struct sway_output *output,
46 struct sway_container *con); 48 struct sway_container *con);
47 49
diff --git a/include/sway/server.h b/include/sway/server.h
index 963d4dc1..b07e86a7 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -12,6 +12,7 @@
12#include <wlr/render/wlr_renderer.h> 12#include <wlr/render/wlr_renderer.h>
13// TODO WLR: make Xwayland optional 13// TODO WLR: make Xwayland optional
14#include <wlr/xwayland.h> 14#include <wlr/xwayland.h>
15#include "list.h"
15 16
16struct sway_server { 17struct sway_server {
17 struct wl_display *wl_display; 18 struct wl_display *wl_display;
@@ -43,6 +44,12 @@ struct sway_server {
43 44
44 struct wlr_wl_shell *wl_shell; 45 struct wlr_wl_shell *wl_shell;
45 struct wl_listener wl_shell_surface; 46 struct wl_listener wl_shell_surface;
47
48 bool terminating;
49
50 // When a view is being destroyed and is waiting for a transaction to
51 // complete it will be stored here.
52 list_t *destroying_containers;
46}; 53};
47 54
48struct sway_server server; 55struct sway_server server;
diff --git a/include/sway/tree/arrange.h b/include/sway/tree/arrange.h
index a14bc5dc..6c8c0dba 100644
--- a/include/sway/tree/arrange.h
+++ b/include/sway/tree/arrange.h
@@ -1,5 +1,6 @@
1#ifndef _SWAY_ARRANGE_H 1#ifndef _SWAY_ARRANGE_H
2#define _SWAY_ARRANGE_H 2#define _SWAY_ARRANGE_H
3#include "sway/desktop/transaction.h"
3 4
4struct sway_container; 5struct sway_container;
5 6
@@ -9,16 +10,23 @@ void remove_gaps(struct sway_container *c);
9// Add gaps around container 10// Add gaps around container
10void add_gaps(struct sway_container *c); 11void add_gaps(struct sway_container *c);
11 12
12// Determine the root container's geometry, then iterate to everything below 13/**
13void arrange_root(void); 14 * Arrange layout for all the children of the given container, and add them to
14 15 * the given transaction.
15// Determine the output's geometry, then iterate to everything below 16 *
16void arrange_output(struct sway_container *output); 17 * Use this function if you need to arrange multiple sections of the tree in one
17 18 * transaction.
18// Determine the workspace's geometry, then iterate to everything below 19 */
19void arrange_workspace(struct sway_container *workspace); 20void arrange_windows(struct sway_container *container,
20 21 struct sway_transaction *transaction);
21// Arrange layout for all the children of the given workspace/container 22
22void arrange_children_of(struct sway_container *parent); 23/**
24 * Arrange layout for the given container and commit the transaction.
25 *
26 * This function is a wrapper around arrange_windows, and handles creating and
27 * committing the transaction for you. Use this function if you're only doing
28 * one arrange operation.
29 */
30void arrange_and_commit(struct sway_container *container);
23 31
24#endif 32#endif
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index b3406bbe..7e78cbef 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -54,6 +54,37 @@ struct sway_output;
54struct sway_workspace; 54struct sway_workspace;
55struct sway_view; 55struct sway_view;
56 56
57struct sway_container_state {
58 // Container/swayc properties
59 enum sway_container_layout layout;
60 double swayc_x, swayc_y;
61 double swayc_width, swayc_height;
62
63 bool has_gaps;
64 double current_gaps;
65 double gaps_inner;
66 double gaps_outer;
67
68 struct sway_container *parent;
69 list_t *children;
70
71 // View properties
72 double view_x, view_y;
73 double view_width, view_height;
74 bool is_fullscreen;
75
76 enum sway_container_border border;
77 int border_thickness;
78 bool border_top;
79 bool border_bottom;
80 bool border_left;
81 bool border_right;
82
83 // Workspace properties
84 struct sway_view *ws_fullscreen;
85 struct sway_container *ws_floating;
86};
87
57struct sway_container { 88struct sway_container {
58 union { 89 union {
59 // TODO: Encapsulate state for other node types as well like C_CONTAINER 90 // TODO: Encapsulate state for other node types as well like C_CONTAINER
@@ -69,6 +100,10 @@ struct sway_container {
69 */ 100 */
70 size_t id; 101 size_t id;
71 102
103 // The pending state is the main container properties, and the current state is in the below struct.
104 // This means most places of the code can refer to the main variables (pending state) and it'll just work.
105 struct sway_container_state current;
106
72 char *name; // The view's title (unformatted) 107 char *name; // The view's title (unformatted)
73 char *formatted_title; // The title displayed in the title bar 108 char *formatted_title; // The title displayed in the title bar
74 109
@@ -97,8 +132,6 @@ struct sway_container {
97 132
98 struct sway_container *parent; 133 struct sway_container *parent;
99 134
100 list_t *marks; // list of char*
101
102 float alpha; 135 float alpha;
103 136
104 struct wlr_texture *title_focused; 137 struct wlr_texture *title_focused;
@@ -107,6 +140,10 @@ struct sway_container {
107 struct wlr_texture *title_urgent; 140 struct wlr_texture *title_urgent;
108 size_t title_height; 141 size_t title_height;
109 142
143 list_t *instructions; // struct sway_transaction_instruction *
144
145 bool destroying;
146
110 struct { 147 struct {
111 struct wl_signal destroy; 148 struct wl_signal destroy;
112 // Raised after the tree updates, but before arrange_windows 149 // Raised after the tree updates, but before arrange_windows
@@ -150,6 +187,8 @@ struct sway_container *workspace_create(struct sway_container *output,
150struct sway_container *container_view_create( 187struct sway_container *container_view_create(
151 struct sway_container *sibling, struct sway_view *sway_view); 188 struct sway_container *sibling, struct sway_view *sway_view);
152 189
190void container_free(struct sway_container *cont);
191
153struct sway_container *container_destroy(struct sway_container *container); 192struct sway_container *container_destroy(struct sway_container *container);
154 193
155struct sway_container *container_close(struct sway_container *container); 194struct sway_container *container_close(struct sway_container *container);
@@ -253,4 +292,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con);
253 */ 292 */
254bool container_is_floating(struct sway_container *container); 293bool container_is_floating(struct sway_container *container);
255 294
295/**
296 * Get a container's box in layout coordinates.
297 */
298struct wlr_box *container_get_box(struct sway_container *container);
299
256#endif 300#endif
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 3df38e2d..5a615b43 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -29,15 +29,15 @@ struct sway_view_impl {
29 const char *(*get_string_prop)(struct sway_view *view, 29 const char *(*get_string_prop)(struct sway_view *view,
30 enum sway_view_prop prop); 30 enum sway_view_prop prop);
31 uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop); 31 uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop);
32 void (*configure)(struct sway_view *view, double lx, double ly, int width, 32 uint32_t (*configure)(struct sway_view *view, double lx, double ly,
33 int height); 33 int width, int height);
34 void (*set_activated)(struct sway_view *view, bool activated); 34 void (*set_activated)(struct sway_view *view, bool activated);
35 void (*set_fullscreen)(struct sway_view *view, bool fullscreen); 35 void (*set_fullscreen)(struct sway_view *view, bool fullscreen);
36 bool (*wants_floating)(struct sway_view *view); 36 bool (*wants_floating)(struct sway_view *view);
37 void (*for_each_surface)(struct sway_view *view, 37 void (*for_each_surface)(struct sway_view *view,
38 wlr_surface_iterator_func_t iterator, void *user_data); 38 wlr_surface_iterator_func_t iterator, void *user_data);
39 void (*close)(struct sway_view *view); 39 void (*close)(struct sway_view *view);
40 void (*destroy)(struct sway_view *view); 40 void (*free)(struct sway_view *view);
41}; 41};
42 42
43struct sway_view { 43struct sway_view {
@@ -68,6 +68,8 @@ struct sway_view {
68 bool border_left; 68 bool border_left;
69 bool border_right; 69 bool border_right;
70 70
71 bool destroying;
72
71 list_t *executed_criteria; // struct criteria * 73 list_t *executed_criteria; // struct criteria *
72 list_t *marks; // char * 74 list_t *marks; // char *
73 75
@@ -103,8 +105,6 @@ struct sway_xdg_shell_v6_view {
103 struct wl_listener map; 105 struct wl_listener map;
104 struct wl_listener unmap; 106 struct wl_listener unmap;
105 struct wl_listener destroy; 107 struct wl_listener destroy;
106
107 int pending_width, pending_height;
108}; 108};
109 109
110struct sway_xdg_shell_view { 110struct sway_xdg_shell_view {
@@ -119,8 +119,6 @@ struct sway_xdg_shell_view {
119 struct wl_listener map; 119 struct wl_listener map;
120 struct wl_listener unmap; 120 struct wl_listener unmap;
121 struct wl_listener destroy; 121 struct wl_listener destroy;
122
123 int pending_width, pending_height;
124}; 122};
125 123
126struct sway_xwayland_view { 124struct sway_xwayland_view {
@@ -138,9 +136,6 @@ struct sway_xwayland_view {
138 struct wl_listener map; 136 struct wl_listener map;
139 struct wl_listener unmap; 137 struct wl_listener unmap;
140 struct wl_listener destroy; 138 struct wl_listener destroy;
141
142 int pending_lx, pending_ly;
143 int pending_width, pending_height;
144}; 139};
145 140
146struct sway_xwayland_unmanaged { 141struct sway_xwayland_unmanaged {
@@ -212,10 +207,15 @@ uint32_t view_get_window_type(struct sway_view *view);
212 207
213const char *view_get_shell(struct sway_view *view); 208const char *view_get_shell(struct sway_view *view);
214 209
215void view_configure(struct sway_view *view, double ox, double oy, int width, 210uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
216 int height); 211 int height);
217 212
218/** 213/**
214 * Center the view in its workspace and build the swayc decorations around it.
215 */
216void view_init_floating(struct sway_view *view);
217
218/**
219 * Configure the view's position and size based on the swayc's position and 219 * Configure the view's position and size based on the swayc's position and
220 * size, taking borders into consideration. 220 * size, taking borders into consideration.
221 */ 221 */
@@ -239,11 +239,16 @@ void view_for_each_surface(struct sway_view *view,
239void view_init(struct sway_view *view, enum sway_view_type type, 239void view_init(struct sway_view *view, enum sway_view_type type,
240 const struct sway_view_impl *impl); 240 const struct sway_view_impl *impl);
241 241
242void view_free(struct sway_view *view);
243
242void view_destroy(struct sway_view *view); 244void view_destroy(struct sway_view *view);
243 245
244void view_map(struct sway_view *view, struct wlr_surface *wlr_surface); 246void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);
245 247
246void view_unmap(struct sway_view *view); 248/**
249 * Unmap the view and return the surviving parent (after reaping).
250 */
251struct sway_container *view_unmap(struct sway_view *view);
247 252
248void view_update_position(struct sway_view *view, double lx, double ly); 253void view_update_position(struct sway_view *view, double lx, double ly);
249 254