diff options
Diffstat (limited to 'swaybg')
-rw-r--r-- | swaybg/main.c | 44 | ||||
-rw-r--r-- | swaybg/meson.build | 36 |
2 files changed, 29 insertions, 51 deletions
diff --git a/swaybg/main.c b/swaybg/main.c index 62ddec6c..f431526c 100644 --- a/swaybg/main.c +++ b/swaybg/main.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <assert.h> | ||
1 | #include <ctype.h> | 2 | #include <ctype.h> |
2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
3 | #include <stdio.h> | 4 | #include <stdio.h> |
@@ -6,7 +7,7 @@ | |||
6 | #include <time.h> | 7 | #include <time.h> |
7 | #include <wayland-client.h> | 8 | #include <wayland-client.h> |
8 | #include <wlr/util/log.h> | 9 | #include <wlr/util/log.h> |
9 | #include "buffer_pool.h" | 10 | #include "pool-buffer.h" |
10 | #include "cairo.h" | 11 | #include "cairo.h" |
11 | #include "util.h" | 12 | #include "util.h" |
12 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 13 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
@@ -127,7 +128,7 @@ static void render_image(struct swaybg_state *state) { | |||
127 | break; | 128 | break; |
128 | } | 129 | } |
129 | case BACKGROUND_MODE_SOLID_COLOR: | 130 | case BACKGROUND_MODE_SOLID_COLOR: |
130 | // Should never happen | 131 | assert(0); |
131 | break; | 132 | break; |
132 | } | 133 | } |
133 | cairo_paint(cairo); | 134 | cairo_paint(cairo); |
@@ -158,7 +159,7 @@ static bool prepare_context(struct swaybg_state *state) { | |||
158 | state->context.color = parse_color(state->args->path); | 159 | state->context.color = parse_color(state->args->path); |
159 | return is_valid_color(state->args->path); | 160 | return is_valid_color(state->args->path); |
160 | } | 161 | } |
161 | #ifdef WITH_GDK_PIXBUF | 162 | #ifdef HAVE_GDK_PIXBUF |
162 | GError *err = NULL; | 163 | GError *err = NULL; |
163 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(state->args->path, &err); | 164 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(state->args->path, &err); |
164 | if (!pixbuf) { | 165 | if (!pixbuf) { |
@@ -170,17 +171,17 @@ static bool prepare_context(struct swaybg_state *state) { | |||
170 | #else | 171 | #else |
171 | state->context.image = cairo_image_surface_create_from_png( | 172 | state->context.image = cairo_image_surface_create_from_png( |
172 | state->args->path); | 173 | state->args->path); |
173 | #endif //WITH_GDK_PIXBUF | 174 | #endif //HAVE_GDK_PIXBUF |
174 | if (!state->context.image) { | 175 | if (!state->context.image) { |
175 | wlr_log(L_ERROR, "Failed to read background image."); | 176 | wlr_log(L_ERROR, "Failed to read background image."); |
176 | return false; | 177 | return false; |
177 | } | 178 | } |
178 | if (cairo_surface_status(state->context.image) != CAIRO_STATUS_SUCCESS) { | 179 | if (cairo_surface_status(state->context.image) != CAIRO_STATUS_SUCCESS) { |
179 | wlr_log(L_ERROR, "Failed to read background image: %s." | 180 | wlr_log(L_ERROR, "Failed to read background image: %s." |
180 | #ifndef WITH_GDK_PIXBUF | 181 | #ifndef HAVE_GDK_PIXBUF |
181 | "\nSway was compiled without gdk_pixbuf support, so only" | 182 | "\nSway was compiled without gdk_pixbuf support, so only" |
182 | "\nPNG images can be loaded. This is the likely cause." | 183 | "\nPNG images can be loaded. This is the likely cause." |
183 | #endif //WITH_GDK_PIXBUF | 184 | #endif //HAVE_GDK_PIXBUF |
184 | , cairo_status_to_string( | 185 | , cairo_status_to_string( |
185 | cairo_surface_status(state->context.image))); | 186 | cairo_surface_status(state->context.image))); |
186 | return false; | 187 | return false; |
@@ -256,7 +257,6 @@ int main(int argc, const char **argv) { | |||
256 | } | 257 | } |
257 | args.output_idx = atoi(argv[1]); | 258 | args.output_idx = atoi(argv[1]); |
258 | args.path = argv[2]; | 259 | args.path = argv[2]; |
259 | args.mode = atoi(argv[3]); | ||
260 | 260 | ||
261 | args.mode = BACKGROUND_MODE_STRETCH; | 261 | args.mode = BACKGROUND_MODE_STRETCH; |
262 | if (strcmp(argv[3], "stretch") == 0) { | 262 | if (strcmp(argv[3], "stretch") == 0) { |
@@ -280,38 +280,20 @@ int main(int argc, const char **argv) { | |||
280 | return 1; | 280 | return 1; |
281 | } | 281 | } |
282 | 282 | ||
283 | state.display = wl_display_connect(NULL); | 283 | assert(state.display = wl_display_connect(NULL)); |
284 | if (!state.display) { | ||
285 | wlr_log(L_ERROR, "Failed to create display\n"); | ||
286 | return 1; | ||
287 | } | ||
288 | 284 | ||
289 | struct wl_registry *registry = wl_display_get_registry(state.display); | 285 | struct wl_registry *registry = wl_display_get_registry(state.display); |
290 | wl_registry_add_listener(registry, ®istry_listener, &state); | 286 | wl_registry_add_listener(registry, ®istry_listener, &state); |
291 | wl_display_roundtrip(state.display); | 287 | wl_display_roundtrip(state.display); |
288 | assert(state.compositor && state.layer_shell && state.output && state.shm); | ||
292 | 289 | ||
293 | if (!state.compositor) { | 290 | assert(state.surface = wl_compositor_create_surface(state.compositor)); |
294 | wlr_log(L_DEBUG, "wl-compositor not available"); | ||
295 | return 1; | ||
296 | } | ||
297 | if (!state.layer_shell) { | ||
298 | wlr_log(L_ERROR, "layer-shell not available"); | ||
299 | return 1; | ||
300 | } | ||
301 | |||
302 | state.surface = wl_compositor_create_surface(state.compositor); | ||
303 | if (!state.surface) { | ||
304 | wlr_log(L_ERROR, "failed to create wl_surface"); | ||
305 | return 1; | ||
306 | } | ||
307 | 291 | ||
308 | state.layer_surface = zwlr_layer_shell_v1_get_layer_surface( | 292 | state.layer_surface = zwlr_layer_shell_v1_get_layer_surface( |
309 | state.layer_shell, state.surface, state.output, | 293 | state.layer_shell, state.surface, state.output, |
310 | ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wallpaper"); | 294 | ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wallpaper"); |
311 | if (!state.layer_surface) { | 295 | assert(state.layer_surface); |
312 | wlr_log(L_ERROR, "failed to create zwlr_layer_surface"); | 296 | |
313 | return 1; | ||
314 | } | ||
315 | zwlr_layer_surface_v1_set_size(state.layer_surface, 0, 0); | 297 | zwlr_layer_surface_v1_set_size(state.layer_surface, 0, 0); |
316 | zwlr_layer_surface_v1_set_anchor(state.layer_surface, | 298 | zwlr_layer_surface_v1_set_anchor(state.layer_surface, |
317 | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | | 299 | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | |
@@ -320,10 +302,10 @@ int main(int argc, const char **argv) { | |||
320 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); | 302 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); |
321 | zwlr_layer_surface_v1_add_listener(state.layer_surface, | 303 | zwlr_layer_surface_v1_add_listener(state.layer_surface, |
322 | &layer_surface_listener, &state); | 304 | &layer_surface_listener, &state); |
305 | state.run_display = true; | ||
323 | wl_surface_commit(state.surface); | 306 | wl_surface_commit(state.surface); |
324 | wl_display_roundtrip(state.display); | 307 | wl_display_roundtrip(state.display); |
325 | 308 | ||
326 | state.run_display = true; | ||
327 | while (wl_display_dispatch(state.display) != -1 && state.run_display) { | 309 | while (wl_display_dispatch(state.display) != -1 && state.run_display) { |
328 | // This space intentionally left blank | 310 | // This space intentionally left blank |
329 | } | 311 | } |
diff --git a/swaybg/meson.build b/swaybg/meson.build index 7f5d6bd1..5e10f3c7 100644 --- a/swaybg/meson.build +++ b/swaybg/meson.build | |||
@@ -1,22 +1,18 @@ | |||
1 | deps = [ | ||
2 | cairo, | ||
3 | jsonc, | ||
4 | math, | ||
5 | pango, | ||
6 | pangocairo, | ||
7 | sway_protos, | ||
8 | wayland_client, | ||
9 | ] | ||
10 | |||
11 | if gdk_pixbuf.found() | ||
12 | deps += [gdk_pixbuf] | ||
13 | endif | ||
14 | |||
15 | executable( | 1 | executable( |
16 | 'swaybg', | 2 | 'swaybg', |
17 | 'main.c', | 3 | 'main.c', |
18 | include_directories: [sway_inc], | 4 | include_directories: [sway_inc], |
19 | dependencies: deps, | 5 | dependencies: [ |
20 | link_with: [lib_sway_common, lib_sway_client], | 6 | cairo, |
21 | install: true | 7 | gdk_pixbuf, |
8 | jsonc, | ||
9 | math, | ||
10 | pango, | ||
11 | pangocairo, | ||
12 | sway_protos, | ||
13 | wayland_client, | ||
14 | wlroots, | ||
15 | ], | ||
16 | link_with: [lib_sway_common, lib_sway_client], | ||
17 | install: true | ||
22 | ) | 18 | ) |