aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorRyan Dwyer <ryandwyer1@gmail.com>2018-10-13 16:52:13 +1000
committerRyan Dwyer <ryandwyer1@gmail.com>2018-10-15 00:26:27 +1000
commitc242712262c5cb751fc0f89050a7f7a24433b105 (patch)
tree73b8b7024da57319fa7038e186719faf319faa16 /common
parent9c833c661ac9e061bf4d666065e3090639f481ff (diff)
swaylock: Remove indicator after 3 seconds
Diffstat (limited to 'common')
-rw-r--r--common/loop.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/common/loop.c b/common/loop.c
index bfbfd5a6..da3c2142 100644
--- a/common/loop.c
+++ b/common/loop.c
@@ -12,6 +12,7 @@
struct loop_event {
void (*callback)(int fd, short mask, void *data);
void *data;
+ bool is_timer;
};
struct loop {
@@ -52,6 +53,11 @@ void loop_poll(struct loop *loop) {
if (pfd.revents & events) {
event->callback(pfd.fd, pfd.revents, event->data);
+
+ if (event->is_timer) {
+ loop_remove_event(loop, event);
+ --i;
+ }
}
}
}
@@ -82,11 +88,14 @@ struct loop_event *loop_add_timer(struct loop *loop, int ms,
struct itimerspec its;
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
- its.it_value.tv_sec = ms / 1000000000;
- its.it_value.tv_nsec = (ms * 1000000) % 1000000000;
+ its.it_value.tv_sec = ms / 1000;
+ its.it_value.tv_nsec = (ms % 1000) * 1000000;
timerfd_settime(fd, 0, &its, NULL);
- return loop_add_fd(loop, fd, POLLIN, callback, data);
+ struct loop_event *event = loop_add_fd(loop, fd, POLLIN, callback, data);
+ event->is_timer = true;
+
+ return event;
}
bool loop_remove_event(struct loop *loop, struct loop_event *event) {
@@ -94,6 +103,10 @@ bool loop_remove_event(struct loop *loop, struct loop_event *event) {
if (loop->events->items[i] == event) {
list_del(loop->events, i);
+ if (event->is_timer) {
+ close(loop->fds[i].fd);
+ }
+
loop->fd_length--;
memmove(&loop->fds[i], &loop->fds[i + 1], sizeof(void*) * (loop->fd_length - i));