Merge pull request #7003 from symless/SYNERGY-979-Server-config-prioritization-rules

SYNERGY-979 Prioritization rules server config
This commit is contained in:
Igor Sikachyna 2021-05-18 20:39:12 +03:00 committed by GitHub
commit 5b4481fb8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 196 additions and 17 deletions

View file

@ -15,7 +15,6 @@ Bug fixes:
- #6993 Fix issues with prefences UI
- #6992 UI issues and use cases
- #7000 Additional UI tweaks
===========
Enhancements:
- #6954 Move language selection to advanced section
@ -29,6 +28,7 @@ Enhancements:
- #6962 | #6965 Add macOS 10.13 builder
- #6990 Change VersionChecker URL and include system language in the header
- #6999 Detect if Linux is running with Wayland, and display a warning message
- #7003 Prioritization rules server config
===========
v1.13.1-stable

View file

@ -131,6 +131,7 @@ QDataStream& operator<<(QDataStream& outStream, const Screen& screen)
<< screen.modifiers()
<< screen.switchCorners()
<< screen.fixes()
<< screen.isServer()
;
}
@ -143,5 +144,6 @@ QDataStream& operator>>(QDataStream& inStream, Screen& screen)
>> screen.m_Modifiers
>> screen.m_SwitchCorners
>> screen.m_Fixes
>> screen.m_isServer
;
}

View file

@ -99,8 +99,6 @@ class Screen : public BaseConfig
bool m_isServer = false;
};
typedef QList<Screen> ScreenList;
QDataStream& operator<<(QDataStream& outStream, const Screen& screen);
QDataStream& operator>>(QDataStream& inStream, Screen& screen);

127
src/gui/src/ScreenList.cpp Normal file
View file

@ -0,0 +1,127 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScreenList.h"
#include <array>
namespace {
/**
* @brief getNeightborIndexes returns indexes for server neighbors
* @param serverIndex server index
* @param width of the grid
* @param size of the grid
* @return indexes for server neighbors
*/
std::array<int, 8> getNeighborsIndexes(int serverIndex, int width, int size)
{
const int UNSET = -1;
const int LEFT = 0;
const int RIGHT = 1;
const int TOP = 2;
const int BOTTOM = 3;
const int TOP_LEFT = 4;
const int TOP_RIGHT = 5;
const int BOTTOM_RIGHT = 6;
const int BOTTOM_LEFT = 7;
std::array<int, 8> indexes = { UNSET };
if (serverIndex >= 0 && serverIndex < size)
{
indexes[LEFT] = (serverIndex - 1) % width != width - 1 ? (serverIndex - 1) : UNSET;
indexes[RIGHT] = (serverIndex + 1) % width != 0 ? (serverIndex + 1) : UNSET;
indexes[TOP] = (serverIndex - width) >= 0 ? (serverIndex - width) : UNSET;
indexes[BOTTOM] = (serverIndex + width) < size ? (serverIndex + width) : UNSET;
indexes[TOP_LEFT] = (indexes[TOP] != UNSET && indexes[LEFT] != UNSET) ? indexes[TOP] - 1 : UNSET;
indexes[TOP_RIGHT] = (indexes[TOP] != UNSET && indexes[RIGHT] != UNSET) ? indexes[TOP] + 1 : UNSET;
indexes[BOTTOM_RIGHT] = (indexes[BOTTOM] != UNSET && indexes[RIGHT] != UNSET) ? indexes[BOTTOM] + 1 : UNSET;
indexes[BOTTOM_LEFT] = (indexes[BOTTOM] != UNSET && indexes[LEFT] != UNSET) ? indexes[BOTTOM] - 1 : UNSET;
}
return indexes;
}
/**
* @brief getServerIndex finds server and returns it's index
* @param screens list to find server
* @return server index
*/
int getServerIndex(const ScreenList& screens)
{
int serverIndex = -1;
for (int i = 0; i < screens.size(); ++i)
{
if (screens[i].isServer()){
serverIndex = i;
break;
}
}
return serverIndex;
}
} //namespace
ScreenList::ScreenList(int width) :
QList<Screen>(),
m_width(width)
{
}
void ScreenList::addScreenByPriority(const Screen& newScreen)
{
int serverIndex = getServerIndex(*this);
auto indexes = getNeighborsIndexes(serverIndex, m_width, size());
bool isAdded = false;
for (const auto& index : indexes)
{
if (index >= 0 && index < size())
{
auto& screen = operator[](index);
if (screen.isNull())
{
screen = newScreen;
isAdded = true;
break;
}
}
}
if (!isAdded)
{
addScreenToFirstEmpty(newScreen);
}
}
void ScreenList::addScreenToFirstEmpty(const Screen& newScreen)
{
for (int i = 0; i < size(); ++i)
{
auto& screen = operator[](i);
if (screen.isNull())
{
screen = newScreen;
break;
}
}
}

52
src/gui/src/ScreenList.h Normal file
View file

@ -0,0 +1,52 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCREENLIST_H
#define SCREENLIST_H
#include "Screen.h"
class ScreenList : public QList<Screen>
{
int m_width = 5;
public:
explicit ScreenList(int width = 5);
/**
* @brief addScreenByPriority adds a new screen according to the following priority:
* 1.left side of the server
* 2.right side of the server
* 3.top
* 4.down
* 5.top left-hand diagonally
* 6.top right-hand diagonally
* 7.bottom right-hand diagonally
* 8.bottom left-hand diagonally
* 9.In case all places from the list have already booked, place in any spare place
* @param newScreen
*/
void addScreenByPriority(const Screen& newScreen);
/**
* @brief addScreenToFirstEmpty adds screen into the first empty place
* @param newScreen
*/
void addScreenToFirstEmpty(const Screen& newScreen);
};
#endif // SCREENLIST_H

View file

@ -29,7 +29,7 @@ class QWidget;
class QString;
class Screen;
using ScreenList = QList<Screen>;
class ScreenList;
class ScreenSettingsDialog : public QDialog, public Ui::ScreenSettingsDialogBase
{

View file

@ -143,13 +143,7 @@ bool ScreenSetupModel::dropMimeData(const QMimeData* data, Qt::DropAction action
void ScreenSetupModel::addScreen(const Screen& newScreen)
{
auto screenTest = std::find_if(m_Screens.begin(), m_Screens.end(),
[](const Screen& item) { return item.isNull(); });
if (screenTest != m_Screens.end())
{
(*screenTest) = newScreen;
}
m_Screens.addScreenByPriority(newScreen);
}
bool ScreenSetupModel::isFull() const

View file

@ -25,7 +25,7 @@
#include <QString>
#include <QStringList>
#include "Screen.h"
#include "ScreenList.h"
class ScreenSetupView;
class ServerConfigDialog;

View file

@ -44,7 +44,7 @@ const int serverDefaultIndex = 7;
ServerConfig::ServerConfig(int numColumns, int numRows, AppConfig* appConfig, MainWindow* mainWindow) :
m_Screens(),
m_Screens(numColumns),
m_NumColumns(numColumns),
m_NumRows(numRows),
m_pAppConfig(appConfig),
@ -429,6 +429,11 @@ bool ServerConfig::isScreenExists(const QString& screenName) const
return isExists;
}
void ServerConfig::addClient(const QString& clientName)
{
m_Screens.addScreenByPriority(clientName);
}
void ServerConfig::setConfigFile(const QString& configFile)
{
m_pAppConfig->setConfigFile(configFile);

View file

@ -22,7 +22,7 @@
#include <QList>
#include "Screen.h"
#include "ScreenList.h"
#include "BaseConfig.h"
#include "Hotkey.h"
#include "ConfigBase.h"
@ -86,6 +86,7 @@ class ServerConfig : public BaseConfig, public GUI::Config::ConfigBase
bool getUseExternalConfig() const;
bool isFull() const;
bool isScreenExists(const QString& screenName) const;
void addClient(const QString& clientName);
protected:
QSettings& settings();

View file

@ -82,7 +82,7 @@ void ServerConnection::addClient(const QString& clientName)
void ServerConnection::configureClient(const QString& clientName)
{
auto& config = m_parent.serverConfig();
config.addToFirstEmptyGrid(clientName);
config.addClient(clientName);
ServerConfigDialog dlg(&m_parent, config);
dlg.exec();

View file

@ -18,7 +18,7 @@
#ifndef SCREENDUPLICATIONSVALIDATOR_H
#define SCREENDUPLICATIONSVALIDATOR_H
#include "Screen.h"
#include "ScreenList.h"
#include "IStringValidator.h"
namespace validators

View file

@ -18,7 +18,7 @@
#ifndef SCREENNAMEVALIDATOR_H
#define SCREENNAMEVALIDATOR_H
#include "Screen.h"
#include "ScreenList.h"
#include "LineEditValidator.h"
namespace validators