aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/input/seat.h20
-rw-r--r--include/sway/tree/arrange.h6
-rw-r--r--include/sway/tree/container.h12
-rw-r--r--include/sway/tree/layout.h1
-rw-r--r--sway/commands.c3
-rw-r--r--sway/commands/gaps.c177
-rw-r--r--sway/commands/smart_gaps.c29
-rw-r--r--sway/desktop/output.c57
-rw-r--r--sway/desktop/transaction.c4
-rw-r--r--sway/input/cursor.c62
-rw-r--r--sway/input/seat.c98
-rw-r--r--sway/ipc-json.c7
-rw-r--r--sway/meson.build2
-rw-r--r--sway/tree/arrange.c53
-rw-r--r--sway/tree/container.c5
-rw-r--r--sway/tree/layout.c7
-rw-r--r--sway/tree/output.c5
17 files changed, 507 insertions, 41 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index 2e4da438..1f7792ba 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -21,6 +21,19 @@ struct sway_seat_container {
21 struct wl_listener destroy; 21 struct wl_listener destroy;
22}; 22};
23 23
24struct sway_drag_icon {
25 struct sway_seat *seat;
26 struct wlr_drag_icon *wlr_drag_icon;
27 struct wl_list link; // sway_root::drag_icons
28
29 double x, y; // in layout-local coordinates
30
31 struct wl_listener surface_commit;
32 struct wl_listener map;
33 struct wl_listener unmap;
34 struct wl_listener destroy;
35};
36
24struct sway_seat { 37struct sway_seat {
25 struct wlr_seat *wlr_seat; 38 struct wlr_seat *wlr_seat;
26 struct sway_cursor *cursor; 39 struct sway_cursor *cursor;
@@ -35,8 +48,13 @@ struct sway_seat {
35 // If exclusive_client is set, no other clients will receive input events 48 // If exclusive_client is set, no other clients will receive input events
36 struct wl_client *exclusive_client; 49 struct wl_client *exclusive_client;
37 50
51 // Last touch point
52 int32_t touch_id;
53 double touch_x, touch_y;
54
38 struct wl_listener focus_destroy; 55 struct wl_listener focus_destroy;
39 struct wl_listener new_container; 56 struct wl_listener new_container;
57 struct wl_listener new_drag_icon;
40 58
41 struct wl_list devices; // sway_seat_device::link 59 struct wl_list devices; // sway_seat_device::link
42 60
@@ -114,4 +132,6 @@ struct seat_config *seat_get_config(struct sway_seat *seat);
114 132
115bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface); 133bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface);
116 134
135void drag_icon_update_position(struct sway_drag_icon *icon);
136
117#endif 137#endif
diff --git a/include/sway/tree/arrange.h b/include/sway/tree/arrange.h
index 897a9392..6c8c0dba 100644
--- a/include/sway/tree/arrange.h
+++ b/include/sway/tree/arrange.h
@@ -4,6 +4,12 @@
4 4
5struct sway_container; 5struct sway_container;
6 6
7// Remove gaps around container
8void remove_gaps(struct sway_container *c);
9
10// Add gaps around container
11void add_gaps(struct sway_container *c);
12
7/** 13/**
8 * Arrange layout for all the children of the given container, and add them to 14 * Arrange layout for all the children of the given container, and add them to
9 * the given transaction. 15 * the given transaction.
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index a8efd893..f4e978ea 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -60,6 +60,11 @@ struct sway_container_state {
60 double swayc_x, swayc_y; 60 double swayc_x, swayc_y;
61 double swayc_width, swayc_height; 61 double swayc_width, swayc_height;
62 62
63 bool has_gaps;
64 double current_gaps;
65 double gaps_inner;
66 double gaps_outer;
67
63 //struct sway_container *parent; 68 //struct sway_container *parent;
64 //list_t *children; 69 //list_t *children;
65 70
@@ -112,6 +117,13 @@ struct sway_container {
112 double saved_x, saved_y; 117 double saved_x, saved_y;
113 double saved_width, saved_height; 118 double saved_width, saved_height;
114 119
120 // The gaps currently applied to the container.
121 double current_gaps;
122
123 bool has_gaps;
124 double gaps_inner;
125 double gaps_outer;
126
115 list_t *children; 127 list_t *children;
116 128
117 struct sway_container *parent; 129 struct sway_container *parent;
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h
index cd131056..ba265623 100644
--- a/include/sway/tree/layout.h
+++ b/include/sway/tree/layout.h
@@ -28,6 +28,7 @@ struct sway_root {
28 struct wl_listener output_layout_change; 28 struct wl_listener output_layout_change;
29 29
30 struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link 30 struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
31 struct wl_list drag_icons; // sway_drag_icon::link
31 32
32 struct wlr_texture *debug_tree; 33 struct wlr_texture *debug_tree;
33 34
diff --git a/sway/commands.c b/sway/commands.c
index 1523fdd1..5b20857a 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -105,6 +105,8 @@ static struct cmd_handler handlers[] = {
105 { "font", cmd_font }, 105 { "font", cmd_font },
106 { "for_window", cmd_for_window }, 106 { "for_window", cmd_for_window },
107 { "force_focus_wrapping", cmd_force_focus_wrapping }, 107 { "force_focus_wrapping", cmd_force_focus_wrapping },
108 { "fullscreen", cmd_fullscreen },
109 { "gaps", cmd_gaps },
108 { "hide_edge_borders", cmd_hide_edge_borders }, 110 { "hide_edge_borders", cmd_hide_edge_borders },
109 { "include", cmd_include }, 111 { "include", cmd_include },
110 { "input", cmd_input }, 112 { "input", cmd_input },
@@ -114,6 +116,7 @@ static struct cmd_handler handlers[] = {
114 { "seat", cmd_seat }, 116 { "seat", cmd_seat },
115 { "set", cmd_set }, 117 { "set", cmd_set },
116 { "show_marks", cmd_show_marks }, 118 { "show_marks", cmd_show_marks },
119 { "smart_gaps", cmd_smart_gaps },
117 { "workspace", cmd_workspace }, 120 { "workspace", cmd_workspace },
118 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, 121 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
119}; 122};
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c
new file mode 100644
index 00000000..801fb179
--- /dev/null
+++ b/sway/commands/gaps.c
@@ -0,0 +1,177 @@
1#include <string.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4#include "sway/tree/arrange.h"
5#include "log.h"
6#include "stringop.h"
7#include <math.h>
8
9enum gaps_op {
10 GAPS_OP_SET,
11 GAPS_OP_ADD,
12 GAPS_OP_SUBTRACT
13};
14
15enum gaps_scope {
16 GAPS_SCOPE_ALL,
17 GAPS_SCOPE_WORKSPACE,
18 GAPS_SCOPE_CURRENT
19};
20
21struct cmd_results *cmd_gaps(int argc, char **argv) {
22 struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1);
23 if (error) {
24 return error;
25 }
26
27 if (strcmp(argv[0], "edge_gaps") == 0) {
28 if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {
29 return error;
30 }
31
32 if (strcmp(argv[1], "on") == 0) {
33 config->edge_gaps = true;
34 } else if (strcmp(argv[1], "off") == 0) {
35 config->edge_gaps = false;
36 } else if (strcmp(argv[1], "toggle") == 0) {
37 if (!config->active) {
38 return cmd_results_new(CMD_INVALID, "gaps",
39 "Cannot toggle gaps while not running.");
40 }
41 config->edge_gaps = !config->edge_gaps;
42 } else {
43 return cmd_results_new(CMD_INVALID, "gaps",
44 "gaps edge_gaps on|off|toggle");
45 }
46 arrange_and_commit(&root_container);
47 } else {
48 int amount_idx = 0; // the current index in argv
49 enum gaps_op op = GAPS_OP_SET;
50 enum gaps_scope scope = GAPS_SCOPE_ALL;
51 bool inner = true;
52
53 if (strcmp(argv[0], "inner") == 0) {
54 amount_idx++;
55 inner = true;
56 } else if (strcmp(argv[0], "outer") == 0) {
57 amount_idx++;
58 inner = false;
59 }
60
61 // If one of the long variants of the gaps command is used
62 // (which starts with inner|outer) check the number of args
63 if (amount_idx > 0) { // if we've seen inner|outer
64 if (argc > 2) { // check the longest variant
65 error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4);
66 if (error) {
67 return error;
68 }
69 } else { // check the next longest format
70 error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2);
71 if (error) {
72 return error;
73 }
74 }
75 } else {
76 error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 1);
77 if (error) {
78 return error;
79 }
80 }
81
82 if (argc == 4) {
83 // Long format: all|workspace|current.
84 if (strcmp(argv[amount_idx], "all") == 0) {
85 amount_idx++;
86 scope = GAPS_SCOPE_ALL;
87 } else if (strcmp(argv[amount_idx], "workspace") == 0) {
88 amount_idx++;
89 scope = GAPS_SCOPE_WORKSPACE;
90 } else if (strcmp(argv[amount_idx], "current") == 0) {
91 amount_idx++;
92 scope = GAPS_SCOPE_CURRENT;
93 }
94
95 // Long format: set|plus|minus
96 if (strcmp(argv[amount_idx], "set") == 0) {
97 amount_idx++;
98 op = GAPS_OP_SET;
99 } else if (strcmp(argv[amount_idx], "plus") == 0) {
100 amount_idx++;
101 op = GAPS_OP_ADD;
102 } else if (strcmp(argv[amount_idx], "minus") == 0) {
103 amount_idx++;
104 op = GAPS_OP_SUBTRACT;
105 }
106 }
107
108 char *end;
109 double val = strtod(argv[amount_idx], &end);
110
111 if (strlen(end) && val == 0.0) { // invalid <amount>
112 // guess which variant of the command was attempted
113 if (argc == 1) {
114 return cmd_results_new(CMD_INVALID, "gaps", "gaps <amount>");
115 }
116 if (argc == 2) {
117 return cmd_results_new(CMD_INVALID, "gaps",
118 "gaps inner|outer <amount>");
119 }
120 return cmd_results_new(CMD_INVALID, "gaps",
121 "gaps inner|outer all|workspace|current set|plus|minus <amount>");
122 }
123
124 if (amount_idx == 0) { // gaps <amount>
125 config->gaps_inner = val;
126 config->gaps_outer = val;
127 arrange_and_commit(&root_container);
128 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
129 }
130 // Other variants. The middle-length variant (gaps inner|outer <amount>)
131 // just defaults the scope to "all" and defaults the op to "set".
132
133 double total;
134 switch (op) {
135 case GAPS_OP_SUBTRACT: {
136 total = (inner ? config->gaps_inner : config->gaps_outer) - val;
137 if (total < 0) {
138 total = 0;
139 }
140 break;
141 }
142 case GAPS_OP_ADD: {
143 total = (inner ? config->gaps_inner : config->gaps_outer) + val;
144 break;
145 }
146 case GAPS_OP_SET: {
147 total = val;
148 break;
149 }
150 }
151
152 if (scope == GAPS_SCOPE_ALL) {
153 if (inner) {
154 config->gaps_inner = total;
155 } else {
156 config->gaps_outer = total;
157 }
158 arrange_and_commit(&root_container);
159 } else {
160 struct sway_container *c =
161 config->handler_context.current_container;
162 if (scope == GAPS_SCOPE_WORKSPACE && c->type != C_WORKSPACE) {
163 c = container_parent(c, C_WORKSPACE);
164 }
165 c->has_gaps = true;
166 if (inner) {
167 c->gaps_inner = total;
168 } else {
169 c->gaps_outer = total;
170 }
171
172 arrange_and_commit(c->parent ? c->parent : &root_container);
173 }
174 }
175
176 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
177}
diff --git a/sway/commands/smart_gaps.c b/sway/commands/smart_gaps.c
new file mode 100644
index 00000000..f687e78e
--- /dev/null
+++ b/sway/commands/smart_gaps.c
@@ -0,0 +1,29 @@
1#include <string.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4#include "sway/tree/arrange.h"
5#include "sway/tree/view.h"
6#include "sway/tree/container.h"
7#include "log.h"
8#include "stringop.h"
9
10struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
11 struct cmd_results *error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1);
12
13 if (error) {
14 return error;
15 }
16
17 if (strcmp(argv[0], "on") == 0) {
18 config->smart_gaps = true;
19 } else if (strcmp(argv[0], "off") == 0) {
20 config->smart_gaps = false;
21 } else {
22 return cmd_results_new(CMD_INVALID, "smart_gaps",
23 "Expected 'smart_gaps <on|off>' ");
24 }
25
26 arrange_and_commit(&root_container);
27
28 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
29}
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 29efdd50..5c26ac52 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -194,6 +194,21 @@ static void unmanaged_for_each_surface(struct wl_list *unmanaged,
194 } 194 }
195} 195}
196 196
197static void drag_icons_for_each_surface(struct wl_list *drag_icons,
198 struct sway_output *output, struct root_geometry *geo,
199 wlr_surface_iterator_func_t iterator, void *user_data) {
200 struct sway_drag_icon *drag_icon;
201 wl_list_for_each(drag_icon, drag_icons, link) {
202 double ox = drag_icon->x - output->swayc->x;
203 double oy = drag_icon->y - output->swayc->y;
204
205 if (drag_icon->wlr_drag_icon->mapped) {
206 surface_for_each_surface(drag_icon->wlr_drag_icon->surface,
207 ox, oy, geo, iterator, user_data);
208 }
209 }
210}
211
197static void scale_box(struct wlr_box *box, float scale) { 212static void scale_box(struct wlr_box *box, float scale) {
198 box->x *= scale; 213 box->x *= scale;
199 box->y *= scale; 214 box->y *= scale;
@@ -315,6 +330,17 @@ static void render_unmanaged(struct sway_output *output,
315 render_surface_iterator, &data); 330 render_surface_iterator, &data);
316} 331}
317 332
333static void render_drag_icons(struct sway_output *output,
334 pixman_region32_t *damage, struct wl_list *drag_icons) {
335 struct render_data data = {
336 .output = output,
337 .damage = damage,
338 .alpha = 1.0f,
339 };
340 drag_icons_for_each_surface(drag_icons, output, &data.root_geo,
341 render_surface_iterator, &data);
342}
343
318static void render_rect(struct wlr_output *wlr_output, 344static void render_rect(struct wlr_output *wlr_output,
319 pixman_region32_t *output_damage, const struct wlr_box *_box, 345 pixman_region32_t *output_damage, const struct wlr_box *_box,
320 float color[static 4]) { 346 float color[static 4]) {
@@ -959,6 +985,7 @@ static void render_output(struct sway_output *output, struct timespec *when,
959 } 985 }
960 render_layer(output, damage, 986 render_layer(output, damage,
961 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); 987 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
988 render_drag_icons(output, damage, &root_container.sway_root->drag_icons);
962 989
963renderer_end: 990renderer_end:
964 if (root_container.sway_root->debug_tree) { 991 if (root_container.sway_root->debug_tree) {
@@ -1009,6 +1036,12 @@ static void send_frame_done_unmanaged(struct send_frame_done_data *data,
1009 send_frame_done_iterator, data); 1036 send_frame_done_iterator, data);
1010} 1037}
1011 1038
1039static void send_frame_done_drag_icons(struct send_frame_done_data *data,
1040 struct wl_list *drag_icons) {
1041 drag_icons_for_each_surface(drag_icons, data->output, &data->root_geo,
1042 send_frame_done_iterator, data);
1043}
1044
1012static void send_frame_done_container_iterator(struct sway_container *con, 1045static void send_frame_done_container_iterator(struct sway_container *con,
1013 void *_data) { 1046 void *_data) {
1014 struct send_frame_done_data *data = _data; 1047 struct send_frame_done_data *data = _data;
@@ -1062,6 +1095,7 @@ static void send_frame_done(struct sway_output *output, struct timespec *when) {
1062 1095
1063 send_frame_done_layer(&data, 1096 send_frame_done_layer(&data,
1064 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); 1097 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
1098 send_frame_done_drag_icons(&data, &root_container.sway_root->drag_icons);
1065} 1099}
1066 1100
1067static void damage_handle_frame(struct wl_listener *listener, void *data) { 1101static void damage_handle_frame(struct wl_listener *listener, void *data) {
@@ -1227,12 +1261,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
1227 container_destroy(output->swayc); 1261 container_destroy(output->swayc);
1228 } 1262 }
1229 1263
1230 if (&output->link) { 1264 wl_list_remove(&output->link);
1231 wl_list_remove(&output->link); 1265 wl_list_remove(&output->destroy.link);
1232 wl_list_remove(&output->destroy.link); 1266 output->wlr_output->data = NULL;
1233 output->wlr_output = NULL; 1267 free(output);
1234 free(output);
1235 }
1236} 1268}
1237 1269
1238static void handle_mode(struct wl_listener *listener, void *data) { 1270static void handle_mode(struct wl_listener *listener, void *data) {
@@ -1270,10 +1302,13 @@ void handle_new_output(struct wl_listener *listener, void *data) {
1270 output->wlr_output = wlr_output; 1302 output->wlr_output = wlr_output;
1271 wlr_output->data = output; 1303 wlr_output->data = output;
1272 output->server = server; 1304 output->server = server;
1273 wl_list_insert(&root_container.sway_root->outputs, &output->link);
1274
1275 output->damage = wlr_output_damage_create(wlr_output); 1305 output->damage = wlr_output_damage_create(wlr_output);
1276 1306
1307 wl_signal_add(&wlr_output->events.destroy, &output->destroy);
1308 output->destroy.notify = handle_destroy;
1309
1310 wl_list_insert(&root_container.sway_root->outputs, &output->link);
1311
1277 if (!wl_list_empty(&wlr_output->modes)) { 1312 if (!wl_list_empty(&wlr_output->modes)) {
1278 struct wlr_output_mode *mode = 1313 struct wlr_output_mode *mode =
1279 wl_container_of(wlr_output->modes.prev, mode, link); 1314 wl_container_of(wlr_output->modes.prev, mode, link);
@@ -1286,6 +1321,10 @@ void handle_new_output(struct wl_listener *listener, void *data) {
1286void output_enable(struct sway_output *output) { 1321void output_enable(struct sway_output *output) {
1287 struct wlr_output *wlr_output = output->wlr_output; 1322 struct wlr_output *wlr_output = output->wlr_output;
1288 1323
1324 if (!sway_assert(output->swayc == NULL, "output is already enabled")) {
1325 return;
1326 }
1327
1289 output->swayc = output_create(output); 1328 output->swayc = output_create(output);
1290 if (!output->swayc) { 1329 if (!output->swayc) {
1291 // Output is disabled 1330 // Output is disabled
@@ -1299,8 +1338,6 @@ void output_enable(struct sway_output *output) {
1299 1338
1300 input_manager_configure_xcursor(input_manager); 1339 input_manager_configure_xcursor(input_manager);
1301 1340
1302 wl_signal_add(&wlr_output->events.destroy, &output->destroy);
1303 output->destroy.notify = handle_destroy;
1304 wl_signal_add(&wlr_output->events.mode, &output->mode); 1341 wl_signal_add(&wlr_output->events.mode, &output->mode);
1305 output->mode.notify = handle_mode; 1342 output->mode.notify = handle_mode;
1306 wl_signal_add(&wlr_output->events.transform, &output->transform); 1343 wl_signal_add(&wlr_output->events.transform, &output->transform);
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index ee9883e2..07bfbf7a 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -82,6 +82,10 @@ void transaction_add_container(struct sway_transaction *transaction,
82 state->swayc_y = container->y; 82 state->swayc_y = container->y;
83 state->swayc_width = container->width; 83 state->swayc_width = container->width;
84 state->swayc_height = container->height; 84 state->swayc_height = container->height;
85 state->has_gaps = container->has_gaps;
86 state->current_gaps = container->current_gaps;
87 state->gaps_inner = container->gaps_inner;
88 state->gaps_outer = container->gaps_outer;
85 89
86 if (container->type == C_VIEW) { 90 if (container->type == C_VIEW) {
87 struct sway_view *view = container->sway_view; 91 struct sway_view *view = container->sway_view;
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 4100479c..37a87756 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -144,21 +144,22 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
144 time_msec = get_current_time_msec(); 144 time_msec = get_current_time_msec();
145 } 145 }
146 146
147 struct wlr_seat *seat = cursor->seat->wlr_seat; 147 struct sway_seat *seat = cursor->seat;
148 struct wlr_seat *wlr_seat = seat->wlr_seat;
148 struct wlr_surface *surface = NULL; 149 struct wlr_surface *surface = NULL;
149 double sx, sy; 150 double sx, sy;
150 151
151 // Find the container beneath the pointer's previous position 152 // Find the container beneath the pointer's previous position
152 struct sway_container *prev_c = container_at_coords(cursor->seat, 153 struct sway_container *prev_c = container_at_coords(seat,
153 cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); 154 cursor->previous.x, cursor->previous.y, &surface, &sx, &sy);
154 // Update the stored previous position 155 // Update the stored previous position
155 cursor->previous.x = cursor->cursor->x; 156 cursor->previous.x = cursor->cursor->x;
156 cursor->previous.y = cursor->cursor->y; 157 cursor->previous.y = cursor->cursor->y;
157 158
158 struct sway_container *c = container_at_coords(cursor->seat, 159 struct sway_container *c = container_at_coords(seat,
159 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); 160 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
160 if (c && config->focus_follows_mouse && allow_refocusing) { 161 if (c && config->focus_follows_mouse && allow_refocusing) {
161 struct sway_container *focus = seat_get_focus(cursor->seat); 162 struct sway_container *focus = seat_get_focus(seat);
162 if (focus && c->type == C_WORKSPACE) { 163 if (focus && c->type == C_WORKSPACE) {
163 // Only follow the mouse if it would move to a new output 164 // Only follow the mouse if it would move to a new output
164 // Otherwise we'll focus the workspace, which is probably wrong 165 // Otherwise we'll focus the workspace, which is probably wrong
@@ -170,20 +171,20 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
170 output = container_parent(c, C_OUTPUT); 171 output = container_parent(c, C_OUTPUT);
171 } 172 }
172 if (output != focus) { 173 if (output != focus) {
173 seat_set_focus_warp(cursor->seat, c, false); 174 seat_set_focus_warp(seat, c, false);
174 } 175 }
175 } else if (c->type == C_VIEW) { 176 } else if (c->type == C_VIEW) {
176 // Focus c if both of the following are true: 177 // Focus c if both of the following are true:
177 // - cursor is over a new view, i.e. entered a new window; and 178 // - cursor is over a new view, i.e. entered a new window; and
178 // - the new view is visible, i.e. not hidden in a stack or tab. 179 // - the new view is visible, i.e. not hidden in a stack or tab.
179 if (c != prev_c && view_is_visible(c->sway_view)) { 180 if (c != prev_c && view_is_visible(c->sway_view)) {
180 seat_set_focus_warp(cursor->seat, c, false); 181 seat_set_focus_warp(seat, c, false);
181 } else { 182 } else {
182 struct sway_container *next_focus = 183 struct sway_container *next_focus =
183 seat_get_focus_inactive(cursor->seat, &root_container); 184 seat_get_focus_inactive(seat, &root_container);
184 if (next_focus && next_focus->type == C_VIEW && 185 if (next_focus && next_focus->type == C_VIEW &&
185 view_is_visible(next_focus->sway_view)) { 186 view_is_visible(next_focus->sway_view)) {
186 seat_set_focus_warp(cursor->seat, next_focus, false); 187 seat_set_focus_warp(seat, next_focus, false);
187 } 188 }
188 } 189 }
189 } 190 }
@@ -202,12 +203,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
202 203
203 // send pointer enter/leave 204 // send pointer enter/leave
204 if (surface != NULL) { 205 if (surface != NULL) {
205 if (seat_is_input_allowed(cursor->seat, surface)) { 206 if (seat_is_input_allowed(seat, surface)) {
206 wlr_seat_pointer_notify_enter(seat, surface, sx, sy); 207 wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy);
207 wlr_seat_pointer_notify_motion(seat, time_msec, sx, sy); 208 wlr_seat_pointer_notify_motion(wlr_seat, time_msec, sx, sy);
208 } 209 }
209 } else { 210 } else {
210 wlr_seat_pointer_clear_focus(seat); 211 wlr_seat_pointer_clear_focus(wlr_seat);
212 }
213
214 struct wlr_drag_icon *wlr_drag_icon;
215 wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) {
216 struct sway_drag_icon *drag_icon = wlr_drag_icon->data;
217 drag_icon_update_position(drag_icon);
211 } 218 }
212} 219}
213 220
@@ -293,22 +300,27 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
293 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); 300 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
294 struct wlr_event_touch_down *event = data; 301 struct wlr_event_touch_down *event = data;
295 302
296 struct wlr_seat *seat = cursor->seat->wlr_seat; 303 struct sway_seat *seat = cursor->seat;
304 struct wlr_seat *wlr_seat = seat->wlr_seat;
297 struct wlr_surface *surface = NULL; 305 struct wlr_surface *surface = NULL;
298 306
299 double lx, ly; 307 double lx, ly;
300 wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, 308 wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device,
301 event->x, event->y, &lx, &ly); 309 event->x, event->y, &lx, &ly);
302 double sx, sy; 310 double sx, sy;
303 container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); 311 container_at_coords(seat, lx, ly, &surface, &sx, &sy);
312
313 seat->touch_id = event->touch_id;
314 seat->touch_x = lx;
315 seat->touch_y = ly;
304 316
305 if (!surface) { 317 if (!surface) {
306 return; 318 return;
307 } 319 }
308 320
309 // TODO: fall back to cursor simulation if client has not bound to touch 321 // TODO: fall back to cursor simulation if client has not bound to touch
310 if (seat_is_input_allowed(cursor->seat, surface)) { 322 if (seat_is_input_allowed(seat, surface)) {
311 wlr_seat_touch_notify_down(seat, surface, event->time_msec, 323 wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec,
312 event->touch_id, sx, sy); 324 event->touch_id, sx, sy);
313 cursor->image_client = NULL; 325 cursor->image_client = NULL;
314 wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); 326 wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0);
@@ -330,7 +342,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
330 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); 342 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
331 struct wlr_event_touch_motion *event = data; 343 struct wlr_event_touch_motion *event = data;
332 344
333 struct wlr_seat *seat = cursor->seat->wlr_seat; 345 struct sway_seat *seat = cursor->seat;
346 struct wlr_seat *wlr_seat = seat->wlr_seat;
334 struct wlr_surface *surface = NULL; 347 struct wlr_surface *surface = NULL;
335 348
336 double lx, ly; 349 double lx, ly;
@@ -339,14 +352,25 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
339 double sx, sy; 352 double sx, sy;
340 container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); 353 container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy);
341 354
355 if (seat->touch_id == event->touch_id) {
356 seat->touch_x = lx;
357 seat->touch_y = ly;
358
359 struct wlr_drag_icon *wlr_drag_icon;
360 wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) {
361 struct sway_drag_icon *drag_icon = wlr_drag_icon->data;
362 drag_icon_update_position(drag_icon);
363 }
364 }
365
342 if (!surface) { 366 if (!surface) {
343 return; 367 return;
344 } 368 }
345 369
346 // TODO: fall back to cursor simulation if client has not bound to touch 370 // TODO: fall back to cursor simulation if client has not bound to touch
347 if (seat_is_input_allowed(cursor->seat, surface)) { 371 if (seat_is_input_allowed(cursor->seat, surface)) {
348 wlr_seat_touch_notify_motion( 372 wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
349 seat, event->time_msec, event->touch_id, sx, sy); 373 event->touch_id, sx, sy);
350 } 374 }
351} 375}
352 376
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 071ef020..1ea36466 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -6,21 +6,22 @@
6#include <wlr/types/wlr_cursor.h> 6#include <wlr/types/wlr_cursor.h>
7#include <wlr/types/wlr_output_layout.h> 7#include <wlr/types/wlr_output_layout.h>
8#include <wlr/types/wlr_xcursor_manager.h> 8#include <wlr/types/wlr_xcursor_manager.h>
9#include "log.h"
9#include "sway/debug.h" 10#include "sway/debug.h"
10#include "sway/tree/container.h" 11#include "sway/desktop.h"
11#include "sway/tree/workspace.h"
12#include "sway/input/seat.h"
13#include "sway/input/cursor.h" 12#include "sway/input/cursor.h"
14#include "sway/input/input-manager.h" 13#include "sway/input/input-manager.h"
15#include "sway/input/keyboard.h" 14#include "sway/input/keyboard.h"
15#include "sway/input/seat.h"
16#include "sway/ipc-server.h" 16#include "sway/ipc-server.h"
17#include "sway/layers.h" 17#include "sway/layers.h"
18#include "sway/output.h" 18#include "sway/output.h"
19#include "sway/tree/arrange.h" 19#include "sway/tree/arrange.h"
20#include "sway/tree/container.h" 20#include "sway/tree/container.h"
21#include "sway/tree/container.h"
21#include "sway/tree/view.h" 22#include "sway/tree/view.h"
22#include "sway/tree/workspace.h" 23#include "sway/tree/workspace.h"
23#include "log.h" 24#include "sway/tree/workspace.h"
24 25
25static void seat_device_destroy(struct sway_seat_device *seat_device) { 26static void seat_device_destroy(struct sway_seat_device *seat_device) {
26 if (!seat_device) { 27 if (!seat_device) {
@@ -40,6 +41,8 @@ void seat_destroy(struct sway_seat *seat) {
40 seat_device_destroy(seat_device); 41 seat_device_destroy(seat_device);
41 } 42 }
42 sway_cursor_destroy(seat->cursor); 43 sway_cursor_destroy(seat->cursor);
44 wl_list_remove(&seat->new_container.link);
45 wl_list_remove(&seat->new_drag_icon.link);
43 wl_list_remove(&seat->link); 46 wl_list_remove(&seat->link);
44 wlr_seat_destroy(seat->wlr_seat); 47 wlr_seat_destroy(seat->wlr_seat);
45} 48}
@@ -234,6 +237,90 @@ static void handle_new_container(struct wl_listener *listener, void *data) {
234 seat_container_from_container(seat, con); 237 seat_container_from_container(seat, con);
235} 238}
236 239
240static void drag_icon_damage_whole(struct sway_drag_icon *icon) {
241 if (!icon->wlr_drag_icon->mapped) {
242 return;
243 }
244 desktop_damage_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, true);
245}
246
247void drag_icon_update_position(struct sway_drag_icon *icon) {
248 drag_icon_damage_whole(icon);
249
250 struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
251 struct sway_seat *seat = icon->seat;
252 struct wlr_cursor *cursor = seat->cursor->cursor;
253 if (wlr_icon->is_pointer) {
254 icon->x = cursor->x + wlr_icon->sx;
255 icon->y = cursor->y + wlr_icon->sy;
256 } else {
257 struct wlr_touch_point *point =
258 wlr_seat_touch_get_point(seat->wlr_seat, wlr_icon->touch_id);
259 if (point == NULL) {
260 return;
261 }
262 icon->x = seat->touch_x + wlr_icon->sx;
263 icon->y = seat->touch_y + wlr_icon->sy;
264 }
265
266 drag_icon_damage_whole(icon);
267}
268
269static void drag_icon_handle_surface_commit(struct wl_listener *listener,
270 void *data) {
271 struct sway_drag_icon *icon =
272 wl_container_of(listener, icon, surface_commit);
273 drag_icon_update_position(icon);
274}
275
276static void drag_icon_handle_map(struct wl_listener *listener, void *data) {
277 struct sway_drag_icon *icon = wl_container_of(listener, icon, map);
278 drag_icon_damage_whole(icon);
279}
280
281static void drag_icon_handle_unmap(struct wl_listener *listener, void *data) {
282 struct sway_drag_icon *icon = wl_container_of(listener, icon, unmap);
283 drag_icon_damage_whole(icon);
284}
285
286static void drag_icon_handle_destroy(struct wl_listener *listener,
287 void *data) {
288 struct sway_drag_icon *icon = wl_container_of(listener, icon, destroy);
289 icon->wlr_drag_icon->data = NULL;
290 wl_list_remove(&icon->link);
291 wl_list_remove(&icon->surface_commit.link);
292 wl_list_remove(&icon->unmap.link);
293 wl_list_remove(&icon->destroy.link);
294 free(icon);
295}
296
297static void handle_new_drag_icon(struct wl_listener *listener, void *data) {
298 struct sway_seat *seat = wl_container_of(listener, seat, new_drag_icon);
299 struct wlr_drag_icon *wlr_drag_icon = data;
300
301 struct sway_drag_icon *icon = calloc(1, sizeof(struct sway_drag_icon));
302 if (icon == NULL) {
303 wlr_log(L_ERROR, "Allocation failed");
304 return;
305 }
306 icon->seat = seat;
307 icon->wlr_drag_icon = wlr_drag_icon;
308 wlr_drag_icon->data = icon;
309
310 icon->surface_commit.notify = drag_icon_handle_surface_commit;
311 wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
312 icon->unmap.notify = drag_icon_handle_unmap;
313 wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap);
314 icon->map.notify = drag_icon_handle_map;
315 wl_signal_add(&wlr_drag_icon->events.map, &icon->map);
316 icon->destroy.notify = drag_icon_handle_destroy;
317 wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
318
319 wl_list_insert(&root_container.sway_root->drag_icons, &icon->link);
320
321 drag_icon_update_position(icon);
322}
323
237static void collect_focus_iter(struct sway_container *con, void *data) { 324static void collect_focus_iter(struct sway_container *con, void *data) {
238 struct sway_seat *seat = data; 325 struct sway_seat *seat = data;
239 if (con->type > C_WORKSPACE) { 326 if (con->type > C_WORKSPACE) {
@@ -278,6 +365,9 @@ struct sway_seat *seat_create(struct sway_input_manager *input,
278 &seat->new_container); 365 &seat->new_container);
279 seat->new_container.notify = handle_new_container; 366 seat->new_container.notify = handle_new_container;
280 367
368 wl_signal_add(&seat->wlr_seat->events.new_drag_icon, &seat->new_drag_icon);
369 seat->new_drag_icon.notify = handle_new_drag_icon;
370
281 seat->input = input; 371 seat->input = input;
282 wl_list_init(&seat->devices); 372 wl_list_init(&seat->devices);
283 373
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 5d402d1b..b9289e25 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -83,7 +83,8 @@ static const char *ipc_json_get_output_transform(enum wl_output_transform transf
83 return NULL; 83 return NULL;
84} 84}
85 85
86static void ipc_json_describe_output(struct sway_container *container, json_object *object) { 86static void ipc_json_describe_output(struct sway_container *container,
87 json_object *object) {
87 struct wlr_output *wlr_output = container->sway_output->wlr_output; 88 struct wlr_output *wlr_output = container->sway_output->wlr_output;
88 json_object_object_add(object, "type", 89 json_object_object_add(object, "type",
89 json_object_new_string("output")); 90 json_object_new_string("output"));
@@ -141,12 +142,12 @@ static void ipc_json_describe_output(struct sway_container *container, json_obje
141 142
142json_object *ipc_json_describe_disabled_output(struct sway_output *output) { 143json_object *ipc_json_describe_disabled_output(struct sway_output *output) {
143 struct wlr_output *wlr_output = output->wlr_output; 144 struct wlr_output *wlr_output = output->wlr_output;
144 145
145 json_object *object = json_object_new_object(); 146 json_object *object = json_object_new_object();
146 147
147 json_object_object_add(object, "type", json_object_new_string("output")); 148 json_object_object_add(object, "type", json_object_new_string("output"));
148 json_object_object_add(object, "name", 149 json_object_object_add(object, "name",
149 wlr_output->name ? json_object_new_string(wlr_output->name) : NULL); 150 json_object_new_string(wlr_output->name));
150 json_object_object_add(object, "active", json_object_new_boolean(false)); 151 json_object_object_add(object, "active", json_object_new_boolean(false));
151 json_object_object_add(object, "make", 152 json_object_object_add(object, "make",
152 json_object_new_string(wlr_output->make)); 153 json_object_new_string(wlr_output->make));
diff --git a/sway/meson.build b/sway/meson.build
index 5ff62490..c461b0ff 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -45,6 +45,7 @@ sway_sources = files(
45 'commands/for_window.c', 45 'commands/for_window.c',
46 'commands/force_focus_wrapping.c', 46 'commands/force_focus_wrapping.c',
47 'commands/fullscreen.c', 47 'commands/fullscreen.c',
48 'commands/gaps.c',
48 'commands/hide_edge_borders.c', 49 'commands/hide_edge_borders.c',
49 'commands/kill.c', 50 'commands/kill.c',
50 'commands/mark.c', 51 'commands/mark.c',
@@ -65,6 +66,7 @@ sway_sources = files(
65 'commands/seat/fallback.c', 66 'commands/seat/fallback.c',
66 'commands/set.c', 67 'commands/set.c',
67 'commands/show_marks.c', 68 'commands/show_marks.c',
69 'commands/smart_gaps.c',
68 'commands/split.c', 70 'commands/split.c',
69 'commands/sticky.c', 71 'commands/sticky.c',
70 'commands/swaybg_command.c', 72 'commands/swaybg_command.c',
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index e138410d..ac99c5df 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -41,6 +41,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
41 child->width = parent->width; 41 child->width = parent->width;
42 } 42 }
43 } 43 }
44 remove_gaps(child);
44 total_width += child->width; 45 total_width += child->width;
45 } 46 }
46 double scale = parent->width / total_width; 47 double scale = parent->width / total_width;
@@ -63,6 +64,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
63 if (i == num_children - 1) { 64 if (i == num_children - 1) {
64 child->width = parent->x + parent->width - child->x; 65 child->width = parent->x + parent->width - child->x;
65 } 66 }
67 add_gaps(child);
66 } 68 }
67} 69}
68 70
@@ -78,7 +80,7 @@ static void apply_vert_layout(struct sway_container *parent) {
78 parent_offset = 80 parent_offset =
79 container_titlebar_height() * parent->parent->children->length; 81 container_titlebar_height() * parent->parent->children->length;
80 } 82 }
81 size_t parent_height = parent->height - parent_offset; 83 size_t parent_height = parent->height + parent_offset;
82 84
83 // Calculate total height of children 85 // Calculate total height of children
84 double total_height = 0; 86 double total_height = 0;
@@ -91,6 +93,7 @@ static void apply_vert_layout(struct sway_container *parent) {
91 child->height = parent_height; 93 child->height = parent_height;
92 } 94 }
93 } 95 }
96 remove_gaps(child);
94 total_height += child->height; 97 total_height += child->height;
95 } 98 }
96 double scale = parent_height / total_height; 99 double scale = parent_height / total_height;
@@ -114,6 +117,7 @@ static void apply_vert_layout(struct sway_container *parent) {
114 child->height = 117 child->height =
115 parent->y + parent_offset + parent_height - child->y; 118 parent->y + parent_offset + parent_height - child->y;
116 } 119 }
120 add_gaps(child);
117 } 121 }
118} 122}
119 123
@@ -131,10 +135,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
131 size_t parent_height = parent->height - parent_offset; 135 size_t parent_height = parent->height - parent_offset;
132 for (int i = 0; i < parent->children->length; ++i) { 136 for (int i = 0; i < parent->children->length; ++i) {
133 struct sway_container *child = parent->children->items[i]; 137 struct sway_container *child = parent->children->items[i];
138 remove_gaps(child);
134 child->x = parent->x; 139 child->x = parent->x;
135 child->y = parent->y + parent_offset; 140 child->y = parent->y + parent_offset;
136 child->width = parent->width; 141 child->width = parent->width;
137 child->height = parent_height; 142 child->height = parent_height;
143 add_gaps(child);
138 } 144 }
139} 145}
140 146
@@ -185,6 +191,11 @@ static void arrange_children_of(struct sway_container *parent,
185 // Recurse into child containers 191 // Recurse into child containers
186 for (int i = 0; i < parent->children->length; ++i) { 192 for (int i = 0; i < parent->children->length; ++i) {
187 struct sway_container *child = parent->children->items[i]; 193 struct sway_container *child = parent->children->items[i];
194 if (parent->has_gaps && !child->has_gaps) {
195 child->has_gaps = true;
196 child->gaps_inner = parent->gaps_inner;
197 child->gaps_outer = parent->gaps_outer;
198 }
188 if (child->type == C_VIEW) { 199 if (child->type == C_VIEW) {
189 view_autoconfigure(child->sway_view); 200 view_autoconfigure(child->sway_view);
190 } else { 201 } else {
@@ -203,10 +214,12 @@ static void arrange_workspace(struct sway_container *workspace,
203 struct wlr_box *area = &output->sway_output->usable_area; 214 struct wlr_box *area = &output->sway_output->usable_area;
204 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 215 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
205 area->width, area->height, area->x, area->y); 216 area->width, area->height, area->x, area->y);
217 remove_gaps(workspace);
206 workspace->width = area->width; 218 workspace->width = area->width;
207 workspace->height = area->height; 219 workspace->height = area->height;
208 workspace->x = output->x + area->x; 220 workspace->x = output->x + area->x;
209 workspace->y = output->y + area->y; 221 workspace->y = output->y + area->y;
222 add_gaps(workspace);
210 transaction_add_container(transaction, workspace); 223 transaction_add_container(transaction, workspace);
211 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, 224 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
212 workspace->x, workspace->y); 225 workspace->x, workspace->y);
@@ -285,3 +298,41 @@ void arrange_and_commit(struct sway_container *container) {
285 arrange_windows(container, transaction); 298 arrange_windows(container, transaction);
286 transaction_commit(transaction); 299 transaction_commit(transaction);
287} 300}
301
302void remove_gaps(struct sway_container *c) {
303 if (c->current_gaps == 0) {
304 wlr_log(L_DEBUG, "Removing gaps: not gapped: %p", c);
305 return;
306 }
307
308 c->width += c->current_gaps * 2;
309 c->height += c->current_gaps * 2;
310 c->x -= c->current_gaps;
311 c->y -= c->current_gaps;
312
313 c->current_gaps = 0;
314
315 wlr_log(L_DEBUG, "Removing gaps %p", c);
316}
317
318void add_gaps(struct sway_container *c) {
319 if (c->current_gaps > 0 || c->type == C_CONTAINER) {
320 wlr_log(L_DEBUG, "Not adding gaps: %p", c);
321 return;
322 }
323
324 if (c->type == C_WORKSPACE &&
325 !(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) {
326 return;
327 }
328
329 double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner;
330
331 c->x += gaps;
332 c->y += gaps;
333 c->width -= 2 * gaps;
334 c->height -= 2 * gaps;
335 c->current_gaps = gaps;
336
337 wlr_log(L_DEBUG, "Adding gaps: %p", c);
338}
diff --git a/sway/tree/container.c b/sway/tree/container.c
index d312eb60..f8620b72 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -125,6 +125,11 @@ struct sway_container *container_create(enum sway_container_type type) {
125 wl_signal_add(&c->events.reparent, &c->reparent); 125 wl_signal_add(&c->events.reparent, &c->reparent);
126 c->reparent.notify = handle_reparent; 126 c->reparent.notify = handle_reparent;
127 127
128 c->has_gaps = false;
129 c->gaps_inner = 0;
130 c->gaps_outer = 0;
131 c->current_gaps = 0;
132
128 return c; 133 return c;
129} 134}
130 135
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 65b61495..3724361d 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -37,6 +37,7 @@ void layout_init(void) {
37 root_container.sway_root->output_layout = wlr_output_layout_create(); 37 root_container.sway_root->output_layout = wlr_output_layout_create();
38 wl_list_init(&root_container.sway_root->outputs); 38 wl_list_init(&root_container.sway_root->outputs);
39 wl_list_init(&root_container.sway_root->xwayland_unmanaged); 39 wl_list_init(&root_container.sway_root->xwayland_unmanaged);
40 wl_list_init(&root_container.sway_root->drag_icons);
40 wl_signal_init(&root_container.sway_root->events.new_container); 41 wl_signal_init(&root_container.sway_root->events.new_container);
41 42
42 root_container.sway_root->output_layout_change.notify = 43 root_container.sway_root->output_layout_change.notify =
@@ -839,6 +840,8 @@ struct sway_container *container_split(struct sway_container *child,
839 840
840 wlr_log(L_DEBUG, "creating container %p around %p", cont, child); 841 wlr_log(L_DEBUG, "creating container %p around %p", cont, child);
841 842
843 remove_gaps(child);
844
842 cont->prev_layout = L_NONE; 845 cont->prev_layout = L_NONE;
843 cont->width = child->width; 846 cont->width = child->width;
844 cont->height = child->height; 847 cont->height = child->height;
@@ -847,6 +850,9 @@ struct sway_container *container_split(struct sway_container *child,
847 850
848 struct sway_seat *seat = input_manager_get_default_seat(input_manager); 851 struct sway_seat *seat = input_manager_get_default_seat(input_manager);
849 bool set_focus = (seat_get_focus(seat) == child); 852 bool set_focus = (seat_get_focus(seat) == child);
853
854 add_gaps(cont);
855
850 if (child->type == C_WORKSPACE) { 856 if (child->type == C_WORKSPACE) {
851 struct sway_container *workspace = child; 857 struct sway_container *workspace = child;
852 while (workspace->children->length) { 858 while (workspace->children->length) {
@@ -874,7 +880,6 @@ struct sway_container *container_split(struct sway_container *child,
874 } 880 }
875 881
876 container_notify_subtree_changed(cont); 882 container_notify_subtree_changed(cont);
877
878 return cont; 883 return cont;
879} 884}
880 885
diff --git a/sway/tree/output.c b/sway/tree/output.c
index ed7e941e..8af319d5 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -26,12 +26,10 @@ static void restore_workspaces(struct sway_container *output) {
26 j--; 26 j--;
27 } 27 }
28 } 28 }
29
30 arrange_output(other);
31 } 29 }
32 30
33 container_sort_workspaces(output); 31 container_sort_workspaces(output);
34 arrange_output(output); 32 arrange_and_commit(&root_container);
35} 33}
36 34
37struct sway_container *output_create( 35struct sway_container *output_create(
@@ -68,6 +66,7 @@ struct sway_container *output_create(
68 66
69 struct sway_container *output = container_create(C_OUTPUT); 67 struct sway_container *output = container_create(C_OUTPUT);
70 output->sway_output = sway_output; 68 output->sway_output = sway_output;
69 sway_output->swayc = output;
71 output->name = strdup(name); 70 output->name = strdup(name);
72 if (output->name == NULL) { 71 if (output->name == NULL) {
73 container_destroy(output); 72 container_destroy(output);