diff --git a/docs/user/configuration.md b/docs/user/configuration.md index 0cdb11154..8ac701328 100644 --- a/docs/user/configuration.md +++ b/docs/user/configuration.md @@ -77,6 +77,10 @@ This section contains general options it will begin with `[core]` | useHooks | `true` or `false` | If Windows uses hooks or not [default: true] | | language | 639 language | The language to display the GUI in [default: en] | | wlClipboard | `true` or `false` | When true the wl-clipboard backend will be enabled [default: false] | +| enableEnterCommand | `true` or `false` | Should the enter command be triggered when the screen is entered [defaut: false] | +| enterCommand | command | A command to run when the screen is entered. | +| enableExitCommand | `true` or `false` | Should the exit command be triggered when the screen is exited [defaut: false] | +| exitCommand | command | A command to run when the screen is exited. | ### Daemon diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index 08d27511b..d06f0d052 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -55,6 +55,10 @@ public: inline static const auto UseHooks = QStringLiteral("core/useHooks"); inline static const auto Language = QStringLiteral("core/language"); inline static const auto UseWlClipboard = QStringLiteral("core/wlClipboard"); + inline static const auto EnableEnterCommand = QStringLiteral("core/enableEnterCommand"); + inline static const auto ScreenEnterCommand = QStringLiteral("core/enterCommand"); + inline static const auto EnableExitCommand = QStringLiteral("core/enableExitCommand"); + inline static const auto ScreenExitCommand = QStringLiteral("core/exitCommand"); // TODO: REMOVE In 2.0 inline static const auto ScreenName = QStringLiteral("core/screenName"); // Replaced By ComputerName @@ -207,6 +211,10 @@ private: , Settings::Core::Port , Settings::Core::PreventSleep , Settings::Core::ProcessMode + , Settings::Core::EnableEnterCommand + , Settings::Core::EnableExitCommand + , Settings::Core::ScreenEnterCommand + , Settings::Core::ScreenExitCommand , Settings::Core::ScreenName , Settings::Core::ComputerName , Settings::Core::Display @@ -250,6 +258,8 @@ private: , Settings::Gui::ShowVersionInTitle , Settings::Core::PreventSleep , Settings::Core::UseWlClipboard + , Settings::Core::EnableEnterCommand + , Settings::Core::EnableExitCommand , Settings::Server::ExternalConfig , Settings::Client::InvertYScroll , Settings::Client::InvertXScroll diff --git a/src/lib/deskflow/Screen.cpp b/src/lib/deskflow/Screen.cpp index ad4a2ca3e..7524c6d6a 100644 --- a/src/lib/deskflow/Screen.cpp +++ b/src/lib/deskflow/Screen.cpp @@ -10,6 +10,8 @@ #include "base/Log.h" #include "deskflow/IPlatformScreen.h" +#include + namespace deskflow { // @@ -119,6 +121,14 @@ void Screen::enter(KeyModifierMask toggleMask) } else { enterSecondary(toggleMask); } + + if (Settings::value(Settings::Core::EnableEnterCommand).toBool()) { + auto args = QProcess::splitCommand(Settings::value(Settings::Core::ScreenEnterCommand).toString()); + const auto command = args.takeFirst(); + LOG_DEBUG("running screen enter command: %s %s", qPrintable(command), qPrintable(args.join(" "))); + if (!QProcess::startDetached(command, args)) + LOG_ERR("failed to run screen enter command"); + } } bool Screen::leave() @@ -140,6 +150,13 @@ bool Screen::leave() } m_screen->leave(); + if (Settings::value(Settings::Core::EnableExitCommand).toBool()) { + auto args = QProcess::splitCommand(Settings::value(Settings::Core::ScreenExitCommand).toString()); + const auto command = args.takeFirst(); + LOG_DEBUG("running screen exit command: %s %s", qPrintable(command), qPrintable(args.join(" "))); + if (!QProcess::startDetached(command, args)) + LOG_ERR("failed to run screen exit command"); + } // make sure our idea of clipboard ownership is correct m_screen->checkClipboards(); diff --git a/src/lib/gui/dialogs/SettingsDialog.cpp b/src/lib/gui/dialogs/SettingsDialog.cpp index 137702ac6..12409e378 100644 --- a/src/lib/gui/dialogs/SettingsDialog.cpp +++ b/src/lib/gui/dialogs/SettingsDialog.cpp @@ -31,10 +31,9 @@ SettingsDialog::SettingsDialog(QWidget *parent, const IServerConfig &serverConfi ui->setupUi(this); - // hide advanced options on macOS and portable windows - if (deskflow::platform::isMac() || (deskflow::platform::isWindows() && Settings::isPortableMode())) { - ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabAdvanced)); - } + // these are enabled by the control next to them + ui->lineCommandEnter->setEnabled(false); + ui->lineCommandExit->setEnabled(false); // set up the language combo I18N::reDetectLanguages(); @@ -100,6 +99,9 @@ void SettingsDialog::initConnections() const &SettingsDialog::resetToDefault ); + connect(ui->cbRunEnterCommand, &QCheckBox::toggled, ui->lineCommandEnter, &QLineEdit::setEnabled); + connect(ui->cbRunExitCommand, &QCheckBox::toggled, ui->lineCommandExit, &QLineEdit::setEnabled); + connect(ui->groupSecurity, &QGroupBox::toggled, this, &SettingsDialog::updateTlsControlsEnabled); connect(ui->groupService, &QGroupBox::toggled, this, &SettingsDialog::updateControls); connect(ui->btnTlsRegenCert, &QPushButton::clicked, this, &SettingsDialog::regenCertificates); @@ -134,6 +136,10 @@ void SettingsDialog::initConnections() const connect(ui->groupSecurity, &QGroupBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); connect(ui->lineLogFilename, &QLineEdit::textChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); connect(ui->lineTlsCertPath, &QLineEdit::textChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbRunEnterCommand, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbRunExitCommand, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->lineCommandEnter, &QLineEdit::textChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->lineCommandExit, &QLineEdit::textChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); } void SettingsDialog::regenCertificates() @@ -229,6 +235,10 @@ void SettingsDialog::accept() Settings::setValue(Settings::Log::GuiDebug, ui->cbGuiDebug->isChecked()); Settings::setValue(Settings::Core::UseWlClipboard, ui->cbUseWlClipboard->isChecked()); Settings::setValue(Settings::Gui::ShowVersionInTitle, ui->cbShowVersion->isChecked()); + Settings::setValue(Settings::Core::EnableEnterCommand, ui->cbRunEnterCommand->isChecked()); + Settings::setValue(Settings::Core::EnableExitCommand, ui->cbRunExitCommand->isChecked()); + Settings::setValue(Settings::Core::ScreenEnterCommand, ui->lineCommandEnter->text()); + Settings::setValue(Settings::Core::ScreenExitCommand, ui->lineCommandExit->text()); Settings::ProcessMode mode; if (ui->groupService->isChecked()) @@ -252,6 +262,10 @@ void SettingsDialog::loadFromConfig() ui->cbGuiDebug->setChecked(Settings::value(Settings::Log::GuiDebug).toBool()); ui->cbUseWlClipboard->setChecked(Settings::value(Settings::Core::UseWlClipboard).toBool()); ui->cbShowVersion->setChecked(Settings::value(Settings::Gui::ShowVersionInTitle).toBool()); + ui->cbRunEnterCommand->setChecked(Settings::value(Settings::Core::EnableEnterCommand).toBool()); + ui->cbRunExitCommand->setChecked(Settings::value(Settings::Core::EnableExitCommand).toBool()); + ui->lineCommandEnter->setText(Settings::value(Settings::Core::ScreenEnterCommand).toString()); + ui->lineCommandExit->setText(Settings::value(Settings::Core::ScreenExitCommand).toString()); const auto processMode = Settings::value(Settings::Core::ProcessMode).value(); ui->groupService->setChecked(processMode == Settings::ProcessMode::Service); @@ -361,6 +375,10 @@ void SettingsDialog::updateControls() ui->comboTlsKeyLength->setEnabled(writable); ui->rbCloseToTray->setEnabled(writable); ui->rbExitOnClose->setEnabled(writable); + ui->cbRunEnterCommand->setEnabled(writable); + ui->cbRunExitCommand->setEnabled(writable); + ui->lineCommandEnter->setEnabled(writable && ui->cbRunEnterCommand->isChecked()); + ui->lineCommandExit->setEnabled(writable && ui->cbRunExitCommand->isChecked()); // Portable mode only ever applies to Windows. // Daemon options should only be available on Windows when *not* in portable mode. @@ -420,6 +438,10 @@ bool SettingsDialog::isModified() const (ui->comboTlsKeyLength->currentText() != Settings::value(Settings::Security::KeySize).toString()) || (ui->groupSecurity->isChecked() != Settings::value(Settings::Security::TlsEnabled).toBool()) || (ui->cbRequireClientCert->isChecked() != Settings::value(Settings::Security::CheckPeers).toBool()) || + (ui->cbRunEnterCommand->isChecked() != Settings::value(Settings::Core::EnableEnterCommand).toBool()) || + (ui->cbRunExitCommand->isChecked() != Settings::value(Settings::Core::EnableExitCommand).toBool()) || + (ui->lineCommandEnter->text() != Settings::value(Settings::Core::ScreenEnterCommand).toString()) || + (ui->lineCommandExit->text() != Settings::value(Settings::Core::ScreenExitCommand).toString()) || (I18N::nativeTo639Name(ui->comboLanguage->currentText()) != Settings::value(Settings::Core::Language).toString()); if (!ignoreInterface) @@ -451,6 +473,10 @@ bool SettingsDialog::isDefault() const (ui->comboTlsKeyLength->currentText() == Settings::defaultValue(Settings::Security::KeySize).toString()) && (ui->groupSecurity->isChecked() == Settings::defaultValue(Settings::Security::TlsEnabled).toBool()) && (ui->cbRequireClientCert->isChecked() == Settings::defaultValue(Settings::Security::CheckPeers).toBool()) && + (ui->lineCommandEnter->text() == Settings::defaultValue(Settings::Core::ScreenEnterCommand).toString()) && + (ui->lineCommandExit->text() == Settings::defaultValue(Settings::Core::ScreenExitCommand).toString()) && + (ui->cbRunEnterCommand->isChecked() == Settings::defaultValue(Settings::Core::EnableEnterCommand).toBool()) && + (ui->cbRunExitCommand->isChecked() == Settings::defaultValue(Settings::Core::EnableExitCommand).toBool()) && (ui->comboLanguage->currentText() == "English") ); } @@ -467,6 +493,10 @@ void SettingsDialog::resetToDefault() ui->cbGuiDebug->setChecked(Settings::defaultValue(Settings::Log::GuiDebug).toBool()); ui->cbUseWlClipboard->setChecked(Settings::defaultValue(Settings::Core::UseWlClipboard).toBool()); ui->cbShowVersion->setChecked(Settings::defaultValue(Settings::Gui::ShowVersionInTitle).toBool()); + ui->cbRunEnterCommand->setChecked(Settings::defaultValue(Settings::Core::EnableEnterCommand).toBool()); + ui->cbRunExitCommand->setChecked(Settings::defaultValue(Settings::Core::EnableExitCommand).toBool()); + ui->lineCommandEnter->setText(Settings::defaultValue(Settings::Core::ScreenEnterCommand).toString()); + ui->lineCommandExit->setText(Settings::defaultValue(Settings::Core::ScreenExitCommand).toString()); const auto autoHide = Settings::defaultValue(Settings::Gui::Autohide).toBool(); ui->rbCloseToTray->setChecked(autoHide); diff --git a/src/lib/gui/dialogs/SettingsDialog.ui b/src/lib/gui/dialogs/SettingsDialog.ui index 96c5f7c2c..a4768cc2c 100644 --- a/src/lib/gui/dialogs/SettingsDialog.ui +++ b/src/lib/gui/dialogs/SettingsDialog.ui @@ -6,33 +6,30 @@ 0 0 - 564 - 431 + 490 + 366 + + + 0 + 0 + + Preferences true - - - 20 - + - - - 0 - 0 - - &General - + 9 @@ -40,13 +37,13 @@ 12 - 20 + 0 12 - 20 + 0 @@ -147,16 +144,16 @@ 12 - 20 + 0 12 - 20 + 0 - + Qt::Orientation::Vertical @@ -266,16 +263,16 @@ 12 - 20 + 0 12 - 20 + 0 - + Qt::Orientation::Vertical @@ -492,16 +489,16 @@ 12 - 20 + 0 12 - 20 + 0 - + Qt::Orientation::Vertical @@ -788,12 +785,6 @@ - - - 0 - 0 - - &Advanced @@ -805,16 +796,16 @@ 12 - 20 + 0 12 - 20 + 0 - + Qt::Orientation::Vertical @@ -831,12 +822,6 @@ true - - - 0 - 0 - - Use background service (daemon) @@ -862,12 +847,6 @@ - - - 0 - 0 - - @@ -889,6 +868,39 @@ + + + + QFormLayout::RowWrapPolicy::DontWrapRows + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + Qt::AlignmentFlag::AlignHCenter|Qt::AlignmentFlag::AlignTop + + + + + Run command on enter + + + + + + + + + + Run command on exit + + + + + + + + diff --git a/translations/deskflow_es.ts b/translations/deskflow_es.ts index 582831702..715925f0a 100644 --- a/translations/deskflow_es.ts +++ b/translations/deskflow_es.ts @@ -1309,6 +1309,14 @@ Al habilitar esta opción, se deshabilitará la interfaz gráfica de usuario (GU Show the main window Mostrar la ventana principal + + Run command on enter + Ejecutar comando al presionar Enter + + + Run command on exit + Ejecutar comando al salir + StatusBar diff --git a/translations/deskflow_it.ts b/translations/deskflow_it.ts index 260221a93..8e86830a1 100644 --- a/translations/deskflow_it.ts +++ b/translations/deskflow_it.ts @@ -1309,6 +1309,14 @@ L'abilitazione di questa impostazione disabiliterà l'interfaccia graf Show the main window Mostra la finestra principale + + Run command on enter + Esegui il comando alla pressione di Invio + + + Run command on exit + Esegui comando all'uscita + StatusBar diff --git a/translations/deskflow_ja.ts b/translations/deskflow_ja.ts index 0d972d5f1..a4fa772d6 100644 --- a/translations/deskflow_ja.ts +++ b/translations/deskflow_ja.ts @@ -1311,6 +1311,14 @@ Enabling this setting will disable the server config GUI. Show the main window メインウィンドウを表示する + + Run command on enter + Enterキーでコマンドを実行 + + + Run command on exit + 終了時にコマンドを実行 + StatusBar diff --git a/translations/deskflow_ko.ts b/translations/deskflow_ko.ts index c64a78986..f4b6826fd 100644 --- a/translations/deskflow_ko.ts +++ b/translations/deskflow_ko.ts @@ -1309,6 +1309,14 @@ Enabling this setting will disable the server config GUI. Show the main window 메인 창을 표시합니다 + + Run command on enter + Enter 키를 누르면 명령 실행 + + + Run command on exit + 종료 시 명령 실행 + StatusBar diff --git a/translations/deskflow_ru.ts b/translations/deskflow_ru.ts index ba03bef50..a319c2f96 100644 --- a/translations/deskflow_ru.ts +++ b/translations/deskflow_ru.ts @@ -1307,6 +1307,14 @@ Enabling this setting will disable the server config GUI. Show the main window Показать главное окно + + Run command on enter + Выполнять команду по нажатию Enter + + + Run command on exit + Выполнить команду при выходе + StatusBar diff --git a/translations/deskflow_zh_CN.ts b/translations/deskflow_zh_CN.ts index 745cfddfe..82c2c7855 100644 --- a/translations/deskflow_zh_CN.ts +++ b/translations/deskflow_zh_CN.ts @@ -1311,6 +1311,14 @@ Enabling this setting will disable the server config GUI. Show the main window 显示主窗口 + + Run command on enter + 按下回车键执行命令 + + + Run command on exit + 退出时运行命令 + StatusBar