Skip to content

Commit

Permalink
Fixed recommended issues. Added support on native FLTK for mouse butt…
Browse files Browse the repository at this point in the history
…ons 8 and 9. Removed the use of the Client message for the psuedo encoding.
  • Loading branch information
PixelSmith committed Jan 5, 2024
1 parent 63ea8b2 commit 1105449
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 81 deletions.
13 changes: 4 additions & 9 deletions common/rfb/CMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ bool CMsgReader::readMsg()
case msgTypeEndOfContinuousUpdates:
ret = readEndOfContinuousUpdates();
break;
case msgTypeExtendedMouseSupport:
ret = readSupportExtendedMouseButton();
break;
default:
throw Exception("Unknown message type %d", currentMsgType);
}
Expand Down Expand Up @@ -205,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 Expand Up @@ -457,12 +458,6 @@ bool CMsgReader::readEndOfContinuousUpdates()
return true;
}

bool CMsgReader::readSupportExtendedMouseButton()
{
handler->supportExtendedMouseButtons();
return true;
}

bool CMsgReader::readFramebufferUpdate()
{
if (!is->hasData(1 + 2))
Expand Down
1 change: 0 additions & 1 deletion common/rfb/CMsgReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ namespace rfb {
bool readExtendedClipboard(int32_t len);
bool readFence();
bool readEndOfContinuousUpdates();
bool readSupportExtendedMouseButton();

bool readFramebufferUpdate();

Expand Down
33 changes: 13 additions & 20 deletions common/rfb/CMsgWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -182,29 +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;

if (server->supportsExtendedMouseButtons)
{
writePointerEventExt(pos,buttonMask);
return;
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();
}

startMsg(msgTypePointerEvent);
os->writeU8(buttonMask);
os->writeU16(p.x);
os->writeU16(p.y);
endMsg();
}

void CMsgWriter::writePointerEventExt(const Point& p, int buttonMask)
{
startMsg(msgTypePointerEventExt);
os->writeU16(buttonMask);
os->writeU16(p.x);
os->writeU16(p.y);
endMsg();
}


void CMsgWriter::writeClientCutText(const char* str)
{
if (strchr(str, '\r') != NULL)
Expand Down
1 change: 0 additions & 1 deletion common/rfb/CMsgWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace rfb {

void writeKeyEvent(uint32_t keysym, uint32_t keycode, bool down);
void writePointerEvent(const Point& pos, int buttonMask);
void writePointerEventExt(const Point& pos, int buttonMask);

void writeClientCutText(const char* str);

Expand Down
5 changes: 3 additions & 2 deletions 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,7 +73,7 @@ void SMsgHandler::setEncodings(int nEncodings, const int32_t* encodings)
supportsLEDState();
if (client.supportsEncoding(pseudoEncodingQEMUKeyEvent) && firstQEMUKeyEvent)
supportsQEMUKeyEvent();
if (client.supportsEncoding(pseudoEncodingExtendedMouseButtons))
if (client.supportsEncoding(pseudoEncodingExtendedMouseButtons) && firstExtMouseButtonEvent)
supportsExtendedMouseButtons();
}

Expand Down
4 changes: 2 additions & 2 deletions common/rfb/SMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool SMsgReader::readMsg()
ret = readPointerEvent();
break;
case msgTypePointerEventExt:
ret = readPointerEvenExt();
ret = readPointerEventExt();
break;
case msgTypeClientCutText:
ret = readClientCutText();
Expand Down Expand Up @@ -284,7 +284,7 @@ bool SMsgReader::readPointerEvent()
return true;
}

bool SMsgReader::readPointerEvenExt()
bool SMsgReader::readPointerEventExt()
{
if (!is->hasData(2 + 2 + 2))
return false;
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SMsgReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace rfb {

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

Expand Down
29 changes: 26 additions & 3 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 @@ -307,9 +308,8 @@ void SMsgWriter::writeExtendedMouseButtonSupport()
{
if (!client->supportsEncoding(pseudoEncodingExtendedMouseButtons))
throw Exception("Client does not support Extended Mouse Buttons");

startMsg(msgTypeExtendedMouseSupport);
endMsg();

needExtMouseButtonEvent = true;
}

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

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

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

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

void SMsgWriter::writeNoDataRects()
Expand Down Expand Up @@ -744,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);
}
2 changes: 2 additions & 0 deletions common/rfb/SMsgWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,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 @@ -163,6 +164,7 @@ namespace rfb {
bool needCursorPos;
bool needLEDState;
bool needQEMUKeyEvent;
bool needExtMouseButtonEvent;

typedef struct {
uint16_t reason, result;
Expand Down
2 changes: 0 additions & 2 deletions common/rfb/msgTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace rfb {

const int msgTypeEndOfContinuousUpdates = 150;

const int msgTypeExtendedMouseSupport = 151;

const int msgTypeServerFence = 248;

// client to server
Expand Down
11 changes: 3 additions & 8 deletions java/com/tigervnc/rfb/CMsgReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ public void readMsg()
case MsgTypes.msgTypeEndOfContinuousUpdates:
readEndOfContinuousUpdates();
break;
case MsgTypes.msgTypeExtendedMouseSupport:
readSupportExtendedMouseButton();
break;
default:
vlog.error("unknown message type "+type);
throw new Exception("unknown message type");
Expand Down Expand Up @@ -119,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 Expand Up @@ -195,11 +195,6 @@ protected void readEndOfContinuousUpdates()
handler.endOfContinuousUpdates();
}

protected void readSupportExtendedMouseButton()
{
handler.SupportExtendedMouseButton();
}

protected void readFramebufferUpdate()
{
is.skip(1);
Expand Down
32 changes: 13 additions & 19 deletions java/com/tigervnc/rfb/CMsgWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +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;

if(server.supportsExtendedMouseButtons)
{
writePointerEventExt(pos,buttonMask);
return;
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();
}

startMsg(MsgTypes.msgTypePointerEvent);
os.writeU8(buttonMask);
os.writeU16(p.x);
os.writeU16(p.y);
endMsg();
}

synchronized public void writePointerEventExt(Point p, int buttonMask)
{
startMsg(MsgTypes.msgTypePointerEventExt);
os.writeU16(buttonMask);
os.writeU16(p.x);
os.writeU16(p.y);
endMsg();
}

synchronized public void writeClientCutText(String str, int len)
Expand Down
12 changes: 6 additions & 6 deletions java/com/tigervnc/vncviewer/Viewport.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ public int handle(MouseEvent e)
if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) != 0)
buttonMask |= 4;

//there are no masks for buttons 4 and 5 so we need to check for them only when pressed.
if (tk.areExtraMouseButtonsEnabled() && e.getID() == MouseEvent.MOUSE_PRESSED) {
//there are no masks for buttons 6 and 7 so we need to check for them only when pressed.
if (tk.areExtraMouseButtonsEnabled()){
//Back
if (MouseInfo.getNumberOfButtons() >= 4 && e.getButton() == 6)
buttonMask |= 128;
if (MouseInfo.getNumberOfButtons() >= 6 && ((e.getModifiersEx() & e.getMaskForButton(6)) != 0))
buttonMask |= 1024;
//Forward
if (MouseInfo.getNumberOfButtons() >= 5 && e.getButton() == 7)
buttonMask |= 256;
if (MouseInfo.getNumberOfButtons() >= 7 && ((e.getModifiersEx() & e.getMaskForButton(7)) != 0))
buttonMask |= 512;
}

if (e.getID() == MouseEvent.MOUSE_WHEEL) {
Expand Down
9 changes: 6 additions & 3 deletions unix/xserver/hw/vnc/vncInput.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern const unsigned int code_map_qnum_to_xorgevdev_len;
extern const unsigned short code_map_qnum_to_xorgkbd[];
extern const unsigned int code_map_qnum_to_xorgkbd_len;

#define BUTTONS 9
#define BUTTONS 11

DeviceIntPtr vncKeyboardDev;
DeviceIntPtr vncPointerDev;
Expand Down Expand Up @@ -206,8 +206,11 @@ static int vncPointerProc(DeviceIntPtr pDevice, int onoff)
btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
btn_labels[7] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_BACK);
btn_labels[8] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_FORWARD);
btn_labels[7] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_SIDE);
btn_labels[8] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_EXTRA);
btn_labels[9] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_FORWARD);
btn_labels[10] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_BACK);



axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
Expand Down
11 changes: 7 additions & 4 deletions vncviewer/Viewport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,13 @@ int Viewport::handle(int event)
if (Fl::event_button3())
buttonMask |= 4;

if(Fl::event_buttons()&FL_BUTTON(4))
buttonMask |= 128;
if(Fl::event_buttons()&FL_BUTTON(5))
buttonMask |= 256;
//Fl::event_button is only good for FL_PUSH and FL_RELEASE
if(event == FL_PUSH) {
if (Fl::event_button() == 8) //Mouse Back
buttonMask |= 1024;
if (Fl::event_button() == 9) //Mouse Forward
buttonMask |= 512;
}

if (event == FL_MOUSEWHEEL) {
wheelMask = 0;
Expand Down

0 comments on commit 1105449

Please sign in to comment.