From 9fae0999d3efa7a04698d639f7bd842ede7a83d2 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sat, 25 Feb 2023 15:16:18 +0100 Subject: [PATCH] Better type for pointer button mask This is a very limited bit field, so use an 8 bit type to clearly show how many bits are available. --- common/rfb/CMsgWriter.cxx | 2 +- common/rfb/CMsgWriter.h | 2 +- common/rfb/SDesktop.h | 2 +- common/rfb/SMsgHandler.cxx | 2 +- common/rfb/SMsgHandler.h | 2 +- common/rfb/VNCSConnectionST.cxx | 2 +- common/rfb/VNCSConnectionST.h | 2 +- common/rfb/VNCServerST.cxx | 2 +- common/rfb/VNCServerST.h | 2 +- tests/unit/emulatemb.cxx | 6 +++--- unix/x0vncserver/XDesktop.cxx | 2 +- unix/x0vncserver/XDesktop.h | 4 ++-- unix/xserver/hw/vnc/XserverDesktop.cc | 2 +- unix/xserver/hw/vnc/XserverDesktop.h | 2 +- vncviewer/EmulateMB.cxx | 8 ++++---- vncviewer/EmulateMB.h | 12 ++++++------ vncviewer/Viewport.cxx | 4 ++-- vncviewer/Viewport.h | 6 +++--- win/rfb_win32/SDisplay.cxx | 2 +- win/rfb_win32/SDisplay.h | 2 +- win/rfb_win32/SInput.cxx | 2 +- win/rfb_win32/SInput.h | 2 +- 22 files changed, 36 insertions(+), 36 deletions(-) diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx index 7d757968..1bd8040f 100644 --- a/common/rfb/CMsgWriter.cxx +++ b/common/rfb/CMsgWriter.cxx @@ -173,7 +173,7 @@ void CMsgWriter::writeKeyEvent(uint32_t keysym, uint32_t keycode, bool down) } -void CMsgWriter::writePointerEvent(const Point& pos, int buttonMask) +void CMsgWriter::writePointerEvent(const Point& pos, uint8_t buttonMask) { Point p(pos); if (p.x < 0) p.x = 0; diff --git a/common/rfb/CMsgWriter.h b/common/rfb/CMsgWriter.h index 1b70a1d0..61df567f 100644 --- a/common/rfb/CMsgWriter.h +++ b/common/rfb/CMsgWriter.h @@ -54,7 +54,7 @@ namespace rfb { void writeFence(uint32_t flags, unsigned len, const uint8_t data[]); void writeKeyEvent(uint32_t keysym, uint32_t keycode, bool down); - void writePointerEvent(const Point& pos, int buttonMask); + void writePointerEvent(const Point& pos, uint8_t buttonMask); void writeClientCutText(const char* str); diff --git a/common/rfb/SDesktop.h b/common/rfb/SDesktop.h index bcdee93c..1d3c325f 100644 --- a/common/rfb/SDesktop.h +++ b/common/rfb/SDesktop.h @@ -98,7 +98,7 @@ namespace rfb { // pointerEvent() is called whenever a client sends an event that // the pointer moved, or a button was pressed or released. virtual void pointerEvent(const Point& /*pos*/, - int /*buttonMask*/) {}; + uint8_t /*buttonMask*/) {}; // handleClipboardRequest() is called whenever a client requests // the server to send over its clipboard data. It will only be diff --git a/common/rfb/SMsgHandler.cxx b/common/rfb/SMsgHandler.cxx index a5f1b7cf..03917926 100644 --- a/common/rfb/SMsgHandler.cxx +++ b/common/rfb/SMsgHandler.cxx @@ -80,7 +80,7 @@ void SMsgHandler::keyEvent(uint32_t /*keysym*/, uint32_t /*keycode*/, } void SMsgHandler::pointerEvent(const Point& /*pos*/, - int /*buttonMask*/) + uint8_t /*buttonMask*/) { } diff --git a/common/rfb/SMsgHandler.h b/common/rfb/SMsgHandler.h index de14d626..cff8b1bd 100644 --- a/common/rfb/SMsgHandler.h +++ b/common/rfb/SMsgHandler.h @@ -57,7 +57,7 @@ namespace rfb { virtual void keyEvent(uint32_t keysym, uint32_t keycode, bool down); virtual void pointerEvent(const Point& pos, - int buttonMask); + uint8_t buttonMask); virtual void clientCutText(const char* str); diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index d20da8cb..bc036004 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -477,7 +477,7 @@ void VNCSConnectionST::setPixelFormat(const PixelFormat& pf) setCursor(); } -void VNCSConnectionST::pointerEvent(const Point& pos, int buttonMask) +void VNCSConnectionST::pointerEvent(const Point& pos, uint8_t buttonMask) { if (rfb::Server::idleTimeout) idleTimer.start(secsToMillis(rfb::Server::idleTimeout)); diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index e9badd72..d857ef32 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -123,7 +123,7 @@ namespace rfb { void queryConnection(const char* userName) override; void clientInit(bool shared) override; void setPixelFormat(const PixelFormat& pf) override; - void pointerEvent(const Point& pos, int buttonMask) override; + void pointerEvent(const Point& pos, uint8_t buttonMask) override; void keyEvent(uint32_t keysym, uint32_t keycode, bool down) override; void framebufferUpdateRequest(const Rect& r, diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 705f7df2..114ff347 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -482,7 +482,7 @@ void VNCServerST::keyEvent(uint32_t keysym, uint32_t keycode, bool down) } void VNCServerST::pointerEvent(VNCSConnectionST* client, - const Point& pos, int buttonMask) + const Point& pos, uint8_t buttonMask) { time_t now = time(nullptr); if (rfb::Server::maxIdleTime) diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index 501882aa..6cc75a68 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -117,7 +117,7 @@ namespace rfb { // Event handlers void keyEvent(uint32_t keysym, uint32_t keycode, bool down); - void pointerEvent(VNCSConnectionST* client, const Point& pos, int buttonMask); + void pointerEvent(VNCSConnectionST* client, const Point& pos, uint8_t buttonMask); void handleClipboardRequest(VNCSConnectionST* client); void handleClipboardAnnounce(VNCSConnectionST* client, bool available); diff --git a/tests/unit/emulatemb.cxx b/tests/unit/emulatemb.cxx index 662eedef..ae022c06 100644 --- a/tests/unit/emulatemb.cxx +++ b/tests/unit/emulatemb.cxx @@ -42,14 +42,14 @@ rfb::BoolParameter emulateMiddleButton("dummy_name", "dummy_desc", true); class TestClass : public EmulateMB { public: - void sendPointerEvent(const rfb::Point& pos, int buttonMask) override; + void sendPointerEvent(const rfb::Point& pos, uint8_t buttonMask) override; - struct PointerEventParams {rfb::Point pos; int mask; }; + struct PointerEventParams {rfb::Point pos; uint8_t mask; }; std::vector results; }; -void TestClass::sendPointerEvent(const rfb::Point& pos, int buttonMask) +void TestClass::sendPointerEvent(const rfb::Point& pos, uint8_t buttonMask) { PointerEventParams params; params.pos = pos; diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index 24cba0df..29af059f 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -342,7 +342,7 @@ void XDesktop::queryConnection(network::Socket* sock, queryConnectDialog->map(); } -void XDesktop::pointerEvent(const Point& pos, int buttonMask) { +void XDesktop::pointerEvent(const Point& pos, uint8_t buttonMask) { #ifdef HAVE_XTEST if (!haveXtest) return; XTestFakeMotionEvent(dpy, DefaultScreen(dpy), diff --git a/unix/x0vncserver/XDesktop.h b/unix/x0vncserver/XDesktop.h index e952fba9..cf374fb9 100644 --- a/unix/x0vncserver/XDesktop.h +++ b/unix/x0vncserver/XDesktop.h @@ -60,7 +60,7 @@ public: bool isRunning(); void queryConnection(network::Socket* sock, const char* userName) override; - void pointerEvent(const rfb::Point& pos, int buttonMask) override; + void pointerEvent(const rfb::Point& pos, uint8_t buttonMask) override; void keyEvent(uint32_t keysym, uint32_t xtcode, bool down) override; unsigned int setScreenLayout(int fb_width, int fb_height, const rfb::ScreenSet& layout) override; @@ -79,7 +79,7 @@ protected: rfb::VNCServer* server; QueryConnectDialog* queryConnectDialog; network::Socket* queryConnectSock; - int oldButtonMask; + uint8_t oldButtonMask; bool haveXtest; bool haveDamage; int maxButtons; diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index 0c2b5bf9..e3bc57d8 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -463,7 +463,7 @@ void XserverDesktop::terminate() kill(getpid(), SIGTERM); } -void XserverDesktop::pointerEvent(const Point& pos, int buttonMask) +void XserverDesktop::pointerEvent(const Point& pos, uint8_t buttonMask) { vncPointerMove(pos.x + vncGetScreenX(screenIndex), pos.y + vncGetScreenY(screenIndex)); diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index 3b0f869f..d287b72f 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -95,7 +95,7 @@ public: void terminate() override; void queryConnection(network::Socket* sock, const char* userName) override; - void pointerEvent(const rfb::Point& pos, int buttonMask) override; + void pointerEvent(const rfb::Point& pos, uint8_t buttonMask) override; void keyEvent(uint32_t keysym, uint32_t keycode, bool down) override; unsigned int setScreenLayout(int fb_width, int fb_height, const rfb::ScreenSet& layout) override; diff --git a/vncviewer/EmulateMB.cxx b/vncviewer/EmulateMB.cxx index cc680df4..fef8b3d9 100644 --- a/vncviewer/EmulateMB.cxx +++ b/vncviewer/EmulateMB.cxx @@ -199,7 +199,7 @@ EmulateMB::EmulateMB() { } -void EmulateMB::filterPointerEvent(const rfb::Point& pos, int buttonMask) +void EmulateMB::filterPointerEvent(const rfb::Point& pos, uint8_t buttonMask) { int btstate; int action1, action2; @@ -280,7 +280,7 @@ void EmulateMB::filterPointerEvent(const rfb::Point& pos, int buttonMask) void EmulateMB::handleTimeout(rfb::Timer *t) { int action1, action2; - int buttonMask; + uint8_t buttonMask; if (&timer != t) return; @@ -312,7 +312,7 @@ void EmulateMB::handleTimeout(rfb::Timer *t) state = stateTab[state][4][2]; } -void EmulateMB::sendAction(const rfb::Point& pos, int buttonMask, int action) +void EmulateMB::sendAction(const rfb::Point& pos, uint8_t buttonMask, int action) { assert(action != 0); @@ -325,7 +325,7 @@ void EmulateMB::sendAction(const rfb::Point& pos, int buttonMask, int action) sendPointerEvent(pos, buttonMask); } -int EmulateMB::createButtonMask(int buttonMask) +int EmulateMB::createButtonMask(uint8_t buttonMask) { // Unset left and right buttons in the mask buttonMask &= ~0x5; diff --git a/vncviewer/EmulateMB.h b/vncviewer/EmulateMB.h index caf3c32a..1afa4881 100644 --- a/vncviewer/EmulateMB.h +++ b/vncviewer/EmulateMB.h @@ -26,22 +26,22 @@ class EmulateMB : public rfb::Timer::Callback { public: EmulateMB(); - void filterPointerEvent(const rfb::Point& pos, int buttonMask); + void filterPointerEvent(const rfb::Point& pos, uint8_t buttonMask); protected: - virtual void sendPointerEvent(const rfb::Point& pos, int buttonMask)=0; + virtual void sendPointerEvent(const rfb::Point& pos, uint8_t buttonMask)=0; void handleTimeout(rfb::Timer *t) override; private: - void sendAction(const rfb::Point& pos, int buttonMask, int action); + void sendAction(const rfb::Point& pos, uint8_t buttonMask, int action); - int createButtonMask(int buttonMask); + int createButtonMask(uint8_t buttonMask); private: int state; - int emulatedButtonMask; - int lastButtonMask; + uint8_t emulatedButtonMask; + uint8_t lastButtonMask; rfb::Point lastPos, origPos; rfb::Timer timer; }; diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 032fd322..b0778505 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -660,7 +660,7 @@ int Viewport::handle(int event) return Fl_Widget::handle(event); } -void Viewport::sendPointerEvent(const rfb::Point& pos, int buttonMask) +void Viewport::sendPointerEvent(const rfb::Point& pos, uint8_t buttonMask) { if (viewOnly) return; @@ -790,7 +790,7 @@ void Viewport::flushPendingClipboard() } -void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask) +void Viewport::handlePointerEvent(const rfb::Point& pos, uint8_t buttonMask) { filterPointerEvent(pos, buttonMask); } diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index d936c708..5f4c1ca7 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -70,7 +70,7 @@ public: int handle(int event) override; protected: - void sendPointerEvent(const rfb::Point& pos, int buttonMask) override; + void sendPointerEvent(const rfb::Point& pos, uint8_t buttonMask) override; private: bool hasFocus(); @@ -81,7 +81,7 @@ private: void flushPendingClipboard(); - void handlePointerEvent(const rfb::Point& pos, int buttonMask); + void handlePointerEvent(const rfb::Point& pos, uint8_t buttonMask); static void handlePointerTimeout(void *data); void resetKeyboard(); @@ -111,7 +111,7 @@ private: PlatformPixelBuffer* frameBuffer; rfb::Point lastPointerPos; - int lastButtonMask; + uint8_t lastButtonMask; typedef std::map DownMap; DownMap downKeySym; diff --git a/win/rfb_win32/SDisplay.cxx b/win/rfb_win32/SDisplay.cxx index b1abf849..0ec5e231 100644 --- a/win/rfb_win32/SDisplay.cxx +++ b/win/rfb_win32/SDisplay.cxx @@ -312,7 +312,7 @@ void SDisplay::handleClipboardData(const char* data) { } -void SDisplay::pointerEvent(const Point& pos, int buttonmask) { +void SDisplay::pointerEvent(const Point& pos, uint8_t buttonmask) { if (pb->getRect().contains(pos)) { Point screenPos = pos.translate(screenRect.tl); // - Check that the SDesktop doesn't need restarting diff --git a/win/rfb_win32/SDisplay.h b/win/rfb_win32/SDisplay.h index 76780d9e..d4cf23e4 100644 --- a/win/rfb_win32/SDisplay.h +++ b/win/rfb_win32/SDisplay.h @@ -80,7 +80,7 @@ namespace rfb { void handleClipboardRequest() override; void handleClipboardAnnounce(bool available) override; void handleClipboardData(const char* data) override; - void pointerEvent(const Point& pos, int buttonmask) override; + void pointerEvent(const Point& pos, uint8_t buttonmask) override; void keyEvent(uint32_t keysym, uint32_t keycode, bool down) override; // -=- Clipboard events diff --git a/win/rfb_win32/SInput.cxx b/win/rfb_win32/SInput.cxx index 94df6e98..65d4a703 100644 --- a/win/rfb_win32/SInput.cxx +++ b/win/rfb_win32/SInput.cxx @@ -65,7 +65,7 @@ win32::SPointer::SPointer() } void -win32::SPointer::pointerEvent(const Point& pos, int buttonmask) +win32::SPointer::pointerEvent(const Point& pos, uint8_t buttonmask) { // - We are specifying absolute coordinates DWORD flags = MOUSEEVENTF_ABSOLUTE; diff --git a/win/rfb_win32/SInput.h b/win/rfb_win32/SInput.h index 9013a37e..29e1df41 100644 --- a/win/rfb_win32/SInput.h +++ b/win/rfb_win32/SInput.h @@ -44,7 +44,7 @@ namespace rfb { // - Create a pointer event at a the given coordinates, with the // specified button state. The event must be specified using // Screen coordinates. - void pointerEvent(const Point& pos, int buttonmask); + void pointerEvent(const Point& pos, uint8_t buttonmask); protected: Point last_position; uint8_t last_buttonmask; -- 2.39.5