Sample Header Ad - 728x90

Xlib: what is the best implementation of GUI digital clock?

0 votes
2 answers
515 views
I am making an X application which contains a digital clock. The clock displays the current time in the format of "hh:mm". I want to master Xlib, so I want to use only Xlib (no other toolkits). The clock has to refresh once in a minute. For the refreshment of the clock, I came up with three implementations, but I cannot judge which is the best one. Please tell me which is the best. And, if there are other better implementations, please tell me. The first implementation refreshes the clock from inside the event loop. The second and third implementations refresh the clock from outside the event loop. The first implementation is as follows: in the event loop, I use XEventsQueued or XPending to know the number remaining events. If there remains no events, check the current time, and if 1 minute or more passed since the last refreshment, I refresh the clock. If there remains some events, I process other window events. The second implementation is as follows: I use setitimer with the interval of 1 minute. The signal handler catch SIGALRM and refresh the clock. The third implementation is as follows: I use pthread. The thread function refreshes the clock and sleep 1 mintes, and does the same thing forever. The first implementation is the most simple. But I am afraid that it frequently repeats the event loop and consumes the CPU power.
Asked by user356126 (609 rep)
Mar 6, 2022, 02:49 AM
Last activity: Mar 6, 2022, 11:25 AM