+ av_init_packet(pkt);
+ pkt->data = image->data;
+ pkt->size = s->frame_size;
+ pkt->pts = curtime;
+
+ screen = DefaultScreen(dpy);
+ root = RootWindow(dpy, screen);
+ if (follow_mouse) {
+ int screen_w, screen_h;
+ int pointer_x, pointer_y, _;
+ Window w;
+
+ screen_w = DisplayWidth(dpy, screen);
+ screen_h = DisplayHeight(dpy, screen);
+ XQueryPointer(dpy, root, &w, &w, &pointer_x, &pointer_y, &_, &_, &_);
+ if (follow_mouse == -1) {
+ // follow the mouse, put it at center of grabbing region
+ x_off += pointer_x - s->width / 2 - x_off;
+ y_off += pointer_y - s->height / 2 - y_off;
+ } else {
+ // follow the mouse, but only move the grabbing region when mouse
+ // reaches within certain pixels to the edge.
+ if (pointer_x > x_off + s->width - follow_mouse) {
+ x_off += pointer_x - (x_off + s->width - follow_mouse);
+ } else if (pointer_x < x_off + follow_mouse)
+ x_off -= (x_off + follow_mouse) - pointer_x;
+ if (pointer_y > y_off + s->height - follow_mouse) {
+ y_off += pointer_y - (y_off + s->height - follow_mouse);
+ } else if (pointer_y < y_off + follow_mouse)
+ y_off -= (y_off + follow_mouse) - pointer_y;
+ }
+ // adjust grabbing region position if it goes out of screen.
+ s->x_off = x_off = FFMIN(FFMAX(x_off, 0), screen_w - s->width);
+ s->y_off = y_off = FFMIN(FFMAX(y_off, 0), screen_h - s->height);
+
+ if (s->show_region && s->region_win)
+ XMoveWindow(dpy, s->region_win,
+ s->x_off - REGION_WIN_BORDER,
+ s->y_off - REGION_WIN_BORDER);