Clean up some things better in wayland clients
This commit is contained in:
parent
1011957465
commit
f7c0d2badb
|
@ -23,7 +23,7 @@ add_executable(swaybg
|
||||||
${common}
|
${common}
|
||||||
)
|
)
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES})
|
TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES} -lm)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
TARGETS swaybg
|
TARGETS swaybg
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
#include <time.h>
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
@ -17,18 +18,28 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
uint8_t r = 0, g = 0, b = 0;
|
uint8_t r = 0, g = 0, b = 0;
|
||||||
|
|
||||||
|
long last_ms = 0;
|
||||||
int rs;
|
int rs;
|
||||||
do {
|
do {
|
||||||
if (!client_prerender(state)) continue;
|
struct timespec spec;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &spec);
|
||||||
|
long ms = round(spec.tv_nsec / 1.0e6);
|
||||||
|
|
||||||
cairo_set_source_rgb(state->cairo, r, g, b);
|
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);
|
||||||
|
|
||||||
rs = client_render(state);
|
rs = client_render(state);
|
||||||
|
|
||||||
if (rs == 1) {
|
if (ms - last_ms > 100) {
|
||||||
sway_log(L_INFO, "rendering %d %d %d", r, g, b);
|
r++;
|
||||||
r++; g++; b++;
|
if (r == 0) {
|
||||||
|
g++;
|
||||||
|
if (g == 0) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ms = last_ms;
|
||||||
}
|
}
|
||||||
} while (rs);
|
} while (rs);
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,9 @@ struct buffer *create_buffer(struct client_state *state,
|
||||||
void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
buf->pool = wl_shm_create_pool(state->shm, fd, size);
|
buf->pool = wl_shm_create_pool(state->shm, fd, size);
|
||||||
buf->buffer = wl_shm_pool_create_buffer(buf->pool, 0, width, height, stride, format);
|
buf->buffer = wl_shm_pool_create_buffer(buf->pool, 0, width, height, stride, format);
|
||||||
|
wl_shm_pool_destroy(buf->pool);
|
||||||
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
|
|
||||||
state->cairo_surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride);
|
state->cairo_surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride);
|
||||||
state->cairo = cairo_create(state->cairo_surface);
|
state->cairo = cairo_create(state->cairo_surface);
|
||||||
|
@ -175,22 +178,21 @@ struct client_state *client_setup(void) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
int client_prerender(struct client_state *state) {
|
|
||||||
wl_display_dispatch_pending(state->display);
|
|
||||||
wl_display_flush(state->display);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int client_render(struct client_state *state) {
|
int client_render(struct client_state *state) {
|
||||||
if (state->frame_cb) {
|
if (state->frame_cb || state->busy) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
sway_log(L_INFO, "Rendering");
|
||||||
|
|
||||||
state->frame_cb = wl_surface_frame(state->surface);
|
state->frame_cb = wl_surface_frame(state->surface);
|
||||||
wl_callback_add_listener(state->frame_cb, &listener, state);
|
wl_callback_add_listener(state->frame_cb, &listener, state);
|
||||||
wl_surface_damage(state->surface, 0, 0, 100, 100);
|
|
||||||
|
wl_surface_damage(state->surface, 0, 0, state->buffer->width, state->buffer->height);
|
||||||
wl_surface_attach(state->surface, state->buffer->buffer, 0, 0);
|
wl_surface_attach(state->surface, state->buffer->buffer, 0, 0);
|
||||||
wl_surface_commit(state->surface);
|
wl_surface_commit(state->surface);
|
||||||
|
|
||||||
state->busy = true;
|
state->busy = true;
|
||||||
|
|
||||||
return wl_display_dispatch(state->display) != -1;
|
return wl_display_dispatch(state->display) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue