~kennylevinsen/wlsunset

44624870e38a51fabbaae96f22d8a31e6fc9123f — Kenny Levinsen 8 months ago 80fb589
Recreate controls on next set if gamma size is zero

If the output is currently disabled and has no CRTC, the exact gamma
details might not yet be known by the compositor, but compositors do not
send updates if the value changes.

Destroy the gamma control and let it be recreated on next temperature
set, hoping that we eventually get functioning size.
1 files changed, 15 insertions(+), 3 deletions(-)

M main.c
M main.c => main.c +15 -3
@@ 443,9 443,17 @@ static void gamma_control_handle_gamma_size(void *data,
		struct zwlr_gamma_control_v1 *gamma_control, uint32_t ramp_size) {
	(void)gamma_control;
	struct output *output = data;
	output->ramp_size = ramp_size;
	if (output->table_fd != -1) {
		close(output->table_fd);
		output->table_fd = -1;
	}
	output->ramp_size = ramp_size;
	if (ramp_size == 0) {
		// Maybe the output does not currently have a CRTC to tell us
		// the gamma size, let's clean up and retry on next set.
		zwlr_gamma_control_v1_destroy(output->gamma_control);
		output->gamma_control = NULL;
		return;
	}
	output->table_fd = create_gamma_table(ramp_size, &output->table);
	output->context->new_output = true;


@@ 635,9 643,13 @@ static void output_set_whitepoint(struct output *output, struct rgb *wp, double 
static void set_temperature(struct wl_list *outputs, int temp, double gamma) {
	struct rgb wp = calc_whitepoint(temp);
	struct output *output;
	fprintf(stderr, "setting temperature to %d K\n", temp);

	wl_list_for_each(output, outputs, link) {
		fprintf(stderr, "setting temperature on output %s (%d) to %d K\n",
				output->name, output->id, temp);
		if (output->gamma_control == NULL) {
			setup_gamma_control(output->context, output);
			continue;
		}
		output_set_whitepoint(output, &wp, gamma);
	}
}