From 1efd5f819f9986bf27e390f4988359388606cea0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 11 Nov 2017 14:41:18 -0500 Subject: Wire up output frame loop --- sway/desktop/output.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 51363e76..6d0bebc5 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -1,21 +1,60 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include #include #include +#include #include "sway/server.h" #include "sway/container.h" #include "sway/workspace.h" +#include "sway/output.h" #include "log.h" +static void output_frame_notify(struct wl_listener *listener, void *data) { + struct sway_output *soutput = wl_container_of( + listener, soutput, frame); + struct wlr_output *wlr_output = data; + struct sway_server *server = soutput->server; + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + wlr_output_make_current(wlr_output); + wlr_renderer_begin(server->renderer, wlr_output); + + wlr_renderer_end(server->renderer); + wlr_output_swap_buffers(wlr_output); + + soutput->last_frame = now; +} + void output_add_notify(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, output_add); struct wlr_output *wlr_output = data; sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); - swayc_t *op = new_output(wlr_output); - if (!sway_assert(op, "Failed to allocate output")) { + + struct sway_output *output = calloc(1, sizeof(struct sway_output)); + output->wlr_output = wlr_output; + output->server = server; + + swayc_t *node = new_output(output); + if (!sway_assert(node, "Failed to allocate output")) { return; } + // Switch to workspace if we need to if (swayc_active_workspace() == NULL) { - swayc_t *ws = op->children->items[0]; + swayc_t *ws = node->children->items[0]; workspace_switch(ws); } + + output->frame.notify = output_frame_notify; + wl_signal_add(&wlr_output->events.frame, &output->frame); +} + +void output_remove_notify(struct wl_listener *listener, void *data) { + struct sway_server *server = wl_container_of(listener, server, output_remove); + struct wlr_output *wlr_output = data; + sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); + // TODO } -- cgit v1.2.3-54-g00ecf