470,870 Members | 1,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

xlib and mouse button


I'm trying to use the Xlib library to detect a mouse button event in C. I'm using linux. I want to run a loop and exit this loop when a mouse button is pressed. It seems possible to me to wait for an event to happen but it it possible to compute something else while we're waiting?

I thought of something like :

do {
} while !(buttonstate1==pressed)

So my question is: is there a command to read the state (pressed or not) of the mouse button?

Jan 13 '08 #1
1 4181
463 Expert 256MB
X windows is based on an event structure and mechanism. Somewhere in your program you turn on X and let it run. All this does is loop over events. Unfortunately, it doesn't allow for other tasks to happen. To get around this limitation, everything that needs to be done is through the X events. This has some draw backs but works reasonably well.

If you want to intercept the events directly, you can modify the X main loop, but this can be pretty messy. Take a look at http://www.everything2.com/index.pl?node_id=39055 for more info.

Usually, you work with X through the widgets. The widgets control the events via callbacks and actions. This is really the way you want to go. For example, to read the mouse from a display widget, you would set a callback for mouse events. Now, the widget will call your routine whenever a mouse event happens.
Jan 14 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by John Champaign | last post: by
reply views Thread by Ed Suominen | last post: by
2 posts views Thread by Artificial Life | last post: by
7 posts views Thread by Tyron | last post: by
reply views Thread by Ferry Boender | last post: by
1 post views Thread by giovanni.iovino | last post: by
2 posts views Thread by Dariusz.Donimirski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.