2

Why does XWarpPointer only work once?

When I run:

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

int main()
{
  Display *dpy = XOpenDisplay(0);
  while (1) {
    Window root_window;
    root_window = XRootWindow(dpy, 0);
    XSelectInput(dpy, root_window, KeyReleaseMask);
    XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, 100, 100);
    XSync(dpy, False);
  }
}

The mouse should appear locked in a single position. But it only moves the mouse once and then lets me move it around while the loop is still runnning. What is causing the XWarpPointer to only run once? Is it some kind of X11 feature to protect the user from the application?

FYI, I am running RHEL 5.2 on VMWare Fusion on Mac OSX 10.6.

Update:

  • When running the binary, components like a button or icon flicker, but the visual mouse cursor stays where I move it.
  • After the one time XWarpPointer does work, when I move the mouse, the cursor jumps to near where it was before I warped it. It's as if there is a (last_x,last_y) that is not getting updated.
  • When I change the pointer via OpenVMTools it seems to make the pointer stick to the desired location more, but the visual pointer does not change.

Thanks, Chenz

4

2 Answers 2

1

I've no experience here but what happens if you don't discard events in XSync? e.g. XSync(dpy, True);?

5
  • No observable difference. I even removed XSync call all together, and no difference. There was one new thing I noticed (as mentioned in the update to the question.) May 1, 2011 at 15:15
  • Basing this off the Wine code they use for implementing SetCursorPos(x,y) it maps to this: XWarpPointer( data->display, root_window, root_window, 0, 0, 0, 0, x - virtual_screen_rect.left, y - virtual_screen_rect.top ); Seems like the differnce is they specify root_window instead of None for src window? source.winehq.org/git/wine.git/blob?f=dlls/winex11.drv/…
    – JohnKlehm
    May 1, 2011 at 16:25
  • Nope, no change.... thanks for the insight though! I am researching into seeing how VMWare does the virtualization of the pointer. My thought is that I am setting the pointer in the guest os correctly, but to be "virtualized" I must set the pointer in the host as well. (Perhaps the X11 I am running is not uptodate enough to do this for me.) May 1, 2011 at 17:59
  • As noted above, I was able to set the host (reported) pointer from the guest OS. It did have an effect, but the visual pointer did not change. I can only guess that the two are separate or something is hardware controlled. May 1, 2011 at 18:40
  • what happens if you use Xflush(dpy) rather than Xsync ?
    – camelccc
    Dec 26, 2012 at 14:36
1

After

XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, 100, 100);

Try

XFlush(dpy);

This should solve the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.