Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Just some cleanup/formatting to make the code more consistent.
  • Loading branch information
adamhalim committed Sep 2, 2024
1 parent 278dc8e commit 0be43b0
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 43 deletions.
2 changes: 1 addition & 1 deletion common/rfb/CConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ void CConnection::updateEncodings()
encodings.push_back(pseudoEncodingContinuousUpdates);
encodings.push_back(pseudoEncodingFence);
encodings.push_back(pseudoEncodingQEMUKeyEvent);
encodings.push_back(pseudoEncodingExtendedMouseButtons);

if (Decoder::supported(preferredEncoding)) {
encodings.push_back(preferredEncoding);
Expand All @@ -852,7 +853,6 @@ void CConnection::updateEncodings()
if (qualityLevel >= 0 && qualityLevel <= 9)
encodings.push_back(pseudoEncodingQualityLevel0 + qualityLevel);

encodings.push_back(pseudoEncodingExtendedMouseButtons);

writer()->writeSetEncodings(encodings);
}
2 changes: 1 addition & 1 deletion common/rfb/CMsgHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void CMsgHandler::endOfContinuousUpdates()
server.supportsContinuousUpdates = true;
}

void CMsgHandler::supportExtendedMouseButtons()
void CMsgHandler::supportsExtendedMouseButtons()
{
server.supportsExtendedMouseButtons = true;
}
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CMsgHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +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();
virtual void supportsExtendedMouseButtons();
virtual void serverInit(int width, int height,
const PixelFormat& pf,
const char* name) = 0;
Expand Down
4 changes: 2 additions & 2 deletions common/rfb/CMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ bool CMsgReader::readMsg()
ret = true;
break;
case pseudoEncodingExtendedMouseButtons:
handler->supportExtendedMouseButtons();
handler->supportsExtendedMouseButtons();
ret = true;
break;
break;
default:
ret = readRect(dataRect, rectEncoding);
break;
Expand Down
1 change: 1 addition & 0 deletions common/rfb/CMsgWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ void CMsgWriter::writePointerEvent(const Point& pos, int buttonMask)
endMsg();
}


void CMsgWriter::writeClientCutText(const char* str)
{
if (strchr(str, '\r') != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/ClientParams.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ bool ClientParams::supportsContinuousUpdates() const
return false;
}

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

int compressLevel;
int qualityLevel;
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void SConnection::supportsQEMUKeyEvent()

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

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

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

client.setEncodings(nEncodings, encodings);

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

Expand Down
20 changes: 14 additions & 6 deletions common/rfb/SMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,26 @@ bool SMsgReader::readKeyEvent()

bool SMsgReader::readPointerEvent()
{
int mask;
int x;
int y;

if (!is->hasData(1 + 2 + 2))
return false;

int mask = is->readU8();
int x = is->readU16();
int y = is->readU16();
mask = is->readU8();
x = is->readU16();
y = is->readU16();

if (handler->client.supportsExtendedMouseButtons() && mask & 0x80 ) {
int highBits;
int lowBits;

if (handler->client.supportExtendedMouseButtons() && mask & 0x80 ) {
if (!is->hasData(1))
return false;

int highBits = is->readU8();
int lowBits = mask & 0x7f; // Clear marker bit
highBits = is->readU8();
lowBits = mask & 0x7f; // Clear marker bit
mask = (highBits << 7) | lowBits;
} else {
// Clear marker bit
Expand All @@ -295,6 +302,7 @@ bool SMsgReader::readPointerEvent()
return true;
}


bool SMsgReader::readClientCutText()
{
if (!is->hasData(3 + 4))
Expand Down
22 changes: 11 additions & 11 deletions common/rfb/SMsgWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SMsgWriter::SMsgWriter(ClientParams* client_, rdr::OutStream* os_)
needSetDesktopName(false), needCursor(false),
needCursorPos(false), needLEDState(false),
needQEMUKeyEvent(false)
,needExtMouseButtonEvent(false)
,needExtMouseButtonsEvent(false)
{
}

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

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

needExtMouseButtonsEvent = true;
}

bool SMsgWriter::needFakeUpdate()
Expand All @@ -324,7 +324,7 @@ bool SMsgWriter::needFakeUpdate()
return true;
if (needQEMUKeyEvent)
return true;
if (needExtMouseButtonEvent)
if (needExtMouseButtonsEvent)
return true;
if (needNoDataUpdate())
return true;
Expand Down Expand Up @@ -374,7 +374,7 @@ void SMsgWriter::writeFramebufferUpdateStart(int nRects)
nRects++;
if (needQEMUKeyEvent)
nRects++;
if (needExtMouseButtonEvent)
if (needExtMouseButtonsEvent)
nRects++;
}

Expand Down Expand Up @@ -516,9 +516,9 @@ void SMsgWriter::writePseudoRects()
needQEMUKeyEvent = false;
}

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

Expand Down Expand Up @@ -753,12 +753,12 @@ void SMsgWriter::writeQEMUKeyEventRect()
os->writeU32(pseudoEncodingQEMUKeyEvent);
}

void SMsgWriter::writeExtendedMouseButtonRect()
void SMsgWriter::writeExtendedMouseButtonsRect()
{
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");
throw Exception("SMsgWriter::writeExtendedMouseButtonsRect: nRects out of sync");

os->writeS16(0);
os->writeS16(0);
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/SMsgWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace rfb {
void writeQEMUKeyEvent();

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

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

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

typedef struct {
uint16_t reason, result;
Expand Down
1 change: 1 addition & 0 deletions vncviewer/Viewport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ void Viewport::resetKeyboard()
handleKeyRelease(downKeySym.begin()->first);
}


void Viewport::handleKeyPress(int keyCode, uint32_t keySym)
{
static bool menuRecursion = false;
Expand Down
1 change: 0 additions & 1 deletion vncviewer/Viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class Viewport : public Fl_Widget, public EmulateMB {
typedef std::map<int, uint32_t> DownMap;
DownMap downKeySym;


#ifdef WIN32
bool altGrArmed;
unsigned int altGrCtrlTime;
Expand Down
22 changes: 11 additions & 11 deletions vncviewer/cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ int cocoa_event_keysym(const void *event)
return ucs2keysym([chars characterAtIndex:0]);
}

void cocoa_get_mouse_coordinates(const void *event, int*x, int *y)
void cocoa_get_mouse_coordinates(const void *event, int *x, int *y)
{
NSEvent *nsevent;
NSPoint pt;
Expand Down Expand Up @@ -517,17 +517,17 @@ int cocoa_get_mouse_button_mask(const void *event, uint16_t *buttonMask,
switch ([nsevent type]) {
case NSLeftMouseDown:
case NSLeftMouseDragged:
(*buttonMask) |= 1 << 0;
*buttonMask |= 1 << 0;
return 0;
case NSLeftMouseUp:
(*buttonMask) &= ~(1 << 0);
*buttonMask &= ~(1 << 0);
return 0;
case NSRightMouseDown:
case NSRightMouseDragged:
(*buttonMask) |= 1 << 2;
*buttonMask |= 1 << 2;
return 0;
case NSRightMouseUp:
(*buttonMask) &= ~(1 << 2);
*buttonMask &= ~(1 << 2);
return 0;
case NSOtherMouseDown:
case NSOtherMouseDragged:
Expand All @@ -541,19 +541,19 @@ int cocoa_get_mouse_button_mask(const void *event, uint16_t *buttonMask,
button = 1 << 8;

if ([nsevent type] == NSOtherMouseUp)
(*buttonMask) &= ~button;
*buttonMask &= ~button;
else
(*buttonMask) |= button;
*buttonMask |= button;
return 0;
case NSScrollWheel:
if (([nsevent deltaY]) > 0)
(*wheelMask) |= 1 << 3;
*wheelMask |= 1 << 3;
if (([nsevent deltaY]) < 0)
(*wheelMask) |= 1 << 4;
*wheelMask |= 1 << 4;
if (([nsevent deltaX]) > 0)
(*wheelMask) |= 1 << 5;
*wheelMask |= 1 << 5;
if (([nsevent deltaX]) < 0)
(*wheelMask) |= 1 << 6;
*wheelMask |= 1 << 6;
return 0;
case NSMouseMoved:
return 0;
Expand Down

0 comments on commit 0be43b0

Please sign in to comment.