gamma-control-v1 now requires manual application of LUTs

This commit is contained in:
Keith Bowes 2023-06-27 12:30:02 -04:00
parent fd0c5b04d3
commit 2b38536dec
4 changed files with 52 additions and 19 deletions

View file

@ -18,10 +18,11 @@ struct wb_output {
struct wlr_scene_tree *shell_top;
} layers;
#if ! WLR_CHECK_VERSION(0, 17, 0)
/* DEPRECATED: Use a tool like swaybg instead */
#if ! WLR_CHECK_VERSION(0, 18, 0)
/* DEPRECATED: Use a tool like swaybg or hyprpaper instead */
struct wlr_scene_rect *background;
#endif
bool gamma_lut_changed;
struct wlr_box geometry;
struct wl_listener destroy;
@ -53,8 +54,9 @@ struct wb_view {
struct wlr_box previous_geometry;
};
void output_frame_notify(struct wl_listener* listener, void *data);
void output_destroy_notify(struct wl_listener* listener, void *data);
void new_output_notify(struct wl_listener* listener, void *data);
void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data);
void output_frame_notify(struct wl_listener *listener, void *data);
void output_destroy_notify(struct wl_listener *listener, void *data);
void new_output_notify(struct wl_listener *listener, void *data);
#endif /* output.h */

View file

@ -43,6 +43,7 @@ struct wb_server {
struct wlr_allocator *allocator;
struct wlr_backend *backend;
struct wlr_compositor *compositor;
struct wlr_gamma_control_manager_v1 *gamma_control_manager;
struct wlr_idle_notifier_v1 *idle_notifier;
struct wlr_output_layout *output_layout;
struct wlr_xdg_output_manager_v1 *output_manager;
@ -65,6 +66,7 @@ struct wb_server {
struct wlr_layer_shell_v1 *layer_shell;
struct wlr_xdg_shell *xdg_shell;
struct wl_listener gamma_control_set_gamma;
struct wl_listener new_layer_surface;
struct wl_listener new_xdg_surface;
struct wl_listener new_xdg_decoration;

View file

@ -10,12 +10,30 @@ void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_layout_get_box(output->server->output_layout,
output->wlr_output, &output->geometry);
#if ! WLR_CHECK_VERSION(0, 17, 0)
#if ! WLR_CHECK_VERSION(0, 18, 0)
/* Update the background for the current output size. */
wlr_scene_rect_set_size(output->background,
output->geometry.width, output->geometry.height);
#endif
if (output->gamma_lut_changed) {
output->gamma_lut_changed = false;
#if WLR_CHECK_VERSION(0, 17, 0)
struct wlr_gamma_control_v1 *gamma_control =
wlr_gamma_control_manager_v1_get_control(output->server->gamma_control_manager,
output->wlr_output);
if (!wlr_gamma_control_v1_apply(gamma_control, &output->wlr_output->pending)) {
return;
}
#endif
if (!wlr_output_test(output->wlr_output)) {
wlr_output_rollback(output->wlr_output);
#if WLR_CHECK_VERSION(0, 17, 0)
wlr_gamma_control_v1_send_failed_and_destroy(gamma_control);
#endif
}
}
/* Render the scene if needed and commit the output */
wlr_scene_output_commit(scene_output);
@ -32,6 +50,13 @@ void output_request_state_notify(struct wl_listener *listener, void *data) {
const struct wlr_output_event_request_state *event = data;
wlr_output_commit_state(output->wlr_output, event->state);
}
void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data) {
const struct wlr_gamma_control_manager_v1_set_gamma_event *event = data;
struct wb_output *output = event->output->data;
output->gamma_lut_changed = true;
wlr_output_schedule_frame(output->wlr_output);
}
#endif
void output_destroy_notify(struct wl_listener *listener, void *data) {
@ -68,19 +93,16 @@ void new_output_notify(struct wl_listener *listener, void *data) {
#if WLR_CHECK_VERSION(0, 17, 0)
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
struct wlr_output_state state;
wlr_output_state_init(&state);
wlr_output_state_set_enabled(&state, true);
if (mode != NULL) {
struct wlr_output_state state = {0};
wlr_output_state_set_mode(&state, mode);
wlr_output_state_set_enabled(&state, true);
if (!wlr_output_commit_state(wlr_output, &state)) {
wlr_output_state_finish(&state);
wlr_log_errno(WLR_ERROR, "%s", _("Couldn't commit state to output"));
return;
}
wlr_output_state_finish(&state);
}
wlr_output_state_finish(&state);
wlr_output_commit_state(wlr_output, &state);
#else
if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
@ -99,7 +121,7 @@ void new_output_notify(struct wl_listener *listener, void *data) {
output->wlr_output = wlr_output;
wlr_output->data = output;
#if ! WLR_CHECK_VERSION(0, 17, 0)
#if ! WLR_CHECK_VERSION(0, 18, 0)
/* Set the background color */
float color[4] = {0.1875, 0.1875, 0.1875, 1.0};
output->background = wlr_scene_rect_create(&server->scene->tree, 0, 0, color);

View file

@ -96,11 +96,18 @@ bool wb_start_server(struct wb_server* server) {
wlr_log(WLR_INFO, "%s: WAYLAND_DISPLAY=%s", _("Running Wayland compositor on Wayland display"), socket);
setenv("WAYLAND_DISPLAY", socket, true);
wlr_gamma_control_manager_v1_create(server->wl_display);
wlr_data_device_manager_create(server->wl_display);
server->gamma_control_manager =
wlr_gamma_control_manager_v1_create(server->wl_display);
#if WLR_CHECK_VERSION(0, 17, 0)
server->gamma_control_set_gamma.notify = handle_gamma_control_set_gamma;
wl_signal_add(&server->gamma_control_manager->events.set_gamma, &server->gamma_control_set_gamma);
#endif
wlr_screencopy_manager_v1_create(server->wl_display);
server->idle_notifier = wlr_idle_notifier_v1_create(server->wl_display);
wlr_data_device_manager_create(server->wl_display);
wl_list_init(&server->views);
init_xdg_decoration(server);
init_layer_shell(server);