Created
August 19, 2016 03:24
-
-
Save willbprog127/5101f9e312e8a1b3ba4ddf3151f44d9d to your computer and use it in GitHub Desktop.
Snippet to show usage of 'GotCursorShape' in libvncserver/libvncclient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This example was written using the Qt toolkit, but you should be | |
* able to get a general idea of what's going on | |
*/ | |
/* ============================================================================== */ | |
/* | |
* When you set up your libvncserver client, you need to set useRemoteCursor | |
* to true and be sure to set the callback for GotCursorShape | |
*/ | |
void VncViewer::setUpVNCClient () | |
{ | |
client = rfbGetClient(3, 3, 2); | |
// client and app options | |
client->canHandleNewFBSize = false; | |
client->appData.qualityLevel = 3; | |
client->appData.compressLevel = 3; | |
client->appData.requestedDepth = 8; | |
client->appData.useRemoteCursor = true; // <===== #### THIS ONE IS IMPORTANT ### | |
// callbacks | |
client->GetPassword = VncViewer::password_proc; | |
client->GotFrameBufferUpdate = VncViewer::fb_start_update; | |
client->FinishedFrameBufferUpdate = VncViewer::fb_end_update; | |
client->GotCursorShape = VncViewer::handleRemoteCursorChange; // <===== #### THIS ONE IS IMPORTANT ### | |
SetFormatAndEncodings(client); | |
} | |
/* | |
* This is a simplified version of what I was using before I abandoned the project. | |
* You will see that the Source and Mask are combined together by Qt to | |
* create a cursor with a transparent background | |
* | |
* This is the callback we set earlier when setting up the libvncserver client | |
* The signature must be as shown below (rfbClient *client, int xhot...) | |
*/ | |
void VncViewer::handleRemoteCursorChange (rfbClient *client, int xhot, int yhot, int width, int height, int bytesPerPixel) | |
{ | |
VncViewer* v = g.currentViewer; | |
if (!v || !v->client) | |
return; | |
if (v->client->rcSource && v->client->rcMask) { | |
QImage imgS = QImage(v->client->rcSource, width, height, width * bytesPerPixel, QImage::Format_RGB16); | |
QImage imgM = QImage(width, height, QImage::Format_Mono); | |
QPixmap pmCursorSource = QPixmap(); | |
pmCursorSource.convertFromImage(imgS); | |
imgM.fromData(v->client->rcMask, width * height); | |
QBitmap pmCursorMask(width, height); | |
pmCursorMask.convertFromImage(imgM); | |
QCursor cCursor = QCursor(pmCursorSource, pmCursorMask, xhot, yhot); | |
g.viewWidget->setCursor(cCursor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment