Simplify transactions by utilising a dirty flag on containers

This PR changes the way we handle transactions to a more simple method.
The new method is to mark containers as dirty from low level code
(eg. arranging, or container_destroy, and eventually seat_set_focus),
then call transaction_commit_dirty which picks up those containers and
runs them through a transaction. The old methods of using transactions
(arrange_and_commit, or creating one manually) are now no longer
possible.

The highest-level code (execute_command and view implementation
handlers) will call transaction_commit_dirty, so most other code just
needs to set containers as dirty. This is done by arranging, but can
also be done by calling container_set_dirty.
This commit is contained in:
Ryan Dwyer 2018-07-14 23:14:55 +10:00
parent 63f28bcf1e
commit 2032f85d94
29 changed files with 139 additions and 190 deletions

View file

@ -6,34 +6,25 @@
/**
* Transactions enable us to perform atomic layout updates.
*
* When we want to make adjustments to the layout, we create a transaction.
* A transaction contains a list of affected containers and their new state.
* A transaction contains a list of containers and their new state.
* A state might contain a new size, or new border settings, or new parent/child
* relationships.
*
* Calling transaction_commit() makes sway notify of all the affected clients
* with their new sizes. We then wait for all the views to respond with their
* new surface sizes. When all are ready, or when a timeout has passed, we apply
* the updates all at the same time.
* Committing a transaction makes sway notify of all the affected clients with
* their new sizes. We then wait for all the views to respond with their new
* surface sizes. When all are ready, or when a timeout has passed, we apply the
* updates all at the same time.
*
* When we want to make adjustments to the layout, we change the pending state
* in containers, mark them as dirty and call transaction_commit_dirty(). This
* create and commits a transaction from the dirty containers.
*/
struct sway_transaction;
/**
* Create a new transaction.
* Find all dirty containers, create and commit a transaction containing them,
* and unmark them as dirty.
*/
struct sway_transaction *transaction_create(void);
/**
* Add a container's pending state to the transaction.
*/
void transaction_add_container(struct sway_transaction *transaction,
struct sway_container *container);
/**
* Submit a transaction to the client views for configuration.
*/
void transaction_commit(struct sway_transaction *transaction);
void transaction_commit_dirty(void);
/**
* Notify the transaction system that a view is ready for the new layout.

View file

@ -47,10 +47,7 @@ struct sway_server {
bool debug_txn_timings;
list_t *transactions;
// When a view is being destroyed and is waiting for a transaction to
// complete it will be stored here.
list_t *destroying_containers;
list_t *dirty_containers;
};
struct sway_server server;

View file

@ -11,26 +11,8 @@ void remove_gaps(struct sway_container *c);
void add_gaps(struct sway_container *c);
/**
* Arrange layout for all the children of the given container, and add them to
* the given transaction.
*
* Use this function if you need to arrange multiple sections of the tree in one
* transaction.
*
* You must set the desired state of the container before calling
* arrange_windows, then don't change any state-tracked properties in the
* container until you've called transaction_commit.
* Arrange layout for all the children of the given container.
*/
void arrange_windows(struct sway_container *container,
struct sway_transaction *transaction);
/**
* Arrange layout for the given container and commit the transaction.
*
* This function is a wrapper around arrange_windows, and handles creating and
* committing the transaction for you. Use this function if you're only doing
* one arrange operation.
*/
void arrange_and_commit(struct sway_container *container);
void arrange_windows(struct sway_container *container);
#endif

View file

@ -144,6 +144,10 @@ struct sway_container {
bool destroying;
// If true, indicates that the container has pending state that differs from
// the current.
bool dirty;
struct {
struct wl_signal destroy;
// Raised after the tree updates, but before arrange_windows
@ -303,4 +307,10 @@ void container_get_box(struct sway_container *container, struct wlr_box *box);
void container_floating_move_to(struct sway_container *con,
double lx, double ly);
/**
* Mark a container as dirty if it isn't already. Dirty containers will be
* included in the next transaction then unmarked as dirty.
*/
void container_set_dirty(struct sway_container *container);
#endif