diff options
author | Pierre Ossman <ossman@cendio.se> | 2025-02-05 13:48:08 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2025-02-05 14:07:13 +0100 |
commit | e0820acd3e87dd83a4b8c8875599618a8609fbbb (patch) | |
tree | eebfa669922403fb1d6c536fcbe6b470552f89bd /vncviewer | |
parent | f3749354c9834a9bb67e300b1c6fec3f35dad8bf (diff) | |
download | tigervnc-e0820acd3e87dd83a4b8c8875599618a8609fbbb.tar.gz tigervnc-e0820acd3e87dd83a4b8c8875599618a8609fbbb.zip |
Better resize rate limiting
Be more aggressive with resizing, limiting it to once ever 100 ms
instead of after a 500 ms idle period. This avoids unnecessary delays
when entering or leaving full screen, or when maximizing.
Diffstat (limited to 'vncviewer')
-rw-r--r-- | vncviewer/CConn.cxx | 11 | ||||
-rw-r--r-- | vncviewer/CConn.h | 4 | ||||
-rw-r--r-- | vncviewer/DesktopWindow.cxx | 33 | ||||
-rw-r--r-- | vncviewer/DesktopWindow.h | 6 |
4 files changed, 50 insertions, 4 deletions
diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 3a5c161f..5f943640 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -37,6 +37,7 @@ #include <rfb/Security.h> #include <rfb/fenceTypes.h> #include <rfb/Timer.h> +#include <rfb/screenTypes.h> #include <network/TcpSocket.h> #ifndef WIN32 #include <network/UnixSocket.h> @@ -316,6 +317,16 @@ void CConn::initDone() setPreferredEncoding(encNum); } +void CConn::setExtendedDesktopSize(unsigned reason, unsigned result, + int w, int h, + const rfb::ScreenSet& layout) +{ + CConnection::setExtendedDesktopSize(reason, result, w, h, layout); + + if (reason == reasonClient) + desktop->setDesktopSizeDone(result); +} + // setName() is called when the desktop name changes void CConn::setName(const char* name) { diff --git a/vncviewer/CConn.h b/vncviewer/CConn.h index 5c470508..e830ecaa 100644 --- a/vncviewer/CConn.h +++ b/vncviewer/CConn.h @@ -57,6 +57,10 @@ public: void initDone() override; + void setExtendedDesktopSize(unsigned reason, unsigned result, + int w, int h, + const rfb::ScreenSet& layout) override; + void setName(const char* name) override; void setColourMapEntries(int firstColour, int nColours, diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index 48b975b2..8e9bc814 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -84,6 +84,7 @@ DesktopWindow::DesktopWindow(int w, int h, const char *name, : Fl_Window(w, h), cc(cc_), offscreen(nullptr), overlay(nullptr), firstUpdate(true), delayedFullscreen(false), sentDesktopSize(false), + pendingRemoteResize(false), lastResize({0, 0}), keyboardGrabbed(false), mouseGrabbed(false), statsLastUpdates(0), statsLastPixels(0), statsLastPosition(0), statsGraph(nullptr) @@ -403,6 +404,19 @@ void DesktopWindow::resizeFramebuffer(int new_w, int new_h) } +void DesktopWindow::setDesktopSizeDone(unsigned result) +{ + pendingRemoteResize = false; + + if (result != 0) + return; + + // We might have resized again whilst waiting for the previous + // request, so check if we are in sync + remoteResize(); +} + + void DesktopWindow::setCursor(int width, int height, const rfb::Point& hotspot, const uint8_t* data) @@ -690,10 +704,7 @@ void DesktopWindow::resize(int x, int y, int w, int h) Fl_Window::resize(x, y, w, h); if (resizing) { - // We delay updating the remote desktop as we tend to get a flood - // of resize events as the user is dragging the window. - Fl::remove_timeout(handleResizeTimeout, this); - Fl::add_timeout(0.5, handleResizeTimeout, this); + remoteResize(); repositionWidgets(); } @@ -1308,6 +1319,18 @@ void DesktopWindow::remoteResize() if (delayedFullscreen) return; + // Rate limit to one pending resize at a time + if (pendingRemoteResize) + return; + + // And no more than once every 100ms + if (msSince(&lastResize) < 100) { + Fl::remove_timeout(handleResizeTimeout, this); + Fl::add_timeout((100.0 - msSince(&lastResize)) / 1000.0, + handleResizeTimeout, this); + return; + } + width = w(); height = h(); @@ -1438,6 +1461,8 @@ void DesktopWindow::remoteResize() vlog.debug("%s", buffer); } + pendingRemoteResize = true; + gettimeofday(&lastResize, nullptr); cc->writer()->writeSetDesktopSize(width, height, layout); } diff --git a/vncviewer/DesktopWindow.h b/vncviewer/DesktopWindow.h index 8ac19c45..97c3c00d 100644 --- a/vncviewer/DesktopWindow.h +++ b/vncviewer/DesktopWindow.h @@ -55,6 +55,9 @@ public: // Resize the current framebuffer, but retain the contents void resizeFramebuffer(int new_w, int new_h); + // A previous call to writeSetDesktopSize() has completed + void setDesktopSizeDone(unsigned result); + // New image for the locally rendered cursor void setCursor(int width, int height, const rfb::Point& hotspot, const uint8_t* data); @@ -132,6 +135,9 @@ private: bool delayedFullscreen; bool sentDesktopSize; + bool pendingRemoteResize; + struct timeval lastResize; + bool keyboardGrabbed; bool mouseGrabbed; |