From c79eb98e68b9867df563f071743a2b3e476ba37f Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 19 Jul 2020 13:53:04 +0000 Subject: [PATCH] output: Add callbacks for change notification --- include/output.h | 10 +++++++++- src/output.c | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/output.h b/include/output.h index 0bab5db..20b8d1b 100644 --- a/include/output.h +++ b/include/output.h @@ -16,9 +16,9 @@ #pragma once -#include #include #include +#include struct zxdg_output_v1; @@ -41,6 +41,14 @@ struct output { char model[256]; char name[256]; char description[256]; + + bool is_dimension_changed; + bool is_transform_changed; + + void (*on_dimension_change)(struct output*); + void (*on_transform_change)(struct output*); + + void* userdata; }; struct output* output_new(struct wl_output* wl_output, uint32_t id); diff --git a/src/output.c b/src/output.c index 72c88cb..bccf4b5 100644 --- a/src/output.c +++ b/src/output.c @@ -123,6 +123,9 @@ static void output_handle_geometry(void* data, struct wl_output* wl_output, { struct output* output = data; + if (transform != (int32_t)output->transform) + output->is_transform_changed = true; + output->x = x; output->y = y; output->transform = transform; @@ -140,12 +143,25 @@ static void output_handle_mode(void* data, struct wl_output* wl_output, if (!(flags & WL_OUTPUT_MODE_CURRENT)) return; + if (width != (int32_t)output->width || height != (int32_t)output->height) + output->is_dimension_changed = true; + output->width = width; output->height = height; } static void output_handle_done(void* data, struct wl_output* wl_output) { + struct output* output = data; + + if (output->is_dimension_changed && output->on_dimension_change) + output->on_dimension_change(output); + + if (output->is_transform_changed && output->on_transform_change) + output->on_transform_change(output); + + output->is_dimension_changed = false; + output->is_transform_changed = false; } static void output_handle_scale(void* data, struct wl_output* wl_output,