diff options
author | emersion <contact@emersion.fr> | 2019-01-17 21:49:06 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-01-18 10:08:34 +0100 |
commit | dc1eac0cf12593fa20122142f087bbb3bc8e7589 (patch) | |
tree | 50a2afd1535473a55a4fea1f312f7e604cace7eb /sway/desktop | |
parent | 5a0c4234b8f0ef5ad3d17430e876e29242b934e2 (diff) | |
download | sway-dc1eac0cf12593fa20122142f087bbb3bc8e7589.tar.xz |
output: remove output_add_listeners
Simplify the code by registering signals when outputs are created and removing
signals when they are destroyed.
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/output.c | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 04c9b4f6..3f6c3d87 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -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) { struct sway_output *output = wl_container_of(listener, output, damage_frame); - - if (!output->wlr_output->enabled) { + if (!output->enabled || !output->wlr_output->enabled) { 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) { struct sway_output *output = wl_container_of(listener, output, damage_destroy); + if (!output->enabled) { + return; + } output_disable(output); transaction_commit_dirty(); } @@ -488,11 +490,22 @@ static void handle_destroy(struct wl_listener *listener, void *data) { } 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(); } static void handle_mode(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, mode); + if (!output->enabled) { + return; + } arrange_layers(output); arrange_output(output); 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) { struct sway_output *output = wl_container_of(listener, output, transform); + if (!output->enabled) { + return; + } arrange_layers(output); arrange_output(output); 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) { struct sway_output *output = wl_container_of(listener, output, scale); + if (!output->enabled) { + return; + } arrange_layers(output); output_for_each_container(output, update_textures, NULL); 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 wlr_output_event_present *output_event = data; + if (!output->enabled) { + return; + } + struct wlr_presentation_event event = { .output = output->wlr_output, .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->damage = wlr_output_damage_create(wlr_output); + + wl_signal_add(&wlr_output->events.destroy, &output->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); @@ -564,12 +601,3 @@ void handle_new_output(struct wl_listener *listener, void *data) { 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; -} |