diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/loop.h | 54 | ||||
-rw-r--r-- | include/swaybar/bar.h | 3 | ||||
-rw-r--r-- | include/swaybar/event_loop.h | 26 | ||||
-rw-r--r-- | include/swaybar/status_line.h | 2 | ||||
-rw-r--r-- | include/swaylock/swaylock.h | 4 |
5 files changed, 63 insertions, 26 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 | |||
12 | struct loop; | ||
13 | struct loop_timer; | ||
14 | |||
15 | /** | ||
16 | * Create an event loop. | ||
17 | */ | ||
18 | struct loop *loop_create(void); | ||
19 | |||
20 | /** | ||
21 | * Destroy the event loop (eg. on program termination). | ||
22 | */ | ||
23 | void loop_destroy(struct loop *loop); | ||
24 | |||
25 | /** | ||
26 | * Poll the event loop. This will block until one of the fds has data. | ||
27 | */ | ||
28 | void loop_poll(struct loop *loop); | ||
29 | |||
30 | /** | ||
31 | * Add a file descriptor to the loop. | ||
32 | */ | ||
33 | void 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 | */ | ||
41 | struct 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 | */ | ||
47 | bool loop_remove_fd(struct loop *loop, int fd); | ||
48 | |||
49 | /** | ||
50 | * Remove a timer from the loop. | ||
51 | */ | ||
52 | bool loop_remove_timer(struct loop *loop, struct loop_timer *timer); | ||
53 | |||
54 | #endif | ||
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 9ff3fe7b..58e2dee6 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -8,6 +8,7 @@ | |||
8 | struct swaybar_config; | 8 | struct swaybar_config; |
9 | struct swaybar_output; | 9 | struct swaybar_output; |
10 | struct swaybar_workspace; | 10 | struct swaybar_workspace; |
11 | struct loop; | ||
11 | 12 | ||
12 | struct swaybar_pointer { | 13 | struct swaybar_pointer { |
13 | struct wl_pointer *pointer; | 14 | struct wl_pointer *pointer; |
@@ -66,6 +67,8 @@ struct swaybar { | |||
66 | struct swaybar_pointer pointer; | 67 | struct swaybar_pointer pointer; |
67 | struct status_line *status; | 68 | struct status_line *status; |
68 | 69 | ||
70 | struct loop *eventloop; | ||
71 | |||
69 | int ipc_event_socketfd; | 72 | int ipc_event_socketfd; |
70 | int ipc_socketfd; | 73 | int ipc_socketfd; |
71 | 74 | ||
diff --git a/include/swaybar/event_loop.h b/include/swaybar/event_loop.h deleted file mode 100644 index 47be5b79..00000000 --- a/include/swaybar/event_loop.h +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #ifndef _SWAYBAR_EVENT_LOOP_H | ||
2 | #define _SWAYBAR_EVENT_LOOP_H | ||
3 | #include <stdbool.h> | ||
4 | #include <time.h> | ||
5 | |||
6 | void add_event(int fd, short mask, | ||
7 | void(*cb)(int fd, short mask, void *data), | ||
8 | void *data); | ||
9 | |||
10 | // Not guaranteed to notify cb immediately | ||
11 | void add_timer(timer_t timer, | ||
12 | void(*cb)(timer_t timer, void *data), | ||
13 | void *data); | ||
14 | |||
15 | // Returns false if nothing exists, true otherwise | ||
16 | bool remove_event(int fd); | ||
17 | |||
18 | // Returns false if nothing exists, true otherwise | ||
19 | bool remove_timer(timer_t timer); | ||
20 | |||
21 | // Blocks and returns after sending callbacks | ||
22 | void event_loop_poll(void); | ||
23 | |||
24 | void init_event_loop(void); | ||
25 | |||
26 | #endif | ||
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h index 5e7e8771..957a808e 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h | |||
@@ -14,6 +14,8 @@ enum status_protocol { | |||
14 | }; | 14 | }; |
15 | 15 | ||
16 | struct status_line { | 16 | struct status_line { |
17 | struct swaybar *bar; | ||
18 | |||
17 | pid_t pid; | 19 | pid_t pid; |
18 | int read_fd, write_fd; | 20 | int read_fd, write_fd; |
19 | FILE *read, *write; | 21 | FILE *read, *write; |
diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h index fbdd42a8..25b41a71 100644 --- a/include/swaylock/swaylock.h +++ b/include/swaylock/swaylock.h | |||
@@ -54,6 +54,10 @@ struct swaylock_password { | |||
54 | }; | 54 | }; |
55 | 55 | ||
56 | struct swaylock_state { | 56 | struct swaylock_state { |
57 | struct loop *eventloop; | ||
58 | struct loop_timer *clear_indicator_timer; // clears the indicator | ||
59 | struct loop_timer *clear_password_timer; // clears the password buffer | ||
60 | struct loop_timer *verify_password_timer; | ||
57 | struct wl_display *display; | 61 | struct wl_display *display; |
58 | struct wl_compositor *compositor; | 62 | struct wl_compositor *compositor; |
59 | struct zwlr_layer_shell_v1 *layer_shell; | 63 | struct zwlr_layer_shell_v1 *layer_shell; |