mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 07:56:31 +01:00
swaygrab: add default output filename.
With this it's possible to run `swaygrab` without a filename argument. With no filename supplied it will use a default name based on the current time. The default file will get the extension `png` for screenshots and `webm` for video capture.
This commit is contained in:
parent
b656297d4f
commit
c97555d9f0
1 changed files with 23 additions and 4 deletions
|
@ -135,6 +135,19 @@ char *get_focused_output(int socketfd) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *default_filename(const char *extension) {
|
||||||
|
int ext_len = strlen(extension);
|
||||||
|
int len = 28 + ext_len; // format: "2015-12-17-180040_swaygrab.ext"
|
||||||
|
char *filename = malloc(len * sizeof(char));
|
||||||
|
time_t t = time(NULL);
|
||||||
|
|
||||||
|
struct tm *lt = localtime(&t);
|
||||||
|
strftime(filename, len, "%Y-%m-%d-%H%M%S_swaygrab.", lt);
|
||||||
|
strncat(filename, extension, ext_len);
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
static int capture = 0, raw = 0;
|
static int capture = 0, raw = 0;
|
||||||
char *socket_path = NULL;
|
char *socket_path = NULL;
|
||||||
|
@ -214,10 +227,7 @@ int main(int argc, char **argv) {
|
||||||
if (optind >= argc + 1) {
|
if (optind >= argc + 1) {
|
||||||
sway_abort("Invalid usage. See `man swaygrab` %d %d", argc, optind);
|
sway_abort("Invalid usage. See `man swaygrab` %d %d", argc, optind);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (optind < argc) {
|
||||||
if (optind >= argc) {
|
|
||||||
sway_abort("Invalid usage. See `man swaygrab`");
|
|
||||||
}
|
|
||||||
file = argv[optind];
|
file = argv[optind];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,6 +238,14 @@ int main(int argc, char **argv) {
|
||||||
output = get_focused_output(socketfd);
|
output = get_focused_output(socketfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
if (!capture) {
|
||||||
|
file = default_filename("png");
|
||||||
|
} else {
|
||||||
|
file = default_filename("webm");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!capture) {
|
if (!capture) {
|
||||||
grab_and_apply_magick(file, output, socketfd, raw);
|
grab_and_apply_magick(file, output, socketfd, raw);
|
||||||
} else {
|
} else {
|
||||||
|
@ -235,6 +253,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
free(output);
|
free(output);
|
||||||
|
free(file);
|
||||||
close(socketfd);
|
close(socketfd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue