Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the abillity for vnc to use 9 mouse buttons instead of 7. #1711

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/rfb/CConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,7 @@ void CConnection::updateEncodings()
if (qualityLevel >= 0 && qualityLevel <= 9)
encodings.push_back(pseudoEncodingQualityLevel0 + qualityLevel);

encodings.push_back(pseudoEncodingExtendedMouseButtons);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not with all the other stuff further up?


writer()->writeSetEncodings(encodings);
}
5 changes: 5 additions & 0 deletions common/rfb/CMsgHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ void CMsgHandler::endOfContinuousUpdates()
server.supportsContinuousUpdates = true;
}

void CMsgHandler::supportExtendedMouseButtons()
{
server.supportsExtendedMouseButtons = true;
}

void CMsgHandler::supportsQEMUKeyEvent()
{
server.supportsQEMUKeyEvent = true;
Expand Down
1 change: 1 addition & 0 deletions common/rfb/CMsgHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace rfb {
virtual void fence(uint32_t flags, unsigned len, const uint8_t data[]);
virtual void endOfContinuousUpdates();
virtual void supportsQEMUKeyEvent();
virtual void supportExtendedMouseButtons();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supports

virtual void serverInit(int width, int height,
const PixelFormat& pf,
const char* name) = 0;
Expand Down
4 changes: 4 additions & 0 deletions common/rfb/CMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ bool CMsgReader::readMsg()
handler->supportsQEMUKeyEvent();
ret = true;
break;
case pseudoEncodingExtendedMouseButtons:
handler->supportExtendedMouseButtons();
ret = true;
break;
default:
ret = readRect(dataRect, rectEncoding);
break;
Expand Down
20 changes: 14 additions & 6 deletions common/rfb/CMsgWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,22 @@ void CMsgWriter::writePointerEvent(const Point& pos, int buttonMask)
if (p.x >= server->width()) p.x = server->width() - 1;
if (p.y >= server->height()) p.y = server->height() - 1;

startMsg(msgTypePointerEvent);
os->writeU8(buttonMask);
os->writeU16(p.x);
os->writeU16(p.y);
endMsg();
if (server->supportsExtendedMouseButtons) {
startMsg(msgTypePointerEventExt);
os->writeU16(buttonMask);
os->writeU16(p.x);
os->writeU16(p.y);
endMsg();
}
else {
startMsg(msgTypePointerEvent);
os->writeU8(buttonMask);
os->writeU16(p.x);
os->writeU16(p.y);
endMsg();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks small enough that we can hopefully keep things in the same method? Like we do for key events.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sure. I had it in different methods to lessen merge conflicts since i was just running this locally. it makes sense to make the main method handle both cases if it's going to be in master.



void CMsgWriter::writeClientCutText(const char* str)
{
if (strchr(str, '\r') != NULL)
Expand Down
7 changes: 7 additions & 0 deletions common/rfb/ClientParams.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,10 @@ bool ClientParams::supportsContinuousUpdates() const
return true;
return false;
}

bool ClientParams::supportExtendedMouseButtons() const
{
if (supportsEncoding(pseudoEncodingExtendedMouseButtons))
return true;
return false;
}
1 change: 1 addition & 0 deletions common/rfb/ClientParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace rfb {
bool supportsLEDState() const;
bool supportsFence() const;
bool supportsContinuousUpdates() const;
bool supportExtendedMouseButtons() const;

int compressLevel;
int qualityLevel;
Expand Down
5 changes: 5 additions & 0 deletions common/rfb/SConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ void SConnection::supportsQEMUKeyEvent()
writer()->writeQEMUKeyEvent();
}

void SConnection::supportsExtendedMouseButtons()
{
writer()->writeExtendedMouseButtonSupport();
}

void SConnection::versionReceived()
{
}
Expand Down
2 changes: 2 additions & 0 deletions common/rfb/SConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ namespace rfb {

virtual void supportsQEMUKeyEvent();

virtual void supportsExtendedMouseButtons() override;


// Methods to be overridden in a derived class

Expand Down
9 changes: 8 additions & 1 deletion common/rfb/SMsgHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ void SMsgHandler::setPixelFormat(const PixelFormat& pf)
void SMsgHandler::setEncodings(int nEncodings, const int32_t* encodings)
{
bool firstFence, firstContinuousUpdates, firstLEDState,
firstQEMUKeyEvent;
firstQEMUKeyEvent, firstExtMouseButtonEvent;

firstFence = !client.supportsFence();
firstContinuousUpdates = !client.supportsContinuousUpdates();
firstLEDState = !client.supportsLEDState();
firstQEMUKeyEvent = !client.supportsEncoding(pseudoEncodingQEMUKeyEvent);
firstExtMouseButtonEvent = !client.supportsEncoding(pseudoEncodingExtendedMouseButtons);

client.setEncodings(nEncodings, encodings);

Expand All @@ -72,6 +73,8 @@ void SMsgHandler::setEncodings(int nEncodings, const int32_t* encodings)
supportsLEDState();
if (client.supportsEncoding(pseudoEncodingQEMUKeyEvent) && firstQEMUKeyEvent)
supportsQEMUKeyEvent();
if (client.supportsEncoding(pseudoEncodingExtendedMouseButtons) && firstExtMouseButtonEvent)
supportsExtendedMouseButtons();
}

void SMsgHandler::handleClipboardCaps(uint32_t flags, const uint32_t* lengths)
Expand Down Expand Up @@ -153,3 +156,7 @@ void SMsgHandler::supportsLEDState()
void SMsgHandler::supportsQEMUKeyEvent()
{
}

void SMsgHandler::supportsExtendedMouseButtons()
{
}
5 changes: 5 additions & 0 deletions common/rfb/SMsgHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ namespace rfb {
// handler will send a pseudo-rect back, signalling server support.
virtual void supportsQEMUKeyEvent();

// supportsExtendedMouseButtons() is called the first time we detect that the
// client supports sending 16 bit mouse button state. This lets us pass more button
// states between server and client.
virtual void supportsExtendedMouseButtons();

ClientParams client;
};
}
Expand Down
13 changes: 13 additions & 0 deletions common/rfb/SMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ bool SMsgReader::readMsg()
case msgTypePointerEvent:
ret = readPointerEvent();
break;
case msgTypePointerEventExt:
ret = readPointerEventExt();
break;
case msgTypeClientCutText:
ret = readClientCutText();
break;
Expand Down Expand Up @@ -281,6 +284,16 @@ bool SMsgReader::readPointerEvent()
return true;
}

bool SMsgReader::readPointerEventExt()
{
if (!is->hasData(2 + 2 + 2))
return false;
int mask = is->readU16();
int x = is->readU16();
int y = is->readU16();
handler->pointerEvent(Point(x, y), mask);
return true;
}

bool SMsgReader::readClientCutText()
{
Expand Down
1 change: 1 addition & 0 deletions common/rfb/SMsgReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace rfb {

bool readKeyEvent();
bool readPointerEvent();
bool readPointerEventExt();
bool readClientCutText();
bool readExtendedClipboard(int32_t len);

Expand Down
32 changes: 32 additions & 0 deletions common/rfb/SMsgWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SMsgWriter::SMsgWriter(ClientParams* client_, rdr::OutStream* os_)
needSetDesktopName(false), needCursor(false),
needCursorPos(false), needLEDState(false),
needQEMUKeyEvent(false)
,needExtMouseButtonEvent(false)
{
}

Expand Down Expand Up @@ -303,6 +304,14 @@ void SMsgWriter::writeQEMUKeyEvent()
needQEMUKeyEvent = true;
}

void SMsgWriter::writeExtendedMouseButtonSupport()
{
if (!client->supportsEncoding(pseudoEncodingExtendedMouseButtons))
throw Exception("Client does not support Extended Mouse Buttons");

needExtMouseButtonEvent = true;
}

bool SMsgWriter::needFakeUpdate()
{
if (needSetDesktopName)
Expand All @@ -315,6 +324,8 @@ bool SMsgWriter::needFakeUpdate()
return true;
if (needQEMUKeyEvent)
return true;
if (needExtMouseButtonEvent)
return true;
if (needNoDataUpdate())
return true;

Expand Down Expand Up @@ -363,6 +374,8 @@ void SMsgWriter::writeFramebufferUpdateStart(int nRects)
nRects++;
if (needQEMUKeyEvent)
nRects++;
if (needExtMouseButtonEvent)
nRects++;
}

os->writeU16(nRects);
Expand Down Expand Up @@ -502,6 +515,11 @@ void SMsgWriter::writePseudoRects()
writeQEMUKeyEventRect();
needQEMUKeyEvent = false;
}

if (needExtMouseButtonEvent) {
writeExtendedMouseButtonRect();
needExtMouseButtonEvent = false;
}
}

void SMsgWriter::writeNoDataRects()
Expand Down Expand Up @@ -735,3 +753,17 @@ void SMsgWriter::writeQEMUKeyEventRect()
os->writeU16(0);
os->writeU32(pseudoEncodingQEMUKeyEvent);
}

void SMsgWriter::writeExtendedMouseButtonRect()
{
if (!client->supportsEncoding(pseudoEncodingExtendedMouseButtons))
throw Exception("Client does not support extended mouse button events");
if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
throw Exception("SMsgWriter::writeExtendedMouseButtonRect: nRects out of sync");

os->writeS16(0);
os->writeS16(0);
os->writeU16(0);
os->writeU16(0);
os->writeU32(pseudoEncodingExtendedMouseButtons);
}
5 changes: 5 additions & 0 deletions common/rfb/SMsgWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ namespace rfb {
// And QEMU keyboard event handshake
void writeQEMUKeyEvent();

// let the client know we support extended mouse button support
void writeExtendedMouseButtonSupport();

// needFakeUpdate() returns true when an immediate update is needed in
// order to flush out pseudo-rectangles to the client.
bool needFakeUpdate();
Expand Down Expand Up @@ -148,6 +151,7 @@ namespace rfb {
void writeSetVMwareCursorPositionRect(int hotspotX, int hotspotY);
void writeLEDStateRect(uint8_t state);
void writeQEMUKeyEventRect();
void writeExtendedMouseButtonRect();

ClientParams* client;
rdr::OutStream* os;
Expand All @@ -160,6 +164,7 @@ namespace rfb {
bool needCursorPos;
bool needLEDState;
bool needQEMUKeyEvent;
bool needExtMouseButtonEvent;

typedef struct {
uint16_t reason, result;
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/ServerParams.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ServerParams::ServerParams()
: majorVersion(0), minorVersion(0),
supportsQEMUKeyEvent(false),
supportsSetDesktopSize(false), supportsFence(false),
supportsContinuousUpdates(false),
supportsContinuousUpdates(false), supportsExtendedMouseButtons(false),
width_(0), height_(0),
ledState_(ledUnknown)
{
Expand Down
1 change: 1 addition & 0 deletions common/rfb/ServerParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace rfb {
bool supportsSetDesktopSize;
bool supportsFence;
bool supportsContinuousUpdates;
bool supportsExtendedMouseButtons;

private:

Expand Down
1 change: 1 addition & 0 deletions common/rfb/encodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace rfb {

const int pseudoEncodingXCursor = -240;
const int pseudoEncodingCursor = -239;
const int pseudoEncodingExtendedMouseButtons = -241;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to be allocated with IANA before we can merge things:

https://www.iana.org/form/protocol-assignment
https://www.iana.org/assignments/rfb/rfb.xml

I'd also like to see a PR for documenting this new extension:

https://github.com/rfbproto/rfbproto

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, i had no idea what these numbers were haha.

const int pseudoEncodingDesktopSize = -223;
const int pseudoEncodingLEDState = -261;
const int pseudoEncodingExtendedDesktopSize = -308;
Expand Down
2 changes: 2 additions & 0 deletions common/rfb/msgTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace rfb {
const int msgTypeKeyEvent = 4;
const int msgTypePointerEvent = 5;
const int msgTypeClientCutText = 6;
const int msgTypePointerEventExt = 7;


const int msgTypeEnableContinuousUpdates = 150;

Expand Down
8 changes: 8 additions & 0 deletions java/com/tigervnc/rfb/CConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ public void endOfContinuousUpdates()
requestNewUpdate();
}
}

public void SupportExtendedMouseButton()
{
super.SupportExtendedMouseButton();
}

// serverInit() is called when the ServerInit message is received. The
// derived class must call on to CConnection::serverInit().
public void serverInit(int width, int height,
Expand Down Expand Up @@ -683,6 +689,8 @@ private void updateEncodings()
encodings.add(Encodings.pseudoEncodingLastRect);
encodings.add(Encodings.pseudoEncodingContinuousUpdates);
encodings.add(Encodings.pseudoEncodingFence);
encodings.add(Encodings.pseudoEncodingExtendedMouseButtons);


if (Decoder.supported(preferredEncoding)) {
encodings.add(preferredEncoding);
Expand Down
5 changes: 5 additions & 0 deletions java/com/tigervnc/rfb/CMsgHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public void endOfContinuousUpdates()
server.supportsContinuousUpdates = true;
}

public void SupportExtendedMouseButton()
{
server.supportsExtendedMouseButtons = true;
}

abstract public void clientRedirect(int port, String host,
String x509subject);

Expand Down
3 changes: 3 additions & 0 deletions java/com/tigervnc/rfb/CMsgReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public void readMsg()
case Encodings.pseudoEncodingExtendedDesktopSize:
readExtendedDesktopSize(x, y, w, h);
break;
case Encodings.pseudoEncodingExtendedMouseButtons:
handler.SupportExtendedMouseButton();
break;
case Encodings.pseudoEncodingClientRedirect:
nUpdateRectsLeft = 0;
readClientRedirect(x, y, w, h);
Expand Down
19 changes: 14 additions & 5 deletions java/com/tigervnc/rfb/CMsgWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,20 @@ synchronized public void writePointerEvent(Point pos, int buttonMask)
if (p.x >= server.width()) p.x = server.width() - 1;
if (p.y >= server.height()) p.y = server.height() - 1;

startMsg(MsgTypes.msgTypePointerEvent);
os.writeU8(buttonMask);
os.writeU16(p.x);
os.writeU16(p.y);
endMsg();
if(server.supportsExtendedMouseButtons) {
startMsg(MsgTypes.msgTypePointerEventExt);
os.writeU16(buttonMask);
os.writeU16(p.x);
os.writeU16(p.y);
endMsg();
}
else {
startMsg(MsgTypes.msgTypePointerEvent);
os.writeU8(buttonMask);
os.writeU16(p.x);
os.writeU16(p.y);
endMsg();
}
}

synchronized public void writeClientCutText(String str, int len)
Expand Down
1 change: 1 addition & 0 deletions java/com/tigervnc/rfb/Encodings.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Encodings {

public static final int pseudoEncodingXCursor = -240;
public static final int pseudoEncodingCursor = -239;
public static final int pseudoEncodingExtendedMouseButtons = -241;
public static final int pseudoEncodingDesktopSize = -223;
public static final int pseudoEncodingExtendedDesktopSize = -308;
public static final int pseudoEncodingDesktopName = -307;
Expand Down
Loading