Skip to content

Commit

Permalink
pass scale to custom effect
Browse files Browse the repository at this point in the history
  • Loading branch information
mortie committed Nov 7, 2020
1 parent 8438973 commit 725a0e3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The main new features compared to upstream swaylock are:
* `--effect-greyscale`: Make the image greyscale.
* `--effect-vignette <base>:<factor>`: Apply a vignette effect (range is 0-1).
* `--effect-compose <position>;<size>;<gravity>;<path>`: Overlay another image.
* `--effect-custom <path>`: Load a custom effect from a shared object.
* `--effect-custom <path>`: Load a custom effect from a C file or shared object.

New feature ideas are welcome as issues (though I may never get around to
implement them), new feature implementations are welcome as pull requests :)
Expand Down
19 changes: 11 additions & 8 deletions effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static void effect_vignette(uint32_t *data, int width, int height,
}
}

static void effect_compose(uint32_t *data, int scale, int width, int height,
static void effect_compose(uint32_t *data, int width, int height, int scale,
struct swaylock_effect_screen_pos posx,
struct swaylock_effect_screen_pos posy,
struct swaylock_effect_screen_pos posw,
Expand Down Expand Up @@ -420,18 +420,18 @@ static void effect_compose(uint32_t *data, int scale, int width, int height,
#endif
}

static void effect_custom_run(uint32_t *data, int width, int height,
static void effect_custom_run(uint32_t *data, int width, int height, int scale,
char *path) {
void *dl = dlopen(path, RTLD_LAZY);
if (dl == NULL) {
swaylock_log(LOG_ERROR, "Custom effect: %s", dlerror());
return;
}

void (*effect_func)(uint32_t *data, int width, int height) =
void (*effect_func)(uint32_t *data, int width, int height, int scale) =
dlsym(dl, "swaylock_effect");
if (effect_func != NULL) {
effect_func(data, width, height);
effect_func(data, width, height, scale);
dlclose(dl);
return;
}
Expand All @@ -451,6 +451,7 @@ static void effect_custom_run(uint32_t *data, int width, int height,
return;
}

(void)dlsym(dl, "swaylock_effect"); // Change the result of dlerror()
swaylock_log(LOG_ERROR, "Custom effect: %s", dlerror());
}

Expand Down Expand Up @@ -555,15 +556,15 @@ static char *effect_custom_compile(const char *path) {
return outpath;
}

static void effect_custom(uint32_t *data, int width, int height,
static void effect_custom(uint32_t *data, int width, int height, int scale,
char *path) {
size_t pathlen = strlen(path);
if (pathlen > 3 && strcmp(path + pathlen - 3, ".so") == 0) {
effect_custom_run(data, width, height, path);
effect_custom_run(data, width, height, scale, path);
} else if (pathlen > 2 && strcmp(path + pathlen - 2, ".c") == 0) {
char *compiled = effect_custom_compile(path);
if (compiled != NULL) {
effect_custom_run(data, width, height, compiled);
effect_custom_run(data, width, height, scale, compiled);
free(compiled);
}
} else {
Expand Down Expand Up @@ -656,9 +657,10 @@ static cairo_surface_t *run_effect(cairo_surface_t *surface, int scale,

case EFFECT_COMPOSE: {
effect_compose(
(uint32_t *)cairo_image_surface_get_data(surface), scale,
(uint32_t *)cairo_image_surface_get_data(surface),
cairo_image_surface_get_width(surface),
cairo_image_surface_get_height(surface),
scale,
effect->e.compose.x, effect->e.compose.y,
effect->e.compose.w, effect->e.compose.h,
effect->e.compose.gravity, effect->e.compose.imgpath);
Expand All @@ -671,6 +673,7 @@ static cairo_surface_t *run_effect(cairo_surface_t *surface, int scale,
(uint32_t *)cairo_image_surface_get_data(surface),
cairo_image_surface_get_width(surface),
cairo_image_surface_get_height(surface),
scale,
effect->e.custom);
cairo_surface_flush(surface);
break;
Expand Down
2 changes: 1 addition & 1 deletion swaylock.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Locks your Wayland session.

*--effect-custom <path>*
Load a custom effect from a shared object. The .so must export a++
*void swaylock_effect(uint32\_t \*data, int width, int height)*++
*void swaylock_effect(uint32\_t \*data, int width, int height, int scale)*++
or an *uint32\_t swaylock_pixel(uint32\_t pix, int x, int y, int width, int height)*.

*--time-effects*
Expand Down

0 comments on commit 725a0e3

Please sign in to comment.