aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/output.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2019-01-17 21:49:06 +0100
committerLibravatar emersion <contact@emersion.fr>2019-01-18 10:08:34 +0100
commitdc1eac0cf12593fa20122142f087bbb3bc8e7589 (patch)
tree50a2afd1535473a55a4fea1f312f7e604cace7eb /sway/desktop/output.c
parentMerge pull request #3447 from emersion/remove-swaylock-includes (diff)
downloadsway-dc1eac0cf12593fa20122142f087bbb3bc8e7589.tar.gz
sway-dc1eac0cf12593fa20122142f087bbb3bc8e7589.tar.zst
sway-dc1eac0cf12593fa20122142f087bbb3bc8e7589.zip
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/output.c')
-rw-r--r--sway/desktop/output.c50
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) {
359static void damage_handle_frame(struct wl_listener *listener, void *data) { 359static void damage_handle_frame(struct wl_listener *listener, void *data) {
360 struct sway_output *output = 360 struct sway_output *output =
361 wl_container_of(listener, output, damage_frame); 361 wl_container_of(listener, output, damage_frame);
362 362 if (!output->enabled || !output->wlr_output->enabled) {
363 if (!output->wlr_output->enabled) {
364 return; 363 return;
365 } 364 }
366 365
@@ -475,6 +474,9 @@ void output_damage_whole_container(struct sway_output *output,
475static void damage_handle_destroy(struct wl_listener *listener, void *data) { 474static void damage_handle_destroy(struct wl_listener *listener, void *data) {
476 struct sway_output *output = 475 struct sway_output *output =
477 wl_container_of(listener, output, damage_destroy); 476 wl_container_of(listener, output, damage_destroy);
477 if (!output->enabled) {
478 return;
479 }
478 output_disable(output); 480 output_disable(output);
479 transaction_commit_dirty(); 481 transaction_commit_dirty();
480} 482}
@@ -488,11 +490,22 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
488 } 490 }
489 output_begin_destroy(output); 491 output_begin_destroy(output);
490 492
493 wl_list_remove(&output->destroy.link);
494 wl_list_remove(&output->mode.link);
495 wl_list_remove(&output->transform.link);
496 wl_list_remove(&output->scale.link);
497 wl_list_remove(&output->present.link);
498 wl_list_remove(&output->damage_destroy.link);
499 wl_list_remove(&output->damage_frame.link);
500
491 transaction_commit_dirty(); 501 transaction_commit_dirty();
492} 502}
493 503
494static void handle_mode(struct wl_listener *listener, void *data) { 504static void handle_mode(struct wl_listener *listener, void *data) {
495 struct sway_output *output = wl_container_of(listener, output, mode); 505 struct sway_output *output = wl_container_of(listener, output, mode);
506 if (!output->enabled) {
507 return;
508 }
496 arrange_layers(output); 509 arrange_layers(output);
497 arrange_output(output); 510 arrange_output(output);
498 transaction_commit_dirty(); 511 transaction_commit_dirty();
@@ -500,6 +513,9 @@ static void handle_mode(struct wl_listener *listener, void *data) {
500 513
501static void handle_transform(struct wl_listener *listener, void *data) { 514static void handle_transform(struct wl_listener *listener, void *data) {
502 struct sway_output *output = wl_container_of(listener, output, transform); 515 struct sway_output *output = wl_container_of(listener, output, transform);
516 if (!output->enabled) {
517 return;
518 }
503 arrange_layers(output); 519 arrange_layers(output);
504 arrange_output(output); 520 arrange_output(output);
505 transaction_commit_dirty(); 521 transaction_commit_dirty();
@@ -512,6 +528,9 @@ static void update_textures(struct sway_container *con, void *data) {
512 528
513static void handle_scale(struct wl_listener *listener, void *data) { 529static void handle_scale(struct wl_listener *listener, void *data) {
514 struct sway_output *output = wl_container_of(listener, output, scale); 530 struct sway_output *output = wl_container_of(listener, output, scale);
531 if (!output->enabled) {
532 return;
533 }
515 arrange_layers(output); 534 arrange_layers(output);
516 output_for_each_container(output, update_textures, NULL); 535 output_for_each_container(output, update_textures, NULL);
517 arrange_output(output); 536 arrange_output(output);
@@ -530,6 +549,10 @@ static void handle_present(struct wl_listener *listener, void *data) {
530 struct sway_output *output = wl_container_of(listener, output, present); 549 struct sway_output *output = wl_container_of(listener, output, present);
531 struct wlr_output_event_present *output_event = data; 550 struct wlr_output_event_present *output_event = data;
532 551
552 if (!output->enabled) {
553 return;
554 }
555
533 struct wlr_presentation_event event = { 556 struct wlr_presentation_event event = {
534 .output = output->wlr_output, 557 .output = output->wlr_output,
535 .tv_sec = (uint64_t)output_event->when->tv_sec, 558 .tv_sec = (uint64_t)output_event->when->tv_sec,
@@ -552,7 +575,21 @@ void handle_new_output(struct wl_listener *listener, void *data) {
552 } 575 }
553 output->server = server; 576 output->server = server;
554 output->damage = wlr_output_damage_create(wlr_output); 577 output->damage = wlr_output_damage_create(wlr_output);
578
579 wl_signal_add(&wlr_output->events.destroy, &output->destroy);
555 output->destroy.notify = handle_destroy; 580 output->destroy.notify = handle_destroy;
581 wl_signal_add(&wlr_output->events.mode, &output->mode);
582 output->mode.notify = handle_mode;
583 wl_signal_add(&wlr_output->events.transform, &output->transform);
584 output->transform.notify = handle_transform;
585 wl_signal_add(&wlr_output->events.scale, &output->scale);
586 output->scale.notify = handle_scale;
587 wl_signal_add(&wlr_output->events.present, &output->present);
588 output->present.notify = handle_present;
589 wl_signal_add(&output->damage->events.frame, &output->damage_frame);
590 output->damage_frame.notify = damage_handle_frame;
591 wl_signal_add(&output->damage->events.destroy, &output->damage_destroy);
592 output->damage_destroy.notify = damage_handle_destroy;
556 593
557 struct output_config *oc = output_find_config(output); 594 struct output_config *oc = output_find_config(output);
558 595
@@ -564,12 +601,3 @@ void handle_new_output(struct wl_listener *listener, void *data) {
564 601
565 transaction_commit_dirty(); 602 transaction_commit_dirty();
566} 603}
567
568void output_add_listeners(struct sway_output *output) {
569 output->mode.notify = handle_mode;
570 output->transform.notify = handle_transform;
571 output->scale.notify = handle_scale;
572 output->present.notify = handle_present;
573 output->damage_frame.notify = damage_handle_frame;
574 output->damage_destroy.notify = damage_handle_destroy;
575}