Skip to content

Commit

Permalink
Completely ignore server clipboard when unfocused
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CendioOssman committed Sep 11, 2023
1 parent 963f11e commit 8d2739f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
23 changes: 4 additions & 19 deletions vncviewer/Viewport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -799,7 +785,6 @@ void Viewport::flushPendingClipboard()
}
}

pendingServerClipboard = false;
pendingClientClipboard = false;
}

Expand Down
1 change: 0 additions & 1 deletion vncviewer/Viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class Viewport : public Fl_Widget, public EmulateMB {

bool firstLEDState;

bool pendingServerClipboard;
bool pendingClientClipboard;

int clipboardSource;
Expand Down

0 comments on commit 8d2739f

Please sign in to comment.