summaryrefslogtreecommitdiffstats
path: root/include/loop.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/loop.h')
-rw-r--r--include/loop.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/loop.h b/include/loop.h
new file mode 100644
index 00000000..2f608eda
--- /dev/null
+++ b/include/loop.h
@@ -0,0 +1,54 @@
1#ifndef _SWAY_LOOP_H
2#define _SWAY_LOOP_H
3#include <stdbool.h>
4
5/**
6 * This is an event loop system designed for sway clients, not sway itself.
7 *
8 * The loop consists of file descriptors and timers. Typically the Wayland
9 * display's file descriptor will be one of the fds in the loop.
10 */
11
12struct loop;
13struct loop_timer;
14
15/**
16 * Create an event loop.
17 */
18struct loop *loop_create(void);
19
20/**
21 * Destroy the event loop (eg. on program termination).
22 */
23void loop_destroy(struct loop *loop);
24
25/**
26 * Poll the event loop. This will block until one of the fds has data.
27 */
28void loop_poll(struct loop *loop);
29
30/**
31 * Add a file descriptor to the loop.
32 */
33void loop_add_fd(struct loop *loop, int fd, short mask,
34 void (*func)(int fd, short mask, void *data), void *data);
35
36/**
37 * Add a timer to the loop.
38 *
39 * When the timer expires, the timer will be removed from the loop and freed.
40 */
41struct loop_timer *loop_add_timer(struct loop *loop, int ms,
42 void (*callback)(void *data), void *data);
43
44/**
45 * Remove a file descriptor from the loop.
46 */
47bool loop_remove_fd(struct loop *loop, int fd);
48
49/**
50 * Remove a timer from the loop.
51 */
52bool loop_remove_timer(struct loop *loop, struct loop_timer *timer);
53
54#endif