On Mon, 8 Sep 2014 18:05:02 +0200
Antonio Ospite <[email protected]> wrote:

> On Mon, 08 Sep 2014 17:26:13 +0200
> Luca Barbato <[email protected]> wrote:
> 
> > On 08/09/14 13:39, Antonio Ospite wrote:
> > > The code uses XFixes to retrieve the cursor coordinates, but XFixes
> > > gives no information of what 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.
> > 
> > Same happens with "follow mouse" I guess, since you have the right setup
> > could you please tell me how it behaves in that specific case?
> >
> 
> You are right, follow_mouse is broken too in multi-screen setups,
> x11grab always draws the captured screen, even when the cursor is on
> _another_ screen.
> 
> I can apply a similar fix to follow_mouse, like in:
> 
>   "don't draw anything when the cursor is on another screen".
> 
> Having the capture following the mouse when it crosses screens would be
> a lot more work I guess, but maybe that doesn't even make sense.
> 

The fix I came up for follow_mouse would actually mean:

  "don't update region position when the cursor is on another screen"

continuing to capture and draw is necessary because the capturing
screen content can change even if the mouse is on another screen.

The proposed change:

diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index 3e3e4d2..4d7085d 100644
--- a/libavdevice/x11grab.c
+++ b/libavdevice/x11grab.c
@@ -479,6 +479,9 @@ static int x11grab_read_packet(AVFormatContext *s1, 
AVPacket *pkt)
     Window root;
     int64_t curtime, delay;
     struct timespec ts;
+    int pointer_x, pointer_y, _;
+    Window w;
+    Bool pointer_on_screen;

     /* Calculate the time of the next frame */
     s->time_frame += INT64_C(1000000);
@@ -504,14 +507,13 @@ static int x11grab_read_packet(AVFormatContext *s1, 
AVPacket *pkt)

     screen = DefaultScreen(dpy);
     root   = RootWindow(dpy, screen);
-    if (follow_mouse) {
+    pointer_on_screen = XQueryPointer(dpy, root, &w, &w, &pointer_x,
+                                      &pointer_y, &_, &_, &_);
+    if (follow_mouse && pointer_on_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;

With this change I could also _drop_ the previous patch and do the
following below in x11grab_read_packet():

    if (s->draw_mouse && pointer_on_screen)
            paint_mouse_pointer(image, s);

What do you think?

>From a logic viewpoint I liked the dedicated XQueryPointer() check inside
paint_mouse_pointer() but it's a bit of duplication now that we always
call XQueryPointer in x11grab_read_packet() too.

Thanks,
   Antonio

-- 
Antonio Ospite
http://ao2.it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to