From 825f1b2dc6886071939f9b8b9738392cd8966cab Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Mon, 5 Dec 2022 21:30:39 +0300 Subject: [PATCH] tinywl: handle wlr_output.events.request_state --- tinywl/tinywl.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index ef993869..5ab795d6 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -73,6 +73,7 @@ struct tinywl_output { struct tinywl_server *server; struct wlr_output *wlr_output; struct wl_listener frame; + struct wl_listener request_state; struct wl_listener destroy; }; @@ -568,10 +569,20 @@ static void output_frame(struct wl_listener *listener, void *data) { wlr_scene_output_send_frame_done(scene_output, &now); } +static void output_request_state(struct wl_listener *listener, void *data) { + /* This function is called when the backend requests a new state for + * the output. For example, Wayland and X11 backends request a new mode + * when the output window is resized. */ + struct tinywl_output *output = wl_container_of(listener, output, request_state); + const struct wlr_output_event_request_state *event = data; + wlr_output_commit_state(output->wlr_output, event->state); +} + static void output_destroy(struct wl_listener *listener, void *data) { struct tinywl_output *output = wl_container_of(listener, output, destroy); wl_list_remove(&output->frame.link); + wl_list_remove(&output->request_state.link); wl_list_remove(&output->destroy.link); wl_list_remove(&output->link); free(output); @@ -607,11 +618,16 @@ static void server_new_output(struct wl_listener *listener, void *data) { calloc(1, sizeof(struct tinywl_output)); output->wlr_output = wlr_output; output->server = server; - /* Sets up a listener for the frame notify event. */ + + /* Sets up a listener for the frame event. */ output->frame.notify = output_frame; wl_signal_add(&wlr_output->events.frame, &output->frame); - /* Sets up a listener for the destroy notify event. */ + /* Sets up a listener for the state request event. */ + output->request_state.notify = output_request_state; + wl_signal_add(&wlr_output->events.request_state, &output->request_state); + + /* Sets up a listener for the destroy event. */ output->destroy.notify = output_destroy; wl_signal_add(&wlr_output->events.destroy, &output->destroy);