Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to capture raw mouse input in X11?


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
7 replies to this topic

#1 Chaosenemy   Members   -  Reputation: 152

Like
0Likes
Like

Posted 16 January 2011 - 09:56 PM

For the Windows version of my game engine, I'm using WM_INPUT and registering the mouse device directly to get the most precise movements. Anyone know how I would go about doing this in X11 (for Linux)? I've searched Google about as thoroughly as I can, but finding good documentation for X11 is next to impossible.

Sponsor:

#2 Bregma   Crossbones+   -  Reputation: 5499

Like
0Likes
Like

Posted 17 January 2011 - 07:30 AM

Input under x.org (the most common X11 implementation on Linux) is performed through the XInput module, or preferably the XInput2 module. You can google for that: it's documented on freedesktop.org and in the header files. If you want the "raw" input, you need to bypass the X11 stack and connect to the appropriate /dev/input/event pseudofile directly. That's certainly not recommended.

Any reason why you want to talk X11 directly instead of using a portable wrapper like SDL (or equivalent)?
Stephen M. Webb
Professional Free Software Developer

#3 Chaosenemy   Members   -  Reputation: 152

Like
0Likes
Like

Posted 17 January 2011 - 11:56 PM

Input under x.org (the most common X11 implementation on Linux) is performed through the XInput module, or preferably the XInput2 module. You can google for that: it's documented on freedesktop.org and in the header files. If you want the "raw" input, you need to bypass the X11 stack and connect to the appropriate /dev/input/event pseudofile directly. That's certainly not recommended.

Thanks, that pointed me in the right direction I think, and I've found a few samples. There is one issue though: Link. That guy's post is the only thing I can find on the internet about this issue, and it hasn't been resolved =\ Can you think of any way to get around that? I was thinking something like sending a certain X event before calling XWarpPointer() and then in my event handler, when I get to the event I sent, ignore the next event, which would be the one sent by XWarpPointer(). Not sure if I'm explaining that right, but does it sound plausible?


Any reason why you want to talk X11 directly instead of using a portable wrapper like SDL (or equivalent)?

SDL murdered my parents.

#4 owl   Banned   -  Reputation: 364

Like
0Likes
Like

Posted 18 January 2011 - 02:48 AM

Any reason why you want to talk X11 directly instead of using a portable wrapper like SDL (or equivalent)?

SDL murdered my parents.


Were they good parents?

I like the Walrus best.

#5 Seaßourne   Members   -  Reputation: 104

Like
0Likes
Like

Posted 18 January 2011 - 07:22 AM

For the Windows version of my game engine, I'm using WM_INPUT and registering the mouse device directly to get the most precise movements. Anyone know how I would go about doing this in X11 (for Linux)? I've searched Google about as thoroughly as I can, but finding good documentation for X11 is next to impossible.


Well in general, no one ever accesses pure X11 for handling this stuff as there are gui libraries out there for this. Have you thought about using a cross OS gui library rather than rolling your own and just wasting time doing that?

#6 Bregma   Crossbones+   -  Reputation: 5499

Like
0Likes
Like

Posted 18 January 2011 - 08:41 AM

Thanks, that pointed me in the right direction I think, and I've found a few samples. There is one issue though: Link. That guy's post is the only thing I can find on the internet about this issue, and it hasn't been resolved =\ Can you think of any way to get around that? I was thinking something like sending a certain X event before calling XWarpPointer() and then in my event handler, when I get to the event I sent, ignore the next event, which would be the one sent by XWarpPointer(). Not sure if I'm explaining that right, but does it sound plausible?

It sounds like you're jumping through hoops to reinvent pointer grabbing. You may dislike SDL, but if you're keen on reinventing what it does you might want to look at how it does it.

I think what you really want to do is read up on XGrabPointer() and it's wife/sister XUngrabPointer(). They're the preferred way to do X11 active pointer grabbing.
Stephen M. Webb
Professional Free Software Developer

#7 Chaosenemy   Members   -  Reputation: 152

Like
1Likes
Like

Posted 19 January 2011 - 09:42 AM


For the Windows version of my game engine, I'm using WM_INPUT and registering the mouse device directly to get the most precise movements. Anyone know how I would go about doing this in X11 (for Linux)? I've searched Google about as thoroughly as I can, but finding good documentation for X11 is next to impossible.


Well in general, no one ever accesses pure X11 for handling this stuff as there are gui libraries out there for this. Have you thought about using a cross OS gui library rather than rolling your own and just wasting time doing that?

I've always wanted to make a game engine from scratch (well as close to scratch as possible), so I'd rather not mess with anything but the required APIs/libraries. And anyways, I'm getting very close to being done with the X11 stuff, so I've already come too far at this point to switch to something else.


Thanks, that pointed me in the right direction I think, and I've found a few samples. There is one issue though: Link. That guy's post is the only thing I can find on the internet about this issue, and it hasn't been resolved =\ Can you think of any way to get around that? I was thinking something like sending a certain X event before calling XWarpPointer() and then in my event handler, when I get to the event I sent, ignore the next event, which would be the one sent by XWarpPointer(). Not sure if I'm explaining that right, but does it sound plausible?

It sounds like you're jumping through hoops to reinvent pointer grabbing. You may dislike SDL, but if you're keen on reinventing what it does you might want to look at how it does it.

I think what you really want to do is read up on XGrabPointer() and it's wife/sister XUngrabPointer(). They're the preferred way to do X11 active pointer grabbing.

My big issue with grabbing the pointer is that it breaks external keyboard shortcuts like Alt+Tab. Also if I'm not careful enough about error checking and a fatal bug occurs, the user could end up trapped and have to restart their machine. I dunno, XGrabPointer just bothers me.

Anyways though, the solution I proposed in my last post seems to have worked, so I think I've got it all figured out. Thanks again for pointing me to the XInput extension.

#8 Seaßourne   Members   -  Reputation: 104

Like
-1Likes
Like

Posted 21 January 2011 - 06:19 PM



For the Windows version of my game engine, I'm using WM_INPUT and registering the mouse device directly to get the most precise movements. Anyone know how I would go about doing this in X11 (for Linux)? I've searched Google about as thoroughly as I can, but finding good documentation for X11 is next to impossible.


Well in general, no one ever accesses pure X11 for handling this stuff as there are gui libraries out there for this. Have you thought about using a cross OS gui library rather than rolling your own and just wasting time doing that?

I've always wanted to make a game engine from scratch (well as close to scratch as possible), so I'd rather not mess with anything but the required APIs/libraries. And anyways, I'm getting very close to being done with the X11 stuff, so I've already come too far at this point to switch to something else.


What you going to gain from it? Probably nothing but headaches and just a lot of stuff that others already did for you. I don't see the point of it unless someone has never done it before. Imho, I just think it's stupid to reinvent the wheel like that. Because you could easily just use an api that does it to where you use Windows to develop it, maybe a few to little any changes to have it run on a cell phone, Mac, Linux, FBSD. Hence why I always looked down and made fun of people who think they are doing the right thing and making their own wrapper around win32. Because why reinvent it when someone has already done it and probably better than you'll ever do it.




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