aboutsummaryrefslogtreecommitdiff
path: root/src/lib/libkogata/mainloop.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-04-01 23:23:34 +0200
committerAlex Auvolat <alex@adnab.me>2018-04-01 23:23:34 +0200
commita36c6528b10cb5b5d48fbf30a941443f738c9dd1 (patch)
tree19249d98dbe3a55d5f18050797959d7ca64a97bd /src/lib/libkogata/mainloop.c
parent67db86ec53336da886153797deb643483e9596d0 (diff)
downloadkogata-a36c6528b10cb5b5d48fbf30a941443f738c9dd1.tar.gz
kogata-a36c6528b10cb5b5d48fbf30a941443f738c9dd1.zip
Terminal inside Lua window manager
Diffstat (limited to 'src/lib/libkogata/mainloop.c')
-rw-r--r--src/lib/libkogata/mainloop.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/lib/libkogata/mainloop.c b/src/lib/libkogata/mainloop.c
index c1758a4..75fb252 100644
--- a/src/lib/libkogata/mainloop.c
+++ b/src/lib/libkogata/mainloop.c
@@ -7,6 +7,9 @@ mainloop_fd_t *mainloop_fds = 0;
bool mainloop_fds_change = false;
bool mainloop_must_exit = false;
+idle_callback_t mainloop_idle_cb = 0;
+void* mainloop_idle_cb_data = 0;
+
void mainloop_add_fd(mainloop_fd_t* fd) {
mainloop_fds_change = true;
@@ -53,12 +56,19 @@ bool mainloop_nonblocking_write(mainloop_fd_t *fd, void* buf, size_t size, bool
return false;
}
+void mainloop_when_idle(idle_callback_t cb, void* data) {
+ mainloop_idle_cb = cb;
+ mainloop_idle_cb_data = data;
+}
+
void mainloop_run() {
sel_fd_t *sel_arg = 0;
int nfds = 0;
mainloop_fds_change = true;
mainloop_must_exit = false;
+
+ bool after_idle_step = false;
while(!mainloop_must_exit) {
if (mainloop_fds_change) {
nfds = 0;
@@ -91,11 +101,12 @@ void mainloop_run() {
// ---- Do the select
/*dbg_printf("(mainloop) begin select\n");*/
- bool ok = sc_select(sel_arg, nfds, -1);
+ bool ok = sc_select(sel_arg, nfds, (after_idle_step || mainloop_idle_cb == 0 ? -1 : 0));
if (!ok) {
- dbg_printf("(mainloop) Failed to select.\n");
- free(sel_arg);
- return;
+ // nothing happenned
+ if (mainloop_idle_cb != 0) mainloop_idle_cb(mainloop_idle_cb_data);
+ after_idle_step = true;
+ continue;
}
/*dbg_printf("(mainloop) end select\n");*/
@@ -131,6 +142,7 @@ void mainloop_run() {
}
i++;
}
+ after_idle_step = false;
}
}
}