aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/transaction.c
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 /sway/desktop/transaction.c
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.
Diffstat (limited to 'sway/desktop/transaction.c')
-rw-r--r--sway/desktop/transaction.c45
1 files changed, 15 insertions, 30 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
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}