1

I'm trying to move and lock a mouse cursor in place, to calculate it's delta position after it was moved by the user. I'm using X11 and the XWarpPointer() function. I found a similar problem in another thread and I followed it, but it didn't work. I even looked into SDL source code but still nothing. The main problem is that after I set the position of the mouse and then the user moves it, the mouse moves back to the original position (before using XWarpPointer).

void sp::Mouse::getDeltaMousePosition(int *posX, int *posY)
{
    if(!m_firstEnter)
    {
         getMousePosition(&m_lastX, &m_lastY);
         m_firstEnter = true;
    }

    int tempX, tempY;
    getMousePosition(&tempX, &tempY);
    *posX = tempX - m_lastX;
    *posY = tempY - m_lastY;

    Window root_window = XRootWindow(ptr_display, 0);
    SelectInput(ptr_display, root_window, KeyReleaseMask);
    XWarpPointer(ptr_display, None, root_window, 0, 0, 0, 0, m_screenCenterX, m_screenCenterY);
    XFlush(ptr_display);
    m_lastX = m_screenCenterX;
    m_lastY = m_screenCenterY;
}
  • Isn't that what XWarpPointer is supposed to do? Also you wrote X**Wrap**Pointer. Is that the same function? – user253751 Oct 02 '20 at 15:29
  • Yes of course I meant XWarpPointer. I just rewrote the code because it is on a other pc. I found some example code online. In the example code after the XWarpPointer call the cursor moves but comes back to the original position after I move the mouse. I don't know what is going on. – Abbion Nebula Oct 02 '20 at 15:46
  • Here is a quick video presenting this problem [link](https://www.youtube.com/watch?v=0KuOa7fFPis&ab_channel=AbbionNebula). – Abbion Nebula Oct 02 '20 at 17:45

1 Answers1

0

I tried to compile the code on a pc with a Linux system, and it worked. Before I was compiling it in a virtual machine, so I'm guessing that the base system has priority when it comes to the mouse.