Further refinement of wayland client support
This commit is contained in:
parent
bfcabe48ef
commit
11b1ba397f
|
@ -4,6 +4,7 @@
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
struct output_state {
|
struct output_state {
|
||||||
|
@ -28,6 +29,8 @@ struct client_state {
|
||||||
struct buffer *buffer;
|
struct buffer *buffer;
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
struct wl_shell_surface *shell_surface;
|
struct wl_shell_surface *shell_surface;
|
||||||
|
struct wl_callback *frame_cb;
|
||||||
|
bool busy;
|
||||||
cairo_t *cairo;
|
cairo_t *cairo;
|
||||||
cairo_surface_t *cairo_surface;
|
cairo_surface_t *cairo_surface;
|
||||||
PangoContext *pango;
|
PangoContext *pango;
|
||||||
|
|
|
@ -15,12 +15,22 @@ int main(int argc, char **argv) {
|
||||||
init_log(L_INFO);
|
init_log(L_INFO);
|
||||||
state = client_setup();
|
state = client_setup();
|
||||||
|
|
||||||
|
uint8_t r = 0, g = 0, b = 0;
|
||||||
|
|
||||||
|
int rs;
|
||||||
do {
|
do {
|
||||||
if (!client_prerender(state)) continue;
|
if (!client_prerender(state)) continue;
|
||||||
cairo_set_source_rgb(state->cairo, 255, 0, 0);
|
cairo_set_source_rgb(state->cairo, r, g, b);
|
||||||
cairo_rectangle(state->cairo, 0, 0, 100, 100);
|
cairo_rectangle(state->cairo, 0, 0, 100, 100);
|
||||||
cairo_fill(state->cairo);
|
cairo_fill(state->cairo);
|
||||||
} while (client_render(state));
|
|
||||||
|
rs = client_render(state);
|
||||||
|
|
||||||
|
if (rs == 1) {
|
||||||
|
sway_log(L_INFO, "rendering %d %d %d", r, g, b);
|
||||||
|
r++; g++; b++;
|
||||||
|
}
|
||||||
|
} while (rs);
|
||||||
|
|
||||||
client_teardown(state);
|
client_teardown(state);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -103,6 +103,16 @@ static int create_pool_file(size_t size) {
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void buffer_release(void *data, struct wl_buffer *buffer) {
|
||||||
|
struct client_state *state = data;
|
||||||
|
state->busy = false;
|
||||||
|
sway_log(L_INFO, "buffer release");
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_buffer_listener buffer_listener = {
|
||||||
|
.release = buffer_release
|
||||||
|
};
|
||||||
|
|
||||||
struct buffer *create_buffer(struct client_state *state,
|
struct buffer *create_buffer(struct client_state *state,
|
||||||
int32_t width, int32_t height, uint32_t format) {
|
int32_t width, int32_t height, uint32_t format) {
|
||||||
|
|
||||||
|
@ -120,10 +130,23 @@ struct buffer *create_buffer(struct client_state *state,
|
||||||
state->cairo = cairo_create(state->cairo_surface);
|
state->cairo = cairo_create(state->cairo_surface);
|
||||||
state->pango = pango_cairo_create_context(state->cairo);
|
state->pango = pango_cairo_create_context(state->cairo);
|
||||||
|
|
||||||
|
wl_buffer_add_listener(buf->buffer, &buffer_listener, state);
|
||||||
|
|
||||||
sway_log(L_INFO, "%p %p", buf->pool, buf->buffer);
|
sway_log(L_INFO, "%p %p", buf->pool, buf->buffer);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void frame_callback(void *data, struct wl_callback *callback, uint32_t time) {
|
||||||
|
sway_log(L_INFO, "frame callback");
|
||||||
|
struct client_state *state = data;
|
||||||
|
wl_callback_destroy(callback);
|
||||||
|
state->frame_cb = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_callback_listener listener = {
|
||||||
|
frame_callback
|
||||||
|
};
|
||||||
|
|
||||||
struct client_state *client_setup(void) {
|
struct client_state *client_setup(void) {
|
||||||
struct client_state *state = malloc(sizeof(struct client_state));
|
struct client_state *state = malloc(sizeof(struct client_state));
|
||||||
memset(state, 0, sizeof(struct client_state));
|
memset(state, 0, sizeof(struct client_state));
|
||||||
|
@ -138,8 +161,8 @@ struct client_state *client_setup(void) {
|
||||||
|
|
||||||
struct wl_registry *registry = wl_display_get_registry(state->display);
|
struct wl_registry *registry = wl_display_get_registry(state->display);
|
||||||
wl_registry_add_listener(registry, ®istry_listener, state);
|
wl_registry_add_listener(registry, ®istry_listener, state);
|
||||||
wl_display_roundtrip(state->display); // globals
|
wl_display_dispatch(state->display);
|
||||||
wl_display_roundtrip(state->display); // listeners
|
wl_display_roundtrip(state->display);
|
||||||
wl_registry_destroy(registry);
|
wl_registry_destroy(registry);
|
||||||
|
|
||||||
state->buffer = create_buffer(state, 100, 100, WL_SHM_FORMAT_ARGB8888);
|
state->buffer = create_buffer(state, 100, 100, WL_SHM_FORMAT_ARGB8888);
|
||||||
|
@ -148,21 +171,26 @@ struct client_state *client_setup(void) {
|
||||||
wl_shell_surface_set_toplevel(state->shell_surface);
|
wl_shell_surface_set_toplevel(state->shell_surface);
|
||||||
|
|
||||||
wl_surface_damage(state->surface, 0, 0, 100, 100);
|
wl_surface_damage(state->surface, 0, 0, 100, 100);
|
||||||
wl_surface_attach(state->surface, state->buffer->buffer, 0, 0);
|
|
||||||
wl_surface_commit(state->surface);
|
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
int client_prerender(struct client_state *state) {
|
int client_prerender(struct client_state *state) {
|
||||||
wl_display_dispatch_pending(state->display);
|
wl_display_dispatch_pending(state->display);
|
||||||
if (wl_display_flush(state->display) < 0 && errno != EAGAIN) {
|
wl_display_flush(state->display);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int client_render(struct client_state *state) {
|
int client_render(struct client_state *state) {
|
||||||
|
if (state->frame_cb) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
state->frame_cb = wl_surface_frame(state->surface);
|
||||||
|
wl_callback_add_listener(state->frame_cb, &listener, state);
|
||||||
|
wl_surface_damage(state->surface, 0, 0, 100, 100);
|
||||||
|
wl_surface_attach(state->surface, state->buffer->buffer, 0, 0);
|
||||||
|
wl_surface_commit(state->surface);
|
||||||
|
state->busy = true;
|
||||||
return wl_display_dispatch(state->display) != -1;
|
return wl_display_dispatch(state->display) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue