Handle gamma-control-v1 set_gamma events

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4046
master
Simon Ser 2 years ago
parent 913a7679cb
commit b1b3563d54

@ -57,6 +57,7 @@ struct sway_output {
uint32_t refresh_nsec; uint32_t refresh_nsec;
int max_render_time; // In milliseconds int max_render_time; // In milliseconds
struct wl_event_source *repaint_timer; struct wl_event_source *repaint_timer;
bool gamma_lut_changed;
}; };
struct sway_output_non_desktop { struct sway_output_non_desktop {
@ -187,6 +188,8 @@ enum wlr_direction opposite_direction(enum wlr_direction d);
void handle_output_layout_change(struct wl_listener *listener, void *data); void handle_output_layout_change(struct wl_listener *listener, void *data);
void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data);
void handle_output_manager_apply(struct wl_listener *listener, void *data); void handle_output_manager_apply(struct wl_listener *listener, void *data);
void handle_output_manager_test(struct wl_listener *listener, void *data); void handle_output_manager_test(struct wl_listener *listener, void *data);

@ -91,6 +91,9 @@ struct sway_server {
struct wl_listener output_manager_apply; struct wl_listener output_manager_apply;
struct wl_listener output_manager_test; struct wl_listener output_manager_test;
struct wlr_gamma_control_manager_v1 *gamma_control_manager_v1;
struct wl_listener gamma_control_set_gamma;
struct { struct {
bool locked; bool locked;
struct wlr_session_lock_manager_v1 *manager; struct wlr_session_lock_manager_v1 *manager;

@ -9,6 +9,7 @@
#include <wlr/render/swapchain.h> #include <wlr/render/swapchain.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h> #include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
@ -564,6 +565,7 @@ static int output_repaint_timer_handler(void *data) {
wlr_output->frame_pending = false; wlr_output->frame_pending = false;
if (!wlr_output->needs_frame && if (!wlr_output->needs_frame &&
!output->gamma_lut_changed &&
!pixman_region32_not_empty(&output->damage_ring.current)) { !pixman_region32_not_empty(&output->damage_ring.current)) {
return 0; return 0;
} }
@ -578,6 +580,19 @@ static int output_repaint_timer_handler(void *data) {
fullscreen_con = workspace->current.fullscreen; fullscreen_con = workspace->current.fullscreen;
} }
if (output->gamma_lut_changed) {
struct wlr_gamma_control_v1 *gamma_control =
wlr_gamma_control_manager_v1_get_control(
server.gamma_control_manager_v1, wlr_output);
if (!wlr_gamma_control_v1_apply(gamma_control, &wlr_output->pending)) {
return 0;
}
if (!wlr_output_test(wlr_output)) {
wlr_output_rollback(wlr_output);
wlr_gamma_control_v1_send_failed_and_destroy(gamma_control);
}
}
pixman_region32_t frame_damage; pixman_region32_t frame_damage;
get_frame_damage(output, &frame_damage); get_frame_damage(output, &frame_damage);
wlr_output_set_damage(wlr_output, &frame_damage); wlr_output_set_damage(wlr_output, &frame_damage);
@ -1076,6 +1091,16 @@ void handle_output_layout_change(struct wl_listener *listener,
update_output_manager_config(server); update_output_manager_config(server);
} }
void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data) {
struct sway_server *server =
wl_container_of(listener, server, gamma_control_set_gamma);
const struct wlr_gamma_control_manager_v1_set_gamma_event *event = data;
struct sway_output *output = event->output->data;
output->gamma_lut_changed = true;
wlr_output_schedule_frame(output->wlr_output);
}
static void output_manager_apply(struct sway_server *server, static void output_manager_apply(struct sway_server *server,
struct wlr_output_configuration_v1 *config, bool test_only) { struct wlr_output_configuration_v1 *config, bool test_only) {
// TODO: perform atomic tests on the whole backend atomically // TODO: perform atomic tests on the whole backend atomically

@ -114,7 +114,11 @@ bool server_init(struct sway_server *server) {
server->data_device_manager = server->data_device_manager =
wlr_data_device_manager_create(server->wl_display); wlr_data_device_manager_create(server->wl_display);
server->gamma_control_manager_v1 =
wlr_gamma_control_manager_v1_create(server->wl_display); wlr_gamma_control_manager_v1_create(server->wl_display);
server->gamma_control_set_gamma.notify = handle_gamma_control_set_gamma;
wl_signal_add(&server->gamma_control_manager_v1->events.set_gamma,
&server->gamma_control_set_gamma);
server->new_output.notify = handle_new_output; server->new_output.notify = handle_new_output;
wl_signal_add(&server->backend->events.new_output, &server->new_output); wl_signal_add(&server->backend->events.new_output, &server->new_output);

Loading…
Cancel
Save