aboutsummaryrefslogtreecommitdiffstats
path: root/swaybg/main.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-11-19 07:58:57 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-11-19 07:58:57 -0500
commitb4e5e1381f909b173a171fb3941610aec989df48 (patch)
treef7dcf63dc6f4ac05c8fbb86da37d52766f210130 /swaybg/main.c
parentFix background extensions (diff)
downloadsway-b4e5e1381f909b173a171fb3941610aec989df48.tar.gz
sway-b4e5e1381f909b173a171fb3941610aec989df48.tar.zst
sway-b4e5e1381f909b173a171fb3941610aec989df48.zip
Refactor the crap out of wayland clients
And create a background surface on every output when invoking swaybg.
Diffstat (limited to 'swaybg/main.c')
-rw-r--r--swaybg/main.c64
1 files changed, 45 insertions, 19 deletions
diff --git a/swaybg/main.c b/swaybg/main.c
index 8d95f60a..56fdc06d 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -3,43 +3,69 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <wayland-client.h> 4#include <wayland-client.h>
5#include <time.h> 5#include <time.h>
6#include "client/client.h" 6#include "client/window.h"
7#include "client/registry.h"
7#include "log.h" 8#include "log.h"
9#include "list.h"
8 10
9struct client_state *state; 11list_t *surfaces;
12
13struct registry *registry;
10 14
11void sway_terminate(void) { 15void sway_terminate(void) {
12 client_teardown(state); 16 int i;
17 for (i = 0; i < surfaces->length; ++i) {
18 struct window *window = surfaces->items[i];
19 window_teardown(window);
20 }
21 list_free(surfaces);
22 registry_teardown(registry);
13 exit(1); 23 exit(1);
14} 24}
15 25
16int main(int argc, char **argv) { 26int main(int argc, char **argv) {
17 init_log(L_INFO); 27 init_log(L_INFO);
18 if (!(state = client_setup(100, 100, false))) { 28 surfaces = create_list();
19 return -1; 29 registry = registry_poll();
20 } 30
21 if (!state->desktop_shell) { 31 if (!registry->desktop_shell) {
22 sway_abort("swaybg requires the compositor to support the desktop-shell extension."); 32 sway_abort("swaybg requires the compositor to support the desktop-shell extension.");
23 } 33 }
24 struct output_state *output = state->outputs->items[0]; 34
25 state->width = output->width; 35 int i;
26 state->height = output->height; 36 for (i = 0; i < registry->outputs->length; ++i) {
27 desktop_shell_set_background(state->desktop_shell, output->output, state->surface); 37 struct output_state *output = registry->outputs->items[i];
38 struct window *window = window_setup(registry, 100, 100, false);
39 if (!window) {
40 sway_abort("Failed to create surfaces.");
41 }
42 window->width = output->width;
43 window->height = output->height;
44 desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
45 list_add(surfaces, window);
46 }
28 47
29 uint8_t r = 0, g = 0, b = 0; 48 uint8_t r = 0, g = 0, b = 0;
30 49
31 do { 50 do {
32 if (client_prerender(state) && state->cairo) { 51 for (i = 0; i < surfaces->length; ++i) {
33 cairo_set_source_rgb(state->cairo, r / 256.0, g / 256.0, b / 256.0); 52 struct window *window = surfaces->items[i];
34 cairo_rectangle(state->cairo, 0, 0, state->width, state->height); 53 if (window_prerender(window) && window->cairo) {
35 cairo_fill(state->cairo); 54 cairo_set_source_rgb(window->cairo, r / 256.0, g / 256.0, b / 256.0);
36 55 cairo_rectangle(window->cairo, 0, 0, window->width, window->height);
37 client_render(state); 56 cairo_fill(window->cairo);
38 57
58 window_render(window);
59 }
39 r++; g += 2; b += 4; 60 r++; g += 2; b += 4;
40 } 61 }
41 } while (wl_display_dispatch(state->display) != -1); 62 } while (wl_display_dispatch(registry->display) != -1);
42 63
43 client_teardown(state); 64 for (i = 0; i < surfaces->length; ++i) {
65 struct window *window = surfaces->items[i];
66 window_teardown(window);
67 }
68 list_free(surfaces);
69 registry_teardown(registry);
44 return 0; 70 return 0;
45} 71}