mirror of
https://github.com/NickHu/sway
synced 2024-12-28 22:23:30 +01:00
Use fork in swaygrab instead of popen.
This commit is contained in:
parent
ab05f60034
commit
fab5720576
1 changed files with 21 additions and 10 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "ipc-client.h"
|
#include "ipc-client.h"
|
||||||
|
@ -47,17 +48,27 @@ void grab_and_apply_magick(const char *file, const char *payload,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *fmt = "convert -depth 8 -size %dx%d+0 rgba:- -flip %s";
|
char size[10 + 1 + 10 + 2 + 1]; // int32_t are max 10 digits
|
||||||
char *cmd = malloc(strlen(fmt) - 6 /*args*/
|
sprintf(size, "%dx%d+0", width, height);
|
||||||
+ numlen(width) + numlen(height) + strlen(file) + 1);
|
|
||||||
sprintf(cmd, fmt, width, height, file);
|
|
||||||
|
|
||||||
FILE *f = popen(cmd, "w");
|
pid_t child;
|
||||||
fwrite(pixels, 1, len, f);
|
int fd[2];
|
||||||
fflush(f);
|
pipe(fd);
|
||||||
fclose(f);
|
|
||||||
free(pixels - 9);
|
if ((child = fork()) < 0) {
|
||||||
free(cmd);
|
sway_log(L_ERROR, "Swaygrab failed to fork.");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else if (child == 0) {
|
||||||
|
close(fd[1]);
|
||||||
|
write(fd[0], pixels, len);
|
||||||
|
free(pixels - 9);
|
||||||
|
waitpid(child, NULL, 0);
|
||||||
|
} else {
|
||||||
|
close(fd[0]);
|
||||||
|
execlp("convert", "-depth", "8", "-size", size, "rgba:-", "-flip", file, NULL);
|
||||||
|
sway_log(L_ERROR, "Swaygrab could not run convert.");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void grab_and_apply_movie_magic(const char *file, const char *payload,
|
void grab_and_apply_movie_magic(const char *file, const char *payload,
|
||||||
|
|
Loading…
Reference in a new issue