|
| 1 | +#include <wlr/types/wlr_fifo_v1.h> |
| 2 | +#include "sway/fifo.h" |
| 3 | +#include "sway/tree/view.h" |
| 4 | + |
| 5 | +void handle_output_commit(struct wl_listener *listener, void *data) { |
| 6 | + struct sway_fifo *fifo = |
| 7 | + wl_container_of(listener, fifo, output_commit); |
| 8 | + |
| 9 | + wlr_fifo_signal_barrier(fifo->wlr_fifo); |
| 10 | + wl_list_remove(&fifo->output_commit.link); |
| 11 | +} |
| 12 | + |
| 13 | +static void find_scene_buffer(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data) { |
| 14 | + struct wlr_scene_surface *scene_surface = |
| 15 | + wlr_scene_surface_try_from_buffer(buffer); |
| 16 | + struct sway_fifo *sway_fifo = user_data; |
| 17 | + |
| 18 | + if (scene_surface && scene_surface->surface == sway_fifo->wlr_fifo->surface && |
| 19 | + buffer->primary_output) { |
| 20 | + sway_fifo->output = buffer->primary_output->output; |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +void handle_fifo_barrier(struct wl_listener *listener, void *data) { |
| 25 | + struct sway_fifo *sway_fifo = |
| 26 | + wl_container_of(listener, sway_fifo, fifo_barrier); |
| 27 | + struct sway_view *view = |
| 28 | + view_from_wlr_surface(sway_fifo->wlr_fifo->surface); |
| 29 | + |
| 30 | + wlr_scene_node_for_each_buffer(&view->content_tree->node, find_scene_buffer, sway_fifo); |
| 31 | + if (sway_fifo->output) { |
| 32 | + sway_fifo->output_commit.notify = handle_output_commit; |
| 33 | + wl_signal_add(&sway_fifo->output->events.commit, &sway_fifo->output_commit); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +void handle_fifo_manager_create_fifo(struct wl_listener *listener, void *data) { |
| 38 | + struct wlr_fifo_v1 *wlr_fifo = data; |
| 39 | + |
| 40 | + struct sway_fifo *sway_fifo = calloc(1, sizeof(*sway_fifo)); |
| 41 | + sway_fifo->wlr_fifo = wlr_fifo; |
| 42 | + |
| 43 | + sway_fifo->fifo_barrier.notify = handle_fifo_barrier; |
| 44 | + wl_signal_add(&wlr_fifo->events.fifo_barrier, &sway_fifo->fifo_barrier); |
| 45 | +} |
0 commit comments