Use backend commits for wlr-output-management-unstable-v1

This commit is contained in:
Simon Ser 2024-02-16 19:56:58 +01:00
parent 256dcdd547
commit 2a3a4cac25
3 changed files with 62 additions and 60 deletions

View File

@ -684,7 +684,8 @@ void merge_output_config(struct output_config *dst, struct output_config *src);
bool apply_output_config(struct output_config *oc, struct sway_output *output); bool apply_output_config(struct output_config *oc, struct sway_output *output);
bool test_output_config(struct output_config *oc, struct sway_output *output); void queue_output_config(struct output_config *oc,
struct sway_output *output, struct wlr_output_state *pending);
struct output_config *store_output_config(struct output_config *oc); struct output_config *store_output_config(struct output_config *oc);

View File

@ -384,7 +384,7 @@ static const uint32_t *bit_depth_preferences[] = {
}, },
}; };
static void queue_output_config(struct output_config *oc, void queue_output_config(struct output_config *oc,
struct sway_output *output, struct wlr_output_state *pending) { struct sway_output *output, struct wlr_output_state *pending) {
if (output == root->fallback_output) { if (output == root->fallback_output) {
return; return;
@ -594,17 +594,6 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
return true; return true;
} }
bool test_output_config(struct output_config *oc, struct sway_output *output) {
if (output == root->fallback_output) {
return false;
}
struct wlr_output_state pending = {0};
wlr_output_state_init(&pending, output->wlr_output);
queue_output_config(oc, output, &pending);
return wlr_output_test_state(output->wlr_output, &pending);
}
static void default_output_config(struct output_config *oc, static void default_output_config(struct output_config *oc,
struct wlr_output *wlr_output) { struct wlr_output *wlr_output) {
oc->enabled = 1; oc->enabled = 1;

View File

@ -545,39 +545,16 @@ void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data) {
wlr_output_schedule_frame(output->wlr_output); wlr_output_schedule_frame(output->wlr_output);
} }
static void output_manager_apply(struct sway_server *server, static struct output_config *output_manager_create_config(struct sway_output *output,
struct wlr_output_configuration_v1 *config, bool test_only) { struct wlr_output_configuration_head_v1 *config_head) {
// TODO: perform atomic tests on the whole backend atomically sway_assert(output != root->fallback_output, "Tried configuring fallback output");
struct wlr_output_configuration_head_v1 *config_head;
// First disable outputs we need to disable
bool ok = true;
wl_list_for_each(config_head, &config->heads, link) {
struct wlr_output *wlr_output = config_head->state.output;
struct sway_output *output = wlr_output->data;
if (!output->enabled || config_head->state.enabled) {
continue;
}
struct output_config *oc = new_output_config(output->wlr_output->name); struct output_config *oc = new_output_config(output->wlr_output->name);
oc->enabled = false; oc->enabled = config_head->state.enabled;
if (!oc->enabled) {
if (test_only) { return oc;
ok &= test_output_config(oc, output);
} else {
oc = store_output_config(oc);
ok &= apply_output_config(oc, output);
}
} }
// Then enable outputs that need to
wl_list_for_each(config_head, &config->heads, link) {
struct wlr_output *wlr_output = config_head->state.output;
struct sway_output *output = wlr_output->data;
if (!config_head->state.enabled) {
continue;
}
struct output_config *oc = new_output_config(output->wlr_output->name);
oc->enabled = true;
if (config_head->state.mode != NULL) { if (config_head->state.mode != NULL) {
struct wlr_output_mode *mode = config_head->state.mode; struct wlr_output_mode *mode = config_head->state.mode;
oc->width = mode->width; oc->width = mode->width;
@ -595,14 +572,37 @@ static void output_manager_apply(struct sway_server *server,
oc->scale = config_head->state.scale; oc->scale = config_head->state.scale;
oc->adaptive_sync = config_head->state.adaptive_sync_enabled; oc->adaptive_sync = config_head->state.adaptive_sync_enabled;
if (test_only) { return oc;
ok &= test_output_config(oc, output); }
} else {
oc = store_output_config(oc); static void output_manager_apply(struct sway_server *server,
ok &= apply_output_config(oc, output); struct wlr_output_configuration_v1 *config, bool test_only) {
} // TODO: perform atomic tests on the whole backend atomically
size_t states_len = wl_list_length(&config->heads);
struct wlr_output_state *states = calloc(states_len, sizeof(states[0]));
struct output_config **configs = calloc(states_len, sizeof(configs[0]));
size_t i = 0;
struct wlr_output_configuration_head_v1 *config_head;
wl_list_for_each(config_head, &config->heads, link) {
struct wlr_output *wlr_output = config_head->state.output;
struct sway_output *output = wlr_output->data;
struct output_config *oc = output_manager_create_config(output, config_head);
queue_output_config(oc, output, &states[i]);
// TODO: populate buffer if output is enabled
configs[i] = oc;
i++;
} }
bool ok = wlr_backend_test(server->backend, states, states_len);
if (!ok || test_only) {
goto out;
}
ok = wlr_backend_commit(server->backend, states, states_len);
out:
if (ok) { if (ok) {
wlr_output_configuration_v1_send_succeeded(config); wlr_output_configuration_v1_send_succeeded(config);
} else { } else {
@ -610,9 +610,21 @@ static void output_manager_apply(struct sway_server *server,
} }
wlr_output_configuration_v1_destroy(config); wlr_output_configuration_v1_destroy(config);
if (!test_only) { if (ok && !test_only) {
for (size_t i = 0; i < states_len; i++) {
struct output_config *oc = store_output_config(configs[i]);
apply_output_config(oc, states[i].output->data);
}
update_output_manager_config(server); update_output_manager_config(server);
} }
for (size_t i = 0; i < states_len; i++) {
wlr_output_state_finish(&states[i]);
}
free(states);
free(configs);
} }
void handle_output_manager_apply(struct wl_listener *listener, void *data) { void handle_output_manager_apply(struct wl_listener *listener, void *data) {