aboutsummaryrefslogtreecommitdiff
path: root/swaybg
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-04-02 22:48:13 -0400
committerDrew DeVault <sir@cmpwn.com>2018-04-04 18:47:48 -0400
commitb32bf595aeae7f8ac68354e45a80c0438374ec17 (patch)
treeb93185d2ac4b7081b9d0651eaaadeae21de48929 /swaybg
parenta28730edee1896242012f80fd0e63e7966652e02 (diff)
Initial swaylock port
Diffstat (limited to 'swaybg')
-rw-r--r--swaybg/main.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/swaybg/main.c b/swaybg/main.c
index ffefcd08..679b8c20 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -64,15 +64,17 @@ bool is_valid_color(const char *color) {
}
static void render_frame(struct swaybg_state *state) {
- state->current_buffer = get_next_buffer(state->shm, state->buffers,
- state->width * state->scale, state->height * state->scale);
+ int buffer_width = state->width * state->scale,
+ buffer_height = state->height * state->scale;
+ state->current_buffer = get_next_buffer(state->shm,
+ state->buffers, buffer_width, buffer_height);
cairo_t *cairo = state->current_buffer->cairo;
if (state->args->mode == BACKGROUND_MODE_SOLID_COLOR) {
cairo_set_source_u32(cairo, state->context.color);
cairo_paint(cairo);
} else {
render_background_image(cairo, state->context.image,
- state->args->mode, state->width, state->height, state->scale);
+ state->args->mode, buffer_width, buffer_height);
}
wl_surface_set_buffer_scale(state->surface, state->scale);
@@ -193,24 +195,10 @@ int main(int argc, const char **argv) {
args.output_idx = atoi(argv[1]);
args.path = argv[2];
- args.mode = BACKGROUND_MODE_STRETCH;
- if (strcmp(argv[3], "stretch") == 0) {
- args.mode = BACKGROUND_MODE_STRETCH;
- } else if (strcmp(argv[3], "fill") == 0) {
- args.mode = BACKGROUND_MODE_FILL;
- } else if (strcmp(argv[3], "fit") == 0) {
- args.mode = BACKGROUND_MODE_FIT;
- } else if (strcmp(argv[3], "center") == 0) {
- args.mode = BACKGROUND_MODE_CENTER;
- } else if (strcmp(argv[3], "tile") == 0) {
- args.mode = BACKGROUND_MODE_TILE;
- } else if (strcmp(argv[3], "solid_color") == 0) {
- args.mode = BACKGROUND_MODE_SOLID_COLOR;
- } else {
- wlr_log(L_ERROR, "Unsupported background mode: %s", argv[3]);
+ args.mode = parse_background_mode(argv[3]);
+ if (args.mode == BACKGROUND_MODE_INVALID) {
return 1;
}
-
if (!prepare_context(&state)) {
return 1;
}
@@ -244,10 +232,10 @@ int main(int argc, const char **argv) {
zwlr_layer_surface_v1_set_exclusive_zone(state.layer_surface, -1);
zwlr_layer_surface_v1_add_listener(state.layer_surface,
&layer_surface_listener, &state);
- state.run_display = true;
wl_surface_commit(state.surface);
wl_display_roundtrip(state.display);
+ state.run_display = true;
while (wl_display_dispatch(state.display) != -1 && state.run_display) {
// This space intentionally left blank
}