output: remove output_add_listeners

Simplify the code by registering signals when outputs are created and removing
signals when they are destroyed.
This commit is contained in:
emersion 2019-01-17 21:49:06 +01:00
parent 5a0c4234b8
commit dc1eac0cf1
3 changed files with 39 additions and 31 deletions

View File

@ -144,8 +144,6 @@ void output_get_box(struct sway_output *output, struct wlr_box *box);
enum sway_container_layout output_get_default_layout( enum sway_container_layout output_get_default_layout(
struct sway_output *output); struct sway_output *output);
void output_add_listeners(struct sway_output *output);
void render_rect(struct wlr_output *wlr_output, void render_rect(struct wlr_output *wlr_output,
pixman_region32_t *output_damage, const struct wlr_box *_box, pixman_region32_t *output_damage, const struct wlr_box *_box,
float color[static 4]); float color[static 4]);

View File

@ -359,8 +359,7 @@ static void send_frame_done(struct sway_output *output, struct timespec *when) {
static void damage_handle_frame(struct wl_listener *listener, void *data) { static void damage_handle_frame(struct wl_listener *listener, void *data) {
struct sway_output *output = struct sway_output *output =
wl_container_of(listener, output, damage_frame); wl_container_of(listener, output, damage_frame);
if (!output->enabled || !output->wlr_output->enabled) {
if (!output->wlr_output->enabled) {
return; return;
} }
@ -475,6 +474,9 @@ void output_damage_whole_container(struct sway_output *output,
static void damage_handle_destroy(struct wl_listener *listener, void *data) { static void damage_handle_destroy(struct wl_listener *listener, void *data) {
struct sway_output *output = struct sway_output *output =
wl_container_of(listener, output, damage_destroy); wl_container_of(listener, output, damage_destroy);
if (!output->enabled) {
return;
}
output_disable(output); output_disable(output);
transaction_commit_dirty(); transaction_commit_dirty();
} }
@ -488,11 +490,22 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
} }
output_begin_destroy(output); output_begin_destroy(output);
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->mode.link);
wl_list_remove(&output->transform.link);
wl_list_remove(&output->scale.link);
wl_list_remove(&output->present.link);
wl_list_remove(&output->damage_destroy.link);
wl_list_remove(&output->damage_frame.link);
transaction_commit_dirty(); transaction_commit_dirty();
} }
static void handle_mode(struct wl_listener *listener, void *data) { static void handle_mode(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, mode); struct sway_output *output = wl_container_of(listener, output, mode);
if (!output->enabled) {
return;
}
arrange_layers(output); arrange_layers(output);
arrange_output(output); arrange_output(output);
transaction_commit_dirty(); transaction_commit_dirty();
@ -500,6 +513,9 @@ static void handle_mode(struct wl_listener *listener, void *data) {
static void handle_transform(struct wl_listener *listener, void *data) { static void handle_transform(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, transform); struct sway_output *output = wl_container_of(listener, output, transform);
if (!output->enabled) {
return;
}
arrange_layers(output); arrange_layers(output);
arrange_output(output); arrange_output(output);
transaction_commit_dirty(); transaction_commit_dirty();
@ -512,6 +528,9 @@ static void update_textures(struct sway_container *con, void *data) {
static void handle_scale(struct wl_listener *listener, void *data) { static void handle_scale(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, scale); struct sway_output *output = wl_container_of(listener, output, scale);
if (!output->enabled) {
return;
}
arrange_layers(output); arrange_layers(output);
output_for_each_container(output, update_textures, NULL); output_for_each_container(output, update_textures, NULL);
arrange_output(output); arrange_output(output);
@ -530,6 +549,10 @@ static void handle_present(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, present); struct sway_output *output = wl_container_of(listener, output, present);
struct wlr_output_event_present *output_event = data; struct wlr_output_event_present *output_event = data;
if (!output->enabled) {
return;
}
struct wlr_presentation_event event = { struct wlr_presentation_event event = {
.output = output->wlr_output, .output = output->wlr_output,
.tv_sec = (uint64_t)output_event->when->tv_sec, .tv_sec = (uint64_t)output_event->when->tv_sec,
@ -552,7 +575,21 @@ void handle_new_output(struct wl_listener *listener, void *data) {
} }
output->server = server; output->server = server;
output->damage = wlr_output_damage_create(wlr_output); output->damage = wlr_output_damage_create(wlr_output);
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
output->destroy.notify = handle_destroy; output->destroy.notify = handle_destroy;
wl_signal_add(&wlr_output->events.mode, &output->mode);
output->mode.notify = handle_mode;
wl_signal_add(&wlr_output->events.transform, &output->transform);
output->transform.notify = handle_transform;
wl_signal_add(&wlr_output->events.scale, &output->scale);
output->scale.notify = handle_scale;
wl_signal_add(&wlr_output->events.present, &output->present);
output->present.notify = handle_present;
wl_signal_add(&output->damage->events.frame, &output->damage_frame);
output->damage_frame.notify = damage_handle_frame;
wl_signal_add(&output->damage->events.destroy, &output->damage_destroy);
output->damage_destroy.notify = damage_handle_destroy;
struct output_config *oc = output_find_config(output); struct output_config *oc = output_find_config(output);
@ -564,12 +601,3 @@ void handle_new_output(struct wl_listener *listener, void *data) {
transaction_commit_dirty(); transaction_commit_dirty();
} }
void output_add_listeners(struct sway_output *output) {
output->mode.notify = handle_mode;
output->transform.notify = handle_transform;
output->scale.notify = handle_scale;
output->present.notify = handle_present;
output->damage_frame.notify = damage_handle_frame;
output->damage_destroy.notify = damage_handle_destroy;
}

View File

@ -57,7 +57,6 @@ struct sway_output *output_create(struct wlr_output *wlr_output) {
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
wlr_output->data = output; wlr_output->data = output;
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
wl_signal_init(&output->events.destroy); wl_signal_init(&output->events.destroy);
wl_list_insert(&root->all_outputs, &output->link); wl_list_insert(&root->all_outputs, &output->link);
@ -116,15 +115,6 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
input_manager_configure_xcursor(); input_manager_configure_xcursor();
wl_signal_add(&wlr_output->events.mode, &output->mode);
wl_signal_add(&wlr_output->events.transform, &output->transform);
wl_signal_add(&wlr_output->events.scale, &output->scale);
wl_signal_add(&wlr_output->events.present, &output->present);
wl_signal_add(&output->damage->events.frame, &output->damage_frame);
wl_signal_add(&output->damage->events.destroy, &output->damage_destroy);
output_add_listeners(output);
wl_signal_emit(&root->events.new_node, &output->node); wl_signal_emit(&root->events.new_node, &output->node);
arrange_layers(output); arrange_layers(output);
@ -233,13 +223,6 @@ void output_disable(struct sway_output *output) {
int index = list_find(root->outputs, output); int index = list_find(root->outputs, output);
list_del(root->outputs, index); list_del(root->outputs, index);
wl_list_remove(&output->mode.link);
wl_list_remove(&output->transform.link);
wl_list_remove(&output->scale.link);
wl_list_remove(&output->present.link);
wl_list_remove(&output->damage_destroy.link);
wl_list_remove(&output->damage_frame.link);
output->enabled = false; output->enabled = false;
arrange_root(); arrange_root();
@ -255,7 +238,6 @@ void output_begin_destroy(struct sway_output *output) {
node_set_dirty(&output->node); node_set_dirty(&output->node);
wl_list_remove(&output->link); wl_list_remove(&output->link);
wl_list_remove(&output->destroy.link);
output->wlr_output->data = NULL; output->wlr_output->data = NULL;
output->wlr_output = NULL; output->wlr_output = NULL;
} }