mirror of
https://github.com/swaywm/sway.git
synced 2026-04-28 06:46:26 -04:00
swayidle: add ability to wait for command to finish
This commit is contained in:
parent
cab5449b1d
commit
9a6f4bc0d9
2 changed files with 18 additions and 3 deletions
|
|
@ -35,6 +35,7 @@ struct swayidle_state {
|
||||||
struct wl_event_loop *event_loop;
|
struct wl_event_loop *event_loop;
|
||||||
list_t *timeout_cmds; // struct swayidle_timeout_cmd *
|
list_t *timeout_cmds; // struct swayidle_timeout_cmd *
|
||||||
char *lock_cmd;
|
char *lock_cmd;
|
||||||
|
bool wait;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
struct swayidle_timeout_cmd {
|
struct swayidle_timeout_cmd {
|
||||||
|
|
@ -54,7 +55,9 @@ static void cmd_exec(char *param) {
|
||||||
wlr_log(WLR_DEBUG, "Cmd exec %s", param);
|
wlr_log(WLR_DEBUG, "Cmd exec %s", param);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
|
if (!state.wait) {
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
}
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
char *const cmd[] = { "sh", "-c", param, NULL, };
|
char *const cmd[] = { "sh", "-c", param, NULL, };
|
||||||
execvp(cmd[0], cmd);
|
execvp(cmd[0], cmd);
|
||||||
|
|
@ -325,16 +328,20 @@ static int parse_args(int argc, char *argv[]) {
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "hd")) != -1) {
|
while ((c = getopt(argc, argv, "hdw")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
debug = true;
|
debug = true;
|
||||||
break;
|
break;
|
||||||
|
case 'w':
|
||||||
|
state.wait = true;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
case '?':
|
case '?':
|
||||||
printf("Usage: %s [OPTIONS]\n", argv[0]);
|
printf("Usage: %s [OPTIONS]\n", argv[0]);
|
||||||
printf(" -d\tdebug\n");
|
|
||||||
printf(" -h\tthis help menu\n");
|
printf(" -h\tthis help menu\n");
|
||||||
|
printf(" -d\tdebug\n");
|
||||||
|
printf(" -w\twait for command to finish\n");
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ swayidle - Idle manager for Wayland
|
||||||
*-d*
|
*-d*
|
||||||
Enable debug output.
|
Enable debug output.
|
||||||
|
|
||||||
|
*-w*
|
||||||
|
Wait for command to finish executing before continuing, helpful for ensuring
|
||||||
|
that a *before-sleep* command has finished before the system goes to sleep.
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
swayidle listens for idle activity on your Wayland compositor and executes tasks
|
swayidle listens for idle activity on your Wayland compositor and executes tasks
|
||||||
|
|
@ -36,6 +40,10 @@ Sending SIGUSR1 to swayidle will immediately enter idle state.
|
||||||
If built with systemd support, executes _command_ before systemd puts the
|
If built with systemd support, executes _command_ before systemd puts the
|
||||||
computer to sleep.
|
computer to sleep.
|
||||||
|
|
||||||
|
Note: this only delays sleeping up to the limit set in *logind.conf(5)* by
|
||||||
|
the option InhibitDelayMaxSec. A command that hasn't finished by then will
|
||||||
|
continue running after resuming from sleep.
|
||||||
|
|
||||||
All commands are executed in a shell.
|
All commands are executed in a shell.
|
||||||
|
|
||||||
# EXAMPLE
|
# EXAMPLE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue