#6518 Added server restart action and hotkey capability

This commit is contained in:
Jamie Newbon 2019-10-15 18:38:42 +01:00
parent 363355bca3
commit 29ab86b734
7 changed files with 150 additions and 5 deletions

View File

@ -24,7 +24,7 @@
const char* Action::m_ActionTypeNames[] = const char* Action::m_ActionTypeNames[] =
{ {
"keyDown", "keyUp", "keystroke", "keyDown", "keyUp", "keystroke",
"switchToScreen", "switchInDirection", "lockCursorToScreen", "switchToScreen", "switchInDirection", "lockCursorToScreen", "restartServer",
"mouseDown", "mouseUp", "mousebutton" "mouseDown", "mouseUp", "mousebutton"
}; };
@ -87,6 +87,9 @@ QString Action::text() const
text += m_LockCursorModeNames[m_LockCursorMode]; text += m_LockCursorModeNames[m_LockCursorMode];
break; break;
case restartAllConnections:
text += "restart";
break;
default: default:
Q_ASSERT(0); Q_ASSERT(0);
break; break;
@ -116,6 +119,7 @@ void Action::loadSettings(QSettings& settings)
setLockCursorMode(settings.value("lockCursorToScreen", lockCursorToggle).toInt()); setLockCursorMode(settings.value("lockCursorToScreen", lockCursorToggle).toInt());
setActiveOnRelease(settings.value("activeOnRelease", false).toBool()); setActiveOnRelease(settings.value("activeOnRelease", false).toBool());
setHaveScreens(settings.value("hasScreens", false).toBool()); setHaveScreens(settings.value("hasScreens", false).toBool());
setRestartServer(settings.value("restartServer", false).toBool());
} }
void Action::saveSettings(QSettings& settings) const void Action::saveSettings(QSettings& settings) const
@ -136,6 +140,7 @@ void Action::saveSettings(QSettings& settings) const
settings.setValue("lockCursorToScreen", lockCursorMode()); settings.setValue("lockCursorToScreen", lockCursorMode());
settings.setValue("activeOnRelease", activeOnRelease()); settings.setValue("activeOnRelease", activeOnRelease());
settings.setValue("hasScreens", haveScreens()); settings.setValue("hasScreens", haveScreens());
settings.setValue("restartServer", restartServer());
} }
QTextStream& operator<<(QTextStream& outStream, const Action& action) QTextStream& operator<<(QTextStream& outStream, const Action& action)

View File

@ -36,9 +36,29 @@ class Action
friend QTextStream& operator<<(QTextStream& outStream, const Action& action); friend QTextStream& operator<<(QTextStream& outStream, const Action& action);
public: public:
enum ActionType { keyDown, keyUp, keystroke, switchToScreen, switchInDirection, lockCursorToScreen, mouseDown, mouseUp, mousebutton }; enum ActionType {
enum SwitchDirection { switchLeft, switchRight, switchUp, switchDown }; keyDown,
enum LockCursorMode { lockCursorToggle, lockCursonOn, lockCursorOff }; keyUp,
keystroke,
switchToScreen,
switchInDirection,
lockCursorToScreen,
restartAllConnections,
mouseDown,
mouseUp,
mousebutton,
};
enum SwitchDirection {
switchLeft,
switchRight,
switchUp,
switchDown
};
enum LockCursorMode {
lockCursorToggle,
lockCursonOn,
lockCursorOff
};
public: public:
Action(); Action();
@ -55,6 +75,7 @@ class Action
int lockCursorMode() const { return m_LockCursorMode; } int lockCursorMode() const { return m_LockCursorMode; }
bool activeOnRelease() const { return m_ActiveOnRelease; } bool activeOnRelease() const { return m_ActiveOnRelease; }
bool haveScreens() const { return m_HasScreens; } bool haveScreens() const { return m_HasScreens; }
bool restartServer() const { return m_restartServer; }
protected: protected:
KeySequence& keySequence() { return m_KeySequence; } KeySequence& keySequence() { return m_KeySequence; }
@ -66,6 +87,7 @@ class Action
void setLockCursorMode(int m) { m_LockCursorMode = m; } void setLockCursorMode(int m) { m_LockCursorMode = m; }
void setActiveOnRelease(bool b) { m_ActiveOnRelease = b; } void setActiveOnRelease(bool b) { m_ActiveOnRelease = b; }
void setHaveScreens(bool b) { m_HasScreens = b; } void setHaveScreens(bool b) { m_HasScreens = b; }
void setRestartServer( bool b) { m_restartServer = b; }
private: private:
KeySequence m_KeySequence; KeySequence m_KeySequence;
@ -76,6 +98,7 @@ class Action
int m_LockCursorMode; int m_LockCursorMode;
bool m_ActiveOnRelease; bool m_ActiveOnRelease;
bool m_HasScreens; bool m_HasScreens;
bool m_restartServer;
static const char* m_ActionTypeNames[]; static const char* m_ActionTypeNames[];
static const char* m_SwitchDirectionNames[]; static const char* m_SwitchDirectionNames[];

View File

@ -39,7 +39,7 @@ ActionDialog::ActionDialog(QWidget* parent, ServerConfig& config, Hotkey& hotkey
// work around Qt Designer's lack of a QButtonGroup; we need it to get // work around Qt Designer's lack of a QButtonGroup; we need it to get
// at the button id of the checked radio button // at the button id of the checked radio button
QRadioButton* const typeButtons[] = { m_pRadioPress, m_pRadioRelease, m_pRadioPressAndRelease, m_pRadioSwitchToScreen, m_pRadioSwitchInDirection, m_pRadioLockCursorToScreen }; QRadioButton* const typeButtons[] = { m_pRadioPress, m_pRadioRelease, m_pRadioPressAndRelease, m_pRadioSwitchToScreen, m_pRadioSwitchInDirection, m_pRadioLockCursorToScreen , m_pRadioRestartAllConnections};
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++) for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++)
m_pButtonGroupType->addButton(typeButtons[i], i); m_pButtonGroupType->addButton(typeButtons[i], i);
@ -91,6 +91,7 @@ void ActionDialog::accept()
m_Action.setSwitchDirection(m_pComboSwitchInDirection->currentIndex()); m_Action.setSwitchDirection(m_pComboSwitchInDirection->currentIndex());
m_Action.setLockCursorMode(m_pComboLockCursorToScreen->currentIndex()); m_Action.setLockCursorMode(m_pComboLockCursorToScreen->currentIndex());
m_Action.setActiveOnRelease(m_pRadioHotkeyReleased->isChecked()); m_Action.setActiveOnRelease(m_pRadioHotkeyReleased->isChecked());
m_Action.setRestartServer(m_pRadioRestartAllConnections->isChecked());
QDialog::accept(); QDialog::accept();
} }

View File

@ -239,6 +239,17 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QRadioButton" name="m_pRadioRestartAllConnections">
<property name="text">
<string>Restart server</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -369,6 +380,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>m_pRadioRestartAllConnections</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>101</x>
<y>353</y>
</hint>
<hint type="destinationlabel">
<x>68</x>
<y>126</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>m_pRadioPress</sender> <sender>m_pRadioPress</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
@ -561,6 +588,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>m_pRadioRestartAllConnections</sender>
<signal>toggled(bool)</signal>
<receiver>m_pGroupBoxScreens</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>48</x>
<y>339</y>
</hint>
<hint type="destinationlabel">
<x>79</x>
<y>234</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>m_pRadioSwitchToScreen</sender> <sender>m_pRadioSwitchToScreen</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>

View File

@ -1241,6 +1241,26 @@ Config::parseAction(ConfigReadContext& s,
action = new InputFilter::LockCursorToScreenAction(m_events, mode); action = new InputFilter::LockCursorToScreenAction(m_events, mode);
} }
else if (name == "restartServer") {
if (args.size() > 1) {
throw XConfigRead(s, "syntax for action: restartServer([{{restart}}])");
}
InputFilter::RestartServer::Mode mode =
InputFilter::RestartServer::restart;
if (args.size() == 1) {
if (args[0] == "restart") {
mode = InputFilter::RestartServer::restart;
}
else {
throw XConfigRead(s, "syntax for action: restartServer([{restart}])");
}
}
action = new InputFilter::RestartServer(m_events, mode);
}
else if (name == "keyboardBroadcast") { else if (name == "keyboardBroadcast") {
if (args.size() > 2) { if (args.size() > 2) {
throw XConfigRead(s, "syntax for action: keyboardBroadcast([{off|on|toggle}[,screens]])"); throw XConfigRead(s, "syntax for action: keyboardBroadcast([{off|on|toggle}[,screens]])");

View File

@ -323,6 +323,40 @@ InputFilter::LockCursorToScreenAction::perform(const Event& event)
Event::kDeliverImmediately)); Event::kDeliverImmediately));
} }
InputFilter::RestartServer::RestartServer(
IEventQueue* events, Mode mode) :
m_mode(mode),
m_events(events)
{
// do nothing
}
InputFilter::RestartServer::Mode
InputFilter::RestartServer::getMode() const
{
return m_mode;
}
InputFilter::Action *InputFilter::RestartServer::clone() const {
return new RestartServer(*this);
}
String
InputFilter::RestartServer::format() const
{
static const char* s_mode[] = { "restart" };
return synergy::string::sprintf("restartServer(%s)", s_mode[m_mode]);
}
void
InputFilter::RestartServer::perform(const Event& event)
{
//HACK Super hack we should gracefully exit
exit(0);
}
InputFilter::SwitchToScreenAction::SwitchToScreenAction( InputFilter::SwitchToScreenAction::SwitchToScreenAction(
IEventQueue* events, const String& screen) : IEventQueue* events, const String& screen) :
m_screen(screen), m_screen(screen),
@ -1088,3 +1122,4 @@ InputFilter::handleEvent(const Event& event, void*)
// not handled so pass through // not handled so pass through
m_events->addEvent(myEvent); m_events->addEvent(myEvent);
} }

View File

@ -150,6 +150,24 @@ public:
IEventQueue* m_events; IEventQueue* m_events;
}; };
class RestartServer : public Action {
public:
enum Mode { restart };
RestartServer(IEventQueue* events, Mode = restart);
Mode getMode() const;
// Action overrides
virtual Action* clone() const;
virtual String format() const;
virtual void perform(const Event&);
private:
Mode m_mode;
IEventQueue* m_events;
};
// SwitchToScreenAction // SwitchToScreenAction
class SwitchToScreenAction : public Action { class SwitchToScreenAction : public Action {
public: public: