aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-25 23:30:09 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-25 23:37:40 +1000
commit60a1d79de71660949f7a6fc83e242d9d95c75187 (patch)
tree821502ef188985ee023df3f24b9e4e468eb96aef
parentMerge pull request #2950 from emersion/presentation-time (diff)
downloadsway-60a1d79de71660949f7a6fc83e242d9d95c75187.tar.gz
sway-60a1d79de71660949f7a6fc83e242d9d95c75187.tar.zst
sway-60a1d79de71660949f7a6fc83e242d9d95c75187.zip
Rebase the cursor after applying transactions
This approaches cursor rebasing from a different angle. Rather than littering the codebase with cursor_rebase calls and using transaction callbacks, this just runs cursor_rebase after applying every transaction - but only if there's outputs connected, because otherwise it causes a crash during shutdown. There is one known case where we still need to call cursor_rebase directly, and that's when running `seat seat0 cursor move ...`. This command doesn't set anything as dirty so no transaction occurs.
-rw-r--r--include/sway/desktop/transaction.h7
-rw-r--r--sway/commands/border.c5
-rw-r--r--sway/commands/focus.c2
-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/tree/view.c1
-rw-r--r--sway/tree/workspace.c1
10 files changed, 18 insertions, 68 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/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/focus.c b/sway/commands/focus.c
index 81af8e0f..b4965cf8 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -236,7 +236,6 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
236 if (argc == 0 && container) { 236 if (argc == 0 && container) {
237 seat_set_focus_container(seat, container); 237 seat_set_focus_container(seat, container);
238 seat_consider_warp_to_focus(seat); 238 seat_consider_warp_to_focus(seat);
239 cursor_rebase(seat->cursor);
240 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 239 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
241 } 240 }
242 241
@@ -294,7 +293,6 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
294 if (next_focus) { 293 if (next_focus) {
295 seat_set_focus(seat, next_focus); 294 seat_set_focus(seat, next_focus);
296 seat_consider_warp_to_focus(seat); 295 seat_consider_warp_to_focus(seat);
297 cursor_rebase(seat->cursor);
298 } 296 }
299 297
300 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 298 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
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/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