Skip to content

Commit d343327

Browse files
sergio-gdrSergio Gómez
authored and
Sergio Gómez
committed
fifo-v1: implement protocol
Signed-off-by: Sergio Gómez <[email protected]>
1 parent 9a9be01 commit d343327

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

include/sway/fifo.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef _SWAY_FIFO_H
2+
#define _SWAY_FIFO_H
3+
4+
#include "util.h"
5+
6+
struct sway_fifo {
7+
struct wlr_fifo_v1 *wlr_fifo;
8+
9+
struct wlr_output *output;
10+
11+
struct wl_listener fifo_barrier;
12+
struct wl_listener output_commit;
13+
};
14+
15+
void handle_fifo_barrier(struct wl_listener *listener, void *data);
16+
17+
void handle_fifo_manager_create_fifo(struct wl_listener *listener, void *data);
18+
19+
#endif

include/sway/server.h

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ struct sway_server {
8989
struct wlr_gamma_control_manager_v1 *gamma_control_manager_v1;
9090
struct wl_listener gamma_control_set_gamma;
9191

92+
struct wlr_fifo_v1_manager *fifo_manager;
93+
struct wl_listener fifo_create;
94+
9295
struct {
9396
struct sway_session_lock *lock;
9497
struct wlr_session_lock_manager_v1 *manager;

sway/fifo.c

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

sway/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sway_sources = files(
33
'config.c',
44
'criteria.c',
55
'decoration.c',
6+
'fifo.c',
67
'ipc-json.c',
78
'ipc-server.c',
89
'lock.c',

sway/server.c

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <wlr/types/wlr_drm.h>
1919
#include <wlr/types/wlr_export_dmabuf_v1.h>
2020
#include <wlr/types/wlr_ext_foreign_toplevel_list_v1.h>
21+
#include <wlr/types/wlr_fifo_v1.h>
2122
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
2223
#include <wlr/types/wlr_fractional_scale_v1.h>
2324
#include <wlr/types/wlr_gamma_control_v1.h>
@@ -57,6 +58,7 @@
5758
#include "sway/server.h"
5859
#include "sway/input/cursor.h"
5960
#include "sway/tree/root.h"
61+
#include "sway/fifo.h"
6062

6163
#if WLR_HAS_XWAYLAND
6264
#include <wlr/xwayland/shell.h>
@@ -405,6 +407,10 @@ bool server_init(struct sway_server *server) {
405407

406408
wl_list_init(&server->pending_launcher_ctxs);
407409

410+
server->fifo_manager = wlr_fifo_manager_create(server->wl_display, 1);
411+
server->fifo_create.notify = handle_fifo_manager_create_fifo;
412+
wl_signal_add(&server->fifo_manager->events.fifo_create, &server->fifo_create);
413+
408414
// Avoid using "wayland-0" as display socket
409415
char name_candidate[16];
410416
for (unsigned int i = 1; i <= 32; ++i) {

0 commit comments

Comments
 (0)