Commit 2a5ac99e authored by Antonio Ospite's avatar Antonio Ospite Committed by Luca Barbato

x11grab: Check the XQueryPointer return value

The paint_mouse_pointer() code uses XFixes to retrieve the cursor
coordinates, but XFixes gives no information about which screen the
pointer is on; this results in always drawing the cursor on the
captured screen even if the mouse pointer was on another screen.

For example, when capturing from screen 1 (i.e. -f x11grab -i ":0.1")
the cursor was being drawn in the captured image even when the mouse
pointer was actually on screen 0, which is wrong and visually confusing.

CC: libav-stable@libav.org
Signed-off-by: 's avatarLuca Barbato <lu_zero@gentoo.org>
parent 5b9c817d
......@@ -487,8 +487,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;
......@@ -516,14 +516,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;
......@@ -550,7 +552,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.
......@@ -572,7 +574,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, s);
return s->frame_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment