logo

inaban

Distrustful Wayland Compositor (inspired by XMonad and dwm) git clone https://hacktivis.me/git/inaban.git
commit: 5a7d3c6e3f06fea2b67b709ffc58558788f409e6
parent b036b81e0afd5dcb1a729a81480aebfc915c64ee
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 10 May 2021 12:33:44 +0200

Handle new outputs

Diffstat:

Minaban.c41+++++++++++++++++++++++++++++++----------
Minaban.h1+
2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/inaban.c b/inaban.c @@ -578,6 +578,22 @@ output_frame(struct wl_listener *listener, void *data) wlr_output_commit(output->wlr_output); } +static void +handle_output_mode(struct wl_listener *listener, void *data) +{ + struct inaban_output *output = wl_container_of(listener, output, mode); + struct wlr_output *wlr_output = output->wlr_output; + + struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); + if(mode) + { + wlr_output_set_mode(wlr_output, mode); + } + + wlr_output_enable(wlr_output, true); + wlr_output_commit(wlr_output); +} + /* raised by the backend when a new output (aka display/monitor) becomes available */ static void server_new_output(struct wl_listener *listener, void *data) @@ -585,20 +601,19 @@ server_new_output(struct wl_listener *listener, void *data) struct inaban_server *server = wl_container_of(listener, server, new_output); struct wlr_output *wlr_output = data; - /* Some backends don't have modes. DRM+KMS does, and we need to set a mode - * before we can use the output. The mode is a tuple of (width, height, - * refresh rate), and each monitor supports only a specific set of modes. We - * just pick the first, a more sophisticated compositor would let the user - * configure it or pick the mode the display advertises as preferred. */ - if(!wl_list_empty(&wlr_output->modes)) + /* Allocates and configures our state for this output */ + struct inaban_output *output = calloc(1, sizeof(struct inaban_output)); + if(output == NULL) { + wlr_log_errno(WLR_ERROR, "Unable to allocate inaban output"); + return; + } + + struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); + if(mode) { - struct wlr_output_mode *mode = wl_container_of(wlr_output->modes.prev, mode, link); wlr_output_set_mode(wlr_output, mode); - wlr_output_commit(wlr_output); } - /* Allocates and configures our state for this output */ - struct inaban_output *output = calloc(1, sizeof(struct inaban_output)); output->wlr_output = wlr_output; output->server = server; /* Sets up a listener for the frame notify event. */ @@ -606,6 +621,9 @@ server_new_output(struct wl_listener *listener, void *data) wl_signal_add(&wlr_output->events.frame, &output->frame); wl_list_insert(&server->outputs, &output->link); + output->mode.notify = handle_output_mode; + wl_signal_add(&wlr_output->events.mode, &output->mode); + /* Adds this to the output layout. The add_auto function arranges outputs * from left-to-right in the order they appear. A more sophisticated * compositor would let the user configure the arrangement of outputs in the @@ -616,6 +634,9 @@ server_new_output(struct wl_listener *listener, void *data) * clients can see to find out information about the output (such as * DPI, scale factor, manufacturer, etc). */ wlr_output_create_global(wlr_output); + + wlr_output_enable(wlr_output, true); + wlr_output_commit(wlr_output); } /* Called when the surface is mapped, or ready to display on-screen. */ diff --git a/inaban.h b/inaban.h @@ -94,6 +94,7 @@ struct inaban_output struct inaban_server *server; struct wlr_output *wlr_output; struct wl_listener frame; + struct wl_listener mode; }; struct inaban_view