Browse Source

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.
pull/1671/head
Pierre Ossman 7 months ago
parent
commit
8d2739fa71
2 changed files with 4 additions and 20 deletions
  1. 4
    19
      vncviewer/Viewport.cxx
  2. 0
    1
      vncviewer/Viewport.h

+ 4
- 19
vncviewer/Viewport.cxx View File

@@ -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;
}


+ 0
- 1
vncviewer/Viewport.h View File

@@ -123,7 +123,6 @@ private:

bool firstLEDState;

bool pendingServerClipboard;
bool pendingClientClipboard;

int clipboardSource;

Loading…
Cancel
Save