aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2019-01-12 09:40:09 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-12 11:24:06 -0500
commitbc808680b173d5a3c4732265b33e2e8bd81e4d9b (patch)
tree800d9f0ba88f37c2dd35aae09fcdbec91c0532c3
parentMerge pull request #3411 from RedSoxFan/fix-brace-detect-seeking (diff)
downloadsway-bc808680b173d5a3c4732265b33e2e8bd81e4d9b.tar.gz
sway-bc808680b173d5a3c4732265b33e2e8bd81e4d9b.tar.zst
sway-bc808680b173d5a3c4732265b33e2e8bd81e4d9b.zip
Split swayidle from sway
-rw-r--r--completions/bash/swayidle48
-rw-r--r--completions/fish/swayidle.fish3
-rw-r--r--completions/zsh/_swayidle22
-rw-r--r--meson.build4
-rw-r--r--swayidle/main.c483
-rw-r--r--swayidle/meson.build27
-rw-r--r--swayidle/swayidle.1.scd63
7 files changed, 0 insertions, 650 deletions
diff --git a/completions/bash/swayidle b/completions/bash/swayidle
deleted file mode 100644
index a0cdc8b2..00000000
--- a/completions/bash/swayidle
+++ /dev/null
@@ -1,48 +0,0 @@
1# swaymsg(1) completion
2
3_swayidle()
4{
5 local cur prev
6 _get_comp_words_by_ref -n : cur prev
7 local prev2=${COMP_WORDS[COMP_CWORD-2]}
8 local prev3=${COMP_WORDS[COMP_CWORD-3]}
9
10 events=(
11 'timeout'
12 'before-sleep'
13 )
14
15 short=(
16 -h
17 -d
18 )
19
20 if [ "$prev" = timeout ]; then
21 # timeout <timeout>
22 return
23 elif [ "$prev2" = timeout ]; then
24 # timeout <timeout> <timeout command>
25 COMPREPLY=($(compgen -c -- "$cur"))
26 return
27 elif [ "$prev3" = timeout ]; then
28 # timeout <timeout> <timeout command> [resume <resume command>]
29 COMPREPLY=(resume)
30 # optional argument; no return here as user may skip 'resume'
31 fi
32
33 case "$prev" in
34 resume)
35 COMPREPLY=($(compgen -c -- "$cur"))
36 return
37 ;;
38 before-sleep)
39 COMPREPLY=($(compgen -c -- "$cur"))
40 return
41 ;;
42 esac
43
44 COMPREPLY+=($(compgen -W "${events[*]}" -- "$cur"))
45 COMPREPLY+=($(compgen -W "${short[*]}" -- "$cur"))
46
47} &&
48complete -F _swayidle swayidle
diff --git a/completions/fish/swayidle.fish b/completions/fish/swayidle.fish
deleted file mode 100644
index 71279925..00000000
--- a/completions/fish/swayidle.fish
+++ /dev/null
@@ -1,3 +0,0 @@
1# swayidle
2complete -c swayidle -s h --description 'show help'
3complete -c swayidle -s d --description 'debug'
diff --git a/completions/zsh/_swayidle b/completions/zsh/_swayidle
deleted file mode 100644
index b419bc2c..00000000
--- a/completions/zsh/_swayidle
+++ /dev/null
@@ -1,22 +0,0 @@
1#compdef swayidle
2#
3# Completion script for swayidle
4#
5
6local events=('timeout:Execute timeout command if there is no activity for timeout seconds'
7 'before-sleep:Execute before-sleep command before sleep')
8local resume=('resume:Execute command when there is activity again')
9
10if (($#words <= 2)); then
11 _arguments -C \
12 '(-h --help)'{-h,--help}'[Show help message and quit]' \
13 '(-d)'-d'[Enable debug output]'
14 _describe -t "events" 'swayidle' events
15
16elif [[ "$words[-3]" == before-sleep || "$words[-3]" == resume ]]; then
17 _describe -t "events" 'swayidle' events
18
19elif [[ "$words[-4]" == timeout ]]; then
20 _describe -t "events" 'swayidle' events
21 _describe -t "resume" 'swayidle' resume
22fi
diff --git a/meson.build b/meson.build
index b1353b59..bffbe312 100644
--- a/meson.build
+++ b/meson.build
@@ -86,7 +86,6 @@ if scdoc.found()
86 'sway/sway-output.5.scd', 86 'sway/sway-output.5.scd',
87 'swaylock/swaylock.1.scd', 87 'swaylock/swaylock.1.scd',
88 'swaymsg/swaymsg.1.scd', 88 'swaymsg/swaymsg.1.scd',
89 'swayidle/swayidle.1.scd',
90 'swaynag/swaynag.1.scd', 89 'swaynag/swaynag.1.scd',
91 'swaynag/swaynag.5.scd', 90 'swaynag/swaynag.5.scd',
92 ] 91 ]
@@ -146,7 +145,6 @@ subdir('swaymsg')
146subdir('client') 145subdir('client')
147subdir('swaybg') 146subdir('swaybg')
148subdir('swaybar') 147subdir('swaybar')
149subdir('swayidle')
150subdir('swaynag') 148subdir('swaynag')
151subdir('swaylock') 149subdir('swaylock')
152 150
@@ -214,7 +212,6 @@ if (get_option('bash-completions'))
214 bash_files = files( 212 bash_files = files(
215 'completions/bash/sway', 213 'completions/bash/sway',
216 'completions/bash/swaybar', 214 'completions/bash/swaybar',
217 'completions/bash/swayidle',
218 'completions/bash/swaylock', 215 'completions/bash/swaylock',
219 'completions/bash/swaymsg', 216 'completions/bash/swaymsg',
220 ) 217 )
@@ -226,7 +223,6 @@ endif
226if (get_option('fish-completions')) 223if (get_option('fish-completions'))
227 fish_files = files( 224 fish_files = files(
228 'completions/fish/sway.fish', 225 'completions/fish/sway.fish',
229 'completions/fish/swayidle.fish',
230 'completions/fish/swaylock.fish', 226 'completions/fish/swaylock.fish',
231 'completions/fish/swaymsg.fish', 227 'completions/fish/swaymsg.fish',
232 'completions/fish/swaynag.fish', 228 'completions/fish/swaynag.fish',
diff --git a/swayidle/main.c b/swayidle/main.c
deleted file mode 100644
index 41eecc41..00000000
--- a/swayidle/main.c
+++ /dev/null
@@ -1,483 +0,0 @@
1#define _POSIX_C_SOURCE 200809L
2#include <assert.h>
3#include <errno.h>
4#include <fcntl.h>
5#include <getopt.h>
6#include <pthread.h>
7#include <signal.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <sys/wait.h>
12#include <unistd.h>
13#include <wayland-client-protocol.h>
14#include <wayland-client.h>
15#include <wayland-server.h>
16#include <wayland-util.h>
17#include <wlr/config.h>
18#include <wlr/util/log.h>
19#include "config.h"
20#include "idle-client-protocol.h"
21#include "list.h"
22#if HAVE_SYSTEMD
23#include <systemd/sd-bus.h>
24#include <systemd/sd-login.h>
25#elif HAVE_ELOGIND
26#include <elogind/sd-bus.h>
27#include <elogind/sd-login.h>
28#endif
29
30static struct org_kde_kwin_idle *idle_manager = NULL;
31static struct wl_seat *seat = NULL;
32
33struct swayidle_state {
34 struct wl_display *display;
35 struct wl_event_loop *event_loop;
36 list_t *timeout_cmds; // struct swayidle_timeout_cmd *
37 char *lock_cmd;
38} state;
39
40struct swayidle_timeout_cmd {
41 int timeout, registered_timeout;
42 struct org_kde_kwin_idle_timeout *idle_timer;
43 char *idle_cmd;
44 char *resume_cmd;
45};
46
47void sway_terminate(int exit_code) {
48 wl_display_disconnect(state.display);
49 wl_event_loop_destroy(state.event_loop);
50 exit(exit_code);
51}
52
53static void cmd_exec(char *param) {
54 wlr_log(WLR_DEBUG, "Cmd exec %s", param);
55 pid_t pid = fork();
56 if (pid == 0) {
57 pid = fork();
58 if (pid == 0) {
59 char *const cmd[] = { "sh", "-c", param, NULL, };
60 execvp(cmd[0], cmd);
61 wlr_log_errno(WLR_ERROR, "execve failed!");
62 exit(1);
63 } else if (pid < 0) {
64 wlr_log_errno(WLR_ERROR, "fork failed");
65 exit(1);
66 }
67 exit(0);
68 } else if (pid < 0) {
69 wlr_log_errno(WLR_ERROR, "fork failed");
70 } else {
71 wlr_log(WLR_DEBUG, "Spawned process %s", param);
72 waitpid(pid, NULL, 0);
73 }
74}
75
76#if HAVE_SYSTEMD || HAVE_ELOGIND
77static int lock_fd = -1;
78static int ongoing_fd = -1;
79static struct sd_bus *bus = NULL;
80
81static int release_lock(void *data) {
82 wlr_log(WLR_INFO, "Releasing sleep lock %d", ongoing_fd);
83 if (ongoing_fd >= 0) {
84 close(ongoing_fd);
85 }
86 ongoing_fd = -1;
87 return 0;
88}
89
90static void acquire_sleep_lock(void) {
91 sd_bus_message *msg = NULL;
92 sd_bus_error error = SD_BUS_ERROR_NULL;
93 int ret = sd_bus_call_method(bus, "org.freedesktop.login1",
94 "/org/freedesktop/login1",
95 "org.freedesktop.login1.Manager", "Inhibit",
96 &error, &msg, "ssss", "sleep", "swayidle",
97 "Setup Up Lock Screen", "delay");
98 if (ret < 0) {
99 wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s", error.message);
100 sd_bus_error_free(&error);
101 return;
102 }
103
104 ret = sd_bus_message_read(msg, "h", &lock_fd);
105 if (ret < 0) {
106 wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s",
107 strerror(-ret));
108 sd_bus_error_free(&error);
109 sd_bus_message_unref(msg);
110 return;
111 } else {
112 wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd);
113 }
114
115 // sd_bus_message_unref closes the file descriptor so we need
116 // to copy it beforehand
117 lock_fd = fcntl(lock_fd, F_DUPFD_CLOEXEC, 3);
118 if (lock_fd < 0) {
119 wlr_log(WLR_ERROR, "Failed to copy sleep lock fd: %s",
120 strerror(errno));
121 }
122
123 sd_bus_error_free(&error);
124 sd_bus_message_unref(msg);
125}
126
127static int prepare_for_sleep(sd_bus_message *msg, void *userdata,
128 sd_bus_error *ret_error) {
129 /* "b" apparently reads into an int, not a bool */
130 int going_down = 1;
131 int ret = sd_bus_message_read(msg, "b", &going_down);
132 if (ret < 0) {
133 wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s",
134 strerror(-ret));
135 }
136 wlr_log(WLR_DEBUG, "PrepareForSleep signal received %d", going_down);
137 if (!going_down) {
138 acquire_sleep_lock();
139 return 0;
140 }
141
142 ongoing_fd = lock_fd;
143
144 if (state.lock_cmd) {
145 cmd_exec(state.lock_cmd);
146 }
147
148 if (ongoing_fd >= 0) {
149 struct wl_event_source *source =
150 wl_event_loop_add_timer(state.event_loop, release_lock, NULL);
151 wl_event_source_timer_update(source, 1000);
152 }
153
154 wlr_log(WLR_DEBUG, "Prepare for sleep done");
155 return 0;
156}
157
158static int dbus_event(int fd, uint32_t mask, void *data) {
159 sd_bus *bus = data;
160
161 if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
162 sway_terminate(0);
163 }
164
165 int count = 0;
166 if (mask & WL_EVENT_READABLE) {
167 count = sd_bus_process(bus, NULL);
168 }
169 if (mask & WL_EVENT_WRITABLE) {
170 sd_bus_flush(bus);
171 }
172 if (mask == 0) {
173 sd_bus_flush(bus);
174 }
175
176 if (count < 0) {
177 wlr_log_errno(WLR_ERROR, "sd_bus_process failed, exiting");
178 sway_terminate(0);
179 }
180
181 return count;
182}
183
184static void setup_sleep_listener(void) {
185 int ret = sd_bus_default_system(&bus);
186 if (ret < 0) {
187 wlr_log(WLR_ERROR, "Failed to open D-Bus connection: %s",
188 strerror(-ret));
189 return;
190 }
191
192 char str[256];
193 const char *fmt = "type='signal',"
194 "sender='org.freedesktop.login1',"
195 "interface='org.freedesktop.login1.%s',"
196 "member='%s'," "path='%s'";
197
198 snprintf(str, sizeof(str), fmt, "Manager", "PrepareForSleep",
199 "/org/freedesktop/login1");
200 ret = sd_bus_add_match(bus, NULL, str, prepare_for_sleep, NULL);
201 if (ret < 0) {
202 wlr_log(WLR_ERROR, "Failed to add D-Bus match: %s", strerror(-ret));
203 return;
204 }
205 acquire_sleep_lock();
206
207 struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop,
208 sd_bus_get_fd(bus), WL_EVENT_READABLE, dbus_event, bus);
209 wl_event_source_check(source);
210}
211#endif
212
213static void handle_global(void *data, struct wl_registry *registry,
214 uint32_t name, const char *interface, uint32_t version) {
215 if (strcmp(interface, org_kde_kwin_idle_interface.name) == 0) {
216 idle_manager =
217 wl_registry_bind(registry, name, &org_kde_kwin_idle_interface, 1);
218 } else if (strcmp(interface, wl_seat_interface.name) == 0) {
219 seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
220 }
221}
222
223static void handle_global_remove(void *data, struct wl_registry *registry,
224 uint32_t name) {
225 // Who cares
226}
227
228static const struct wl_registry_listener registry_listener = {
229 .global = handle_global,
230 .global_remove = handle_global_remove,
231};
232
233static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener;
234
235static void register_timeout(struct swayidle_timeout_cmd *cmd,
236 int timeout) {
237 if (cmd->idle_timer != NULL) {
238 org_kde_kwin_idle_timeout_destroy(cmd->idle_timer);
239 cmd->idle_timer = NULL;
240 }
241 if (timeout < 0) {
242 wlr_log(WLR_DEBUG, "Not registering idle timeout");
243 return;
244 }
245 wlr_log(WLR_DEBUG, "Register with timeout: %d", timeout);
246 cmd->idle_timer =
247 org_kde_kwin_idle_get_idle_timeout(idle_manager, seat, timeout);
248 org_kde_kwin_idle_timeout_add_listener(cmd->idle_timer,
249 &idle_timer_listener, cmd);
250 cmd->registered_timeout = timeout;
251}
252
253static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
254 struct swayidle_timeout_cmd *cmd = data;
255 wlr_log(WLR_DEBUG, "idle state");
256 if (cmd->idle_cmd) {
257 cmd_exec(cmd->idle_cmd);
258 }
259}
260
261static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) {
262 struct swayidle_timeout_cmd *cmd = data;
263 wlr_log(WLR_DEBUG, "active state");
264 if (cmd->registered_timeout != cmd->timeout) {
265 register_timeout(cmd, cmd->timeout);
266 }
267 if (cmd->resume_cmd) {
268 cmd_exec(cmd->resume_cmd);
269 }
270}
271
272static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
273 .idle = handle_idle,
274 .resumed = handle_resume,
275};
276
277static char *parse_command(int argc, char **argv) {
278 if (argc < 1) {
279 wlr_log(WLR_ERROR, "Missing command");
280 return NULL;
281 }
282
283 wlr_log(WLR_DEBUG, "Command: %s", argv[0]);
284 return strdup(argv[0]);
285}
286
287static int parse_timeout(int argc, char **argv) {
288 if (argc < 3) {
289 wlr_log(WLR_ERROR, "Too few parameters to timeout command. "
290 "Usage: timeout <seconds> <command>");
291 exit(-1);
292 }
293 errno = 0;
294 char *endptr;
295 int seconds = strtoul(argv[1], &endptr, 10);
296 if (errno != 0 || *endptr != '\0') {
297 wlr_log(WLR_ERROR, "Invalid timeout parameter '%s', it should be a "
298 "numeric value representing seconds", optarg);
299 exit(-1);
300 }
301
302 struct swayidle_timeout_cmd *cmd =
303 calloc(1, sizeof(struct swayidle_timeout_cmd));
304
305 if (seconds > 0) {
306 cmd->timeout = seconds * 1000;
307 } else {
308 cmd->timeout = -1;
309 }
310
311 wlr_log(WLR_DEBUG, "Register idle timeout at %d ms", cmd->timeout);
312 wlr_log(WLR_DEBUG, "Setup idle");
313 cmd->idle_cmd = parse_command(argc - 2, &argv[2]);
314
315 int result = 3;
316 if (argc >= 5 && !strcmp("resume", argv[3])) {
317 wlr_log(WLR_DEBUG, "Setup resume");
318 cmd->resume_cmd = parse_command(argc - 4, &argv[4]);
319 result = 5;
320 }
321 list_add(state.timeout_cmds, cmd);
322 return result;
323}
324
325static int parse_sleep(int argc, char **argv) {
326 if (argc < 2) {
327 wlr_log(WLR_ERROR, "Too few parameters to before-sleep command. "
328 "Usage: before-sleep <command>");
329 exit(-1);
330 }
331
332 state.lock_cmd = parse_command(argc - 1, &argv[1]);
333 if (state.lock_cmd) {
334 wlr_log(WLR_DEBUG, "Setup sleep lock: %s", state.lock_cmd);
335 }
336
337 return 2;
338}
339
340static int parse_args(int argc, char *argv[]) {
341 bool debug = false;
342
343 int c;
344 while ((c = getopt(argc, argv, "hd")) != -1) {
345 switch (c) {
346 case 'd':
347 debug = true;
348 break;
349 case 'h':
350 case '?':
351 printf("Usage: %s [OPTIONS]\n", argv[0]);
352 printf(" -d\tdebug\n");
353 printf(" -h\tthis help menu\n");
354 return 1;
355 default:
356 return 1;
357 }
358 }
359
360 wlr_log_init(debug ? WLR_DEBUG : WLR_INFO, NULL);
361
362 state.timeout_cmds = create_list();
363
364 int i = optind;
365 while (i < argc) {
366 if (!strcmp("timeout", argv[i])) {
367 wlr_log(WLR_DEBUG, "Got timeout");
368 i += parse_timeout(argc - i, &argv[i]);
369 } else if (!strcmp("before-sleep", argv[i])) {
370 wlr_log(WLR_DEBUG, "Got before-sleep");
371 i += parse_sleep(argc - i, &argv[i]);
372 } else {
373 wlr_log(WLR_ERROR, "Unsupported command '%s'", argv[i]);
374 return 1;
375 }
376 }
377
378 return 0;
379}
380
381static int handle_signal(int sig, void *data) {
382 switch (sig) {
383 case SIGINT:
384 case SIGTERM:
385 sway_terminate(0);
386 return 0;
387 case SIGUSR1:
388 wlr_log(WLR_DEBUG, "Got SIGUSR1");
389 for (int i = 0; i < state.timeout_cmds->length; ++i) {
390 register_timeout(state.timeout_cmds->items[i], 0);
391 }
392 return 1;
393 }
394 assert(false); // not reached
395}
396
397static int display_event(int fd, uint32_t mask, void *data) {
398 if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
399 sway_terminate(0);
400 }
401
402 int count = 0;
403 if (mask & WL_EVENT_READABLE) {
404 count = wl_display_dispatch(state.display);
405 }
406 if (mask & WL_EVENT_WRITABLE) {
407 wl_display_flush(state.display);
408 }
409 if (mask == 0) {
410 count = wl_display_dispatch_pending(state.display);
411 wl_display_flush(state.display);
412 }
413
414 if (count < 0) {
415 wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting");
416 sway_terminate(0);
417 }
418
419 return count;
420}
421
422int main(int argc, char *argv[]) {
423 if (parse_args(argc, argv) != 0) {
424 return -1;
425 }
426
427 state.event_loop = wl_event_loop_create();
428
429 wl_event_loop_add_signal(state.event_loop, SIGINT, handle_signal, NULL);
430 wl_event_loop_add_signal(state.event_loop, SIGTERM, handle_signal, NULL);
431 wl_event_loop_add_signal(state.event_loop, SIGUSR1, handle_signal, NULL);
432
433 state.display = wl_display_connect(NULL);
434 if (state.display == NULL) {
435 wlr_log(WLR_ERROR, "Unable to connect to the compositor. "
436 "If your compositor is running, check or set the "
437 "WAYLAND_DISPLAY environment variable.");
438 return -3;
439 }
440
441 struct wl_registry *registry = wl_display_get_registry(state.display);
442 wl_registry_add_listener(registry, &registry_listener, NULL);
443 wl_display_roundtrip(state.display);
444
445 if (idle_manager == NULL) {
446 wlr_log(WLR_ERROR, "Display doesn't support idle protocol");
447 return -4;
448 }
449 if (seat == NULL) {
450 wlr_log(WLR_ERROR, "Seat error");
451 return -5;
452 }
453
454 bool should_run = state.timeout_cmds->length > 0;
455#if HAVE_SYSTEMD || HAVE_ELOGIND
456 if (state.lock_cmd) {
457 should_run = true;
458 setup_sleep_listener();
459 }
460#endif
461 if (!should_run) {
462 wlr_log(WLR_INFO, "No command specified! Nothing to do, will exit");
463 sway_terminate(0);
464 }
465
466 for (int i = 0; i < state.timeout_cmds->length; ++i) {
467 struct swayidle_timeout_cmd *cmd = state.timeout_cmds->items[i];
468 register_timeout(cmd, cmd->timeout);
469 }
470
471 wl_display_roundtrip(state.display);
472
473 struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop,
474 wl_display_get_fd(state.display), WL_EVENT_READABLE,
475 display_event, NULL);
476 wl_event_source_check(source);
477
478 while (wl_event_loop_dispatch(state.event_loop, -1) != 1) {
479 // This space intentionally left blank
480 }
481
482 sway_terminate(0);
483}
diff --git a/swayidle/meson.build b/swayidle/meson.build
deleted file mode 100644
index 79d2c5c4..00000000
--- a/swayidle/meson.build
+++ /dev/null
@@ -1,27 +0,0 @@
1threads = dependency('threads')
2
3swayidle_deps = [
4 client_protos,
5 pixman,
6 wayland_client,
7 wayland_server,
8 wlroots,
9]
10
11if systemd.found()
12 swayidle_deps += systemd
13endif
14if elogind.found()
15 swayidle_deps += elogind
16endif
17
18executable(
19 'swayidle', [
20 'main.c',
21 ],
22 include_directories: [sway_inc],
23 dependencies: swayidle_deps,
24 link_with: [lib_sway_common, lib_sway_client],
25 install_rpath : rpathdir,
26 install: true
27)
diff --git a/swayidle/swayidle.1.scd b/swayidle/swayidle.1.scd
deleted file mode 100644
index 0e3b5c3c..00000000
--- a/swayidle/swayidle.1.scd
+++ /dev/null
@@ -1,63 +0,0 @@
1swayidle (1)
2
3# NAME
4
5swayidle - Idle manager for Wayland
6
7# SYNOPSIS
8
9*swayidle* [options] [events...]
10
11# OPTIONS
12
13*-h*
14 Show help message and quit.
15
16*-d*
17 Enable debug output.
18
19# DESCRIPTION
20
21swayidle listens for idle activity on your Wayland compositor and executes tasks
22on various idle-related events. You can specify any number of events at the
23command line.
24
25Sending SIGUSR1 to swayidle will immediately enter idle state.
26
27# EVENTS
28
29*timeout* <timeout> <timeout command> [resume <resume command>]
30 Execute _timeout command_ if there is no activity for <timeout> seconds.
31
32 If you specify "resume <resume command>", _resume command_ will be run when
33 there is activity again.
34
35*before-sleep* <command>
36 If built with systemd support, executes _command_ before systemd puts the
37 computer to sleep.
38
39All commands are executed in a shell.
40
41# EXAMPLE
42
43```
44swayidle \
45 timeout 300 'swaylock -c 000000' \
46 timeout 600 'swaymsg "output * dpms off"' \
47 resume 'swaymsg "output * dpms on"' \
48 before-sleep 'swaylock -c 000000'
49```
50
51This will lock your screen after 300 seconds of inactivity, then turn off your
52displays after another 300 seconds, and turn your screens back on when resumed.
53It will also lock your screen before your computer goes to sleep.
54
55# AUTHORS
56
57Maintained by Drew DeVault <sir@cmpwn.com>, who is assisted by other open
58source contributors. For more information about sway development, see
59https://github.com/swaywm/sway.
60
61# SEE ALSO
62
63*sway*(5) *swaymsg*(1) *sway-input*(5) *sway-output*(5) *sway-bar*(5)