SYNERGY-979 Add clients by priority
This commit is contained in:
parent
86bac9745f
commit
025c2c1629
12 changed files with 186 additions and 16 deletions
|
|
@ -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
|
||||
;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
118
src/gui/src/ScreenList.cpp
Normal file
118
src/gui/src/ScreenList.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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)
|
||||
{
|
||||
enum{kLEFT, kRIGHT, kTOP, kBOTTOM, kTOP_LEFT, kTOP_RIGHT, kBOTTOM_RIGHT, kBOTTOM_LEFT};
|
||||
std::array<int, 8> indexes = { -1 };
|
||||
|
||||
if (serverIndex >= 0 && serverIndex < size)
|
||||
{
|
||||
indexes[kLEFT] = (serverIndex - 1) % width != width - 1 ? (serverIndex - 1) : -1;;
|
||||
indexes[kRIGHT] = (serverIndex + 1) % width != 0 ? (serverIndex + 1) : -1;
|
||||
indexes[kTOP] = (serverIndex - width) >= 0 ? (serverIndex - width) : -1;
|
||||
indexes[kBOTTOM] = (serverIndex + width) < size ? (serverIndex + width) : -1;
|
||||
indexes[kTOP_LEFT] = (indexes[kTOP] != - 1 && indexes[kLEFT] != -1) ? indexes[kTOP] - 1 : -1;
|
||||
indexes[kTOP_RIGHT] = (indexes[kTOP] != -1 && indexes[kRIGHT] != -1) ? indexes[kTOP] + 1 : -1;;
|
||||
indexes[kBOTTOM_RIGHT] = (indexes[kBOTTOM] != -1 && indexes[kRIGHT] != -1) ? indexes[kBOTTOM] + 1 : -1;;
|
||||
indexes[kBOTTOM_LEFT] = (indexes[kBOTTOM] != -1 && indexes[kLEFT] != -1) ? indexes[kBOTTOM] - 1 : -1;;
|
||||
}
|
||||
|
||||
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
52
src/gui/src/ScreenList.h
Normal 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
|
||||
|
|
@ -29,7 +29,7 @@ class QWidget;
|
|||
class QString;
|
||||
|
||||
class Screen;
|
||||
using ScreenList = QList<Screen>;
|
||||
class ScreenList;
|
||||
|
||||
class ScreenSettingsDialog : public QDialog, public Ui::ScreenSettingsDialogBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "Screen.h"
|
||||
#include "ScreenList.h"
|
||||
|
||||
class ScreenSetupView;
|
||||
class ServerConfigDialog;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#ifndef SCREENDUPLICATIONSVALIDATOR_H
|
||||
#define SCREENDUPLICATIONSVALIDATOR_H
|
||||
|
||||
#include "Screen.h"
|
||||
#include "ScreenList.h"
|
||||
#include "IStringValidator.h"
|
||||
|
||||
namespace validators
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#ifndef SCREENNAMEVALIDATOR_H
|
||||
#define SCREENNAMEVALIDATOR_H
|
||||
|
||||
#include "Screen.h"
|
||||
#include "ScreenList.h"
|
||||
#include "LineEditValidator.h"
|
||||
|
||||
namespace validators
|
||||
|
|
|
|||
Loading…
Reference in a new issue