summaryrefslogtreecommitdiffstats
path: root/tools/guest-diag/xgrab.c
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-10-28 18:04:16 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-10-28 18:04:16 -0400
commit1fd8d50a8d7277148ef8a7bbe67d1c62a29429b2 (patch)
tree78bbee4b39a8113e45b6c04b5bf1dc86af1d592e /tools/guest-diag/xgrab.c
parent375d627a7abd0c07b95d70395ce89b2f4c42d106 (diff)
downloadopen-iov-master.tar.gz
open-iov-master.zip
tools/guest-diag: working guest-GL capture and input for virtio-gpu virgl guests (SDL swap-hook capture; XSendEvent input - SDL ignores XTEST here; region capture, focus query, window resize)HEADmaster
Diffstat (limited to 'tools/guest-diag/xgrab.c')
-rw-r--r--tools/guest-diag/xgrab.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/tools/guest-diag/xgrab.c b/tools/guest-diag/xgrab.c
index 3f4ec76..eb605d6 100644
--- a/tools/guest-diag/xgrab.c
+++ b/tools/guest-diag/xgrab.c
@@ -22,6 +22,10 @@ int main(int argc, char **argv)
const char *out = argc > 2 ? argv[2] : "/dev/shm/gzframes.bin";
long maxf = argc > 3 ? atol(argv[3]) : 0;
long pace = argc > 4 ? atol(argv[4]) : 0;
+ int r_x = argc > 5 ? atoi(argv[5]) : -1;
+ int r_y = argc > 6 ? atoi(argv[6]) : 0;
+ int r_w = argc > 7 ? atoi(argv[7]) : 0;
+ int r_h = argc > 8 ? atoi(argv[8]) : 0;
Display *d;
Window root;
XWindowAttributes wa;
@@ -39,8 +43,12 @@ int main(int argc, char **argv)
fprintf(stderr, "xgrab: no root attrs\n");
return 1;
}
- fprintf(stderr, "xgrab: root %dx%d depth=%d\n", wa.width, wa.height,
- wa.depth);
+ if (r_x < 0 || r_w <= 0 || r_h <= 0 || r_x + r_w > wa.width ||
+ r_y + r_h > wa.height) {
+ r_x = 0; r_y = 0; r_w = wa.width; r_h = wa.height;
+ }
+ fprintf(stderr, "xgrab: root %dx%d depth=%d region %d,%d %dx%d\n",
+ wa.width, wa.height, wa.depth, r_x, r_y, r_w, r_h);
f = fopen(out, "wb");
if (!f) {
perror("xgrab: open out");
@@ -52,8 +60,8 @@ int main(int argc, char **argv)
fflush(f);
while (!maxf || (long)seq < maxf) {
- XImage *im = XGetImage(d, root, 0, 0, wa.width, wa.height,
- AllPlanes, ZPixmap);
+ XImage *im = XGetImage(d, root, r_x, r_y, r_w, r_h, AllPlanes,
+ ZPixmap);
struct timespec ts;
uint64_t tns;
uint32_t rh[4];
@@ -72,17 +80,17 @@ int main(int argc, char **argv)
}
clock_gettime(CLOCK_MONOTONIC, &ts);
tns = (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec;
- rh[0] = (uint32_t)wa.width;
- rh[1] = (uint32_t)wa.height;
- rh[2] = (uint32_t)wa.width * 4;
+ rh[0] = (uint32_t)r_w;
+ rh[1] = (uint32_t)r_h;
+ rh[2] = (uint32_t)r_w * 4;
rh[3] = 32;
fwrite(m, 1, 4, f);
fwrite(rh, 4, 4, f);
fwrite(&tns, 8, 1, f);
fwrite(&seq, 8, 1, f);
- for (y = 0; y < wa.height; y++)
+ for (y = 0; y < r_h; y++)
fwrite(im->data + (size_t)y * im->bytes_per_line, 1,
- (size_t)wa.width * 4, f);
+ (size_t)r_w * 4, f);
fflush(f);
seq++;
XDestroyImage(im);