Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed X11 clipboard issues, added size limit, added webp/tiff/png/jpg #1904

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/newsfragments/adds-clipboard-memory-limit.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Adds clipboard memory limit for transfers between server/clients, the feature was documented
in wiki but missing in code. The feature can be set by using the spin box under the clipboard
checkbox in advanced settings.

The value used to limit clipboard size to transfer between client and sever is set in bytes
and can be set in the UI or throough the config file by setting the value in bytes with the
'clipboardSharingSize' tag.
19 changes: 19 additions & 0 deletions src/gui/src/ServerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ServerConfig::ServerConfig(QSettings* settings, int numColumns, int numRows ,
m_IgnoreAutoConfigClient(false),
m_EnableDragAndDrop(false),
m_ClipboardSharing(true),
m_ClipboardSharingSize(defaultClipboardSharingSize()),
m_pMainWindow(mainWindow)
{
Q_ASSERT(m_pSettings);
Expand Down Expand Up @@ -119,6 +120,7 @@ void ServerConfig::saveSettings()
settings().setValue("ignoreAutoConfigClient", ignoreAutoConfigClient());
settings().setValue("enableDragAndDrop", enableDragAndDrop());
settings().setValue("clipboardSharing", clipboardSharing());
settings().setValue("clipboardSharingSize", (int)clipboardSharingSize());

writeSettings<bool>(settings(), switchCorners(), "switchCorner");

Expand Down Expand Up @@ -164,6 +166,8 @@ void ServerConfig::loadSettings()
setIgnoreAutoConfigClient(settings().value("ignoreAutoConfigClient").toBool());
setEnableDragAndDrop(settings().value("enableDragAndDrop", true).toBool());
setClipboardSharing(settings().value("clipboardSharing", true).toBool());
setClipboardSharingSize(settings().value("clipboardSharingSize",
(int) ServerConfig::defaultClipboardSharingSize()).toULongLong());

readSettings<bool>(settings(), switchCorners(), "switchCorner", false,
static_cast<int>(SwitchCorner::Count));
Expand Down Expand Up @@ -412,3 +416,18 @@ void::ServerConfig::addToFirstEmptyGrid(const QString &clientName)
}
}
}

size_t ServerConfig::defaultClipboardSharingSize() {
return 100 * 1000 * 1000; // 100 MB
}

size_t ServerConfig::setClipboardSharingSize(size_t size) {
if (size) {
setClipboardSharing(true);
} else {
setClipboardSharing(false);
}
using std::swap;
swap (size, m_ClipboardSharingSize);
return size;
}
6 changes: 5 additions & 1 deletion src/gui/src/ServerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class ServerConfig : public BaseConfig
bool ignoreAutoConfigClient() const { return m_IgnoreAutoConfigClient; }
bool enableDragAndDrop() const { return m_EnableDragAndDrop; }
bool clipboardSharing() const { return m_ClipboardSharing; }

size_t clipboardSharingSize() const { return m_ClipboardSharingSize; }
static size_t defaultClipboardSharingSize();

void saveSettings();
void loadSettings();
bool save(const QString& fileName) const;
Expand Down Expand Up @@ -92,6 +94,7 @@ class ServerConfig : public BaseConfig
void setIgnoreAutoConfigClient(bool on) { m_IgnoreAutoConfigClient = on; }
void setEnableDragAndDrop(bool on) { m_EnableDragAndDrop = on; }
void setClipboardSharing(bool on) { m_ClipboardSharing = on; }
size_t setClipboardSharingSize(size_t size);
QList<bool>& switchCorners() { return m_SwitchCorners; }
std::vector<Hotkey>& hotkeys() { return m_Hotkeys; }

Expand Down Expand Up @@ -125,6 +128,7 @@ class ServerConfig : public BaseConfig
bool m_IgnoreAutoConfigClient;
bool m_EnableDragAndDrop;
bool m_ClipboardSharing;
size_t m_ClipboardSharingSize;
MainWindow* m_pMainWindow;
};

Expand Down
3 changes: 3 additions & 0 deletions src/gui/src/ServerConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ ServerConfigDialog::ServerConfigDialog(QWidget* parent, ServerConfig& config, co
m_pCheckBoxEnableDragAndDrop->setChecked(serverConfig().enableDragAndDrop());

m_pCheckBoxEnableClipboard->setChecked(serverConfig().clipboardSharing());
m_pSpinBoxClipboardSizeLimit->setValue(serverConfig().clipboardSharingSize());
m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing());

for (const Hotkey& hotkey : serverConfig().hotkeys()) {
m_pListHotkeys->addItem(hotkey.text());
Expand Down Expand Up @@ -108,6 +110,7 @@ void ServerConfigDialog::accept()
serverConfig().setIgnoreAutoConfigClient(m_pCheckBoxIgnoreAutoConfigClient->isChecked());
serverConfig().setEnableDragAndDrop(m_pCheckBoxEnableDragAndDrop->isChecked());
serverConfig().setClipboardSharing(m_pCheckBoxEnableClipboard->isChecked());
serverConfig().setClipboardSharingSize(m_pSpinBoxClipboardSizeLimit->value());

// now that the dialog has been accepted, copy the new server config to the original one,
// which is a reference to the one in MainWindow.
Expand Down
105 changes: 62 additions & 43 deletions src/gui/src/ServerConfigDialogBase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>795</width>
<height>534</height>
<width>816</width>
<height>580</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="m_pTabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="m_pTabScreens">
<attribute name="title">
Expand All @@ -44,7 +44,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap resource="Barrier.qrc">:/res/icons/64x64/user-trash.png</pixmap>
<pixmap>:/res/icons/64x64/user-trash.png</pixmap>
</property>
</widget>
</item>
Expand Down Expand Up @@ -82,7 +82,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap resource="Barrier.qrc">:/res/icons/64x64/video-display.png</pixmap>
<pixmap>:/res/icons/64x64/video-display.png</pixmap>
</property>
</widget>
</item>
Expand Down Expand Up @@ -422,13 +422,27 @@ Double click on a screen to edit its settings.</string>
<string>&amp;Options</string>
</property>
<layout class="QGridLayout">
<item row="3" column="0">
<widget class="QCheckBox" name="m_pCheckBoxWin32KeepForeground">
<item row="5" column="0">
<widget class="QCheckBox" name="m_pCheckBoxEnableDragAndDrop">
<property name="text">
<string>Enable drag and drop file transfers</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="m_pCheckBoxIgnoreAutoConfigClient">
<property name="text">
<string>Ignore auto config clients</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="m_pCheckBoxScreenSaverSync">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Don't take &amp;foreground window on Windows servers</string>
<string>S&amp;ynchronize screen savers</string>
</property>
</widget>
</item>
Expand All @@ -442,13 +456,36 @@ Double click on a screen to edit its settings.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="m_pCheckBoxScreenSaverSync">
<item row="3" column="0">
<widget class="QCheckBox" name="m_pCheckBoxWin32KeepForeground">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>S&amp;ynchronize screen savers</string>
<string>Don't take &amp;foreground window on Windows servers</string>
</property>
</widget>
</item>
<item row="7" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="m_pCheckBoxEnableClipboard">
<property name="text">
<string>Enable clipboard sharing</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
Expand Down Expand Up @@ -505,40 +542,22 @@ Double click on a screen to edit its settings.</string>
</item>
</layout>
</item>
<item row="7" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="m_pCheckBoxEnableDragAndDrop">
<property name="text">
<string>Enable drag and drop file transfers</string>
<item row="8" column="0">
<widget class="QSpinBox" name="m_pSpinBoxClipboardSizeLimit">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="m_pCheckBoxIgnoreAutoConfigClient">
<property name="text">
<string>Ignore auto config clients</string>
<property name="minimum">
<number>1000000</number>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="m_pCheckBoxEnableClipboard">
<property name="text">
<string>Enable clipboard sharing</string>
</property>
<property name="checked">
<bool>true</bool>
<property name="singleStep">
<number>1000</number>
</property>
<property name="value">
<number>100000000</number>
</property>
</widget>
</item>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/barrier/IClipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ class IClipboard : public IInterface {
enum EFormat {
kText, //!< Text format, UTF-8, newline is LF
kHTML, //!< HTML format, HTML fragment, UTF-8, newline is LF
kBitmap, //!< Bitmap format, BMP 24/32bpp, BI_RGB
kNumFormats //!< The number of clipboard formats
kBitmap, //!< Bitmap format, BMP 24/32bpp, BI_RGB
kPNG, //!< PNG format
kJpeg, //!< JPEG format
kTiff, //!< TIFF format
kWebp, //!< WEBP format
kNumFormats //!< The number of clipboard formats
};

//! @name manipulators
Expand Down
1 change: 1 addition & 0 deletions src/lib/barrier/option_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static const OptionID kOptionScreenPreserveFocus = OPTION_CODE("SFOC")
static const OptionID kOptionRelativeMouseMoves = OPTION_CODE("MDLT");
static const OptionID kOptionWin32KeepForeground = OPTION_CODE("_KFW");
static const OptionID kOptionClipboardSharing = OPTION_CODE("CLPS");
static const OptionID kOptionClipboardSharingSize = OPTION_CODE("CLSZ");
//@}

//! @name Screen switch corner enumeration
Expand Down
22 changes: 20 additions & 2 deletions src/lib/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Client::Client(IEventQueue* events, const std::string& name, const NetworkAddres
m_socket(NULL),
m_useSecureNetwork(args.m_enableCrypto),
m_args(args),
m_enableClipboard(true)
m_enableClipboard(true),
m_maximumClipboardSize(INT_MAX)
{
assert(m_socketFactory != NULL);
assert(m_screen != NULL);
Expand Down Expand Up @@ -369,9 +370,20 @@ Client::setOptions(const OptionsList& options)
m_enableClipboard = *index;

break;
} else if (id == kOptionClipboardSharingSize) {
index++;
if (index != options.end()) {
m_maximumClipboardSize = *index;
}
}
}

if (m_enableClipboard && !m_maximumClipboardSize) {
m_enableClipboard = false;
LOG((CLOG_NOTE "clipboard sharing is disabled because the server "
"set the maximum clipboard size to 0"));
}

m_screen->setOptions(options);
}

Expand Down Expand Up @@ -406,6 +418,12 @@ Client::sendClipboard(ClipboardID id)

// marshall the data
std::string data = clipboard.marshall();
if (data.size() >= m_maximumClipboardSize) {
LOG((CLOG_NOTE "Skipping clipboard transfer because the clipboard"
" contents exceeds the %i MB size limit set by the server",
m_maximumClipboardSize));
return;
}

// save and send data if different or not yet sent
if (!m_sentClipboard[id] || data != m_dataClipboard[id]) {
Expand Down Expand Up @@ -660,7 +678,7 @@ Client::handleShapeChanged(const Event&, void*)
void
Client::handleClipboardGrabbed(const Event& event, void*)
{
if (!m_enableClipboard) {
if (!m_enableClipboard || (m_maximumClipboardSize == 0)) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,5 @@ class Client : public IClient, public INode {
bool m_useSecureNetwork;
ClientArgs m_args;
bool m_enableClipboard;
size_t m_maximumClipboardSize;
};