Merge pull request #249 from vorph1/screen-change-script

Screen change script argument
This commit is contained in:
Adrian Lucrèce Céleste 2019-02-10 11:26:28 -05:00 committed by GitHub
commit fac5610b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 34 deletions

5
.gitignore vendored
View File

@ -20,3 +20,8 @@ src/gui/gui.pro.user*
src/gui/.qmake.stash src/gui/.qmake.stash
src/gui/.rnd src/gui/.rnd
src/setup/win32/barrier.suo src/setup/win32/barrier.suo
Makefile
*.cmake
**/CMakeFiles/
CMakeCache.txt
/rpm

View File

@ -29,7 +29,7 @@
#ifdef WINAPI_MSWINDOWS #ifdef WINAPI_MSWINDOWS
#include <VersionHelpers.h> #include <VersionHelpers.h>
#endif #endif
ArgsBase* ArgParser::m_argsBase = NULL; ArgsBase* ArgParser::m_argsBase = NULL;
ArgParser::ArgParser(App* app) : ArgParser::ArgParser(App* app) :
@ -61,6 +61,10 @@ ArgParser::parseServerArgs(ServerArgs& args, int argc, const char* const* argv)
// save configuration file path // save configuration file path
args.m_configFile = argv[++i]; args.m_configFile = argv[++i];
} }
else if (isArg(i, argc, argv, NULL, "--screen-change-script", 1)) {
// save screen change script path
args.m_screenChangeScript = argv[++i];
}
else { else {
LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE, args.m_exename.c_str(), argv[i], args.m_exename.c_str())); LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE, args.m_exename.c_str(), argv[i], args.m_exename.c_str()));
return false; return false;

View File

@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility * barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman * Copyright (C) 2002 Chris Schoeneman
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file. * found in the file LICENSE that should have accompanied this file.
* *
* This package is distributed in the hope that it will be useful, * This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -49,6 +49,8 @@
#if WINAPI_MSWINDOWS #if WINAPI_MSWINDOWS
#include "platform/MSWindowsScreen.h" #include "platform/MSWindowsScreen.h"
#elif WINAPI_XWINDOWS #elif WINAPI_XWINDOWS
#include <unistd.h>
#include <signal.h>
#include "platform/XWindowsScreen.h" #include "platform/XWindowsScreen.h"
#elif WINAPI_CARBON #elif WINAPI_CARBON
#include "platform/OSXScreen.h" #include "platform/OSXScreen.h"
@ -95,7 +97,7 @@ ServerApp::parseArgs(int argc, const char* const* argv)
else { else {
if (!args().m_barrierAddress.empty()) { if (!args().m_barrierAddress.empty()) {
try { try {
*m_barrierAddress = NetworkAddress(args().m_barrierAddress, *m_barrierAddress = NetworkAddress(args().m_barrierAddress,
kDefaultPort); kDefaultPort);
m_barrierAddress->resolve(); m_barrierAddress->resolve();
} }
@ -117,7 +119,10 @@ ServerApp::help()
" [--display <display>] [--no-xinitthreads]" " [--display <display>] [--no-xinitthreads]"
# define WINAPI_INFO \ # define WINAPI_INFO \
" --display <display> connect to the X server at <display>\n" \ " --display <display> connect to the X server at <display>\n" \
" --no-xinitthreads do not call XInitThreads()\n" " --no-xinitthreads do not call XInitThreads()\n" \
" --screen-change-script <path>\n" \
" full path to script to run on screen change\n" \
" first argument is the new screen name\n"
#else #else
# define WINAPI_ARGS "" # define WINAPI_ARGS ""
# define WINAPI_INFO "" # define WINAPI_INFO ""
@ -240,7 +245,7 @@ ServerApp::loadConfig(const String& pathname)
return false; return false;
} }
void void
ServerApp::forceReconnect(const Event&, void*) ServerApp::forceReconnect(const Event&, void*)
{ {
if (m_server != NULL) { if (m_server != NULL) {
@ -248,7 +253,7 @@ ServerApp::forceReconnect(const Event&, void*)
} }
} }
void void
ServerApp::handleClientConnected(const Event&, void* vlistener) ServerApp::handleClientConnected(const Event&, void* vlistener)
{ {
ClientListener* listener = static_cast<ClientListener*>(vlistener); ClientListener* listener = static_cast<ClientListener*>(vlistener);
@ -282,7 +287,7 @@ ServerApp::closeServer(Server* server)
new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientsDisconnected)); new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientsDisconnected));
m_events->adoptHandler(m_events->forServer().disconnected(), server, m_events->adoptHandler(m_events->forServer().disconnected(), server,
new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientsDisconnected)); new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientsDisconnected));
m_events->loop(); m_events->loop();
m_events->removeHandler(Event::kTimer, timer); m_events->removeHandler(Event::kTimer, timer);
@ -293,7 +298,7 @@ ServerApp::closeServer(Server* server)
delete server; delete server;
} }
void void
ServerApp::stopRetryTimer() ServerApp::stopRetryTimer()
{ {
if (m_timer != NULL) { if (m_timer != NULL) {
@ -317,7 +322,7 @@ void ServerApp::updateStatus(const String& msg)
} }
} }
void void
ServerApp::closeClientListener(ClientListener* listen) ServerApp::closeClientListener(ClientListener* listen)
{ {
if (listen != NULL) { if (listen != NULL) {
@ -326,7 +331,7 @@ ServerApp::closeClientListener(ClientListener* listen)
} }
} }
void void
ServerApp::stopServer() ServerApp::stopServer()
{ {
if (m_serverState == kStarted) { if (m_serverState == kStarted) {
@ -350,7 +355,7 @@ ServerApp::closePrimaryClient(PrimaryClient* primaryClient)
delete primaryClient; delete primaryClient;
} }
void void
ServerApp::closeServerScreen(barrier::Screen* screen) ServerApp::closeServerScreen(barrier::Screen* screen)
{ {
if (screen != NULL) { if (screen != NULL) {
@ -517,7 +522,7 @@ static const char* const family_string(IArchNetwork::EAddressFamily family)
return "Unknown"; return "Unknown";
} }
bool bool
ServerApp::startServer() ServerApp::startServer()
{ {
// skip if already started or starting // skip if already started or starting
@ -582,7 +587,7 @@ ServerApp::startServer()
} }
} }
barrier::Screen* barrier::Screen*
ServerApp::createScreen() ServerApp::createScreen()
{ {
#if WINAPI_MSWINDOWS #if WINAPI_MSWINDOWS
@ -597,7 +602,7 @@ ServerApp::createScreen()
#endif #endif
} }
PrimaryClient* PrimaryClient*
ServerApp::openPrimaryClient(const String& name, barrier::Screen* screen) ServerApp::openPrimaryClient(const String& name, barrier::Screen* screen)
{ {
LOG((CLOG_DEBUG1 "creating primary screen")); LOG((CLOG_DEBUG1 "creating primary screen"));
@ -612,7 +617,7 @@ ServerApp::handleScreenError(const Event&, void*)
m_events->addEvent(Event(Event::kQuit)); m_events->addEvent(Event(Event::kQuit));
} }
void void
ServerApp::handleSuspend(const Event&, void*) ServerApp::handleSuspend(const Event&, void*)
{ {
if (!m_suspended) { if (!m_suspended) {
@ -622,7 +627,7 @@ ServerApp::handleSuspend(const Event&, void*)
} }
} }
void void
ServerApp::handleResume(const Event&, void*) ServerApp::handleResume(const Event&, void*)
{ {
if (m_suspended) { if (m_suspended) {
@ -640,16 +645,16 @@ ServerApp::openClientListener(const NetworkAddress& address)
new TCPSocketFactory(m_events, getSocketMultiplexer()), new TCPSocketFactory(m_events, getSocketMultiplexer()),
m_events, m_events,
args().m_enableCrypto); args().m_enableCrypto);
m_events->adoptHandler( m_events->adoptHandler(
m_events->forClientListener().connected(), listen, m_events->forClientListener().connected(), listen,
new TMethodEventJob<ServerApp>( new TMethodEventJob<ServerApp>(
this, &ServerApp::handleClientConnected, listen)); this, &ServerApp::handleClientConnected, listen));
return listen; return listen;
} }
Server* Server*
ServerApp::openServer(Config& config, PrimaryClient* primaryClient) ServerApp::openServer(Config& config, PrimaryClient* primaryClient)
{ {
Server* server = new Server(config, primaryClient, m_serverScreen, m_events, args()); Server* server = new Server(config, primaryClient, m_serverScreen, m_events, args());
@ -679,6 +684,28 @@ ServerApp::handleNoClients(const Event&, void*)
void void
ServerApp::handleScreenSwitched(const Event& e, void*) ServerApp::handleScreenSwitched(const Event& e, void*)
{ {
Server::SwitchToScreenInfo* info = (Server::SwitchToScreenInfo*)(e.getData());
#ifdef WINAPI_XWINDOWS
if (!args().m_screenChangeScript.empty()) {
LOG((CLOG_INFO "Running shell script for screen \"%s\"", info->m_screen));
signal(SIGCHLD, SIG_IGN);
if (!access(args().m_screenChangeScript.c_str(), X_OK)) {
pid_t pid = fork();
if (pid == 0) {
execl(args().m_screenChangeScript.c_str(),args().m_screenChangeScript.c_str(),info->m_screen,NULL);
exit(0);
} else if (pid < 0) {
LOG((CLOG_ERR "Script forking error"));
exit(1);
}
} else {
LOG((CLOG_ERR "Script not accessible \"%s\"", args().m_screenChangeScript.c_str()));
}
}
#endif
} }
int int
@ -714,7 +741,7 @@ ServerApp::mainLoop()
// start server, etc // start server, etc
appUtil().startNode(); appUtil().startNode();
// init ipc client after node start, since create a new screen wipes out // init ipc client after node start, since create a new screen wipes out
// the event queue (the screen ctors call adoptBuffer). // the event queue (the screen ctors call adoptBuffer).
if (argsBase().m_enableIpc) { if (argsBase().m_enableIpc) {
@ -743,24 +770,24 @@ ServerApp::mainLoop()
// later. the timer installed by startServer() will take care of // later. the timer installed by startServer() will take care of
// that. // that.
DAEMON_RUNNING(true); DAEMON_RUNNING(true);
#if defined(MAC_OS_X_VERSION_10_7) #if defined(MAC_OS_X_VERSION_10_7)
Thread thread( Thread thread(
new TMethodJob<ServerApp>( new TMethodJob<ServerApp>(
this, &ServerApp::runEventsLoop, this, &ServerApp::runEventsLoop,
NULL)); NULL));
// wait until carbon loop is ready // wait until carbon loop is ready
OSXScreen* screen = dynamic_cast<OSXScreen*>( OSXScreen* screen = dynamic_cast<OSXScreen*>(
m_serverScreen->getPlatformScreen()); m_serverScreen->getPlatformScreen());
screen->waitForCarbonLoop(); screen->waitForCarbonLoop();
runCocoaApp(); runCocoaApp();
#else #else
m_events->loop(); m_events->loop();
#endif #endif
DAEMON_RUNNING(false); DAEMON_RUNNING(false);
// close down // close down
@ -788,7 +815,7 @@ void ServerApp::resetServer(const Event&, void*)
startServer(); startServer();
} }
int int
ServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup) ServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup)
{ {
// general initialization // general initialization
@ -819,7 +846,7 @@ int daemonMainLoopStatic(int argc, const char** argv) {
return ServerApp::instance().daemonMainLoop(argc, argv); return ServerApp::instance().daemonMainLoop(argc, argv);
} }
int int
ServerApp::standardStartup(int argc, char** argv) ServerApp::standardStartup(int argc, char** argv)
{ {
initApp(argc, argv); initApp(argc, argv);
@ -833,7 +860,7 @@ ServerApp::standardStartup(int argc, char** argv)
} }
} }
int int
ServerApp::foregroundStartup(int argc, char** argv) ServerApp::foregroundStartup(int argc, char** argv)
{ {
initApp(argc, argv); initApp(argc, argv);
@ -842,7 +869,7 @@ ServerApp::foregroundStartup(int argc, char** argv)
return mainLoop(); return mainLoop();
} }
const char* const char*
ServerApp::daemonName() const ServerApp::daemonName() const
{ {
#if SYSAPI_WIN32 #if SYSAPI_WIN32
@ -852,7 +879,7 @@ ServerApp::daemonName() const
#endif #endif
} }
const char* const char*
ServerApp::daemonInfo() const ServerApp::daemonInfo() const
{ {
#if SYSAPI_WIN32 #if SYSAPI_WIN32

View File

@ -1,11 +1,11 @@
/* /*
* barrier -- mouse and keyboard sharing utility * barrier -- mouse and keyboard sharing utility
* Copyright (C) 2014-2016 Symless Ltd. * Copyright (C) 2014-2016 Symless Ltd.
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file. * found in the file LICENSE that should have accompanied this file.
* *
* This package is distributed in the hope that it will be useful, * This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -19,7 +19,8 @@
ServerArgs::ServerArgs() : ServerArgs::ServerArgs() :
m_configFile(), m_configFile(),
m_config(NULL) m_config(NULL),
m_screenChangeScript()
{ {
} }

View File

@ -29,4 +29,5 @@ public:
public: public:
String m_configFile; String m_configFile;
Config* m_config; Config* m_config;
String m_screenChangeScript;
}; };