diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-25 23:30:09 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-25 23:37:40 +1000 |
commit | 60a1d79de71660949f7a6fc83e242d9d95c75187 (patch) | |
tree | 821502ef188985ee023df3f24b9e4e468eb96aef /sway/desktop | |
parent | Merge pull request #2950 from emersion/presentation-time (diff) | |
download | sway-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.
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/transaction.c | 45 | ||||
-rw-r--r-- | sway/desktop/xdg_shell.c | 8 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 8 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 8 |
4 files changed, 18 insertions, 51 deletions
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 | ||
32 | struct sway_transaction_instruction { | 32 | struct 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 | ||
508 | static void do_commit_dirty(struct sway_transaction *transaction) { | 511 | void 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 | |||
528 | void 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 | |||
539 | void 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 | ||
400 | static void do_rebase(void *data) { | ||
401 | struct sway_cursor *cursor = data; | ||
402 | cursor_rebase(cursor); | ||
403 | } | ||
404 | |||
405 | static void handle_map(struct wl_listener *listener, void *data) { | 400 | static 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 | ||
397 | static void do_rebase(void *data) { | ||
398 | struct sway_cursor *cursor = data; | ||
399 | cursor_rebase(cursor); | ||
400 | } | ||
401 | |||
402 | static void handle_map(struct wl_listener *listener, void *data) { | 397 | static 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 | ||
394 | static void do_rebase(void *data) { | ||
395 | struct sway_cursor *cursor = data; | ||
396 | cursor_rebase(cursor); | ||
397 | } | ||
398 | |||
399 | static void handle_map(struct wl_listener *listener, void *data) { | 394 | static 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 | ||
429 | static void handle_request_configure(struct wl_listener *listener, void *data) { | 423 | static void handle_request_configure(struct wl_listener *listener, void *data) { |