2018-06-03 08:35:06 +02:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-07-28 02:24:04 +02:00
|
|
|
#include <errno.h>
|
2018-08-18 08:58:50 +02:00
|
|
|
#include <limits.h>
|
2018-06-03 08:35:06 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2018-06-25 01:09:43 +02:00
|
|
|
#include <time.h>
|
2018-06-18 12:42:12 +02:00
|
|
|
#include <wlr/types/wlr_buffer.h>
|
2018-06-03 08:35:06 +02:00
|
|
|
#include "sway/debug.h"
|
2018-08-18 07:10:06 +02:00
|
|
|
#include "sway/desktop.h"
|
2018-06-30 07:09:32 +02:00
|
|
|
#include "sway/desktop/idle_inhibit_v1.h"
|
2018-06-03 08:35:06 +02:00
|
|
|
#include "sway/desktop/transaction.h"
|
|
|
|
#include "sway/output.h"
|
|
|
|
#include "sway/tree/container.h"
|
|
|
|
#include "sway/tree/view.h"
|
2018-06-23 08:24:11 +02:00
|
|
|
#include "sway/tree/workspace.h"
|
2018-06-03 08:35:06 +02:00
|
|
|
#include "list.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
2018-06-06 14:57:34 +02:00
|
|
|
struct sway_transaction {
|
|
|
|
struct wl_event_source *timer;
|
|
|
|
list_t *instructions; // struct sway_transaction_instruction *
|
|
|
|
size_t num_waiting;
|
2018-06-25 01:25:51 +02:00
|
|
|
size_t num_configures;
|
2018-08-12 02:44:45 +02:00
|
|
|
uint32_t con_ids; // Bitwise XOR of view container IDs
|
2018-06-25 01:09:43 +02:00
|
|
|
struct timespec commit_time;
|
2018-06-06 14:57:34 +02:00
|
|
|
};
|
|
|
|
|
2018-06-03 08:35:06 +02:00
|
|
|
struct sway_transaction_instruction {
|
|
|
|
struct sway_transaction *transaction;
|
|
|
|
struct sway_container *container;
|
|
|
|
struct sway_container_state state;
|
|
|
|
uint32_t serial;
|
|
|
|
};
|
|
|
|
|
2018-07-14 15:14:55 +02:00
|
|
|
static struct sway_transaction *transaction_create() {
|
2018-06-03 08:35:06 +02:00
|
|
|
struct sway_transaction *transaction =
|
|
|
|
calloc(1, sizeof(struct sway_transaction));
|
2018-08-15 02:03:55 +02:00
|
|
|
if (!sway_assert(transaction, "Unable to allocate transaction")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-06-03 08:35:06 +02:00
|
|
|
transaction->instructions = create_list();
|
|
|
|
return transaction;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transaction_destroy(struct sway_transaction *transaction) {
|
|
|
|
// Free instructions
|
2018-06-23 08:24:11 +02:00
|
|
|
for (int i = 0; i < transaction->instructions->length; ++i) {
|
2018-06-03 08:35:06 +02:00
|
|
|
struct sway_transaction_instruction *instruction =
|
|
|
|
transaction->instructions->items[i];
|
2018-06-23 08:24:11 +02:00
|
|
|
struct sway_container *con = instruction->container;
|
2018-08-15 02:03:55 +02:00
|
|
|
con->ntxnrefs--;
|
|
|
|
if (con->instruction == instruction) {
|
|
|
|
con->instruction = NULL;
|
2018-06-03 08:35:06 +02:00
|
|
|
}
|
2018-08-15 02:03:55 +02:00
|
|
|
if (con->destroying && con->ntxnrefs == 0) {
|
2018-06-23 08:24:11 +02:00
|
|
|
container_free(con);
|
|
|
|
}
|
2018-06-03 08:35:06 +02:00
|
|
|
free(instruction);
|
|
|
|
}
|
|
|
|
list_free(transaction->instructions);
|
|
|
|
|
2018-06-26 10:51:37 +02:00
|
|
|
if (transaction->timer) {
|
|
|
|
wl_event_source_remove(transaction->timer);
|
|
|
|
}
|
2018-06-03 08:35:06 +02:00
|
|
|
free(transaction);
|
|
|
|
}
|
|
|
|
|
2018-06-23 08:24:11 +02:00
|
|
|
static void copy_pending_state(struct sway_container *container,
|
|
|
|
struct sway_container_state *state) {
|
2018-06-06 11:19:30 +02:00
|
|
|
state->layout = container->layout;
|
|
|
|
state->swayc_x = container->x;
|
|
|
|
state->swayc_y = container->y;
|
|
|
|
state->swayc_width = container->width;
|
|
|
|
state->swayc_height = container->height;
|
2018-07-25 12:56:23 +02:00
|
|
|
state->is_fullscreen = container->is_fullscreen;
|
2018-06-11 03:03:43 +02:00
|
|
|
state->has_gaps = container->has_gaps;
|
|
|
|
state->current_gaps = container->current_gaps;
|
|
|
|
state->gaps_inner = container->gaps_inner;
|
|
|
|
state->gaps_outer = container->gaps_outer;
|
2018-06-23 08:24:11 +02:00
|
|
|
state->parent = container->parent;
|
2018-06-06 11:19:30 +02:00
|
|
|
|
|
|
|
if (container->type == C_VIEW) {
|
|
|
|
struct sway_view *view = container->sway_view;
|
|
|
|
state->view_x = view->x;
|
|
|
|
state->view_y = view->y;
|
|
|
|
state->view_width = view->width;
|
|
|
|
state->view_height = view->height;
|
|
|
|
state->border = view->border;
|
|
|
|
state->border_thickness = view->border_thickness;
|
|
|
|
state->border_top = view->border_top;
|
|
|
|
state->border_left = view->border_left;
|
|
|
|
state->border_right = view->border_right;
|
|
|
|
state->border_bottom = view->border_bottom;
|
2018-08-17 12:25:33 +02:00
|
|
|
state->using_csd = view->using_csd;
|
2018-06-23 08:24:11 +02:00
|
|
|
} else if (container->type == C_WORKSPACE) {
|
|
|
|
state->ws_fullscreen = container->sway_workspace->fullscreen;
|
2018-08-19 07:07:07 +02:00
|
|
|
state->ws_floating = create_list();
|
2018-06-23 08:24:11 +02:00
|
|
|
state->children = create_list();
|
2018-08-19 07:07:07 +02:00
|
|
|
list_cat(state->ws_floating, container->sway_workspace->floating);
|
2018-06-23 08:24:11 +02:00
|
|
|
list_cat(state->children, container->children);
|
|
|
|
} else {
|
|
|
|
state->children = create_list();
|
|
|
|
list_cat(state->children, container->children);
|
|
|
|
}
|
2018-07-15 07:20:21 +02:00
|
|
|
|
|
|
|
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
|
|
|
state->focused = seat_get_focus(seat) == container;
|
|
|
|
|
|
|
|
if (container->type != C_VIEW) {
|
|
|
|
state->focused_inactive_child =
|
|
|
|
seat_get_active_child(seat, container);
|
|
|
|
}
|
2018-06-23 08:24:11 +02:00
|
|
|
}
|
|
|
|
|
2018-07-14 15:14:55 +02:00
|
|
|
static void transaction_add_container(struct sway_transaction *transaction,
|
2018-06-23 08:24:11 +02:00
|
|
|
struct sway_container *container) {
|
|
|
|
struct sway_transaction_instruction *instruction =
|
|
|
|
calloc(1, sizeof(struct sway_transaction_instruction));
|
2018-08-15 02:03:55 +02:00
|
|
|
if (!sway_assert(instruction, "Unable to allocate instruction")) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-23 08:24:11 +02:00
|
|
|
instruction->transaction = transaction;
|
|
|
|
instruction->container = container;
|
|
|
|
|
|
|
|
copy_pending_state(container, &instruction->state);
|
2018-06-06 11:19:30 +02:00
|
|
|
|
2018-06-03 08:35:06 +02:00
|
|
|
list_add(transaction->instructions, instruction);
|
2018-08-15 02:03:55 +02:00
|
|
|
container->ntxnrefs++;
|
2018-06-03 08:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply a transaction to the "current" state of the tree.
|
|
|
|
*/
|
|
|
|
static void transaction_apply(struct sway_transaction *transaction) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Applying transaction %p", transaction);
|
2018-08-18 08:58:50 +02:00
|
|
|
if (debug.txn_timings) {
|
2018-06-25 01:09:43 +02:00
|
|
|
struct timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
struct timespec *commit = &transaction->commit_time;
|
2018-08-18 08:58:50 +02:00
|
|
|
float ms = (now.tv_sec - commit->tv_sec) * 1000 +
|
2018-06-25 01:09:43 +02:00
|
|
|
(now.tv_nsec - commit->tv_nsec) / 1000000.0;
|
2018-08-18 08:58:50 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Transaction %p: %.1fms waiting "
|
|
|
|
"(%.1f frames if 60Hz)", transaction, ms, ms / (1000.0f / 60));
|
2018-06-25 01:09:43 +02:00
|
|
|
}
|
2018-06-27 09:46:03 +02:00
|
|
|
|
2018-06-23 08:24:11 +02:00
|
|
|
// Apply the instruction state to the container's current state
|
2018-06-27 09:23:44 +02:00
|
|
|
for (int i = 0; i < transaction->instructions->length; ++i) {
|
2018-06-03 08:35:06 +02:00
|
|
|
struct sway_transaction_instruction *instruction =
|
|
|
|
transaction->instructions->items[i];
|
|
|
|
struct sway_container *container = instruction->container;
|
|
|
|
|
2018-08-18 07:10:06 +02:00
|
|
|
// Damage the old location
|
|
|
|
desktop_damage_whole_container(container);
|
|
|
|
if (container->type == C_VIEW && container->sway_view->saved_buffer) {
|
2018-08-16 14:41:10 +02:00
|
|
|
struct sway_view *view = container->sway_view;
|
2018-08-18 07:10:06 +02:00
|
|
|
struct wlr_box box = {
|
|
|
|
.x = container->current.view_x - view->saved_geometry.x,
|
|
|
|
.y = container->current.view_y - view->saved_geometry.y,
|
|
|
|
.width = view->saved_buffer_width,
|
|
|
|
.height = view->saved_buffer_height,
|
|
|
|
};
|
|
|
|
desktop_damage_box(&box);
|
2018-06-27 09:46:03 +02:00
|
|
|
}
|
|
|
|
|
2018-06-23 08:24:11 +02:00
|
|
|
// There are separate children lists for each instruction state, the
|
|
|
|
// container's current state and the container's pending state
|
|
|
|
// (ie. con->children). The list itself needs to be freed here.
|
|
|
|
// Any child containers which are being deleted will be cleaned up in
|
|
|
|
// transaction_destroy().
|
|
|
|
list_free(container->current.children);
|
2018-08-19 07:07:07 +02:00
|
|
|
list_free(container->current.ws_floating);
|
2018-06-03 08:35:06 +02:00
|
|
|
|
2018-06-23 08:24:11 +02:00
|
|
|
memcpy(&container->current, &instruction->state,
|
|
|
|
sizeof(struct sway_container_state));
|
Correctly track saved surfaces during multiple transactions
Fixes #2364.
Suppose a view is 600px wide, and we tell it to resize to 601px during a
resize operation. We create a transaction, save the 600px buffer and
send the configure. This buffer is saved into the associated
instruction, and is rendered while we wait for the view to commit a
601px buffer.
Before the view commits the 601px buffer, suppose we tell it to resize
to 602px. The new transaction will also save the buffer, but it's still
the 600px buffer because we haven't received a new one yet.
Then suppose the view commits its original 601px buffer. This completes
the first transaction, so we apply the 601px width to the container.
There's still the second (now only) transaction remaining, so we render
the saved buffer from that. But this is still the 600px buffer, and we
believe it's 601px. Whoops.
The problem here is we can't stack buffers like this. So this commit
removes the saved buffer from the instructions, places it in the view
instead, and re-saves the latest buffer every time the view completes a
transaction and still has further pending transactions.
As saved buffers are now specific to views rather than instructions, the
functions for saving and removing the saved buffer have been moved to
view.c.
The calls to save and restore the buffer have been relocated to more
appropriate functions too, favouring transaction_commit and
transaction_apply rather than transaction_add_container and
transaction_destroy.
2018-08-01 08:23:11 +02:00
|
|
|
|
2018-08-15 02:03:55 +02:00
|
|
|
if (container->type == C_VIEW && container->sway_view->saved_buffer) {
|
2018-08-20 00:54:58 +02:00
|
|
|
if (!container->destroying || container->ntxnrefs == 1) {
|
|
|
|
view_remove_saved_buffer(container->sway_view);
|
|
|
|
}
|
Correctly track saved surfaces during multiple transactions
Fixes #2364.
Suppose a view is 600px wide, and we tell it to resize to 601px during a
resize operation. We create a transaction, save the 600px buffer and
send the configure. This buffer is saved into the associated
instruction, and is rendered while we wait for the view to commit a
601px buffer.
Before the view commits the 601px buffer, suppose we tell it to resize
to 602px. The new transaction will also save the buffer, but it's still
the 600px buffer because we haven't received a new one yet.
Then suppose the view commits its original 601px buffer. This completes
the first transaction, so we apply the 601px width to the container.
There's still the second (now only) transaction remaining, so we render
the saved buffer from that. But this is still the 600px buffer, and we
believe it's 601px. Whoops.
The problem here is we can't stack buffers like this. So this commit
removes the saved buffer from the instructions, places it in the view
instead, and re-saves the latest buffer every time the view completes a
transaction and still has further pending transactions.
As saved buffers are now specific to views rather than instructions, the
functions for saving and removing the saved buffer have been moved to
view.c.
The calls to save and restore the buffer have been relocated to more
appropriate functions too, favouring transaction_commit and
transaction_apply rather than transaction_add_container and
transaction_destroy.
2018-08-01 08:23:11 +02:00
|
|
|
}
|
2018-08-15 02:03:55 +02:00
|
|
|
|
2018-08-18 07:10:06 +02:00
|
|
|
// Damage the new location
|
|
|
|
desktop_damage_whole_container(container);
|
|
|
|
if (container->type == C_VIEW && container->sway_view->surface) {
|
|
|
|
struct sway_view *view = container->sway_view;
|
|
|
|
struct wlr_surface *surface = view->surface;
|
|
|
|
struct wlr_box box = {
|
|
|
|
.x = container->current.view_x - view->geometry.x,
|
|
|
|
.y = container->current.view_y - view->geometry.y,
|
|
|
|
.width = surface->current.width,
|
|
|
|
.height = surface->current.height,
|
|
|
|
};
|
|
|
|
desktop_damage_box(&box);
|
|
|
|
}
|
|
|
|
|
2018-08-15 02:03:55 +02:00
|
|
|
container->instruction = NULL;
|
2018-08-19 03:01:51 +02:00
|
|
|
if (container->type == C_CONTAINER || container->type == C_VIEW) {
|
|
|
|
container_discover_outputs(container);
|
|
|
|
}
|
2018-06-03 08:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-12 02:44:45 +02:00
|
|
|
static void transaction_commit(struct sway_transaction *transaction);
|
|
|
|
|
2018-06-25 08:50:01 +02:00
|
|
|
static void transaction_progress_queue() {
|
2018-08-12 02:44:45 +02:00
|
|
|
if (!server.transactions->length) {
|
|
|
|
return;
|
2018-08-11 12:04:44 +02:00
|
|
|
}
|
2018-08-12 02:44:45 +02:00
|
|
|
// There's only ever one committed transaction,
|
|
|
|
// and it's the first one in the queue.
|
|
|
|
struct sway_transaction *transaction = server.transactions->items[0];
|
|
|
|
if (transaction->num_waiting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
transaction_apply(transaction);
|
|
|
|
transaction_destroy(transaction);
|
|
|
|
list_del(server.transactions, 0);
|
|
|
|
|
|
|
|
if (!server.transactions->length) {
|
|
|
|
idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's a bunch of consecutive transactions which all apply to the
|
|
|
|
// same views, skip all except the last one.
|
|
|
|
while (server.transactions->length >= 2) {
|
|
|
|
struct sway_transaction *a = server.transactions->items[0];
|
|
|
|
struct sway_transaction *b = server.transactions->items[1];
|
|
|
|
if (a->con_ids == b->con_ids) {
|
|
|
|
list_del(server.transactions, 0);
|
|
|
|
transaction_destroy(a);
|
|
|
|
} else {
|
|
|
|
break;
|
2018-06-27 11:07:48 +02:00
|
|
|
}
|
2018-06-24 04:33:23 +02:00
|
|
|
}
|
2018-08-12 02:44:45 +02:00
|
|
|
|
|
|
|
transaction = server.transactions->items[0];
|
|
|
|
transaction_commit(transaction);
|
|
|
|
transaction_progress_queue();
|
2018-06-24 04:33:23 +02:00
|
|
|
}
|
|
|
|
|
2018-06-03 08:35:06 +02:00
|
|
|
static int handle_timeout(void *data) {
|
|
|
|
struct sway_transaction *transaction = data;
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Transaction %p timed out (%li waiting)",
|
2018-06-03 08:35:06 +02:00
|
|
|
transaction, transaction->num_waiting);
|
2018-06-24 04:33:23 +02:00
|
|
|
transaction->num_waiting = 0;
|
2018-06-25 08:50:01 +02:00
|
|
|
transaction_progress_queue();
|
2018-06-03 08:35:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-24 04:33:23 +02:00
|
|
|
static bool should_configure(struct sway_container *con,
|
|
|
|
struct sway_transaction_instruction *instruction) {
|
|
|
|
if (con->type != C_VIEW) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (con->destroying) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-15 02:03:55 +02:00
|
|
|
if (con->current.view_width == instruction->state.view_width &&
|
|
|
|
con->current.view_height == instruction->state.view_height) {
|
2018-06-24 04:33:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-14 15:14:55 +02:00
|
|
|
static void transaction_commit(struct sway_transaction *transaction) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Transaction %p committing with %i instructions",
|
2018-06-03 08:35:06 +02:00
|
|
|
transaction, transaction->instructions->length);
|
|
|
|
transaction->num_waiting = 0;
|
|
|
|
for (int i = 0; i < transaction->instructions->length; ++i) {
|
|
|
|
struct sway_transaction_instruction *instruction =
|
|
|
|
transaction->instructions->items[i];
|
2018-06-06 14:57:34 +02:00
|
|
|
struct sway_container *con = instruction->container;
|
2018-06-24 04:33:23 +02:00
|
|
|
if (should_configure(con, instruction)) {
|
2018-06-06 14:57:34 +02:00
|
|
|
instruction->serial = view_configure(con->sway_view,
|
2018-06-03 08:35:06 +02:00
|
|
|
instruction->state.view_x,
|
|
|
|
instruction->state.view_y,
|
|
|
|
instruction->state.view_width,
|
|
|
|
instruction->state.view_height);
|
2018-06-24 15:01:09 +02:00
|
|
|
++transaction->num_waiting;
|
2018-08-12 02:44:45 +02:00
|
|
|
transaction->con_ids ^= con->id;
|
2018-06-30 06:30:14 +02:00
|
|
|
|
|
|
|
// From here on we are rendering a saved buffer of the view, which
|
|
|
|
// means we can send a frame done event to make the client redraw it
|
|
|
|
// as soon as possible. Additionally, this is required if a view is
|
|
|
|
// mapping and its default geometry doesn't intersect an output.
|
|
|
|
struct timespec when;
|
|
|
|
wlr_surface_send_frame_done(con->sway_view->surface, &when);
|
2018-08-02 12:54:03 +02:00
|
|
|
}
|
2018-08-20 00:54:58 +02:00
|
|
|
if (con->type == C_VIEW && !con->sway_view->saved_buffer) {
|
2018-08-02 12:54:03 +02:00
|
|
|
view_save_buffer(con->sway_view);
|
2018-08-18 07:10:06 +02:00
|
|
|
memcpy(&con->sway_view->saved_geometry, &con->sway_view->geometry,
|
|
|
|
sizeof(struct wlr_box));
|
2018-06-03 08:35:06 +02:00
|
|
|
}
|
2018-08-15 02:03:55 +02:00
|
|
|
con->instruction = instruction;
|
2018-06-03 08:35:06 +02:00
|
|
|
}
|
2018-06-25 01:25:51 +02:00
|
|
|
transaction->num_configures = transaction->num_waiting;
|
2018-08-18 08:58:50 +02:00
|
|
|
if (debug.txn_timings) {
|
2018-06-25 01:09:43 +02:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &transaction->commit_time);
|
|
|
|
}
|
2018-08-18 08:58:50 +02:00
|
|
|
if (debug.noatomic) {
|
|
|
|
transaction->num_waiting = 0;
|
|
|
|
} else if (debug.txn_wait) {
|
|
|
|
// Force the transaction to time out even if all views are ready.
|
|
|
|
// We do this by inflating the waiting counter.
|
|
|
|
transaction->num_waiting += 1000000;
|
|
|
|
}
|
2018-06-03 08:35:06 +02:00
|
|
|
|
2018-06-24 04:33:23 +02:00
|
|
|
if (transaction->num_waiting) {
|
|
|
|
// Set up a timer which the views must respond within
|
|
|
|
transaction->timer = wl_event_loop_add_timer(server.wl_event_loop,
|
|
|
|
handle_timeout, transaction);
|
2018-07-28 01:22:37 +02:00
|
|
|
if (transaction->timer) {
|
2018-08-18 08:58:50 +02:00
|
|
|
wl_event_source_timer_update(transaction->timer,
|
|
|
|
server.txn_timeout_ms);
|
2018-07-28 01:22:37 +02:00
|
|
|
} else {
|
2018-07-28 02:00:04 +02:00
|
|
|
wlr_log(WLR_ERROR, "Unable to create transaction timer (%s). "
|
|
|
|
"Some imperfect frames might be rendered.",
|
|
|
|
strerror(errno));
|
2018-08-18 08:58:50 +02:00
|
|
|
transaction->num_waiting = 0;
|
2018-07-28 01:22:37 +02:00
|
|
|
}
|
2018-06-24 04:33:23 +02:00
|
|
|
}
|
2018-06-23 08:24:11 +02:00
|
|
|
|
|
|
|
// The debug tree shows the pending/live tree. Here is a good place to
|
|
|
|
// update it, because we make a transaction every time we change the pending
|
|
|
|
// tree.
|
|
|
|
update_debug_tree();
|
2018-06-03 08:35:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:09 +02:00
|
|
|
static void set_instruction_ready(
|
|
|
|
struct sway_transaction_instruction *instruction) {
|
2018-06-25 01:25:51 +02:00
|
|
|
struct sway_transaction *transaction = instruction->transaction;
|
|
|
|
|
2018-08-18 08:58:50 +02:00
|
|
|
if (debug.txn_timings) {
|
2018-06-25 01:25:51 +02:00
|
|
|
struct timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
struct timespec *start = &transaction->commit_time;
|
|
|
|
float ms = (now.tv_sec - start->tv_sec) * 1000 +
|
|
|
|
(now.tv_nsec - start->tv_nsec) / 1000000.0;
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Transaction %p: %li/%li ready in %.1fms (%s)",
|
2018-06-25 01:25:51 +02:00
|
|
|
transaction,
|
|
|
|
transaction->num_configures - transaction->num_waiting + 1,
|
|
|
|
transaction->num_configures, ms,
|
|
|
|
instruction->container->name);
|
|
|
|
}
|
2018-06-23 08:24:11 +02:00
|
|
|
|
2018-06-24 04:33:23 +02:00
|
|
|
// If the transaction has timed out then its num_waiting will be 0 already.
|
|
|
|
if (transaction->num_waiting > 0 && --transaction->num_waiting == 0) {
|
2018-08-18 08:58:50 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Transaction %p is ready", transaction);
|
|
|
|
wl_event_source_timer_update(transaction->timer, 0);
|
2018-06-03 08:35:06 +02:00
|
|
|
}
|
2018-06-23 08:24:11 +02:00
|
|
|
|
2018-08-15 02:03:55 +02:00
|
|
|
instruction->container->instruction = NULL;
|
2018-08-19 03:29:59 +02:00
|
|
|
transaction_progress_queue();
|
2018-06-27 11:07:48 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 02:03:55 +02:00
|
|
|
void transaction_notify_view_ready_by_serial(struct sway_view *view,
|
|
|
|
uint32_t serial) {
|
|
|
|
struct sway_transaction_instruction *instruction = view->swayc->instruction;
|
|
|
|
if (view->swayc->instruction->serial == serial) {
|
|
|
|
set_instruction_ready(instruction);
|
2018-06-24 15:01:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void transaction_notify_view_ready_by_size(struct sway_view *view,
|
|
|
|
int width, int height) {
|
2018-08-15 02:03:55 +02:00
|
|
|
struct sway_transaction_instruction *instruction = view->swayc->instruction;
|
|
|
|
if (instruction->state.view_width == width &&
|
|
|
|
instruction->state.view_height == height) {
|
|
|
|
set_instruction_ready(instruction);
|
2018-06-24 15:01:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-15 02:41:10 +02:00
|
|
|
void transaction_commit_dirty(void) {
|
2018-07-14 15:14:55 +02:00
|
|
|
if (!server.dirty_containers->length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct sway_transaction *transaction = transaction_create();
|
2018-08-15 02:03:55 +02:00
|
|
|
if (!transaction) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-14 15:14:55 +02:00
|
|
|
for (int i = 0; i < server.dirty_containers->length; ++i) {
|
|
|
|
struct sway_container *container = server.dirty_containers->items[i];
|
|
|
|
transaction_add_container(transaction, container);
|
|
|
|
container->dirty = false;
|
|
|
|
}
|
|
|
|
server.dirty_containers->length = 0;
|
2018-08-12 02:44:45 +02:00
|
|
|
|
|
|
|
list_add(server.transactions, transaction);
|
|
|
|
|
|
|
|
// There's only ever one committed transaction,
|
|
|
|
// and it's the first one in the queue.
|
|
|
|
if (server.transactions->length == 1) {
|
|
|
|
transaction_commit(transaction);
|
|
|
|
// Attempting to progress the queue here is useful
|
|
|
|
// if the transaction has nothing to wait for.
|
|
|
|
transaction_progress_queue();
|
|
|
|
}
|
2018-07-14 15:14:55 +02:00
|
|
|
}
|