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

@ -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

@ -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"
@ -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 ""
@ -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

View File

@ -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;
}; };