labwc/server.c
2019-12-26 21:37:31 +00:00

43 lines
1.8 KiB
C

#include "labwc.h"
void server_new_output(struct wl_listener *listener, void *data)
{
/* This event is rasied by the backend when a new output (aka a display or
* monitor) becomes available. */
struct tinywl_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)) {
struct wlr_output_mode *mode =
wl_container_of(wlr_output->modes.prev, mode, link);
wlr_output_set_mode(wlr_output, mode);
}
/* Allocates and configures our state for this output */
struct tinywl_output *output =
calloc(1, sizeof(struct tinywl_output));
output->wlr_output = wlr_output;
output->server = server;
/* Sets up a listener for the frame notify event. */
output->frame.notify = output_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&server->outputs, &output->link);
/* 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
* layout. */
wlr_output_layout_add_auto(server->output_layout, wlr_output);
/* Creating the global adds a wl_output global to the display, which Wayland
* clients can see to find out information about the output (such as
* DPI, scale factor, manufacturer, etc). */
wlr_output_create_global(wlr_output);
}