From 0be43b03dc7a8c35234171e2386a3e59bc29d7a2 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 2 Sep 2024 12:40:23 +0200 Subject: [PATCH] Cleanup Just some cleanup/formatting to make the code more consistent. --- common/rfb/CConnection.cxx | 2 +- common/rfb/CMsgHandler.cxx | 2 +- common/rfb/CMsgHandler.h | 2 +- common/rfb/CMsgReader.cxx | 4 ++-- common/rfb/CMsgWriter.cxx | 1 + common/rfb/ClientParams.cxx | 2 +- common/rfb/ClientParams.h | 2 +- common/rfb/SConnection.cxx | 2 +- common/rfb/SMsgHandler.cxx | 6 +++--- common/rfb/SMsgReader.cxx | 20 ++++++++++++++------ common/rfb/SMsgWriter.cxx | 22 +++++++++++----------- common/rfb/SMsgWriter.h | 6 +++--- vncviewer/Viewport.cxx | 1 + vncviewer/Viewport.h | 1 - vncviewer/cocoa.mm | 22 +++++++++++----------- 15 files changed, 52 insertions(+), 43 deletions(-) diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 4bd71b1cd2..12fc8ef7e4 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -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); @@ -852,7 +853,6 @@ void CConnection::updateEncodings() if (qualityLevel >= 0 && qualityLevel <= 9) encodings.push_back(pseudoEncodingQualityLevel0 + qualityLevel); - encodings.push_back(pseudoEncodingExtendedMouseButtons); writer()->writeSetEncodings(encodings); } diff --git a/common/rfb/CMsgHandler.cxx b/common/rfb/CMsgHandler.cxx index db928d47fc..5c05961678 100644 --- a/common/rfb/CMsgHandler.cxx +++ b/common/rfb/CMsgHandler.cxx @@ -80,7 +80,7 @@ void CMsgHandler::endOfContinuousUpdates() server.supportsContinuousUpdates = true; } -void CMsgHandler::supportExtendedMouseButtons() +void CMsgHandler::supportsExtendedMouseButtons() { server.supportsExtendedMouseButtons = true; } diff --git a/common/rfb/CMsgHandler.h b/common/rfb/CMsgHandler.h index ce7e005751..5963eb396f 100644 --- a/common/rfb/CMsgHandler.h +++ b/common/rfb/CMsgHandler.h @@ -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; diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index 3787950b8e..d7cbc2fd75 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -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; diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx index 47201855ed..2ab5e18c9d 100644 --- a/common/rfb/CMsgWriter.cxx +++ b/common/rfb/CMsgWriter.cxx @@ -205,6 +205,7 @@ void CMsgWriter::writePointerEvent(const Point& pos, int buttonMask) endMsg(); } + void CMsgWriter::writeClientCutText(const char* str) { if (strchr(str, '\r') != nullptr) diff --git a/common/rfb/ClientParams.cxx b/common/rfb/ClientParams.cxx index 367452c8ad..5ea104cf1a 100644 --- a/common/rfb/ClientParams.cxx +++ b/common/rfb/ClientParams.cxx @@ -229,7 +229,7 @@ bool ClientParams::supportsContinuousUpdates() const return false; } -bool ClientParams::supportExtendedMouseButtons() const +bool ClientParams::supportsExtendedMouseButtons() const { if (supportsEncoding(pseudoEncodingExtendedMouseButtons)) return true; diff --git a/common/rfb/ClientParams.h b/common/rfb/ClientParams.h index 156c69bce3..f715c47f16 100644 --- a/common/rfb/ClientParams.h +++ b/common/rfb/ClientParams.h @@ -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; diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 7389579503..ded8774246 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -435,7 +435,7 @@ void SConnection::supportsQEMUKeyEvent() void SConnection::supportsExtendedMouseButtons() { - writer()->writeExtendedMouseButtonSupport(); + writer()->writeExtendedMouseButtonsSupport(); } void SConnection::versionReceived() diff --git a/common/rfb/SMsgHandler.cxx b/common/rfb/SMsgHandler.cxx index bee4530f81..e41b6a0db7 100644 --- a/common/rfb/SMsgHandler.cxx +++ b/common/rfb/SMsgHandler.cxx @@ -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); @@ -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(); } diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index 80ccc74914..6366407bba 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -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 @@ -295,6 +302,7 @@ bool SMsgReader::readPointerEvent() return true; } + bool SMsgReader::readClientCutText() { if (!is->hasData(3 + 4)) diff --git a/common/rfb/SMsgWriter.cxx b/common/rfb/SMsgWriter.cxx index 0590fa10bb..47dd3b4c6f 100644 --- a/common/rfb/SMsgWriter.cxx +++ b/common/rfb/SMsgWriter.cxx @@ -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) { } @@ -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() @@ -324,7 +324,7 @@ bool SMsgWriter::needFakeUpdate() return true; if (needQEMUKeyEvent) return true; - if (needExtMouseButtonEvent) + if (needExtMouseButtonsEvent) return true; if (needNoDataUpdate()) return true; @@ -374,7 +374,7 @@ void SMsgWriter::writeFramebufferUpdateStart(int nRects) nRects++; if (needQEMUKeyEvent) nRects++; - if (needExtMouseButtonEvent) + if (needExtMouseButtonsEvent) nRects++; } @@ -516,9 +516,9 @@ void SMsgWriter::writePseudoRects() needQEMUKeyEvent = false; } - if (needExtMouseButtonEvent) { - writeExtendedMouseButtonRect(); - needExtMouseButtonEvent = false; + if (needExtMouseButtonsEvent) { + writeExtendedMouseButtonsRect(); + needExtMouseButtonsEvent = false; } } @@ -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); diff --git a/common/rfb/SMsgWriter.h b/common/rfb/SMsgWriter.h index e96257ea6b..7bc0ed6a50 100644 --- a/common/rfb/SMsgWriter.h +++ b/common/rfb/SMsgWriter.h @@ -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. @@ -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; @@ -164,7 +164,7 @@ namespace rfb { bool needCursorPos; bool needLEDState; bool needQEMUKeyEvent; - bool needExtMouseButtonEvent; + bool needExtMouseButtonsEvent; typedef struct { uint16_t reason, result; diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 57754669bc..e4894aae87 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -789,6 +789,7 @@ void Viewport::resetKeyboard() handleKeyRelease(downKeySym.begin()->first); } + void Viewport::handleKeyPress(int keyCode, uint32_t keySym) { static bool menuRecursion = false; diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index a790ddf2f7..f0dcf4f0e5 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -120,7 +120,6 @@ class Viewport : public Fl_Widget, public EmulateMB { typedef std::map DownMap; DownMap downKeySym; - #ifdef WIN32 bool altGrArmed; unsigned int altGrCtrlTime; diff --git a/vncviewer/cocoa.mm b/vncviewer/cocoa.mm index 93af37e531..8b3c11deb7 100644 --- a/vncviewer/cocoa.mm +++ b/vncviewer/cocoa.mm @@ -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; @@ -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: @@ -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;