diff -u xwrits-2.26/main.c xwrits/main.c --- xwrits-2.26/main.c 2009-04-04 01:17:02.000000000 +0400 +++ xwrits/main.c 2010-08-13 13:13:36.344975405 +0400 @@ -10,6 +10,7 @@ #ifdef HAVE_XINERAMA #include #endif +#include static Options onormal; Options *ocurrent; @@ -63,6 +64,9 @@ static int force_mono = 0; static int multiscreen = 0; +static const char *before_lock_command = 0; +static const char *after_lock_command = 0; + static void short_usage(void) @@ -757,6 +761,10 @@ ; else if (optparse(s, "wp", 2, "ss", &o->slideshow_text)) ; + else if (optparse(s, "before-lock", 1, "ss", &before_lock_command)) + ; + else if (optparse(s, "after-lock", 1, "ss", &after_lock_command)) + ; else short_usage(); @@ -1089,6 +1097,32 @@ } +void fork_and_run(const char* const cmd) +{ + pid_t pid; + pid = fork(); + if (pid == 0) { + execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); + _exit(0); + } +} + +void on_before_lock() +{ + printf("Before lock\n"); + if (before_lock_command) { + fork_and_run(before_lock_command); + } +} +void on_after_lock() +{ + printf("After lock\n"); + if (after_lock_command) { + fork_and_run(after_lock_command); + } +} + + /* main! */ typedef enum { @@ -1159,7 +1193,9 @@ case ST_LOCK: was_lock = 1; + on_before_lock(); tran = lock(); + on_after_lock(); assert(tran == TRAN_AWAKE || tran == TRAN_FAIL); if (tran == TRAN_AWAKE) s = ST_AWAKE; @@ -1198,6 +1234,8 @@ default_settings(); parse_options(argc - 1, argv + 1); + signal(SIGCLD, SIG_IGN); + /* At this point, all ports have 'display_name' valid and everything else invalid. Open displays, check multiscreen */ orig_nports = nports;