output: Add callbacks for change notification

pull/58/head
Andri Yngvason 2020-07-19 13:53:04 +00:00
parent f9b3d98f83
commit c79eb98e68
2 changed files with 25 additions and 1 deletions

View File

@ -16,9 +16,9 @@
#pragma once
#include <wayland-client-protocol.h>
#include <wayland-client.h>
#include <stdint.h>
#include <stdbool.h>
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);

View File

@ -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,