From 8d2739fa71eaf7a28d63ac62583e8087c66a5247 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 11 Sep 2023 13:05:25 +0200 Subject: [PATCH] Completely ignore server clipboard when unfocused We can get races with clipboard managers in the server that is very confusing to the user. When the clipboard changes locally, we tell the server to drop the old clipboard (as it is now lost). But we don't send over the new clipboard until we get focus again, in order to not leak more data than necessary. This causes some clibpoard managers to take over ownership in order to avoid an empty clipboard. And this takes precedence over the new client clipboard as it happened later. Effectively reverting the clipboard the user sees. Avoid all of this by simply ignoring the server when we don't have focus. This is likely what users expect anyway as they expect their currently focused application to control the clipboard, not vncviewer in the background. --- vncviewer/Viewport.cxx | 23 ++++------------------- vncviewer/Viewport.h | 1 - 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index d46c0021..9753184c 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -120,8 +120,7 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& /*serverPF*/, CConn* cc #ifdef WIN32 altGrArmed(false), #endif - firstLEDState(true), - pendingServerClipboard(false), pendingClientClipboard(false), + firstLEDState(true), pendingClientClipboard(false), menuCtrlKey(false), menuAltKey(false), cursor(NULL) { #if !defined(WIN32) && !defined(__APPLE__) @@ -295,18 +294,16 @@ void Viewport::handleClipboardAnnounce(bool available) if (!available) { vlog.debug("Clipboard is no longer available on server"); - pendingServerClipboard = false; return; } - pendingClientClipboard = false; - if (!hasFocus()) { - vlog.debug("Got notification of new clipboard on server whilst not focused, will request data later"); - pendingServerClipboard = true; + vlog.debug("Got notification of new clipboard on server whilst not focused, ignoring"); return; } + pendingClientClipboard = false; + vlog.debug("Got notification of new clipboard on server, requesting data"); cc->requestClipboard(); } @@ -758,8 +755,6 @@ void Viewport::handleClipboardChange(int source, void *data) self->clipboardSource = source; - self->pendingServerClipboard = false; - if (!self->hasFocus()) { vlog.debug("Local clipboard changed whilst not focused, will notify server later"); self->pendingClientClipboard = true; @@ -780,15 +775,6 @@ void Viewport::handleClipboardChange(int source, void *data) void Viewport::flushPendingClipboard() { - if (pendingServerClipboard) { - vlog.debug("Focus regained after remote clipboard change, requesting data"); - try { - cc->requestClipboard(); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); - abort_connection_with_unexpected_error(e); - } - } if (pendingClientClipboard) { vlog.debug("Focus regained after local clipboard change, notifying server"); try { @@ -799,7 +785,6 @@ void Viewport::flushPendingClipboard() } } - pendingServerClipboard = false; pendingClientClipboard = false; } diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index c70cca6e..4b674aa1 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -123,7 +123,6 @@ private: bool firstLEDState; - bool pendingServerClipboard; bool pendingClientClipboard; int clipboardSource; -- 2.39.5