summaryrefslogtreecommitdiffstats
path: root/swaygrab
diff options
context:
space:
mode:
authorLibravatar Emerson Ferreira <12075874+nuskorpios@users.noreply.github.com>2017-08-31 20:35:03 +0000
committerLibravatar GitHub <noreply@github.com>2017-08-31 20:35:03 +0000
commit013df6a8a5b99c873cd08e8b1cd6350def2a0b2c (patch)
tree4187dee4d31e39deec32cbf2005e4b6b4b910a84 /swaygrab
parentTranslate README to portuguese (diff)
parentMerge pull request #1336 from akokshar/master (diff)
downloadsway-013df6a8a5b99c873cd08e8b1cd6350def2a0b2c.tar.gz
sway-013df6a8a5b99c873cd08e8b1cd6350def2a0b2c.tar.zst
sway-013df6a8a5b99c873cd08e8b1cd6350def2a0b2c.zip
Merge branch 'master' into master
Diffstat (limited to 'swaygrab')
-rw-r--r--swaygrab/main.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/swaygrab/main.c b/swaygrab/main.c
index c437653d..6e851899 100644
--- a/swaygrab/main.c
+++ b/swaygrab/main.c
@@ -9,6 +9,7 @@
9#include <stdint.h> 9#include <stdint.h>
10#include <math.h> 10#include <math.h>
11#include <time.h> 11#include <time.h>
12#include <sys/wait.h>
12#include <json-c/json.h> 13#include <json-c/json.h>
13#include "log.h" 14#include "log.h"
14#include "ipc-client.h" 15#include "ipc-client.h"
@@ -47,17 +48,27 @@ void grab_and_apply_magick(const char *file, const char *payload,
47 return; 48 return;
48 } 49 }
49 50
50 const char *fmt = "convert -depth 8 -size %dx%d+0 rgba:- -flip %s"; 51 char size[10 + 1 + 10 + 2 + 1]; // int32_t are max 10 digits
51 char *cmd = malloc(strlen(fmt) - 6 /*args*/ 52 sprintf(size, "%dx%d+0", width, height);
52 + numlen(width) + numlen(height) + strlen(file) + 1);
53 sprintf(cmd, fmt, width, height, file);
54 53
55 FILE *f = popen(cmd, "w"); 54 pid_t child;
56 fwrite(pixels, 1, len, f); 55 int fd[2];
57 fflush(f); 56 pipe(fd);
58 fclose(f); 57
59 free(pixels - 9); 58 if ((child = fork()) < 0) {
60 free(cmd); 59 sway_log(L_ERROR, "Swaygrab failed to fork.");
60 exit(EXIT_FAILURE);
61 } else if (child == 0) {
62 close(fd[1]);
63 write(fd[0], pixels, len);
64 free(pixels - 9);
65 waitpid(child, NULL, 0);
66 } else {
67 close(fd[0]);
68 execlp("convert", "-depth", "8", "-size", size, "rgba:-", "-flip", file, NULL);
69 sway_log(L_ERROR, "Swaygrab could not run convert.");
70 exit(EXIT_FAILURE);
71 }
61} 72}
62 73
63void grab_and_apply_movie_magic(const char *file, const char *payload, 74void grab_and_apply_movie_magic(const char *file, const char *payload,