aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--swaybg/CMakeLists.txt2
-rw-r--r--swaybg/main.c19
-rw-r--r--wayland/client.c20
3 files changed, 27 insertions, 14 deletions
diff --git a/swaybg/CMakeLists.txt b/swaybg/CMakeLists.txt
index 8da31faa..5a46ffb8 100644
--- a/swaybg/CMakeLists.txt
+++ b/swaybg/CMakeLists.txt
@@ -23,7 +23,7 @@ add_executable(swaybg
23 ${common} 23 ${common}
24) 24)
25 25
26TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES}) 26TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES} -lm)
27 27
28install( 28install(
29 TARGETS swaybg 29 TARGETS swaybg
diff --git a/swaybg/main.c b/swaybg/main.c
index 5ceb94bc..af0a1b27 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -1,6 +1,7 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <wayland-client.h> 3#include <wayland-client.h>
4#include <time.h>
4#include "client.h" 5#include "client.h"
5#include "log.h" 6#include "log.h"
6 7
@@ -17,18 +18,28 @@ int main(int argc, char **argv) {
17 18
18 uint8_t r = 0, g = 0, b = 0; 19 uint8_t r = 0, g = 0, b = 0;
19 20
21 long last_ms = 0;
20 int rs; 22 int rs;
21 do { 23 do {
22 if (!client_prerender(state)) continue; 24 struct timespec spec;
25 clock_gettime(CLOCK_MONOTONIC, &spec);
26 long ms = round(spec.tv_nsec / 1.0e6);
27
23 cairo_set_source_rgb(state->cairo, r, g, b); 28 cairo_set_source_rgb(state->cairo, r, g, b);
24 cairo_rectangle(state->cairo, 0, 0, 100, 100); 29 cairo_rectangle(state->cairo, 0, 0, 100, 100);
25 cairo_fill(state->cairo); 30 cairo_fill(state->cairo);
26 31
27 rs = client_render(state); 32 rs = client_render(state);
28 33
29 if (rs == 1) { 34 if (ms - last_ms > 100) {
30 sway_log(L_INFO, "rendering %d %d %d", r, g, b); 35 r++;
31 r++; g++; b++; 36 if (r == 0) {
37 g++;
38 if (g == 0) {
39 b++;
40 }
41 }
42 ms = last_ms;
32 } 43 }
33 } while (rs); 44 } while (rs);
34 45
diff --git a/wayland/client.c b/wayland/client.c
index 5c5c0751..fcbba885 100644
--- a/wayland/client.c
+++ b/wayland/client.c
@@ -93,7 +93,7 @@ static int create_pool_file(size_t size) {
93 93
94 if (fd < 0) { 94 if (fd < 0) {
95 return -1; 95 return -1;
96 } 96 }
97 97
98 if (ftruncate(fd, size) < 0) { 98 if (ftruncate(fd, size) < 0) {
99 close(fd); 99 close(fd);
@@ -125,6 +125,9 @@ struct buffer *create_buffer(struct client_state *state,
125 void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 125 void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
126 buf->pool = wl_shm_create_pool(state->shm, fd, size); 126 buf->pool = wl_shm_create_pool(state->shm, fd, size);
127 buf->buffer = wl_shm_pool_create_buffer(buf->pool, 0, width, height, stride, format); 127 buf->buffer = wl_shm_pool_create_buffer(buf->pool, 0, width, height, stride, format);
128 wl_shm_pool_destroy(buf->pool);
129 close(fd);
130 fd = -1;
128 131
129 state->cairo_surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); 132 state->cairo_surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride);
130 state->cairo = cairo_create(state->cairo_surface); 133 state->cairo = cairo_create(state->cairo_surface);
@@ -175,22 +178,21 @@ struct client_state *client_setup(void) {
175 return state; 178 return state;
176} 179}
177 180
178int client_prerender(struct client_state *state) {
179 wl_display_dispatch_pending(state->display);
180 wl_display_flush(state->display);
181 return 1;
182}
183
184int client_render(struct client_state *state) { 181int client_render(struct client_state *state) {
185 if (state->frame_cb) { 182 if (state->frame_cb || state->busy) {
186 return 2; 183 return 2;
187 } 184 }
185 sway_log(L_INFO, "Rendering");
186
188 state->frame_cb = wl_surface_frame(state->surface); 187 state->frame_cb = wl_surface_frame(state->surface);
189 wl_callback_add_listener(state->frame_cb, &listener, state); 188 wl_callback_add_listener(state->frame_cb, &listener, state);
190 wl_surface_damage(state->surface, 0, 0, 100, 100); 189
190 wl_surface_damage(state->surface, 0, 0, state->buffer->width, state->buffer->height);
191 wl_surface_attach(state->surface, state->buffer->buffer, 0, 0); 191 wl_surface_attach(state->surface, state->buffer->buffer, 0, 0);
192 wl_surface_commit(state->surface); 192 wl_surface_commit(state->surface);
193
193 state->busy = true; 194 state->busy = true;
195
194 return wl_display_dispatch(state->display) != -1; 196 return wl_display_dispatch(state->display) != -1;
195} 197}
196 198