views:

156

answers:

1

I am currently implementing a program in X11 using C. I got the program to handle right- and left-click events, however middle-clicking poses a problem. It seems my window manager (Gnome on Ubuntu 9.10) thinks it's better if, instead of having a single middle-click, I should have a series of other clicks instead. I assume it's got something to do with the middle-click being used for copying-pasting. I really don't want this, though, as I'm making a full-screen application with OpenGL, and such things aren't appropriate. Is there any way to have the middle mouse button just working like any other button?

My current code goes something like this:

switch(currentXEvent.type) {
    case ButtonPress:
        switch(currentXEvent.xbutton.button) {
            case 1:
                leftMouseButton(currentXEvent.xbutton.x, currentXEvent.xbutton.y);
                break;
            case 2:
                middleMouseButton(currentXEvent.xbutton.x, currentXEvent.xbutton.y);
                break;
        }
}

My difficulty is that it behaves like leftMouseButton() has been pressed. Any ideas?

+1  A: 

To do this, you have to grab controls from the server. Then the window manager is left out of the processing chain. The most comfortable way is to use libSDL. It creates the appropriate context for a fullscreen OpenGL application and is easier to handle than Xlib+GLX.

ypnos
Thanks for your response. I would prefer not to add another library considering most of the code for working with X has already been written. I would like to know how to grab the controls. I've previously made calls like:XGrabKeyboard(display, window, true, GrabModeAsync, GrabModeAsync, CurrentTime);XGrabPointer(display, window, true, masks, GrabModeAsync, GrabModeAsync, window, None, CurrentTime);Is there something else I would need to add?
Warpspace
Looks good. I don't see anything else needed, just make sure your event_mask is set correctly. In doubt, you may find further hints by looking at the libSDL code. I didn't do the grabbing myself, so this is all the help I can provide.p.s.: If you like my answer, you should give it an upvote. You're new to stackoverflow, that's why I'm telling you -- voting is a vital thing that makes stackoverflow work.
ypnos
It won't let me upvote (I'm too new), but thanks for the reply. You're right, it almost works the way I have it, and the libSDL code will have the rest if I need it. Thanks.
Warpspace