Jump to content

  • Log In with Google      Sign In   
  • Create Account

X11: Locking cursor in the center of the window


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Aluthreney   Members   -  Reputation: 256

Like
0Likes
Like

Posted 27 December 2012 - 12:09 PM

I'm developing a game using an engine called Gameplay 3D on Ubuntu and while trying to use the engine's "captureMouse" function I learned that this particular function has not yet been defined for the linux distro. I've already told them about my need for this function to be defined, but luckily the engine is open source; so for quite a few hours now I've been trying to get the cursor to lock in the center of the screen.

 

This is what I've been able to do so far:

- using this function

 

 

XWarpPointer(__display, None, __window, 0, 0, 0, 0, getDisplayWidth()/2, getDisplayHeight/2);

I've been able to move the cursor onto the center of the window, but if I move the mouse the cursor will leave the center. This seemed like a step in the right directing so I kept looking for another function for actually locked the cursor in place

 

- using this code:

 


 

/* vars to make blank cursor */
Pixmap blank;
XColor dummy;
char data[1] = {0};
Cursor cursor;

/* make a blank cursor */
blank = XCreateBitmapFromData (dpy, win, data, 1, 1);
if(blank == None) fprintf(stderr, "error: out of memory.\n");
cursor = XCreatePixmapCursor(dpy, blank, blank, &dummy, &dummy, 0, 0);
XFreePixmap (dpy, blank);
Con_Printf("Cursor blanked.\n")

found here: Link; I was able to make an invisible with the help of this function:

 

 

 

XGrabPointer(__display, __window, true, 0, GrabModeAsync, GrabModeASnyc, __window, cursor, CurrentTime)

Unfortunatly the XGrabPointer function didn't lock the pointer in place. Instead it just disabled the cursor from leaving the window, ei.: the cursor wouldn't move past the edges of the window.

 

So right now I have an invisible cursor, confined to the application window, that jumps the center (of the window) when I run the program. My question: How do I lock the cursor in place (at the center)?


Aluthreney -- the King of sheep.


Sponsor:

#2 rnlf   Members   -  Reputation: 1185

Like
1Likes
Like

Posted 27 December 2012 - 01:12 PM

I don't think there is a function to lock the cursor in position (shame on me if I'm wrong), but you can call XWarpPointer every time you receive a mouse event, which has the same effect.


my blog (German)


#3 santa01   Members   -  Reputation: 307

Like
3Likes
Like

Posted 27 December 2012 - 02:44 PM

I don't think there is a function to lock the cursor in position (shame on me if I'm wrong), but you can call XWarpPointer every time you receive a mouse event, which has the same effect.

sorry for plusing your answer smile.png its not exactly the way its done. XWarpPointer() would move the cursor and produce the mouse event itself, performance falls drastically for no good reason. its better to call XWarpPointer() after the event queue is empty:

while (XPending(display)) {
    XNextEvent(display, &event);
    // process you events
}

XWarpPointer(...);

or you can look through the freeglut sources to find out how its implemented for X11.


Edited by santa01, 27 December 2012 - 02:49 PM.


#4 Aluthreney   Members   -  Reputation: 256

Like
0Likes
Like

Posted 27 December 2012 - 04:33 PM

Thanks for the replies. I kind of figured there wasn't an easy way to do this, but I wanted to make sure before I started messing too much with the engine's code.


Aluthreney -- the King of sheep.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS