mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 02:19:49 +01:00
Split wlr_output_configuration_head_v1
This commit is contained in:
parent
3a233b3fcc
commit
0b64ecc162
2 changed files with 131 additions and 77 deletions
|
@ -12,14 +12,13 @@
|
|||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
|
||||
struct wlr_output_configuration_v1;
|
||||
|
||||
struct wlr_output_manager_v1 {
|
||||
struct wl_display *display;
|
||||
struct wl_global *global;
|
||||
struct wl_list resources;
|
||||
struct wl_list resources; // wl_resource_get_link
|
||||
|
||||
struct wlr_output_configuration_v1 *current;
|
||||
struct wl_list heads; // wlr_output_head_v1::link
|
||||
uint32_t serial;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
|
@ -30,25 +29,37 @@ struct wlr_output_manager_v1 {
|
|||
void *data;
|
||||
};
|
||||
|
||||
// TODO: split this into multiple structs (state + output_head + output_configuration_head)
|
||||
struct wlr_output_configuration_head_v1 {
|
||||
struct wlr_output_configuration_v1 *config;
|
||||
struct wlr_output_head_v1_state {
|
||||
struct wlr_output *output;
|
||||
struct wl_list link;
|
||||
|
||||
// for current config only
|
||||
struct wl_list resources;
|
||||
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
struct wlr_output_head_v1 {
|
||||
struct wlr_output_head_v1_state state;
|
||||
struct wlr_output_manager_v1 *manager;
|
||||
struct wl_list link; // wlr_output_manager_v1::heads
|
||||
|
||||
struct wl_list resources; // wl_resource_get_link
|
||||
|
||||
struct wl_listener output_destroy;
|
||||
};
|
||||
|
||||
struct wlr_output_configuration_v1 {
|
||||
struct wl_list heads;
|
||||
struct wl_list heads; // wlr_output_configuration_head_v1::link
|
||||
uint32_t serial;
|
||||
};
|
||||
|
||||
struct wlr_output_configuration_head_v1 {
|
||||
struct wlr_output_head_v1_state state;
|
||||
struct wlr_output_configuration_v1 *config;
|
||||
struct wl_list link; // wlr_output_configuration_v1::heads
|
||||
|
||||
struct wl_resource *resource; // can be NULL
|
||||
|
||||
struct wl_listener output_destroy;
|
||||
};
|
||||
|
||||
struct wlr_output_manager_v1 *wlr_output_manager_v1_create(
|
||||
struct wl_display *display);
|
||||
void wlr_output_manager_v1_set_configuration(
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/types/wlr_output_management_v1.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/signal.h"
|
||||
#include "wlr-output-management-unstable-v1-protocol.h"
|
||||
|
||||
|
@ -16,14 +17,14 @@ static const uint32_t HEAD_STATE_ALL = HEAD_STATE_ENABLED;
|
|||
|
||||
|
||||
// Can return NULL if the head is inert
|
||||
static struct wlr_output_configuration_head_v1 *
|
||||
config_head_from_head_resource(struct wl_resource *resource) {
|
||||
static struct wlr_output_head_v1 *head_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource,
|
||||
&zwlr_output_head_v1_interface, NULL));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static void config_head_destroy(struct wlr_output_configuration_head_v1 *head) {
|
||||
static void head_destroy(struct wlr_output_head_v1 *head) {
|
||||
if (head == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -39,32 +40,68 @@ static void config_head_destroy(struct wlr_output_configuration_head_v1 *head) {
|
|||
free(head);
|
||||
}
|
||||
|
||||
static void config_head_handle_output_destroy(struct wl_listener *listener,
|
||||
static void head_handle_output_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output_configuration_head_v1 *head =
|
||||
struct wlr_output_head_v1 *head =
|
||||
wl_container_of(listener, head, output_destroy);
|
||||
config_head_destroy(head);
|
||||
head_destroy(head);
|
||||
}
|
||||
|
||||
struct wlr_output_configuration_head_v1 *
|
||||
wlr_output_configuration_head_v1_create(
|
||||
struct wlr_output_configuration_v1 *config, struct wlr_output *output) {
|
||||
struct wlr_output_configuration_head_v1 *head = calloc(1, sizeof(*head));
|
||||
static struct wlr_output_head_v1 *head_create(
|
||||
struct wlr_output_manager_v1 *manager, struct wlr_output *output) {
|
||||
struct wlr_output_head_v1 *head = calloc(1, sizeof(*head));
|
||||
if (head == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
head->config = config;
|
||||
head->output = output;
|
||||
head->manager = manager;
|
||||
head->state.output = output;
|
||||
wl_list_init(&head->resources);
|
||||
wl_list_insert(&config->heads, &head->link);
|
||||
head->output_destroy.notify = config_head_handle_output_destroy;
|
||||
wl_list_insert(&manager->heads, &head->link);
|
||||
head->output_destroy.notify = head_handle_output_destroy;
|
||||
wl_signal_add(&output->events.destroy, &head->output_destroy);
|
||||
return head;
|
||||
}
|
||||
|
||||
|
||||
static void config_head_destroy(
|
||||
struct wlr_output_configuration_head_v1 *config_head) {
|
||||
if (config_head == NULL) {
|
||||
return;
|
||||
}
|
||||
if (config_head->resource != NULL) {
|
||||
wl_resource_set_user_data(config_head->resource, NULL); // make inert
|
||||
}
|
||||
wl_list_remove(&config_head->link);
|
||||
wl_list_remove(&config_head->output_destroy.link);
|
||||
free(config_head);
|
||||
}
|
||||
|
||||
static void config_head_handle_output_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output_configuration_head_v1 *config_head =
|
||||
wl_container_of(listener, config_head, output_destroy);
|
||||
config_head_destroy(config_head);
|
||||
}
|
||||
|
||||
struct wlr_output_configuration_head_v1 *
|
||||
wlr_output_configuration_head_v1_create(
|
||||
struct wlr_output_configuration_v1 *config, struct wlr_output *output) {
|
||||
struct wlr_output_configuration_head_v1 *config_head =
|
||||
calloc(1, sizeof(*config_head));
|
||||
if (config_head == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
config_head->config = config;
|
||||
config_head->state.output = output;
|
||||
wl_list_insert(&config->heads, &config_head->link);
|
||||
config_head->output_destroy.notify = config_head_handle_output_destroy;
|
||||
wl_signal_add(&output->events.destroy, &config_head->output_destroy);
|
||||
return config_head;
|
||||
}
|
||||
|
||||
static const struct zwlr_output_configuration_head_v1_interface config_head_impl;
|
||||
|
||||
// Can return NULL if the configuration head is inert
|
||||
static struct wlr_output_configuration_head_v1 *config_head_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource,
|
||||
|
@ -77,9 +114,9 @@ static const struct zwlr_output_configuration_head_v1_interface config_head_impl
|
|||
};
|
||||
|
||||
static void config_head_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_output_configuration_head_v1 *head =
|
||||
struct wlr_output_configuration_head_v1 *config_head =
|
||||
config_head_from_resource(resource);
|
||||
config_head_destroy(head);
|
||||
config_head_destroy(config_head);
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,7 +133,7 @@ static struct wlr_output_configuration_head_v1 *config_create_head(
|
|||
struct wlr_output_configuration_v1 *config, struct wlr_output *output) {
|
||||
struct wlr_output_configuration_head_v1 *head;
|
||||
wl_list_for_each(head, &config->heads, link) {
|
||||
if (head->output == output) {
|
||||
if (head->state.output == output) {
|
||||
return NULL; // TODO: post already_configured_head error instead
|
||||
}
|
||||
}
|
||||
|
@ -109,12 +146,12 @@ static void config_handle_enable_head(struct wl_client *client,
|
|||
struct wlr_output_configuration_v1 *config =
|
||||
config_from_resource(config_resource);
|
||||
// Can be NULL if the head no longer exists
|
||||
struct wlr_output_configuration_head_v1 *existing_head =
|
||||
config_head_from_head_resource(head_resource);
|
||||
struct wlr_output_head_v1 *head = head_from_resource(head_resource);
|
||||
|
||||
// Create an inert resource if the head no longer exists
|
||||
struct wlr_output_configuration_head_v1 *config_head = NULL;
|
||||
if (existing_head != NULL) {
|
||||
config_head = config_create_head(config, existing_head->output);
|
||||
if (head != NULL) {
|
||||
config_head = config_create_head(config, head->state.output);
|
||||
if (config_head == NULL) {
|
||||
wl_resource_post_no_memory(config_resource);
|
||||
return;
|
||||
|
@ -131,9 +168,10 @@ static void config_handle_enable_head(struct wl_client *client,
|
|||
wl_resource_set_implementation(resource, &config_head_impl,
|
||||
config_head, config_head_handle_resource_destroy);
|
||||
|
||||
config_head->enabled = true;
|
||||
|
||||
// TODO: when the output is destroyed, make this resource inert
|
||||
if (config_head != NULL) {
|
||||
config_head->resource = resource;
|
||||
config_head->state.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void config_handle_disable_head(struct wl_client *client,
|
||||
|
@ -141,20 +179,19 @@ static void config_handle_disable_head(struct wl_client *client,
|
|||
struct wl_resource *head_resource) {
|
||||
struct wlr_output_configuration_v1 *config =
|
||||
config_from_resource(config_resource);
|
||||
struct wlr_output_configuration_head_v1 *existing_head =
|
||||
config_head_from_head_resource(head_resource);
|
||||
if (existing_head == NULL) {
|
||||
struct wlr_output_head_v1 *head = head_from_resource(head_resource);
|
||||
if (head == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_output_configuration_head_v1 *config_head =
|
||||
config_create_head(config, existing_head->output);
|
||||
config_create_head(config, head->state.output);
|
||||
if (config_head == NULL) {
|
||||
wl_resource_post_no_memory(config_resource);
|
||||
return;
|
||||
}
|
||||
|
||||
config_head->enabled = false;
|
||||
config_head->state.enabled = false;
|
||||
}
|
||||
|
||||
static void config_handle_apply(struct wl_client *client,
|
||||
|
@ -261,7 +298,10 @@ static void manager_handle_display_destroy(struct wl_listener *listener,
|
|||
wl_container_of(listener, manager, display_destroy);
|
||||
wlr_signal_emit_safe(&manager->events.destroy, manager);
|
||||
wl_list_remove(&manager->display_destroy.link);
|
||||
wlr_output_configuration_v1_destroy(manager->current);
|
||||
struct wlr_output_head_v1 *head, *tmp;
|
||||
wl_list_for_each_safe(head, tmp, &manager->heads, link) {
|
||||
head_destroy(head);
|
||||
}
|
||||
wl_global_destroy(manager->global);
|
||||
free(manager);
|
||||
}
|
||||
|
@ -294,20 +334,20 @@ static struct wlr_output_configuration_head_v1 *configuration_get_head(
|
|||
struct wlr_output_configuration_v1 *config, struct wlr_output *output) {
|
||||
struct wlr_output_configuration_head_v1 *head;
|
||||
wl_list_for_each(head, &config->heads, link) {
|
||||
if (head->output == output) {
|
||||
if (head->state.output == output) {
|
||||
return head;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void head_send_state(struct wlr_output_configuration_head_v1 *head,
|
||||
static void head_send_state(struct wlr_output_head_v1 *head,
|
||||
struct wl_resource *resource, uint32_t state) {
|
||||
if (state & HEAD_STATE_ENABLED) {
|
||||
zwlr_output_head_v1_send_enabled(resource, head->enabled);
|
||||
zwlr_output_head_v1_send_enabled(resource, head->state.enabled);
|
||||
}
|
||||
|
||||
if (!head->enabled) {
|
||||
if (!head->state.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -319,9 +359,8 @@ static void head_handle_resource_destroy(struct wl_resource *resource) {
|
|||
}
|
||||
|
||||
static void manager_send_head(struct wlr_output_manager_v1 *manager,
|
||||
struct wlr_output_configuration_head_v1 *head,
|
||||
struct wl_resource *manager_resource) {
|
||||
struct wlr_output *output = head->output;
|
||||
struct wlr_output_head_v1 *head, struct wl_resource *manager_resource) {
|
||||
struct wlr_output *output = head->state.output;
|
||||
|
||||
struct wl_client *client = wl_resource_get_client(manager_resource);
|
||||
uint32_t version = wl_resource_get_version(manager_resource);
|
||||
|
@ -355,12 +394,14 @@ static void manager_send_head(struct wlr_output_manager_v1 *manager,
|
|||
}
|
||||
|
||||
static void manager_update_head(struct wlr_output_manager_v1 *manager,
|
||||
struct wlr_output_configuration_head_v1 *head,
|
||||
struct wlr_output_configuration_head_v1 *next) {
|
||||
struct wlr_output_head_v1 *head,
|
||||
struct wlr_output_head_v1_state *next) {
|
||||
struct wlr_output_head_v1_state *current = &head->state;
|
||||
|
||||
uint32_t state = 0;
|
||||
if (head->enabled != next->enabled) {
|
||||
if (current->enabled != next->enabled) {
|
||||
state |= HEAD_STATE_ENABLED;
|
||||
head->enabled = next->enabled;
|
||||
current->enabled = next->enabled;
|
||||
}
|
||||
// TODO: update other properties
|
||||
|
||||
|
@ -373,32 +414,32 @@ static void manager_update_head(struct wlr_output_manager_v1 *manager,
|
|||
void wlr_output_manager_v1_set_configuration(
|
||||
struct wlr_output_manager_v1 *manager,
|
||||
struct wlr_output_configuration_v1 *config) {
|
||||
if (manager->current != NULL) {
|
||||
// Either update or destroy existing heads
|
||||
struct wlr_output_configuration_head_v1 *existing_head, *tmp;
|
||||
wl_list_for_each_safe(existing_head, tmp,
|
||||
&manager->current->heads, link) {
|
||||
struct wlr_output_configuration_head_v1 *updated_head =
|
||||
configuration_get_head(config, existing_head->output);
|
||||
if (updated_head != NULL) {
|
||||
manager_update_head(manager, existing_head, updated_head);
|
||||
config_head_destroy(updated_head);
|
||||
} else {
|
||||
config_head_destroy(existing_head);
|
||||
}
|
||||
// Either update or destroy existing heads
|
||||
struct wlr_output_head_v1 *existing_head, *head_tmp;
|
||||
wl_list_for_each_safe(existing_head, head_tmp, &manager->heads, link) {
|
||||
struct wlr_output_configuration_head_v1 *updated_head =
|
||||
configuration_get_head(config, existing_head->state.output);
|
||||
if (updated_head != NULL) {
|
||||
manager_update_head(manager, existing_head, &updated_head->state);
|
||||
config_head_destroy(updated_head);
|
||||
} else {
|
||||
head_destroy(existing_head);
|
||||
}
|
||||
|
||||
// Heads remaining in `config` are new heads
|
||||
} else {
|
||||
manager->current = wlr_output_configuration_v1_create();
|
||||
}
|
||||
|
||||
// Heads remaining in `config` are new heads
|
||||
|
||||
// Move new heads to current config
|
||||
struct wlr_output_configuration_head_v1 *head, *tmp;
|
||||
wl_list_for_each_safe(head, tmp, &config->heads, link) {
|
||||
head->config = manager->current;
|
||||
wl_list_remove(&head->link);
|
||||
wl_list_insert(&manager->current->heads, &head->link);
|
||||
struct wlr_output_configuration_head_v1 *config_head, *config_head_tmp;
|
||||
wl_list_for_each_safe(config_head, config_head_tmp, &config->heads, link) {
|
||||
struct wlr_output_head_v1 *head =
|
||||
head_create(manager, config_head->state.output);
|
||||
if (head == NULL) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
head->state = config_head->state;
|
||||
|
||||
struct wl_resource *manager_resource;
|
||||
wl_resource_for_each(manager_resource, &manager->resources) {
|
||||
|
@ -406,10 +447,12 @@ void wlr_output_manager_v1_set_configuration(
|
|||
}
|
||||
}
|
||||
|
||||
manager->current->serial = wl_display_next_serial(manager->display);
|
||||
wlr_output_configuration_v1_destroy(config);
|
||||
|
||||
manager->serial = wl_display_next_serial(manager->display);
|
||||
struct wl_resource *manager_resource;
|
||||
wl_resource_for_each(manager_resource, &manager->resources) {
|
||||
zwlr_output_manager_v1_send_done(manager_resource,
|
||||
manager->current->serial);
|
||||
manager->serial);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue