ltk

Socket-based GUI for X11 (WIP)
git clone git://lumidify.org/ltk.git (fast, but not encrypted)
git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

commit 941ab3d0f212701eab992f0390279d75425589d4
parent c437b901b8ed5a6ebbc4c46806ee215adad4373c
Author: lumidify <nobody@lumidify.org>
Date:   Tue, 29 Dec 2020 14:34:44 +0100

Fix select delay on Linux; realize that microseconds are not, in fact, milliseconds

Diffstat:
Mltkc.c | 9++++++---
Mltkd.c | 30+++++++++++++++++-------------
2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/ltkc.c b/ltkc.c @@ -50,9 +50,9 @@ int main(int argc, char *argv[]) { int outfd = fileno(stdout); struct sockaddr_un un; fd_set rfds, wfds, rallfds, wallfds; - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 15; + struct timeval tv, tv_master; + tv_master.tv_sec = 0; + tv_master.tv_usec = 20000; char *ltk_dir = NULL, *sock_path = NULL; int path_size; @@ -122,7 +122,10 @@ int main(int argc, char *argv[]) { wfds = wallfds; /* Separate this because the writing fds are *usually* always ready, leading to the loop looping way too fast */ + tv = tv_master; select(maxrfd + 1, &rfds, NULL, NULL, &tv); + /* value of tv doesn't really matter anymore here because the + necessary framerate-limiting delay is already done */ select(maxwfd + 1, NULL, &wfds, NULL, &tv); if (FD_ISSET(sockfd, &rfds)) { diff --git a/ltkd.c b/ltkd.c @@ -112,19 +112,6 @@ static char *sock_path = NULL; int main(int argc, char *argv[]) { ltk_window *window = ltk_create_window("theme.ini", "Demo", 0, 0, 500, 500); - return ltk_mainloop(window); -} - -static int -ltk_mainloop(ltk_window *window) { - XEvent event; - fd_set rfds, wfds, rallfds, wallfds; - int maxfd; - int rretval, wretval; - int clifd; - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 10; ltk_dir = ltk_setup_directory(); if (!ltk_dir) ltk_fatal("Unable to setup ltk directory.\n"); @@ -142,6 +129,20 @@ ltk_mainloop(ltk_window *window) { sockets[i].tokens.tokens = NULL; } + return ltk_mainloop(window); +} + +static int +ltk_mainloop(ltk_window *window) { + XEvent event; + fd_set rfds, wfds, rallfds, wallfds; + int maxfd; + int rretval, wretval; + int clifd; + struct timeval tv, tv_master; + tv_master.tv_sec = 0; + tv_master.tv_usec = 10; + FD_ZERO(&rallfds); FD_ZERO(&wallfds); @@ -159,7 +160,10 @@ ltk_mainloop(ltk_window *window) { wfds = wallfds; /* separate these because the writing fds are usually always ready for writing */ + tv = tv_master; rretval = select(maxfd + 1, &rfds, NULL, NULL, &tv); + /* value of tv doesn't really matter anymore here because the + necessary framerate-limiting delay is already done */ wretval = select(maxfd + 1, NULL, &wfds, NULL, &tv); while (XPending(window->dpy)) { XNextEvent(window->dpy, &event);