diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-24 19:38:52 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-24 19:38:52 +1000 |
commit | bdae625cb344209424841a7c5f0c0967773c8c10 (patch) | |
tree | 754adb52ec2e2eb9d336d1c826bab62ea96e6c52 /sway/desktop/transaction.c | |
parent | bdb176863c3c45caae70abb909f9eca9f611e78f (diff) |
Rebase the cursor after mapping a view
I originally put the rebase at the end of view_map, but at this point
the view is still at its native size and will ignore the motion event if
it falls outside of its native size. The only way to do this properly is
to rebase the cursor later - either after sending the configure, after
the view commits with the new size, or after applying the transaction. I
chose to do it after applying the transaction for simplicity.
I then attempted to just call cursor_rebase after applying every
transaction, but this causes crashes when exiting sway (and possibly
other places) because cursor_rebase assumes the tree is in a valid
state.
So my chosen solution introduces transaction_commit_dirty_with_callback
which allows handle_map to register a callback which will run when the
transaction is applied.
Diffstat (limited to 'sway/desktop/transaction.c')
-rw-r--r-- | sway/desktop/transaction.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 5dec279d..b2f7f922 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -25,6 +25,8 @@ struct sway_transaction { size_t num_waiting; size_t num_configures; struct timespec commit_time; + void (*callback)(void *data); + void *callback_data; }; struct sway_transaction_instruction { @@ -295,6 +297,10 @@ static void transaction_apply(struct sway_transaction *transaction) { node->instruction = NULL; } + + if (transaction->callback) { + transaction->callback(transaction->callback_data); + } } static void transaction_commit(struct sway_transaction *transaction); @@ -499,14 +505,7 @@ void transaction_notify_view_ready_by_size(struct sway_view *view, } } -void transaction_commit_dirty(void) { - if (!server.dirty_nodes->length) { - return; - } - struct sway_transaction *transaction = transaction_create(); - if (!transaction) { - return; - } +static void do_commit_dirty(struct sway_transaction *transaction) { for (int i = 0; i < server.dirty_nodes->length; ++i) { struct sway_node *node = server.dirty_nodes->items[i]; transaction_add_node(transaction, node); @@ -525,3 +524,28 @@ void transaction_commit_dirty(void) { transaction_progress_queue(); } } + +void transaction_commit_dirty(void) { + if (!server.dirty_nodes->length) { + return; + } + struct sway_transaction *transaction = transaction_create(); + if (!transaction) { + return; + } + do_commit_dirty(transaction); +} + +void transaction_commit_dirty_with_callback( + void (*callback)(void *data), void *data) { + if (!server.dirty_nodes->length) { + return; + } + struct sway_transaction *transaction = transaction_create(); + if (!transaction) { + return; + } + transaction->callback = callback; + transaction->callback_data = data; + do_commit_dirty(transaction); +} |