diff options
-rw-r--r-- | include/client/client.h | 1 | ||||
-rw-r--r-- | swaybg/main.c | 5 | ||||
-rw-r--r-- | wayland/buffers.c | 42 |
3 files changed, 27 insertions, 21 deletions
diff --git a/include/client/client.h b/include/client/client.h index bac2c1a6..02806eae 100644 --- a/include/client/client.h +++ b/include/client/client.h | |||
@@ -15,6 +15,7 @@ struct output_state { | |||
15 | 15 | ||
16 | struct buffer { | 16 | struct buffer { |
17 | struct wl_buffer *buffer; | 17 | struct wl_buffer *buffer; |
18 | int fd; | ||
18 | cairo_surface_t *surface; | 19 | cairo_surface_t *surface; |
19 | cairo_t *cairo; | 20 | cairo_t *cairo; |
20 | PangoContext *pango; | 21 | PangoContext *pango; |
diff --git a/swaybg/main.c b/swaybg/main.c index e8f400c0..790eb66b 100644 --- a/swaybg/main.c +++ b/swaybg/main.c | |||
@@ -17,11 +17,14 @@ int main(int argc, char **argv) { | |||
17 | if (!(state = client_setup(100, 100))) { | 17 | if (!(state = client_setup(100, 100))) { |
18 | return -1; | 18 | return -1; |
19 | } | 19 | } |
20 | struct output_state *output = state->outputs->items[0]; | ||
21 | state->width = output->width; | ||
22 | state->height = output->height; | ||
20 | 23 | ||
21 | uint8_t r = 100, g = 100, b = 100; | 24 | uint8_t r = 100, g = 100, b = 100; |
22 | 25 | ||
23 | do { | 26 | do { |
24 | if (client_prerender(state)) { | 27 | if (client_prerender(state) && state->cairo) { |
25 | cairo_set_source_rgb(state->cairo, r / 256.0, g / 256.0, b / 256.0); | 28 | cairo_set_source_rgb(state->cairo, r / 256.0, g / 256.0, b / 256.0); |
26 | cairo_rectangle(state->cairo, 0, 0, state->width, state->height); | 29 | cairo_rectangle(state->cairo, 0, 0, state->width, state->height); |
27 | cairo_fill(state->cairo); | 30 | cairo_fill(state->cairo); |
diff --git a/wayland/buffers.c b/wayland/buffers.c index 13193423..cc8740c4 100644 --- a/wayland/buffers.c +++ b/wayland/buffers.c | |||
@@ -11,34 +11,33 @@ | |||
11 | #include "list.h" | 11 | #include "list.h" |
12 | #include "log.h" | 12 | #include "log.h" |
13 | 13 | ||
14 | static int create_pool_file(size_t size) { | 14 | static int create_pool_file(size_t size, char **name) { |
15 | static const char template[] = "/sway-client-XXXXXX"; | 15 | static const char template[] = "/sway-client-XXXXXX"; |
16 | const char *path = getenv("XDG_RUNTIME_DIR"); | 16 | const char *path = getenv("XDG_RUNTIME_DIR"); |
17 | if (!path) { | 17 | if (!path) { |
18 | return -1; | 18 | return -1; |
19 | } | 19 | } |
20 | 20 | ||
21 | int ts = (path[strlen(path) - 1] == '/'); | 21 | int ts = (path[strlen(path) - 1] == '/'); |
22 | 22 | ||
23 | char *name = malloc( | 23 | *name = malloc( |
24 | strlen(template) + | 24 | strlen(template) + |
25 | strlen(path) + | 25 | strlen(path) + |
26 | (ts ? 1 : 0) + 1); | 26 | (ts ? 1 : 0) + 1); |
27 | sprintf(name, "%s%s%s", path, ts ? "" : "/", template); | 27 | sprintf(*name, "%s%s%s", path, ts ? "" : "/", template); |
28 | 28 | ||
29 | int fd = mkstemp(name); | 29 | int fd = mkstemp(*name); |
30 | free(name); | ||
31 | 30 | ||
32 | if (fd < 0) { | 31 | if (fd < 0) { |
33 | return -1; | 32 | return -1; |
34 | } | 33 | } |
35 | 34 | ||
36 | if (ftruncate(fd, size) < 0) { | 35 | if (ftruncate(fd, size) < 0) { |
37 | close(fd); | 36 | close(fd); |
38 | return -1; | 37 | return -1; |
39 | } | 38 | } |
40 | 39 | ||
41 | return fd; | 40 | return fd; |
42 | } | 41 | } |
43 | 42 | ||
44 | static void buffer_release(void *data, struct wl_buffer *wl_buffer) { | 43 | static void buffer_release(void *data, struct wl_buffer *wl_buffer) { |
@@ -56,12 +55,15 @@ static struct buffer *create_buffer(struct client_state *state, struct buffer *b | |||
56 | uint32_t stride = width * 4; | 55 | uint32_t stride = width * 4; |
57 | uint32_t size = stride * height; | 56 | uint32_t size = stride * height; |
58 | 57 | ||
59 | int fd = create_pool_file(size); | 58 | char *name; |
59 | int fd = create_pool_file(size, &name); | ||
60 | void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | 60 | void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
61 | struct wl_shm_pool *pool = wl_shm_create_pool(state->shm, fd, size); | 61 | struct wl_shm_pool *pool = wl_shm_create_pool(state->shm, fd, size); |
62 | buf->buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, format); | 62 | buf->buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, format); |
63 | wl_shm_pool_destroy(pool); | 63 | wl_shm_pool_destroy(pool); |
64 | close(fd); | 64 | close(fd); |
65 | unlink(name); | ||
66 | free(name); | ||
65 | fd = -1; | 67 | fd = -1; |
66 | 68 | ||
67 | buf->surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); | 69 | buf->surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); |