diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c index 9066ae21ad..3a833eb27f 100644 --- a/libavdevice/x11grab.c +++ b/libavdevice/x11grab.c @@ -410,14 +410,6 @@ static void paint_mouse_pointer(XImage *image, AVFormatContext *s1) uint8_t *pix = image->data; Window root; XSetWindowAttributes attr; - Bool pointer_on_screen; - Window w; - int _; - - root = DefaultRootWindow(dpy); - pointer_on_screen = XQueryPointer(dpy, root, &w, &w, &_, &_, &_, &_, &_); - if (!pointer_on_screen) - return; /* Code doesn't currently support 16-bit or PAL8 */ if (image->bits_per_pixel != 24 && image->bits_per_pixel != 32) @@ -425,6 +417,7 @@ static void paint_mouse_pointer(XImage *image, AVFormatContext *s1) if (!s->c) s->c = XCreateFontCursor(dpy, XC_left_ptr); + root = DefaultRootWindow(dpy); attr.cursor = s->c; XChangeWindowAttributes(dpy, root, CWCursor, &attr); @@ -527,8 +520,8 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) int x_off = s->x_off; int y_off = s->y_off; int follow_mouse = s->follow_mouse; - int screen; - Window root; + int screen, pointer_x, pointer_y, _, same_screen = 1; + Window w, root; int64_t curtime, delay; struct timespec ts; @@ -566,14 +559,16 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); - if (follow_mouse) { + + if (follow_mouse || s->draw_mouse) + same_screen = XQueryPointer(dpy, root, &w, &w, + &pointer_x, &pointer_y, &_, &_, &_); + + if (follow_mouse && same_screen) { 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; @@ -600,7 +595,7 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) s->y_off - REGION_WIN_BORDER); } - if (s->show_region) { + if (s->show_region && same_screen) { if (s->region_win) { XEvent evt = { .type = NoEventMask }; // Clean up the events, and do the initial draw or redraw. @@ -622,7 +617,7 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) av_log(s1, AV_LOG_INFO, "XGetZPixmap() failed\n"); } - if (s->draw_mouse) + if (s->draw_mouse && same_screen) paint_mouse_pointer(image, s1); return s->frame_size;