Enable geometry on swaygrab options

This commit is contained in:
Ranieri Althoff 2017-10-25 21:52:34 -02:00
parent d75ee3f9ce
commit 6de77fb558
No known key found for this signature in database
GPG key ID: 5B5C826F4CC77499

View file

@ -168,6 +168,7 @@ int main(int argc, char **argv) {
char *output = NULL; char *output = NULL;
int framerate = 30; int framerate = 30;
bool grab_focused = false; bool grab_focused = false;
char *geometry = NULL;
init_log(L_INFO); init_log(L_INFO);
@ -180,6 +181,7 @@ int main(int argc, char **argv) {
{"raw", no_argument, NULL, 'r'}, {"raw", no_argument, NULL, 'r'},
{"rate", required_argument, NULL, 'R'}, {"rate", required_argument, NULL, 'R'},
{"focused", no_argument, NULL, 'f'}, {"focused", no_argument, NULL, 'f'},
{"geometry", required_argument, NULL, 'g'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -193,16 +195,20 @@ int main(int argc, char **argv) {
" -s, --socket <socket> Use the specified socket.\n" " -s, --socket <socket> Use the specified socket.\n"
" -R, --rate <rate> Specify framerate (default: 30)\n" " -R, --rate <rate> Specify framerate (default: 30)\n"
" -r, --raw Write raw rgba data to stdout.\n" " -r, --raw Write raw rgba data to stdout.\n"
" -f, --focused Grab the focused container.\n"; " -f, --focused Grab the focused container.\n"
" -g, --geometry <wxh+x+y> Sets the region to capture (default: fullscreen).\n";
int c; int c;
while (1) { while (1) {
int option_index = 0; int option_index = 0;
c = getopt_long(argc, argv, "hco:vs:R:rf", long_options, &option_index); c = getopt_long(argc, argv, "hco:vs:R:rfg:", long_options, &option_index);
if (c == -1) { if (c == -1) {
break; break;
} }
switch (c) { switch (c) {
case 'g':
geometry = strdup(optarg);
break;
case 'f': case 'f':
grab_focused = true; grab_focused = true;
break; break;
@ -261,6 +267,13 @@ int main(int argc, char **argv) {
json_object_object_get_ex(con, "name", &name); json_object_object_get_ex(con, "name", &name);
geo = get_container_geometry(con); geo = get_container_geometry(con);
free(con); free(con);
} else if (geometry) {
geo = malloc(sizeof(struct wlc_geometry));
int read = sscanf(geometry, "%ux%u%d%d",
&geo->size.w, &geo->size.h, &geo->origin.x, &geo->origin.y);
if (read != 4) {
sway_abort("Unable to parse geometry");
}
} else { } else {
if (!output) { if (!output) {
output = get_focused_output(); output = get_focused_output();