aboutsummaryrefslogtreecommitdiffstats
path: root/include/loop.h
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-13 16:04:37 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-15 00:26:27 +1000
commit4056c09e13c1aeead6dd4085fc7e263a17a0b195 (patch)
treea3413f2a5717968e370d68521b689580d5adc5a0 /include/loop.h
parentDocument `border csd` (diff)
downloadsway-4056c09e13c1aeead6dd4085fc7e263a17a0b195.tar.gz
sway-4056c09e13c1aeead6dd4085fc7e263a17a0b195.tar.zst
sway-4056c09e13c1aeead6dd4085fc7e263a17a0b195.zip
Move swaybar's event loop to common directory and refactor
* The loop functions are now prefixed with `loop_`. * It is now easy to add timers to the loop. * Timers are implemented using pollfd and timerfd, rather than manually checking them when any other event happens to arrive.
Diffstat (limited to 'include/loop.h')
-rw-r--r--include/loop.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/include/loop.h b/include/loop.h
new file mode 100644
index 00000000..7c151785
--- /dev/null
+++ b/include/loop.h
@@ -0,0 +1,47 @@
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 * It uses pollfds to block on multiple file descriptors at once, and provides
9 * an easy way to set timers. Typically the Wayland display's fd will be one of
10 * the fds in the loop.
11 */
12
13struct loop;
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 an fd to the loop.
32 */
33struct loop_event *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 */
39struct loop_event *loop_add_timer(struct loop *loop, int ms,
40 void (*callback)(int fd, short mask, void *data), void *data);
41
42/**
43 * Remove an event from the loop.
44 */
45bool loop_remove_event(struct loop *loop, struct loop_event *event);
46
47#endif