c++qtvnc-viewer

libvncclient SendPointerEvent sending only left button


I am working on a VNC viewer using Qt 5 and the libvncserver / libvncclient library. I am subclassing a QWidget object to provide the VNC viewer widget.

I'm able to connect to a VNC server (running TightVNC and Windows XP), I'm able to move the remote cursor, able to left-click and able to drag things through the viewer, however I have been unsuccessful in getting right-clicks to work. It's as if the server is ignoring right-clicks sent to it, although wherever I right-click does seem to change the focus of the window on the server, but not icons.

Unfortunately the libvncclient documentation is not very helpful if you aren't already an expert. I did look through several projects' code for help, and tried using the approaches there with no success. The one I've settled on for reference is: https://github.com/LibVNC/libvncserver/blob/master/client_examples/SDLvncviewer.c#L383

This is the SendPointerEvent function:

rfbBool SendPointerEvent (rfbClient * client,
    int     x,
    int     y,
    int     buttonMask 
)       

The relevant excerpt from the documentation:

A pointer event includes a cursor location and a button mask. The button mask indicates which buttons on the pointing device are pressed. Each button is represented by a bit in the button mask. A 1 indicates the button is pressed while a 0 indicates that it is not pressed.

You may use these pre-defined button masks by ORing them together: rfbButton1Mask, rfbButton2Mask, rfbButton3Mask, rfbButton4Mask rfbButton5Mask

I'm not understanding when, where and how I should use these pre-defined button masks. I looked at the enum and they all just correspond with '1', '2', '3', etc. Qt emits '1' for left button and '2' for right button.

Here is my relevant code:

static int nButtonMask;

void VncViewer::handleMouseEvents(QMouseEvent* event)
{
    if (event->type() == QMouseEvent::MouseButtonPress) {
        nButtonMask |= event->button();
    }

    if (event->type() == QMouseEvent::MouseButtonRelease) {
        nButtonMask &= ~event->button();
    }

    SendPointerEvent(g.currentViewer->client, event->x(), event->y(), nButtonMask);

    nButtonMask &= ~(rfbButton4Mask | rfbButton5Mask);
}

Any clues on how to make right-clicks work?

Thank you in advance :-)


Solution

  • This is resolved.

    The problem was that the button numbers emitted by Qt were not matching up with the rfb buttons expected by the VNC server. Again, libvncserver's documentation was very unhelpful, so the button mapping issue wasn't noticeable right away.

    All is working well now. :-D Thanks!