wio

a wayland wm stylised after plan9 rio - forked from git.sr.ht/~srcmpwn/wio
git clone git://src.gearsix.net/wio
Log | Files | Refs | Atom | Submodules | README | LICENSE

commit 97e22bf27b36ffb1c37feb86fbfca6ca6a1de2f7
parent f65bb0c47b79d9c038d00b7c85be96e6080b6474
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed,  9 Jan 2019 22:51:48 -0500

Handle new outputs

Diffstat:
Minclude/server.h | 13+++++++++++++
Mmain.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/include/server.h b/include/server.h @@ -3,12 +3,25 @@ #include <wayland-server.h> #include <wlr/backend.h> #include <wlr/render/wlr_renderer.h> +#include <wlr/types/wlr_output.h> struct wio_server { struct wl_display *wl_display; struct wlr_backend *backend; struct wlr_renderer *renderer; + + struct wl_list outputs; + + struct wl_listener new_output; +}; + +struct wio_output { + struct wl_list link; + struct wio_server *server; + struct wlr_output *wlr_output; + + struct wl_listener frame; }; #endif diff --git a/main.c b/main.c @@ -1,13 +1,60 @@ #define _POSIX_C_SOURCE 200112L #include <stdlib.h> +#include <time.h> #include <wayland-server.h> #include <wlr/backend.h> #include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_data_device.h> +#include <wlr/types/wlr_output.h> #include <wlr/render/wlr_renderer.h> #include <wlr/util/log.h> #include "server.h" +static void output_frame(struct wl_listener *listener, void *data) { + struct wio_output *output = wl_container_of(listener, output, frame); + struct wlr_renderer *renderer = output->server->renderer; + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + if (!wlr_output_make_current(output->wlr_output, NULL)) { + return; + } + + int width, height; + wlr_output_effective_resolution(output->wlr_output, &width, &height); + wlr_renderer_begin(renderer, width, height); + + float color[4] = {0.3, 0.3, 0.3, 1.0}; + wlr_renderer_clear(renderer, color); + // TODO: other stuff + wlr_renderer_end(renderer); + wlr_output_swap_buffers(output->wlr_output, NULL, NULL); +} + +static void server_new_output(struct wl_listener *listener, void *data) { + struct wio_server *server = + wl_container_of(listener, server, new_output); + struct wlr_output *wlr_output = data; + + 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); + } + + struct wio_output *output = calloc(1, sizeof(struct wio_output)); + output->wlr_output = wlr_output; + output->server = server; + output->frame.notify = output_frame; + wl_signal_add(&wlr_output->events.frame, &output->frame); + wl_list_insert(&server->outputs, &output->link); + + // TODO + //wlr_output_layout_add_auto(server->output_layout, wlr_output); + wlr_output_create_global(wlr_output); +} + int main(int argc, char **argv) { struct wio_server server; @@ -21,6 +68,10 @@ int main(int argc, char **argv) { wlr_compositor_create(server.wl_display, server.renderer); wlr_data_device_manager_create(server.wl_display); + wl_list_init(&server.outputs); + server.new_output.notify = server_new_output; + wl_signal_add(&server.backend->events.new_output, &server.new_output); + const char *socket = wl_display_add_socket_auto(server.wl_display); if (!socket) { wlr_backend_destroy(server.backend);