aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/desktop/transaction.h7
-rw-r--r--include/sway/output.h1
-rw-r--r--include/sway/server.h6
-rw-r--r--sway/commands/border.c5
-rw-r--r--sway/commands/floating.c4
-rw-r--r--sway/commands/focus.c6
-rw-r--r--sway/commands/fullscreen.c4
-rw-r--r--sway/commands/gaps.c4
-rw-r--r--sway/commands/kill.c4
-rw-r--r--sway/commands/layout.c4
-rw-r--r--sway/commands/move.c4
-rw-r--r--sway/commands/rename.c4
-rw-r--r--sway/commands/resize.c4
-rw-r--r--sway/commands/scratchpad.c4
-rw-r--r--sway/commands/split.c4
-rw-r--r--sway/commands/swap.c4
-rw-r--r--sway/commands/workspace.c4
-rw-r--r--sway/desktop/output.c185
-rw-r--r--sway/desktop/transaction.c45
-rw-r--r--sway/desktop/xdg_shell.c8
-rw-r--r--sway/desktop/xdg_shell_v6.c8
-rw-r--r--sway/desktop/xwayland.c8
-rw-r--r--sway/input/seat.c1
-rw-r--r--sway/server.c3
-rw-r--r--sway/tree/output.c2
-rw-r--r--sway/tree/view.c1
-rw-r--r--sway/tree/workspace.c1
27 files changed, 178 insertions, 157 deletions
diff --git a/include/sway/desktop/transaction.h b/include/sway/desktop/transaction.h
index f38f033c..66e8c9a2 100644
--- a/include/sway/desktop/transaction.h
+++ b/include/sway/desktop/transaction.h
@@ -29,13 +29,6 @@ struct sway_view;
29void transaction_commit_dirty(void); 29void transaction_commit_dirty(void);
30 30
31/** 31/**
32 * Same as above, but runs the specific callback when the transaction is
33 * applied.
34 */
35void transaction_commit_dirty_with_callback(
36 void (*callback)(void *data), void *data);
37
38/**
39 * Notify the transaction system that a view is ready for the new layout. 32 * Notify the transaction system that a view is ready for the new layout.
40 * 33 *
41 * When all views in the transaction are ready, the layout will be applied. 34 * When all views in the transaction are ready, the layout will be applied.
diff --git a/include/sway/output.h b/include/sway/output.h
index 19a61175..369e62ce 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -40,6 +40,7 @@ struct sway_output {
40 struct wl_listener mode; 40 struct wl_listener mode;
41 struct wl_listener transform; 41 struct wl_listener transform;
42 struct wl_listener scale; 42 struct wl_listener scale;
43 struct wl_listener present;
43 struct wl_listener damage_destroy; 44 struct wl_listener damage_destroy;
44 struct wl_listener damage_frame; 45 struct wl_listener damage_frame;
45 46
diff --git a/include/sway/server.h b/include/sway/server.h
index 3e1cbb33..5fced224 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -8,12 +8,12 @@
8#include <wlr/types/wlr_compositor.h> 8#include <wlr/types/wlr_compositor.h>
9#include <wlr/types/wlr_data_device.h> 9#include <wlr/types/wlr_data_device.h>
10#include <wlr/types/wlr_layer_shell_v1.h> 10#include <wlr/types/wlr_layer_shell_v1.h>
11#include <wlr/types/wlr_presentation_time.h>
11#include <wlr/types/wlr_server_decoration.h> 12#include <wlr/types/wlr_server_decoration.h>
12#include <wlr/types/wlr_xdg_shell_v6.h> 13#include <wlr/types/wlr_xdg_shell_v6.h>
13#include <wlr/types/wlr_xdg_shell.h> 14#include <wlr/types/wlr_xdg_shell.h>
14// TODO WLR: make Xwayland optional
15#include "list.h"
16#include "config.h" 15#include "config.h"
16#include "list.h"
17#ifdef HAVE_XWAYLAND 17#ifdef HAVE_XWAYLAND
18#include "sway/xwayland.h" 18#include "sway/xwayland.h"
19#endif 19#endif
@@ -58,6 +58,8 @@ struct sway_server {
58 struct wl_listener xdg_decoration; 58 struct wl_listener xdg_decoration;
59 struct wl_list xdg_decorations; // sway_xdg_decoration::link 59 struct wl_list xdg_decorations; // sway_xdg_decoration::link
60 60
61 struct wlr_presentation *presentation;
62
61 size_t txn_timeout_ms; 63 size_t txn_timeout_ms;
62 list_t *transactions; 64 list_t *transactions;
63 list_t *dirty_nodes; 65 list_t *dirty_nodes;
diff --git a/sway/commands/border.c b/sway/commands/border.c
index 5b65148d..37047812 100644
--- a/sway/commands/border.c
+++ b/sway/commands/border.c
@@ -94,10 +94,5 @@ struct cmd_results *cmd_border(int argc, char **argv) {
94 94
95 arrange_container(view->container); 95 arrange_container(view->container);
96 96
97 struct sway_seat *seat = input_manager_current_seat();
98 if (seat->cursor) {
99 cursor_rebase(seat->cursor);
100 }
101
102 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 97 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
103} 98}
diff --git a/sway/commands/floating.c b/sway/commands/floating.c
index 97662a18..81bb86f8 100644
--- a/sway/commands/floating.c
+++ b/sway/commands/floating.c
@@ -15,6 +15,10 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
15 if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { 15 if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) {
16 return error; 16 return error;
17 } 17 }
18 if (!root->outputs->length) {
19 return cmd_results_new(CMD_INVALID, "floating",
20 "Can't run this command while there's no outputs connected.");
21 }
18 struct sway_container *container = config->handler_context.container; 22 struct sway_container *container = config->handler_context.container;
19 struct sway_workspace *workspace = config->handler_context.workspace; 23 struct sway_workspace *workspace = config->handler_context.workspace;
20 if (!container && workspace->tiling->length == 0) { 24 if (!container && workspace->tiling->length == 0) {
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 81af8e0f..2204f722 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -224,6 +224,10 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
224 if (config->reading || !config->active) { 224 if (config->reading || !config->active) {
225 return cmd_results_new(CMD_DEFER, NULL, NULL); 225 return cmd_results_new(CMD_DEFER, NULL, NULL);
226 } 226 }
227 if (!root->outputs->length) {
228 return cmd_results_new(CMD_INVALID, "focus",
229 "Can't run this command while there's no outputs connected.");
230 }
227 struct sway_node *node = config->handler_context.node; 231 struct sway_node *node = config->handler_context.node;
228 struct sway_container *container = config->handler_context.container; 232 struct sway_container *container = config->handler_context.container;
229 struct sway_workspace *workspace = config->handler_context.workspace; 233 struct sway_workspace *workspace = config->handler_context.workspace;
@@ -236,7 +240,6 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
236 if (argc == 0 && container) { 240 if (argc == 0 && container) {
237 seat_set_focus_container(seat, container); 241 seat_set_focus_container(seat, container);
238 seat_consider_warp_to_focus(seat); 242 seat_consider_warp_to_focus(seat);
239 cursor_rebase(seat->cursor);
240 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 243 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
241 } 244 }
242 245
@@ -294,7 +297,6 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
294 if (next_focus) { 297 if (next_focus) {
295 seat_set_focus(seat, next_focus); 298 seat_set_focus(seat, next_focus);
296 seat_consider_warp_to_focus(seat); 299 seat_consider_warp_to_focus(seat);
297 cursor_rebase(seat->cursor);
298 } 300 }
299 301
300 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 302 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c
index 0204a73c..ff7cbba7 100644
--- a/sway/commands/fullscreen.c
+++ b/sway/commands/fullscreen.c
@@ -12,6 +12,10 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
12 if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_MOST, 1))) { 12 if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_MOST, 1))) {
13 return error; 13 return error;
14 } 14 }
15 if (!root->outputs->length) {
16 return cmd_results_new(CMD_INVALID, "fullscreen",
17 "Can't run this command while there's no outputs connected.");
18 }
15 struct sway_node *node = config->handler_context.node; 19 struct sway_node *node = config->handler_context.node;
16 struct sway_container *container = config->handler_context.container; 20 struct sway_container *container = config->handler_context.container;
17 struct sway_workspace *workspace = config->handler_context.workspace; 21 struct sway_workspace *workspace = config->handler_context.workspace;
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c
index 042b415f..ca8cb27a 100644
--- a/sway/commands/gaps.c
+++ b/sway/commands/gaps.c
@@ -88,6 +88,10 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
88 if (error) { 88 if (error) {
89 return error; 89 return error;
90 } 90 }
91 if (!root->outputs->length) {
92 return cmd_results_new(CMD_INVALID, "gaps",
93 "Can't run this command while there's no outputs connected.");
94 }
91 95
92 struct gaps_data data; 96 struct gaps_data data;
93 97
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index 85ca0f33..f1d75b9a 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -14,6 +14,10 @@ static void close_container_iterator(struct sway_container *con, void *data) {
14} 14}
15 15
16struct cmd_results *cmd_kill(int argc, char **argv) { 16struct cmd_results *cmd_kill(int argc, char **argv) {
17 if (!root->outputs->length) {
18 return cmd_results_new(CMD_INVALID, "kill",
19 "Can't run this command while there's no outputs connected.");
20 }
17 struct sway_container *con = config->handler_context.container; 21 struct sway_container *con = config->handler_context.container;
18 struct sway_workspace *ws = config->handler_context.workspace; 22 struct sway_workspace *ws = config->handler_context.workspace;
19 23
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
index 65f67af8..8fde1776 100644
--- a/sway/commands/layout.c
+++ b/sway/commands/layout.c
@@ -99,6 +99,10 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
99 if ((error = checkarg(argc, "layout", EXPECTED_AT_LEAST, 1))) { 99 if ((error = checkarg(argc, "layout", EXPECTED_AT_LEAST, 1))) {
100 return error; 100 return error;
101 } 101 }
102 if (!root->outputs->length) {
103 return cmd_results_new(CMD_INVALID, "layout",
104 "Can't run this command while there's no outputs connected.");
105 }
102 struct sway_container *container = config->handler_context.container; 106 struct sway_container *container = config->handler_context.container;
103 struct sway_workspace *workspace = config->handler_context.workspace; 107 struct sway_workspace *workspace = config->handler_context.workspace;
104 108
diff --git a/sway/commands/move.c b/sway/commands/move.c
index e0a958bf..ffe12d41 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -844,6 +844,10 @@ struct cmd_results *cmd_move(int argc, char **argv) {
844 if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { 844 if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) {
845 return error; 845 return error;
846 } 846 }
847 if (!root->outputs->length) {
848 return cmd_results_new(CMD_INVALID, "move",
849 "Can't run this command while there's no outputs connected.");
850 }
847 851
848 if (strcasecmp(argv[0], "left") == 0) { 852 if (strcasecmp(argv[0], "left") == 0) {
849 return cmd_move_in_direction(MOVE_LEFT, argc, argv); 853 return cmd_move_in_direction(MOVE_LEFT, argc, argv);
diff --git a/sway/commands/rename.c b/sway/commands/rename.c
index d982f941..0cee9293 100644
--- a/sway/commands/rename.c
+++ b/sway/commands/rename.c
@@ -20,6 +20,10 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
20 if ((error = checkarg(argc, "rename", EXPECTED_AT_LEAST, 3))) { 20 if ((error = checkarg(argc, "rename", EXPECTED_AT_LEAST, 3))) {
21 return error; 21 return error;
22 } 22 }
23 if (!root->outputs->length) {
24 return cmd_results_new(CMD_INVALID, "rename",
25 "Can't run this command while there's no outputs connected.");
26 }
23 if (strcasecmp(argv[0], "workspace") != 0) { 27 if (strcasecmp(argv[0], "workspace") != 0) {
24 return cmd_results_new(CMD_INVALID, "rename", expected_syntax); 28 return cmd_results_new(CMD_INVALID, "rename", expected_syntax);
25 } 29 }
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 8666f40b..8635b309 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -671,6 +671,10 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
671} 671}
672 672
673struct cmd_results *cmd_resize(int argc, char **argv) { 673struct cmd_results *cmd_resize(int argc, char **argv) {
674 if (!root->outputs->length) {
675 return cmd_results_new(CMD_INVALID, "resize",
676 "Can't run this command while there's no outputs connected.");
677 }
674 struct sway_container *current = config->handler_context.container; 678 struct sway_container *current = config->handler_context.container;
675 if (!current) { 679 if (!current) {
676 return cmd_results_new(CMD_INVALID, "resize", "Cannot resize nothing"); 680 return cmd_results_new(CMD_INVALID, "resize", "Cannot resize nothing");
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c
index 26f0e490..6eab456d 100644
--- a/sway/commands/scratchpad.c
+++ b/sway/commands/scratchpad.c
@@ -87,6 +87,10 @@ struct cmd_results *cmd_scratchpad(int argc, char **argv) {
87 return cmd_results_new(CMD_INVALID, "scratchpad", 87 return cmd_results_new(CMD_INVALID, "scratchpad",
88 "Expected 'scratchpad show'"); 88 "Expected 'scratchpad show'");
89 } 89 }
90 if (!root->outputs->length) {
91 return cmd_results_new(CMD_INVALID, "scratchpad",
92 "Can't run this command while there's no outputs connected.");
93 }
90 if (!root->scratchpad->length) { 94 if (!root->scratchpad->length) {
91 return cmd_results_new(CMD_INVALID, "scratchpad", 95 return cmd_results_new(CMD_INVALID, "scratchpad",
92 "Scratchpad is empty"); 96 "Scratchpad is empty");
diff --git a/sway/commands/split.c b/sway/commands/split.c
index 9a53f3d3..ed106a86 100644
--- a/sway/commands/split.c
+++ b/sway/commands/split.c
@@ -28,6 +28,10 @@ struct cmd_results *cmd_split(int argc, char **argv) {
28 if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) { 28 if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) {
29 return error; 29 return error;
30 } 30 }
31 if (!root->outputs->length) {
32 return cmd_results_new(CMD_INVALID, "split",
33 "Can't run this command while there's no outputs connected.");
34 }
31 if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { 35 if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
32 return do_split(L_VERT); 36 return do_split(L_VERT);
33 } else if (strcasecmp(argv[0], "h") == 0 || 37 } else if (strcasecmp(argv[0], "h") == 0 ||
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index afe11a47..a70a6cdd 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -171,6 +171,10 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
171 if ((error = checkarg(argc, "swap", EXPECTED_AT_LEAST, 4))) { 171 if ((error = checkarg(argc, "swap", EXPECTED_AT_LEAST, 4))) {
172 return error; 172 return error;
173 } 173 }
174 if (!root->outputs->length) {
175 return cmd_results_new(CMD_INVALID, "swap",
176 "Can't run this command while there's no outputs connected.");
177 }
174 178
175 if (strcasecmp(argv[0], "container") || strcasecmp(argv[1], "with")) { 179 if (strcasecmp(argv[0], "container") || strcasecmp(argv[1], "with")) {
176 return cmd_results_new(CMD_INVALID, "swap", EXPECTED_SYNTAX); 180 return cmd_results_new(CMD_INVALID, "swap", EXPECTED_SYNTAX);
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 745b40c7..8364e607 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -38,6 +38,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
38 if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { 38 if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) {
39 return error; 39 return error;
40 } 40 }
41 if (!root->outputs->length) {
42 return cmd_results_new(CMD_INVALID, "workspace",
43 "Can't run this command while there's no outputs connected.");
44 }
41 45
42 int output_location = -1; 46 int output_location = -1;
43 int gaps_location = -1; 47 int gaps_location = -1;
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 018a7285..ed9300bb 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -11,10 +11,11 @@
11#include <wlr/types/wlr_output_damage.h> 11#include <wlr/types/wlr_output_damage.h>
12#include <wlr/types/wlr_output_layout.h> 12#include <wlr/types/wlr_output_layout.h>
13#include <wlr/types/wlr_output.h> 13#include <wlr/types/wlr_output.h>
14#include <wlr/types/wlr_presentation_time.h>
14#include <wlr/types/wlr_surface.h> 15#include <wlr/types/wlr_surface.h>
15#include <wlr/util/region.h> 16#include <wlr/util/region.h>
16#include "log.h"
17#include "config.h" 17#include "config.h"
18#include "log.h"
18#include "sway/config.h" 19#include "sway/config.h"
19#include "sway/desktop/transaction.h" 20#include "sway/desktop/transaction.h"
20#include "sway/input/input-manager.h" 21#include "sway/input/input-manager.h"
@@ -223,6 +224,75 @@ void output_drag_icons_for_each_surface(struct sway_output *output,
223 } 224 }
224} 225}
225 226
227static void for_each_surface_container_iterator(struct sway_container *con,
228 void *_data) {
229 if (!con->view || !view_is_visible(con->view)) {
230 return;
231 }
232
233 struct surface_iterator_data *data = _data;
234 output_view_for_each_surface(data->output, con->view,
235 data->user_iterator, data->user_data);
236}
237
238static void output_for_each_surface(struct sway_output *output,
239 sway_surface_iterator_func_t iterator, void *user_data) {
240 if (output_has_opaque_overlay_layer_surface(output)) {
241 goto overlay;
242 }
243
244 struct surface_iterator_data data = {
245 .user_iterator = iterator,
246 .user_data = user_data,
247 .output = output,
248 };
249
250 struct sway_workspace *workspace = output_get_active_workspace(output);
251 if (workspace->current.fullscreen) {
252 for_each_surface_container_iterator(
253 workspace->current.fullscreen, &data);
254 container_for_each_child(workspace->current.fullscreen,
255 for_each_surface_container_iterator, &data);
256 for (int i = 0; i < workspace->current.floating->length; ++i) {
257 struct sway_container *floater =
258 workspace->current.floating->items[i];
259 if (container_is_transient_for(floater,
260 workspace->current.fullscreen)) {
261 for_each_surface_container_iterator(floater, &data);
262 }
263 }
264#ifdef HAVE_XWAYLAND
265 output_unmanaged_for_each_surface(output, &root->xwayland_unmanaged,
266 iterator, user_data);
267#endif
268 } else {
269 output_layer_for_each_surface(output,
270 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
271 iterator, user_data);
272 output_layer_for_each_surface(output,
273 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM],
274 iterator, user_data);
275
276 workspace_for_each_container(workspace,
277 for_each_surface_container_iterator, &data);
278
279#ifdef HAVE_XWAYLAND
280 output_unmanaged_for_each_surface(output, &root->xwayland_unmanaged,
281 iterator, user_data);
282#endif
283 output_layer_for_each_surface(output,
284 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
285 iterator, user_data);
286 }
287
288overlay:
289 output_layer_for_each_surface(output,
290 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY],
291 iterator, user_data);
292 output_drag_icons_for_each_surface(output, &root->drag_icons,
293 iterator, user_data);
294}
295
226static int scale_length(int length, int offset, float scale) { 296static int scale_length(int length, int offset, float scale) {
227 return round((offset + length) * scale) - round(offset * scale); 297 return round((offset + length) * scale) - round(offset * scale);
228} 298}
@@ -274,96 +344,13 @@ bool output_has_opaque_overlay_layer_surface(struct sway_output *output) {
274 344
275static void send_frame_done_iterator(struct sway_output *output, 345static void send_frame_done_iterator(struct sway_output *output,
276 struct wlr_surface *surface, struct wlr_box *box, float rotation, 346 struct wlr_surface *surface, struct wlr_box *box, float rotation,
277 void *_data) { 347 void *data) {
278 struct timespec *when = _data; 348 struct timespec *when = data;
279 wlr_surface_send_frame_done(surface, when); 349 wlr_surface_send_frame_done(surface, when);
280} 350}
281 351
282static void send_frame_done_layer(struct sway_output *output,
283 struct wl_list *layer_surfaces, struct timespec *when) {
284 output_layer_for_each_surface(output, layer_surfaces,
285 send_frame_done_iterator, when);
286}
287
288#ifdef HAVE_XWAYLAND
289static void send_frame_done_unmanaged(struct sway_output *output,
290 struct wl_list *unmanaged, struct timespec *when) {
291 output_unmanaged_for_each_surface(output, unmanaged,
292 send_frame_done_iterator, when);
293}
294#endif
295
296static void send_frame_done_drag_icons(struct sway_output *output,
297 struct wl_list *drag_icons, struct timespec *when) {
298 output_drag_icons_for_each_surface(output, drag_icons,
299 send_frame_done_iterator, when);
300}
301
302struct send_frame_done_data {
303 struct sway_output *output;
304 struct timespec *when;
305};
306
307static void send_frame_done_container_iterator(struct sway_container *con,
308 void *_data) {
309 if (!con->view) {
310 return;
311 }
312 if (!view_is_visible(con->view)) {
313 return;
314 }
315
316 struct send_frame_done_data *data = _data;
317 output_view_for_each_surface(data->output, con->view,
318 send_frame_done_iterator, data->when);
319}
320
321static void send_frame_done(struct sway_output *output, struct timespec *when) { 352static void send_frame_done(struct sway_output *output, struct timespec *when) {
322 if (output_has_opaque_overlay_layer_surface(output)) { 353 output_for_each_surface(output, send_frame_done_iterator, when);
323 goto send_frame_overlay;
324 }
325
326 struct send_frame_done_data data = {
327 .output = output,
328 .when = when,
329 };
330 struct sway_workspace *workspace = output_get_active_workspace(output);
331 if (workspace->current.fullscreen) {
332 send_frame_done_container_iterator(
333 workspace->current.fullscreen, &data);
334 container_for_each_child(workspace->current.fullscreen,
335 send_frame_done_container_iterator, &data);
336 for (int i = 0; i < workspace->current.floating->length; ++i) {
337 struct sway_container *floater =
338 workspace->current.floating->items[i];
339 if (container_is_transient_for(floater,
340 workspace->current.fullscreen)) {
341 send_frame_done_container_iterator(floater, &data);
342 }
343 }
344#ifdef HAVE_XWAYLAND
345 send_frame_done_unmanaged(output, &root->xwayland_unmanaged, when);
346#endif
347 } else {
348 send_frame_done_layer(output,
349 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], when);
350 send_frame_done_layer(output,
351 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], when);
352
353 workspace_for_each_container(workspace,
354 send_frame_done_container_iterator, &data);
355
356#ifdef HAVE_XWAYLAND
357 send_frame_done_unmanaged(output, &root->xwayland_unmanaged, when);
358#endif
359 send_frame_done_layer(output,
360 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], when);
361 }
362
363send_frame_overlay:
364 send_frame_done_layer(output,
365 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], when);
366 send_frame_done_drag_icons(output, &root->drag_icons, when);
367} 354}
368 355
369static void damage_handle_frame(struct wl_listener *listener, void *data) { 356static void damage_handle_frame(struct wl_listener *listener, void *data) {
@@ -545,6 +532,29 @@ static void handle_scale(struct wl_listener *listener, void *data) {
545 transaction_commit_dirty(); 532 transaction_commit_dirty();
546} 533}
547 534
535static void send_presented_iterator(struct sway_output *output,
536 struct wlr_surface *surface, struct wlr_box *box, float rotation,
537 void *data) {
538 struct wlr_presentation_event *event = data;
539 wlr_presentation_send_surface_presented(server.presentation,
540 surface, event);
541}
542
543static void handle_present(struct wl_listener *listener, void *data) {
544 struct sway_output *output = wl_container_of(listener, output, present);
545 struct wlr_output_event_present *output_event = data;
546
547 struct wlr_presentation_event event = {
548 .output = output->wlr_output,
549 .tv_sec = (uint64_t)output_event->when->tv_sec,
550 .tv_nsec = (uint32_t)output_event->when->tv_nsec,
551 .refresh = (uint32_t)output_event->refresh,
552 .seq = (uint64_t)output_event->seq,
553 .flags = output_event->flags,
554 };
555 output_for_each_surface(output, send_presented_iterator, &event);
556}
557
548void handle_new_output(struct wl_listener *listener, void *data) { 558void handle_new_output(struct wl_listener *listener, void *data) {
549 struct sway_server *server = wl_container_of(listener, server, new_output); 559 struct sway_server *server = wl_container_of(listener, server, new_output);
550 struct wlr_output *wlr_output = data; 560 struct wlr_output *wlr_output = data;
@@ -571,6 +581,7 @@ void output_add_listeners(struct sway_output *output) {
571 output->mode.notify = handle_mode; 581 output->mode.notify = handle_mode;
572 output->transform.notify = handle_transform; 582 output->transform.notify = handle_transform;
573 output->scale.notify = handle_scale; 583 output->scale.notify = handle_scale;
584 output->present.notify = handle_present;
574 output->damage_frame.notify = damage_handle_frame; 585 output->damage_frame.notify = damage_handle_frame;
575 output->damage_destroy.notify = damage_handle_destroy; 586 output->damage_destroy.notify = damage_handle_destroy;
576} 587}
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index b2f7f922..955b05d6 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -11,6 +11,8 @@
11#include "sway/desktop.h" 11#include "sway/desktop.h"
12#include "sway/desktop/idle_inhibit_v1.h" 12#include "sway/desktop/idle_inhibit_v1.h"
13#include "sway/desktop/transaction.h" 13#include "sway/desktop/transaction.h"
14#include "sway/input/cursor.h"
15#include "sway/input/input-manager.h"
14#include "sway/output.h" 16#include "sway/output.h"
15#include "sway/tree/container.h" 17#include "sway/tree/container.h"
16#include "sway/tree/node.h" 18#include "sway/tree/node.h"
@@ -25,8 +27,6 @@ struct sway_transaction {
25 size_t num_waiting; 27 size_t num_waiting;
26 size_t num_configures; 28 size_t num_configures;
27 struct timespec commit_time; 29 struct timespec commit_time;
28 void (*callback)(void *data);
29 void *callback_data;
30}; 30};
31 31
32struct sway_transaction_instruction { 32struct sway_transaction_instruction {
@@ -298,8 +298,11 @@ static void transaction_apply(struct sway_transaction *transaction) {
298 node->instruction = NULL; 298 node->instruction = NULL;
299 } 299 }
300 300
301 if (transaction->callback) { 301 if (root->outputs->length) {
302 transaction->callback(transaction->callback_data); 302 struct sway_seat *seat;
303 wl_list_for_each(seat, &server.input->seats, link) {
304 cursor_rebase(seat->cursor);
305 }
303 } 306 }
304} 307}
305 308
@@ -505,7 +508,14 @@ void transaction_notify_view_ready_by_size(struct sway_view *view,
505 } 508 }
506} 509}
507 510
508static void do_commit_dirty(struct sway_transaction *transaction) { 511void transaction_commit_dirty(void) {
512 if (!server.dirty_nodes->length) {
513 return;
514 }
515 struct sway_transaction *transaction = transaction_create();
516 if (!transaction) {
517 return;
518 }
509 for (int i = 0; i < server.dirty_nodes->length; ++i) { 519 for (int i = 0; i < server.dirty_nodes->length; ++i) {
510 struct sway_node *node = server.dirty_nodes->items[i]; 520 struct sway_node *node = server.dirty_nodes->items[i];
511 transaction_add_node(transaction, node); 521 transaction_add_node(transaction, node);
@@ -524,28 +534,3 @@ static void do_commit_dirty(struct sway_transaction *transaction) {
524 transaction_progress_queue(); 534 transaction_progress_queue();
525 } 535 }
526} 536}
527
528void transaction_commit_dirty(void) {
529 if (!server.dirty_nodes->length) {
530 return;
531 }
532 struct sway_transaction *transaction = transaction_create();
533 if (!transaction) {
534 return;
535 }
536 do_commit_dirty(transaction);
537}
538
539void transaction_commit_dirty_with_callback(
540 void (*callback)(void *data), void *data) {
541 if (!server.dirty_nodes->length) {
542 return;
543 }
544 struct sway_transaction *transaction = transaction_create();
545 if (!transaction) {
546 return;
547 }
548 transaction->callback = callback;
549 transaction->callback_data = data;
550 do_commit_dirty(transaction);
551}
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 064e2707..0b2ebc96 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -397,11 +397,6 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
397 wl_list_remove(&xdg_shell_view->set_app_id.link); 397 wl_list_remove(&xdg_shell_view->set_app_id.link);
398} 398}
399 399
400static void do_rebase(void *data) {
401 struct sway_cursor *cursor = data;
402 cursor_rebase(cursor);
403}
404
405static void handle_map(struct wl_listener *listener, void *data) { 400static void handle_map(struct wl_listener *listener, void *data) {
406 struct sway_xdg_shell_view *xdg_shell_view = 401 struct sway_xdg_shell_view *xdg_shell_view =
407 wl_container_of(listener, xdg_shell_view, map); 402 wl_container_of(listener, xdg_shell_view, map);
@@ -428,8 +423,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
428 view_map(view, view->wlr_xdg_surface->surface, 423 view_map(view, view->wlr_xdg_surface->surface,
429 xdg_surface->toplevel->client_pending.fullscreen, csd); 424 xdg_surface->toplevel->client_pending.fullscreen, csd);
430 425
431 struct sway_seat *seat = input_manager_current_seat(); 426 transaction_commit_dirty();
432 transaction_commit_dirty_with_callback(do_rebase, seat->cursor);
433 427
434 xdg_shell_view->commit.notify = handle_commit; 428 xdg_shell_view->commit.notify = handle_commit;
435 wl_signal_add(&xdg_surface->surface->events.commit, 429 wl_signal_add(&xdg_surface->surface->events.commit,
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 90bf55b2..692cfbf5 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -394,11 +394,6 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
394 wl_list_remove(&xdg_shell_v6_view->set_app_id.link); 394 wl_list_remove(&xdg_shell_v6_view->set_app_id.link);
395} 395}
396 396
397static void do_rebase(void *data) {
398 struct sway_cursor *cursor = data;
399 cursor_rebase(cursor);
400}
401
402static void handle_map(struct wl_listener *listener, void *data) { 397static void handle_map(struct wl_listener *listener, void *data) {
403 struct sway_xdg_shell_v6_view *xdg_shell_v6_view = 398 struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
404 wl_container_of(listener, xdg_shell_v6_view, map); 399 wl_container_of(listener, xdg_shell_v6_view, map);
@@ -419,8 +414,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
419 view_map(view, view->wlr_xdg_surface_v6->surface, 414 view_map(view, view->wlr_xdg_surface_v6->surface,
420 xdg_surface->toplevel->client_pending.fullscreen, csd); 415 xdg_surface->toplevel->client_pending.fullscreen, csd);
421 416
422 struct sway_seat *seat = input_manager_current_seat(); 417 transaction_commit_dirty();
423 transaction_commit_dirty_with_callback(do_rebase, seat->cursor);
424 418
425 xdg_shell_v6_view->commit.notify = handle_commit; 419 xdg_shell_v6_view->commit.notify = handle_commit;
426 wl_signal_add(&xdg_surface->surface->events.commit, 420 wl_signal_add(&xdg_surface->surface->events.commit,
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 95275937..0c41d960 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -391,11 +391,6 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
391 wl_list_remove(&xwayland_view->commit.link); 391 wl_list_remove(&xwayland_view->commit.link);
392} 392}
393 393
394static void do_rebase(void *data) {
395 struct sway_cursor *cursor = data;
396 cursor_rebase(cursor);
397}
398
399static void handle_map(struct wl_listener *listener, void *data) { 394static void handle_map(struct wl_listener *listener, void *data) {
400 struct sway_xwayland_view *xwayland_view = 395 struct sway_xwayland_view *xwayland_view =
401 wl_container_of(listener, xwayland_view, map); 396 wl_container_of(listener, xwayland_view, map);
@@ -422,8 +417,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
422 // Put it back into the tree 417 // Put it back into the tree
423 view_map(view, xsurface->surface, xsurface->fullscreen, false); 418 view_map(view, xsurface->surface, xsurface->fullscreen, false);
424 419
425 struct sway_seat *seat = input_manager_current_seat(); 420 transaction_commit_dirty();
426 transaction_commit_dirty_with_callback(do_rebase, seat->cursor);
427} 421}
428 422
429static void handle_request_configure(struct wl_listener *listener, void *data) { 423static void handle_request_configure(struct wl_listener *listener, void *data) {
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 89d841bb..577619a7 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -1196,5 +1196,4 @@ void seat_consider_warp_to_focus(struct sway_seat *seat) {
1196 } else { 1196 } else {
1197 cursor_warp_to_workspace(seat->cursor, focus->sway_workspace); 1197 cursor_warp_to_workspace(seat->cursor, focus->sway_workspace);
1198 } 1198 }
1199 cursor_rebase(seat->cursor);
1200} 1199}
diff --git a/sway/server.c b/sway/server.c
index 23d42028..f06173d1 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -135,6 +135,9 @@ bool server_init(struct sway_server *server) {
135 server->xdg_decoration.notify = handle_xdg_decoration; 135 server->xdg_decoration.notify = handle_xdg_decoration;
136 wl_list_init(&server->xdg_decorations); 136 wl_list_init(&server->xdg_decorations);
137 137
138 server->presentation =
139 wlr_presentation_create(server->wl_display, server->backend);
140
138 wlr_export_dmabuf_manager_v1_create(server->wl_display); 141 wlr_export_dmabuf_manager_v1_create(server->wl_display);
139 wlr_screencopy_manager_v1_create(server->wl_display); 142 wlr_screencopy_manager_v1_create(server->wl_display);
140 143
diff --git a/sway/tree/output.c b/sway/tree/output.c
index 04219b5f..e5794b8a 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -103,6 +103,7 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
103 wl_signal_add(&wlr_output->events.mode, &output->mode); 103 wl_signal_add(&wlr_output->events.mode, &output->mode);
104 wl_signal_add(&wlr_output->events.transform, &output->transform); 104 wl_signal_add(&wlr_output->events.transform, &output->transform);
105 wl_signal_add(&wlr_output->events.scale, &output->scale); 105 wl_signal_add(&wlr_output->events.scale, &output->scale);
106 wl_signal_add(&wlr_output->events.present, &output->present);
106 wl_signal_add(&output->damage->events.frame, &output->damage_frame); 107 wl_signal_add(&output->damage->events.frame, &output->damage_frame);
107 wl_signal_add(&output->damage->events.destroy, &output->damage_destroy); 108 wl_signal_add(&output->damage->events.destroy, &output->damage_destroy);
108 109
@@ -214,6 +215,7 @@ void output_disable(struct sway_output *output) {
214 wl_list_remove(&output->mode.link); 215 wl_list_remove(&output->mode.link);
215 wl_list_remove(&output->transform.link); 216 wl_list_remove(&output->transform.link);
216 wl_list_remove(&output->scale.link); 217 wl_list_remove(&output->scale.link);
218 wl_list_remove(&output->present.link);
217 wl_list_remove(&output->damage_destroy.link); 219 wl_list_remove(&output->damage_destroy.link);
218 wl_list_remove(&output->damage_frame.link); 220 wl_list_remove(&output->damage_frame.link);
219 221
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 20babf7b..4bc9e0f3 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -661,7 +661,6 @@ void view_unmap(struct sway_view *view) {
661 cursor_warp_to_workspace(seat->cursor, node->sway_workspace); 661 cursor_warp_to_workspace(seat->cursor, node->sway_workspace);
662 } 662 }
663 } 663 }
664 cursor_rebase(seat->cursor);
665 } 664 }
666 665
667 transaction_commit_dirty(); 666 transaction_commit_dirty();
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 65284679..27e9ac7a 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -404,7 +404,6 @@ bool workspace_switch(struct sway_workspace *workspace,
404 } 404 }
405 seat_set_focus(seat, next); 405 seat_set_focus(seat, next);
406 arrange_workspace(workspace); 406 arrange_workspace(workspace);
407 cursor_rebase(seat->cursor);
408 return true; 407 return true;
409} 408}
410 409